浏览代码

feat:1、套餐包制单功能;2、销售订单导入物流添加圆通

caoliqin 1 周之前
父节点
当前提交
16cd3aa5fe

+ 1 - 1
fs-service/src/main/java/com/fs/course/dto/FsOrderDeliveryNoteDTO.java

@@ -16,7 +16,7 @@ public class FsOrderDeliveryNoteDTO {
     @Excel(name = "系统订单号(必填)",width = 20,sort = 1)
     private String orderNumber;
 
-    @Excel(name = "物流公司编号(必填)(SF:顺丰、EMS:邮政、ZTO:中通、JD:京东、DBL:德邦)",width = 30,sort = 2)
+    @Excel(name = "物流公司编号(必填)(SF:顺丰、EMS:邮政、ZTO:中通、JD:京东、DBL:德邦、YTO:圆通)",width = 30,sort = 2)
     private String deliverySn;
 
     private String deliveryName;

+ 1 - 0
fs-service/src/main/java/com/fs/hisStore/param/FsStoreConfirmPackageIdOrderParam.java

@@ -8,4 +8,5 @@ import lombok.Setter;
 public class FsStoreConfirmPackageIdOrderParam {
     private Long packageId;
     private Long couponUserId;
+    private String createOrderKey;
 }

+ 6 - 0
fs-service/src/main/java/com/fs/hisStore/param/FsStorePackageOrderCreateParam.java

@@ -6,6 +6,7 @@ import lombok.Data;
 import javax.validation.constraints.NotNull;
 import javax.validation.constraints.Size;
 import java.io.Serializable;
+import java.math.BigDecimal;
 
 @Data
 public class FsStorePackageOrderCreateParam implements Serializable
@@ -22,5 +23,10 @@ public class FsStorePackageOrderCreateParam implements Serializable
     private Long packageId;
     private Long companyUserId;
     private Long couponUserId;
+    @ApiModelProperty(value = "修改后的价格")
+    private BigDecimal payAmount;
+
+    @ApiModelProperty(value = "是否是套餐包制单",example  = "0")
+    private Integer isPackage;
 
 }

+ 11 - 1
fs-service/src/main/java/com/fs/hisStore/service/IFsStoreOrderScrmService.java

@@ -181,7 +181,7 @@ public interface IFsStoreOrderScrmService
 
     R addUserCart(long userId, String createOrderKey);
 
-    R updateSalseOrderMoney(String createOrderKey, BigDecimal money,BigDecimal payAmount,Integer payType);
+    R updateSalseOrderMoney(String createOrderKey, BigDecimal money,BigDecimal payAmount,Integer payType, Integer isPackage);
 
     Integer selectFsStoreOrderCountByType(Long companyId, long userId, int type);
 
@@ -320,4 +320,14 @@ public interface IFsStoreOrderScrmService
     R dfOrderResult(String body);
 
     R receiveWaybillPush(String body);
+
+    /**
+     * 套餐包制单
+     * @param companyUser 销售
+     * @param packageId 套餐包id
+     * @param orderType 订单类型
+     * @param orderMedium 媒体类型
+     * @return
+     */
+    R createPackageSalesOrder(CompanyUser companyUser, String packageId, Integer orderType, Integer orderMedium);
 }

+ 123 - 28
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreOrderScrmServiceImpl.java

@@ -112,6 +112,7 @@ import com.github.binarywang.wxpay.bean.result.WxPayRefundResult;
 import com.github.binarywang.wxpay.config.WxPayConfig;
 import com.github.binarywang.wxpay.exception.WxPayException;
 import com.github.binarywang.wxpay.service.WxPayService;
+import com.google.common.base.Joiner;
 import lombok.Synchronized;
 import lombok.extern.slf4j.Slf4j;
 import me.chanjar.weixin.common.error.WxErrorException;
@@ -361,6 +362,9 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
     @Autowired
     private FsStoreOrderDfMapper fsStoreOrderDfMapper;
 
+    @Autowired
+    private IFsStoreCartScrmService fsStoreCartScrmService;
+
     @PostConstruct
     public void initErpServiceMap() {
         erpServiceMap = new HashMap<>();
@@ -1450,14 +1454,24 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
     public R confirmPackageOrder(long uid, FsStoreConfirmPackageIdOrderParam param) {
         FsUserAddressScrm address = userAddressMapper.selectFsUserAddressByDefaultAddress(uid);
         FsStoreProductPackageScrm storeProductPackage = productPackageService.selectFsStoreProductPackageById(param.getPackageId());
-        String uuid = IdUtil.randomUUID();
-        BigDecimal totalMoney = storeProductPackage.getPayMoney();
+        // 由于套餐制单前面有生成oderkey,并且要取修改的价格,所以这里判断,如果有传就用传的orderkey,如果没有就生成(代表走的是直接购买)
+        String uuid;
+        BigDecimal totalMoney;
+        if(param.getCreateOrderKey().isEmpty() ){
+            //直接购买
+            uuid = IdUtil.randomUUID();
+            totalMoney = storeProductPackage.getPayMoney();
+        } else {
+            // 套餐制单
+            uuid = param.getCreateOrderKey();
+            totalMoney = redisCache.getCacheObject("createOrderMoney:" + param.getCreateOrderKey());
+        }
+
         if (param.getCouponUserId() != null) {
             FsStoreCouponUserScrm couponUser = couponUserService.selectFsStoreCouponUserById(param.getCouponUserId());
             if (couponUser != null && couponUser.getStatus() == 0) {
                 if (couponUser.getUseMinPrice().compareTo(storeProductPackage.getPayMoney()) == -1) {
-                    //
-                    totalMoney = totalMoney.subtract(couponUser.getCouponPrice());
+                    totalMoney = totalMoney != null ? totalMoney.subtract(couponUser.getCouponPrice()) : BigDecimal.ZERO.subtract(couponUser.getCouponPrice());
                 }
             }
         }
@@ -1493,29 +1507,37 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
             List<StorePackageProductDTO> goodsList = JSONUtil.toList(jsonArray, StorePackageProductDTO.class);
             //检测库存
             Integer totalNum = 0;
-            List<FsStoreCartQueryVO> carts = new ArrayList<>();
-            for (StorePackageProductDTO goods : goodsList) {
-                FsStoreProductAttrValueScrm attrValue = attrValueService.selectFsStoreProductAttrValueById(goods.getId());
-                if (attrValue != null && attrValue.getProductId() != null) {
-                    FsStoreProductScrm product = storeProductService.selectFsStoreProductById(attrValue.getProductId());
-                    if (product != null) {
-                        totalNum += goods.getCount();
-                        FsStoreCartQueryVO vo = new FsStoreCartQueryVO();
-                        vo.setProductId(attrValue.getProductId());
-                        vo.setProductAttrValueId(goods.getId());
-                        vo.setCartNum(goods.getCount());
-                        vo.setProductName(product.getProductName());
-                        vo.setProductAttrName(attrValue.getSku());
-                        vo.setProductImage(product.getImage());
-                        vo.setBarCode(attrValue.getBarCode());
-                        vo.setGroupBarCode(attrValue.getGroupBarCode());
-                        vo.setPrice(product.getPrice());
-                        vo.setProductType(product.getProductType());
-                        carts.add(vo);
+            List<FsStoreCartQueryVO> carts = redisCache.getCacheObject("orderCarts:" + param.getOrderKey());
+            String joinCartIds = null;
+            if(carts == null || carts.isEmpty()){
+                carts = new ArrayList<>();
+                for (StorePackageProductDTO goods : goodsList) {
+                    FsStoreProductAttrValueScrm attrValue = attrValueService.selectFsStoreProductAttrValueById(goods.getId());
+                    if (attrValue != null && attrValue.getProductId() != null) {
+                        FsStoreProductScrm product = storeProductService.selectFsStoreProductById(attrValue.getProductId());
+                        if (product != null) {
+                            totalNum += goods.getCount();
+                            FsStoreCartQueryVO vo = new FsStoreCartQueryVO();
+                            vo.setProductId(attrValue.getProductId());
+                            vo.setProductAttrValueId(goods.getId());
+                            vo.setCartNum(goods.getCount());
+                            vo.setProductName(product.getProductName());
+                            vo.setProductAttrName(attrValue.getSku());
+                            vo.setProductImage(product.getImage());
+                            vo.setBarCode(attrValue.getBarCode());
+                            vo.setGroupBarCode(attrValue.getGroupBarCode());
+                            vo.setPrice(product.getPrice());
+                            vo.setProductType(product.getProductType());
+                            carts.add(vo);
 
+                        }
                     }
+                    cartService.checkProductStock(attrValue.getProductId(), attrValue.getId());
                 }
-                cartService.checkProductStock(attrValue.getProductId(), attrValue.getId());
+            } else {
+                // 如果cartIds不为空,则表示是套餐制单购买,非套餐制单是没有购物车信息的。
+                List<Long> cartIds = carts.stream().map(FsStoreCartQueryVO::getId).collect(Collectors.toList());
+                joinCartIds = Joiner.on(",").join(cartIds);
             }
             //生成分布式唯一值
             String orderSn = IdUtil.getSnowflake(0, 0).nextIdStr();
@@ -1524,6 +1546,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
             //组合数据
             CompanyUser user = companyUserService.selectCompanyUserById(param.getCompanyUserId());
             FsStoreOrderScrm storeOrder = new FsStoreOrderScrm();
+            storeOrder.setCartId(joinCartIds);
             //修改默认仓库
 
             storeOrder.setStoreHouseCode("CK01");
@@ -1532,7 +1555,13 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
                 storeOrder.setCompanyId(user.getCompanyId());
                 storeOrder.setDeptId(user.getDeptId());
             }
-            BigDecimal totalMoney = storeProductPackage.getPayMoney();
+            BigDecimal totalMoney;
+            if(param.getIsPackage() != null && param.getIsPackage() == 1){
+                totalMoney = redisCache.getCacheObject("createOrderMoney:" + param.getOrderKey());
+            } else {
+                totalMoney = storeProductPackage.getPayMoney();
+            }
+
             //优惠券处理
             if (param.getCouponUserId() != null) {
                 FsStoreCouponUserScrm couponUser = couponUserService.selectFsStoreCouponUserById(param.getCouponUserId());
@@ -1597,6 +1626,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
             //减库存加销量
             this.deStockIncSale(carts);
             //保存购物车商品信息
+            List<FsStoreOrderItemScrm> listOrderItem = new ArrayList<>();
             for (FsStoreCartQueryVO vo : carts) {
                 FsStoreCartDTO fsStoreCartDTO = new FsStoreCartDTO();
                 fsStoreCartDTO.setProductId(vo.getProductId());
@@ -1624,7 +1654,13 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
                     item.setIsPrescribe(1);
                 }
                 fsStoreOrderItemMapper.insertFsStoreOrderItem(item);
+                listOrderItem.add(item);
+            }
+            if (!listOrderItem.isEmpty()) {
+                storeOrder.setItemJson(JSONUtil.toJsonStr(listOrderItem));
             }
+            fsStoreOrderMapper.updateFsStoreOrder(storeOrder);
+
             //删除缓存
             redisCache.deleteObject("orderKey:" + param.getOrderKey());
             //添加记录
@@ -2489,7 +2525,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
     }
 
     @Override
-    public R updateSalseOrderMoney(String createOrderKey, BigDecimal money, BigDecimal payAmount,Integer payType) {
+    public R updateSalseOrderMoney(String createOrderKey, BigDecimal money, BigDecimal payAmount,Integer payType, Integer isPackage) {
         //货到付款自定义金额
         if (payAmount == null) {
             String configJson = configService.selectConfigByKey("store.config");
@@ -2513,8 +2549,13 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
         }
         List<FsStoreCartQueryVO> carts = redisCache.getCacheObject("orderCarts:" + createOrderKey);
         BigDecimal totalMoney = BigDecimal.ZERO;
-        for (FsStoreCartQueryVO vo : carts) {
-            totalMoney = totalMoney.add(vo.getPrice().multiply(new BigDecimal(vo.getCartNum().toString())));
+        if(isPackage == 0){
+            for (FsStoreCartQueryVO vo : carts) {
+                totalMoney = totalMoney.add(vo.getPrice().multiply(new BigDecimal(vo.getCartNum().toString())));
+            }
+        } else {
+            //套餐制单
+            totalMoney = carts.get(0).getPrice();
         }
         if (money.compareTo(totalMoney) == 1) {
             throw new CustomException("价格不能大于商品总价", 501);
@@ -4710,6 +4751,59 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
         return null;
     }
 
+    @Override
+    public R createPackageSalesOrder(CompanyUser companyUser, String packageId, Integer orderType, Integer orderMedium) {
+        FsStoreProductPackageScrm storeProductPackage = productPackageService.selectFsStoreProductPackageById(Long.parseLong(packageId));
+        if(storeProductPackage == null){
+            return R.error("商品套餐不存在");
+        }
+
+        /**
+         * 由于套餐包制单前端页面没有走购物车,因为为了保证后续可以使用之前商品制单的改价接口、创建订单接口、支付等接口,
+         * 也为了保持结构一致,因此这里手动添加购物车
+         */
+        // 获取套餐包的商品信息,然后添加购物车
+        JSONArray jsonArray = JSONUtil.parseArray(storeProductPackage.getProducts());
+        List<StorePackageProductDTO> goodsList = JSONUtil.toList(jsonArray, StorePackageProductDTO.class);
+        String cartIds = "";
+        for (StorePackageProductDTO goods : goodsList) {
+            FsStoreCartParam fsStoreCartParam = new FsStoreCartParam();
+            FsStoreProductAttrValueScrm attrValue = attrValueService.selectFsStoreProductAttrValueById(goods.getId());
+            if (attrValue != null && attrValue.getProductId() != null) {
+                    fsStoreCartParam.setProductId(attrValue.getProductId());
+                    fsStoreCartParam.setCartNum(goods.getCount());
+                    fsStoreCartParam.setIsBuy(1);
+                    fsStoreCartParam.setAttrValueId(goods.getId());
+                R r = fsStoreCartScrmService.addCart(companyUser.getUserId(), fsStoreCartParam);
+                Object id = r.get("id");
+                if(id != null){
+                    cartIds += id + ",";
+                }
+            }
+
+        }
+
+        List<FsStoreCartQueryVO> carts = cartMapper.selectFsStoreCartListByIds(cartIds);
+        String uuid = IdUtil.randomUUID();
+        redisCache.setCacheObject("createOrderKey:" + uuid, companyUser.getCompanyId() + "-" + companyUser.getUserId(), 24, TimeUnit.HOURS);
+
+        // 这里的carts是购物车信息,价格取的套餐包价格
+        for (FsStoreCartQueryVO vo : carts) {
+            vo.setPrice(storeProductPackage.getPayMoney());
+        }
+        redisCache.setCacheObject("orderCarts:" + uuid, carts, 24, TimeUnit.HOURS);
+        if (orderType != null || orderMedium != null) {
+            FsStoreOrderScrm fsStoreOrder = new FsStoreOrderScrm();
+            fsStoreOrder.setOrderMedium(orderMedium);
+            fsStoreOrder.setOrderType(orderType);
+            redisCache.setCacheObject("orderInfo:" + uuid, fsStoreOrder, 24, TimeUnit.HOURS);
+        }
+
+        redisCache.setCacheObject("createOrderMoney:" + uuid, storeProductPackage.getPayMoney(), 24, TimeUnit.HOURS);
+        // 根据前端要求,为了前端方便取值,所以返回的参数key与商品制单的接口保持一致
+        return R.ok().put("orderKey", uuid);
+    }
+
     private static final DateTimeFormatter CST_FORMATTER = DateTimeFormatter
             .ofPattern("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US)
             .withZone(ZoneId.of("Asia/Shanghai"));
@@ -4746,6 +4840,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
         map.put("ZTO", "中通");
         map.put("JD", "京东");
         map.put("DBL", "德邦");
+        map.put("YTO", "圆通");
         return map;
     }
 

+ 17 - 3
fs-user-app/src/main/java/com/fs/app/controller/store/CompanyOrderScrmController.java

@@ -64,9 +64,11 @@ public class CompanyOrderScrmController extends AppBaseController {
     @ApiOperation("制单")
     @GetMapping("/createSalesOrder")
     public R createSalesOrder(@RequestParam("token")String token,
-                              @RequestParam("cateIds")String cateIds,
+                              @RequestParam(value = "cateIds", required = false)String cateIds,
                               @RequestParam(value = "orderType",required = false)Integer orderType,
                               @RequestParam(value = "orderMedium",required = false)Integer orderMedium,
+                              @RequestParam(value = "isPackage", required = false, defaultValue = "0")Integer isPackage,
+                              @RequestParam(value = "packageId", required = false)String packageId,
                               HttpServletRequest request){
         Long userId=redisCache.getCacheObject("company-user-token:"+token);
         if(userId==null){
@@ -79,7 +81,18 @@ public class CompanyOrderScrmController extends AppBaseController {
         if(!companyUser.getStatus().equals("0")){
             return R.error("用户已禁用");
         }
-        return orderService.createSalesOrder(companyUser,cateIds,orderType,orderMedium);
+        if(isPackage == 0){
+            return orderService.createSalesOrder(companyUser,cateIds,orderType,orderMedium);
+        } else if(isPackage == 1){
+            // 套餐包制单
+            if (packageId == null){
+                return R.error("套餐包ID不能为空");
+            }
+            return orderService.createPackageSalesOrder(companyUser,packageId,orderType,orderMedium);
+        } else {
+            return R.error("参数错误");
+        }
+
     }
 
     @ApiOperation("改价")
@@ -89,6 +102,7 @@ public class CompanyOrderScrmController extends AppBaseController {
                                    @RequestParam(value = "money",required = false) BigDecimal money,
                                    @RequestParam(value = "payAmount",required = false) BigDecimal payAmount,
                                    @RequestParam(value = "payType",required = false) Integer payType,
+                                   @RequestParam(value = "isPackage",required = false,defaultValue = "0")Integer isPackage,
                                    HttpServletRequest request){
         Long userId=redisCache.getCacheObject("company-user-token:"+token);
         if(userId==null){
@@ -100,7 +114,7 @@ public class CompanyOrderScrmController extends AppBaseController {
         if (payAmount == null){
             payAmount = BigDecimal.ZERO;
         }
-        return orderService.updateSalseOrderMoney(createOrderKey,money,payAmount,payType);
+        return orderService.updateSalseOrderMoney(createOrderKey,money,payAmount,payType, isPackage);
     }
 
     @ApiOperation("商品改价")