ApiCartService.java 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. package com.kmall.api.service;
  2. import com.google.common.collect.Maps;
  3. import com.kmall.api.annotation.LoginUser;
  4. import com.kmall.api.dao.*;
  5. import com.kmall.api.dto.CampMinusDto;
  6. import com.kmall.api.dto.CheckOutDto;
  7. import com.kmall.api.dto.UserCouponDto;
  8. import com.kmall.api.entity.*;
  9. import com.kmall.api.entity.mk.MkStoreCampMinusVo;
  10. import com.kmall.api.service.mk.ApiMkStoreCampMinusService;
  11. import com.kmall.common.constant.Dict;
  12. import com.kmall.common.utils.Constant;
  13. import com.kmall.common.utils.MapUtils;
  14. import com.kmall.common.utils.RRException;
  15. import org.apache.commons.logging.Log;
  16. import org.apache.commons.logging.LogFactory;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.stereotype.Service;
  19. import java.math.BigDecimal;
  20. import java.util.ArrayList;
  21. import java.util.HashMap;
  22. import java.util.List;
  23. import java.util.Map;
  24. @Service
  25. public class ApiCartService {
  26. private Log logger = LogFactory.getLog(ApiCartService.class);
  27. @Autowired
  28. private ApiCartMapper cartDao;
  29. @Autowired
  30. private ApiGoodsCrashMapper apiGoodsCrashMapper;
  31. @Autowired
  32. private ApiProductMapper apiProductMapper;
  33. @Autowired
  34. private ApiGoodsMapper apiGoodsMapper;
  35. @Autowired
  36. private ApiGoodsSpecificationService apiGoodsSpecificationService;
  37. @Autowired
  38. private ApiStoreMapper apiStoreMapper;
  39. @Autowired
  40. private ApiThirdMerchantBizMapper apiThirdMerchantBizMapper;
  41. @Autowired
  42. private ApiFreightMapper apiFreightMapper;
  43. @Autowired
  44. private ApiUserCouponService apiUserCouponService;
  45. @Autowired
  46. private ApiMkStoreCampMinusService apiMkStoreCampMinusService;
  47. public CartVo queryObject(Integer id) {
  48. return cartDao.queryObject(id);
  49. }
  50. public CartVo queryObjectByGoodsIdAndUserId(Long goods_id,Long user_id,Long storeId) {
  51. return cartDao.queryObjectByGoodsIdAndUserId(goods_id,user_id,storeId);
  52. }
  53. public List<CartVo> queryList(Map<String, Object> map) {
  54. return cartDao.queryList(map);
  55. }
  56. public List<CartVo> queryValidCartList(Map<String, Object> map) {
  57. return cartDao.queryValidCartList(map);
  58. }
  59. public int queryTotal(Map<String, Object> map) {
  60. return cartDao.queryTotal(map);
  61. }
  62. public void save(CartVo cart) {
  63. // 更新购物车搭配减价
  64. cartDao.save(cart);
  65. // 判断购物车中是否存在此规格商品
  66. Map cartParam = Maps.newHashMap();
  67. cartParam.put("user_id", cart.getUser_id());
  68. List<CartVo> cartInfoList = cartDao.queryList(cartParam);
  69. // 是否有搭配减价
  70. Map crashParam = Maps.newHashMap();
  71. List<Long> goods_ids = new ArrayList();
  72. List<CartVo> cartUpdateList = new ArrayList();
  73. if(cartInfoList != null && cartInfoList.size() > 0) {
  74. for (CartVo cartItem : cartInfoList) {
  75. if (null != cartItem.getChecked() && 1 == cartItem.getChecked()) {
  76. goods_ids.add(cartItem.getGoods_id());
  77. }
  78. if (!cartItem.getRetail_price().equals(cartItem.getRetail_product_price())) {
  79. cartItem.setRetail_price(cartItem.getRetail_product_price());
  80. cartUpdateList.add(cartItem);
  81. }
  82. }
  83. }else{
  84. goods_ids.add(cart.getGoods_id());
  85. }
  86. crashParam.put("store_id", cart.getStore_id());
  87. crashParam.put("goods_ids", goods_ids);
  88. List<GoodsCrashVo> goodsCrashList = apiGoodsCrashMapper.queryList(crashParam);
  89. if (null != goodsCrashList) {
  90. for (GoodsCrashVo crashVo : goodsCrashList) {
  91. for (CartVo cartItem : cartInfoList) {
  92. // 存在原始的
  93. if (null != cartItem.getChecked() && 1 == cartItem.getChecked()
  94. && cartItem.getGoods_id().equals(crashVo.getGoods_id())) {
  95. for (CartVo cartCrash : cartInfoList) { // 搭配上了商品
  96. if (!cartCrash.getId().equals(cartItem.getId())
  97. && cartCrash.getGoods_id().equals(crashVo.getGoods_crash_id())
  98. && cartCrash.getProduct_id().equals(crashVo.getProduct_crash_id())) {
  99. cartItem.setRetail_price(crashVo.getRetail_crash_price());
  100. cartUpdateList.add(cartItem);
  101. }
  102. }
  103. }
  104. }
  105. }
  106. }
  107. if (null != cartUpdateList && cartUpdateList.size() > 0) {
  108. for (CartVo cartItem : cartUpdateList) {
  109. cartDao.update(cartItem);
  110. }
  111. }
  112. }
  113. public void update(CartVo cart) {
  114. cartDao.update(cart);
  115. }
  116. public void delete(Long id) {
  117. cartDao.delete(id);
  118. }
  119. public void deleteBatch(Integer[] ids) {
  120. cartDao.deleteBatch(ids);
  121. }
  122. public void updateCheck(String[] goodsIds, Integer isChecked, Long userId, Long storeId) {
  123. cartDao.updateCheck(goodsIds, isChecked, userId, storeId);
  124. }
  125. public void deleteByProductIds(String[] productIds, Long storeId) {
  126. cartDao.deleteByProductIds(productIds, storeId);
  127. }
  128. /**
  129. * 只根据商品Id添加到购物车
  130. *
  131. * @param user_id
  132. * @param goods_id
  133. */
  134. public Map addByGoodsId(Long user_id, Long goods_id, Long store_id) {
  135. Map<String, Object> resultObj = Maps.newHashMap();
  136. resultObj.put("errno", 0);
  137. resultObj.put("errmsg", "添加成功");
  138. // 判断购物车中是否存在此规格商品
  139. Map cartParam = Maps.newHashMap();
  140. cartParam.put("user_id", user_id);
  141. cartParam.put("goods_id", goods_id);
  142. List<CartVo> cartInfoList = cartDao.queryList(cartParam);
  143. if (null != cartInfoList && cartInfoList.size() > 0) {
  144. CartVo cartVo = cartInfoList.get(0);
  145. cartVo.setNumber(cartVo.getNumber() + 1);
  146. update(cartVo);
  147. return resultObj;
  148. }
  149. ProductVo productVo = apiProductMapper.queryOneByGoodsId(goods_id, store_id);
  150. if (null == productVo || productVo.getStock_num() < 1) {
  151. // resultObj.put("errno", 1);
  152. // resultObj.put("errmsg", "库存不足,仅剩余" + productVo.getStock_num());
  153. // return resultObj;
  154. logger.error("库存不足,仅剩余" + productVo.getStock_num());
  155. throw new RRException("库存不足,仅剩余" + productVo.getStock_num());
  156. }
  157. GoodsVo goodsVo = apiGoodsMapper.queryObjectByStoreId(goods_id, store_id);
  158. CartVo cartInfo = new CartVo();
  159. cartInfo.setGoods_id(productVo.getGoods_id());
  160. cartInfo.setProduct_id(productVo.getId());
  161. cartInfo.setGoods_sn(productVo.getGoods_sn());
  162. cartInfo.setGoods_name(goodsVo.getName());
  163. cartInfo.setList_pic_url(goodsVo.getList_pic_url());
  164. cartInfo.setNumber(1);
  165. cartInfo.setStore_id(store_id);
  166. cartInfo.setUser_id(user_id);
  167. cartInfo.setRetail_price(productVo.getRetail_price());
  168. cartInfo.setMarket_price(productVo.getMarket_price());
  169. //添加规格名和值
  170. cartInfo.setGoods_specification_name_value(productVo.getGoods_specification_name_value());
  171. cartInfo.setGoods_specification_ids(productVo.getGoods_specification_ids());
  172. cartInfo.setChecked(1);
  173. cartInfo.setGoodsBizType(goodsVo.getGoodsBizType());
  174. cartInfo.setMerchSn(goodsVo.getMerchSn());
  175. save(cartInfo);
  176. return resultObj;
  177. }
  178. public List<CartVo> queryCartByGoodsBizType(String goodsBizType) {
  179. return cartDao.queryCartByGoodsBizType(goodsBizType);
  180. }
  181. public Map<String, Object> getCartMoney(UserVo loginUser, String checkCart, Long storeId){
  182. Map<String, Object> resultObj = Maps.newHashMap();
  183. //查询列表数据
  184. Map param = Maps.newHashMap();
  185. param.put("user_id", loginUser.getId());
  186. param.put("store_id", storeId);
  187. param.put("checkCart",checkCart);
  188. param.put("checked", "1");
  189. param.putAll(setIsStockShare(storeId));
  190. List<CartVo> cartList = cartDao.queryList(param);
  191. //获取购物车统计信息
  192. Integer goodsCount = 0;
  193. BigDecimal goodsAmount = new BigDecimal(0.00);
  194. Integer checkedGoodsCount = 0;
  195. BigDecimal checkedGoodsAmount = new BigDecimal(0.00);
  196. BigDecimal checkedGoodsAmount00 = new BigDecimal(0.00);
  197. BigDecimal checkedGoodsAmount02 = new BigDecimal(0.00);
  198. BigDecimal checkedGoodsAmount10 = new BigDecimal(0.00);
  199. BigDecimal checkedGoodsAmount11 = new BigDecimal(0.00);
  200. for (CartVo cartItem : cartList) {
  201. goodsCount += cartItem.getNumber();
  202. goodsAmount = goodsAmount.add(cartItem.getRetail_price().multiply(new BigDecimal(cartItem.getNumber())));
  203. if (null != cartItem.getChecked() && 1 == cartItem.getChecked()) {
  204. if(cartItem.getGoodsBizType().equalsIgnoreCase(Dict.orderBizType.item_00.getItem())){
  205. checkedGoodsAmount00 = checkedGoodsAmount00.add(cartItem.getRetail_price().multiply(new BigDecimal(cartItem.getNumber())));
  206. }
  207. if(cartItem.getGoodsBizType().equalsIgnoreCase(Dict.orderBizType.item_02.getItem())){
  208. checkedGoodsAmount02 = checkedGoodsAmount02.add(cartItem.getRetail_price().multiply(new BigDecimal(cartItem.getNumber())));
  209. }
  210. if(cartItem.getGoodsBizType().equalsIgnoreCase(Dict.orderBizType.item_10.getItem())){
  211. checkedGoodsAmount10 = checkedGoodsAmount10.add(cartItem.getRetail_price().multiply(new BigDecimal(cartItem.getNumber())));
  212. }
  213. if (cartItem.getGoodsBizType().equalsIgnoreCase(Dict.orderBizType.item_11.getItem())) {
  214. checkedGoodsAmount11 = checkedGoodsAmount11.add(cartItem.getRetail_price().multiply(new BigDecimal(cartItem.getNumber())));
  215. }
  216. checkedGoodsCount += cartItem.getNumber();
  217. checkedGoodsAmount = checkedGoodsAmount.add(cartItem.getRetail_price().multiply(new BigDecimal(cartItem.getNumber())));
  218. }
  219. }
  220. resultObj.put("cartList", cartList);
  221. Map<String, Object> cartTotal = Maps.newHashMap();
  222. cartTotal.put("goodsCount", goodsCount);
  223. cartTotal.put("goodsAmount", goodsAmount);
  224. cartTotal.put("checkedGoodsCount", checkedGoodsCount);
  225. cartTotal.put("checkedGoodsAmount", checkedGoodsAmount);
  226. cartTotal.put("checkedGoodsAmount00", checkedGoodsAmount00);
  227. cartTotal.put("checkedGoodsAmount02", checkedGoodsAmount02);
  228. cartTotal.put("checkedGoodsAmount10", checkedGoodsAmount10);
  229. cartTotal.put("checkedGoodsAmount11", checkedGoodsAmount11);
  230. resultObj.put("cartTotal", cartTotal);
  231. return resultObj;
  232. }
  233. private Map setIsStockShare(Long storeId){
  234. Map param = Maps.newHashMap();
  235. StoreVo storeVo = apiStoreMapper.queryObject(storeId);
  236. if(storeVo != null) {
  237. ThirdMerchantBizVo thirdMerchantBiz = apiThirdMerchantBizMapper.getThirdMerchangByCode(storeVo.getThirdPartyMerchCode());
  238. if (null == thirdMerchantBiz) {
  239. logger.error("第三方商户为空" );
  240. throw new RRException("第三方商户为空");
  241. }
  242. param.put("isStockShare", thirdMerchantBiz.getIsStockShare());
  243. }
  244. return param;
  245. }
  246. public Integer queryCartNumByStoreId(Map<String, Object> map){
  247. return cartDao.queryCartNumByStoreId(map);
  248. }
  249. /**
  250. * 优惠券活动计算实付抵扣
  251. * @param checkedCoupon
  252. * @param actualPrice
  253. * @return
  254. */
  255. public BigDecimal mathActualPrice(UserCouponVo checkedCoupon, BigDecimal actualPrice){
  256. if(checkedCoupon != null){
  257. if (checkedCoupon.getTickDiscType().equalsIgnoreCase(Dict.tickDiscType.item_00.getItem())) {
  258. actualPrice = actualPrice.subtract(checkedCoupon.getTypeMoney());
  259. }
  260. if (checkedCoupon.getTickDiscType().equalsIgnoreCase(Dict.tickDiscType.item_01.getItem())) {
  261. //实付金额*(优惠券折扣*0.1) = 折扣后的实付金额
  262. actualPrice = actualPrice.multiply(checkedCoupon.getTypeMoney().multiply(new BigDecimal(0.1))).setScale(2, BigDecimal.ROUND_HALF_UP);//满多少打几折
  263. }
  264. }
  265. return actualPrice;
  266. }
  267. /**
  268. * 满减满折活动计算实付满减
  269. * @param checkedCampMinus
  270. * @param actualPrice
  271. * @return
  272. */
  273. public BigDecimal mathActualPriceByCamp(CampMinusDto checkedCampMinus, BigDecimal actualPrice){
  274. if(checkedCampMinus != null){
  275. if (checkedCampMinus.getCampMinusType().equalsIgnoreCase(Dict.campMinusType.item_00.getItem()) || checkedCampMinus.getCampMinusType().equalsIgnoreCase(Dict.campMinusType.item_01.getItem())) {
  276. actualPrice = actualPrice.subtract(checkedCampMinus.getMoney());
  277. }
  278. if (checkedCampMinus.getCampMinusType().equalsIgnoreCase(Dict.campMinusType.item_10.getItem()) || checkedCampMinus.getCampMinusType().equalsIgnoreCase(Dict.campMinusType.item_11.getItem())) {
  279. //实付金额*(满减满折折扣*0.1) = 折扣后的实付金额
  280. actualPrice = actualPrice.multiply(checkedCampMinus.getMoney().multiply(new BigDecimal(0.1))).setScale(2, BigDecimal.ROUND_HALF_UP);//满多少打几折
  281. }
  282. }
  283. return actualPrice;
  284. }
  285. /**
  286. * 确认订单页
  287. * @param checkOutDto
  288. * @return
  289. */
  290. public Map<String, Object> getCheckOut(CheckOutDto checkOutDto){
  291. Map<String, Object> resultObj = Maps.newHashMap();
  292. UserVo loginUser = checkOutDto.getLoginUser();
  293. String checkCart = checkOutDto.getCheckCart();
  294. Long storeId = checkOutDto.getStoreId();
  295. Long tickDiscId00 = checkOutDto.getTickDiscId00();
  296. Long tickDiscId02 = checkOutDto.getTickDiscId02();
  297. Long tickDiscId10 = checkOutDto.getTickDiscId10();
  298. Long tickDiscId11 = checkOutDto.getTickDiscId11();
  299. Integer campId00 = checkOutDto.getCampId00();
  300. Integer campId02 = checkOutDto.getCampId02();
  301. Integer campId10 = checkOutDto.getCampId10();
  302. Integer campId11 = checkOutDto.getCampId11();
  303. Map<String, Object> cartData = checkOutDto.getCartData();
  304. List<CartVo> checkedGoodsList = new ArrayList();
  305. List<CartVo> cartGoodsList = (List<CartVo>) cartData.get("cartList");
  306. for (CartVo cartEntity : cartGoodsList) {
  307. if (cartEntity.getChecked() == 1) {
  308. checkedGoodsList.add(cartEntity);
  309. }
  310. }
  311. //计算订单的费用 商品总价
  312. BigDecimal goodsTotalPrice = (BigDecimal) ((HashMap) cartData.get("cartTotal")).get("checkedGoodsAmount");
  313. //商品销售价*数量
  314. BigDecimal goodsTotalPrice00 = (BigDecimal) ((HashMap) cartData.get("cartTotal")).get("checkedGoodsAmount00");
  315. BigDecimal goodsTotalPrice02 = (BigDecimal) ((HashMap) cartData.get("cartTotal")).get("checkedGoodsAmount02");
  316. BigDecimal goodsTotalPrice10 = (BigDecimal) ((HashMap) cartData.get("cartTotal")).get("checkedGoodsAmount10");
  317. BigDecimal goodsTotalPrice11 = (BigDecimal) ((HashMap) cartData.get("cartTotal")).get("checkedGoodsAmount11");
  318. // 根据收货地址计算运费
  319. // BigDecimal freightPrice = apiCouponService.matchShipping(loginUser.getId(), goodsTotalPrice);
  320. BigDecimal freightPrice00 = new BigDecimal("00");
  321. BigDecimal freightPrice02 = new BigDecimal("00");
  322. BigDecimal freightPrice10 = new BigDecimal("00");
  323. BigDecimal freightPrice11 = new BigDecimal("00");
  324. Boolean isBizType00 = false;
  325. Boolean isBizType02 = false;
  326. Boolean isBizType10 = false;
  327. Boolean isBizType11 = false;
  328. //查询运费模板
  329. for (CartVo vo: checkedGoodsList) {
  330. if(org.apache.commons.lang.StringUtils.isEmpty(checkCart)){
  331. if(vo.getGoodsBizType().equalsIgnoreCase(Dict.orderBizType.item_00.getItem())){
  332. FreightEntity freightEntity = apiFreightMapper.queryObjectByGoodsId(vo.getGoods_id(), storeId);
  333. freightPrice00 = freightEntity!=null ? freightEntity.getDefaultFreight().add(freightPrice00) : freightPrice00;
  334. isBizType00 =true;
  335. }
  336. if(vo.getGoodsBizType().equalsIgnoreCase(Dict.orderBizType.item_02.getItem())){
  337. FreightEntity freightEntity = apiFreightMapper.queryObjectByGoodsId(vo.getGoods_id(), storeId);
  338. freightPrice02 = freightEntity!=null ? freightEntity.getDefaultFreight().add(freightPrice02) : freightPrice02;
  339. isBizType02 =true;
  340. }
  341. if(vo.getGoodsBizType().equalsIgnoreCase(Dict.orderBizType.item_10.getItem())){
  342. FreightEntity freightEntity = apiFreightMapper.queryObjectByGoodsId(vo.getGoods_id(), storeId);
  343. freightPrice10 = freightEntity!=null ? freightEntity.getDefaultFreight().add(freightPrice10) : freightPrice10;
  344. isBizType10 =true;
  345. }
  346. if (vo.getGoodsBizType().equalsIgnoreCase(Dict.orderBizType.item_11.getItem())) {
  347. FreightEntity freightEntity = apiFreightMapper.queryObjectByGoodsId(vo.getGoods_id(), storeId);
  348. freightPrice11 = freightEntity != null ? freightEntity.getDefaultFreight().add(freightPrice11) : freightPrice11;
  349. isBizType11 =true;
  350. }
  351. }else{
  352. if(Dict.orderBizType.item_11.getItem().equalsIgnoreCase(checkCart)) {
  353. if (vo.getGoodsBizType().equalsIgnoreCase(Dict.orderBizType.item_11.getItem())) {
  354. FreightEntity freightEntity = apiFreightMapper.queryObjectByGoodsId(vo.getGoods_id(), storeId);
  355. freightPrice11 = freightEntity != null ? freightEntity.getDefaultFreight().add(freightPrice11) : freightPrice11;
  356. isBizType11 =true;
  357. }
  358. }else{
  359. if(vo.getGoodsBizType().equalsIgnoreCase(Dict.orderBizType.item_00.getItem())){
  360. FreightEntity freightEntity = apiFreightMapper.queryObjectByGoodsId(vo.getGoods_id(), storeId);
  361. freightPrice00 = freightEntity!=null ? freightEntity.getDefaultFreight().add(freightPrice00) : freightPrice00;
  362. isBizType00 =true;
  363. }
  364. if(vo.getGoodsBizType().equalsIgnoreCase(Dict.orderBizType.item_02.getItem())){
  365. FreightEntity freightEntity = apiFreightMapper.queryObjectByGoodsId(vo.getGoods_id(), storeId);
  366. freightPrice02 = freightEntity!=null ? freightEntity.getDefaultFreight().add(freightPrice02) : freightPrice02;
  367. isBizType02 =true;
  368. }
  369. if(vo.getGoodsBizType().equalsIgnoreCase(Dict.orderBizType.item_10.getItem())){
  370. FreightEntity freightEntity = apiFreightMapper.queryObjectByGoodsId(vo.getGoods_id(), storeId);
  371. freightPrice10 = freightEntity!=null ? freightEntity.getDefaultFreight().add(freightPrice10) : freightPrice10;
  372. isBizType10 =true;
  373. }
  374. }
  375. }
  376. }
  377. //整个订单包含运费的总价,商品总价+运费
  378. BigDecimal orderTotalPrice = goodsTotalPrice.add(freightPrice00).add(freightPrice02).add(freightPrice10).add(freightPrice11);
  379. // 计算满减 todo 暂时不计算全场金额满减
  380. // BigDecimal fullCutCouponDec = Constant.ZERO;
  381. // Long fullCutCouponId = 0L;
  382. /*CouponVo fullSubCoupon = apiCouponService.matchFullSub(loginUser.getId(), goodsTotalPrice);
  383. if (null != fullSubCoupon && null != fullSubCoupon.getId()) {
  384. // 满减
  385. fullCutCouponDec = fullSubCoupon.getType_money();
  386. fullCutCouponId = fullSubCoupon.getId();
  387. }*/
  388. // resultObj.put("fullCutCouponDec", fullCutCouponDec);
  389. // resultObj.put("fullCutCouponId", fullCutCouponId);
  390. List<UserCouponVo> couponList00 = null;
  391. List<UserCouponVo> couponList02 = null;
  392. List<UserCouponVo> couponList10 = null;
  393. List<UserCouponVo> couponList11 = null;
  394. List<CampMinusDto> campList00 = null;
  395. List<CampMinusDto> campList02 = null;
  396. List<CampMinusDto> campList10 = null;
  397. List<CampMinusDto> campList11 = null;
  398. //获取每个订单的可用的优惠券信息 抵用券
  399. if(goodsTotalPrice00.compareTo(new BigDecimal(0)) > 0){
  400. UserCouponDto userCouponDto00 = new UserCouponDto();
  401. userCouponDto00.setUserId(loginUser.getId());
  402. userCouponDto00.setStoreId(storeId);
  403. userCouponDto00.setGoodsTotalPrice(goodsTotalPrice00);
  404. userCouponDto00.setCartGoodsList(cartGoodsList);
  405. userCouponDto00.setBizType(Dict.orderBizType.item_00.getItem());
  406. couponList00 = apiUserCouponService.matchUserCouponList(userCouponDto00);
  407. campList00 = apiMkStoreCampMinusService.matchUserCampMinusList(userCouponDto00);
  408. }
  409. if(goodsTotalPrice02.compareTo(new BigDecimal(0)) > 0) {
  410. UserCouponDto userCouponDto02 = new UserCouponDto();
  411. userCouponDto02.setUserId(loginUser.getId());
  412. userCouponDto02.setStoreId(storeId);
  413. userCouponDto02.setGoodsTotalPrice(goodsTotalPrice02);
  414. userCouponDto02.setCartGoodsList(cartGoodsList);
  415. userCouponDto02.setBizType(Dict.orderBizType.item_02.getItem());
  416. couponList02 = apiUserCouponService.matchUserCouponList(userCouponDto02);
  417. campList02 = apiMkStoreCampMinusService.matchUserCampMinusList(userCouponDto02);
  418. }
  419. if(goodsTotalPrice10.compareTo(new BigDecimal(0)) > 0) {
  420. UserCouponDto userCouponDto10 = new UserCouponDto();
  421. userCouponDto10.setUserId(loginUser.getId());
  422. userCouponDto10.setStoreId(storeId);
  423. userCouponDto10.setGoodsTotalPrice(goodsTotalPrice10);
  424. userCouponDto10.setCartGoodsList(cartGoodsList);
  425. userCouponDto10.setBizType(Dict.orderBizType.item_10.getItem());
  426. couponList10 = apiUserCouponService.matchUserCouponList(userCouponDto10);
  427. campList10 = apiMkStoreCampMinusService.matchUserCampMinusList(userCouponDto10);
  428. }
  429. if(goodsTotalPrice11.compareTo(new BigDecimal(0)) > 0) {
  430. UserCouponDto userCouponDto11 = new UserCouponDto();
  431. userCouponDto11.setUserId(loginUser.getId());
  432. userCouponDto11.setStoreId(storeId);
  433. userCouponDto11.setGoodsTotalPrice(goodsTotalPrice11);
  434. userCouponDto11.setCartGoodsList(cartGoodsList);
  435. userCouponDto11.setBizType(Dict.orderBizType.item_11.getItem());
  436. couponList11 = apiUserCouponService.matchUserCouponList(userCouponDto11);
  437. campList11 = apiMkStoreCampMinusService.matchUserCampMinusList(userCouponDto11);
  438. }
  439. CampMinusDto campMinusDto00 = null;
  440. CampMinusDto campMinusDto02 = null;
  441. CampMinusDto campMinusDto10 = null;
  442. CampMinusDto campMinusDto11 = null;
  443. UserCouponVo checkedCoupon00 = null;
  444. UserCouponVo checkedCoupon02 = null;
  445. UserCouponVo checkedCoupon10 = null;
  446. UserCouponVo checkedCoupon11 = null;
  447. Integer isLoadStatus = checkOutDto.getIsLoadStatus();
  448. //商品销售价*数量
  449. BigDecimal actualPrice00 = goodsTotalPrice00;
  450. BigDecimal actualPrice02 = goodsTotalPrice02;
  451. BigDecimal actualPrice10 = goodsTotalPrice10;
  452. BigDecimal actualPrice11 = goodsTotalPrice11;
  453. Map campMinusMap00 = checkedCampMinus(campList00, campMinusDto00, actualPrice00, campId00, isLoadStatus);
  454. Map campMinusMap02 = checkedCampMinus(campList02, campMinusDto02, actualPrice02, campId02, isLoadStatus);
  455. Map campMinusMap10 = checkedCampMinus(campList10, campMinusDto10, actualPrice10, campId10, isLoadStatus);
  456. Map campMinusMap11 = checkedCampMinus(campList11, campMinusDto11, actualPrice11, campId11, isLoadStatus);
  457. Map couponMap00 = checkedCoupon(couponList00, checkedCoupon00, tickDiscId00, campMinusMap00, isLoadStatus);
  458. Map couponMap02 = checkedCoupon(couponList02, checkedCoupon02, tickDiscId02, campMinusMap02, isLoadStatus);
  459. Map couponMap10 = checkedCoupon(couponList10, checkedCoupon10, tickDiscId10, campMinusMap10, isLoadStatus);
  460. Map couponMap11 = checkedCoupon(couponList11, checkedCoupon11, tickDiscId11, campMinusMap11, isLoadStatus);
  461. campMinusDto00 = getCampMinusByMap(campMinusMap00);
  462. campMinusDto02 = getCampMinusByMap(campMinusMap02);
  463. campMinusDto10 = getCampMinusByMap(campMinusMap10);
  464. campMinusDto11 = getCampMinusByMap(campMinusMap11);
  465. checkedCoupon00 = getUserCouponByMap(couponMap00);
  466. checkedCoupon02 = getUserCouponByMap(couponMap02);
  467. checkedCoupon10 = getUserCouponByMap(couponMap10);
  468. checkedCoupon11 = getUserCouponByMap(couponMap11);
  469. actualPrice00 = getActualPriceByMap(couponMap00);
  470. actualPrice02 = getActualPriceByMap(couponMap02);
  471. actualPrice10 = getActualPriceByMap(couponMap10);
  472. actualPrice11 = getActualPriceByMap(couponMap11);
  473. //商品销售价*数量-优惠金额+运费
  474. actualPrice00 = actualPrice00.add(freightPrice00);
  475. actualPrice02 = actualPrice02.add(freightPrice02);
  476. actualPrice10 = actualPrice10.add(freightPrice10);
  477. actualPrice11 = actualPrice11.add(freightPrice11);
  478. BigDecimal actualPrice = actualPrice00.add(actualPrice02).add(actualPrice10).add(actualPrice11); //实付金额:商品销售价*数量-优惠金额+运费的总和
  479. resultObj.put("freightPrice00", freightPrice00);
  480. resultObj.put("freightPrice02", freightPrice02);
  481. resultObj.put("freightPrice10", freightPrice10);
  482. resultObj.put("freightPrice11", freightPrice11);
  483. resultObj.put("checkedCoupon00", checkedCoupon00);
  484. resultObj.put("checkedCoupon02", checkedCoupon02);
  485. resultObj.put("checkedCoupon10", checkedCoupon10);
  486. resultObj.put("checkedCoupon11", checkedCoupon11);
  487. resultObj.put("campMinusDto00", campMinusDto00);
  488. resultObj.put("campMinusDto02", campMinusDto02);
  489. resultObj.put("campMinusDto10", campMinusDto10);
  490. resultObj.put("campMinusDto11", campMinusDto11);
  491. resultObj.put("couponList00", couponList00);
  492. resultObj.put("couponList02", couponList02);
  493. resultObj.put("couponList10", couponList10);
  494. resultObj.put("couponList11", couponList11);
  495. resultObj.put("campList00", campList00);
  496. resultObj.put("campList02", campList02);
  497. resultObj.put("campList10", campList10);
  498. resultObj.put("campList11", campList11);
  499. resultObj.put("campId00", campMinusDto00 != null ? campMinusDto00.getCampMinusId():0);
  500. resultObj.put("campId02", campMinusDto02 != null ? campMinusDto02.getCampMinusId():0);
  501. resultObj.put("campId10", campMinusDto10 != null ? campMinusDto10.getCampMinusId():0);
  502. resultObj.put("campId11", campMinusDto11 != null ? campMinusDto11.getCampMinusId():0);
  503. resultObj.put("tickDiscId00", checkedCoupon00 != null ? checkedCoupon00.getId():0);
  504. resultObj.put("tickDiscId02", checkedCoupon02 != null ? checkedCoupon02.getId():0);
  505. resultObj.put("tickDiscId10", checkedCoupon10 != null ? checkedCoupon10.getId():0);
  506. resultObj.put("tickDiscId11", checkedCoupon11 != null ? checkedCoupon11.getId():0);
  507. BigDecimal couponPrice = new BigDecimal(0.00); //使用优惠券减免的金额
  508. resultObj.put("couponPrice", couponPrice);
  509. resultObj.put("checkedGoodsList", checkedGoodsList);
  510. resultObj.put("goodsTotalPrice", goodsTotalPrice);//整个订单商品总价,不包含运费和优惠金额
  511. resultObj.put("orderTotalPrice", orderTotalPrice);//整个订单包含运费的总价
  512. resultObj.put("actualPrice", actualPrice);
  513. resultObj.put("actualPrice00", actualPrice00);
  514. resultObj.put("actualPrice02", actualPrice02);
  515. resultObj.put("actualPrice10", actualPrice10);
  516. resultObj.put("actualPrice11", actualPrice11);
  517. resultObj.put("goodsTotalPrice00", goodsTotalPrice00);
  518. resultObj.put("goodsTotalPrice02", goodsTotalPrice02);
  519. resultObj.put("goodsTotalPrice10", goodsTotalPrice10);
  520. resultObj.put("goodsTotalPrice11", goodsTotalPrice11);
  521. resultObj.put("isBizType00", isBizType00);
  522. resultObj.put("isBizType02", isBizType02);
  523. resultObj.put("isBizType10", isBizType10);
  524. resultObj.put("isBizType11", isBizType11);
  525. return resultObj;
  526. }
  527. /**
  528. * 选择满减满折
  529. * @param campList
  530. * @param campMinusDto
  531. * @param actualPrice
  532. * @param campId
  533. * @param isLoadStatus 0则为进入页面加载优惠信息,默认选择最高层级促销活动,1为选择促销活动后加载优惠信息,2为选择优惠券时触发,优惠券不能与促销活动同时使用
  534. */
  535. private Map checkedCampMinus(List<CampMinusDto> campList, CampMinusDto campMinusDto, BigDecimal actualPrice, Integer campId, Integer isLoadStatus){
  536. Map campMap = new HashMap();
  537. if(campList != null && campList.size() > 0 && isLoadStatus != null){
  538. if(isLoadStatus == 0){ //0则为进入页面加载优惠信息,默认选择最高层级促销活动
  539. campMinusDto = campList.get(0);
  540. if(campMinusDto.getCampMinusId().compareTo(0) > 0){
  541. //商品销售价*数量-优惠金额
  542. actualPrice = mathActualPriceByCamp(campMinusDto, actualPrice);
  543. campMap.put("actualPrice", actualPrice);
  544. campMap.put("isCamp", true);//满减活动是否满足该次订单
  545. }else{
  546. campMap.put("actualPrice", actualPrice);
  547. campMap.put("isCamp", false);
  548. }
  549. campMap.put("campMinusDto", campMinusDto);
  550. return campMap;
  551. }else if(isLoadStatus == 1) { //1为选择促销活动后加载优惠信息
  552. if (null != campId) {
  553. if (campId == 0) {
  554. //不参与满减活动
  555. setNotCampMinus(campList, actualPrice, campMap);
  556. } else {
  557. for (CampMinusDto dto : campList) {
  558. if (campId.compareTo(dto.getCampMinusId()) == 0) {
  559. campMinusDto = dto;
  560. //商品销售价*数量-优惠金额
  561. actualPrice = mathActualPriceByCamp(campMinusDto, actualPrice);
  562. campMap.put("actualPrice", actualPrice);
  563. campMap.put("isCamp", true);
  564. campMap.put("campMinusDto", campMinusDto);
  565. }
  566. }
  567. }
  568. }else{
  569. campMap.put("actualPrice", actualPrice);
  570. campMap.put("isCamp", false);
  571. }
  572. }else{//2为选择优惠券时触发,优惠券不能与促销活动同时使用
  573. setNotCampMinus(campList, actualPrice, campMap);
  574. }
  575. return campMap;
  576. }else{
  577. campMap.put("actualPrice", actualPrice);
  578. campMap.put("isCamp", false);
  579. return campMap;
  580. }
  581. }
  582. /**
  583. * 选择优惠券
  584. * @param couponList
  585. * @param checkedCoupon
  586. * @param tickDiscId
  587. * @param campMinusMap
  588. * @param isLoadStatus 0则为进入页面加载优惠信息,默认选择最高层级促销活动,1为选择促销活动后加载优惠信息,2为选择优惠券时触发,优惠券不能与促销活动同时使用
  589. */
  590. private Map checkedCoupon(List<UserCouponVo> couponList, UserCouponVo checkedCoupon, Long tickDiscId, Map campMinusMap, Integer isLoadStatus){
  591. BigDecimal actualPrice = MapUtils.getBigDecimal("actualPrice", campMinusMap);
  592. Boolean isCamp = (Boolean)campMinusMap.get("isCamp");
  593. Map couponMap = new HashMap();
  594. //满减活动不与优惠券同时使用,当isCamp为false时可使用优惠券
  595. if(isCamp == false) {
  596. if (null != couponList && couponList.size() > 0) {
  597. if (isLoadStatus == 0) {
  598. checkedCoupon = couponList.get(0);
  599. couponMap.put("actualPrice", actualPrice);
  600. couponMap.put("checkedCoupon", checkedCoupon);
  601. }else if(isLoadStatus == 1) {
  602. //不参与优惠活动
  603. setNotCoupon(couponList,actualPrice,couponMap);
  604. }else{
  605. if (null != tickDiscId && tickDiscId == 0) {//不参与优惠活动
  606. setNotCoupon(couponList,actualPrice,couponMap);
  607. } else {
  608. for (UserCouponVo userCouponVo : couponList) {
  609. if (null != tickDiscId && tickDiscId.equals(userCouponVo.getId())) {
  610. checkedCoupon = userCouponVo;
  611. //商品销售价*数量-优惠金额
  612. actualPrice = mathActualPrice(checkedCoupon, actualPrice);
  613. couponMap.put("actualPrice", actualPrice);
  614. couponMap.put("checkedCoupon", checkedCoupon);
  615. }
  616. }
  617. }
  618. }
  619. }else {
  620. couponMap.put("actualPrice", actualPrice);
  621. }
  622. return couponMap;
  623. }else{
  624. setNotCoupon(couponList,actualPrice,couponMap);
  625. return couponMap;
  626. }
  627. }
  628. /**
  629. * 不参与满减活动
  630. * @return
  631. */
  632. private void setNotCampMinus(List<CampMinusDto> campList,BigDecimal actualPrice, Map campMap){
  633. for (CampMinusDto dto : campList) {
  634. if (dto.getCampMinusId().compareTo(0)==0) {
  635. CampMinusDto campMinusDto = dto;
  636. campMap.put("actualPrice", actualPrice);
  637. campMap.put("isCamp", false);
  638. campMap.put("campMinusDto", campMinusDto);
  639. return;
  640. }
  641. }
  642. }
  643. /**
  644. * 不参与优惠券活动
  645. * @return
  646. */
  647. private void setNotCoupon(List<UserCouponVo> couponList,BigDecimal actualPrice, Map couponMap){
  648. if(couponList != null && couponList.size() > 0){
  649. for (UserCouponVo userCouponVo : couponList) {
  650. if (userCouponVo.getId().compareTo(0L)==0) {
  651. UserCouponVo checkedCoupon = userCouponVo;
  652. couponMap.put("actualPrice", actualPrice);
  653. couponMap.put("checkedCoupon", checkedCoupon);
  654. return;
  655. }
  656. }
  657. }else{
  658. couponMap.put("actualPrice", actualPrice);
  659. return;
  660. }
  661. }
  662. private CampMinusDto getCampMinusByMap(Map campMinusMap){
  663. if(campMinusMap.get("campMinusDto") != null){
  664. return (CampMinusDto)campMinusMap.get("campMinusDto");
  665. }
  666. return null;
  667. }
  668. private UserCouponVo getUserCouponByMap(Map couponMap){
  669. if(couponMap.get("checkedCoupon") != null){
  670. return (UserCouponVo) couponMap.get("checkedCoupon");
  671. }
  672. return null;
  673. }
  674. private BigDecimal getActualPriceByMap(Map couponMap){
  675. if(couponMap.get("actualPrice") != null){
  676. return MapUtils.getBigDecimal("actualPrice", couponMap);
  677. }
  678. return null;
  679. }
  680. }