import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.ekyong.www.pay.pay.qrcode.api.RhtQrcodePayApi; import com.ekyong.www.pay.pay.qrcode.bean.QrcodeQueryRequestBean; import com.ekyong.www.pay.pay.qrcode.bean.QrcodeQueryResponseBean; import com.sqx.SqxApplication; import com.sqx.common.utils.Constant; import com.sqx.common.utils.DateUtils; import com.sqx.common.utils.RedisUtils; import com.sqx.common.utils.Result; 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.errand.entity.TbIndent; import com.sqx.modules.errand.entity.TbIndentSmsSendLog; import com.sqx.modules.errand.service.TbIndentService; import com.sqx.modules.errand.service.TbIndentSmsSendLogService; import com.sqx.modules.goods.entity.GoodsShop; import com.sqx.modules.goods.service.GoodsShopService; 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.pay.config.WechatPayConfig; import com.sqx.modules.pay.service.WxService; import com.sqx.modules.shop.service.ShopMessageService; import com.sqx.scheduler.order.OrderScheduler; import lombok.extern.slf4j.Slf4j; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.Map; /** * @author : codingliang * @date : 2024-09-10 16:24 */ @Slf4j @RunWith(SpringRunner.class) @SpringBootTest(classes = SqxApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class OrderTest { @Resource private AppOrderService appOrderService; @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; @Resource private WxService wxService; @Resource private RedisUtils redisUtils; @Autowired private AppOrderDao appOrderDao; @Autowired private AppOrderService orderService; @Autowired private GoodsShopService goodsShopService; @Autowired private TbIndentSmsSendLogService smsSendLogService; @Autowired private TbIndentService tbIndentService; @Test public void test() { TbOrder tbOrder = appOrderService.selectOrderByNum("202603111524117723"); orderService.subStock(tbOrder); } @Test public void test2() { List orderNumbers = Arrays.asList("202603171658527850", "202603171619351849", "202603171710572245", "202603171714048452", "202603171638169334", "202603171630378942", "202603171748451859", "202603171701106897", "202603171650405141", "202603171620564497", "202603171642345788", "202603171749291525", "202603171623034174", "202603171737258426", "202603171635097793", "202603171722291718", "202603171758527104", "202601061658273032", "202603171702219075", "202603061751057889", "202603171756291948", "202603171759418369", "202603171721108130", "202603171719358825", "202603161117352549", "202603171740425528", "202603171708442864", "202603161746295701", "202603171805259872", "202603171719246998", "202603171644476707", "202603171709029503", "202603171644542515", "202603151407369659", "202603171806023314", "202603171804086449", "202603171621529775", "202601131602524734", "202603171724289097", "202603171802209739", "202603171801064578", "202603171638089608", "202603151825132239", "202603071224354624", "202603171721285003", "202603171649493851", "202603171741425727", "202603171820348387", "202603171623508052", "202603171731148811", "202603171706139841", "202603141014225288", "202603171645301175", "202603171738077815", "202603171631472362", "202603161808435542", "202603171621406667", "202603171709198659", "202603171713048654", "202603171623196547", "202603171614043059", "202603171811466449", "202603171622048052", "202603171725342877", "202603171713225462", "202603171631307251", "202603171751242823", "202603171727426485", "202603171705516972", "202603171652208569", "202603171731103142", "202603171645548122", "202603171618168512", "202603171714322093", "202603101702495228", "202603171714424020", "202511191950472470", "202603171727504578", "202603171632565021", "202603171618507259", "202603171629126621", "202603171541583648", "202603171738311378", "202603171624238458", "202510141117431653", "202603171749365333", "202603171629044014", "202603171720331910", "202603171538471740", "202603171758378816", "202603170938553359", "202603171708297626", "202603141545452583", "202603171703332189", "202603171622568889", "202603061957284523", "202603171627058425", "202603171645356441", "202603171539219622", "202603171746039921", "202603171650566927", "202603171708117590", "202603171627003546", "202603171648503963", "202603171652486958", "202603171624083278", "202603171634448770", "202603171626482161", "202603171749504957", "202603171755208256", "202603171728162921", "202603171730195807", "202603171643307822", "202603171627265421", "202603171724101591", "202603141107296175", "202603171539319893", "202603171627236101", "202603171639232165", "202603171655131079", "202603171657055630", "202603171543323001", "202603171735113067", "202603171723286067", "202603171734214261", "202603171712446392", "202603161114176003", "202603171621492177", "202603171652289291", "202603171610071188", "202603171753509654", "202603171638023229", "202603171707567855", "202603171633592455", "202603171753146128", "202603171808167281", "202603171657049869", "202603171717027225", "202603171720002131", "202603171724353115", "202603140959588453", "202603171725534379", "202603171633428380", "202603171642061107", "202603171651343111", "202603171528529975", "202511222048006265", "202603171810439711", "202603171722486650", "202603171735498787", "202603171724184062", "202603171726423685", "202603171123205174", "202603171821396794", "202603171809423918", "202603121127423276", "202603171639385171", "202603171821493560", "202603171719278277", "202603171646502848", "202603171633049375", "202603171742512690", "202603171622299622", "202603171725488097", "202603171752566876", "202603171818486265", "202603171715301136", "202603171553503819", "202603171806544458", "202603171529325208", "202603171756394394", "202603161700407694", "202603171758446886", "202603171621501358", "202603171744543689", "202603131048046481", "202603121844438578", "202603111719122334", "202603171757475220", "202603171744275139", "202603171735035470", "202603171621581824", "202603171746048999", "202603171731401407", "202603171817562763", "202603171735545248", "202603171623403056", "202603171807109386"); // for (String orderNumber : orderNumbers) { // List userMoneyDetails = userMoneyDetailsDao.findByTitle(orderNumber); // if (CollUtil.isNotEmpty(userMoneyDetails)) { // for (UserMoneyDetails userMoneyDetail : userMoneyDetails) { // System.out.println(userMoneyDetail.getId() + "," + userMoneyDetail.getContent()); // } // } // } } public static void main(String[] args) throws Exception { WechatPayConfig wechatMchConfig = WechatPayConfig.builder() .appId("wx45ab46867002aa0b") .mchId("866360132440001") .mchKey("B9591F61B1944A93938DD3DFA9070763") .h5Url("https://mxys.chuanghai-tech.com") .build(); RhtQrcodePayApi qrcodePay = new RhtQrcodePayApi(wechatMchConfig.getMchId(), wechatMchConfig.getMchKey(), "https://api.ekbuyclub.com"); String orderNumberStr = "118702260413005915377980" ; for (String orderNumber : orderNumberStr.split(",")) { QrcodeQueryRequestBean qqrb = new QrcodeQueryRequestBean(); // qqrb.setTraceno(orderNumber);// 商户流水号 qqrb.setRefno(orderNumber);// 商户流水号 QrcodeQueryResponseBean response2 = qrcodePay.query(qqrb); System.out.println("订单【" + orderNumber + "】查询响应2" + response2); String respCode = response2.getRespCode(); if ("0".equals(respCode)) { System.out.println("订单【" + orderNumber + "】未支付2"); } else if ("1".equals(respCode)) { System.out.println("订单【" + orderNumber + "】已经支付2"); } } } @Test public void test3() { // Integer orderId=2201878; // TbOrder tbOrder = appOrderDao.selectById(orderId); // String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); // TbIndent indent = tbIndentService.getOne(new QueryWrapper().eq("order_id", orderId)); // // log.info("订单id【{}】,开始计算商户应得金额", orderId); // // GoodsShop goodsShop = shopMessageService.selectShopId(tbOrder.getShopId()); // 计算商户应得金额 // BigDecimal shopRate = goodsShop.getShopRate(); // 商家抽拥比例 BigDecimal shopRate = new BigDecimal(0.955); // BigDecimal sumMoney = tbOrder.getPayMoney(); // 订单实付金额 BigDecimal sumMoney = new BigDecimal(44.6); // 当前无优惠券 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(); errandMoney = new BigDecimal(1.00); // sumMoney = sumMoney.subtract(tbOrder.getErrandMoney()); sumMoney = sumMoney.subtract(errandMoney); // } 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); // 商家配送短信服务费 BigDecimal smsSendMoney = BigDecimal.ZERO; // if (tbOrder.getAutoSendOrder() != null && tbOrder.getAutoSendOrder() == 1) { // // 查询短信发送结果 // if (ObjectUtil.isNotNull(indent)) { // TbIndentSmsSendLog smsSendLog = smsSendLogService.getSendSuccessByOrderId(indent.getIndentId()); // if (ObjectUtil.isNotNull(smsSendLog)) { // // 查询短信发送费用 // CommonInfo commonInfo = commonInfoService.findOne(421); // smsSendMoney = new BigDecimal(commonInfo.getValue()); // // // 店铺收入-短信费用 // shopMoney = shopMoney.subtract(smsSendMoney); // } // } // } // 这里再判断 是否是商家优惠券 如果是商家优惠券 这笔钱商家承担 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(); // 当前订单优惠金额 activityDiscountAmount = new BigDecimal(2.000000); // } // if (tbOrder.getAutoSendOrder() != null && tbOrder.getAutoSendOrder() == 1) { // //如果达到商家满减 则商家不加上配送费 // if (!"本单已达到商家满减金额,跑腿费由商家承担".equals(tbOrder.getErrandMoneyIsShop())) { // shopMoney = shopMoney.add(tbOrder.getErrandMoney()); // } // } else { // /*if("本单已达到商家满减金额,跑腿费由商家承担".equals(tbOrder.getErrandMoneyIsShop())){ // shopMoney=shopMoney.subtract(tbOrder.getErrandMoney()); // }*/ // } StringBuffer contentBuffer = new StringBuffer(); BigDecimal rider = new BigDecimal(0); // 当前是骑手配送,并且额外配送费是0 // if (ObjectUtils.isNotEmpty(tbOrder.getOrderTypeExtra()) && tbOrder.getOrderTypeExtra() == 2) { // 获取骑手额外配送费 // 配送费大于等于1.5就不需要骑手额外配送费 // if (tbOrder.getErrandMoney().doubleValue()<1.5) { // CommonInfo commonInfo = commonInfoService.findOne(443); // if (ObjectUtils.isNotEmpty(commonInfo)) { // rider = rider.add(new BigDecimal(commonInfo.getValue())); // shopMoney = shopMoney.subtract(rider); // } //// } // log.info("订单id【{}】,骑手额外配送费【{}】", orderId, rider); // } // tbOrder.setShopIncomeMoney(shopMoney); System.out.println("shop_income_money商家本单收入 = " + shopMoney); // log.info("订单id【{}】,商户应得金额计算完毕", orderId); // log.info("订单id【{}】,开始添加商户用户钱包收入记录", orderId); // 添加商户用户钱包收入记录 UserMoneyDetails userMoneyDetails1 = new UserMoneyDetails(); // userMoneyDetails1.setShopId(goodsShop.getShopId()); userMoneyDetails1.setShopId(438L); userMoneyDetails1.setTitle("商户订单收入,订单号:" + "202604121145576836"); // 订单金额 // BigDecimal orderAmount = tbOrder.getPayMoney().add(couponMoney).add(activityDiscountAmount); BigDecimal orderAmount = new BigDecimal(44.60).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(",其中"); contentBuffer.append(",用户实付金额:").append(new BigDecimal(44.60)).append(",其中"); // if (tbOrder.getOrderType() != 1) { if (2 != 1) { // contentBuffer.append("跑腿费:").append(errandMoney.setScale(2, BigDecimal.ROUND_DOWN)).append("(").append(tbOrder.getErrandMoneyIsShop()).append(")").append(","); contentBuffer.append("跑腿费:").append(errandMoney.setScale(2, BigDecimal.ROUND_DOWN)).append("(").append("商家未开启配送费满减,跑腿费由用户承担").append(")").append(","); } // contentBuffer.append("特殊地址跑腿费:").append(tbOrder.getInsideDeliveryFee().setScale(2, BigDecimal.ROUND_DOWN)).append(","); contentBuffer.append("特殊地址跑腿费:").append(new BigDecimal(0.000000).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(","); // } // 会员优惠 // if (StrUtil.equals(tbOrder.getVipPromotion(), Constant.YES)) { if (StrUtil.equals("0", Constant.YES)) { CommonInfo commonInfo = commonInfoService.findOne(444); contentBuffer.append("会员优惠金额:").append(commonInfo.getValue()).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(format); userMoneyDetails1.setState(2); System.out.println("userMoneyDetails1 = " + userMoneyDetails1); // log.info("订单id【{}】,商户用户钱包收入记录新增成功", orderId); //将用户支付的金额转入商户用户钱包 } }