| | |
| | | package com.dsh.activity.controller; |
| | | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.dsh.activity.entity.BodySideAppointment; |
| | | import com.dsh.activity.entity.IntroduceRewards; |
| | | import com.dsh.activity.feignclient.account.AppUserClient; |
| | | import com.dsh.activity.feignclient.model.IntrduceOfUserRequest; |
| | | import com.dsh.activity.feignclient.model.PurchaseRecordVo; |
| | | import com.dsh.activity.feignclient.other.model.Store; |
| | | import com.dsh.activity.model.*; |
| | | import com.dsh.activity.service.IntroduceRewardsService; |
| | | import com.dsh.activity.service.IntroduceUserService; |
| | | import io.swagger.annotations.Api; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.text.Format; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Api |
| | | @CrossOrigin |
| | |
| | | @RequestMapping("") |
| | | public class IntroduceRewardsController { |
| | | |
| | | |
| | | @Autowired |
| | | private IntroduceRewardsService idrService; |
| | | @Autowired |
| | | private IntroduceUserService introduceUserService; |
| | | |
| | | |
| | | private final SimpleDateFormat mat = new SimpleDateFormat("MM-dd HH:mm"); |
| | | |
| | | /** |
| | | * 获取介绍有礼-参与用户记录表 |
| | | * |
| | | * @return |
| | | */ |
| | | @RequestMapping("/base/introduceUser/listAllUser") |
| | | public List<IntroduceUser> listAllUser(@RequestBody IntroduceUserQuery query) { |
| | | return introduceUserService.listAll(query); |
| | | } |
| | | |
| | | /** |
| | | * 通过id获取介绍有礼 |
| | | * |
| | | * @return |
| | | */ |
| | | @RequestMapping("/base/introduce/getInfoById") |
| | | public IntroduceRewards getInfoById(@RequestBody Integer id) { |
| | | return idrService.getById(id); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 获取介绍有礼记录表 |
| | | * |
| | | * @return |
| | | */ |
| | | @RequestMapping("/base/introduce/listAll") |
| | | public List<IntroduceVO> listAll(@RequestBody IntroduceQuery query) { |
| | | Date date = new Date(); |
| | | List<IntroduceVO> introduceVOS = idrService.listAll(query); |
| | | for (IntroduceVO introduceVO : introduceVOS) { |
| | | |
| | | Date startTime = introduceVO.getStartTime(); |
| | | Date endTime = introduceVO.getEndTime(); |
| | | if (date.after(startTime) && date.before(endTime)) { |
| | | introduceVO.setActivityState(1); |
| | | } else if (date.before(startTime)) { |
| | | introduceVO.setActivityState(2); |
| | | } else if (date.after(endTime)) { |
| | | introduceVO.setActivityState(3); |
| | | } |
| | | } |
| | | return introduceVOS; |
| | | } |
| | | |
| | | /** |
| | | * 增加/修改介绍有礼记录 |
| | | * |
| | | * @return |
| | | */ |
| | | @RequestMapping("/base/introduce/addIntroduce") |
| | | public Object addIntroduce(@RequestBody IntroduceRewards introduceRewards) { |
| | | |
| | | |
| | | if (introduceRewards.getId() != null) { |
| | | IntroduceRewards byId = idrService.getById(introduceRewards.getId()); |
| | | // 判断当前活动有没有开始 如果开始了不能编辑赠送课时数 不能编辑活动开始时间 |
| | | Date endTime = byId.getEndTime(); |
| | | Date startTime = byId.getStartTime(); |
| | | Date local = new Date(); |
| | | if (startTime.before(local) && endTime.after(local)) { |
| | | // 证明当前活动已开始 |
| | | // 判断有没有修改开始时间 |
| | | if (!introduceRewards.getStartTime().equals(byId.getStartTime())) { |
| | | // 表示不能修改开始时间 |
| | | return 5002; |
| | | } |
| | | if (!introduceRewards.getGiveClass().equals(byId.getGiveClass())) { |
| | | // 表示不能修改赠送课时数 |
| | | return 5001; |
| | | } |
| | | } |
| | | return idrService.updateById(introduceRewards); |
| | | } else { |
| | | introduceRewards.setInsertTime(new Date()); |
| | | return idrService.save(introduceRewards); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 上/下架介绍有礼 type = 1上架 type=2下架 |
| | | * |
| | | * @return |
| | | */ |
| | | @RequestMapping("/base/introduce/changeState") |
| | | public Object changeState(@RequestBody IntroduceChangeStateDTO dto) { |
| | | return idrService.changeState(dto); |
| | | } |
| | | |
| | | @PostMapping("/base/introduce/useOfRewards") |
| | | public List<PurchaseRecordVo> queryAppUsersofIntroduce(@RequestBody IntrduceOfUserRequest request){ |
| | | public List<PurchaseRecordVo> queryAppUsersofIntroduce(@RequestBody IntrduceOfUserRequest request) { |
| | | List<PurchaseRecordVo> recordVos = new ArrayList<>(); |
| | | List<IntroduceRewards> list = idrService.list(new QueryWrapper<IntroduceRewards>() |
| | | .ge("startTime",request.getStartTime()) |
| | | .lt("endTime",request.getEndTime())); |
| | | if (request.getUserIds().size() > 0 && list.size() > 0){ |
| | | .ge("startTime", request.getStartTime()) |
| | | .lt("endTime", request.getEndTime())); |
| | | if (request.getUserIds().size() > 0 && list.size() > 0) { |
| | | IntroduceRewards introduceRewards = list.get(0); |
| | | request.getUserIds().forEach( userId -> { |
| | | request.getUserIds().forEach(userId -> { |
| | | PurchaseRecordVo recordVo = new PurchaseRecordVo(); |
| | | recordVo.setPurchaseAmount("+"+introduceRewards.getGiveClass()); |
| | | recordVo.setPurchaseAmount("+" + introduceRewards.getGiveClass()); |
| | | recordVo.setPurchaseType("介绍有礼"); |
| | | recordVos.add(recordVo); |
| | | } ); |
| | | }); |
| | | } |
| | | return recordVos; |
| | | } |
| | | |
| | | @PostMapping("/base/introduce/getGiftList") |
| | | @ResponseBody |
| | | public List<IntroduceRewards> getGiftList(@RequestBody String cityCode) { |
| | | List<IntroduceRewards> list = idrService.list(new LambdaQueryWrapper<IntroduceRewards>() |
| | | .eq(IntroduceRewards::getCityCode, cityCode) |
| | | .le(IntroduceRewards::getStartTime, new Date()) |
| | | .ge(IntroduceRewards::getEndTime, new Date()) |
| | | .eq(IntroduceRewards::getState, 1) |
| | | .orderByDesc(IntroduceRewards::getInsertTime) |
| | | ); |
| | | return list; |
| | | } |
| | | |
| | | } |