| | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.dsh.activity.entity.Coupon; |
| | | import com.dsh.activity.entity.CouponStore; |
| | | 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.course.CoursePackageClient; |
| | | import com.dsh.activity.feignclient.course.model.CoursePackage; |
| | | import com.dsh.activity.feignclient.other.StoreClient; |
| | | import com.dsh.activity.feignclient.other.model.StoreDetailOfCourse; |
| | | import com.dsh.activity.mapper.CouponMapper; |
| | | import com.dsh.activity.mapper.CouponStoreMapper; |
| | | import com.dsh.activity.mapper.UserCouponMapper; |
| | | import com.dsh.activity.model.ConponJsonRuleModel; |
| | | import com.dsh.activity.model.CouponListVo; |
| | | import com.dsh.activity.model.request.CouponPackageReq; |
| | | import com.dsh.activity.model.response.CouponPackageResp; |
| | | import com.dsh.activity.service.UserCouponService; |
| | | import com.dsh.activity.util.DateUtil; |
| | | import com.dsh.activity.util.GDMapGeocodingUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Autowired |
| | | private GDMapGeocodingUtil gdMapGeocodingUtil; |
| | | |
| | | @Autowired |
| | | private AppUserClient appClient; |
| | | |
| | | @Autowired |
| | | private StudentClient studentClient; |
| | | |
| | | @Autowired |
| | | private CouponMapper couponMapper; |
| | | |
| | | @Autowired |
| | | private StoreClient storeClient; |
| | | |
| | | @Autowired |
| | | private CouponStoreMapper csMapper; |
| | | |
| | | /** |
| | | * 获取购买课程可用优惠券列表 |
| | |
| | | } |
| | | return listVos; |
| | | } |
| | | |
| | | @Override |
| | | public List<CouponPackageResp> queryCouponPackagesList(Integer uid, CouponPackageReq req) { |
| | | List<CouponPackageResp> respList = new ArrayList<>(); |
| | | AppUser appUser = appClient.queryAppUser(uid); |
| | | if (null != appUser) { |
| | | List<UserCoupon> userCoupons = this.baseMapper.selectList(new QueryWrapper<UserCoupon>() |
| | | .eq("userId",appUser.getId() ) |
| | | .orderByDesc("insertTime")); |
| | | if (userCoupons.size() > 0){ |
| | | for (UserCoupon userCoupon : userCoupons) { |
| | | Coupon coupon = couponMapper.selectById(userCoupon.getCouponId()); |
| | | CouponPackageResp packageResp = new CouponPackageResp(); |
| | | packageResp.setId(coupon.getId()); |
| | | packageResp.setName(coupon.getName()); |
| | | packageResp.setType(coupon.getType()); |
| | | packageResp.setUseCondition(coupon.getUseScope()); |
| | | switch (coupon.getUseScope()){ |
| | | case 1: |
| | | packageResp.setAvailable("全国通用"); |
| | | break; |
| | | case 2: |
| | | packageResp.setAvailable("指定城市可用"); |
| | | packageResp.setCityOrStore(""); |
| | | break; |
| | | case 3: |
| | | packageResp.setAvailable("指定门店可用"); |
| | | CouponStore couponStore = csMapper.selectOne(new QueryWrapper<CouponStore>() |
| | | .eq("couponId",coupon.getId())); |
| | | StoreDetailOfCourse courseOfStore = storeClient.getCourseOfStore(couponStore.getStoreId()); |
| | | packageResp.setCityOrStore(courseOfStore.getStoreName()+","+courseOfStore.getStoreAddr()); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | packageResp.setInstructionsForUse(coupon.getIllustrate()); |
| | | ConponJsonRuleModel ruleModel = new ConponJsonRuleModel(); |
| | | JSONObject jsonObject = JSON.parseObject(coupon.getContent()); |
| | | switch (coupon.getType()) { |
| | | case 1: |
| | | // 满减券 |
| | | Double num1 = jsonObject.getDouble("num1"); |
| | | Double num2 = jsonObject.getDouble("num2"); |
| | | ruleModel.setConditionalAmount("满"+num1+"可用"); |
| | | ruleModel.setDeductionAmount("¥ "+num2); |
| | | ruleModel.setExperienceName(""); |
| | | break; |
| | | case 2: |
| | | // 代金券 |
| | | Double jsonObjectDouble = jsonObject.getDouble("num1"); |
| | | ruleModel.setConditionalAmount(""); |
| | | ruleModel.setDeductionAmount("¥ "+jsonObjectDouble); |
| | | ruleModel.setExperienceName(""); |
| | | break; |
| | | case 3: |
| | | // 体验券 |
| | | ruleModel.setConditionalAmount(""); |
| | | ruleModel.setDeductionAmount(""); |
| | | ruleModel.setExperienceName(jsonObject.getString("num1")); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | packageResp.setRuleModel(ruleModel); |
| | | |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); |
| | | packageResp.setEffectiveTime(simpleDateFormat.format(coupon.getEndTime())); |
| | | |
| | | if (userCoupon.getStatus() == 1){ |
| | | if (DateUtil.getDate().before(coupon.getEndTime())){ |
| | | packageResp.setUseStatus(1); |
| | | }else { |
| | | packageResp.setUseStatus(3); |
| | | } |
| | | } |
| | | if (userCoupon.getStatus() == 2){ |
| | | packageResp.setUseStatus(2); |
| | | } |
| | | respList.add(packageResp); |
| | | } |
| | | if (null != req.getCouponType()){ |
| | | respList = respList.stream() |
| | | .filter(couponPackageResp -> couponPackageResp.getType().equals(req.getCouponType())) |
| | | .collect(Collectors.toList()); |
| | | } |
| | | if (null != req.getUseStatus()){ |
| | | respList = respList.stream() |
| | | .filter(couponPackageResp -> couponPackageResp.getUseStatus().equals(req.getUseStatus())) |
| | | .collect(Collectors.toList()); |
| | | } |
| | | } |
| | | |
| | | } |
| | | return respList; |
| | | } |
| | | |
| | | } |