Quellcode durchsuchen

商城订单制单

wjj vor 1 Tag
Ursprung
Commit
957fecf7e0

+ 8 - 0
fs-service/src/main/java/com/fs/hisStore/mapper/FsStoreProductAttrValueScrmMapper.java

@@ -104,6 +104,14 @@ public interface FsStoreProductAttrValueScrmMapper
             "and find_in_set(#{maps.companyId},p.company_ids)  " +
             "</if>" +
 
+            "<if test = 'maps.erpType != null    '> " +
+            "and p.erp_type = #{maps.erpType}  " +
+            "</if>" +
+
+            "<if test = 'maps.isGift != null    '> " +
+            "and p.is_gift = #{maps.isGift}  " +
+            "</if>" +
+
             " order by v.id desc "+
             "</script>"})
     List<FsStoreProductAttrValueVO> selectFsStoreProductAttrValueListVO(@Param("maps")FsProductAttrValueParam param);

+ 2 - 0
fs-service/src/main/java/com/fs/hisStore/param/FsProductAttrValueParam.java

@@ -13,4 +13,6 @@ public class FsProductAttrValueParam implements Serializable
     private Integer isShow;
     Integer tuiCateId;
     private Long companyId;
+    private Integer erpType;
+    private Integer isGift;
 }

+ 2 - 0
fs-service/src/main/java/com/fs/hisStore/param/FsStoreConfirmOrderParam.java

@@ -14,4 +14,6 @@ public class FsStoreConfirmOrderParam {
     @NotBlank(message = "购买类型不能为空")
     @ApiModelProperty(value = "buy cart")
     private String type;
+
+    private String giftCartIds;
 }

+ 15 - 2
fs-service/src/main/java/com/fs/hisStore/param/FsStoreOrderCreateUserParam.java

@@ -15,9 +15,9 @@ public class FsStoreOrderCreateUserParam implements Serializable
 {
     private Long companyId;
     private Long companyUserId;
-    @NotNull(message = "会员不能为空")
+    //@NotNull(message = "会员不能为空")
     private Long userId;
-    @NotNull(message = "地址不能为空")
+    //@NotNull(message = "地址不能为空")
     private Long addressId;
     @Size(max = 200,message = "备注长度超过了限制")
     @ApiModelProperty(value = "备注")
@@ -32,4 +32,17 @@ public class FsStoreOrderCreateUserParam implements Serializable
     private BigDecimal amount; //货到付款代收金额
     private Integer orderType; //订单类型
     private Integer orderMedium; //媒体来源
+    private Long companyCustomerId;//患者会员id
+    private BigDecimal reduceAmount;//抵扣金额
+
+    //地址信息
+    private String realName;
+    private String phone;
+    private String province;
+    private String city;
+    private String district;
+    private String detail;
+
+    //赠品
+    private List<FsStoreProductAttrValueVO> giftProducts;
 }

+ 59 - 1
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreOrderScrmServiceImpl.java

@@ -1,6 +1,7 @@
 package com.fs.hisStore.service.impl;
 
 import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
+import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.date.DateTime;
 import cn.binarywang.wx.miniapp.api.WxMaService;
 import cn.hutool.core.net.URLDecoder;
@@ -94,6 +95,8 @@ import com.fs.hisStore.constants.StoreConstants;
 import com.fs.hisStore.domain.*;
 import com.fs.hisStore.enums.*;
 import com.fs.hisStore.service.*;
+import com.fs.qw.domain.FsCompanyCustomer;
+import com.fs.qw.mapper.FsCompanyCustomerMapper;
 import com.fs.system.service.ISysConfigService;
 import com.fs.wx.miniapp.config.WxMaProperties;
 import com.fs.ybPay.domain.OrderResult;
@@ -350,6 +353,9 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
     @Autowired
     private IFsOrderSopLogService fsOrderSopLogService;
 
+    @Autowired
+    private FsCompanyCustomerMapper fsCompanyCustomerMapper;
+
     //ERP 类型到服务的映射
     private Map<Integer, IErpOrderService> erpServiceMap;
     @PostConstruct
@@ -610,6 +616,11 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
             }
         }
         String uuid = IdUtil.randomUUID();
+        //赠品
+        if (StringUtils.isNotEmpty(cartParam.getGiftCartIds())) {
+            List<FsStoreCartQueryVO> giftCarts = cartMapper.selectFsStoreCartListByIds(cartParam.getGiftCartIds());
+            redisCache.setCacheObject("orderGiftCarts:" + uuid, giftCarts, 300, TimeUnit.SECONDS);
+        }
         redisCache.setCacheObject("orderKey:" + uuid, cartParam.getCartIds(), 300, TimeUnit.SECONDS);
         redisCache.setCacheObject("orderCarts:" + uuid, carts, 300, TimeUnit.SECONDS);
         return R.ok().put("orderKey", uuid).put("address", address).put("carts", carts);
@@ -1545,7 +1556,34 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
     @Override
     @Transactional
     public R createUserOrder(FsStoreOrderCreateUserParam param) {
-
+        if (param.getCompanyCustomerId() != null) {
+            FsCompanyCustomer fsCompanyCustomer = fsCompanyCustomerMapper.selectFsCompanyCustomerById(param.getCompanyCustomerId());
+            if (fsCompanyCustomer == null) {
+                return R.error("客户信息为空,制单失败");
+            }
+            param.setUserId(1L);
+            //保存收货地址
+            FsUserAddressScrm address = new FsUserAddressScrm();
+            address.setPhone(param.getPhone());
+            address.setRealName(param.getRealName());
+            address.setDetail(param.getDetail());
+            address.setProvince(param.getProvince());
+            address.setCity(param.getCity());
+            address.setDistrict(param.getDistrict());
+            address.setUserId(1L);//目前默认给id为1的用户
+            int i = userAddressMapper.insertFsUserAddress(address);
+            if (i <= 0) {
+                return R.error("收货地址保存失败");
+            }
+            param.setAddressId(address.getId());
+        } else {
+            if (param.getUserId() == null) {
+                return R.error("会员不能为空");
+            }
+            if (param.getAddressId() == null) {
+                return R.error("收货地址不能为空");
+            }
+        }
         List<String> cartIds = new ArrayList<>();
         for (FsStoreProductAttrValueVO productAttrValue : param.getProducts()) {
             FsStoreCartScrm storeCart = FsStoreCartScrm.builder()
@@ -1565,6 +1603,26 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
         FsStoreConfirmOrderParam confirmOrderParam = new FsStoreConfirmOrderParam();
         confirmOrderParam.setCartIds(StringUtils.join(cartIds.toArray(), ","));
         confirmOrderParam.setType("buy");
+        //赠品信息
+        if (CollectionUtil.isNotEmpty(param.getGiftProducts())) {
+            List<String> giftCartIds = new ArrayList<>();
+            for (FsStoreProductAttrValueVO giftProduct : param.getGiftProducts()) {
+                FsStoreCartScrm storeCart = FsStoreCartScrm.builder()
+                        .cartNum(giftProduct.getCount())
+                        .productAttrValueId(giftProduct.getId())
+                        .productId(giftProduct.getProductId())
+                        .userId(param.getUserId())
+                        .isPay(0)
+                        .isDel(0)
+                        .isBuy(0)
+                        .build();
+                storeCart.setCreateTime(new Date());
+                cartService.checkProductStock(giftProduct.getProductId(), storeCart.getProductAttrValueId());
+                cartService.insertFsStoreCart(storeCart);
+                giftCartIds.add(storeCart.getId().toString());
+            }
+            confirmOrderParam.setGiftCartIds(StringUtils.join(giftCartIds.toArray(), ","));
+        }
         R confirmResult = this.confirmOrder(param.getUserId(), confirmOrderParam);
         if (confirmResult.get("code").equals(200)) {
             FsStoreOrderCreateParam createParam = new FsStoreOrderCreateParam();