|
|
@@ -25,6 +25,7 @@ import com.cyksj.config.zfb.AliPayClientFactory;
|
|
|
import com.cyksj.dto.RedisKey;
|
|
|
import com.cyksj.mapper.*;
|
|
|
import com.cyksj.mapper.channel.ShopConfigMapper;
|
|
|
+import com.cyksj.mapper.channel.UserPayEquipmentAvailableBenefitsMapper;
|
|
|
import com.cyksj.mapper.channel.UserPayEquipmentReceiveBenefitsRecordMapper;
|
|
|
import com.cyksj.mapper.manage.cms.CmsUserMapper;
|
|
|
import com.cyksj.mapper.manage.distribute.DistributeWaitingSendPointsMapper;
|
|
|
@@ -159,6 +160,8 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
|
|
|
|
|
|
private final YhShopUserDistributeBusinessOrderDonRecordMapper yhShopBusinessOrderDonRecordMapper;
|
|
|
|
|
|
+ private final UserPayEquipmentAvailableBenefitsMapper availableBenefitsMapper;
|
|
|
+
|
|
|
private static final GlobalThreadPoolTaskExecutor TASK_POOL = GlobalThreadPoolTaskExecutor.getInstance();
|
|
|
|
|
|
@Override
|
|
|
@@ -180,79 +183,86 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
|
|
|
orderDonWaybill.setOrderId(reqSetLogisticsPost.getOrderId());
|
|
|
orderDonWaybill.setRemark(reqSetLogisticsPost.getRemark());
|
|
|
OrderDon orderDon = getById(orderDonWaybill.getOrderId());
|
|
|
- if(orderDonWaybill.getId() == null){
|
|
|
- try {
|
|
|
- orderDonWaybillMapper.insert(orderDonWaybill);
|
|
|
- } catch (DuplicateKeyException e) {
|
|
|
- return orderDonWaybill;
|
|
|
+ Integer type = Optional.ofNullable(reqSetLogisticsPost.getType()).orElse(0);
|
|
|
+ //实物发货
|
|
|
+ if (type == 0 || type == 1) {
|
|
|
+ if (orderDonWaybill.getId() == null) {
|
|
|
+ try {
|
|
|
+ orderDonWaybillMapper.insert(orderDonWaybill);
|
|
|
+ } catch (DuplicateKeyException e) {
|
|
|
+ return orderDonWaybill;
|
|
|
+ }
|
|
|
+ orderDon.setStatus(OrderDon.Status.transport);
|
|
|
+ updateById(orderDon);
|
|
|
+ //库存扣减逻辑
|
|
|
+ List<GoodsSkuStockRelate> relateList = skuStockRelateMapper.selectList(Wrappers.lambdaQuery(GoodsSkuStockRelate.class).eq(GoodsSkuStockRelate::getSkuId, orderDon.getSkuId()));
|
|
|
+ if (!relateList.isEmpty()) {
|
|
|
+ relateList.forEach((relate) -> {
|
|
|
+ goodsDonStockService.upStockRelate(relate.getStockId(), orderDon.getId(), "transport");
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (orderDon.getStatus() == OrderDon.Status.hasPayment) {
|
|
|
+ orderDon.setStatus(OrderDon.Status.transport);
|
|
|
+ updateById(orderDon);
|
|
|
+ }
|
|
|
+ orderDonWaybillMapper.updateById(orderDonWaybill);
|
|
|
}
|
|
|
- orderDon.setStatus(OrderDon.Status.transport);
|
|
|
- updateById(orderDon);
|
|
|
|
|
|
- GoodsDonSku sku = goodsDonSkuMapper.selectById(orderDon.getSkuId());
|
|
|
- //库存扣减逻辑
|
|
|
- List<GoodsSkuStockRelate> relateList = skuStockRelateMapper.selectList(Wrappers.lambdaQuery(GoodsSkuStockRelate.class).eq(GoodsSkuStockRelate::getSkuId,orderDon.getSkuId()));
|
|
|
- if(!relateList.isEmpty()){
|
|
|
- relateList.forEach((relate)->{
|
|
|
- goodsDonStockService.upStockRelate(relate.getStockId(),orderDon.getId(),"transport");
|
|
|
- });
|
|
|
+ //实物分销订单是否存在
|
|
|
+ DistributeWaitingSendPoints waitingSendPoints = distributeWaitingSendPointsMapper.selectOne(Wrappers.lambdaQuery(DistributeWaitingSendPoints.class)
|
|
|
+ .eq(DistributeWaitingSendPoints::getOrderId, orderDon.getId())
|
|
|
+ .eq(DistributeWaitingSendPoints::getIsDelivery, false)
|
|
|
+ .last("limit 1"));
|
|
|
+ if (waitingSendPoints != null) {
|
|
|
+ //实物分销订单发货后再 进行提成结算期
|
|
|
+ waitingSendPoints.setIsDelivery(true);
|
|
|
+ distributeWaitingSendPointsMapper.updateById(waitingSendPoints);
|
|
|
+ }
|
|
|
+ //分销有礼 分销实物是否有发货后用户权益
|
|
|
+ EquipmentUserDistributeTransportBenefits transportBenefits = transportBenefitsMapper.selectOne(Wrappers.lambdaQuery(EquipmentUserDistributeTransportBenefits.class)
|
|
|
+ .eq(EquipmentUserDistributeTransportBenefits::getOrderId, orderDon.getId())
|
|
|
+ .eq(EquipmentUserDistributeTransportBenefits::getStatus, EquipmentUserDistributeTransportBenefits.Status.hasPayment).last("limit 1"));
|
|
|
+ if (transportBenefits != null) {
|
|
|
+ if (transportBenefits.getBalance().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ //7天后余额到账
|
|
|
+ transportBenefitsMapper.update(null, Wrappers.lambdaUpdate(EquipmentUserDistributeTransportBenefits.class)
|
|
|
+ .set(EquipmentUserDistributeTransportBenefits::getStatus, EquipmentUserDistributeTransportBenefits.Status.transport)
|
|
|
+ .set(EquipmentUserDistributeTransportBenefits::getSendTime, DateUtil.offsetDay(DateTime.now(), 7))
|
|
|
+ .eq(EquipmentUserDistributeTransportBenefits::getOrderId, orderDon.getId())
|
|
|
+ .eq(EquipmentUserDistributeTransportBenefits::getStatus, EquipmentUserDistributeTransportBenefits.Status.hasPayment));
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- //发放实物购买权益
|
|
|
- Boolean isReceivedAll = true;
|
|
|
- if (sku != null) {
|
|
|
- if (sku.getIsBenefits()) {
|
|
|
- if (StrUtil.isNotEmpty(sku.getBenefitsList())) {
|
|
|
- try {
|
|
|
- List<GoodsDonSku> goodsDonSkus = Jsons.parseList(sku.getBenefitsList(), GoodsDonSku.class);
|
|
|
- //自购实物 获取权益
|
|
|
- isReceivedAll = userRealOrderBenefitsService.getPayRealGoodsBenefits(orderDon.getUserId(), orderDon.getId(), orderDon.getYhsId(), goodsDonSkus);
|
|
|
- } catch (Exception e) {
|
|
|
+ //权益发货
|
|
|
+ if (type == 0 || type == 2) {
|
|
|
+ GoodsDonSku sku = goodsDonSkuMapper.selectById(orderDon.getSkuId());
|
|
|
+ if (sku != null && sku.getIsBenefits()) {
|
|
|
+ //是否实物权益已发放
|
|
|
+ Integer count = receiveBenefitsRecordMapper.selectCount(Wrappers.lambdaQuery(UserPayEquipmentReceiveBenefitsRecord.class)
|
|
|
+ .eq(UserPayEquipmentReceiveBenefitsRecord::getRealOrderId, orderDon.getId()));
|
|
|
+ if (count == 0) {
|
|
|
+ count = availableBenefitsMapper.selectCount(Wrappers.lambdaQuery(UserPayEquipmentAvailableBenefits.class)
|
|
|
+ .eq(UserPayEquipmentAvailableBenefits::getRealOrderId, orderDon.getId()));
|
|
|
+ }
|
|
|
+ if (count == 0) {
|
|
|
+ //实物权益未发
|
|
|
+ String benefitsKey = RedisService.key.REAL_GOODS_BENEFITS_KEY.getNameFormat(orderDon.getId());
|
|
|
+ if (redisService.setNx(benefitsKey, orderDon.getId(), RedisService.key.REAL_GOODS_BENEFITS_KEY.getTimeout())) {
|
|
|
+ //发放实物购买权益
|
|
|
+ if (StrUtil.isNotEmpty(sku.getBenefitsList())) {
|
|
|
+ try {
|
|
|
+ List<GoodsDonSku> goodsDonSkus = Jsons.parseList(sku.getBenefitsList(), GoodsDonSku.class);
|
|
|
+ //自购实物 获取权益
|
|
|
+ userRealOrderBenefitsService.getPayRealGoodsBenefits(orderDon.getUserId(), orderDon.getId(), orderDon.getYhsId(), goodsDonSkus);
|
|
|
+ } catch (Exception e) {
|
|
|
+ redisService.del(benefitsKey);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- final Boolean flag = isReceivedAll;
|
|
|
-
|
|
|
- //发送微信模板消息
|
|
|
-// TASK_POOL.execute(()->{
|
|
|
-// try {
|
|
|
-// log.info("发送发货通知至{}用户", orderDon.getUserId());
|
|
|
-// templateCommonService.sendTransportMsgNotify(orderDon, reqSetLogisticsPost, flag);
|
|
|
-// } catch (Exception e) {
|
|
|
-// log.error("发送发货通知至{}用户失败:{}", orderDon.getUserId(), e);
|
|
|
-// }
|
|
|
-// });
|
|
|
- }else {
|
|
|
- if (orderDon.getStatus() == OrderDon.Status.hasPayment) {
|
|
|
- orderDon.setStatus(OrderDon.Status.transport);
|
|
|
- updateById(orderDon);
|
|
|
- }
|
|
|
- orderDonWaybillMapper.updateById(orderDonWaybill);
|
|
|
- }
|
|
|
- //实物分销订单是否存在
|
|
|
- DistributeWaitingSendPoints waitingSendPoints = distributeWaitingSendPointsMapper.selectOne(Wrappers.lambdaQuery(DistributeWaitingSendPoints.class)
|
|
|
- .eq(DistributeWaitingSendPoints::getOrderId, orderDon.getId())
|
|
|
- .eq(DistributeWaitingSendPoints::getIsDelivery, false)
|
|
|
- .last("limit 1"));
|
|
|
- if (waitingSendPoints != null) {
|
|
|
- //实物分销订单发货后再 进行提成结算期
|
|
|
- waitingSendPoints.setIsDelivery(true);
|
|
|
- distributeWaitingSendPointsMapper.updateById(waitingSendPoints);
|
|
|
- }
|
|
|
- //分销有礼 分销实物是否有发货后用户权益
|
|
|
- EquipmentUserDistributeTransportBenefits transportBenefits = transportBenefitsMapper.selectOne(Wrappers.lambdaQuery(EquipmentUserDistributeTransportBenefits.class)
|
|
|
- .eq(EquipmentUserDistributeTransportBenefits::getOrderId, orderDon.getId())
|
|
|
- .eq(EquipmentUserDistributeTransportBenefits::getStatus, EquipmentUserDistributeTransportBenefits.Status.hasPayment).last("limit 1"));
|
|
|
- if (transportBenefits != null) {
|
|
|
- if (transportBenefits.getBalance().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
- //7天后余额到账
|
|
|
- transportBenefitsMapper.update(null, Wrappers.lambdaUpdate(EquipmentUserDistributeTransportBenefits.class)
|
|
|
- .set(EquipmentUserDistributeTransportBenefits::getStatus, EquipmentUserDistributeTransportBenefits.Status.transport)
|
|
|
- .set(EquipmentUserDistributeTransportBenefits::getSendTime, DateUtil.offsetDay(DateTime.now(), 7))
|
|
|
- .eq(EquipmentUserDistributeTransportBenefits::getOrderId, orderDon.getId())
|
|
|
- .eq(EquipmentUserDistributeTransportBenefits::getStatus, EquipmentUserDistributeTransportBenefits.Status.hasPayment));
|
|
|
- }
|
|
|
}
|
|
|
return orderDonWaybill;
|
|
|
}
|