fwq
2024-10-10 86a7a078c89a671f9ada908e8f82ebd43d463b18
phi_platform_user/src/main/java/com/hx/phip/service/init/impl/OrderInitServiceImpl.java
@@ -25,6 +25,7 @@
import com.hx.phiappt.model.user.UserCard;
import com.hx.phiappt.model.user.UserCardPay;
import com.hx.phiappt.model.user.UserProjectItem;
import com.hx.phiappt.model.warehouse.PickUpGoodItem;
import com.hx.phiappt.tool.project.ProjectIntegralCashTool;
import com.hx.phiappt.vo.payMethod.PayMethodVo;
import com.hx.phip.config.CustomParameter;
@@ -382,6 +383,85 @@
                orderItemSonHandle(ordersTotal,orderItem,updateUserProject);
            }
        }
        //提货单金额处理
        pickUpOrderHandle(ordersTotal,orderItemList);
    }
    /**关联提货单数据处理*/
    private void pickUpOrderHandle(OrdersTotal ordersTotal, List<OrderItem> orderItemList) {
        if (orderItemList == null || orderItemList.size() == 0) {
            return;
        }
        SqlSentence sqlSentence = new SqlSentence();
        Map<String, Object> sqlMap = new HashMap<>();
        sqlMap.put("orderId", ordersTotal.getId());
        StringBuilder sql = new StringBuilder();
        sql.append(" SELECT * FROM pick_up_good_item AS i ");
        sql.append(" JOIN pick_up_good AS p ON p.id = i.pickUpGoodId ");
        sql.append(" WHERE p.isDel = 0 AND i.isDel = 0 AND p.commonId = #{m.orderId} ");
        sqlSentence.sqlSentence(sql.toString(), sqlMap);
        List<PickUpGoodItem> pickUpGoodItemList = commonService.selectList(PickUpGoodItemMapper.class, sqlSentence);
        if (pickUpGoodItemList == null || pickUpGoodItemList.size() < 1) {
            return;
        }
        //耗材标识,数据
        Map<String, PickUpGoodItem> pickUpGoodItemMap = new HashMap<>();
        for (PickUpGoodItem pickUpGoodItem : pickUpGoodItemList) {
            pickUpGoodItemMap.put(pickUpGoodItem.getConsumablesId(), pickUpGoodItem);
        }
        for (OrderItem orderItem : orderItemList) {
            //商品直接来
            if (OrderItemConstants.TYPE_RETAIL.equals(orderItem.getType())) {
                PickUpGoodItem pickUpGoodItem = pickUpGoodItemMap.get(orderItem.getCommonId());
                if (pickUpGoodItem == null) {
                    continue;
                }
                //查询这个子单分到的钱
                sqlMap.put("typeId", orderItem.getId());
                sqlSentence.sqlSentence("SELECT SUM(actualTotal) AS actualTotal FROM consume_pay_item WHERE isDel = 0 AND typeId = #{m.typeId} ", sqlMap);
                ConsumePayItem consumePayItem = commonService.selectOne(ConsumePayItemMapper.class, sqlSentence);
                sqlMap.put("orderPrice", consumePayItem == null ? BigDecimal.ZERO : consumePayItem.getActualTotal());
                sqlMap.put("id", pickUpGoodItem.getId());
                sqlSentence.sqlSentence("orderPrice = #{m.orderPrice} WHERE id = #{m.id}", sqlMap);
                if (commonService.updateWhere(PickUpGoodItemMapper.class, sqlSentence) != 1) {
                    throw new TipsException("处理提货单金额信息错误");
                }
            } else {
                if (OrderItemConstants.TYPE_PROMOTION.equals(orderItem.getType()) || OrderItemConstants.CARD_BAG.equals(orderItem.getType())) {
                    //促销和卡包查询二级子单
                    sqlMap.put("orderItemId", orderItem.getId());
                    sqlSentence.sqlSentence("SELECT * FROM order_item_source WHERE isDel = 0 AND orderItemId = #{m.orderItemId}", sqlMap);
                    List<OrderItemSon> orderItemSonList = orderItemSonMapper.selectList(sqlSentence);
                    if (orderItemSonList == null || orderItemSonList.size() < 1) {
                        continue;
                    }
                    for (OrderItemSon orderItemSon : orderItemSonList) {
                        PickUpGoodItem pickUpGoodItem = pickUpGoodItemMap.get(orderItemSon.getGoodsId());
                        if (pickUpGoodItem == null) {
                            continue;
                        }
                        //促销
                        if (OrderItemConstants.TYPE_PROMOTION.equals(orderItem.getType())) {
                            //查询这个子单分到的钱
                            sqlMap.put("typeId", orderItemSon.getId());
                            sqlSentence.sqlSentence("SELECT SUM(actualTotal) AS actualTotal FROM consume_pay_item_son WHERE isDel = 0 AND typeId = #{m.typeId} ", sqlMap);
                            ConsumePayItemSon consumePayItemSon = commonService.selectOne(ConsumePayItemSonMapper.class, sqlSentence);
                            sqlMap.put("orderPrice", consumePayItemSon == null ? BigDecimal.ZERO : consumePayItemSon.getActualTotal());
                        } else if (OrderItemConstants.CARD_BAG.equals(orderItem.getType())) {
                            //查询这个卡包单分到的钱
                            sqlMap.put("orderPrice", UserCardTool.orderItemSonMoney(orderItemSon.getId(), commonService));
                        }
                        sqlMap.put("id", pickUpGoodItem.getId());
                        sqlSentence.sqlSentence("orderPrice = #{m.orderPrice} WHERE id = #{m.id}", sqlMap);
                        if (commonService.updateWhere(PickUpGoodItemMapper.class, sqlSentence) != 1) {
                            throw new TipsException("处理提货单金额信息错误");
                        }
                    }
                }
            }
        }
    }
    /**一级订单金额处理*/