| | |
| | | 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.Coupon; |
| | | import com.dsh.activity.entity.CouponStore; |
| | | import com.dsh.activity.entity.TStudent; |
| | | import com.dsh.activity.entity.UserCoupon; |
| | | import com.dsh.activity.feignclient.account.AppUserClient; |
| | | import com.dsh.activity.feignclient.account.StudentClient; |
| | | import com.dsh.activity.feignclient.account.model.AppUser; |
| | | import com.dsh.activity.feignclient.model.CouponStuAvailableVo; |
| | | import com.dsh.activity.feignclient.model.QueryUserCouponByIdAndUserId; |
| | | import com.dsh.activity.model.CouponListVo; |
| | | import com.dsh.activity.model.SendCouponReq; |
| | | import com.dsh.activity.service.CouponStoreService; |
| | | import com.dsh.activity.service.ICouponService; |
| | | import com.dsh.activity.service.UserCouponService; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | |
| | | @Autowired |
| | | private UserCouponService userCouponService; |
| | | |
| | | |
| | | @Autowired |
| | | private CouponStoreService csServie; |
| | | |
| | | @Resource |
| | | private AppUserClient appUserClient; |
| | | |
| | | @Resource |
| | | private StudentClient studentClient; |
| | | |
| | | |
| | | |
| | |
| | | private final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM"); |
| | | |
| | | @PostMapping("/base/userConpon/getStuOfConpons") |
| | | public List<CouponStuAvailableVo> queryUserWithConponList(@RequestParam("appUserId") Integer appUserId){ |
| | | public List<CouponStuAvailableVo> queryUserWithConponList(@RequestParam("appUserId") Integer appUserId) { |
| | | |
| | | List<CouponStuAvailableVo> availableVos = new ArrayList<>(); |
| | | |
| | | List<UserCoupon> list = userCouponService.list(new QueryWrapper<UserCoupon>() |
| | | .eq("userId", appUserId) |
| | | .eq("status",1)); |
| | | if (list.size() > 0){ |
| | | .eq("status", 1)); |
| | | if (list.size() > 0) { |
| | | List<Integer> collect = list.stream().map(UserCoupon::getCouponId).collect(Collectors.toList()); |
| | | List<Coupon> conponList = cService.list(new QueryWrapper<Coupon>() |
| | | .in("id", collect)); |
| | |
| | | availableVo.setConponId(coupon.getId()); |
| | | availableVo.setConponName(coupon.getName()); |
| | | availableVo.setConponType(coupon.getType()); |
| | | Map<String,Object> conponRuleMap = cService.queryConponRuleOfJson(coupon.getId()); |
| | | switch (coupon.getType()){ |
| | | Map<String, Object> conponRuleMap = cService.queryConponRuleOfJson(coupon.getId()); |
| | | switch (coupon.getType()) { |
| | | case 1: |
| | | Object conditionalAmount = conponRuleMap.get("conditionalAmount"); |
| | | Object deductionAmount = conponRuleMap.get("deductionAmount"); |
| | |
| | | break; |
| | | case 2: |
| | | Object amount = conponRuleMap.get("deductionAmount"); |
| | | availableVo.setAmount((double)amount); |
| | | availableVo.setAmount((double) amount); |
| | | break; |
| | | default: |
| | | break; |
| | |
| | | return availableVos; |
| | | } |
| | | |
| | | @PostMapping("/base/userConpon/queryCouponRules") |
| | | public Map<String, Object> getCouponRules(@RequestBody Integer couponId) { |
| | | return cService.queryConponRuleOfJson(couponId); |
| | | } |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/base/userConpon/getCoupons") |
| | | public List<Coupon> getCoupons(@RequestBody String couponIds) { |
| | | ArrayList<Integer> integers = new ArrayList<>(); |
| | | for (String s : couponIds.split(",")) { |
| | | Integer integer = Integer.valueOf(s); |
| | | integers.add(integer); |
| | | } |
| | | return cService.list(new LambdaQueryWrapper<Coupon>().in(Coupon::getId, integers)); |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | |
| | | @ApiImplicitParam(value = "纬度", name = "lat", dataType = "string", required = true), |
| | | @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") |
| | | }) |
| | | public ResultUtil<List<CouponListVo>> queryAvailableCouponList(Integer coursePackageId, Double price, String lon, String lat){ |
| | | public ResultUtil<List<CouponListVo>> queryAvailableCouponList(Integer coursePackageId, Double price, String lon, String lat) { |
| | | try { |
| | | Integer uid = tokenUtil.getUserIdFormRedis(); |
| | | if(null == uid){ |
| | | if (null == uid) { |
| | | return ResultUtil.tokenErr(); |
| | | } |
| | | List<CouponListVo> listVos = userCouponService.queryAvailableCouponList(uid, coursePackageId, price, lon, lat); |
| | | return ResultUtil.success(listVos); |
| | | }catch (Exception e){ |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return ResultUtil.runErr(); |
| | | } |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/api/coupon/querySiteCouponList") |
| | | @ApiOperation(value = "获取场地支付页面可用优惠券列表", tags = {"APP-预约场地", ""}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "场地id", name = "siteId", dataType = "int", required = true), |
| | | @ApiImplicitParam(value = "支付金额", name = "price", dataType = "double", required = true), |
| | | @ApiImplicitParam(value = "经度", name = "lon", dataType = "string", required = true), |
| | | @ApiImplicitParam(value = "纬度", name = "lat", dataType = "string", required = true), |
| | | @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") |
| | | }) |
| | | public ResultUtil<List<CouponListVo>> querySiteCouponList(Integer siteId, Double price, String lon, String lat) { |
| | | try { |
| | | Integer uid = tokenUtil.getUserIdFormRedis(); |
| | | if (null == uid) { |
| | | return ResultUtil.tokenErr(); |
| | | } |
| | | List<CouponListVo> listVos = userCouponService.querySiteCouponList(uid, siteId, price, lon, lat); |
| | | return ResultUtil.success(listVos); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return ResultUtil.runErr(); |
| | | } |
| | |
| | | |
| | | /** |
| | | * 根据id获取用户优惠券数据 |
| | | * @param id |
| | | * |
| | | * @param |
| | | * @return |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping("/userCoupon/queryUserCouponById") |
| | | public UserCoupon queryUserCouponById(@RequestBody Long id){ |
| | | public UserCoupon queryUserCouponById(@RequestBody QueryUserCouponByIdAndUserId userCouponByIdAndUserId) { |
| | | try { |
| | | UserCoupon userCoupon = userCouponService.getById(id); |
| | | UserCoupon userCoupon = userCouponService.getOne(new LambdaQueryWrapper<UserCoupon>().eq(UserCoupon::getId, userCouponByIdAndUserId.getId()).eq(UserCoupon::getUserId, userCouponByIdAndUserId.getUserId())); |
| | | return userCoupon; |
| | | }catch (Exception e){ |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/userCoupon/queryUserCouponById1") |
| | | public UserCoupon queryUserCouponById1(@RequestBody Long id) { |
| | | try { |
| | | UserCoupon userCoupon = userCouponService.getOne(new LambdaQueryWrapper<UserCoupon>().eq(UserCoupon::getId, id)); |
| | | return userCoupon; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | @Autowired |
| | | private ICouponService couponService; |
| | | |
| | | @PostMapping("/userCoupon/edit") |
| | | public void edit(@RequestBody UserCoupon userCoupon) { |
| | | userCoupon.setUserId(null); |
| | | userCouponService.updateById(userCoupon); |
| | | |
| | | } |
| | | |
| | | @PostMapping("/userCoupon/sendUserCoupon") |
| | | public void sendUserCoupon(@RequestBody SendCouponReq sendCouponReq) { |
| | | try { |
| | | String couponIds = sendCouponReq.getCouponIds(); |
| | | for (String s : couponIds.split(",")) { |
| | | Coupon coupon = couponService.getById(s); |
| | | Integer userId = sendCouponReq.getUserId(); |
| | | if(coupon.getAuditStatus() != 2){ |
| | | continue; |
| | | } |
| | | if(coupon.getStatus() != 2){ |
| | | continue; |
| | | } |
| | | if(coupon.getState() != 1){ |
| | | continue; |
| | | } |
| | | if(coupon.getUserPopulation() == 2){ |
| | | AppUser appUser = appUserClient.queryAppUser(userId); |
| | | if(appUser.getIsVip() == 0){ |
| | | continue; |
| | | } |
| | | } |
| | | if(coupon.getUserPopulation() == 3){ |
| | | List<TStudent> tStudents = studentClient.queryStudentList(userId); |
| | | if(tStudents.size() == 0){ |
| | | continue; |
| | | } |
| | | } |
| | | if (new Date().before(coupon.getStartTime()) && new Date().after(coupon.getEndTime())) { |
| | | continue; |
| | | } |
| | | //查询该优惠卷的数量够不够 |
| | | List<Integer> queryIds = new ArrayList<>(); |
| | | queryIds.add(coupon.getId()); |
| | | int counts = userCouponService.count(new QueryWrapper<UserCoupon>().eq("couponId", s)); |
| | | if (coupon.getQuantityIssued() <= counts) { |
| | | continue; |
| | | } |
| | | counts = userCouponService.count(new QueryWrapper<UserCoupon>().eq("couponId", s).eq("userId", userId)); |
| | | if (coupon.getPickUpQuantity() <= counts) { |
| | | continue; |
| | | } |
| | | |
| | | UserCoupon userCoupon = new UserCoupon(); |
| | | userCoupon.setCouponId(Integer.valueOf(s)); |
| | | userCoupon.setUserId(sendCouponReq.getUserId()); |
| | | userCoupon.setStatus(1); |
| | | userCoupon.setInsertTime(new Date()); |
| | | userCouponService.save(userCoupon); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 修改优惠券数据 |
| | | * |
| | | * @param userCoupon |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping("/userCoupon/updateUserCoupon") |
| | | public void updateUserCoupon(@RequestBody UserCoupon userCoupon) { |
| | | try { |
| | | userCoupon.setUserId(null); |
| | | userCouponService.updateById(userCoupon); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/userCoupon/queryCouponOfStore") |
| | | public List<Integer> getCouponStoreIds(@RequestBody Integer couponId){ |
| | | public List<Integer> getCouponStoreIds(@RequestBody Integer couponId) { |
| | | try { |
| | | List<Integer> storeIds = new ArrayList<>(); |
| | | List<CouponStore> list = csServie.list(new QueryWrapper<CouponStore>() |
| | | .eq("couponId",couponId)); |
| | | if (list.size() > 0 ){ |
| | | .eq("couponId", couponId)); |
| | | if (list.size() > 0) { |
| | | storeIds = list.stream().map(CouponStore::getStoreId).collect(Collectors.toList()); |
| | | } |
| | | if (storeIds.size() == 0) { |
| | | storeIds.add(-1); |
| | | } |
| | | return storeIds; |
| | | }catch (Exception e){ |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/userCoupon/queryCounts") |
| | | public Integer queryCounts(@RequestBody List<Integer> queryIds) { |
| | | return userCouponService.count(new QueryWrapper<UserCoupon>().eq("couponId", queryIds.get(0))); |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/userCoupon/queryCounts1") |
| | | public Integer queryCounts1(@RequestBody List<Integer> queryIds) { |
| | | return userCouponService.count(new QueryWrapper<UserCoupon>().eq("couponId", queryIds.get(0)).eq("userId", queryIds.get(1))); |
| | | |
| | | |
| | | } |
| | | |
| | | } |