OrderCommonService.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. package com.caimei365.order.components;
  2. import com.caimei365.order.mapper.BaseMapper;
  3. import com.caimei365.order.mapper.OrderCommonMapper;
  4. import com.caimei365.order.model.enums.OrderStatus;
  5. import com.caimei365.order.model.enums.ReceivablesType;
  6. import com.caimei365.order.model.vo.*;
  7. import com.caimei365.order.utils.ImageUtil;
  8. import com.caimei365.order.utils.MathUtil;
  9. import com.google.common.util.concurrent.AtomicDouble;
  10. import lombok.extern.slf4j.Slf4j;
  11. import org.apache.commons.lang3.StringUtils;
  12. import org.springframework.beans.factory.annotation.Value;
  13. import org.springframework.stereotype.Service;
  14. import javax.annotation.Resource;
  15. import java.util.*;
  16. import java.util.concurrent.atomic.AtomicInteger;
  17. import java.util.stream.Collectors;
  18. /**
  19. * Description
  20. *
  21. * @author : Charles
  22. * @date : 2021/7/26
  23. */
  24. @Slf4j
  25. @Service
  26. public class OrderCommonService {
  27. @Value("${caimei.wwwDomain}")
  28. private String domain;
  29. @Resource
  30. private OrderCommonMapper orderCommonMapper;
  31. @Resource
  32. private BaseMapper baseMapper;
  33. /**
  34. * 设置订单状态
  35. */
  36. public void setOrderStatus(OrderVo order) {
  37. // 111, 待付待收待发
  38. if (OrderStatus.UNRECEIVED_AND_UNSHIPPED.getCode() == order.getStatus() && 1 == order.getPayStatus()) {
  39. order.setStatus(111);
  40. }
  41. // 判断交易全退情况下,是否发过货,77,交易全退可以查看物流
  42. int logisticsCount = orderCommonMapper.countLogisticsBatch(order.getOrderId());
  43. if (OrderStatus.FULL_RETURNED.getCode() == order.getStatus() && logisticsCount > 0) {
  44. order.setStatus(77);
  45. }
  46. // 判断二手订单情况下,若部分付款和已付款,排除退货/款的情况,且未确认打款供应商,10,添加确认打款供应商按钮
  47. if (1 == order.getSecondHandOrderFlag() && 0 == order.getRefundType() && 0 == order.getAffirmPaymentFlag()) {
  48. if (order.getStatus().toString().startsWith("2") || order.getStatus().toString().startsWith("3")) {
  49. // 之前是 “00”, 现在int 10, 前端显示按钮用
  50. order.setAffirmPaymentFlag(10);
  51. }
  52. }
  53. }
  54. /**
  55. * 设置子订单数据
  56. */
  57. public void getShopOrderData(OrderVo order) {
  58. // 子订单
  59. if (StringUtils.isEmpty(order.getShopOrderIds())) {
  60. return;
  61. }
  62. Integer organizeId = orderCommonMapper.getOrganizeId(order.getOrderId());
  63. String[] shopOrderIdArr = order.getShopOrderIds().split(",");
  64. List<String> shopOrderIds = Arrays.asList(shopOrderIdArr);
  65. List<ShopOrderVo> shopOrderList = orderCommonMapper.getShopOrderList(shopOrderIds);
  66. shopOrderList.forEach(shopOrder -> {
  67. // 冷链商品类型
  68. List<Integer> arrList = new ArrayList<>();
  69. // 店铺促销活动
  70. PromotionsVo shopPromotion = null;
  71. if (null != shopOrder.getOrderPromotionsId() && shopOrder.getOrderPromotionsId() > 0) {
  72. shopPromotion = orderCommonMapper.getOrderPromotionsById(shopOrder.getOrderPromotionsId());
  73. shopOrder.setShopPromotion(shopPromotion);
  74. }
  75. List<OrderProductVo> orderProductList = orderCommonMapper.getShopOrderProduct(shopOrder.getShopOrderId());
  76. orderProductList.removeIf(Objects::isNull);
  77. // 冷链商品判定
  78. List<Integer> collect = orderProductList.stream().map(OrderProductVo::getProductId).collect(Collectors.toList());
  79. collect.removeIf(c -> c == 999);
  80. if (collect.stream().allMatch(c -> c == 7536)) {
  81. arrList.add(1);
  82. } else if (!collect.contains(7536)) {
  83. arrList.add(2);
  84. } else {
  85. arrList.add(3);
  86. }
  87. orderProductList.forEach(orderProduct -> {
  88. // 不含税可开票商品,单价/折后单价在原基础上加上税费
  89. boolean taxFlag = false;
  90. if (0 == organizeId) {
  91. taxFlag = (Integer.valueOf(0).equals(orderProduct.getIncludedTax()) && (Integer.valueOf(1).equals(orderProduct.getInvoiceType()) || Integer.valueOf(2).equals(orderProduct.getInvoiceType())));
  92. }
  93. if (taxFlag) {
  94. Double valueTax = MathUtil.div(MathUtil.mul(orderProduct.getPrice(), orderProduct.getTaxRate()), 100).doubleValue();
  95. orderProduct.setPrice(MathUtil.add(orderProduct.getPrice(), valueTax).doubleValue());
  96. orderProduct.setDiscountPrice(MathUtil.add(orderProduct.getDiscountPrice(), orderProduct.getAddedValueTax()).doubleValue());
  97. }
  98. orderProduct.setImage(ImageUtil.getImageUrl("product", orderProduct.getImage(), domain));
  99. // 查询订单下商品的促销活动
  100. if (null != orderProduct.getOrderPromotionsId() && orderProduct.getOrderPromotionsId() > 0) {
  101. PromotionsVo promotions = orderCommonMapper.getOrderPromotionsById(orderProduct.getOrderPromotionsId());
  102. if (null != promotions) {
  103. if (1 == promotions.getType() && 1 == promotions.getMode()) {
  104. // 单品优惠价取sku的优惠价
  105. Double touchPrice = baseMapper.getTouchPriceBySku(orderProduct.getSkuId(),promotions.getId());
  106. promotions.setTouchPrice(touchPrice);
  107. }
  108. if (taxFlag && Integer.valueOf(1).equals(promotions.getType()) && Integer.valueOf(1).equals(promotions.getMode())) {
  109. promotions.setTouchPrice(MathUtil.add(promotions.getTouchPrice(), MathUtil.div(MathUtil.mul(promotions.getTouchPrice(), orderProduct.getTaxRate()), 100)).doubleValue());
  110. }
  111. orderProduct.setProductPromotion(promotions);
  112. }
  113. }
  114. // 超级会员优惠商品设置优惠标签
  115. if (null != orderProduct.getSvipPriceFlag() && 1 == orderProduct.getSvipPriceFlag()) {
  116. if (1 == orderProduct.getSvipPriceType()) {
  117. orderProduct.setSvipPriceTag(MathUtil.div(orderProduct.getSvipDiscount(), 10, 1) + "折");
  118. } else if (2 == orderProduct.getSvipPriceType()) {
  119. orderProduct.setSvipPriceTag("¥" + orderProduct.getDiscountPrice());
  120. }
  121. }
  122. });
  123. // 冷链运输费 -- 联合丽格
  124. if (null != shopOrder.getIsColdChina() && 1 == shopOrder.getIsColdChina()) {
  125. shopOrder.setColdChina(700.00d);
  126. } else {
  127. shopOrder.setColdChina(0.00d);
  128. }
  129. // 拼接运费信息--联合丽格
  130. if (null != shopOrder.getColdChina()) {
  131. String open = "";
  132. String close = "";
  133. if (shopOrder.getIsColdChina()==1) {
  134. open = "(";
  135. close = ")";
  136. } else if (!arrList.stream().allMatch(c -> c == 1)) {
  137. open = "(";
  138. close = ")";
  139. } else {
  140. open = "";
  141. close = "";
  142. }
  143. if (-1 == shopOrder.getShopPostFlag()) {
  144. // 到付
  145. shopOrder.setPostageInfo("¥" + shopOrder.getShopPostFee().doubleValue() + open +(shopOrder.getIsColdChina()==1?"冷链费: ¥" + shopOrder.getColdChina().doubleValue():"") + (arrList.stream().allMatch(c -> c == 1)?"":" 其他: 到付")+close);
  146. } else if (0 == shopOrder.getShopPostFlag()) {
  147. // 包邮
  148. shopOrder.setPostageInfo("¥" + shopOrder.getShopPostFee().doubleValue() + open +(shopOrder.getIsColdChina()==1?"冷链费: ¥" + shopOrder.getColdChina().doubleValue():"") + (arrList.stream().allMatch(c -> c == 1)?"":" 其他: 包邮")+close);
  149. } else {
  150. // 有运费
  151. shopOrder.setPostageInfo("¥" + shopOrder.getShopPostFee().doubleValue() + open +(shopOrder.getIsColdChina()==1?"冷链费: ¥" + shopOrder.getColdChina().doubleValue():"") + (!arrList.stream().allMatch(c -> c == 1)?" 其他: ¥" + MathUtil.sub(order.getPostage(), order.getColdChina()).doubleValue():"") + close);
  152. }
  153. } else {
  154. shopOrder.setPostageInfo(shopOrder.getShopPostFlag() == -1?"到付":shopOrder.getShopPostFlag() == 0?"包邮":"¥" + shopOrder.getShopPostFee().doubleValue());
  155. }
  156. shopOrder.setOrderProductList(orderProductList);
  157. shopOrder.setShopLogo(ImageUtil.getImageUrl("shopLogo", shopOrder.getShopLogo(), domain));
  158. if (0 == order.getOnlinePayFlag()) {
  159. shopOrder.setObligation(MathUtil.sub(shopOrder.getRealPay(), shopOrder.getReceiptAmount()).doubleValue());
  160. }
  161. });
  162. // 过滤运费商品
  163. shopOrderList.removeIf(shopOrder -> shopOrder.getShopId() == 998);
  164. order.setShopOrderList(shopOrderList);
  165. }
  166. /**
  167. * 设置付款金额
  168. *
  169. * @param order OrderVo
  170. */
  171. public List<DiscernReceiptVo> getDiscernReceiptAndSetOrder(OrderVo order) {
  172. // 支付记录
  173. List<DiscernReceiptVo> discernReceiptList = orderCommonMapper.getDiscernReceipt(order.getOrderId(), order.getShopOrderIds());
  174. Double receiptAmount = 0d;
  175. // 订单款
  176. if (!discernReceiptList.isEmpty()) {
  177. AtomicDouble finalReceiptAmount = new AtomicDouble(0d);
  178. discernReceiptList.forEach(discernReceipt -> {
  179. finalReceiptAmount.set(MathUtil.add(finalReceiptAmount.get(), discernReceipt.getAssociateAmount()).doubleValue());
  180. if (null != discernReceipt.getPayType()) {
  181. discernReceipt.setPayTypeStr(ReceivablesType.getReceivablesType(discernReceipt.getPayType()));
  182. }
  183. });
  184. receiptAmount = finalReceiptAmount.get();
  185. } else {
  186. //返佣款
  187. if (!order.getShopOrderIds().contains(",")) {
  188. Double tempAmount = orderCommonMapper.getRebateAmountByShopOrder(Integer.parseInt(order.getShopOrderIds()));
  189. if (null != tempAmount) {
  190. order.setOnlinePayFlag(1);
  191. }
  192. }
  193. }
  194. // 判断是否可以走线上支付
  195. int offlineCount = orderCommonMapper.countOfflinePayment(order.getOrderId());
  196. if (offlineCount > 0) {
  197. order.setOnlinePayFlag(1);
  198. }
  199. // //付供应商总金额 + 默认手续费 > 订单总金额
  200. // Double payTotalFee = order.getPayTotalFee();
  201. // Double handlingFee = MathUtil.mul(payTotalFee, 0.0038, 2).doubleValue();
  202. // if (MathUtil.compare(handlingFee, 8) < 0) {
  203. // handlingFee = 8d;
  204. // }
  205. // List<Double> shouldPayShopAmount = orderCommonMapper.getShouldPayShopAmountList(order.getOrderId());
  206. // if (!shouldPayShopAmount.isEmpty()) {
  207. // AtomicDouble finalHandlingFee = new AtomicDouble(handlingFee);
  208. // shouldPayShopAmount.forEach(amount -> {
  209. // finalHandlingFee.set(MathUtil.add(finalHandlingFee.get(), amount).doubleValue());
  210. // });
  211. // handlingFee = finalHandlingFee.get();
  212. // }
  213. // if (MathUtil.compare(payTotalFee, handlingFee) < 0) {
  214. // order.setPayButton(true);
  215. // } else {
  216. // order.setPayButton(false);
  217. // }
  218. //待付总金额
  219. order.setPendingPayments(MathUtil.sub(order.getPayableAmount(), receiptAmount).doubleValue());
  220. //支付总金额
  221. order.setReceiptAmount(receiptAmount);
  222. return discernReceiptList;
  223. }
  224. /**
  225. * 设置子订单状态
  226. * shopStatus 0:待确认 1:已确认 2:交易完成 3:订单完成 4:已关闭 5:交易全退
  227. *
  228. * payStatus (付款供应商)付款状态:1待付款、2部分付款、3已付款
  229. * sendOutStatus 发货状态:1待发货、2部分发货、3已发货
  230. * receiptStatus 收款状态:1待收款、2部分收款、3已收款
  231. */
  232. public void setShopOrderStatus(ShopOrderVo shopOrderVo) {
  233. // 111, 待付待收待发
  234. if (1 == shopOrderVo.getStatus() ) {
  235. if ( 1 == shopOrderVo.getSendOutStatus() && 1 == shopOrderVo.getReceiptStatus()){
  236. shopOrderVo.setStatus(11);
  237. } else if (1 == shopOrderVo.getSendOutStatus() && 2 == shopOrderVo.getReceiptStatus()) {
  238. shopOrderVo.setStatus(12);
  239. } else if (1 == shopOrderVo.getSendOutStatus() && 3 == shopOrderVo.getReceiptStatus()) {
  240. shopOrderVo.setStatus(13);
  241. } else if (2 == shopOrderVo.getSendOutStatus() && 1 == shopOrderVo.getReceiptStatus()) {
  242. shopOrderVo.setStatus(21);
  243. } else if (2 == shopOrderVo.getSendOutStatus() && 2 == shopOrderVo.getReceiptStatus()) {
  244. shopOrderVo.setStatus(22);
  245. } else if (2 == shopOrderVo.getSendOutStatus() && 3 == shopOrderVo.getReceiptStatus()) {
  246. shopOrderVo.setStatus(23);
  247. } else if (3 == shopOrderVo.getSendOutStatus() && 1 == shopOrderVo.getReceiptStatus()) {
  248. shopOrderVo.setStatus(31);
  249. } else if (3 == shopOrderVo.getSendOutStatus() && 2 == shopOrderVo.getReceiptStatus()) {
  250. shopOrderVo.setStatus(32);
  251. } else if (3 == shopOrderVo.getSendOutStatus() && 3 == shopOrderVo.getReceiptStatus()) {
  252. shopOrderVo.setStatus(33);
  253. }
  254. }
  255. // 判断交易全退情况下,是否发过货,6,交易全退可以查看物流
  256. int logisticsCount = orderCommonMapper.countLogisticsBatchShop(shopOrderVo.getShopOrderId());
  257. if (5 == shopOrderVo.getStatus() && logisticsCount > 0) {
  258. shopOrderVo.setStatus(6);
  259. }
  260. }
  261. /**
  262. * 子订单信息
  263. * @param shopOrder
  264. */
  265. public void setShopOrderInfo(ShopOrderVo shopOrder) {
  266. if (null != shopOrder) {
  267. Integer organizeId = orderCommonMapper.getShopOrganizeId(shopOrder.getShopOrderId());
  268. // 冷链商品类型
  269. List<Integer> arrList = new ArrayList<>();
  270. // 店铺促销活动
  271. PromotionsVo shopPromotion = null;
  272. if (null != shopOrder.getOrderPromotionsId() && shopOrder.getOrderPromotionsId() > 0) {
  273. shopPromotion = orderCommonMapper.getOrderPromotionsById(shopOrder.getOrderPromotionsId());
  274. shopOrder.setShopPromotion(shopPromotion);
  275. }
  276. List<OrderProductVo> orderProductList = orderCommonMapper.getShopOrderProduct(shopOrder.getShopOrderId());
  277. orderProductList.removeIf(Objects::isNull);
  278. // 冷链商品判定
  279. List<Integer> collect = orderProductList.stream().map(OrderProductVo::getProductId).collect(Collectors.toList());
  280. collect.removeIf(c -> c == 999);
  281. if (collect.stream().allMatch(c -> c == 7536)) {
  282. arrList.add(1);
  283. } else if (!collect.contains(7536)) {
  284. arrList.add(2);
  285. } else {
  286. arrList.add(3);
  287. }
  288. orderProductList.forEach(orderProduct -> {
  289. // 不含税可开票商品,单价/折后单价在原基础上加上税费
  290. boolean taxFlag = false;
  291. if (0 == organizeId) {
  292. taxFlag = (Integer.valueOf(0).equals(orderProduct.getIncludedTax()) && (Integer.valueOf(1).equals(orderProduct.getInvoiceType()) || Integer.valueOf(2).equals(orderProduct.getInvoiceType())));
  293. }
  294. if (taxFlag) {
  295. Double valueTax = MathUtil.div(MathUtil.mul(orderProduct.getPrice(), orderProduct.getTaxRate()), 100).doubleValue();
  296. orderProduct.setPrice(MathUtil.add(orderProduct.getPrice(), valueTax).doubleValue());
  297. orderProduct.setDiscountPrice(MathUtil.add(orderProduct.getDiscountPrice(), orderProduct.getAddedValueTax()).doubleValue());
  298. }
  299. orderProduct.setImage(ImageUtil.getImageUrl("product", orderProduct.getImage(), domain));
  300. // 查询订单下商品的促销活动
  301. if (null != orderProduct.getOrderPromotionsId() && orderProduct.getOrderPromotionsId() > 0) {
  302. PromotionsVo promotions = orderCommonMapper.getOrderPromotionsById(orderProduct.getOrderPromotionsId());
  303. if (null != promotions) {
  304. if (1 == promotions.getType() && 1 == promotions.getMode()) {
  305. // 单品优惠价取sku的优惠价
  306. Double touchPrice = baseMapper.getTouchPriceBySku(orderProduct.getSkuId(),promotions.getId());
  307. promotions.setTouchPrice(touchPrice);
  308. }
  309. if (taxFlag && Integer.valueOf(1).equals(promotions.getType()) && Integer.valueOf(1).equals(promotions.getMode())) {
  310. promotions.setTouchPrice(MathUtil.add(promotions.getTouchPrice(), MathUtil.div(MathUtil.mul(promotions.getTouchPrice(), orderProduct.getTaxRate()), 100)).doubleValue());
  311. }
  312. orderProduct.setProductPromotion(promotions);
  313. }
  314. }
  315. // 超级会员优惠商品设置优惠标签
  316. if (null != orderProduct.getSvipPriceFlag() && 1 == orderProduct.getSvipPriceFlag()) {
  317. if (1 == orderProduct.getSvipPriceType()) {
  318. orderProduct.setSvipPriceTag(MathUtil.div(orderProduct.getSvipDiscount(), 10, 1) + "折");
  319. } else if (2 == orderProduct.getSvipPriceType()) {
  320. orderProduct.setSvipPriceTag("¥" + orderProduct.getDiscountPrice());
  321. }
  322. }
  323. });
  324. // 冷链运输费 -- 联合丽格
  325. if (null != shopOrder.getIsColdChina() && 1 == shopOrder.getIsColdChina()) {
  326. shopOrder.setColdChina(700.00d);
  327. } else {
  328. shopOrder.setColdChina(0.00d);
  329. }
  330. // 拼接运费信息--联合丽格
  331. if (null != shopOrder.getColdChina()) {
  332. String open = "";
  333. String close = "";
  334. if (shopOrder.getIsColdChina()==1) {
  335. open = "(";
  336. close = ")";
  337. } else if (!arrList.stream().allMatch(c -> c == 1)) {
  338. open = "(";
  339. close = ")";
  340. } else {
  341. open = "";
  342. close = "";
  343. }
  344. if (-1 == shopOrder.getShopPostFlag()) {
  345. // 到付
  346. shopOrder.setPostageInfo("¥" + MathUtil.add(shopOrder.getShopPostFee(), shopOrder.getColdChina()).doubleValue() + open +(shopOrder.getIsColdChina()==1?"冷链费: ¥" + shopOrder.getColdChina().doubleValue():"") + (arrList.stream().allMatch(c -> c == 1)?"":" 其他: 到付")+close);
  347. } else if (0 == shopOrder.getShopPostFlag()) {
  348. // 包邮
  349. shopOrder.setPostageInfo("¥" + MathUtil.add(shopOrder.getShopPostFee(), shopOrder.getColdChina()).doubleValue() + open +(shopOrder.getIsColdChina()==1?"冷链费: ¥" + shopOrder.getColdChina().doubleValue():"") + (arrList.stream().allMatch(c -> c == 1)?"":" 其他: 包邮")+close);
  350. } else {
  351. // 有运费
  352. shopOrder.setPostageInfo("¥" + MathUtil.add(shopOrder.getShopPostFee(), shopOrder.getColdChina()).doubleValue() + open +(shopOrder.getIsColdChina()==1?"冷链费: ¥" + shopOrder.getColdChina().doubleValue():"") + (!arrList.stream().allMatch(c -> c == 1)?" 其他: ¥" + shopOrder.getShopPostFee():"") + close);
  353. }
  354. } else {
  355. shopOrder.setPostageInfo(shopOrder.getShopPostFlag() == -1?"到付":shopOrder.getShopPostFlag() == 0?"包邮":"¥" + shopOrder.getShopPostFee().doubleValue());
  356. }
  357. shopOrder.setOrderProductList(orderProductList);
  358. shopOrder.setShopLogo(ImageUtil.getImageUrl("shopLogo", shopOrder.getShopLogo(), domain));
  359. //if (0 == order.getOnlinePayFlag()) {
  360. shopOrder.setObligation(MathUtil.sub(shopOrder.getRealPay(), shopOrder.getReceiptAmount()).doubleValue());
  361. //}
  362. }
  363. }
  364. /**
  365. * 设置子订单付款金额
  366. * @param shopOrderVo
  367. * @return
  368. */
  369. public List<DiscernReceiptVo> getDiscernReceiptAndSetShoporder(ShopOrderVo shopOrderVo) {
  370. // 支付记录
  371. List<DiscernReceiptVo> discernReceiptList = orderCommonMapper.getDiscernReceipt(shopOrderVo.getOrderId(), shopOrderVo.getShopOrderId().toString());
  372. Double receiptAmount = 0d;
  373. // 订单款
  374. if (!discernReceiptList.isEmpty()) {
  375. AtomicDouble finalReceiptAmount = new AtomicDouble(0d);
  376. discernReceiptList.forEach(discernReceipt -> {
  377. finalReceiptAmount.set(MathUtil.add(finalReceiptAmount.get(), discernReceipt.getAssociateAmount()).doubleValue());
  378. if (null != discernReceipt.getPayType()) {
  379. discernReceipt.setPayTypeStr(ReceivablesType.getReceivablesType(discernReceipt.getPayType()));
  380. }
  381. });
  382. receiptAmount = finalReceiptAmount.get();
  383. } else {
  384. //返佣款
  385. Double tempAmount = orderCommonMapper.getRebateAmountByShopOrder(shopOrderVo.getShopOrderId());
  386. if (null != tempAmount) {
  387. shopOrderVo.setOnlinePay(1);
  388. }
  389. }
  390. // 判断是否可以走线上支付
  391. int offlineCount = orderCommonMapper.countOfflinePaymentshopOrder(shopOrderVo.getShopOrderId());
  392. if (offlineCount > 0) {
  393. shopOrderVo.setOnlinePay(1);
  394. }
  395. //待付总金额
  396. shopOrderVo.setObligation(MathUtil.sub(shopOrderVo.getRealPay(), receiptAmount).doubleValue());
  397. //支付总金额
  398. shopOrderVo.setReceiptAmount(receiptAmount);
  399. return discernReceiptList;
  400. }
  401. /**
  402. * 设置搜索关键词历史记录
  403. *
  404. * @param userId 用户Id
  405. * @param searchWord 搜索关键词
  406. */
  407. public void setHistoryRecord(Integer userId, String searchWord) {
  408. // 初始化一个搜索关键词历史记录
  409. SearchHistoryVo historyRecord = new SearchHistoryVo();
  410. historyRecord.setUserId(userId);
  411. historyRecord.setSearchDate(new Date());
  412. historyRecord.setSearchWord(searchWord);
  413. historyRecord.setDelFlag(0);
  414. // 查询搜索关键词历史记录是否存在
  415. Integer recordId = orderCommonMapper.getSearchHistoryIdByWord(searchWord);
  416. // 保存搜索关键词历史记录
  417. if (null != recordId && recordId > 0) {
  418. historyRecord.setId(recordId);
  419. orderCommonMapper.updateSearchHistory(historyRecord);
  420. } else {
  421. orderCommonMapper.insertSearchHistory(historyRecord);
  422. }
  423. // 查询关键字历史记录条数
  424. int count = orderCommonMapper.countSearchHistory(userId);
  425. // 只保留10条的搜索关键词历史记录
  426. if (count > 10) {
  427. orderCommonMapper.deleteSearchHistoryLimit(userId);
  428. }
  429. }
  430. }