OrderTest.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. import cn.hutool.core.collection.CollUtil;
  2. import cn.hutool.core.util.ObjectUtil;
  3. import cn.hutool.core.util.StrUtil;
  4. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  5. import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
  6. import com.ekyong.www.pay.pay.qrcode.api.RhtQrcodePayApi;
  7. import com.ekyong.www.pay.pay.qrcode.bean.QrcodeQueryRequestBean;
  8. import com.ekyong.www.pay.pay.qrcode.bean.QrcodeQueryResponseBean;
  9. import com.sqx.SqxApplication;
  10. import com.sqx.common.utils.Constant;
  11. import com.sqx.common.utils.DateUtils;
  12. import com.sqx.common.utils.RedisUtils;
  13. import com.sqx.common.utils.Result;
  14. import com.sqx.modules.activity.entity.ActivityPartRecord;
  15. import com.sqx.modules.activity.service.ActivityPartRecordService;
  16. import com.sqx.modules.app.dao.UserMoneyDetailsDao;
  17. import com.sqx.modules.app.entity.UserMoneyDetails;
  18. import com.sqx.modules.app.service.UserMoneyDetailsService;
  19. import com.sqx.modules.app.service.UserMoneyService;
  20. import com.sqx.modules.common.entity.CommonInfo;
  21. import com.sqx.modules.common.service.CommonInfoService;
  22. import com.sqx.modules.coupon.dao.TbCouponUserDao;
  23. import com.sqx.modules.coupon.entity.TbCouponUser;
  24. import com.sqx.modules.errand.entity.TbIndent;
  25. import com.sqx.modules.errand.entity.TbIndentSmsSendLog;
  26. import com.sqx.modules.errand.service.TbIndentService;
  27. import com.sqx.modules.errand.service.TbIndentSmsSendLogService;
  28. import com.sqx.modules.goods.entity.GoodsShop;
  29. import com.sqx.modules.goods.service.GoodsShopService;
  30. import com.sqx.modules.order.dao.AppOrderDao;
  31. import com.sqx.modules.order.entity.TbOrder;
  32. import com.sqx.modules.order.service.AppOrderService;
  33. import com.sqx.modules.pay.config.WechatPayConfig;
  34. import com.sqx.modules.pay.service.WxService;
  35. import com.sqx.modules.shop.service.ShopMessageService;
  36. import com.sqx.scheduler.order.OrderScheduler;
  37. import lombok.extern.slf4j.Slf4j;
  38. import org.junit.Test;
  39. import org.junit.runner.RunWith;
  40. import org.springframework.beans.factory.annotation.Autowired;
  41. import org.springframework.boot.test.context.SpringBootTest;
  42. import org.springframework.test.context.junit4.SpringRunner;
  43. import javax.annotation.Resource;
  44. import java.math.BigDecimal;
  45. import java.text.SimpleDateFormat;
  46. import java.util.Arrays;
  47. import java.util.Date;
  48. import java.util.List;
  49. import java.util.Map;
  50. /**
  51. * @author : codingliang
  52. * @date : 2024-09-10 16:24
  53. */
  54. @Slf4j
  55. @RunWith(SpringRunner.class)
  56. @SpringBootTest(classes = SqxApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
  57. public class OrderTest {
  58. @Resource
  59. private AppOrderService appOrderService;
  60. @Resource
  61. private ShopMessageService shopMessageService;
  62. @Resource
  63. private TbCouponUserDao tbCouponUserDao;
  64. @Resource
  65. private ActivityPartRecordService activityPartRecordService;
  66. @Resource
  67. private CommonInfoService commonInfoService;
  68. @Resource
  69. private UserMoneyDetailsDao userMoneyDetailsDao;
  70. @Resource
  71. private UserMoneyDetailsService userMoneyDetailsService;
  72. @Resource
  73. private UserMoneyService userMoneyService;
  74. @Resource
  75. private OrderScheduler orderScheduler;
  76. @Resource
  77. private WxService wxService;
  78. @Resource
  79. private RedisUtils redisUtils;
  80. @Autowired
  81. private AppOrderDao appOrderDao;
  82. @Autowired
  83. private AppOrderService orderService;
  84. @Autowired
  85. private GoodsShopService goodsShopService;
  86. @Autowired
  87. private TbIndentSmsSendLogService smsSendLogService;
  88. @Autowired
  89. private TbIndentService tbIndentService;
  90. @Test
  91. public void test() {
  92. TbOrder tbOrder = appOrderService.selectOrderByNum("202603111524117723");
  93. orderService.subStock(tbOrder);
  94. }
  95. @Test
  96. public void test2() {
  97. List<String> orderNumbers = Arrays.asList("202603171658527850",
  98. "202603171619351849",
  99. "202603171710572245",
  100. "202603171714048452",
  101. "202603171638169334",
  102. "202603171630378942",
  103. "202603171748451859",
  104. "202603171701106897",
  105. "202603171650405141",
  106. "202603171620564497",
  107. "202603171642345788",
  108. "202603171749291525",
  109. "202603171623034174",
  110. "202603171737258426",
  111. "202603171635097793",
  112. "202603171722291718",
  113. "202603171758527104",
  114. "202601061658273032",
  115. "202603171702219075",
  116. "202603061751057889",
  117. "202603171756291948",
  118. "202603171759418369",
  119. "202603171721108130",
  120. "202603171719358825",
  121. "202603161117352549",
  122. "202603171740425528",
  123. "202603171708442864",
  124. "202603161746295701",
  125. "202603171805259872",
  126. "202603171719246998",
  127. "202603171644476707",
  128. "202603171709029503",
  129. "202603171644542515",
  130. "202603151407369659",
  131. "202603171806023314",
  132. "202603171804086449",
  133. "202603171621529775",
  134. "202601131602524734",
  135. "202603171724289097",
  136. "202603171802209739",
  137. "202603171801064578",
  138. "202603171638089608",
  139. "202603151825132239",
  140. "202603071224354624",
  141. "202603171721285003",
  142. "202603171649493851",
  143. "202603171741425727",
  144. "202603171820348387",
  145. "202603171623508052",
  146. "202603171731148811",
  147. "202603171706139841",
  148. "202603141014225288",
  149. "202603171645301175",
  150. "202603171738077815",
  151. "202603171631472362",
  152. "202603161808435542",
  153. "202603171621406667",
  154. "202603171709198659",
  155. "202603171713048654",
  156. "202603171623196547",
  157. "202603171614043059",
  158. "202603171811466449",
  159. "202603171622048052",
  160. "202603171725342877",
  161. "202603171713225462",
  162. "202603171631307251",
  163. "202603171751242823",
  164. "202603171727426485",
  165. "202603171705516972",
  166. "202603171652208569",
  167. "202603171731103142",
  168. "202603171645548122",
  169. "202603171618168512",
  170. "202603171714322093",
  171. "202603101702495228",
  172. "202603171714424020",
  173. "202511191950472470",
  174. "202603171727504578",
  175. "202603171632565021",
  176. "202603171618507259",
  177. "202603171629126621",
  178. "202603171541583648",
  179. "202603171738311378",
  180. "202603171624238458",
  181. "202510141117431653",
  182. "202603171749365333",
  183. "202603171629044014",
  184. "202603171720331910",
  185. "202603171538471740",
  186. "202603171758378816",
  187. "202603170938553359",
  188. "202603171708297626",
  189. "202603141545452583",
  190. "202603171703332189",
  191. "202603171622568889",
  192. "202603061957284523",
  193. "202603171627058425",
  194. "202603171645356441",
  195. "202603171539219622",
  196. "202603171746039921",
  197. "202603171650566927",
  198. "202603171708117590",
  199. "202603171627003546",
  200. "202603171648503963",
  201. "202603171652486958",
  202. "202603171624083278",
  203. "202603171634448770",
  204. "202603171626482161",
  205. "202603171749504957",
  206. "202603171755208256",
  207. "202603171728162921",
  208. "202603171730195807",
  209. "202603171643307822",
  210. "202603171627265421",
  211. "202603171724101591",
  212. "202603141107296175",
  213. "202603171539319893",
  214. "202603171627236101",
  215. "202603171639232165",
  216. "202603171655131079",
  217. "202603171657055630",
  218. "202603171543323001",
  219. "202603171735113067",
  220. "202603171723286067",
  221. "202603171734214261",
  222. "202603171712446392",
  223. "202603161114176003",
  224. "202603171621492177",
  225. "202603171652289291",
  226. "202603171610071188",
  227. "202603171753509654",
  228. "202603171638023229",
  229. "202603171707567855",
  230. "202603171633592455",
  231. "202603171753146128",
  232. "202603171808167281",
  233. "202603171657049869",
  234. "202603171717027225",
  235. "202603171720002131",
  236. "202603171724353115",
  237. "202603140959588453",
  238. "202603171725534379",
  239. "202603171633428380",
  240. "202603171642061107",
  241. "202603171651343111",
  242. "202603171528529975",
  243. "202511222048006265",
  244. "202603171810439711",
  245. "202603171722486650",
  246. "202603171735498787",
  247. "202603171724184062",
  248. "202603171726423685",
  249. "202603171123205174",
  250. "202603171821396794",
  251. "202603171809423918",
  252. "202603121127423276",
  253. "202603171639385171",
  254. "202603171821493560",
  255. "202603171719278277",
  256. "202603171646502848",
  257. "202603171633049375",
  258. "202603171742512690",
  259. "202603171622299622",
  260. "202603171725488097",
  261. "202603171752566876",
  262. "202603171818486265",
  263. "202603171715301136",
  264. "202603171553503819",
  265. "202603171806544458",
  266. "202603171529325208",
  267. "202603171756394394",
  268. "202603161700407694",
  269. "202603171758446886",
  270. "202603171621501358",
  271. "202603171744543689",
  272. "202603131048046481",
  273. "202603121844438578",
  274. "202603111719122334",
  275. "202603171757475220",
  276. "202603171744275139",
  277. "202603171735035470",
  278. "202603171621581824",
  279. "202603171746048999",
  280. "202603171731401407",
  281. "202603171817562763",
  282. "202603171735545248",
  283. "202603171623403056",
  284. "202603171807109386");
  285. // for (String orderNumber : orderNumbers) {
  286. // List<UserMoneyDetails> userMoneyDetails = userMoneyDetailsDao.findByTitle(orderNumber);
  287. // if (CollUtil.isNotEmpty(userMoneyDetails)) {
  288. // for (UserMoneyDetails userMoneyDetail : userMoneyDetails) {
  289. // System.out.println(userMoneyDetail.getId() + "," + userMoneyDetail.getContent());
  290. // }
  291. // }
  292. // }
  293. }
  294. public static void main(String[] args) throws Exception {
  295. WechatPayConfig wechatMchConfig = WechatPayConfig.builder()
  296. .appId("wx45ab46867002aa0b")
  297. .mchId("866360132440001")
  298. .mchKey("B9591F61B1944A93938DD3DFA9070763")
  299. .h5Url("https://mxys.chuanghai-tech.com")
  300. .build();
  301. RhtQrcodePayApi qrcodePay = new RhtQrcodePayApi(wechatMchConfig.getMchId(), wechatMchConfig.getMchKey(), "https://api.ekbuyclub.com");
  302. String orderNumberStr =
  303. "118702260608006383131158"
  304. ;
  305. for (String orderNumber : orderNumberStr.split(",")) {
  306. QrcodeQueryRequestBean qqrb = new QrcodeQueryRequestBean();
  307. // qqrb.setTraceno(orderNumber);// 商户流水号
  308. qqrb.setRefno(orderNumber);// 商户流水号
  309. QrcodeQueryResponseBean response2 = qrcodePay.query(qqrb);
  310. System.out.println("订单【" + orderNumber + "】查询响应2" + response2);
  311. String respCode = response2.getRespCode();
  312. if ("0".equals(respCode)) {
  313. System.out.println("订单【" + orderNumber + "】未支付2");
  314. } else if ("1".equals(respCode)) {
  315. System.out.println("订单【" + orderNumber + "】已经支付2");
  316. }
  317. }
  318. }
  319. @Test
  320. public void test3() {
  321. // Integer orderId=2201878;
  322. // TbOrder tbOrder = appOrderDao.selectById(orderId);
  323. // String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
  324. // TbIndent indent = tbIndentService.getOne(new QueryWrapper<TbIndent>().eq("order_id", orderId));
  325. //
  326. // log.info("订单id【{}】,开始计算商户应得金额", orderId);
  327. //
  328. // GoodsShop goodsShop = shopMessageService.selectShopId(tbOrder.getShopId());
  329. // 计算商户应得金额
  330. // BigDecimal shopRate = goodsShop.getShopRate();
  331. // 商家抽拥比例
  332. BigDecimal shopRate = new BigDecimal(0.955);
  333. // BigDecimal sumMoney = tbOrder.getPayMoney();
  334. // 订单实付金额
  335. BigDecimal sumMoney = new BigDecimal(44.6);
  336. // 当前无优惠券
  337. BigDecimal couponMoney = BigDecimal.ZERO;
  338. Long shopIds = -1L;
  339. // if (tbOrder.getCouponId() != null) {
  340. // TbCouponUser tbCouponUser = tbCouponUserDao.selectById(tbOrder.getCouponId());
  341. // sumMoney = tbOrder.getPayMoney().add(tbCouponUser.getMoney());
  342. // couponMoney = tbCouponUser.getMoney();
  343. // shopIds = tbCouponUser.getShopId();
  344. // }
  345. BigDecimal errandMoney = BigDecimal.ZERO;
  346. // if (tbOrder.getOrderType() != 1) {
  347. //判断是否达到商家满减 如果达到商家满减 跑腿费让商家承担
  348. // if (tbOrder.getAutoSendOrder() != null && tbOrder.getAutoSendOrder() == 0) {
  349. // errandMoney = tbOrder.getErrandMoney();
  350. errandMoney = new BigDecimal(1.00);
  351. // sumMoney = sumMoney.subtract(tbOrder.getErrandMoney());
  352. sumMoney = sumMoney.subtract(errandMoney);
  353. // } else {
  354. // sumMoney = sumMoney.subtract(tbOrder.getErrandMoney());
  355. // errandMoney = tbOrder.getErrandMoney();
  356. // }
  357. // }
  358. // 再减去校内配送费
  359. // sumMoney = sumMoney.subtract(tbOrder.getInsideDeliveryFee());
  360. // 店铺收入
  361. BigDecimal shopMoney = sumMoney.multiply(shopRate);
  362. shopMoney = shopMoney.setScale(2, BigDecimal.ROUND_DOWN);
  363. BigDecimal pingRate = sumMoney.subtract(shopMoney);
  364. // 商家配送短信服务费
  365. BigDecimal smsSendMoney = BigDecimal.ZERO;
  366. // if (tbOrder.getAutoSendOrder() != null && tbOrder.getAutoSendOrder() == 1) {
  367. // // 查询短信发送结果
  368. // if (ObjectUtil.isNotNull(indent)) {
  369. // TbIndentSmsSendLog smsSendLog = smsSendLogService.getSendSuccessByOrderId(indent.getIndentId());
  370. // if (ObjectUtil.isNotNull(smsSendLog)) {
  371. // // 查询短信发送费用
  372. // CommonInfo commonInfo = commonInfoService.findOne(421);
  373. // smsSendMoney = new BigDecimal(commonInfo.getValue());
  374. //
  375. // // 店铺收入-短信费用
  376. // shopMoney = shopMoney.subtract(smsSendMoney);
  377. // }
  378. // }
  379. // }
  380. // 这里再判断 是否是商家优惠券 如果是商家优惠券 这笔钱商家承担
  381. if (shopIds != -1 && shopIds != 0) {
  382. shopMoney = shopMoney.subtract(couponMoney);
  383. }
  384. // 判断订单是否参与活动,如果参与活动,则优惠金额由商家承担
  385. // ActivityPartRecord activityPartRecord = activityPartRecordService.getByOrderId(tbOrder.getOrderId());
  386. BigDecimal activityDiscountAmount = BigDecimal.ZERO;
  387. // if (ObjectUtil.isNotNull(activityPartRecord)) {
  388. // activityDiscountAmount = activityPartRecord.getDiscountAmount();
  389. // 当前订单优惠金额
  390. activityDiscountAmount = new BigDecimal(2.000000);
  391. // }
  392. // if (tbOrder.getAutoSendOrder() != null && tbOrder.getAutoSendOrder() == 1) {
  393. // //如果达到商家满减 则商家不加上配送费
  394. // if (!"本单已达到商家满减金额,跑腿费由商家承担".equals(tbOrder.getErrandMoneyIsShop())) {
  395. // shopMoney = shopMoney.add(tbOrder.getErrandMoney());
  396. // }
  397. // } else {
  398. // /*if("本单已达到商家满减金额,跑腿费由商家承担".equals(tbOrder.getErrandMoneyIsShop())){
  399. // shopMoney=shopMoney.subtract(tbOrder.getErrandMoney());
  400. // }*/
  401. // }
  402. StringBuffer contentBuffer = new StringBuffer();
  403. BigDecimal rider = new BigDecimal(0);
  404. // 当前是骑手配送,并且额外配送费是0
  405. // if (ObjectUtils.isNotEmpty(tbOrder.getOrderTypeExtra()) && tbOrder.getOrderTypeExtra() == 2) {
  406. // 获取骑手额外配送费
  407. // 配送费大于等于1.5就不需要骑手额外配送费
  408. // if (tbOrder.getErrandMoney().doubleValue()<1.5) {
  409. // CommonInfo commonInfo = commonInfoService.findOne(443);
  410. // if (ObjectUtils.isNotEmpty(commonInfo)) {
  411. // rider = rider.add(new BigDecimal(commonInfo.getValue()));
  412. // shopMoney = shopMoney.subtract(rider);
  413. // }
  414. //// }
  415. // log.info("订单id【{}】,骑手额外配送费【{}】", orderId, rider);
  416. // }
  417. // tbOrder.setShopIncomeMoney(shopMoney);
  418. System.out.println("shop_income_money商家本单收入 = " + shopMoney);
  419. // log.info("订单id【{}】,商户应得金额计算完毕", orderId);
  420. // log.info("订单id【{}】,开始添加商户用户钱包收入记录", orderId);
  421. // 添加商户用户钱包收入记录
  422. UserMoneyDetails userMoneyDetails1 = new UserMoneyDetails();
  423. // userMoneyDetails1.setShopId(goodsShop.getShopId());
  424. userMoneyDetails1.setShopId(438L);
  425. userMoneyDetails1.setTitle("商户订单收入,订单号:" + "202604121145576836");
  426. // 订单金额
  427. // BigDecimal orderAmount = tbOrder.getPayMoney().add(couponMoney).add(activityDiscountAmount);
  428. BigDecimal orderAmount = new BigDecimal(44.60).add(couponMoney).add(activityDiscountAmount);
  429. contentBuffer.append("订单金额:").append(orderAmount.setScale(2, BigDecimal.ROUND_DOWN));
  430. if (!couponMoney.equals(BigDecimal.ZERO)) {
  431. contentBuffer.append(",优惠券金额:").append(couponMoney.setScale(2, BigDecimal.ROUND_DOWN));
  432. }
  433. if (!activityDiscountAmount.equals(BigDecimal.ZERO)) {
  434. contentBuffer.append(",活动优惠金额:").append(activityDiscountAmount.setScale(2, BigDecimal.ROUND_DOWN));
  435. }
  436. // contentBuffer.append(",用户实付金额:").append(tbOrder.getPayMoney()).append(",其中");
  437. contentBuffer.append(",用户实付金额:").append(new BigDecimal(44.60)).append(",其中");
  438. // if (tbOrder.getOrderType() != 1) {
  439. if (2 != 1) {
  440. // contentBuffer.append("跑腿费:").append(errandMoney.setScale(2, BigDecimal.ROUND_DOWN)).append("(").append(tbOrder.getErrandMoneyIsShop()).append(")").append(",");
  441. contentBuffer.append("跑腿费:").append(errandMoney.setScale(2, BigDecimal.ROUND_DOWN)).append("(").append("商家未开启配送费满减,跑腿费由用户承担").append(")").append(",");
  442. }
  443. // contentBuffer.append("特殊地址跑腿费:").append(tbOrder.getInsideDeliveryFee().setScale(2, BigDecimal.ROUND_DOWN)).append(",");
  444. contentBuffer.append("特殊地址跑腿费:").append(new BigDecimal(0.000000).setScale(2, BigDecimal.ROUND_DOWN)).append(",");
  445. contentBuffer.append("平台服务费:").append(pingRate.setScale(2, BigDecimal.ROUND_DOWN)).append(",");
  446. contentBuffer.append("短信服务费:").append(smsSendMoney.setScale(2, BigDecimal.ROUND_DOWN)).append(",");
  447. // if (ObjectUtils.isNotEmpty(tbOrder.getOrderTypeExtra()) && tbOrder.getOrderTypeExtra() == 2) {
  448. contentBuffer.append("骑手额外配送费:").append(rider.setScale(2, BigDecimal.ROUND_DOWN)).append(",");
  449. // }
  450. // 会员优惠
  451. // if (StrUtil.equals(tbOrder.getVipPromotion(), Constant.YES)) {
  452. if (StrUtil.equals("0", Constant.YES)) {
  453. CommonInfo commonInfo = commonInfoService.findOne(444);
  454. contentBuffer.append("会员优惠金额:").append(commonInfo.getValue()).append("元,");
  455. }
  456. contentBuffer.append("到账金额:").append(shopMoney.setScale(2, BigDecimal.ROUND_DOWN));
  457. if (shopIds == 0) {
  458. contentBuffer.append("(本单为平台优惠券,平台补贴)");
  459. } else if (shopIds != -1) {
  460. contentBuffer.append("(本单为商家优惠券,商家补贴)");
  461. }
  462. userMoneyDetails1.setContent(contentBuffer.toString());
  463. userMoneyDetails1.setType(1);
  464. userMoneyDetails1.setClassify(3);
  465. userMoneyDetails1.setMoney(shopMoney);
  466. // userMoneyDetails1.setCreateTime(format);
  467. userMoneyDetails1.setState(2);
  468. System.out.println("userMoneyDetails1 = " + userMoneyDetails1);
  469. // log.info("订单id【{}】,商户用户钱包收入记录新增成功", orderId);
  470. //将用户支付的金额转入商户用户钱包
  471. }
  472. }