ApiCartController.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. package com.kmall.api.api;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.kmall.api.annotation.LoginUser;
  4. import com.kmall.api.contants.Dict;
  5. import com.kmall.api.entity.*;
  6. import com.kmall.api.service.*;
  7. import com.kmall.api.util.ApiBaseAction;
  8. import com.kmall.common.utils.MapUtils;
  9. import com.qiniu.util.StringUtils;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.web.bind.annotation.GetMapping;
  12. import org.springframework.web.bind.annotation.PostMapping;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.RestController;
  15. import java.math.BigDecimal;
  16. import java.util.ArrayList;
  17. import java.util.HashMap;
  18. import java.util.List;
  19. import java.util.Map;
  20. /**
  21. * 作者: @author Scott <br>
  22. * 时间: 2017-08-11 08:32<br>
  23. * 描述: ApiIndexController <br>
  24. */
  25. @RestController
  26. @RequestMapping("/api/cart")
  27. public class ApiCartController extends ApiBaseAction {
  28. @Autowired
  29. private ApiCartService cartService;
  30. @Autowired
  31. private ApiGoodsService goodsService;
  32. @Autowired
  33. private ApiProductService productService;
  34. @Autowired
  35. private ApiAddressService addressService;
  36. @Autowired
  37. private ApiCouponService apiCouponService;
  38. @Autowired
  39. private ApiUserCouponService apiUserCouponService;
  40. @Autowired
  41. private ApiOrderGoodsService apiOrderGoodsService;
  42. /**
  43. * 获取购物车中的数据
  44. */
  45. @GetMapping("getCartMoney")
  46. public Object getCartMoney(@LoginUser UserVo loginUser) {
  47. Map<String, Object> resultObj = new HashMap();
  48. //查询列表数据
  49. Map param = new HashMap();
  50. param.put("user_id", loginUser.getId());
  51. Long storeId = getStoreId();
  52. param.put("store_id", storeId);
  53. List<CartVo> cartList = cartService.queryList(param);
  54. //获取购物车统计信息
  55. Integer goodsCount = 0;
  56. BigDecimal goodsAmount = new BigDecimal(0.00);
  57. Integer checkedGoodsCount = 0;
  58. BigDecimal checkedGoodsAmount = new BigDecimal(0.00);
  59. for (CartVo cartItem : cartList) {
  60. goodsCount += cartItem.getNumber();
  61. goodsAmount = goodsAmount.add(cartItem.getRetail_price().multiply(new BigDecimal(cartItem.getNumber())));
  62. if (null != cartItem.getChecked() && 1 == cartItem.getChecked()) {
  63. checkedGoodsCount += cartItem.getNumber();
  64. checkedGoodsAmount = checkedGoodsAmount.add(cartItem.getRetail_price().multiply(new BigDecimal(cartItem.getNumber())));
  65. }
  66. }
  67. resultObj.put("cartList", cartList);
  68. //
  69. Map<String, Object> cartTotal = new HashMap();
  70. cartTotal.put("goodsCount", goodsCount);
  71. cartTotal.put("goodsAmount", goodsAmount);
  72. cartTotal.put("checkedGoodsCount", checkedGoodsCount);
  73. cartTotal.put("checkedGoodsAmount", checkedGoodsAmount);
  74. //
  75. resultObj.put("cartTotal", cartTotal);
  76. return resultObj;
  77. }
  78. /**
  79. * 获取购物车中的数据
  80. */
  81. @GetMapping("getCart")
  82. public Object getCart() {
  83. UserVo loginUser = new UserVo();
  84. loginUser.setId(getUserId());
  85. Map<String, Object> resultObj = new HashMap();
  86. //查询列表数据
  87. Map param = new HashMap();
  88. param.put("user_id", loginUser.getId());
  89. Long storeId = getStoreId();
  90. param.put("store_id", storeId);
  91. List<CartVo> cartList = cartService.queryList(param);
  92. //获取购物车统计信息
  93. Integer goodsCount = 0;
  94. BigDecimal goodsAmount = new BigDecimal(0.00);
  95. Integer checkedGoodsCount = 0;
  96. BigDecimal checkedGoodsAmount = new BigDecimal(0.00);
  97. for (CartVo cartItem : cartList) {
  98. goodsCount += cartItem.getNumber();
  99. goodsAmount = goodsAmount.add(cartItem.getRetail_price().multiply(new BigDecimal(cartItem.getNumber())));
  100. if (null != cartItem.getChecked() && 1 == cartItem.getChecked()) {
  101. checkedGoodsCount += cartItem.getNumber();
  102. checkedGoodsAmount = checkedGoodsAmount.add(cartItem.getRetail_price().multiply(new BigDecimal(cartItem.getNumber())));
  103. }
  104. if(org.apache.commons.lang.StringUtils.isNotEmpty(cartItem.getGoodsBizType())){
  105. cartItem.setGoodsBizType(Dict.orderBizType.valueOf("item_"+ cartItem.getGoodsBizType()).getItemName());
  106. }else{
  107. cartItem.setGoodsBizType("");
  108. }
  109. }
  110. // 获取优惠信息提示 邮费
  111. CouponVo shippingCoupon = apiCouponService.matchShippingSign(loginUser.getId(), checkedGoodsAmount);
  112. // 获取优惠信息提示 满减
  113. CouponVo fullSubCoupon = apiCouponService.matchFullSubSign(loginUser.getId(), checkedGoodsAmount);
  114. List<CouponVo> couponInfoList = new ArrayList();
  115. if (null != shippingCoupon) {
  116. couponInfoList.add(shippingCoupon);
  117. }
  118. if (null != fullSubCoupon) {
  119. couponInfoList.add(fullSubCoupon);
  120. }
  121. resultObj.put("couponInfoList", couponInfoList);
  122. resultObj.put("cartList", cartList);
  123. //
  124. Map<String, Object> cartTotal = new HashMap();
  125. cartTotal.put("goodsCount", goodsCount);
  126. cartTotal.put("goodsAmount", goodsAmount);
  127. cartTotal.put("checkedGoodsCount", checkedGoodsCount);
  128. cartTotal.put("checkedGoodsAmount", checkedGoodsAmount);
  129. //
  130. resultObj.put("cartTotal", cartTotal);
  131. return resultObj;
  132. }
  133. /**
  134. * 获取购物车中的数据,底部显示
  135. */
  136. @GetMapping("getFootCart")
  137. public Object getFootCart(@LoginUser UserVo loginUser) {
  138. Map<String, Object> resultObj = new HashMap();
  139. //查询列表数据
  140. Map param = new HashMap();
  141. param.put("user_id", loginUser.getId());
  142. Long storeId = getStoreId();
  143. param.put("store_id", storeId);
  144. List<CartVo> cartList = cartService.queryList(param);
  145. //获取购物车统计信息
  146. Integer goodsCount = 0;
  147. BigDecimal goodsAmount = new BigDecimal(0.00);
  148. Integer checkedGoodsCount = 0;
  149. BigDecimal checkedGoodsAmount = new BigDecimal(0.00);
  150. for (CartVo cartItem : cartList) {
  151. goodsCount += 1;
  152. goodsAmount = goodsAmount.add(cartItem.getRetail_price().multiply(new BigDecimal(cartItem.getNumber())));
  153. if (null != cartItem.getChecked() && 1 == cartItem.getChecked()) {
  154. checkedGoodsCount += cartItem.getNumber();
  155. checkedGoodsAmount = checkedGoodsAmount.add(cartItem.getRetail_price().multiply(new BigDecimal(cartItem.getNumber())));
  156. }
  157. }
  158. //
  159. resultObj.put("goodsCount", goodsCount);
  160. resultObj.put("goodsAmount", goodsAmount);
  161. resultObj.put("checkedGoodsCount", checkedGoodsCount);
  162. resultObj.put("checkedGoodsAmount", checkedGoodsAmount);
  163. //
  164. return toResponsSuccess(resultObj);
  165. }
  166. /**
  167. * 获取购物车信息,所有对购物车的增删改操作,都要重新返回购物车的信息
  168. */
  169. @GetMapping("index")
  170. public Object index() {
  171. return toResponsSuccess(getCart());
  172. }
  173. /**
  174. * 添加商品到购物车
  175. */
  176. @PostMapping("add")
  177. public Object add(@LoginUser UserVo loginUser) {
  178. JSONObject jsonParam = getJsonRequest();
  179. Long goodsId = jsonParam.getLong("goodsId");
  180. Long productId = jsonParam.getLong("productId");
  181. Integer number = jsonParam.getInteger("number");
  182. //判断商品是否可以购买
  183. GoodsVo goodsInfo = goodsService.queryObject(goodsId);
  184. if (null == goodsInfo || goodsInfo.getIs_delete() == 1) {
  185. return this.toResponsObject(400, "商品已下架", "");
  186. }
  187. Long storeId = getStoreId();
  188. //取得规格的信息,判断规格库存
  189. ProductVo productInfo = productService.queryObjectByStoreId(productId, storeId);
  190. if (null == productInfo) {
  191. return this.toResponsObject(400, "商品已下架", "");
  192. }
  193. if (null == productInfo.getRetail_price()) {
  194. productInfo.setRetail_price(goodsInfo.getRetail_price());
  195. productInfo.setMarket_price(goodsInfo.getMarket_price());
  196. }
  197. //判断购物车中是否存在此规格商品
  198. Map cartParam = new HashMap();
  199. cartParam.put("goods_id", goodsId);
  200. cartParam.put("product_id", productId);
  201. cartParam.put("user_id", loginUser.getId());
  202. cartParam.put("store_id", storeId);
  203. List<CartVo> cartInfoList = cartService.queryList(cartParam);
  204. CartVo cartInfo = null != cartInfoList && cartInfoList.size() > 0 ? cartInfoList.get(0) : null;
  205. if (null == cartInfo) {
  206. //添加规格名和值
  207. cartInfo = new CartVo();
  208. cartInfo.setGoods_id(goodsId);
  209. cartInfo.setProduct_id(productId);
  210. cartInfo.setGoods_sn(productInfo.getGoods_sn());
  211. cartInfo.setGoods_name(goodsInfo.getName());
  212. cartInfo.setList_pic_url(goodsInfo.getList_pic_url());
  213. cartInfo.setNumber(number);
  214. cartInfo.setStore_id(storeId);
  215. cartInfo.setUser_id(loginUser.getId());
  216. cartInfo.setRetail_price(productInfo.getRetail_price());
  217. cartInfo.setMarket_price(productInfo.getMarket_price());
  218. cartInfo.setGoods_specification_name_value(productInfo.getGoods_specification_name_value());
  219. cartInfo.setGoods_specification_ids(productInfo.getGoods_specification_ids());
  220. cartInfo.setChecked(1);
  221. cartInfo.setGoodsBizType(goodsInfo.getGoodsBizType());//业务类型
  222. cartService.save(cartInfo);
  223. } else {
  224. cartInfo.setNumber(cartInfo.getNumber() + number);
  225. cartInfo.setGoodsBizType(goodsInfo.getGoodsBizType());//业务类型
  226. cartService.update(cartInfo);
  227. }
  228. return toResponsSuccess(getCart());
  229. }
  230. /**
  231. * 添加商品到购物车
  232. */
  233. @PostMapping("addByGoodsId")
  234. public Object addByGoodsId(@LoginUser UserVo loginUser) {
  235. JSONObject jsonParam = getJsonRequest();
  236. Long goodsId = jsonParam.getLong("goodsId");
  237. //判断商品是否可以购买
  238. GoodsVo goodsInfo = goodsService.queryObject(goodsId);
  239. if (null == goodsInfo || goodsInfo.getIs_delete() == 1) {
  240. return this.toResponsObject(400, "商品已下架", "");
  241. }
  242. Long storeId = getStoreId();
  243. Map resultObj = cartService.addByGoodsId(getUserId(), goodsId, storeId);
  244. if (0 != MapUtils.getInteger("errno", resultObj)) {
  245. return toResponsObject(MapUtils.getInteger("errno", resultObj), MapUtils.getString("errmsg", resultObj), "");
  246. }
  247. return toResponsSuccess(getCart());
  248. }
  249. /**
  250. * 根据订单号添加商品到购物车
  251. */
  252. @GetMapping("addByOrder")
  253. public Object addByOrder(@LoginUser UserVo loginUser, Long orderId) {
  254. JSONObject jsonParam = getJsonRequest();
  255. //
  256. Map params = new HashMap();
  257. params.put("order_id", orderId);
  258. List<OrderGoodsVo> orderGoodsVos = apiOrderGoodsService.queryList(params);
  259. for (OrderGoodsVo goodsVo : orderGoodsVos) {
  260. //判断商品是否可以购买
  261. GoodsVo goodsInfo = goodsService.queryObject(goodsVo.getGoods_id());
  262. if (null == goodsInfo || goodsInfo.getIs_delete() == 1) {
  263. return this.toResponsObject(400, "商品已下架", "");
  264. }
  265. }
  266. Long storeId = getStoreId();
  267. for (OrderGoodsVo goodsVo : orderGoodsVos) {
  268. CartVo cartInfo = new CartVo();
  269. cartInfo.setGoods_id(goodsVo.getGoods_id());
  270. cartInfo.setProduct_id(goodsVo.getProduct_id());
  271. cartInfo.setGoods_sn(goodsVo.getGoods_sn());
  272. cartInfo.setGoods_name(goodsVo.getGoods_name());
  273. cartInfo.setList_pic_url(goodsVo.getList_pic_url());
  274. cartInfo.setNumber(goodsVo.getNumber());
  275. cartInfo.setStore_id(storeId);
  276. cartInfo.setUser_id(loginUser.getId());
  277. cartInfo.setRetail_price(goodsVo.getRetail_price());
  278. cartInfo.setMarket_price(goodsVo.getMarket_price());
  279. cartInfo.setGoods_specification_name_value(goodsVo.getGoods_specification_name_value());
  280. cartInfo.setGoods_specification_ids(goodsVo.getGoods_specification_ids());
  281. cartInfo.setChecked(1);
  282. cartInfo.setGoodsBizType(goodsVo.getOrderBizType());
  283. cartService.save(cartInfo);
  284. }
  285. return toResponsSuccess("添加成功");
  286. }
  287. /**
  288. * 减少商品到购物车
  289. */
  290. @PostMapping("minus")
  291. public Object minus(@LoginUser UserVo loginUser) {
  292. JSONObject jsonParam = getJsonRequest();
  293. Integer goodsId = jsonParam.getInteger("goodsId");
  294. Integer productId = jsonParam.getInteger("productId");
  295. Integer number = jsonParam.getInteger("number");
  296. //判断购物车中是否存在此规格商品
  297. Map cartParam = new HashMap();
  298. cartParam.put("goods_id", goodsId);
  299. cartParam.put("product_id", productId);
  300. Long storeId = getStoreId();
  301. cartParam.put("store_id", storeId);
  302. cartParam.put("user_id", loginUser.getId());
  303. List<CartVo> cartInfoList = cartService.queryList(cartParam);
  304. CartVo cartInfo = null != cartInfoList && cartInfoList.size() > 0 ? cartInfoList.get(0) : null;
  305. int cart_num = 0;
  306. if (null != cartInfo) {
  307. if (cartInfo.getNumber() > number) {
  308. cartInfo.setNumber(cartInfo.getNumber() - number);
  309. cartService.update(cartInfo);
  310. cart_num = cartInfo.getNumber();
  311. } else if (cartInfo.getNumber() == 1) {
  312. cartService.delete(cartInfo.getId());
  313. cart_num = 0;
  314. }
  315. }
  316. return toResponsSuccess(cart_num);
  317. }
  318. /**
  319. * 更新指定的购物车信息
  320. */
  321. @PostMapping("update")
  322. public Object update(@LoginUser UserVo loginUser) {
  323. JSONObject jsonParam = getJsonRequest();
  324. Long goodsId = jsonParam.getLong("goodsId");
  325. Long storeId = getStoreId();
  326. Long productId = jsonParam.getLong("productId");
  327. Integer number = jsonParam.getInteger("number");
  328. Integer id = jsonParam.getInteger("id");
  329. //取得规格的信息,判断规格库存
  330. ProductVo productInfo = productService.queryObjectByStoreId(productId, storeId);
  331. if (null == productInfo || productInfo.getStock_num() == 0) {
  332. // String[] productIds = new String[1];
  333. // productIds[0] = productId + "";
  334. // cartService.deleteByProductIds(productIds, storeId);
  335. return this.toResponsObject(400, "商品已下架", "");
  336. }
  337. String msg = "";
  338. if (productInfo.getStock_num() < number) {
  339. msg = "库存不足,仅剩余" + productInfo.getStock_num();
  340. number = productInfo.getStock_num();
  341. // return this.toResponsObject(400, "库存不足,仅剩余" + productInfo.getStock_num(), "");
  342. }
  343. //判断是否已经存在product_id购物车商品
  344. CartVo cartInfo = cartService.queryObject(id);
  345. //只是更新number
  346. if (cartInfo.getProduct_id().equals(productId)) {
  347. cartInfo.setNumber(number);
  348. cartService.update(cartInfo);
  349. return toResponsObject(0, msg, getCart());
  350. }
  351. Map cartParam = new HashMap();
  352. cartParam.put("goodsId", goodsId);
  353. cartParam.put("productId", productId);
  354. cartParam.put("store_id", storeId);
  355. List<CartVo> cartInfoList = cartService.queryList(cartParam);
  356. CartVo newcartInfo = null != cartInfoList && cartInfoList.size() > 0 ? cartInfoList.get(0) : null;
  357. if (null == newcartInfo) {
  358. cartInfo.setProduct_id(productId);
  359. cartInfo.setGoods_sn(productInfo.getGoods_sn());
  360. cartInfo.setNumber(number);
  361. cartInfo.setRetail_price(productInfo.getRetail_price());
  362. cartInfo.setMarket_price(productInfo.getRetail_price());
  363. cartInfo.setGoods_specification_name_value(productInfo.getGoods_specification_name_value());
  364. cartInfo.setGoods_specification_ids(productInfo.getGoods_specification_ids());
  365. cartService.update(cartInfo);
  366. } else {
  367. //添加规格名和值
  368. cartInfo.setProduct_id(productId);
  369. cartInfo.setGoods_sn(productInfo.getGoods_sn());
  370. cartInfo.setNumber(number);
  371. cartInfo.setRetail_price(productInfo.getRetail_price());
  372. cartInfo.setMarket_price(productInfo.getRetail_price());
  373. cartInfo.setGoods_specification_name_value(productInfo.getGoods_specification_name_value());
  374. cartInfo.setGoods_specification_ids(productInfo.getGoods_specification_ids());
  375. cartService.update(cartInfo);
  376. }
  377. return toResponsObject(0, msg, getCart());
  378. }
  379. /**
  380. * 是否选择商品,如果已经选择,则取消选择,批量操作
  381. */
  382. @PostMapping("checked")
  383. public Object checked(@LoginUser UserVo loginUser) {
  384. JSONObject jsonParam = getJsonRequest();
  385. String productIds = jsonParam.getString("productIds");
  386. Integer isChecked = jsonParam.getInteger("isChecked");
  387. if (StringUtils.isNullOrEmpty(productIds)) {
  388. return this.toResponsFail("删除出错");
  389. }
  390. String[] productIdArray = productIds.split(",");
  391. cartService.updateCheck(productIdArray, isChecked, loginUser.getId(), getStoreId());
  392. return toResponsSuccess(getCart());
  393. }
  394. //删除选中的购物车商品,批量删除
  395. @PostMapping("delete")
  396. public Object delete(@LoginUser UserVo loginUser) {
  397. JSONObject jsonObject = getJsonRequest();
  398. Long cartId = jsonObject.getLong("cartId");
  399. if (null == cartId) {
  400. return toResponsFail("删除出错");
  401. }
  402. cartService.delete(cartId);
  403. return toResponsSuccess(getCart());
  404. }
  405. // 获取购物车商品的总件件数
  406. @GetMapping("goodscount")
  407. public Object goodscount(@LoginUser UserVo loginUser) {
  408. if (null == loginUser || null == loginUser.getId()) {
  409. return toResponsFail("未登录");
  410. }
  411. Map<String, Object> resultObj = new HashMap();
  412. //查询列表数据
  413. Map param = new HashMap();
  414. param.put("user_id", loginUser.getId());
  415. param.put("store_id", getStoreId());
  416. List<CartVo> cartList = cartService.queryList(param);
  417. //获取购物车统计信息
  418. Integer goodsCount = 0;
  419. for (CartVo cartItem : cartList) {
  420. goodsCount += cartItem.getNumber();
  421. }
  422. resultObj.put("cartList", cartList);
  423. //
  424. Map<String, Object> cartTotal = new HashMap();
  425. cartTotal.put("goodsCount", goodsCount);
  426. //
  427. resultObj.put("cartTotal", cartTotal);
  428. return toResponsSuccess(resultObj);
  429. }
  430. /**
  431. * 订单提交前的检验和填写相关订单信息
  432. */
  433. @GetMapping("checkout")
  434. public Object checkout(@LoginUser UserVo loginUser, Long userCouponId) {
  435. Map<String, Object> resultObj = new HashMap();
  436. //选择的收货地址
  437. Map param = new HashMap();
  438. param.put("is_default", 1);
  439. param.put("user_id", loginUser.getId());
  440. List<AddressVo> addressEntityList = addressService.queryList(param);
  441. //获取要购买的商品
  442. Map<String, Object> cartData = (Map<String, Object>) this.getCartMoney(loginUser);
  443. List<CartVo> checkedGoodsList = new ArrayList();
  444. for (CartVo cartEntity : (List<CartVo>) cartData.get("cartList")) {
  445. if (cartEntity.getChecked() == 1) {
  446. checkedGoodsList.add(cartEntity);
  447. }
  448. }
  449. //计算订单的费用
  450. //商品总价
  451. BigDecimal goodsTotalPrice = (BigDecimal) ((HashMap) cartData.get("cartTotal")).get("checkedGoodsAmount");
  452. //获取可用的优惠券信息 抵用券
  453. List<UserCouponVo> enableCouponList = apiUserCouponService.matchUserCouponList(loginUser.getId(), goodsTotalPrice);
  454. UserCouponVo checkedCoupon = null;
  455. BigDecimal couponPrice = new BigDecimal(0.00); //使用优惠券减免的金额
  456. if (null != enableCouponList && enableCouponList.size() > 0) {
  457. if (null != userCouponId) {
  458. for (UserCouponVo couponVo : enableCouponList) {
  459. if (null != userCouponId && userCouponId.equals(couponVo.getId())) {
  460. couponPrice = couponVo.getType_money();
  461. checkedCoupon = couponVo;
  462. }
  463. }
  464. }
  465. }
  466. // 根据收货地址计算运费
  467. BigDecimal freightPrice = apiCouponService.matchShipping(loginUser.getId(), goodsTotalPrice);
  468. // 单独计算满减券
  469. BigDecimal fullCutCouponDec = new BigDecimal(0);
  470. Long fullCutCouponId = 0L;
  471. CouponVo fullSubCoupon = apiCouponService.matchFullSub(loginUser.getId(), goodsTotalPrice);
  472. if (null != fullSubCoupon && null != fullSubCoupon.getId()) {
  473. // 满减
  474. fullCutCouponDec = fullSubCoupon.getType_money();
  475. fullCutCouponId = fullSubCoupon.getId();
  476. }
  477. resultObj.put("fullCutCouponDec", fullCutCouponDec);
  478. resultObj.put("fullCutCouponId", fullCutCouponId);
  479. //订单的总价
  480. BigDecimal orderTotalPrice = goodsTotalPrice.add(freightPrice);
  481. //
  482. BigDecimal actualPrice = orderTotalPrice.subtract(fullCutCouponDec).subtract(couponPrice); //减去其它支付的金额后,要实际支付的金额
  483. resultObj.put("freightPrice", freightPrice);
  484. resultObj.put("checkedCoupon", checkedCoupon);
  485. resultObj.put("couponList", enableCouponList);
  486. resultObj.put("couponPrice", couponPrice);
  487. resultObj.put("checkedGoodsList", checkedGoodsList);
  488. resultObj.put("goodsTotalPrice", goodsTotalPrice);
  489. resultObj.put("orderTotalPrice", orderTotalPrice);
  490. resultObj.put("actualPrice", actualPrice);
  491. if (null != addressEntityList && addressEntityList.size() > 0) {
  492. resultObj.put("addressVo", addressEntityList.get(0));
  493. } else { // 没有默认地址,选择一个
  494. param = new HashMap();
  495. param.put("user_id", loginUser.getId());
  496. addressEntityList = addressService.queryList(param);
  497. if (null != addressEntityList && addressEntityList.size() > 0) {
  498. resultObj.put("addressVo", addressEntityList.get(0));
  499. }
  500. }
  501. return toResponsSuccess(resultObj);
  502. }
  503. /**
  504. * 选择优惠券列表
  505. */
  506. @GetMapping("checkedCouponList")
  507. public Object checkedCouponList(@LoginUser UserVo loginUser) {
  508. //查询列表数据
  509. Map param = new HashMap();
  510. param.put("user_id", loginUser.getId());
  511. Long storeId = getStoreId();
  512. param.put("store_id", storeId);
  513. List<CartVo> cartList = cartService.queryList(param);
  514. //获取购物车统计信息
  515. BigDecimal checkedGoodsAmount = new BigDecimal(0.00);
  516. for (CartVo cartItem : cartList) {
  517. if (null != cartItem.getChecked() && 1 == cartItem.getChecked()) {
  518. checkedGoodsAmount = checkedGoodsAmount.add(cartItem.getRetail_price().multiply(new BigDecimal(cartItem.getNumber())));
  519. }
  520. }
  521. // 匹配优惠券
  522. List<UserCouponVo> couponVos = apiUserCouponService.signUserCouponList(loginUser.getId(), checkedGoodsAmount);
  523. return toResponsSuccess(couponVos);
  524. }
  525. }