|
|
@@ -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();
|