|
@@ -1,15 +1,38 @@
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.sqx.SqxApplication;
|
|
import com.sqx.SqxApplication;
|
|
|
|
|
+import com.sqx.common.utils.Query;
|
|
|
import com.sqx.common.utils.RedisUtils;
|
|
import com.sqx.common.utils.RedisUtils;
|
|
|
|
|
+import com.sqx.modules.activity.entity.ActivityPartRecord;
|
|
|
|
|
+import com.sqx.modules.activity.service.ActivityPartRecordService;
|
|
|
|
|
+import com.sqx.modules.app.dao.UserMoneyDetailsDao;
|
|
|
|
|
+import com.sqx.modules.app.entity.UserMoneyDetails;
|
|
|
|
|
+import com.sqx.modules.app.service.UserMoneyDetailsService;
|
|
|
|
|
+import com.sqx.modules.app.service.UserMoneyService;
|
|
|
|
|
+import com.sqx.modules.common.entity.CommonInfo;
|
|
|
|
|
+import com.sqx.modules.common.service.CommonInfoService;
|
|
|
|
|
+import com.sqx.modules.coupon.dao.TbCouponUserDao;
|
|
|
|
|
+import com.sqx.modules.coupon.entity.TbCouponUser;
|
|
|
|
|
+import com.sqx.modules.coupon.service.TbCouponService;
|
|
|
|
|
+import com.sqx.modules.errand.entity.TbIndentSmsSendLog;
|
|
|
|
|
+import com.sqx.modules.goods.entity.GoodsShop;
|
|
|
|
|
+import com.sqx.modules.order.dao.AppOrderDao;
|
|
|
|
|
+import com.sqx.modules.order.entity.TbOrder;
|
|
|
import com.sqx.modules.order.service.AppOrderService;
|
|
import com.sqx.modules.order.service.AppOrderService;
|
|
|
import com.sqx.modules.pay.service.WxService;
|
|
import com.sqx.modules.pay.service.WxService;
|
|
|
|
|
+import com.sqx.modules.shop.service.ShopMessageService;
|
|
|
import com.sqx.scheduler.order.OrderScheduler;
|
|
import com.sqx.scheduler.order.OrderScheduler;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.junit.jupiter.api.Test;
|
|
import org.junit.jupiter.api.Test;
|
|
|
import org.junit.runner.RunWith;
|
|
import org.junit.runner.RunWith;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
import org.springframework.test.context.junit4.SpringRunner;
|
|
import org.springframework.test.context.junit4.SpringRunner;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @author : codingliang
|
|
* @author : codingliang
|
|
@@ -24,6 +47,27 @@ public class OrderTest {
|
|
|
private AppOrderService appOrderService;
|
|
private AppOrderService appOrderService;
|
|
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
|
|
|
+ private ShopMessageService shopMessageService;
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private TbCouponUserDao tbCouponUserDao;
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private ActivityPartRecordService activityPartRecordService;
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private CommonInfoService commonInfoService;
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private UserMoneyDetailsDao userMoneyDetailsDao;
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private UserMoneyDetailsService userMoneyDetailsService;
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private UserMoneyService userMoneyService;
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
private OrderScheduler orderScheduler;
|
|
private OrderScheduler orderScheduler;
|
|
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
@@ -31,9 +75,137 @@ public class OrderTest {
|
|
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
|
private RedisUtils redisUtils;
|
|
private RedisUtils redisUtils;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private AppOrderDao appOrderDao;
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
public void test() {
|
|
public void test() {
|
|
|
|
|
+ List<TbOrder> orderList = appOrderDao.temp();
|
|
|
|
|
+ for (TbOrder tbOrder : orderList) {
|
|
|
|
|
+ QueryWrapper<UserMoneyDetails> queryWrapper = new QueryWrapper<>();
|
|
|
|
|
+ queryWrapper.eq("title", "商户订单收入,订单号:" + tbOrder.getOrderNumber());
|
|
|
|
|
+ if (userMoneyDetailsService.count(queryWrapper) > 0) {
|
|
|
|
|
+ log.info("订单id【{}】,商户用户钱包收入记录已存在,跳过", tbOrder.getOrderId());
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ log.info("订单id【{}】,开始计算商户用户钱包收入记录", tbOrder.getOrderId());
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ GoodsShop goodsShop = shopMessageService.selectShopId(tbOrder.getShopId());
|
|
|
|
|
+
|
|
|
|
|
+ // 计算商户应得金额
|
|
|
|
|
+ BigDecimal shopRate = goodsShop.getShopRate();
|
|
|
|
|
+ BigDecimal sumMoney = tbOrder.getPayMoney();
|
|
|
|
|
+ BigDecimal couponMoney = BigDecimal.ZERO;
|
|
|
|
|
+ Long shopIds = -1L;
|
|
|
|
|
+ if (tbOrder.getCouponId() != null) {
|
|
|
|
|
+ TbCouponUser tbCouponUser = tbCouponUserDao.selectById(tbOrder.getCouponId());
|
|
|
|
|
+ sumMoney = tbOrder.getPayMoney().add(tbCouponUser.getMoney());
|
|
|
|
|
+ couponMoney = tbCouponUser.getMoney();
|
|
|
|
|
+ shopIds = tbCouponUser.getShopId();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ BigDecimal errandMoney = BigDecimal.ZERO;
|
|
|
|
|
+ if (tbOrder.getOrderType() != 1) {
|
|
|
|
|
+ //判断是否达到商家满减 如果达到商家满减 跑腿费让商家承担
|
|
|
|
|
+ if (tbOrder.getAutoSendOrder() != null && tbOrder.getAutoSendOrder() == 0) {
|
|
|
|
|
+ errandMoney = tbOrder.getErrandMoney();
|
|
|
|
|
+ sumMoney = sumMoney.subtract(tbOrder.getErrandMoney());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ sumMoney = sumMoney.subtract(tbOrder.getErrandMoney());
|
|
|
|
|
+ errandMoney = tbOrder.getErrandMoney();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 再减去校内配送费
|
|
|
|
|
+ sumMoney = sumMoney.subtract(tbOrder.getInsideDeliveryFee());
|
|
|
|
|
+
|
|
|
|
|
+ // 店铺收入
|
|
|
|
|
+ BigDecimal shopMoney = sumMoney.multiply(shopRate);
|
|
|
|
|
+ shopMoney = shopMoney.setScale(2, BigDecimal.ROUND_DOWN);
|
|
|
|
|
+ BigDecimal pingRate = sumMoney.subtract(shopMoney);
|
|
|
|
|
+
|
|
|
|
|
+ // 商家配送短信服务费 为0
|
|
|
|
|
+ BigDecimal smsSendMoney = BigDecimal.ZERO;
|
|
|
|
|
+
|
|
|
|
|
+ // 这里再判断 是否是商家优惠券 如果是商家优惠券 这笔钱商家承担
|
|
|
|
|
+ if (shopIds != -1 && shopIds != 0) {
|
|
|
|
|
+ shopMoney = shopMoney.subtract(couponMoney);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 判断订单是否参与活动,如果参与活动,则优惠金额由商家承担
|
|
|
|
|
+ ActivityPartRecord activityPartRecord = activityPartRecordService.getByOrderId(tbOrder.getOrderId());
|
|
|
|
|
+ BigDecimal activityDiscountAmount = BigDecimal.ZERO;
|
|
|
|
|
+ if (ObjectUtil.isNotNull(activityPartRecord)) {
|
|
|
|
|
+ activityDiscountAmount = activityPartRecord.getDiscountAmount();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (tbOrder.getAutoSendOrder() != null && tbOrder.getAutoSendOrder() == 1) {
|
|
|
|
|
+ //如果达到商家满减 则商家不加上配送费
|
|
|
|
|
+ if (!"本单已达到商家满减金额,跑腿费由商家承担".equals(tbOrder.getErrandMoneyIsShop())) {
|
|
|
|
|
+ shopMoney = shopMoney.add(tbOrder.getErrandMoney());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ StringBuffer contentBuffer = new StringBuffer();
|
|
|
|
|
+ BigDecimal rider = new BigDecimal(0);
|
|
|
|
|
+ if (ObjectUtils.isNotEmpty(tbOrder.getOrderTypeExtra())&&tbOrder.getOrderTypeExtra()==2) {
|
|
|
|
|
+ // 获取骑手额外配送费
|
|
|
|
|
+ CommonInfo commonInfo = commonInfoService.findOne(443);
|
|
|
|
|
+ if (ObjectUtils.isNotEmpty(commonInfo)) {
|
|
|
|
|
+ rider =rider.add(new BigDecimal(commonInfo.getValue()));
|
|
|
|
|
+ shopMoney=shopMoney.subtract(rider);
|
|
|
|
|
+ }
|
|
|
|
|
+ log.info("订单id【{}】,骑手额外配送费【{}】", tbOrder.getOrderId(), rider);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 添加商户用户钱包收入记录
|
|
|
|
|
+ UserMoneyDetails userMoneyDetails1 = new UserMoneyDetails();
|
|
|
|
|
+ userMoneyDetails1.setShopId(goodsShop.getShopId());
|
|
|
|
|
+ userMoneyDetails1.setTitle("商户订单收入,订单号:" + tbOrder.getOrderNumber());
|
|
|
|
|
+
|
|
|
|
|
+ // 订单金额
|
|
|
|
|
+ BigDecimal orderAmount = tbOrder.getPayMoney().add(couponMoney).add(activityDiscountAmount);
|
|
|
|
|
+ contentBuffer.append("订单金额:").append(orderAmount.setScale(2, BigDecimal.ROUND_DOWN));
|
|
|
|
|
+ if (!couponMoney.equals(BigDecimal.ZERO)) {
|
|
|
|
|
+ contentBuffer.append(",优惠券金额:").append(couponMoney.setScale(2, BigDecimal.ROUND_DOWN));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!activityDiscountAmount.equals(BigDecimal.ZERO)) {
|
|
|
|
|
+ contentBuffer.append(",活动优惠金额:").append(activityDiscountAmount.setScale(2, BigDecimal.ROUND_DOWN));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ contentBuffer.append(",用户实付金额:").append(tbOrder.getPayMoney()).append(",其中");
|
|
|
|
|
+ if (tbOrder.getOrderType() != 1) {
|
|
|
|
|
+ contentBuffer.append("跑腿费:").append(errandMoney.setScale(2, BigDecimal.ROUND_DOWN)).append("(").append(tbOrder.getErrandMoneyIsShop()).append(")").append(",");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ contentBuffer.append("特殊地址跑腿费:").append(tbOrder.getInsideDeliveryFee().setScale(2, BigDecimal.ROUND_DOWN)).append(",");
|
|
|
|
|
+ contentBuffer.append("平台服务费:").append(pingRate.setScale(2, BigDecimal.ROUND_DOWN)).append(",");
|
|
|
|
|
+ contentBuffer.append("短信服务费:").append(smsSendMoney.setScale(2, BigDecimal.ROUND_DOWN)).append(",");
|
|
|
|
|
+ if (ObjectUtils.isNotEmpty(tbOrder.getOrderTypeExtra())&&tbOrder.getOrderTypeExtra()==2) {
|
|
|
|
|
+ contentBuffer.append("骑手额外配送费:").append(rider.setScale(2, BigDecimal.ROUND_DOWN)).append(",");
|
|
|
|
|
+ }
|
|
|
|
|
+ contentBuffer.append("到账金额:").append(shopMoney.setScale(2, BigDecimal.ROUND_DOWN));
|
|
|
|
|
+
|
|
|
|
|
+ if (shopIds == 0) {
|
|
|
|
|
+ contentBuffer.append("(本单为平台优惠券,平台补贴)");
|
|
|
|
|
+ } else if (shopIds != -1) {
|
|
|
|
|
+ contentBuffer.append("(本单为商家优惠券,商家补贴)");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ userMoneyDetails1.setContent(contentBuffer.toString());
|
|
|
|
|
+
|
|
|
|
|
+ userMoneyDetails1.setType(1);
|
|
|
|
|
+ userMoneyDetails1.setClassify(3);
|
|
|
|
|
+ userMoneyDetails1.setMoney(shopMoney);
|
|
|
|
|
+ userMoneyDetails1.setCreateTime("2025-10-09 23:59:59");
|
|
|
|
|
+ userMoneyDetails1.setState(2);
|
|
|
|
|
+ userMoneyDetailsDao.insert(userMoneyDetails1);
|
|
|
|
|
+ log.info("订单id【{}】,商户用户钱包收入记录新增成功", tbOrder.getOrderId());
|
|
|
|
|
|
|
|
|
|
+ //将用户支付的金额转入商户用户钱包
|
|
|
|
|
+ userMoneyService.updateMoney(1, goodsShop.getUserId(), shopMoney.doubleValue());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|