|
|
@@ -758,23 +758,47 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
@Override
|
|
|
public FsStoreOrderComputeDTO computedOrder(long uid, FsStoreOrderComputedParam param) {
|
|
|
logger.info("computedOrder param:{},uid:{}", param,uid);
|
|
|
- String cartIds = redisCache.getCacheObject("orderKey:" + param.getOrderKey());
|
|
|
- if (ObjectUtil.isNull(cartIds)) {
|
|
|
- throw new CustomException("订单已过期", 501);
|
|
|
- }
|
|
|
- List<FsStoreCartQueryVO> carts = redisCache.getCacheObject("orderCarts:" + param.getOrderKey());
|
|
|
- BigDecimal payPrice = getOrderSumPrice(carts, "truePrice");
|
|
|
- if (StringUtils.isNotEmpty(param.getCreateOrderKey())) {
|
|
|
+
|
|
|
+ // type=2: orderKey即为createOrderKey,不走购物车逻辑
|
|
|
+ boolean isTypeTwo = param.getType() != null && param.getType() == 2;
|
|
|
+
|
|
|
+ List<FsStoreCartQueryVO> carts = null;
|
|
|
+ BigDecimal payPrice;
|
|
|
+
|
|
|
+ if (isTypeTwo) {
|
|
|
+ // type=2: 直接从orderKey(createOrderKey)获取金额
|
|
|
+ BigDecimal money = redisCache.getCacheObject("createOrderMoney:" + param.getCreateOrderKey());
|
|
|
+ if (money == null) {
|
|
|
+ throw new CustomException("订单已过期", 501);
|
|
|
+ }
|
|
|
Integer payType = redisCache.getCacheObject("createOrderPayType:" + param.getCreateOrderKey());
|
|
|
if (payType != null && payType == 3) {
|
|
|
payPrice = redisCache.getCacheObject("createOrderAmount:" + param.getCreateOrderKey());
|
|
|
- } else {
|
|
|
- BigDecimal money = redisCache.getCacheObject("createOrderMoney:" + param.getCreateOrderKey());
|
|
|
- if (money != null) {
|
|
|
+ if (payPrice == null) {
|
|
|
payPrice = money;
|
|
|
}
|
|
|
+ } else {
|
|
|
+ payPrice = money;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // type=1: 原有逻辑
|
|
|
+ String cartIds = redisCache.getCacheObject("orderKey:" + param.getOrderKey());
|
|
|
+ if (ObjectUtil.isNull(cartIds)) {
|
|
|
+ throw new CustomException("订单已过期", 501);
|
|
|
+ }
|
|
|
+ carts = redisCache.getCacheObject("orderCarts:" + param.getOrderKey());
|
|
|
+ payPrice = getOrderSumPrice(carts, "truePrice");
|
|
|
+ if (StringUtils.isNotEmpty(param.getCreateOrderKey())) {
|
|
|
+ Integer payType = redisCache.getCacheObject("createOrderPayType:" + param.getCreateOrderKey());
|
|
|
+ if (payType != null && payType == 3) {
|
|
|
+ payPrice = redisCache.getCacheObject("createOrderAmount:" + param.getCreateOrderKey());
|
|
|
+ } else {
|
|
|
+ BigDecimal money = redisCache.getCacheObject("createOrderMoney:" + param.getCreateOrderKey());
|
|
|
+ if (money != null) {
|
|
|
+ payPrice = money;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
BigDecimal serviceFee = BigDecimal.ZERO;
|
|
|
String configJson = configService.selectConfigByKey("store.config");
|
|
|
@@ -787,14 +811,28 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
if (param.getAddressId() != null) {
|
|
|
userAddress = userAddressMapper.selectFsUserAddressById(param.getAddressId());
|
|
|
}
|
|
|
- FsStoreOrderPriceDTO priceGroup = this.getOrderPriceGroup(carts, userAddress);
|
|
|
- BigDecimal payPostage = priceGroup.getStorePostage();
|
|
|
- BigDecimal badCode = BigDecimal.valueOf(-1);
|
|
|
- // 检查运费计算结果,如果是 -1 表示偏远地区不可购买
|
|
|
- if (payPostage.compareTo(badCode) == 0) {
|
|
|
- throw new ServiceException("偏远地区暂不可购买");
|
|
|
+
|
|
|
+ FsStoreOrderPriceDTO priceGroup;
|
|
|
+ BigDecimal payPostage = BigDecimal.ZERO;
|
|
|
+
|
|
|
+ if (isTypeTwo && carts == null) {
|
|
|
+ // type=2 且无购物车信息时,邮费为0,总价为支付金额
|
|
|
+ priceGroup = new FsStoreOrderPriceDTO();
|
|
|
+ priceGroup.setStorePostage(BigDecimal.ZERO);
|
|
|
+ priceGroup.setTotalPrice(payPrice);
|
|
|
+ priceGroup.setCostPrice(BigDecimal.ZERO);
|
|
|
+ priceGroup.setPayIntegral(BigDecimal.ZERO);
|
|
|
+ priceGroup.setPayPrice(BigDecimal.ZERO);
|
|
|
+ } else {
|
|
|
+ priceGroup = this.getOrderPriceGroup(carts, userAddress);
|
|
|
+ payPostage = priceGroup.getStorePostage();
|
|
|
+ BigDecimal badCode = BigDecimal.valueOf(-1);
|
|
|
+ // 检查运费计算结果,如果是 -1 表示偏远地区不可购买
|
|
|
+ if (payPostage.compareTo(badCode) == 0) {
|
|
|
+ throw new ServiceException("偏远地区暂不可购买");
|
|
|
+ }
|
|
|
+ payPrice = NumberUtil.add(payPrice, payPostage);
|
|
|
}
|
|
|
- payPrice = NumberUtil.add(payPrice, payPostage);
|
|
|
|
|
|
FsUserScrm user = userService.selectFsUserById(uid);
|
|
|
// 积分抵扣
|
|
|
@@ -855,6 +893,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
.usedIntegral(usedIntegral)
|
|
|
.payIntegral(priceGroup.getPayIntegral())
|
|
|
.serviceFee(serviceFee)
|
|
|
+ .price(priceGroup.getPayPrice())
|
|
|
.build();
|
|
|
}
|
|
|
|
|
|
@@ -1184,6 +1223,552 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
|
|
|
return R.error("订单已过期");
|
|
|
}
|
|
|
}
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public R createOrderNew(long userId, FsStoreOrderCreateParam param) {
|
|
|
+
|
|
|
+ FsUserCompanyUser fsUserCompanyUser = fsUserCompanyUserMapper.selectFsUserCompanyUserByUserId(userId);
|
|
|
+ if (ObjectUtil.isNotEmpty(fsUserCompanyUser)){
|
|
|
+ param.setCompanyId(fsUserCompanyUser.getCompanyId());
|
|
|
+ param.setCompanyUserId(fsUserCompanyUser.getCompanyUserId());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!CloudHostUtils.hasCloudHostName("鹤颜堂")){
|
|
|
+ log.error("进入到数据");
|
|
|
+ if (ObjectUtil.isEmpty(param.getAddressId())){
|
|
|
+ return R.error("地址不能为空!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ FsStoreOrderComputedParam computedParam = new FsStoreOrderComputedParam();
|
|
|
+ BeanUtils.copyProperties(param, computedParam);
|
|
|
+ //计算金额
|
|
|
+ FsStoreOrderComputeDTO dto;
|
|
|
+ try {
|
|
|
+ computedParam.setCreateOrderKey(param.getOrderKey());
|
|
|
+ computedParam.setType(2);
|
|
|
+ dto = this.computedOrder(userId, computedParam);
|
|
|
+ } catch (ServiceException e) {
|
|
|
+ // 捕获运费模板检查异常,直接返回错误
|
|
|
+ if ("偏远地区暂不可购买".equals(e.getMessage())) {
|
|
|
+ return R.error("偏远地区暂不可购买");
|
|
|
+ }
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 根据type决定从哪个key获取数据
|
|
|
+ String cartIds = redisCache.getCacheObject("orderKey:" + param.getOrderKey());
|
|
|
+ Integer payType = redisCache.getCacheObject("createOrderPayType:" + param.getOrderKey());
|
|
|
+ if (payType != null) {
|
|
|
+ param.setPayType(payType.toString());
|
|
|
+ }
|
|
|
+// Integer totalNum = 0;
|
|
|
+ BigDecimal integral = BigDecimal.ZERO;
|
|
|
+
|
|
|
+ // type=2时,如果cartIds为空,尝试从createOrderKey获取
|
|
|
+ List<FsStoreCartQueryVO> carts = null;
|
|
|
+ carts = redisCache.getCacheObject("orderCarts:" + param.getOrderKey());
|
|
|
+ if (carts == null) {
|
|
|
+ // 如果没有购物车信息,直接创建订单(仅使用createOrderKey中的金额信息)
|
|
|
+ return createOrderFromCreateOrderKey(userId, param, dto, param.getOrderKey());
|
|
|
+ }
|
|
|
+ cartIds = redisCache.getCacheObject("createOrderKey:" + param.getOrderKey());
|
|
|
+
|
|
|
+ if (cartIds != null) {
|
|
|
+ //获取购物车列表
|
|
|
+ if (carts == null) {
|
|
|
+ carts = redisCache.getCacheObject("orderCarts:" + param.getOrderKey());
|
|
|
+ }
|
|
|
+ //获取地址
|
|
|
+ FsUserAddressScrm address = userAddressMapper.selectFsUserAddressById(param.getAddressId());
|
|
|
+ //生成分布式唯一值
|
|
|
+
|
|
|
+ String orderSn = OrderCodeUtils.getOrderSn();
|
|
|
+ //是否使用积分
|
|
|
+ Boolean isIntegral = false;
|
|
|
+ //组合数据
|
|
|
+ FsStoreOrderScrm storeOrder = new FsStoreOrderScrm();
|
|
|
+ storeOrder.setStoreHouseCode("CK01");
|
|
|
+ storeOrder.setCompanyId(param.getCompanyId());
|
|
|
+ storeOrder.setCompanyUserId(param.getCompanyUserId());
|
|
|
+
|
|
|
+ String json = configService.selectConfigByKey("store.config");
|
|
|
+ StoreConfig config= JSONUtil.toBean(json, StoreConfig.class);
|
|
|
+ //绑定销售
|
|
|
+ FsUserScrm fsuser= userService.selectFsUserById(userId);
|
|
|
+ if(ObjectUtil.isEmpty(config.getOrderAttribution())
|
|
|
+ ||!config.getOrderAttribution().equals(1)){
|
|
|
+ if(param.getCompanyUserId()!=null){
|
|
|
+ if (ObjectUtil.isNotEmpty(fsuser.getCompanyUserId())&&!fsuser.getCompanyUserId().equals(param.getCompanyUserId())){
|
|
|
+ CompanyUser companyUser=companyUserService.selectCompanyUserById(fsuser.getCompanyUserId());
|
|
|
+ return R.error(String.format("请联系%s销售进行购买商品!",companyUser.getNickName()));
|
|
|
+ }else {
|
|
|
+ fsuser.setCompanyUserId(param.getCompanyUserId());
|
|
|
+ userService.updateFsUser(fsuser);
|
|
|
+ }
|
|
|
+ CompanyUser companyUser=companyUserService.selectCompanyUserById(param.getCompanyUserId());
|
|
|
+ if(companyUser!=null){
|
|
|
+ storeOrder.setDeptId(companyUser.getDeptId());
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ storeOrder.setCompanyUserId(fsuser.getCompanyUserId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ CompanyUserUser map=new CompanyUserUser();
|
|
|
+ map.setCompanyUserId(param.getCompanyUserId());
|
|
|
+ map.setUserId(userId);
|
|
|
+ List<CompanyUserUser> list= companyUserUserMapper.selectCompanyUserUserList(map);
|
|
|
+ if(list==null||list.size()==0){
|
|
|
+ CompanyUser companyUser=companyUserService.selectCompanyUserById(param.getCompanyUserId());
|
|
|
+ if(companyUser!=null&&companyUser.getStatus().equals("0")){
|
|
|
+ map.setCompanyId(companyUser.getCompanyId());
|
|
|
+ companyUserUserMapper.insertCompanyUserUser(map);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ storeOrder.setUserId(userId);
|
|
|
+ storeOrder.setOrderCode(orderSn);
|
|
|
+ if (ObjectUtil.isNotEmpty(address)){
|
|
|
+ storeOrder.setRealName(address.getRealName());
|
|
|
+ storeOrder.setUserPhone(address.getPhone());
|
|
|
+ storeOrder.setUserAddress(address.getProvince() + " " + address.getCity() +
|
|
|
+ " " + address.getDistrict() + " " + address.getDetail().trim());
|
|
|
+ }
|
|
|
+ storeOrder.setCartId(cartIds);
|
|
|
+ storeOrder.setTotalNum(Long.parseLong(String.valueOf(carts.size())));
|
|
|
+ storeOrder.setTotalPrice(dto.getTotalPrice());
|
|
|
+ storeOrder.setTotalPostage(dto.getPayPostage());
|
|
|
+
|
|
|
+ //优惠券处理
|
|
|
+ if (param.getCouponUserId() != null) {
|
|
|
+ FsStoreCouponUserScrm couponUser = couponUserService.selectFsStoreCouponUserById(param.getCouponUserId());
|
|
|
+ if (couponUser != null && couponUser.getStatus() == 0) {
|
|
|
+ storeOrder.setCouponId(couponUser.getId());
|
|
|
+ storeOrder.setCouponPrice(couponUser.getCouponPrice());
|
|
|
+ //更新优惠券状态
|
|
|
+ couponUser.setStatus(1);
|
|
|
+ couponUser.setUseTime(new Date());
|
|
|
+ couponUserService.updateFsStoreCouponUser(couponUser);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //处理推荐人
|
|
|
+ FsUserScrm user = userService.selectFsUserById(storeOrder.getUserId());
|
|
|
+ if (user.getSpreadUserId() != null && user.getSpreadUserId() > 0) {
|
|
|
+ storeOrder.setTuiUserId(user.getSpreadUserId());
|
|
|
+ } else {
|
|
|
+ if (param.getTuiUserId() != null) {
|
|
|
+ FsUserScrm tuiUser = userService.selectFsUserById(param.getTuiUserId());
|
|
|
+ if (tuiUser != null && tuiUser.getIsPromoter() == 1) {
|
|
|
+ storeOrder.setTuiUserId(param.getTuiUserId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ storeOrder.setPayPostage(dto.getPayPostage());
|
|
|
+ storeOrder.setDeductionPrice(dto.getDeductionPrice());
|
|
|
+ storeOrder.setPaid(0);
|
|
|
+ storeOrder.setPayType(param.getPayType());
|
|
|
+ if (isIntegral) {
|
|
|
+ storeOrder.setPayIntegral(integral);
|
|
|
+ }
|
|
|
+ storeOrder.setUseIntegral(BigDecimal.valueOf(dto.getUsedIntegral()));
|
|
|
+ storeOrder.setBackIntegral(BigDecimal.ZERO);
|
|
|
+ storeOrder.setGainIntegral(BigDecimal.ZERO);
|
|
|
+ storeOrder.setMark(param.getMark());
|
|
|
+ //todo 获取成本价
|
|
|
+ BigDecimal costPrice = this.getOrderSumPrice(carts, "costPrice");
|
|
|
+ storeOrder.setCost(costPrice);
|
|
|
+ storeOrder.setIsChannel(1);
|
|
|
+ storeOrder.setShippingType(1);
|
|
|
+ storeOrder.setCreateTime(new Date());
|
|
|
+
|
|
|
+// String json = configService.selectConfigByKey("store.config");
|
|
|
+// StoreConfig config = JSONUtil.toBean(json, StoreConfig.class);
|
|
|
+ if (config.getServiceFee() != null) {
|
|
|
+ storeOrder.setServiceFee(config.getServiceFee());
|
|
|
+ }
|
|
|
+
|
|
|
+ //后台制单处理
|
|
|
+ if (param.getPayPrice() != null && param.getPayPrice().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ if (param.getPayPrice().compareTo(dto.getTotalPrice()) > 0) {
|
|
|
+ return R.error("改价价格不能大于商品总价");
|
|
|
+ }
|
|
|
+ storeOrder.setPayPrice(param.getPayPrice());
|
|
|
+ } else {
|
|
|
+ storeOrder.setPayPrice(dto.getPayPrice());
|
|
|
+ }
|
|
|
+
|
|
|
+ //付款方式
|
|
|
+ if (param.getPayType().equals("1")) {
|
|
|
+ //全款支付
|
|
|
+ storeOrder.setStatus(0);
|
|
|
+ if("广州郑多燕".equals(cloudHostProper.getCompanyName())){
|
|
|
+ BigDecimal amount = redisCache.getCacheObject("createOrderAmount:" + param.getCreateOrderKey());
|
|
|
+ storeOrder.setPayDelivery(amount != null ? amount : BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+ } else if (param.getPayType().equals("2")) {
|
|
|
+ //物流代收
|
|
|
+ storeOrder.setStatus(1);
|
|
|
+ } else if (param.getPayType().equals("3")) {
|
|
|
+ //货到付款
|
|
|
+ BigDecimal amount = param.getAmount(); //货到付款 自定义代收金额
|
|
|
+ if (amount != null && amount.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ storeOrder.setStatus(0);
|
|
|
+ storeOrder.setPayMoney(amount);
|
|
|
+ storeOrder.setPayDelivery(storeOrder.getPayPrice().subtract(amount));
|
|
|
+ } else {
|
|
|
+ storeOrder.setStatus(1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Boolean isPay = true;
|
|
|
+ if (param.getOrderCreateType() != null && param.getOrderCreateType() == 3 && param.getCompanyId() != null) {
|
|
|
+ //后台制单 判断是否需要付款
|
|
|
+ Company company = companyMapper.selectCompanyById(param.getCompanyId());
|
|
|
+ if (company != null) {
|
|
|
+ if (company.getIsPay() != null && company.getIsPay() == 0 && param.getIsUserApp()) {
|
|
|
+ //不需要付款
|
|
|
+ storeOrder.setStatus(1); //待发货
|
|
|
+ isPay = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ storeOrder.setOrderCreateType(param.getOrderCreateType());
|
|
|
+ Long prescribe = carts.stream().filter(item -> item.getProductType() != null && item.getProductType() == 2).count();
|
|
|
+ if (prescribe > 0) {
|
|
|
+ storeOrder.setIsPrescribe(1);
|
|
|
+ } else {
|
|
|
+ storeOrder.setIsPrescribe(0);
|
|
|
+ }
|
|
|
+ if (storeOrder.getCustomerId() == null) {
|
|
|
+ storeOrder.setCustomerId(param.getCustomerId());//6.13 添加客户id
|
|
|
+ }
|
|
|
+ FsStoreOrderScrm tempOrder = redisCache.getCacheObject("orderInfo:" + param.getCreateOrderKey());
|
|
|
+ if (tempOrder != null) {
|
|
|
+ storeOrder.setOrderType(tempOrder.getOrderType());
|
|
|
+ storeOrder.setOrderMedium(tempOrder.getOrderMedium());
|
|
|
+ redisCache.deleteObject("orderInfo:" + param.getCreateOrderKey());
|
|
|
+ } else {
|
|
|
+ storeOrder.setOrderType(param.getOrderType());
|
|
|
+ storeOrder.setOrderMedium(param.getOrderMedium());
|
|
|
+ }
|
|
|
+ Integer flag = fsStoreOrderMapper.insertFsStoreOrder(storeOrder);
|
|
|
+ if (flag == 0) {
|
|
|
+ return R.error("订单创建失败");
|
|
|
+ }
|
|
|
+ if (!isPay && storeOrder.getCompanyId() != null) {
|
|
|
+ // 添加订单审核
|
|
|
+ addOrderAudit(storeOrder);
|
|
|
+ }
|
|
|
+ //使用了积分扣积分
|
|
|
+ if (dto.getUsedIntegral() > 0) {
|
|
|
+ this.decIntegral(userId, dto.getUsedIntegral(), dto.getDeductionPrice(), storeOrder.getId().toString());
|
|
|
+ }
|
|
|
+ //减库存加销量
|
|
|
+ this.deStockIncSale(carts);
|
|
|
+ //保存OrderItem
|
|
|
+ List<FsStoreOrderItemScrm> listOrderItem = new ArrayList<>();
|
|
|
+ //保存购物车商品信息
|
|
|
+ for (FsStoreCartQueryVO vo : carts) {
|
|
|
+ // 检查限购
|
|
|
+ checkAndRecordPurchaseLimit(userId, vo.getProductId(), vo.getCartNum());
|
|
|
+
|
|
|
+ FsStoreCartDTO fsStoreCartDTO = new FsStoreCartDTO();
|
|
|
+ fsStoreCartDTO.setProductId(vo.getProductId());
|
|
|
+ fsStoreCartDTO.setPrice(vo.getPrice());
|
|
|
+ fsStoreCartDTO.setSku(vo.getProductAttrName());
|
|
|
+ fsStoreCartDTO.setProductName(vo.getProductName());
|
|
|
+ fsStoreCartDTO.setNum(vo.getCartNum());
|
|
|
+ fsStoreCartDTO.setBarCode(vo.getBarCode());
|
|
|
+ fsStoreCartDTO.setGroupBarCode(vo.getGroupBarCode());
|
|
|
+ fsStoreCartDTO.setBrokerage(vo.getBrokerage());
|
|
|
+ fsStoreCartDTO.setBrokerageTwo(vo.getBrokerageTwo());
|
|
|
+ fsStoreCartDTO.setBrokerageThree(vo.getBrokerageThree());
|
|
|
+ if (StringUtils.isEmpty(vo.getProductAttrImage())) {
|
|
|
+ fsStoreCartDTO.setImage(vo.getProductImage());
|
|
|
+ } else {
|
|
|
+ fsStoreCartDTO.setImage(vo.getProductAttrImage());
|
|
|
+ }
|
|
|
+
|
|
|
+ FsStoreOrderItemScrm item = new FsStoreOrderItemScrm();
|
|
|
+ item.setOrderId(storeOrder.getId());
|
|
|
+ item.setOrderCode(orderSn);
|
|
|
+ item.setProductAttrValueId(vo.getProductAttrValueId());
|
|
|
+ item.setCartId(vo.getId());
|
|
|
+ item.setProductId(vo.getProductId());
|
|
|
+ item.setJsonInfo(JSONUtil.toJsonStr(fsStoreCartDTO));
|
|
|
+ item.setNum(vo.getCartNum());
|
|
|
+ item.setIsAfterSales(0);
|
|
|
+ //处方药
|
|
|
+ if (vo.getProductType().equals(2)) {
|
|
|
+ item.setIsPrescribe(1);
|
|
|
+ }
|
|
|
+ fsStoreOrderItemMapper.insertFsStoreOrderItem(item);
|
|
|
+ listOrderItem.add(item);
|
|
|
+
|
|
|
+ }
|
|
|
+ if (listOrderItem.size() > 0) {
|
|
|
+ String itemJson = JSONUtil.toJsonStr(listOrderItem);
|
|
|
+ storeOrder.setItemJson(itemJson);
|
|
|
+ fsStoreOrderMapper.updateFsStoreOrder(storeOrder);
|
|
|
+ }
|
|
|
+ //购物车状态修改
|
|
|
+ cartMapper.updateIsPay(cartIds);
|
|
|
+
|
|
|
+ //删除缓存
|
|
|
+ if (config.getIsBrushOrders() == null || !(config.getIsBrushOrders() && param.getCompanyUserId() != null)) {
|
|
|
+ redisCache.deleteObject("createOrderKey:" + param.getOrderKey());
|
|
|
+ redisCache.deleteObject("orderCarts:" + param.getOrderKey());
|
|
|
+ redisCache.deleteObject("createOrderMoney:" + param.getOrderKey());
|
|
|
+ }
|
|
|
+ redisCache.deleteObject("createOrderAmount:" + param.getOrderKey());
|
|
|
+ redisCache.deleteObject("createOrderPayType:" + param.getOrderKey());
|
|
|
+
|
|
|
+ //添加记录
|
|
|
+ orderStatusService.create(storeOrder.getId(), OrderLogEnum.CREATE_ORDER.getValue(),
|
|
|
+ OrderLogEnum.CREATE_ORDER.getDesc());
|
|
|
+
|
|
|
+ //加入redis,24小时自动取消
|
|
|
+ String redisKey = String.valueOf(StrUtil.format("{}{}",
|
|
|
+ StoreConstants.REDIS_ORDER_OUTTIME_UNPAY, storeOrder.getId()));
|
|
|
+
|
|
|
+ if (config.getUnPayTime() != null && config.getUnPayTime() > 0) {
|
|
|
+ redisCache.setCacheObject(redisKey, storeOrder.getId(), config.getUnPayTime(), TimeUnit.MINUTES);
|
|
|
+ } else {
|
|
|
+ redisCache.setCacheObject(redisKey, storeOrder.getId(), 30, TimeUnit.MINUTES);
|
|
|
+ }
|
|
|
+ //添加支付到期时间
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(storeOrder.getCreateTime());
|
|
|
+ if (config.getUnPayTime() != null) {
|
|
|
+ calendar.add(Calendar.MINUTE, config.getUnPayTime());
|
|
|
+ }
|
|
|
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String payLimitTime = format.format(calendar.getTime());
|
|
|
+ redisCache.setCacheObject("orderAmount:" + storeOrder.getId(), storeOrder.getPayMoney(), 24, TimeUnit.HOURS);//物流代收自定义金额
|
|
|
+ //删除推荐订单KEY
|
|
|
+ if("鸿森堂".equals(cloudHostProper.getCompanyName())){
|
|
|
+ BigDecimal amount = redisCache.getCacheObject("createOrderAmount:" + param.getOrderKey());
|
|
|
+ redisCache.setCacheObject("orderAmount:" + storeOrder.getId(), amount, 24, TimeUnit.HOURS);//物流代收自定义金额
|
|
|
+ }else {
|
|
|
+ if (StringUtils.isNotEmpty(param.getOrderKey())) {
|
|
|
+ // type=1时才删除createOrderKey相关缓存(type=2已在上面删除)
|
|
|
+ if (config.getIsBrushOrders() == null || !(config.getIsBrushOrders() && param.getCompanyUserId() != null)) {
|
|
|
+ redisCache.deleteObject("createOrderKey:" + param.getOrderKey());
|
|
|
+ redisCache.deleteObject("orderCarts:" + param.getOrderKey());
|
|
|
+ redisCache.deleteObject("createOrderMoney:" + param.getOrderKey());
|
|
|
+ }
|
|
|
+
|
|
|
+ //货到付款自定义金额 key改为id存储
|
|
|
+ BigDecimal amount = redisCache.getCacheObject("createOrderAmount:" + param.getOrderKey());
|
|
|
+ redisCache.deleteObject("createOrderAmount:" + param.getOrderKey());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.ok().put("order", storeOrder).put("payLimitTime", payLimitTime);
|
|
|
+ } else {
|
|
|
+ return R.error("订单已过期");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * type=2时,无购物车信息的订单创建
|
|
|
+ */
|
|
|
+ private R createOrderFromCreateOrderKey(long userId, FsStoreOrderCreateParam param, FsStoreOrderComputeDTO dto, String effectiveCreateOrderKey) {
|
|
|
+ //获取地址
|
|
|
+ FsUserAddressScrm address = userAddressMapper.selectFsUserAddressById(param.getAddressId());
|
|
|
+ //生成分布式唯一值
|
|
|
+ String orderSn = OrderCodeUtils.getOrderSn();
|
|
|
+
|
|
|
+ //组合数据
|
|
|
+ FsStoreOrderScrm storeOrder = new FsStoreOrderScrm();
|
|
|
+ storeOrder.setStoreHouseCode("CK01");
|
|
|
+ storeOrder.setCompanyId(param.getCompanyId());
|
|
|
+ storeOrder.setCompanyUserId(param.getCompanyUserId());
|
|
|
+
|
|
|
+ String json = configService.selectConfigByKey("store.config");
|
|
|
+ StoreConfig config = JSONUtil.toBean(json, StoreConfig.class);
|
|
|
+ //绑定销售
|
|
|
+ FsUserScrm fsuser = userService.selectFsUserById(userId);
|
|
|
+ if (ObjectUtil.isEmpty(config.getOrderAttribution()) || !config.getOrderAttribution().equals(1)) {
|
|
|
+ if (param.getCompanyUserId() != null) {
|
|
|
+ if (ObjectUtil.isNotEmpty(fsuser.getCompanyUserId()) && !fsuser.getCompanyUserId().equals(param.getCompanyUserId())) {
|
|
|
+ CompanyUser companyUser = companyUserService.selectCompanyUserById(fsuser.getCompanyUserId());
|
|
|
+ return R.error(String.format("请联系%s销售进行购买商品!", companyUser.getNickName()));
|
|
|
+ } else {
|
|
|
+ fsuser.setCompanyUserId(param.getCompanyUserId());
|
|
|
+ userService.updateFsUser(fsuser);
|
|
|
+ }
|
|
|
+ CompanyUser companyUser = companyUserService.selectCompanyUserById(param.getCompanyUserId());
|
|
|
+ if (companyUser != null) {
|
|
|
+ storeOrder.setDeptId(companyUser.getDeptId());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ storeOrder.setCompanyUserId(fsuser.getCompanyUserId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ storeOrder.setUserId(userId);
|
|
|
+ storeOrder.setOrderCode(orderSn);
|
|
|
+ if (ObjectUtil.isNotEmpty(address)) {
|
|
|
+ storeOrder.setRealName(address.getRealName());
|
|
|
+ storeOrder.setUserPhone(address.getPhone());
|
|
|
+ storeOrder.setUserAddress(address.getProvince() + " " + address.getCity() +
|
|
|
+ " " + address.getDistrict() + " " + address.getDetail().trim());
|
|
|
+ }
|
|
|
+ storeOrder.setTotalNum(1L);
|
|
|
+ storeOrder.setTotalPrice(dto.getTotalPrice());
|
|
|
+ storeOrder.setTotalPostage(dto.getPayPostage());
|
|
|
+
|
|
|
+ //优惠券处理
|
|
|
+ if (param.getCouponUserId() != null) {
|
|
|
+ FsStoreCouponUserScrm couponUser = couponUserService.selectFsStoreCouponUserById(param.getCouponUserId());
|
|
|
+ if (couponUser != null && couponUser.getStatus() == 0) {
|
|
|
+ storeOrder.setCouponId(couponUser.getId());
|
|
|
+ storeOrder.setCouponPrice(couponUser.getCouponPrice());
|
|
|
+ couponUser.setStatus(1);
|
|
|
+ couponUser.setUseTime(new Date());
|
|
|
+ couponUserService.updateFsStoreCouponUser(couponUser);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //处理推荐人
|
|
|
+ FsUserScrm user = userService.selectFsUserById(storeOrder.getUserId());
|
|
|
+ if (user.getSpreadUserId() != null && user.getSpreadUserId() > 0) {
|
|
|
+ storeOrder.setTuiUserId(user.getSpreadUserId());
|
|
|
+ } else {
|
|
|
+ if (param.getTuiUserId() != null) {
|
|
|
+ FsUserScrm tuiUser = userService.selectFsUserById(param.getTuiUserId());
|
|
|
+ if (tuiUser != null && tuiUser.getIsPromoter() == 1) {
|
|
|
+ storeOrder.setTuiUserId(param.getTuiUserId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ storeOrder.setPayPostage(dto.getPayPostage());
|
|
|
+ storeOrder.setDeductionPrice(dto.getDeductionPrice());
|
|
|
+ storeOrder.setPaid(0);
|
|
|
+ storeOrder.setPayType(param.getPayType());
|
|
|
+ storeOrder.setUseIntegral(BigDecimal.valueOf(dto.getUsedIntegral()));
|
|
|
+ storeOrder.setBackIntegral(BigDecimal.ZERO);
|
|
|
+ storeOrder.setGainIntegral(BigDecimal.ZERO);
|
|
|
+ storeOrder.setMark(param.getMark());
|
|
|
+ storeOrder.setCost(BigDecimal.ZERO);
|
|
|
+ storeOrder.setIsChannel(1);
|
|
|
+ storeOrder.setShippingType(1);
|
|
|
+ storeOrder.setCreateTime(new Date());
|
|
|
+
|
|
|
+ if (config.getServiceFee() != null) {
|
|
|
+ storeOrder.setServiceFee(config.getServiceFee());
|
|
|
+ }
|
|
|
+
|
|
|
+ //后台制单处理
|
|
|
+ if (param.getPayPrice() != null && param.getPayPrice().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ if (param.getPayPrice().compareTo(dto.getTotalPrice()) > 0) {
|
|
|
+ return R.error("改价价格不能大于商品总价");
|
|
|
+ }
|
|
|
+ storeOrder.setPayPrice(param.getPayPrice());
|
|
|
+ } else {
|
|
|
+ storeOrder.setPayPrice(dto.getPayPrice());
|
|
|
+ }
|
|
|
+
|
|
|
+ //付款方式
|
|
|
+ if (param.getPayType().equals("1")) {
|
|
|
+ storeOrder.setStatus(0);
|
|
|
+ if ("广州郑多燕".equals(cloudHostProper.getCompanyName())) {
|
|
|
+ BigDecimal amount = redisCache.getCacheObject("createOrderAmount:" + effectiveCreateOrderKey);
|
|
|
+ storeOrder.setPayDelivery(amount != null ? amount : BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+ } else if (param.getPayType().equals("2")) {
|
|
|
+ storeOrder.setStatus(1);
|
|
|
+ } else if (param.getPayType().equals("3")) {
|
|
|
+ BigDecimal amount = param.getAmount();
|
|
|
+ if (amount != null && amount.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ storeOrder.setStatus(0);
|
|
|
+ storeOrder.setPayMoney(amount);
|
|
|
+ storeOrder.setPayDelivery(storeOrder.getPayPrice().subtract(amount));
|
|
|
+ } else {
|
|
|
+ storeOrder.setStatus(1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Boolean isPay = true;
|
|
|
+ if (param.getOrderCreateType() != null && param.getOrderCreateType() == 3 && param.getCompanyId() != null) {
|
|
|
+ Company company = companyMapper.selectCompanyById(param.getCompanyId());
|
|
|
+ if (company != null) {
|
|
|
+ if (company.getIsPay() != null && company.getIsPay() == 0 && param.getIsUserApp()) {
|
|
|
+ storeOrder.setStatus(1);
|
|
|
+ isPay = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ storeOrder.setOrderCreateType(param.getOrderCreateType());
|
|
|
+ storeOrder.setIsPrescribe(0);
|
|
|
+ if (storeOrder.getCustomerId() == null) {
|
|
|
+ storeOrder.setCustomerId(param.getCustomerId());
|
|
|
+ }
|
|
|
+ FsStoreOrderScrm tempOrder = redisCache.getCacheObject("orderInfo:" + effectiveCreateOrderKey);
|
|
|
+ if (tempOrder != null) {
|
|
|
+ storeOrder.setOrderType(tempOrder.getOrderType());
|
|
|
+ storeOrder.setOrderMedium(tempOrder.getOrderMedium());
|
|
|
+ redisCache.deleteObject("orderInfo:" + effectiveCreateOrderKey);
|
|
|
+ } else {
|
|
|
+ storeOrder.setOrderType(param.getOrderType());
|
|
|
+ storeOrder.setOrderMedium(param.getOrderMedium());
|
|
|
+ }
|
|
|
+
|
|
|
+ Integer flag = fsStoreOrderMapper.insertFsStoreOrder(storeOrder);
|
|
|
+ if (flag == 0) {
|
|
|
+ return R.error("订单创建失败");
|
|
|
+ }
|
|
|
+ if (!isPay && storeOrder.getCompanyId() != null) {
|
|
|
+ addOrderAudit(storeOrder);
|
|
|
+ }
|
|
|
+
|
|
|
+ //使用了积分扣积分
|
|
|
+ if (dto.getUsedIntegral() > 0) {
|
|
|
+ this.decIntegral(userId, dto.getUsedIntegral(), dto.getDeductionPrice(), storeOrder.getId().toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ //添加记录
|
|
|
+ orderStatusService.create(storeOrder.getId(), OrderLogEnum.CREATE_ORDER.getValue(),
|
|
|
+ OrderLogEnum.CREATE_ORDER.getDesc());
|
|
|
+
|
|
|
+ //加入redis,24小时自动取消
|
|
|
+ String redisKey = String.valueOf(StrUtil.format("{}{}",
|
|
|
+ StoreConstants.REDIS_ORDER_OUTTIME_UNPAY, storeOrder.getId()));
|
|
|
+
|
|
|
+ if (config.getUnPayTime() != null && config.getUnPayTime() > 0) {
|
|
|
+ redisCache.setCacheObject(redisKey, storeOrder.getId(), config.getUnPayTime(), TimeUnit.MINUTES);
|
|
|
+ } else {
|
|
|
+ redisCache.setCacheObject(redisKey, storeOrder.getId(), 30, TimeUnit.MINUTES);
|
|
|
+ }
|
|
|
+
|
|
|
+ //添加支付到期时间
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(storeOrder.getCreateTime());
|
|
|
+ if (config.getUnPayTime() != null) {
|
|
|
+ calendar.add(Calendar.MINUTE, config.getUnPayTime());
|
|
|
+ }
|
|
|
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String payLimitTime = format.format(calendar.getTime());
|
|
|
+ redisCache.setCacheObject("orderAmount:" + storeOrder.getId(), storeOrder.getPayMoney(), 24, TimeUnit.HOURS);
|
|
|
+
|
|
|
+ //删除createOrderKey相关缓存
|
|
|
+ if ("鸿森堂".equals(cloudHostProper.getCompanyName())) {
|
|
|
+ BigDecimal amount = redisCache.getCacheObject("createOrderAmount:" + effectiveCreateOrderKey);
|
|
|
+ redisCache.setCacheObject("orderAmount:" + storeOrder.getId(), amount, 24, TimeUnit.HOURS);
|
|
|
+ } else {
|
|
|
+ if (config.getIsBrushOrders() == null || !(config.getIsBrushOrders() && param.getCompanyUserId() != null)) {
|
|
|
+ redisCache.deleteObject("createOrderKey:" + effectiveCreateOrderKey);
|
|
|
+ redisCache.deleteObject("orderCarts:" + effectiveCreateOrderKey);
|
|
|
+ redisCache.deleteObject("createOrderMoney:" + effectiveCreateOrderKey);
|
|
|
+ }
|
|
|
+ BigDecimal amount = redisCache.getCacheObject("createOrderAmount:" + effectiveCreateOrderKey);
|
|
|
+ redisCache.deleteObject("createOrderAmount:" + effectiveCreateOrderKey);
|
|
|
+ redisCache.deleteObject("createOrderPayType:" + effectiveCreateOrderKey);
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.ok().put("order", storeOrder).put("payLimitTime", payLimitTime);
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public R createOrderByPrescribe(Long prescribeId) {
|