|
|
@@ -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;
|
|
|
}
|
|
|
|