| package com.matrix.system.shopXcx.api.action; | 
|   | 
| import com.matrix.biz.bean.BizUser; | 
| import com.matrix.component.redis.RedisUserLoginUtils; | 
| import com.matrix.core.pojo.AjaxResult; | 
| import com.matrix.system.common.interceptor.HostInterceptor; | 
| import com.matrix.system.hive.dao.SysVipInfoDao; | 
| import com.matrix.system.shopXcx.api.service.WXShopOrderService; | 
| import com.matrix.system.shopXcx.api.service.WxShopActivitiesGroupService; | 
| import com.matrix.system.shopXcx.api.vo.WxActivitiesGroupBuyVO; | 
| import com.matrix.system.shopXcx.bean.*; | 
| import com.matrix.system.shopXcx.dao.*; | 
| import com.matrix.system.shopXcx.dto.CreateGroupBuyDTO; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.beans.factory.annotation.Value; | 
| import org.springframework.transaction.annotation.Transactional; | 
| import org.springframework.web.bind.annotation.*; | 
|   | 
| import java.math.BigDecimal; | 
| import java.util.Calendar; | 
| import java.util.Date; | 
| import java.util.List; | 
|   | 
| /** | 
|  * 小程序端 拼团接口 | 
|  * | 
|  * @Author wzy | 
|  */ | 
| @CrossOrigin(origins = "*") | 
| @RestController | 
| @RequestMapping(value = "wxapi/groupBuy") | 
| public class WxShopActivitiesGroupBuyController { | 
|   | 
|     @Autowired | 
|     private ShopActivitiesDao shopActivitiesDao; | 
|   | 
|     @Autowired | 
|     private ShopActivitiesGroupInfoDao shopActivitiesGroupInfoDao; | 
|   | 
|     @Autowired | 
|     private ShopActivitiesGroupJoinDao shopActivitiesGroupJoinDao; | 
|   | 
|     @Autowired | 
|     private ShopActivitiesGroupPriceDao shopActivitiesGroupPriceDao; | 
|   | 
|     @Autowired | 
|     private ShopActivitiesGroupJoinUserDao shopActivitiesGroupJoinUserDao; | 
|   | 
|     @Autowired | 
|     private ShopProductAttrRefDao shopProductAttrRefDao; | 
|   | 
|     @Autowired | 
|     private ShopSkuDao shopSkuDao; | 
|   | 
|     @Autowired | 
|     private ShopProductImgDao shopProductImgDao; | 
|   | 
|     @Autowired | 
|     private ShopProductParamRefDao shopProductParamRefDao; | 
|   | 
|     @Autowired | 
|     private ShopProductDao shopProductDao; | 
|   | 
|     @Autowired | 
|     private RedisUserLoginUtils redisUserLoginUtils; | 
|   | 
|     @Autowired | 
|     private WxShopActivitiesGroupService wxShopActivitiesGroupService; | 
|   | 
|     @Autowired | 
|     private WXShopOrderService wxShopOrderService; | 
|   | 
|     @Value("${activities.groupBuy.limit}") | 
|     private String groupBuyLimit; | 
|   | 
|     @Value("${groupBuy.pay.timeLimit}") | 
|     private String payTimeLimit; | 
|   | 
|     /** | 
|      * 获取拼团列表 | 
|      * | 
|      * @param buyVO | 
|      * @return | 
|      */ | 
|     @PostMapping(value = "/showGroupByList") | 
|     public AjaxResult showGroupByList(@RequestBody WxActivitiesGroupBuyVO buyVO) { | 
|         buyVO.setCompanyId(HostInterceptor.getCompanyId()); | 
|         List<WxActivitiesGroupBuyVO> dataList = shopActivitiesGroupInfoDao.selectGroupBuyList(buyVO); | 
|         int count = shopActivitiesGroupInfoDao.selectGroupBuyListCnt(buyVO); | 
|         return new AjaxResult(AjaxResult.STATUS_SUCCESS, dataList, count); | 
|     } | 
|   | 
|     /** | 
|      * 获取拼团信息及商品信息 | 
|      * | 
|      * @param actId | 
|      * @return | 
|      */ | 
|     @GetMapping(value = "/findGroupBuyInfo/{actId}") | 
|     public AjaxResult findGroupBuyInfo(@PathVariable("actId") Long actId) { | 
|         WxActivitiesGroupBuyVO groupBuyVO = shopActivitiesGroupInfoDao.selectGroupInfoWithPriceByActId(actId); | 
|         ShopProduct goods = shopProductDao.selectById(groupBuyVO.getGoodsId().intValue()); | 
|   | 
|         //补充产品 扩展信息 | 
|         List<ShopProductAttrRef> shopProductAttrRefs = shopProductAttrRefDao.selectByPid(goods.getId()); | 
|         List<ShopProductImg> shopProductImgs = shopProductImgDao.selectByPid(goods.getId()); | 
|         List<ShopSku> shopSkus = shopSkuDao.selectByPid(goods.getId()); | 
|         List<ShopProductParamRef> shopProductParamRefs = shopProductParamRefDao.selectByPid(goods.getId()); | 
|         goods.setAttrRefs(shopProductAttrRefs); | 
|         goods.setProductImgs(shopProductImgs); | 
|         goods.setSkus(shopSkus); | 
|         goods.setParams(shopProductParamRefs); | 
|   | 
|   | 
|         AjaxResult ajaxResult = new AjaxResult(AjaxResult.STATUS_SUCCESS, null); | 
|         ajaxResult.putInMap("groupBuyInfo", groupBuyVO); | 
|         ajaxResult.putInMap("goodsInfo", goods); | 
|         return ajaxResult; | 
|     } | 
|   | 
|     /** | 
|      * 获取用户当前的拼团信息 | 
|      * | 
|      * @return | 
|      */ | 
|     @GetMapping(value = "/findOwnerGroupBuyInfo/{actId}") | 
|     public AjaxResult findOwnerGroupBuyInfo(@PathVariable("actId") Long actId) { | 
|         BizUser bizUser = redisUserLoginUtils.getLoginUser(BizUser.class); | 
|   | 
|         // 1、判断该用户在该活动中有没有正在拼团 若有,则返回正在拼团的用户列表,若没有则返回gruoping=1且返回正在拼团的拼团列表, 若加入了团未完成付款,则需要再做设置 | 
|         ShopActivitiesGroupJoin isExsit = shopActivitiesGroupJoinDao.selectIsExistGroupInfoByUserId(actId, bizUser.getOpenId()); | 
|         AjaxResult ajaxResult = new AjaxResult(AjaxResult.STATUS_SUCCESS, null); | 
|         if (isExsit == null) { | 
|             ajaxResult.putInMap("grouping", 2); | 
|             List<ShopActivitiesGroupJoin> list = shopActivitiesGroupJoinDao.selectGroupingListByActId(actId); | 
|             ajaxResult.putInMap("groupList", list); | 
|         } else { | 
|             ajaxResult.putInMap("grouping", 1); | 
|             ShopActivitiesGroupJoin groupJoin = shopActivitiesGroupJoinDao.selectOwnerGroupJoinInfoWithNoPay(isExsit.getId()); | 
|             ShopActivitiesGroupJoinUser groupJoinUser = shopActivitiesGroupJoinUserDao.selectGroupJoinUserByUserIdAndGjId(bizUser.getOpenId(), groupJoin.getId()); | 
|             ShopActivitiesGroupPrice price = shopActivitiesGroupPriceDao.selectById(groupJoin.getGpId()); | 
|             int theLast = price.getGpCount() - groupJoin.getJoinUserList().size(); | 
|             groupJoin.setTheLast(theLast); | 
|             ajaxResult.putInMap("ownerGroupInfo", groupJoin); | 
|             ajaxResult.putInMap("myself", groupJoinUser); | 
|             ajaxResult.putInMap("price", price); | 
|             ajaxResult.putInMap("theLast", theLast); | 
|         } | 
|         return ajaxResult; | 
|     } | 
|   | 
|     /** | 
|      * 获取当前拼团信息及用户列表 | 
|      * | 
|      * @param gjId | 
|      * @return | 
|      */ | 
|     @GetMapping(value = "/findGroupJoinInfo/{gjId}") | 
|     public AjaxResult findGroupJoinInfo(@PathVariable Long gjId) { | 
|         BizUser bizUser = redisUserLoginUtils.getLoginUser(BizUser.class); | 
|         ShopActivitiesGroupJoin groupJoin = shopActivitiesGroupJoinDao.selectOwnerGroupJoinInfo(gjId); | 
|         int isExist = 2; | 
|   | 
|         for (ShopActivitiesGroupJoinUser joinUser : groupJoin.getJoinUserList()) { | 
|             if (bizUser.getOpenId().equals(joinUser.getUserId())) { | 
|                 isExist = 1; | 
|             } | 
|         } | 
|         ShopActivitiesGroupPrice price = shopActivitiesGroupPriceDao.selectById(groupJoin.getGpId()); | 
|         int theLast = price.getGpCount() - groupJoin.getJoinUserList().size(); | 
|         AjaxResult ajaxResult = new AjaxResult(AjaxResult.STATUS_SUCCESS, null); | 
|         groupJoin.setTheLast(theLast); | 
|         ajaxResult.putInMap("groupJoin", groupJoin); | 
|         ajaxResult.putInMap("isExist", isExist); | 
|         ajaxResult.putInMap("price", price); | 
|         return ajaxResult; | 
|     } | 
|   | 
|     /** | 
|      * 拼团开团接口 | 
|      * | 
|      * @param createGroupBuyDTO | 
|      * @return | 
|      */ | 
|     @PostMapping(value = "/createGroupBuy") | 
|     @Transactional | 
|     public AjaxResult createGroupBuy(@RequestBody CreateGroupBuyDTO createGroupBuyDTO) throws Exception { | 
|         return wxShopActivitiesGroupService.createGroupBuy(createGroupBuyDTO); | 
|     } | 
|   | 
|     /** | 
|      * 用户加入拼团 | 
|      * | 
|      * @param createGroupBuyDTO | 
|      * @return | 
|      */ | 
|     @PostMapping(value = "/joinGroupBuy") | 
|     public AjaxResult joinGroupBuy(@RequestBody CreateGroupBuyDTO createGroupBuyDTO) throws Exception { | 
|         return wxShopActivitiesGroupService.joinGroupBuy(createGroupBuyDTO); | 
|     } | 
|   | 
|     @PostMapping(value = "/calPrice") | 
|     public AjaxResult calPrice(@RequestBody CreateGroupBuyDTO createGroupBuyDTO) { | 
|         ShopActivitiesGroupPrice groupPrice = shopActivitiesGroupPriceDao.selectById(createGroupBuyDTO.getGpId()); | 
|         // 判断参数中gjId是否为空,若为空则为团长开团。再判断团长价是否为空,如果不为空则拥有团长价 | 
|         if (createGroupBuyDTO.getGjId() == null) { | 
|             if (groupPrice.getGpHeadPrice() != null) { | 
|                 createGroupBuyDTO.setPrice(groupPrice.getGpHeadPrice()); | 
|             } else { | 
|                 createGroupBuyDTO.setPrice(groupPrice.getGpPrice()); | 
|             } | 
|         } else { | 
|             createGroupBuyDTO.setPrice(groupPrice.getGpPrice()); | 
|         } | 
|         BigDecimal postage = wxShopOrderService.calculationPostage(createGroupBuyDTO.getAddressId(), createGroupBuyDTO.getPrice()); | 
|         BigDecimal payPrice = createGroupBuyDTO.getPrice().multiply(BigDecimal.valueOf(createGroupBuyDTO.getCount())).add(postage); | 
|         AjaxResult ajaxResult = new AjaxResult(AjaxResult.STATUS_SUCCESS, null); | 
|         ajaxResult.putInMap("billPrice", createGroupBuyDTO.getPrice().multiply(BigDecimal.valueOf(createGroupBuyDTO.getCount()))); | 
|         ajaxResult.putInMap("totalPrice", payPrice); | 
|         ajaxResult.putInMap("postage", postage); | 
|         return ajaxResult; | 
|     } | 
| } |