购车,订单结算增加了 打包费逻辑

This commit is contained in:
Jack 2025-08-16 22:54:20 +08:00
parent 655f71abfd
commit 19fb718496
3 changed files with 211 additions and 204 deletions

View File

@ -1285,319 +1285,320 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
throw new ApiUserException(I18nUtil._("用户信息异常!")); throw new ApiUserException(I18nUtil._("用户信息异常!"));
} }
Integer user_id = user.getId(); Integer userId = user.getId();
Integer ud_id = getParameter("ud_id", Integer.class); Integer udId = getParameter("ud_id", Integer.class);
Integer is_edu = getParameter("is_edu", Integer.class); Integer isEdu = getParameter("is_edu", Integer.class);
Integer is_voucher = getParameter("is_voucher", Integer.class); Integer isVoucher = getParameter("is_voucher", Integer.class);
if (ud_id == null && CheckUtil.isEmpty(is_edu) && CheckUtil.isEmpty(is_voucher)) { if (udId == null && CheckUtil.isEmpty(isEdu) && CheckUtil.isEmpty(isVoucher)) {
throw new ApiException(I18nUtil._("请选择你的收货地址!")); throw new ApiException(I18nUtil._("请选择你的收货地址!"));
} }
Integer chain_id = getParameter("chain_id", 0); Integer chainId = getParameter("chain_id", 0);
Boolean if_chain = Convert.toBool(getParameter("if_chain"), false); Boolean ifChain = Convert.toBool(getParameter("if_chain"), false);
Integer checked_store = getParameter("checked_store", 0); Integer checkedStore = getParameter("checked_store", 0);
Integer ifcart = getParameter("ifcart", 0); Integer ifCart = getParameter("ifcart", 0);
List<Map> item_rows = new ArrayList(); // 购物车商品列表
if (ifcart > 0) { List<Map> cartItemRows = new ArrayList();
if (ifCart > 0) {
// 从购物车走 // 从购物车走
QueryWrapper<ShopUserCart> cartQueryWrapper = new QueryWrapper<>(); QueryWrapper<ShopUserCart> cartQueryWrapper = new QueryWrapper<>();
cartQueryWrapper.eq("chain_id", chain_id).eq("user_id", user_id).eq("cart_select", 1).gt("cart_quantity", 0); cartQueryWrapper.eq("chain_id", chainId).eq("user_id", userId).eq("cart_select", 1).gt("cart_quantity", 0);
if (checked_store > 0) { if (checkedStore > 0) {
// 权限判断 // 权限判断
cartQueryWrapper.eq("store_id", checked_store); cartQueryWrapper.eq("store_id", checkedStore);
} }
Map cart_data = shopUserCartService.getLists(cartQueryWrapper, 1, 500); // 购物车数据
item_rows = (List<Map>) cart_data.get("items"); Map cartResultData = shopUserCartService.getLists(cartQueryWrapper);
cartItemRows = (List<Map>) cartResultData.get("items");
} }
// 重要方法 // 重要方法
return doQuickAddOrder(user_id, item_rows, ud_id, true, "", StateCode.ORDER_TYPE_DD, null); return doQuickAddOrder(userId, cartItemRows, udId, true, "", StateCode.ORDER_TYPE_DD, null);
} }
/** /**
* 添加订单详细信息 预处理 -> addOrder 转移过来所以直接读取request 不合规范兼容前后端下单逻辑 * 添加订单详细信息 预处理 -> addOrder 转移过来所以直接读取request 不合规范兼容前后端下单逻辑
* *
* @param user_id 用户编号 * @param userId 用户编号
* @param item_rows 订单数据 * @param itemRows 订单数据
* @param ud_id 地址编号 或者 地址数据Map * @param udId 地址编号 或者 地址数据Map
* @param cal_freight 是否需要计算运费 * @param calFreight 是否需要计算运费
* @param src_order_id 供应商转单源订单 * @param srcOrderId 供应商转单源订单
* @param order_type 订单类型 * @param orderType 订单类型
* @return * @return
* @access public * @access public
*/ */
@Override @Override
public CommonResult doQuickAddOrder(Integer user_id, List<Map> item_rows, Object ud_id, boolean cal_freight, String src_order_id, Integer order_type, FixOrderVo fixOrderVo) { public CommonResult doQuickAddOrder(Integer userId, List<Map> itemRows, Object udId, boolean calFreight, String srcOrderId, Integer orderType, FixOrderVo fixOrderVo) {
AccountUserBase user_row = accountService.getUserBase(user_id); AccountUserBase userRow = accountService.getUserBase(userId);
Integer pfgb_id = Convert.toInt(getParameter("pfgb_id"), 0); Integer pfgbId = Convert.toInt(getParameter("pfgb_id"), 0);
Integer activity_id = Convert.toInt(getParameter("activity_id"), 0); Integer activityId = Convert.toInt(getParameter("activity_id"), 0);
Integer quantity = getParameter("quantity", 1); Integer quantity = getParameter("quantity", 1);
Integer channel_type = getParameter("channel_type", 0); Integer channelType = getParameter("channel_type", 0);
Map activity_rows = new HashMap(); Map activityRows = new HashMap();
if (!activity_id.equals(0)) { if (!activityId.equals(0)) {
activity_rows = shopStoreActivityBaseService.getActivityFormatOne(activity_id, quantity); activityRows = shopStoreActivityBaseService.getActivityFormatOne(activityId, quantity);
} }
Boolean force_bind_mobile = accountBaseConfigService.getConfig("force_bind_mobile", false); Boolean forceBindMobile = accountBaseConfigService.getConfig("force_bind_mobile", false);
Map userBind = accountService.getBind(user_id, BindCode.MOBILE); Map userBind = accountService.getBind(userId, BindCode.MOBILE);
Map cart_data; Map cartData;
if (!force_bind_mobile || CollUtil.isNotEmpty(userBind)) { if (!forceBindMobile || CollUtil.isNotEmpty(userBind)) {
// 手机绑定的情况 // 手机绑定的情况
Integer chain_id = Convert.toInt(getParameter("chain_id")); Integer chainId = Convert.toInt(getParameter("chain_id"));
Boolean if_chain = Convert.toBool(getParameter("if_chain"), false); Boolean ifChain = Convert.toBool(getParameter("if_chain"), false);
Integer checked_store = getParameter("checked_store", 0); Integer checkedStore = getParameter("checked_store", 0);
// 优惠券id检测 // 优惠券id检测
List<Integer> user_voucher_ids = checkCoupon(); List<Integer> userVoucherIds = checkCoupon();
Map checkout_row = new HashMap(); Map checkoutRow = new HashMap();
// 配送方式5-门店自提10-普通快递16-同城配送 // 配送方式5-门店自提10-普通快递16-同城配送
Integer delivery_type_id = getParameter("delivery_type_id", StateCode.DELIVERY_TYPE_SAME_CITY); Integer deliveryTypeId = getParameter("delivery_type_id", StateCode.DELIVERY_TYPE_SAME_CITY);
logger.debug("提交订单时,配送方式 delivery_type_id:{}", delivery_type_id); logger.debug("提交订单时,配送方式 delivery_type_id:{}", deliveryTypeId);
if (getParameter("checkout_row") == null) { if (getParameter("checkout_row") == null) {
Date cur_date = new Date(); Date curDate = new Date();
checkout_row.put("payment_type_id", StateCode.PAYMENT_TYPE_ONLINE); checkoutRow.put("payment_type_id", StateCode.PAYMENT_TYPE_ONLINE);
checkout_row.put("delivery_type_id", delivery_type_id); checkoutRow.put("delivery_type_id", deliveryTypeId);
checkout_row.put("delivery_time_id", 1); checkoutRow.put("delivery_time_id", 1);
checkout_row.put("invoice_type_id", 1); checkoutRow.put("invoice_type_id", 1);
checkout_row.put("order_invoice_title", ""); checkoutRow.put("order_invoice_title", "");
checkout_row.put("delivery_time", cur_date); checkoutRow.put("delivery_time", curDate);
checkout_row.put("delivery_time_h", DateUtil.hour(cur_date, true)); checkoutRow.put("delivery_time_h", DateUtil.hour(curDate, true));
} else { } else {
checkout_row = Convert.toMap(String.class, Object.class, JSONUtil.parseObj(getParameter("checkout_row"))); checkoutRow = Convert.toMap(String.class, Object.class, JSONUtil.parseObj(getParameter("checkout_row")));
} }
//// 配送方式5-门店自提10-普通快递16-同城配送 //// 配送方式5-门店自提10-普通快递16-同城配送
if (delivery_type_id.equals(StateCode.DELIVERY_TYPE_SELF_PICK_UP)) { if (deliveryTypeId.equals(StateCode.DELIVERY_TYPE_SELF_PICK_UP)) {
// 5-门店自提 // 5-门店自提
cal_freight = false; calFreight = false;
} }
Integer user_invoice_id = Convert.toInt(getParameter("user_invoice_id")); Integer userInvoiceId = Convert.toInt(getParameter("user_invoice_id"));
// 用户发票检测 // 用户发票检测
checkUserInvoice(user_id, checkout_row, user_invoice_id); checkUserInvoice(userId, checkoutRow, userInvoiceId);
List cartRows = new ArrayList();
List cart_rows = new ArrayList(); Integer ifCart = getParameter("ifcart", 0);
Integer ifcart = getParameter("ifcart", 0); if (ifCart > 0) {
if (ifcart > 0) {
// 从购物车走 // 从购物车走
QueryWrapper<ShopUserCart> cartQueryWrapper = new QueryWrapper<>(); QueryWrapper<ShopUserCart> cartQueryWrapper = new QueryWrapper<>();
cartQueryWrapper.eq("user_id", user_id).eq("cart_select", 1).gt("cart_quantity", 0); cartQueryWrapper.eq("user_id", userId).eq("cart_select", 1).gt("cart_quantity", 0);
// .eq("chain_id", chain_id) TODO update 2024-12-23 蓝驰要求 // .eq("chain_id", chainId) TODO update 2024-12-23 蓝驰要求
if (checked_store > 0) { if (checkedStore > 0) {
cartQueryWrapper.eq("store_id", checked_store); cartQueryWrapper.eq("store_id", checkedStore);
} }
cart_data = shopUserCartService.getLists(cartQueryWrapper, 1, 500); cartData = shopUserCartService.getLists(cartQueryWrapper, 1, 500);
} else { } else {
String item_info = getParameter("cart_id"); String itemInfo = getParameter("cart_id");
List<String> item_info_row = new ArrayList(); List<String> itemInfoRow = new ArrayList();
if (StrUtil.isNotBlank(item_info)) { if (StrUtil.isNotBlank(itemInfo)) {
item_info_row = Convert.toList(String.class, item_info.split(",")); itemInfoRow = Convert.toList(String.class, itemInfo.split(","));
} else { } else {
for (Map item_row : item_rows) { for (Map itemRow : itemRows) {
Integer cart_quantity = Convert.toInt(item_row.get("cart_quantity")); Integer cartQuantity = Convert.toInt(itemRow.get("cart_quantity"));
if (cart_quantity >= 1) { if (cartQuantity >= 1) {
Long item_id = Convert.toLong(item_row.get("item_id")); Long itemId = Convert.toLong(itemRow.get("item_id"));
item_info_row.add(item_id + "|" + cart_quantity); itemInfoRow.add(itemId + "|" + cartQuantity);
} }
} }
} }
for (String item : item_info_row) { for (String item : itemInfoRow) {
String[] item_row = item.split("\\|"); String[] itemRow = item.split("\\|");
Long item_id = Convert.toLong(item_row[0]); Long itemId = Convert.toLong(itemRow[0]);
Integer cart_quantity = Convert.toInt(item_row[1]); Integer cartQuantity = Convert.toInt(itemRow[1]);
HashMap cart_row = new HashMap(); HashMap cartRow = new HashMap();
cart_rows.add(cart_row); cartRows.add(cartRow);
ShopProductItem product_row = shopProductItemService.get(item_id); ShopProductItem productRow = shopProductItemService.get(itemId);
if (if_chain) { if (ifChain) {
cart_row.put("chain_id", chain_id); cartRow.put("chain_id", chainId);
} }
cart_row.put("user_id", user_id); cartRow.put("user_id", userId);
cart_row.put("store_id", product_row.getStore_id()); cartRow.put("store_id", productRow.getStore_id());
cart_row.put("item_id", item_id); cartRow.put("item_id", itemId);
cart_row.put("cart_quantity", cart_quantity); cartRow.put("cart_quantity", cartQuantity);
cart_row.put("single_activity", shopUserCartService.ifSingleActivity()); cartRow.put("single_activity", shopUserCartService.ifSingleActivity());
cart_row.put("cart_select", 1); cartRow.put("cart_select", 1);
cart_row.put("cart_type", 1); cartRow.put("cart_type", 1);
cart_row.put("activity_id", activity_id); cartRow.put("activity_id", activityId);
cart_row.put("cart_file", getParameter("cart_file")); cartRow.put("cart_file", getParameter("cart_file"));
cart_row.put("pfgb_id", pfgb_id); cartRow.put("pfgb_id", pfgbId);
} }
cart_data = shopUserCartService.formatCartRows(cart_rows, activity_rows, null, fixOrderVo); cartData = shopUserCartService.formatCartRows(cartRows, activityRows, null, fixOrderVo);
} }
cart_data.put("payment_form_id", getParameter("payment_form_id")); cartData.put("payment_form_id", getParameter("payment_form_id"));
Integer salesperson_id = Convert.toInt(getParameter("salesperson_id")); // 导购员用户编号 Integer salespersonId = Convert.toInt(getParameter("salesperson_id")); // 导购员用户编号
cart_data.put("order_message", JSONUtil.parseObj(getParameter("order_message"))); cartData.put("order_message", JSONUtil.parseObj(getParameter("order_message")));
cart_data.put("salesperson_id", 0); cartData.put("salesperson_id", 0);
// 来源订单 // 来源订单
cart_data.put("src_order_id", src_order_id); cartData.put("src_order_id", srcOrderId);
//订单类型线上线下 //订单类型线上线下
cart_data.put("order_type", order_type); cartData.put("order_type", orderType);
// 配送方式 // 配送方式
cart_data.put("delivery_type_id", delivery_type_id); cartData.put("delivery_type_id", deliveryTypeId);
// 修改为distributor_user_id // 修改为distributor_user_id
Integer distributor_user_id = getParameter("distributor_user_id", Integer.class); Integer distributorUserId = getParameter("distributor_user_id", Integer.class);
if (CheckUtil.isNotEmpty(distributor_user_id)) { if (CheckUtil.isNotEmpty(distributorUserId)) {
cart_data.put("distributor_user_id", distributor_user_id); // 分销商店铺编号 cartData.put("distributor_user_id", distributorUserId); // 分销商店铺编号
} }
Integer distributor_id = getParameter("distributor_id", Integer.class); Integer distributorId = getParameter("distributor_id", Integer.class);
if (CheckUtil.isNotEmpty(distributor_id)) { if (CheckUtil.isNotEmpty(distributorId)) {
// 读取分销商编号 // 读取分销商编号
QueryWrapper<ShopStoreEmployee> employeeQueryWrapper = new QueryWrapper<>(); QueryWrapper<ShopStoreEmployee> employeeQueryWrapper = new QueryWrapper<>();
employeeQueryWrapper.eq("store_id", distributor_id).eq("employee_is_admin", CommonConstant.USER_TYPE_ADMIN); employeeQueryWrapper.eq("store_id", distributorId).eq("employee_is_admin", CommonConstant.USER_TYPE_ADMIN);
ShopStoreEmployee epl_row = storeEmployeeService.findOne(employeeQueryWrapper); ShopStoreEmployee eplRow = storeEmployeeService.findOne(employeeQueryWrapper);
if (epl_row != null && ObjectUtil.equal(epl_row.getUser_id(), distributor_user_id)) { if (eplRow != null && ObjectUtil.equal(eplRow.getUser_id(), distributorUserId)) {
cart_data.put("distributor_user_id", distributor_user_id); cartData.put("distributor_user_id", distributorUserId);
} }
} }
// 自提和上门服务走 User_DeliveryAddressModel到店取货填写手机接受短信兑换码 // 自提和上门服务走 User_DeliveryAddressModel到店取货填写手机接受短信兑换码
Integer _ud_id = getParameter("ud_id", Integer.class); Integer udIdParam = getParameter("ud_id", Integer.class);
Integer is_edu = getParameter("is_edu", Integer.class); Integer isEdu = getParameter("is_edu", Integer.class);
Integer is_voucher = getParameter("is_voucher", Integer.class); Integer isVoucher = getParameter("is_voucher", Integer.class);
if (CheckUtil.isEmpty(is_edu) || CheckUtil.isEmpty(is_voucher)) { if (CheckUtil.isEmpty(isEdu) || CheckUtil.isEmpty(isVoucher)) {
if (ud_id != null && ud_id instanceof Map) { if (udId != null && udId instanceof Map) {
cart_data.put("address_row", ud_id); cartData.put("address_row", udId);
} else if (ud_id != null || (ud_id = _ud_id) != null) { } else if (udId != null || (udId = udIdParam) != null) {
ShopUserDeliveryAddress deliveryAddress = userDeliveryAddressService.get((Integer) ud_id); ShopUserDeliveryAddress deliveryAddress = userDeliveryAddressService.get((Integer) udId);
Map address_row = Convert.toMap(String.class, Object.class, deliveryAddress); Map addressRow = Convert.toMap(String.class, Object.class, deliveryAddress);
cart_data.put("address_row", address_row); cartData.put("address_row", addressRow);
// 用户选中的收货地址 2024-12-05 add // 用户选中的收货地址 2024-12-05 add
cart_data.put("delivery_address_row", deliveryAddress); cartData.put("delivery_address_row", deliveryAddress);
cart_data.put("is_delivery", true); cartData.put("is_delivery", true);
} else { } else {
cart_data.put("is_delivery", false); cartData.put("is_delivery", false);
} }
} else { } else {
cart_data.put("is_delivery", false); cartData.put("is_delivery", false);
} }
// 如果后台下单只有一个教育商品则不走运费 // 如果后台下单只有一个教育商品则不走运费
if (CheckUtil.isEmpty(is_edu) && item_rows.size() == 1) { if (CheckUtil.isEmpty(isEdu) && itemRows.size() == 1) {
Integer kind_id = Convert.toInt(item_rows.get(0).get("kind_id"), 0); Integer kindId = Convert.toInt(itemRows.get(0).get("kind_id"), 0);
// 商品包含一个教育 // 商品包含一个教育
if (ObjectUtil.equal(kind_id, StateCode.PRODUCT_KIND_EDU)) { if (ObjectUtil.equal(kindId, StateCode.PRODUCT_KIND_EDU)) {
cal_freight = false; calFreight = false;
cart_data.put("is_delivery", false); cartData.put("is_delivery", false);
} }
} }
cart_data.put("user_voucher_ids", user_voucher_ids); cartData.put("user_voucher_ids", userVoucherIds);
cart_data.put("checkout_row", checkout_row); cartData.put("checkout_row", checkoutRow);
cart_data.put("buyer_user_id", user_id); cartData.put("buyer_user_id", userId);
cart_data.put("buyer_user_name", user_row.getUser_nickname()); cartData.put("buyer_user_name", userRow.getUser_nickname());
// 判断是否拼团购买 // 判断是否拼团购买
String str_gb_id = getParameter("gb_id"); String strGbId = getParameter("gb_id");
Integer gb_id = null; Integer gbId = null;
if (StrUtil.isNotBlank(str_gb_id)) { if (StrUtil.isNotBlank(strGbId)) {
gb_id = NumberUtil.isNumber(str_gb_id) ? Convert.toInt(str_gb_id) : 0; gbId = NumberUtil.isNumber(strGbId) ? Convert.toInt(strGbId) : 0;
cart_data.put("gb_id", gb_id); // 拼团ID, 为0在创建拼团 cartData.put("gb_id", gbId); // 拼团ID, 为0在创建拼团
} }
// 判断是否砍价购买 // 判断是否砍价购买
Integer ac_id = getParameter("ac_id", Integer.class); Integer acId = getParameter("ac_id", Integer.class);
if (ac_id != null) { if (acId != null) {
cart_data.put("ac_id", ac_id); // 拼团ID, 为0在创建拼团 cartData.put("ac_id", acId); // 拼团ID, 为0在创建拼团
} }
// 重要邮费检测和计算 // 重要邮费检测和计算
dealWithCalFee(cal_freight, cart_data, chain_id, is_edu); dealWithCalFee(calFreight, cartData, chainId, isEdu);
// 判断是否上传素材 // 判断是否上传素材
checkIsUploadMaterial(cart_data); checkIsUploadMaterial(cartData);
// 是否单品推广 // 是否单品推广
JSONObject source_item_id_rows = new JSONObject(); JSONObject sourceItemIdRows = new JSONObject();
String source_item_id = getParameter("source_item_id"); String sourceItemId = getParameter("source_item_id");
if (StrUtil.isNotBlank(source_item_id)) { if (StrUtil.isNotBlank(sourceItemId)) {
source_item_id_rows = JSONUtil.parseObj(source_item_id); sourceItemIdRows = JSONUtil.parseObj(sourceItemId);
} }
cart_data.put("source_item_id", source_item_id_rows); cartData.put("source_item_id", sourceItemIdRows);
//门店自提方式则判断是否需要分店铺下单 //门店自提方式则判断是否需要分店铺下单
if (StateCode.DELIVERY_TYPE_SELF_PICK_UP == getParameter("delivery_type_id", StateCode.DELIVERY_TYPE_EXP)) { if (StateCode.DELIVERY_TYPE_SELF_PICK_UP == getParameter("delivery_type_id", StateCode.DELIVERY_TYPE_EXP)) {
if (CommonConstant.Enable == accountBaseConfigService.getConfig("product_ziti_flag", CommonConstant.Disable)) { if (CommonConstant.Enable == accountBaseConfigService.getConfig("product_ziti_flag", CommonConstant.Disable)) {
List<Integer> store_o2o_flag_row = ((List<Map>) cart_data.get("items")).stream().map(s -> Convert.toInt(s.get("store_o2o_flag"))).distinct().collect(Collectors.toList()); List<Integer> storeO2oFlagRow = ((List<Map>) cartData.get("items")).stream().map(s -> Convert.toInt(s.get("store_o2o_flag"))).distinct().collect(Collectors.toList());
if (store_o2o_flag_row.size() > 1) { if (storeO2oFlagRow.size() > 1) {
throw new ApiException(I18nUtil._("请分店铺下单!")); throw new ApiException(I18nUtil._("请分店铺下单!"));
} }
} }
} }
// 添加订单关键方法 // 添加保存订单关键方法
List<String> order_id_row = addOrder(cart_data, true, false, null); List<String> orderIdRow = addOrder(cartData, true, false, null);
// 最终应付金额 // 最终应付金额
BigDecimal orderSelMoneyAmount = Convert.toBigDecimal(cart_data.get("orderSelMoneyAmount")); BigDecimal orderSelMoneyAmount = Convert.toBigDecimal(cartData.get("orderSelMoneyAmount"));
if (CollUtil.isNotEmpty(order_id_row) && ObjectUtil.compare(orderSelMoneyAmount, BigDecimal.ZERO) <= 0) { if (CollUtil.isNotEmpty(orderIdRow) && ObjectUtil.compare(orderSelMoneyAmount, BigDecimal.ZERO) <= 0) {
// 处理订单支付成功 // 处理订单支付成功
Map notify_row = new HashMap(); Map notifyRow = new HashMap();
notify_row.put("store_id", 0); // 所属店铺 notifyRow.put("store_id", 0); // 所属店铺
notify_row.put("chain_id", 0); // 所属门店 notifyRow.put("chain_id", 0); // 所属门店
notify_row.put("payment_channel_id", StateCode.PAYMENT_MONEY); // 余额支付 notifyRow.put("payment_channel_id", StateCode.PAYMENT_MONEY); // 余额支付
notify_row.put("order_id", order_id_row); // 所属店铺 notifyRow.put("order_id", orderIdRow); // 所属店铺
// todo 支付完成后[包含充值及订单支付],异步通知商城,更新订单状态 // todo 支付完成后[包含充值及订单支付],异步通知商城,更新订单状态
} }
cart_data.put("order_id", order_id_row); cartData.put("order_id", orderIdRow);
// BigDecimal packingFee = BigDecimal.ZERO; // BigDecimal packingFee = BigDecimal.ZERO;
// if (1 == 1) { // if (1 == 1) {
// cart_data.put("packing_fee", packingFee); // cartData.put("packing_fee", packingFee);
// } // }
// 判断是否拼团购买 // 判断是否拼团购买
if (gb_id != null) { if (gbId != null) {
QueryWrapper<ShopActivityGroupbookingHistory> historyQueryWrapper = new QueryWrapper<>(); QueryWrapper<ShopActivityGroupbookingHistory> historyQueryWrapper = new QueryWrapper<>();
historyQueryWrapper.eq("order_id", order_id_row.get(0)); historyQueryWrapper.eq("order_id", orderIdRow.get(0));
ShopActivityGroupbookingHistory ag_row = groupbookingHistoryService.findOne(historyQueryWrapper); ShopActivityGroupbookingHistory agRow = groupbookingHistoryService.findOne(historyQueryWrapper);
if (ObjectUtil.isNotEmpty(ag_row) && CheckUtil.isNotEmpty(ag_row.getGb_id())) { if (ObjectUtil.isNotEmpty(agRow) && CheckUtil.isNotEmpty(agRow.getGb_id())) {
cart_data.put("gb_id", ag_row.getGb_id()); cartData.put("gb_id", agRow.getGb_id());
} }
} }
// 判断是否砍价购买 // 判断是否砍价购买
if (ac_id != null) { if (acId != null) {
} }
PayUserResource user_res_row = payService.getPayUserResource(user_id); PayUserResource userResRow = payService.getPayUserResource(userId);
if (user_res_row != null) { if (userResRow != null) {
cart_data.put("user_money", user_res_row.getUser_money()); cartData.put("user_money", userResRow.getUser_money());
cart_data.put("user_points", user_res_row.getUser_points()); cartData.put("user_points", userResRow.getUser_points());
} }
} else { } else {
//未绑定手机返回参数封装,与前端约定该代码代表未绑定手机异常77011 //未绑定手机返回参数封装,与前端约定该代码代表未绑定手机异常77011
@ -1606,14 +1607,14 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
} }
// 优惠券使用提醒 // 优惠券使用提醒
List user_voucher_ids = Convert.toList(cart_data.get("user_voucher_ids")); List userVoucherIds = Convert.toList(cartData.get("user_voucher_ids"));
if (CollUtil.isNotEmpty(user_voucher_ids)) { if (CollUtil.isNotEmpty(userVoucherIds)) {
String message_id = "the-use-of-vouchers-to-remind"; String messageId = "the-use-of-vouchers-to-remind";
Map args = new HashMap(); Map args = new HashMap();
messageService.sendNoticeMsg(user_id, 0, message_id, args); messageService.sendNoticeMsg(userId, 0, messageId, args);
} }
return CommonResult.success(cart_data, I18nUtil._("下单成功!")); return CommonResult.success(cartData, I18nUtil._("下单成功!"));
} }
/** /**
@ -6324,7 +6325,7 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
// 将积分换成钱 // 将积分换成钱
Float sp_vaue_rate = accountBaseConfigService.getConfig("sp_vaue_rate", 0.01f); Float sp_vaue_rate = accountBaseConfigService.getConfig("sp_vaue_rate", 0.01f);
BigDecimal order_resource_ext2_need_money = NumberUtil.mul(order_resource_ext2_need, sp_vaue_rate); BigDecimal order_resource_ext2_need_money = NumberUtil.mul(order_resource_ext2_need, sp_vaue_rate);
BigDecimal order_money_select_items = Convert.toBigDecimal(store_item.get("order_money_select_items")); BigDecimal order_money_select_items = Convert.toBigDecimal(store_item.get("order_money_select_items")); // 这里应该包含有打包费在里面
store_item.put("order_money_select_items", NumberUtil.add(NumberUtil.max(order_money_select_items, BigDecimal.valueOf(0), order_resource_ext2_need_money))); store_item.put("order_money_select_items", NumberUtil.add(NumberUtil.max(order_money_select_items, BigDecimal.valueOf(0), order_resource_ext2_need_money)));
} }
@ -6337,27 +6338,22 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
// TODO 配送方式5-到店自提10-普通快递16-同城配送 // TODO 配送方式5-到店自提10-普通快递16-同城配送
Integer delivery_type_id = Convert.toInt(checkout_row.get("delivery_type_id")); //StateCode.DELIVERY_TYPE_SAME_CITY; Integer delivery_type_id = Convert.toInt(checkout_row.get("delivery_type_id")); //StateCode.DELIVERY_TYPE_SAME_CITY;
// 店铺统一设置的打包费 // 店铺统一设置的打包费(formatCartRows 方法里计算好的)
BigDecimal packingFee = BigDecimal.ZERO; BigDecimal packingFee = Convert.toBigDecimal(store_item.get("packing_fee"));
if (is_delivery && !is_virtual && delivery_type_id.equals(StateCode.DELIVERY_TYPE_SAME_CITY)) {
packingFee = shopStoreBaseService.getStorePackingFee(_store_id);
if (packingFee.compareTo(new BigDecimal("10")) > 0) {
packingFee = new BigDecimal("10");
}
}
// 打包费 // 打包费
base_row.put("packing_fee", packingFee); base_row.put("packing_fee", packingFee);
BigDecimal voucher_price = Convert.toBigDecimal(order_voucher_row.get("voucher_price")); BigDecimal voucher_price = Convert.toBigDecimal(order_voucher_row.get("voucher_price"));
// 重要应付款金额计算 // 重要应付款金额计算
BigDecimal order_payment_amount = NumberUtil.sub(NumberUtil.add(order_money_select_items, freight, packingFee), voucher_price); BigDecimal order_payment_amount = NumberUtil.sub(NumberUtil.add(order_money_select_items, freight), voucher_price);
order_payment_amount = NumberUtil.sub(order_payment_amount, dedu_price); order_payment_amount = NumberUtil.sub(order_payment_amount, dedu_price);
order_payment_amount = NumberUtil.max(order_payment_amount, BigDecimal.valueOf(0)); order_payment_amount = NumberUtil.max(order_payment_amount, BigDecimal.valueOf(0));
// 订单原价商品金额
base_row.put("order_product_amount", Convert.toBigDecimal(store_item.get("productMoneyOriginGoods"))); base_row.put("order_product_amount", Convert.toBigDecimal(store_item.get("productMoneyOriginGoods")));
// 重要应付款金额计算 //重要应付款金额计算
base_row.put("order_payment_amount", order_payment_amount); base_row.put("order_payment_amount", order_payment_amount);
// 增加汇率 // 增加汇率
@ -6395,7 +6391,7 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
base_row.put("buyer_user_name", buyer_user_name); base_row.put("buyer_user_name", buyer_user_name);
ShopOrderBase baseRow = Convert.convert(ShopOrderBase.class, base_row); ShopOrderBase baseRow = Convert.convert(ShopOrderBase.class, base_row);
// 订单基础信息保存 // 重要订单基础信息保存
boolean flag = saveOrUpdate(baseRow); boolean flag = saveOrUpdate(baseRow);
Integer chain_store_id = chain_row.getStore_id(); Integer chain_store_id = chain_row.getStore_id();
@ -6642,7 +6638,6 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
BigDecimal item_unit_sp = Convert.toBigDecimal(_item.get("item_unit_sp")); BigDecimal item_unit_sp = Convert.toBigDecimal(_item.get("item_unit_sp"));
BigDecimal item_unit_points = Convert.toBigDecimal(_item.get("item_unit_points")); BigDecimal item_unit_points = Convert.toBigDecimal(_item.get("item_unit_points"));
BigDecimal item_share_redemption = BigDecimal.ZERO; BigDecimal item_share_redemption = BigDecimal.ZERO;
// 均分优惠券 // 均分优惠券
@ -6673,7 +6668,7 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
}*/ }*/
// 需要ext1但是ext1不足 将ext1变为money使用 将需要的积分订单均分 // 需要ext1但是ext1不足 将ext1变为money使用 将需要的积分订单均分
BigDecimal tmp_rate = BigDecimal.ZERO; BigDecimal tmp_rate;
if (CheckUtil.isNotEmpty(order_resource_ext1)) { if (CheckUtil.isNotEmpty(order_resource_ext1)) {
if (ObjectUtil.compare(order_resource_ext1, order_resource_ext1_use) > 0) { if (ObjectUtil.compare(order_resource_ext1, order_resource_ext1_use) > 0) {
tmp_rate = NumberUtil.div(order_resource_ext1_use, order_resource_ext1); tmp_rate = NumberUtil.div(order_resource_ext1_use, order_resource_ext1);
@ -7501,7 +7496,10 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
String order_heka = (String) checkout_row.get("order_heka"); String order_heka = (String) checkout_row.get("order_heka");
String invoice_company_code = (String) checkout_row.get("invoice_company_code"); String invoice_company_code = (String) checkout_row.get("invoice_company_code");
JSONObject order_message = (JSONObject) ObjectUtil.defaultIfNull(cart_data.get("order_message"), new JSONObject()); JSONObject order_message = (JSONObject) ObjectUtil.defaultIfNull(cart_data.get("order_message"), new JSONObject());
BigDecimal _order_money_select_items = Convert.toBigDecimal(store_item.get("order_money_select_items"));
BigDecimal _order_money_select_items = Convert.toBigDecimal(store_item.get("order_money_select_items")); // 包含了打包费需要减去
_order_money_select_items = NumberUtil.sub(_order_money_select_items, packingFee); // 减去打包费
Map _item = item_items.get(item_items.size() - 1); Map _item = item_items.get(item_items.size() - 1);
BigDecimal points_amount = Convert.toBigDecimal(_item.get("points_amount")); BigDecimal points_amount = Convert.toBigDecimal(_item.get("points_amount"));
BigDecimal activityDiscountMoney = Convert.toBigDecimal(store_item.get("activityDiscountMoney")); //店铺非单品优惠总额 BigDecimal activityDiscountMoney = Convert.toBigDecimal(store_item.get("activityDiscountMoney")); //店铺非单品优惠总额
@ -7529,7 +7527,7 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
data_row.setInvoice_company_code(StrUtil.isNotBlank(invoice_company_code) ? invoice_company_code : ""); // 发票信息 data_row.setInvoice_company_code(StrUtil.isNotBlank(invoice_company_code) ? invoice_company_code : ""); // 发票信息
data_row.setOrder_message((String) order_message.get(StrUtil.toString(base_row.get("store_id")))); // 买家订单留言 data_row.setOrder_message((String) order_message.get(StrUtil.toString(base_row.get("store_id")))); // 买家订单留言
data_row.setOrder_item_amount(_order_money_select_items); // 商品总价格/商品金额, 不包含运费含打包费 data_row.setOrder_item_amount(_order_money_select_items); // 商品总价格/商品金额, 不包含运费含打包费
data_row.setOrder_adjust_fee(BigDecimal.valueOf(0)); // 手工调整费用店铺优惠 data_row.setOrder_adjust_fee(BigDecimal.valueOf(0)); // 手工调整费用店铺优惠
data_row.setOrder_points_fee(2 == cart_type_id ? points_amount : BigDecimal.valueOf(0)); // 积分费用, 只考虑每次兑换一个此处直接复用item变量反正只有一个 data_row.setOrder_points_fee(2 == cart_type_id ? points_amount : BigDecimal.valueOf(0)); // 积分费用, 只考虑每次兑换一个此处直接复用item变量反正只有一个
// 积分抵扣费用 是否采用负数 // 积分抵扣费用 是否采用负数
@ -7543,6 +7541,7 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
// base_row 中获取应付款 order_payment_amount计算平台和代理商的总计分账金额 // base_row 中获取应付款 order_payment_amount计算平台和代理商的总计分账金额
BigDecimal split_amount_from = NumberUtil.sub(order_payment_amount, _freight, packingFee); BigDecimal split_amount_from = NumberUtil.sub(order_payment_amount, _freight, packingFee);
// 计算平台费
BigDecimal platform_fee = calculatePlatformAndAgentShareAmount(Convert.toInt(base_row.get("store_id")), split_amount_from); BigDecimal platform_fee = calculatePlatformAndAgentShareAmount(Convert.toInt(base_row.get("store_id")), split_amount_from);
data_row.setTotal_separate_value(platform_fee); // 从拉卡拉分账给平台和代理商的总计分账金额 data_row.setTotal_separate_value(platform_fee); // 从拉卡拉分账给平台和代理商的总计分账金额
data_row.setPlatform_fee(platform_fee); data_row.setPlatform_fee(platform_fee);
@ -7785,7 +7784,7 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
throw new ApiException(e.getMessage()); throw new ApiException(e.getMessage());
} }
cart_data.put("orderSelMoneyAmount", order_sel_money_amount); cart_data.put("orderSelMoneyAmount", order_sel_money_amount); // 总计支付金额
cart_data.put("orderSelPointsAmount", order_sel_points_amount); cart_data.put("orderSelPointsAmount", order_sel_points_amount);
cart_data.put("orderSelSpAmount", order_sel_sp_amount); cart_data.put("orderSelSpAmount", order_sel_sp_amount);
@ -9093,22 +9092,22 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
} }
try { try {
// 获取平台和代理商的分账比例例如 5 表示 5% // 获取店铺的分账比例例如 5 表示 5%
BigDecimal platformAgentSplitRatio = shopStoreBaseService.getStoreSplitRatio(storeId, false); BigDecimal storeSplitRatio = shopStoreBaseService.getStoreSplitRatio(storeId, false);
if (platformAgentSplitRatio == null) { if (storeSplitRatio == null) {
logger.warn("获取店铺分账比例失败storeId: {}", storeId); logger.warn("获取店铺分账比例失败storeId: {}", storeId);
return BigDecimal.ZERO; return BigDecimal.ZERO;
} }
// 确保比例在合理范围 [0, 100] // 确保比例在合理范围 [0, 100]
platformAgentSplitRatio = platformAgentSplitRatio.max(BigDecimal.ZERO).min(new BigDecimal("100")); storeSplitRatio = storeSplitRatio.max(BigDecimal.ZERO).min(new BigDecimal("100"));
// 分账金额 = 支付金额 × 平台和代理商分账比例 ÷ 100 将百分比转换为小数 // 分账金额 = 支付金额 × 平台和代理商分账比例 ÷ 100 将百分比转换为小数
BigDecimal result = pendingAmount.multiply(platformAgentSplitRatio) BigDecimal result = pendingAmount.multiply(new BigDecimal("100").subtract(storeSplitRatio))
.divide(new BigDecimal("100"), 2, RoundingMode.HALF_DOWN); // 保留两位小数 .divide(new BigDecimal("100"), 2, RoundingMode.HALF_DOWN); // 保留两位小数
logger.debug("计算分账金额: storeId={}, pendingAmount={}, ratio={}, result={}", logger.debug("计算分账金额: storeId={}, pendingAmount={}, ratio={}, result={}",
storeId, pendingAmount, platformAgentSplitRatio, result); storeId, pendingAmount, storeSplitRatio, result);
return result; return result;

View File

@ -33,7 +33,7 @@ public interface ShopUserCartService extends IBaseService<ShopUserCart> {
Map getLists(Integer store_id, Integer chain_id, Integer page, Integer rows); Map getLists(Integer store_id, Integer chain_id, Integer page, Integer rows);
/** /**
* 读取购物车 * 读取购物车分页
* *
* @param queryWrapper * @param queryWrapper
* @param page * @param page
@ -42,6 +42,14 @@ public interface ShopUserCartService extends IBaseService<ShopUserCart> {
*/ */
Map getLists(QueryWrapper<ShopUserCart> queryWrapper, Integer page, Integer rows); Map getLists(QueryWrapper<ShopUserCart> queryWrapper, Integer page, Integer rows);
/**
* 读取购物车(不分页)
*
* @param queryWrapper
* @return
*/
Map getLists(QueryWrapper<ShopUserCart> queryWrapper);
/** /**
* 修改购物车数量 * 修改购物车数量
* *

View File

@ -1216,6 +1216,7 @@ public class ShopUserCartServiceImpl extends BaseServiceImpl<ShopUserCartMapper,
* @param rows 每页显示记录数 * @param rows 每页显示记录数
* @return * @return
*/ */
@Override
@Transactional @Transactional
public Map getLists(QueryWrapper<ShopUserCart> queryWrapper, Integer page, Integer rows) { public Map getLists(QueryWrapper<ShopUserCart> queryWrapper, Integer page, Integer rows) {
Page<ShopUserCart> userCartPage = lists(queryWrapper, page, rows); Page<ShopUserCart> userCartPage = lists(queryWrapper, page, rows);
@ -1229,6 +1230,7 @@ public class ShopUserCartServiceImpl extends BaseServiceImpl<ShopUserCartMapper,
* @param queryWrapper 查询条件 * @param queryWrapper 查询条件
* @return * @return
*/ */
@Override
@Transactional @Transactional
public Map getLists(QueryWrapper<ShopUserCart> queryWrapper) { public Map getLists(QueryWrapper<ShopUserCart> queryWrapper) {
List<ShopUserCart> cart_rows = find(queryWrapper); List<ShopUserCart> cart_rows = find(queryWrapper);
@ -2287,7 +2289,7 @@ public class ShopUserCartServiceImpl extends BaseServiceImpl<ShopUserCartMapper,
} }
// 店铺的打包费 // 店铺的打包费
logger.info("开始确认店铺打包费"); // logger.info("开始确认店铺打包费");
BigDecimal packingFee = getStorePackingFee(storeId, isVirtualOrder, Convert.toInt(storeInfo.get("delivery_type_id"))); // 商家打包费 BigDecimal packingFee = getStorePackingFee(storeId, isVirtualOrder, Convert.toInt(storeInfo.get("delivery_type_id"))); // 商家打包费
storeInfo.put("packing_fee", packingFee); storeInfo.put("packing_fee", packingFee);
@ -2336,9 +2338,7 @@ public class ShopUserCartServiceImpl extends BaseServiceImpl<ShopUserCartMapper,
checkoutResult.put("orderSelPointsAmount", totalPointsAmount); checkoutResult.put("orderSelPointsAmount", totalPointsAmount);
checkoutResult.put("orderSelSpAmount", totalPromotionAmount); checkoutResult.put("orderSelSpAmount", totalPromotionAmount);
checkoutResult.put("order_rebate_amount", totalRebateAmount); checkoutResult.put("order_rebate_amount", totalRebateAmount);
checkoutResult.put("totalPackingFee", totalPackingFee); // 多个店铺总计打包费
// 多个店铺总计打包费
checkoutResult.put("totalPackingFee", totalPackingFee);
if (CollUtil.isNotEmpty(storeInfoList)) { if (CollUtil.isNotEmpty(storeInfoList)) {
checkoutResult.put("items", storeInfoList); checkoutResult.put("items", storeInfoList);