Prechádzať zdrojové kódy

APP下单流程调整

FengChaoYu 1 mesiac pred
rodič
commit
4cadf318da

+ 9 - 26
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/bean/order/OrderBuyBean.java

@@ -8,6 +8,7 @@ import lombok.Data;
 
 import javax.validation.constraints.NotEmpty;
 import java.math.BigDecimal;
+import java.util.Date;
 import java.util.List;
 
 @ApiModel
@@ -15,56 +16,38 @@ import java.util.List;
 public class OrderBuyBean {
     @ApiModelProperty("用户id")
     private String userId;
+    @ApiModelProperty("提货仓库id")
+    private String storageId;
+    @ApiModelProperty("提货方式")
+    private String takeGoodsType;
     @ApiModelProperty("我的优惠券id")
     private String userCouponId;
     @ApiModelProperty("收货地址id")
     private String userAddressId;
-    @ApiModelProperty("是否代客下单")
-    private Boolean proxyUser = false;
     @ApiModelProperty("买家留言")
     private String buyerMsg;
-    @ApiModelProperty("兑换码")
-    private String exchangeCode;
 
     @ApiModelProperty("购物车")
     public List<BuyGood> buyGoods;
 
-    @ApiModelProperty("申请优惠的订单号")
-    private String orderId;
-    @ApiModelProperty("申请优惠价格")
-    private BigDecimal applyAmount;
-    @ApiModelProperty("申请优惠备注")
-    private String applyRemark;
-
-    @ApiModelProperty("套购商品id(如果是套购商品必传这个)")
-    private String goodsPackageId;
-
     @ApiModelProperty("工单派单方式 自卖自装/当地安装")
     private String dispatchType;
 
     @ApiModelProperty("wechat pay")
     private Boolean wechatPay = true;
-    private Boolean h5Pay ;
 
     @ApiModelProperty("WECHAT=微信支付   STORE = 到店支付")
     private String payTypeId = PayTypeEnum.WECHAT.getKey();
 
-
     @ApiModelProperty("是否小程序支付")
     private Boolean miniPay ;
 
     @ApiModelProperty("小程序支付openId")
     private String openId ;
 
-
-    @ApiModelProperty("是否以旧换新")
-    private String isOld;
-
-
-
-    @ApiModelProperty("回收信息明细")
-    private OrderOldProductAdd orderOldProductAdds;
-
-
+    @ApiModelProperty("预约提货开始时间")
+    private Date appointmentPickStartTime;
+    @ApiModelProperty("预约提货结束时间")
+    private Date appointmentPickEndTime;
 
 }

+ 0 - 3
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/bean/order/OrderDetailBean.java

@@ -22,7 +22,4 @@ public class OrderDetailBean extends OrderInfo {
     private Boolean isShareOrder = false;
 
 
-    @ApiModelProperty("回收信息明细")
-    private List<OrderOldProductDTO> orderOldProductDTOList;
-
 }

+ 7 - 12
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/controller/common/CommonController.java

@@ -45,15 +45,6 @@ import java.util.UUID;
 @RequestMapping(value = "/common", produces = "application/json; charset=utf-8")
 public class CommonController {
 
-//    @Value("${wechat.cp.corpId}")
-//    private String corpId;
-//    @Value("${work.token}")
-//    private String workToken;
-//    @Value("${work.encodingAesKey}")
-//    private String encodingAesKey;
-//    @Autowired
-//    FucaiLogic fucaiLogic;
-
     @Autowired
     CommonLogic commonLogic;
     @Autowired
@@ -62,11 +53,8 @@ public class CommonController {
     OrderTaxService orderTaxService;
     @Autowired
     RedisUtil redisUtil;
-
     @Resource
     CarouselMapLogic carouselMapLogic;
-//    @Autowired
-//    WechatLogic wechatLogic;
 
     @Autowired
     OrderInfoService orderInfoService;
@@ -234,4 +222,11 @@ public class CommonController {
         return wechatLogic.getMpQrcode(userId, companyWechatId);
     }
 
+    @PostMapping("/order/pick/time/list")
+    @ApiParam(value ="列表")
+    public ResponseHelper<List<OrderPickTimeConfig>> orderPickTimeList() {
+        List<OrderPickTimeConfig> list = commonLogic.orderPickTimeList();
+        return ResponseHelper.success(list);
+    }
+
 }

+ 22 - 0
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/enums/TakeGoodsTypeEnum.java

@@ -0,0 +1,22 @@
+package com.gree.mall.miniapp.enums;
+
+import com.baomidou.mybatisplus.annotation.EnumValue;
+import com.fasterxml.jackson.annotation.JsonValue;
+import com.gree.mall.miniapp.enums.base.BaseEnum;
+import lombok.AccessLevel;
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+
+@Getter
+@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
+public enum TakeGoodsTypeEnum implements BaseEnum {
+    Z("0","自提"),
+    Y("1","邮寄"),
+    ;
+
+    @EnumValue
+    @JsonValue
+    private final String key;
+
+    private final String remark;
+}

+ 5 - 5
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/logic/FreightLogic.java

@@ -43,11 +43,11 @@ public class FreightLogic {
 
     public BigDecimal getFreightAmountV2(OrderBuyBean freightBean, HttpServletRequest request) throws RemoteServiceException {
         CurrentCompanyWechat currentCompanyWechat = commonLogic.getCurrentCompanyWechat(request);
-        if(StringUtils.isNotBlank(freightBean.getUserAddressId())) {
-            UserAddress userAddress = userAddressService.getById(freightBean.getUserAddressId());
-            BigDecimal freightAmountV2 = this.getFreightAmountV2(userAddress.getProvince(), userAddress.getCity(), userAddress.getArea(), freightBean.getBuyGoods(),currentCompanyWechat);
-            return freightAmountV2;
-        }
+//        if(StringUtils.isNotBlank(freightBean.getUserAddressId())) {
+//            UserAddress userAddress = userAddressService.getById(freightBean.getUserAddressId());
+//            BigDecimal freightAmountV2 = this.getFreightAmountV2(userAddress.getProvince(), userAddress.getCity(), userAddress.getArea(), freightBean.getBuyGoods(),currentCompanyWechat);
+//            return freightAmountV2;
+//        }
         return BigDecimal.valueOf(0);
     }
 

+ 10 - 0
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/logic/common/CommonLogic.java

@@ -1,5 +1,6 @@
 package com.gree.mall.miniapp.logic.common;
 
+import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.http.HttpUtil;
 import com.alibaba.fastjson.JSON;
@@ -24,6 +25,7 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import java.io.BufferedOutputStream;
 import java.io.IOException;
@@ -51,6 +53,8 @@ public class CommonLogic {
     RedisUtil redisUtil;
     @Autowired
     UserWaitService userWaitService;
+    @Resource
+    OrderPickTimeConfigService orderPickTimeConfigService;
     @Value("${spring.profiles.active}")
     private String profiles;
     @Value("${inf.url}")
@@ -362,4 +366,10 @@ public class CommonLogic {
         return infUrl;
     }
 
+    public List<OrderPickTimeConfig> orderPickTimeList() {
+        CurrentCompanyWechat currentCompanyWechat = getCurrentCompanyWechat();
+        return orderPickTimeConfigService.lambdaQuery()
+                .eq(OrderPickTimeConfig::getCompanyWechatId, currentCompanyWechat.getCompanyWechatId())
+                .list();
+    }
 }

+ 104 - 180
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/logic/order/OrderLogic.java

@@ -45,6 +45,7 @@ import org.springframework.integration.redis.util.RedisLockRegistry;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
@@ -145,31 +146,52 @@ public class OrderLogic {
 
     @Autowired
     GoodsCategoryService goodsCategoryService;
+    @Resource
+    GoodsMaterialStorageService goodsMaterialStorageService;
+    @Resource
+    StorageService storageService;
 
 
     /**
      * 立即购买
      */
     @Transactional
-    public PayDetail buy(OrderBuyBean orderBuyBean,HttpServletRequest request) throws Exception {
+    public PayDetail buy(OrderBuyBean orderBuyBean, HttpServletRequest request) throws Exception {
         String ip = IpUtil.getIpAddr(request);
-        if(StringUtils.isBlank(orderBuyBean.getUserAddressId())){
-            throw new RemoteServiceException(1100,"请选择收货地址");
+        if (StringUtils.isBlank(orderBuyBean.getStorageId())) {
+            throw new RemoteServiceException(1100, "缺少仓库");
+        }
+        if (StringUtils.isBlank(orderBuyBean.getPayTypeId())) {
+            throw new RemoteServiceException(1100, "请选择支付方式");
+        }
+        if (StringUtils.isBlank(orderBuyBean.getUserAddressId())
+                && orderBuyBean.getPayTypeId().equals(PayTypeEnum.WECHAT.getKey())
+                && orderBuyBean.getTakeGoodsType().equals(TakeGoodsTypeEnum.Y.getKey())) {
+            throw new RemoteServiceException(1100, "请选择收货地址");
+        }
+        if (StringUtils.isBlank(orderBuyBean.getTakeGoodsType())) {
+            throw new RemoteServiceException(1100, "请选择提货方式");
+        }
+        if (orderBuyBean.getTakeGoodsType().equals(TakeGoodsTypeEnum.Z.getKey())
+                && (Objects.isNull(orderBuyBean.getAppointmentPickStartTime())
+                || Objects.isNull(orderBuyBean.getAppointmentPickEndTime()))) {
+            throw new RemoteServiceException(1100, "请选择提货时间");
         }
         CurrentCompanyWechat currentCompanyWechat = commonLogic.getCurrentCompanyWechat(request);
+
+        final Storage storage = storageService.getById(orderBuyBean.getStorageId());
         //订单
         OrderInfo orderInfo = new OrderInfo();
         String orderId = currentCompanyWechat.getOrderPrefix() + IdWorker.getIdStr();
         orderInfo.setOrderId(orderId);
+        orderInfo.setTakeGoodsType(orderBuyBean.getTakeGoodsType());
+        orderInfo.setPickStorageId(storage.getStorageId());
+        orderInfo.setPickStorageName(storage.getStorageName());
+        orderInfo.setAppointmentPickStartTime(orderBuyBean.getAppointmentPickStartTime());
+        orderInfo.setAppointmentPickEndTime(orderBuyBean.getAppointmentPickEndTime());
         //购买人
-        String userId = currentCompanyWechat.getUserId();
         User user = currentCompanyWechat.getUser();
-        //分销员
-        String serviceId = user.getServiceId();
-        if(user.getType().equals(UserTypeEnum.SERVICE.toString())) {
-            serviceId = user.getUserId();
-        }
-        User service = userService.getById(serviceId);
+
         //商品总金额(不包含运费,优惠金额,非实际支付金额)
         BigDecimal totalPrice = BigDecimal.valueOf(0);
         //商品实际支付总金额
@@ -178,33 +200,25 @@ public class OrderLogic {
         BigDecimal totalFreight = BigDecimal.valueOf(0);
         //订单标题
         String orderTitle = "";
-        //分账金额
-        BigDecimal shareAmount = BigDecimal.valueOf(0);
-        //非团购商品的分账金额
-        BigDecimal notPromotionShareAmount = BigDecimal.valueOf(0);
         //总数量
         Integer totalNum = 0;
-        //兑换码
-        String exchangeCode = orderBuyBean.getExchangeCode();
-        //是否有使用了礼品码的商品
-        Boolean hasGiftCode = false;
-        //收获地址
-        UserAddress userAddress = userAddressService.getById(orderBuyBean.getUserAddressId());
-        //团长id
-        String promotionGroupUserId = "";
-        String orderPromotionGroupId = "";
+
+        // 收货地址
+        UserAddress userAddress = null;
+        if (StringUtils.isNotBlank(orderBuyBean.getUserAddressId())
+                && orderBuyBean.getPayTypeId().equals(PayTypeEnum.WECHAT.getKey())
+                && orderBuyBean.getTakeGoodsType().equals(TakeGoodsTypeEnum.Y.getKey())) {
+            userAddress = userAddressService.getById(orderBuyBean.getUserAddressId());
+        }
+
         List<String> goodsIds = orderBuyBean.getBuyGoods().stream().map(BuyGood::getGoodsId).collect(Collectors.toList());
-        //满件折扣活动
-        Boolean promotionFullPiece = false;
-        String promotionFullPieceId = "";
-        String promotionFullPieceRemark = "";
-        List<PromotionFullPieceItem> promotionFullPieceItems = promotionFullPieceLogic.getItems();
+
 
         //购物车ids
         List<String> shoppingCartIds = orderBuyBean.getBuyGoods().stream().map(BuyGood::getShoppingCartId).collect(Collectors.toList());
         //如果用户存在,则判断是否为业务员,并更新相关信息
         if (!user.getStatus()) {
-            throw new RemoteServiceException(1100,"用户已被冻结");
+            throw new RemoteServiceException(1100, "用户已被冻结");
         }
 
         //这里面会处理各个活动对单价以及佣金金额的处理
@@ -213,16 +227,13 @@ public class OrderLogic {
         //订单详情
         List<OrderDetail> orderDetails = new ArrayList<>();
         for (BuyGood buyGood : buyGoods) {
-            if(StringUtils.isBlank(orderPromotionGroupId)) {
-                orderPromotionGroupId = buyGood.getPromotionGroupId();
-            }
             //商品
             Goods goods = buyGood.getGoods();
-            if(!goods.getStatus()){
-               throw new RemoteServiceException("存在已下架商品:"+goods.getGoodsName());
+            if (!goods.getStatus()) {
+                throw new RemoteServiceException("存在已下架商品:" + goods.getGoodsName());
             }
             //处理库存并返回商品规格
-            GoodsSpec goodsSpec = this.stock(buyGood.getGoodsSpecId(), goods.getGoodsName(), buyGood.getNum());
+            GoodsSpec goodsSpec = this.stock(buyGood.getGoodsSpecId(), goods.getGoodsName(), buyGood.getNum(), orderBuyBean.getStorageId());
 
             String goodsId = goodsSpec.getGoodsId();
             String goodsSpecId = goodsSpec.getGoodsSpecId();
@@ -232,7 +243,6 @@ public class OrderLogic {
             BigDecimal goodsSecPrice = buyGood.getPrice();
             String catagoryId = goods.getCategoryId();
             String userCouponId = orderBuyBean.getUserCouponId();
-            BigDecimal cutAmount = new BigDecimal("0");
 
             GoodsMaterial gm = goodsMaterialService.getById(goodsSpec.getGoodsCode());
 
@@ -254,7 +264,7 @@ public class OrderLogic {
 
             if (StringUtils.isNotBlank(catagoryId)) {
                 GoodsCategory goodsCategory = goodsCategoryLogic.queryById(catagoryId);
-                if(goodsCategory != null) {
+                if (goodsCategory != null) {
                     orderDetail.setMainNumber(goodsCategory.getMainNumber());
                     orderDetail.setMainName(goodsCategory.getMainName());
                     orderDetail.setSmallNumber(goodsCategory.getSmallNumber());
@@ -276,7 +286,7 @@ public class OrderLogic {
             orderDetail.setInsideNum(insideQty * orderDetail.getNum());
             orderDetail.setOutNum(outQty * orderDetail.getNum());
             orderDetail.setPartNum(partsQty * orderDetail.getNum());
-            if(gm != null) {
+            if (gm != null) {
                 orderDetail.setGoodsMaterialId(gm.getId());
                 orderDetail.setGoodsMaterialName(gm.getGoodsName());
                 orderDetail.setGoodsSpecValue(gm.getSpecsName());
@@ -288,7 +298,7 @@ public class OrderLogic {
             orderDetail.setSmallName(goodsSpec.getSmallName());
             orderDetail.setFlag(1);
 
-            BigDecimal freightAmountItem = this.getFreightAmountItem(userAddress.getProvince(), userAddress.getCity(), userAddress.getArea(), buyGood,currentCompanyWechat);
+            BigDecimal freightAmountItem = Objects.nonNull(userAddress) ? this.getFreightAmountItem(userAddress.getProvince(), userAddress.getCity(), userAddress.getArea(), buyGood, currentCompanyWechat) : BigDecimal.valueOf(0);
             orderDetail.setFreight(freightAmountItem);
 
             orderDetails.add(orderDetail);
@@ -305,53 +315,40 @@ public class OrderLogic {
 
         //生成订单
         orderInfo.setIsAllVr(orderDetails.stream().filter(v -> !v.getIsVr()).count() == 0);
-        //orderInfo.setIsAddCorp(yrzqw > 0);
+
         orderInfo.setBuyerMsg(orderBuyBean.getBuyerMsg());
+
         orderInfo.setOrderStatus(OrderStatusEnum.NOPAY.toString());
+        // 如果是到店支付,订单改为待确认
+        if (orderBuyBean.getPayTypeId().equals(PayTypeEnum.STORE.getKey())) {
+            orderInfo.setOrderStatus(OrderStatusEnum.DQR.toString());
+        }
         orderInfo.setUserId(user.getUserId());
         orderInfo.setUserName(user.getNickName());
         orderInfo.setPhone(user.getMobile());
-        orderInfo.setUserAddressId(userAddress.getUserAddressId());
-        orderInfo.setReceUserName(userAddress.getName());
-        orderInfo.setReceAddress(userAddress.getAddress());
-        orderInfo.setRecePhone(userAddress.getPhone());
-        orderInfo.setProvince(userAddress.getProvince());
-        orderInfo.setCity(userAddress.getCity());
-        orderInfo.setArea(userAddress.getArea());
-        orderInfo.setStreet(userAddress.getStreet());
-        orderInfo.setHouseNo(userAddress.getHouseNo());
+        if (Objects.nonNull(userAddress)) {
+            orderInfo.setUserAddressId(userAddress.getUserAddressId());
+            orderInfo.setReceUserName(userAddress.getName());
+            orderInfo.setReceAddress(userAddress.getAddress());
+            orderInfo.setRecePhone(userAddress.getPhone());
+            orderInfo.setProvince(userAddress.getProvince());
+            orderInfo.setCity(userAddress.getCity());
+            orderInfo.setArea(userAddress.getArea());
+            orderInfo.setStreet(userAddress.getStreet());
+            orderInfo.setHouseNo(userAddress.getHouseNo());
+        }
         orderInfo.setCreateTime(new Date());
         orderInfo.setFreight(totalFreight);
         orderInfo.setTotalAmount(totalPrice);
         orderInfo.setPayAmount(payAmount);
         orderInfo.setPayTypeId(orderBuyBean.getPayTypeId());
-        orderInfo.setPayType(BaseEnum.keyToEnum(PayTypeEnum.class,orderBuyBean.getPayTypeId()).getRemark());
+        orderInfo.setPayType(BaseEnum.keyToEnum(PayTypeEnum.class, orderBuyBean.getPayTypeId()).getRemark());
         //检查优惠券的使用合法性
-        //if(!isPromotion && !hasGiftCode) {
-            UserCouponBean userCoupon = couponLogic.check(orderBuyBean.getUserCouponId(), totalPrice, goodsIds,true);
-//            if(userCoupon == null){
-//                throw new RemoteServiceException("优惠券暂不可用,请联系相关人员");
-//            }
-            if (userCoupon != null && this.checkPackageUseCoupon(orderBuyBean.getGoodsPackageId(),userCoupon)) {
-                orderInfo.setDiscountAmount(userCoupon.getCouponValue());
-                orderInfo.setCouponId(userCoupon.getCouponId());
-                orderInfo.setCouponName(userCoupon.getCouponName());
-                orderInfo.setCouponValue(userCoupon.getCouponValue());
-                orderInfo.setUserCouponId(userCoupon.getId());
-
-                //检查是否优惠超过50%,如果超过,拒绝下单
-                BigDecimal divide = totalPrice.divide(userCoupon.getCouponValue(), 3, RoundingMode.HALF_UP);
-                if(divide.doubleValue() < 2){
-                    throw new RemoteServiceException("优惠券抵扣额度不可超订单价格50%");
-                }
+        UserCouponBean userCoupon = couponLogic.check(orderBuyBean.getUserCouponId(), totalPrice, goodsIds, true);
 
-                //扣减优惠券金额
-                orderInfo.setPayAmount(orderInfo.getPayAmount().subtract(orderInfo.getDiscountAmount()));
-            }
-        //}
         orderInfo.setTotalNum(totalNum);
-        if(StringUtils.isNotBlank(orderTitle) && orderTitle.length() > 0) {
-            orderTitle = orderTitle.substring(0,orderTitle.length() - 1);
+        if (StringUtils.isNotBlank(orderTitle) && orderTitle.length() > 0) {
+            orderTitle = orderTitle.substring(0, orderTitle.length() - 1);
             orderInfo.setOrderTitle(orderTitle);
         }
         orderInfo.setTotalProductAmount(totalPrice);
@@ -360,14 +357,14 @@ public class OrderLogic {
         orderInfo.setDispatchType(orderBuyBean.getDispatchType());
 
         //支付金额不可为负数
-        if(orderInfo.getPayAmount().doubleValue() < 0){
+        if (orderInfo.getPayAmount().doubleValue() < 0) {
             throw new RemoteServiceException("优惠金额超出,请联系客服");
         }
 
         //来源
-        if(orderBuyBean.getMiniPay() != null && orderBuyBean.getMiniPay()){
+        if (orderBuyBean.getMiniPay() != null && orderBuyBean.getMiniPay()) {
             orderInfo.setSource(OrderInfoSourceEnum.A.getRemark());
-        }else{
+        } else {
             orderInfo.setSource(OrderInfoSourceEnum.B.getRemark());
         }
 
@@ -378,36 +375,20 @@ public class OrderLogic {
         if (!CollectionUtils.isEmpty(shoppingCartIds)) {
             shoppingCartService.lambdaUpdate().in(ShoppingCart::getShoppingCartId, shoppingCartIds).remove();
         }
-        //代客下单
-        if (orderBuyBean.getProxyUser()) {
-            PayDetail payDetail = new PayDetail();
-            payDetail.setIsPay(false);
-            payDetail.setId(orderInfo.getOrderId());
-            payDetail.setCodeUrl(wechatLogic.getQrcode(QrCodeEnum.ORDER.toString().toLowerCase(Locale.ROOT),
-                    orderInfo.getOrderId(), orderInfo.getUserId(),user.getCompanyWechatId()));
-            return payDetail;
-        }
+
         //调起支付
         String profitSharingFlag = "N";
         BigDecimal zero = new BigDecimal("0.00");
-        if (shareAmount.compareTo(zero) > 0) {
-            profitSharingFlag = "Y";
-        }
 
         PayDetail payDetail = new PayDetail();
         payDetail.setId(orderInfo.getOrderId());
 
-        //if(orderBuyBean.getWechatPay()) {
-        if(!StringUtils.equals(orderBuyBean.getPayTypeId(),PayTypeEnum.STORE.getKey())) {
-            if (orderBuyBean.getH5Pay() != null && orderBuyBean.getH5Pay()) {
-                payDetail = wechatLogic.paymentH5(orderInfo.getOrderId(), orderInfo.getPayAmount(), user.getOpenId(),
-                        profitSharingFlag, ip, user.getCompanyWechatId());
-            } else {
-                payDetail = wechatLogic.payment(orderInfo.getOrderId(), orderInfo.getPayAmount(),
-                        orderBuyBean.getMiniPay() != null && orderBuyBean.getMiniPay() ? orderBuyBean.getOpenId() : user.getOpenId(),
-                        profitSharingFlag, ip, user.getCompanyWechatId(), orderBuyBean.getMiniPay());
-            }
-        }else{
+        if (!StringUtils.equals(orderBuyBean.getPayTypeId(), PayTypeEnum.STORE.getKey())) {
+            payDetail = wechatLogic.payment(orderInfo.getOrderId(), orderInfo.getPayAmount(),
+                    orderBuyBean.getMiniPay() != null && orderBuyBean.getMiniPay() ? orderBuyBean.getOpenId() : user.getOpenId(),
+                    profitSharingFlag, ip, user.getCompanyWechatId(), orderBuyBean.getMiniPay());
+
+        } else {
             payDetail.setIsPay(false);
         }
 
@@ -415,68 +396,10 @@ public class OrderLogic {
         if (!payDetail.getIsPay()) {
             payLogic.payCall(payDetail.getId(), "", orderInfo.getPayAmount());
         }
-        //}
-        return payDetail;
-    }
-
-
-    /**
-     * 处理旧机
-     * @param orderBuyBean
-     * @param orderId
-     * @param yjhxDkFlag
-     * @return
-     */
-    private OrderOldProduct handleOldProduct(OrderBuyBean orderBuyBean,String orderId,Integer yjhxDkFlag){
-        //以旧换新
-        if (orderBuyBean.getOrderOldProductAdds() != null) {
-
-            List<OrderOldProductItem> orderOldProductItems = new ArrayList<>();
-
-            GoodsCategoryItem goodsCategoryItemDto = goodsCategoryItemService.getById(orderBuyBean.getOrderOldProductAdds().getId());
-
-            GoodsCategory goodsCategory = goodsCategoryService.getById(goodsCategoryItemDto.getMainId());
-            GoodsCategory goodsCategorySmall = goodsCategoryService.getById(goodsCategoryItemDto.getSmallId());
-
-            OrderOldProduct orderOldProduct = new OrderOldProduct();
-            this.productCategory(orderOldProduct, goodsCategoryItemDto);
-            orderOldProduct.setId(null);
-            orderOldProduct.setSaleType(1);
-            orderOldProduct.setOrderId(orderId);
-            orderOldProduct.setId(IdWorker.getIdStr());
-            orderOldProduct.setNum(1);
-            orderOldProduct.setYjhxDkFlag(yjhxDkFlag);
-            orderOldProduct.setPrice(goodsCategoryItemDto.getPrice());
-            orderOldProduct.setPayAmount(goodsCategoryItemDto.getPrice());
-
-            orderOldProduct.setMainImg(goodsCategory.getImgUrl());
-            orderOldProduct.setSmallImg(goodsCategorySmall.getImgUrl());
-
-            for (String goodsCategoryItem : orderBuyBean.getOrderOldProductAdds().getItemIds()) {
-                GoodsCategoryItem goodsCategoryItems = goodsCategoryItemService.getById(goodsCategoryItem);
-                OrderOldProductItem orderOldProductItem = this.productCategoryItem(goodsCategoryItems);
-                orderOldProductItem.setId(null);
-                orderOldProductItem.setGoodsCategoryItemId(goodsCategoryItems.getId());
-                orderOldProductItem.setOrderId(orderOldProduct.getOrderId());
-                orderOldProductItem.setOrderOldProductId(orderOldProduct.getId());
-                orderOldProduct.setPayAmount(orderOldProduct.getPayAmount().add(goodsCategoryItems.getPrice()));
-                orderOldProductItems.add(orderOldProductItem);
-            }
-
-            orderOldProductService.lambdaUpdate().eq(OrderOldProduct::getOrderId,orderId).remove();
-            orderOldProductItemService.lambdaUpdate().eq(OrderOldProductItem::getOrderId,orderId).remove();
-            orderOldProductService.save(orderOldProduct);
 
-            if (!org.springframework.util.CollectionUtils.isEmpty(orderOldProductItems)){
-                orderOldProductItemService.saveBatch(orderOldProductItems);
-            }
-
-            return orderOldProduct;
-        }
-        return null;
+        return payDetail;
     }
 
-
     private OrderOldProductItem productCategoryItem(GoodsCategoryItem goodsCategoryItem) {
         OrderOldProductItem orderOldProductItem = BeanUtil.toBean(goodsCategoryItem, OrderOldProductItem.class);
         return orderOldProductItem;
@@ -699,19 +622,6 @@ public class OrderLogic {
         List<OrderOldProduct> listProduce = orderOldProductService.lambdaQuery()
                 .eq(OrderOldProduct::getOrderId, orderId).list();
 
-        List<OrderOldProductDTO> orderOldProductDTOS = new ArrayList<>();
-
-        for (OrderOldProduct orderOldProduct : listProduce) {
-            OrderOldProductDTO orderOldProductDTO = BeanUtil.toBean(orderOldProduct, OrderOldProductDTO.class);
-            List<OrderOldProductItem> orderOldProductItemList = orderOldProductItemService.lambdaQuery()
-                    .eq(OrderOldProductItem::getOrderOldProductId, orderOldProduct.getId()).list();
-            orderOldProductDTO.setItemList(orderOldProductItemList);
-
-            orderOldProductDTOS.add(orderOldProductDTO);
-        }
-
-        orderDetailBean.setOrderOldProductDTOList(orderOldProductDTOS);
-
         return orderDetailBean;
     }
 
@@ -990,17 +900,24 @@ public class OrderLogic {
      * @throws RemoteServiceException
      * @throws InterruptedException
      */
-    private GoodsSpec stock(String goodsSpecId, String goodsName, Integer num) throws RemoteServiceException, InterruptedException {
+    private GoodsSpec stock(String goodsSpecId, String goodsName, Integer num, String storageId) throws RemoteServiceException, InterruptedException {
         Lock obtain = redisLockRegistry.obtain(Constant.RedisPrefix.LOCK_ORDER_STOCK +":"+ goodsSpecId);
         try {
             if (!obtain.tryLock(10, TimeUnit.SECONDS)) {
                 throw new RemoteServiceException("系统繁忙,请稍后再试");
             }
             GoodsSpec goodsSpec = goodsLogic.getGoodsSpecById(goodsSpecId);
-            if (goodsSpec.getStockNum() < num) {
-                throw new RemoteServiceException(1100,goodsName+"库存不足");
+            final GoodsMaterialStorage storage = goodsMaterialStorageService.lambdaQuery()
+                    .eq(GoodsMaterialStorage::getGoodsMaterialId, goodsSpec.getGoodsCode())
+                    .eq(GoodsMaterialStorage::getStorageId, storageId)
+                    .one();
+//            if (goodsSpec.getStockNum() < num) {
+//                throw new RemoteServiceException(1100,goodsName+"库存不足");
+//            }
+            if (Objects.isNull(storage) || storage.getStockQty() < num) {
+                throw new RemoteServiceException(1100, goodsName+"库存不足");
             }
-            goodsSpec.setStockNum(goodsSpec.getStockNum() - num);
+//            goodsSpec.setStockNum(goodsSpec.getStockNum() - num);
             goodsSpec.setSoldNum(goodsSpec.getSoldNum() + num);
             goodsSpec.updateById();
 
@@ -1091,8 +1008,6 @@ public class OrderLogic {
         BigDecimal totalAmount = new BigDecimal(0);
         //总的商品数量
         Integer totalNum = 0;
-        //满件打折金额
-        BigDecimal promotionFullPieceDiscountAmount = BigDecimal.valueOf(0);
 
         OrderAckBean orderAckBean = new OrderAckBean();
         orderAckBean.setDiscountAmount(BigDecimal.valueOf(0));
@@ -1101,11 +1016,23 @@ public class OrderLogic {
         //填充必要参数
         List<BuyGood> buyGoods = this.supplyBuyBoods(orderBuyBean,user);
 
+        final Map<String, Integer> storageMap = goodsMaterialStorageService.lambdaQuery()
+                .eq(GoodsMaterialStorage::getStorageId, orderBuyBean.getStorageId())
+                .in(GoodsMaterialStorage::getGoodsMaterialId, buyGoods.stream().map(v -> v.getGoodsSpec().getGoodsCode()).collect(Collectors.toList()))
+                .list()
+                .stream()
+                .collect(Collectors.toMap(GoodsMaterialStorage::getGoodsMaterialId, GoodsMaterialStorage::getStockQty));
+
         for (BuyGood buyGood : buyGoods) {
 
             Goods goods = buyGood.getGoods();
             GoodsSpec goodsSpec = buyGood.getGoodsSpec();
 
+            final Integer stockQty = storageMap.get(goodsSpec.getGoodsCode());
+            if (Objects.isNull(stockQty) || stockQty <= 0) {
+                throw new RemoteServiceException(goods.getGoodsName() + "商品" + goodsSpec.getSpecValue() + "规格不存在,请重新添加");
+            }
+
             //总购买数量
             totalNum += buyGood.getNum();
 
@@ -1126,9 +1053,6 @@ public class OrderLogic {
         //检查优惠券的使用合法性(团购和礼品卡和兑换码不可使用)
         List<String> goodsIds = buyGoods.stream().map(BuyGood::getGoodsId).collect(Collectors.toList());
         UserCouponBean userCoupon = couponLogic.check(orderBuyBean.getUserCouponId(), totalAmount, goodsIds,false);
-        if (userCoupon != null && this.checkPackageUseCoupon(orderBuyBean.getGoodsPackageId(),userCoupon)) {
-            orderAckBean.setExchangeAmount(userCoupon.getCouponValue());
-        }
 
         if(orderAckBean.getExchangeAmount() == null){
             orderAckBean.setExchangeAmount(BigDecimal.valueOf(0));