| | |
| | | package com.dsh.activity.service.impl; |
| | | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.dsh.activity.entity.Coupon; |
| | | 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.account.model.Student; |
| | | import com.dsh.activity.feignclient.model.CouponExamineListSearch; |
| | | import com.dsh.activity.feignclient.model.CouponListOfSearch; |
| | | import com.dsh.activity.mapper.CouponMapper; |
| | | import com.dsh.activity.service.CouponService; |
| | | import com.dsh.activity.model.CouponListVo; |
| | | import com.dsh.activity.model.request.IntegralGoodsOfSearch; |
| | | import com.dsh.activity.service.ICouponService; |
| | | import com.dsh.activity.service.UserCouponService; |
| | | import com.dsh.activity.util.RedisUtil; |
| | | import com.dsh.activity.util.ToolUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | | * 优惠券 服务实现类 |
| | | * </p> |
| | | * |
| | | * @author jqs |
| | | * @since 2023-06-29 |
| | | * @author zhibing.pu |
| | | * @date 2023/6/24 11:26 |
| | | */ |
| | | @Service |
| | | public class CouponServiceImpl extends ServiceImpl<CouponMapper, Coupon> implements CouponService { |
| | | public class CouponServiceImpl extends ServiceImpl<CouponMapper, Coupon> implements ICouponService { |
| | | |
| | | @Resource |
| | | private AppUserClient appUserClient; |
| | | |
| | | @Resource |
| | | private StudentClient studentClient; |
| | | |
| | | @Autowired |
| | | private UserCouponService userCouponService; |
| | | |
| | | @Autowired |
| | | private ICouponService couponService; |
| | | |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | |
| | | |
| | | /** |
| | | * 获取购买会员支付成功页面的优惠券 |
| | | * |
| | | * @param uid |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public List<CouponListVo> queryCouponList(Integer uid, Integer distributionMethod) throws Exception { |
| | | String value = redisUtil.getValue("VIP_P_" + uid); |
| | | if (ToolUtil.isEmpty(value)) { |
| | | Thread.sleep(3000); |
| | | value = redisUtil.getValue("VIP_P_" + uid); |
| | | } |
| | | List<CouponListVo> listVos = new ArrayList<>(); |
| | | if (ToolUtil.isNotEmpty(value)) { |
| | | List<Long> longs = JSON.parseArray(value, Long.class); |
| | | List<UserCoupon> list = userCouponService.getBaseMapper().selectBatchIds(longs); |
| | | List<Integer> collect = list.stream().map(UserCoupon::getCouponId).collect(Collectors.toList()); |
| | | List<Coupon> coupons = couponService.getBaseMapper().selectBatchIds(collect); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | for (Coupon coupon : coupons) { |
| | | if (coupon.getDistributionMethod() != 2) { |
| | | continue; |
| | | } |
| | | CouponListVo couponListVo = new CouponListVo(); |
| | | couponListVo.setId(coupon.getId().longValue()); |
| | | couponListVo.setName(coupon.getName()); |
| | | couponListVo.setType(coupon.getType()); |
| | | couponListVo.setEffectiveTime(sdf.format(coupon.getStartTime()) + "-" + sdf.format(coupon.getEndTime())); |
| | | String content = coupon.getContent(); |
| | | if (coupon.getType() == 1) {//满减 |
| | | // {"conditionalAmount":50,"deductionAmount":10,"experienceName":""} |
| | | JSONObject jsonObject = JSON.parseObject(content); |
| | | couponListVo.setUseCondition("满" + jsonObject.getDouble("conditionalAmount") + "元可用"); |
| | | couponListVo.setFavorable(jsonObject.getString("deductionAmount")); |
| | | } |
| | | if (coupon.getType() == 2) {//代金券{"num1":1} |
| | | JSONObject jsonObject = JSON.parseObject(content); |
| | | couponListVo.setUseCondition(""); |
| | | couponListVo.setFavorable(jsonObject.getString("conditionalAmount")); |
| | | } |
| | | if (coupon.getType() == 3) {//体验券{"num1":1} |
| | | JSONObject jsonObject = JSON.parseObject(content); |
| | | couponListVo.setUseCondition(""); |
| | | couponListVo.setFavorable(jsonObject.getString("experienceName")); |
| | | } |
| | | listVos.add(couponListVo); |
| | | } |
| | | } |
| | | return listVos; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public Map<String, Object> queryConponRuleOfJson(Integer id) { |
| | | return this.baseMapper.queryConponRuleOfJson(id); |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> queryCouponListOfSearch(CouponListOfSearch ofSearch) { |
| | | return this.baseMapper.queryCouponListOfSearch(ofSearch.getName(), |
| | | ofSearch.getType(), |
| | | ofSearch.getDistributionMethod(), |
| | | ofSearch.getUserPopulation(), |
| | | ofSearch.getStatus(), |
| | | ofSearch.getState(), |
| | | ofSearch.getCityCode(), |
| | | ofSearch.getStoreId(), |
| | | ofSearch.getOperatorId(), |
| | | ofSearch.getObjType()); |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> queryCouponListOfSearch1(CouponListOfSearch ofSearch) { |
| | | return this.baseMapper.queryCouponListOfSearch1(ofSearch.getName(), ofSearch.getType(), ofSearch.getDistributionMethod(), ofSearch.getUserPopulation(), ofSearch.getStatus(), ofSearch.getState(), ofSearch.getPage(), ofSearch.getCityCode(), ofSearch.getStoreId()); |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> queryCouponExamineList(CouponExamineListSearch ofSearch) { |
| | | return this.baseMapper.queryCouponExamineList(ofSearch.getName(), ofSearch.getType(), ofSearch.getUserPopulation(), ofSearch.getDistributionMethod(), ofSearch.getAuditStatus(), ofSearch.getPage()); |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> listRecord(Integer id, List<Integer> ids, Integer type) { |
| | | return this.baseMapper.listRecord(id, ids, type); |
| | | } |
| | | |
| | | @Override |
| | | public void updateType(Long id) { |
| | | this.baseMapper.updateType(id); |
| | | } |
| | | |
| | | } |