| | |
| | | package com.dsh.activity.controller; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | 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.UserCoupon; |
| | | import com.dsh.activity.entity.*; |
| | | 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.GrantCoupon; |
| | | 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 com.dsh.activity.service.VipDetailService; |
| | | import com.dsh.activity.util.DateUtil; |
| | | import com.dsh.activity.util.ResultUtil; |
| | | import com.dsh.activity.util.TokenUtil; |
| | | import io.swagger.annotations.Api; |
| | |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | |
| | | @Autowired |
| | | private UserCouponService userCouponService; |
| | | |
| | | |
| | | @Autowired |
| | | private CouponStoreService csServie; |
| | | |
| | | @Resource |
| | | private AppUserClient appUserClient; |
| | | |
| | | @Resource |
| | | private StudentClient studentClient; |
| | | @Autowired |
| | | private VipDetailService vipDetailService; |
| | | |
| | | |
| | | |
| | | |
| | | private final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM"); |
| | |
| | | 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; |
| | | } |
| | |
| | | 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; |
| | | } |
| | | |
| | |
| | | @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))); |
| | | |
| | | |
| | | } |
| | | |
| | | // 开通会员后 赠送优惠券和门票 |
| | | @ResponseBody |
| | | @PostMapping("/userCoupon/grantCoupon") |
| | | public void grantCoupon(@RequestBody GrantCoupon grantCoupon) { |
| | | String couponJson = grantCoupon.getCouponJson(); |
| | | if (StringUtils.hasLength(couponJson)) { |
| | | |
| | | // 赠送优惠券 |
| | | JSONArray objects = JSON.parseArray(couponJson); |
| | | for (Object object : objects) { |
| | | JSONObject jsonObject = (JSONObject) object; |
| | | // 优惠券id |
| | | String id = jsonObject.getString("id"); |
| | | // 优惠券数量 |
| | | String value = jsonObject.getString("value"); |
| | | for (Integer i = 0; i < Integer.valueOf(value); i++) { |
| | | UserCoupon userCoupon = new UserCoupon(); |
| | | userCoupon.setCouponId(Integer.valueOf(id)); |
| | | userCoupon.setUserId(grantCoupon.getUserId()); |
| | | userCoupon.setStatus(1); |
| | | userCoupon.setVerificationUserId(null); |
| | | userCoupon.setVerificationTime(null); |
| | | userCoupon.setInsertTime(new Date()); |
| | | userCoupon.setIsVipGrant(1); |
| | | userCouponService.save(userCoupon); |
| | | // 生成对应的权益明细记录 |
| | | VipDetail vipDetail = new VipDetail(); |
| | | vipDetail.setAppUserId(grantCoupon.getUserId()); |
| | | vipDetail.setStatus(1); |
| | | vipDetail.setInsertTime(new Date()); |
| | | vipDetail.setVipId(grantCoupon.getVipId()); |
| | | vipDetail.setType(1); |
| | | vipDetail.setVipPaymentId(grantCoupon.getVipPaymentId()); |
| | | vipDetail.setCouponId(Integer.valueOf(id)); |
| | | vipDetail.setUserCouponId(userCoupon.getId()); |
| | | vipDetailService.save(vipDetail); |
| | | } |
| | | } |
| | | } |
| | | String ticketJson = grantCoupon.getTicketJson(); |
| | | if (StringUtils.hasLength(ticketJson)) { |
| | | // 赠送优惠券 |
| | | JSONArray objects = JSON.parseArray(ticketJson); |
| | | for (Object object : objects) { |
| | | JSONObject jsonObject = (JSONObject) object; |
| | | // 门票名称 |
| | | String name = jsonObject.getString("name"); |
| | | // 领取后x天有效 |
| | | String time = jsonObject.getString("time"); |
| | | Integer days = Integer.valueOf(time); |
| | | // 可用次数 |
| | | String count = jsonObject.getString("count"); |
| | | for (Integer i = 0; i < Integer.valueOf(count); i++) { |
| | | // 生成对应的权益明细记录 |
| | | VipDetail vipDetail = new VipDetail(); |
| | | vipDetail.setTicketName(name); |
| | | vipDetail.setStartTime(new Date()); |
| | | Date date = new Date(); |
| | | // 加X天 |
| | | Date tomorrow = new Date(date.getTime() + 24 * 60 * 60 * 1000L * days); |
| | | vipDetail.setEndTime(tomorrow); |
| | | vipDetail.setAppUserId(grantCoupon.getUserId()); |
| | | vipDetail.setStatus(1); |
| | | vipDetail.setInsertTime(new Date()); |
| | | vipDetail.setVipId(grantCoupon.getVipPaymentId()); |
| | | vipDetail.setType(2); |
| | | vipDetail.setVipPaymentId(grantCoupon.getVipPaymentId()); |
| | | vipDetailService.save(vipDetail); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |