| | |
| | | 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.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | 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.feignclient.other.SiteClient; |
| | | import com.dsh.activity.feignclient.other.StoreClient; |
| | | import com.dsh.activity.feignclient.other.model.Store; |
| | | import com.dsh.activity.model.CouponListVo; |
| | | import com.dsh.activity.model.CouponDeductionQuery; |
| | | import com.dsh.activity.model.CouponDeductionVO; |
| | | 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.*; |
| | | 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; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Api |
| | |
| | | |
| | | @Autowired |
| | | private UserCouponService userCouponService; |
| | | @Autowired |
| | | private UserPointsMerchandiseService userPointsMerchandiseService; |
| | | |
| | | |
| | | @Autowired |
| | | private CouponStoreService csServie; |
| | | |
| | | @Resource |
| | | private AppUserClient appUserClient; |
| | | |
| | | @Resource |
| | | private StudentClient studentClient; |
| | | @Autowired |
| | | private VipDetailService vipDetailService; |
| | | @Autowired |
| | | private StoreClient storeClient; |
| | | @Autowired |
| | | private SiteClient siteClient; |
| | | @Autowired |
| | | private PointsMerchandiseService pointsMerchandiseService; |
| | | |
| | | |
| | | |
| | | |
| | | private final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM"); |
| | | |
| | | /** |
| | | * 批量查询已核销优惠券的抵扣金额,供运营数据统计使用。 |
| | | * |
| | | * @param query 用户优惠券领取记录 ID 集合 |
| | | * @return 每条领取记录对应的抵扣金额 |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping("/base/userCoupon/queryDeductionAmounts") |
| | | public List<CouponDeductionVO> queryDeductionAmounts(@RequestBody CouponDeductionQuery query) { |
| | | return userCouponService.queryDeductionAmounts(query); |
| | | } |
| | | |
| | | @PostMapping("/base/userConpon/getStuOfConpons") |
| | | public List<CouponStuAvailableVo> queryUserWithConponList(@RequestParam("appUserId") Integer appUserId) { |
| | |
| | | if (null == uid) { |
| | | return ResultUtil.tokenErr(); |
| | | } |
| | | if(!StringUtils.hasLength(lon)){ |
| | | return ResultUtil.success(new ArrayList<>()); |
| | | } |
| | | if (lon.equals("0.0")){ |
| | | return ResultUtil.success(new ArrayList<>()); |
| | | |
| | | } |
| | | List<CouponListVo> listVos = userCouponService.querySiteCouponList(uid, siteId, price, lon, lat); |
| | | return ResultUtil.success(listVos); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return ResultUtil.runErr(); |
| | | } |
| | | } |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/api/coupon/queryStoreCouponList") |
| | | @ApiOperation(value = "订单支付页可用优惠券列表(购买门票、购买惠民卡)") |
| | | public ResultUtil<List<CouponListVo>> queryStoreCouponList(Integer storeId, Double price, String lon, String lat) { |
| | | try { |
| | | Integer uid = tokenUtil.getUserIdFormRedis(); |
| | | if (uid == null) { |
| | | return ResultUtil.tokenErr(); |
| | | } |
| | | if (storeId == null || price == null || price < 0) { |
| | | return ResultUtil.error("门店和订单金额不能为空"); |
| | | } |
| | | return ResultUtil.success(userCouponService.queryStoreCouponList(uid, storeId, price, lon, lat)); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return ResultUtil.runErr(); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根据id修改门票使用状态 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @GetMapping("/userCoupon/changeTicketStatus/{id}/{storeId}/{siteId}") |
| | | public void changeTicketStatus(@PathVariable("id") String id,@PathVariable("storeId") Integer storeId,@PathVariable("siteId") Integer siteId){ |
| | | System.err.println("数据id"+id); |
| | | if (id.length()<=11){ |
| | | // 购买会员赠送的门票 |
| | | System.err.println("会员赠送门票"); |
| | | VipDetail vipDetail = vipDetailService.getById(Integer.valueOf(id)); |
| | | System.err.println("会员权益门票数据"+ vipDetail); |
| | | if (vipDetail!=null){ |
| | | System.err.println("修改使用状态"); |
| | | vipDetail.setStatus(2); |
| | | vipDetail.setUseStoreId(storeId); |
| | | vipDetail.setUseSiteId(siteId); |
| | | vipDetailService.updateById(vipDetail); |
| | | }else{ |
| | | System.err.println("未查询到会员权益门票数据"+ id); |
| | | } |
| | | }else{ |
| | | // 积分商城门票 |
| | | System.err.println("积分商城门票id"); |
| | | UserPointsMerchandise userPointsMerchandise = userPointsMerchandiseService.getById(id); |
| | | System.err.println("积分商城门票数据"+ userPointsMerchandise); |
| | | if (userPointsMerchandise!=null){ |
| | | PointsMerchandise pointsMerchandise = pointsMerchandiseService.getById(userPointsMerchandise.getPointsMerchandiseId()); |
| | | if (pointsMerchandise!=null){ |
| | | if (pointsMerchandise.getCardType()==1){ |
| | | System.err.println("日卡修改使用状态"); |
| | | userPointsMerchandise.setUserId(null); |
| | | userPointsMerchandise.setVerificationTime(new Date()); |
| | | userPointsMerchandise.setVerifiStoreId(storeId); |
| | | userPointsMerchandise.setStatus(2); |
| | | userPointsMerchandiseService.updateById(userPointsMerchandise); |
| | | } |
| | | } |
| | | |
| | | }else{ |
| | | System.err.println("未查询到积分商城门票数据"+ id); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/userCoupon/queryUserCouponById1") |
| | | public UserCoupon queryUserCouponById1(@RequestBody Long id) { |
| | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/userCoupon/updateUserCouponStatus/{id}/{storeId}/{siteId}") |
| | | public void updateUserCouponStatus(@PathVariable("id") Long id,@PathVariable("storeId") Integer storeId,@PathVariable("siteId") Integer siteId) { |
| | | |
| | | UserCoupon userCoupon = userCouponService.getOne(new LambdaQueryWrapper<UserCoupon>().eq(UserCoupon::getId, id)); |
| | | userCoupon.setUserId(null); |
| | | userCoupon.setStatus(2); |
| | | userCouponService.updateById(userCoupon); |
| | | if (userCoupon.getIsVipGrant()!=null && userCoupon.getIsVipGrant()==1){ |
| | | VipDetail vipDetailServiceById = vipDetailService.getById(userCoupon.getVipDetailId()); |
| | | vipDetailServiceById.setStatus(2); |
| | | List<Store> stores = storeClient.queryStoreByIds(Collections.singletonList(storeId)); |
| | | Store store = stores.get(0); |
| | | vipDetailServiceById.setUseSiteId(siteId); |
| | | vipDetailServiceById.setUseStoreId(storeId); |
| | | if (store.getOperatorId()==0){ |
| | | vipDetailServiceById.setOperatorId(0); |
| | | }else{ |
| | | vipDetailServiceById.setOperatorId(store.getOperatorId()); |
| | | } |
| | | vipDetailServiceById.setUseTime(new Date()); |
| | | vipDetailService.updateById(vipDetailServiceById); |
| | | } |
| | | } |
| | | |
| | |
| | | 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/updateUserCoupon") |
| | | public void updateUserCoupon(@RequestBody UserCoupon userCoupon) { |
| | | try { |
| | | |
| | | userCoupon.setUserId(null); |
| | | |
| | | userCouponService.updateById(userCoupon); |
| | | UserCoupon byId = userCouponService.getById(userCoupon.getId()); |
| | | if (byId.getIsVipGrant()!=null && byId.getIsVipGrant()==1){ |
| | | VipDetail vipDetailServiceById = vipDetailService.getById(byId.getVipDetailId()); |
| | | vipDetailServiceById.setStatus(2); |
| | | vipDetailServiceById.setUseSiteId(byId.getSiteId()); |
| | | List<Store> stores = storeClient.queryStoreByIds(Collections.singletonList(vipDetailServiceById.getUseStoreId())); |
| | | Store store = stores.get(0); |
| | | vipDetailServiceById.setUseStoreId(store.getId()); |
| | | vipDetailServiceById.setStatus(2); |
| | | vipDetailServiceById.setUseTime(new Date()); |
| | | if (store.getOperatorId()==null|| store.getOperatorId()==0){ |
| | | vipDetailServiceById.setOperatorId(0); |
| | | }else{ |
| | | vipDetailServiceById.setOperatorId(store.getOperatorId()); |
| | | } |
| | | vipDetailService.updateById(vipDetailServiceById); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | |
| | | @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))); |
| | | |
| | | |
| | | } |
| | | @GetMapping("/userCoupon/setStatusVipDetail/{id}") |
| | | void setStatusVipDetail(@PathVariable("id") Integer id){ |
| | | List<VipDetail> list = vipDetailService.lambdaQuery().eq(VipDetail::getVipPaymentId, id).list(); |
| | | for (VipDetail vipDetail : list) { |
| | | vipDetail.setStatus(3); |
| | | if (vipDetail.getType()==1){ |
| | | // 将优惠券修改为过期 |
| | | UserCoupon userCoupon = userCouponService.getById(vipDetail.getUserCouponId()); |
| | | userCoupon.setUserId(null); |
| | | userCoupon.setStatus(3); |
| | | userCouponService.updateById(userCoupon); |
| | | } |
| | | } |
| | | vipDetailService.updateBatchById(list); |
| | | } |
| | | // 开通会员后 赠送优惠券和门票 |
| | | @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); |
| | | userCoupon.setVipDetailId(vipDetail.getId()); |
| | | userCoupon.setUserId(null); |
| | | userCouponService.updateById(userCoupon); |
| | | } |
| | | } |
| | | } |
| | | 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.getVipId()); |
| | | vipDetail.setType(2); |
| | | vipDetail.setVipPaymentId(grantCoupon.getVipPaymentId()); |
| | | vipDetailService.save(vipDetail); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |