|  |  |  | 
|---|
|  |  |  | package com.matrix.system.shopXcx.api.action; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.matrix.system.hive.bean.SysVipInfo; | 
|---|
|  |  |  | import com.matrix.component.redis.RedisUserLoginUtils; | 
|---|
|  |  |  | import com.matrix.core.constance.SystemErrorCode; | 
|---|
|  |  |  | import com.matrix.core.constance.SystemMessageCode; | 
|---|
|  |  |  | import com.matrix.core.exception.GlobleException; | 
|---|
|  |  |  | import com.matrix.core.pojo.AjaxResult; | 
|---|
|  |  |  | import com.matrix.core.tools.StringUtils; | 
|---|
|  |  |  | import com.matrix.biz.bean.BizUser; | 
|---|
|  |  |  | import com.matrix.component.redis.RedisUserLoginUtils; | 
|---|
|  |  |  | import com.matrix.system.common.constance.AppConstance; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.matrix.system.shopXcx.bean.ShopShoppingCart; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.bean.ShopSku; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.dao.ShopShoppingCartDao; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.dao.ShopSkuDao; | 
|---|
|  |  |  | import com.matrix.system.common.interceptor.HostInterceptor; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.api.service.OrderCouponGroupService; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.api.service.ShoppingCartService; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.api.service.WxShopCouponService; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.api.vo.ShopCartBillVo; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.api.vo.ShopCartVo; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.bean.ShopShoppingCart; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.bean.ShopSku; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.dao.ShopShoppingCartDao; | 
|---|
|  |  |  | import com.matrix.system.shopXcx.dao.ShopSkuDao; | 
|---|
|  |  |  | import io.swagger.annotations.Api; | 
|---|
|  |  |  | import io.swagger.annotations.ApiOperation; | 
|---|
|  |  |  | import org.apache.commons.collections.CollectionUtils; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Controller; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | 
|---|
|  |  |  | * @date 2019-06-12 19:15 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @CrossOrigin(origins = "*", maxAge = 3600) | 
|---|
|  |  |  | @Controller | 
|---|
|  |  |  | @Api(tags = "购物车类") | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | @RequestMapping(value = "wxapi/ShoppingCart") | 
|---|
|  |  |  | public class WxShoppingCartAction { | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | ShopSkuDao skuDao; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | OrderCouponGroupService orderCouponGroupService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据ID删除购物车 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @ApiOperation(value = "根据ID删除购物车", notes = "") | 
|---|
|  |  |  | @PostMapping("/deleteByCartId/{cartId}") | 
|---|
|  |  |  | @ResponseBody | 
|---|
|  |  |  | public AjaxResult deleteByCartId(@PathVariable("cartId") Integer cartId) { | 
|---|
|  |  |  | 
|---|
|  |  |  | return new AjaxResult(AjaxResult.STATUS_SUCCESS, "删除成功"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据用户ID查询购物车 没有分页 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "根据用户ID查询购物车 没有分页", notes = "") | 
|---|
|  |  |  | @PostMapping("/findShoppingCart") | 
|---|
|  |  |  | @ResponseBody | 
|---|
|  |  |  | public AjaxResult getShoppingCartByUserId(@RequestBody ShopShoppingCart shoppingCart) { | 
|---|
|  |  |  | List<ShopCartVo> cartList = shoppingCartService.findUserCartList(shoppingCart.getShopId(),ShopShoppingCart.CAR_TYPE_MICRO); | 
|---|
|  |  |  | AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, cartList, cartList.size()); | 
|---|
|  |  |  | ShopCartBillVo shopCartBill = shoppingCartService.buildShopCartBillVo(cartList); | 
|---|
|  |  |  | SysVipInfo loginUser = redisUserLoginUtils.getLoginUser(SysVipInfo.class); | 
|---|
|  |  |  | List<ShopShoppingCart> list = shoppingCartDao.selectByCartUserId(shoppingCart.getShopId(),loginUser.getId()); | 
|---|
|  |  |  | List<ShopCartVo> shopCartVoList = shoppingCartService.buildShopCart(list); | 
|---|
|  |  |  | AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, shopCartVoList, shopCartVoList.size()); | 
|---|
|  |  |  | ShopCartBillVo shopCartBill = shoppingCartService.buildShopCartBillVo(shopCartVoList); | 
|---|
|  |  |  | result.putInMap("billTotal", shopCartBill.getBillTotal().stripTrailingZeros().toPlainString()); | 
|---|
|  |  |  | result.putInMap("selectCount", shopCartBill.getSelectCount()); | 
|---|
|  |  |  | result.putInMap("cartCount", shopCartBill.getCartCount()); | 
|---|
|  |  |  | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 批量删除 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "批量删除", notes = "") | 
|---|
|  |  |  | @PostMapping(value = "/delShoppingCart/{keys}") | 
|---|
|  |  |  | public | 
|---|
|  |  |  | @ResponseBody | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "查询微商城购物车数量", notes = "") | 
|---|
|  |  |  | @PostMapping(value = "/getUserCartCount/{shopId}") | 
|---|
|  |  |  | public | 
|---|
|  |  |  | @ResponseBody | 
|---|
|  |  |  | AjaxResult getUserCartCount(@PathVariable("shopId") Long shopId) { | 
|---|
|  |  |  | BizUser loginUser = redisUserLoginUtils.getLoginUser(BizUser.class); | 
|---|
|  |  |  | Integer userCartCount = shoppingCartDao.selectUserCartCount(shopId, loginUser.getOpenId()); | 
|---|
|  |  |  | SysVipInfo loginUser = redisUserLoginUtils.getLoginUser(SysVipInfo.class); | 
|---|
|  |  |  | Integer userCartCount = shoppingCartDao.selectUserCartCount(shopId, loginUser.getId()); | 
|---|
|  |  |  | if (userCartCount == null) { | 
|---|
|  |  |  | userCartCount = 0; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | AjaxResult saveShoppingCart(@RequestBody ShopShoppingCart shoppingCart) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //查询到sku设置对应的产品id | 
|---|
|  |  |  | ShopSku sku= skuDao.selectById(shoppingCart.getCartSkuId()); | 
|---|
|  |  |  | if(sku==null){ | 
|---|
|  |  |  | return new AjaxResult(AjaxResult.STATUS_FAIL,"无效的产品id"); | 
|---|
|  |  |  | ShopSku sku = skuDao.selectById(shoppingCart.getCartSkuId()); | 
|---|
|  |  |  | if (sku == null) { | 
|---|
|  |  |  | return new AjaxResult(AjaxResult.STATUS_FAIL, "无效的产品id"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | shoppingCart.setCartProductId(sku.getpId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | BizUser loginUser = redisUserLoginUtils.getLoginUser(BizUser.class); | 
|---|
|  |  |  | SysVipInfo loginUser = redisUserLoginUtils.getLoginUser(SysVipInfo.class); | 
|---|
|  |  |  | shoppingCart.setCreateBy(loginUser.getOpenId()); | 
|---|
|  |  |  | shoppingCart.setUpdateBy(loginUser.getOpenId()); | 
|---|
|  |  |  | shoppingCart.setCartUserId(loginUser.getOpenId()); | 
|---|
|  |  |  | shoppingCart.setCartType(ShopShoppingCart.CAR_TYPE_MICRO); | 
|---|
|  |  |  | shoppingCart.setCartUserId(loginUser.getId()); | 
|---|
|  |  |  | shoppingCart.setCompanyId(HostInterceptor.getCompanyId()); | 
|---|
|  |  |  | ShopShoppingCart shoppCartLimt = shoppingCartDao.selectBuyLimit(shoppingCart.getCartProductId(), | 
|---|
|  |  |  | shoppingCart.getCartSkuId()); | 
|---|
|  |  |  | // Integer buyLimitNum = 0; | 
|---|
|  |  |  | 
|---|
|  |  |  | ShopShoppingCart shopShoppingCart = new ShopShoppingCart(); | 
|---|
|  |  |  | shopShoppingCart.setCartProductId(cartProductId); | 
|---|
|  |  |  | shopShoppingCart.setCartSkuId(cartSkuId); | 
|---|
|  |  |  | shopShoppingCart.setCartUserId(loginUser.getOpenId()); | 
|---|
|  |  |  | shopShoppingCart.setCartUserId(loginUser.getId()); | 
|---|
|  |  |  | shopShoppingCart.setShopId(shoppingCart.getShopId()); | 
|---|
|  |  |  | List<ShopShoppingCart> shopShoppingCarts = shoppingCartDao.selectByModel(shopShoppingCart); | 
|---|
|  |  |  | int i = 0; | 
|---|
|  |  |  | 
|---|
|  |  |  | return new AjaxResult(AjaxResult.STATUS_FAIL, "保存失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | int userCartCount = shoppingCartDao.selectUserCartCount(shoppingCart.getShopId(), | 
|---|
|  |  |  | loginUser.getOpenId()); | 
|---|
|  |  |  | loginUser.getId()); | 
|---|
|  |  |  | AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, "保存成功"); | 
|---|
|  |  |  | result.putInMap("userCartCount", userCartCount); | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | 
|---|
|  |  |  | * @param | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @RequestMapping("/updateCartSelected") | 
|---|
|  |  |  | @PostMapping("/updateCartSelected") | 
|---|
|  |  |  | @ResponseBody | 
|---|
|  |  |  | public AjaxResult updateCartSelected(@RequestBody ShopShoppingCart shoppingCart) { | 
|---|
|  |  |  | Map<String, Object> modifyMap = new HashMap<>(); | 
|---|
|  |  |  | 
|---|
|  |  |  | * @param | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @RequestMapping("/updateCartAllSelected/{shopId}/{isSelected}") | 
|---|
|  |  |  | @PostMapping("/updateCartAllSelected/{shopId}/{isSelected}") | 
|---|
|  |  |  | @ResponseBody | 
|---|
|  |  |  | public AjaxResult updateCartAllSelected(@PathVariable("isSelected") Integer isSelected, | 
|---|
|  |  |  | @PathVariable("shopId") Long shopId) { | 
|---|
|  |  |  | Map<String, Object> modifyMap = new HashMap<>(); | 
|---|
|  |  |  | BizUser user = redisUserLoginUtils.getLoginUser(BizUser.class); | 
|---|
|  |  |  | shoppingCartDao.updateAllSelected(user.getOpenId(),shopId, isSelected); | 
|---|
|  |  |  | SysVipInfo user = redisUserLoginUtils.getLoginUser(SysVipInfo.class); | 
|---|
|  |  |  | shoppingCartDao.updateAllSelected(user.getOpenId(), shopId, isSelected); | 
|---|
|  |  |  | return new AjaxResult(AjaxResult.STATUS_SUCCESS, "修改成功"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|