| | |
| | | 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.CouponCity; |
| | | 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.model.AppUser; |
| | | import com.dsh.activity.feignclient.course.CoursePackageClient; |
| | | import com.dsh.activity.feignclient.course.model.CoursePackage; |
| | | import com.dsh.activity.feignclient.other.SiteClient; |
| | | import com.dsh.activity.feignclient.other.StoreClient; |
| | | import com.dsh.activity.feignclient.other.model.Site; |
| | | import com.dsh.activity.feignclient.other.model.StoreDetailOfCourse; |
| | | import com.dsh.activity.mapper.CouponCityMapper; |
| | | import com.dsh.activity.mapper.CouponMapper; |
| | | import com.dsh.activity.mapper.CouponStoreMapper; |
| | | import com.dsh.activity.mapper.UserCouponMapper; |
| | |
| | | @Autowired |
| | | private GDMapGeocodingUtil gdMapGeocodingUtil; |
| | | |
| | | @Autowired |
| | | @Resource |
| | | private AppUserClient appClient; |
| | | |
| | | @Autowired |
| | | @Resource |
| | | private StudentClient studentClient; |
| | | |
| | | @Autowired |
| | | @Resource |
| | | private CouponMapper couponMapper; |
| | | |
| | | @Autowired |
| | | @Resource |
| | | private CouponCityMapper couponCityMapper; |
| | | |
| | | @Resource |
| | | private StoreClient storeClient; |
| | | |
| | | @Autowired |
| | | @Resource |
| | | private CouponStoreMapper csMapper; |
| | | |
| | | @Resource |
| | | private SiteClient siteClient; |
| | | |
| | | |
| | | /** |
| | | * 获取购买课程可用优惠券列表 |
| | | * |
| | | * @param uid |
| | | * @param coursePackageId |
| | | * @return |
| | |
| | | String content = userCoupon.get("content").toString(); |
| | | if (type == 1) {//满减{"num1":1,"num2":1} |
| | | JSONObject jsonObject = JSON.parseObject(content); |
| | | Double num1 = jsonObject.getDouble("num1"); |
| | | if(price.compareTo(num1) <= 0){ |
| | | Double num1 = jsonObject.getDouble("conditionalAmount"); |
| | | if (price.compareTo(num1) < 0) { |
| | | continue; |
| | | } |
| | | couponListVo.setUseCondition("满" + num1 + "元可用"); |
| | | couponListVo.setFavorable(jsonObject.getDouble("num2") + "元"); |
| | | couponListVo.setUseCondition("满¥" + num1 + "元可用"); |
| | | couponListVo.setFavorable(jsonObject.getString("deductionAmount")); |
| | | } |
| | | if (type == 2) {//代金券{"num1":1} |
| | | JSONObject jsonObject = JSON.parseObject(content); |
| | | Double num1 = jsonObject.getDouble("num1"); |
| | | if(price.compareTo(num1) <= 0){ |
| | | Double num1 = jsonObject.getDouble("conditionalAmount"); |
| | | if (num1 == null) { |
| | | num1 = 0d; |
| | | } |
| | | if (price.compareTo(num1) < 0) { |
| | | continue; |
| | | } |
| | | couponListVo.setUseCondition(""); |
| | | couponListVo.setFavorable(num1 + "元"); |
| | | couponListVo.setFavorable(num1 + ""); |
| | | } |
| | | if (type == 3) {//体验券{"num1":1} |
| | | JSONObject jsonObject = JSON.parseObject(content); |
| | | couponListVo.setUseCondition(""); |
| | | couponListVo.setFavorable(jsonObject.getString("num1")); |
| | | couponListVo.setFavorable(jsonObject.getString("experienceName")); |
| | | } |
| | | listVos.add(couponListVo); |
| | | } |
| | | return listVos; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取预约场地可用优惠券列表 |
| | | * |
| | | * @param siteId |
| | | * @param price |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public List<CouponListVo> querySiteCouponList(Integer uid, Integer siteId, Double price, String lon, String lat) throws Exception { |
| | | Site site = siteClient.querySiteById(siteId); |
| | | Integer storeId = site.getStoreId(); |
| | | Map<String, String> geocode = gdMapGeocodingUtil.geocode(lon, lat); |
| | | String provinceCode = geocode.get("provinceCode"); |
| | | String cityCode = geocode.get("cityCode"); |
| | | List<Map<String, Object>> userCoupons = this.baseMapper.queryAvailableCouponList(uid, storeId, provinceCode, cityCode); |
| | | List<CouponListVo> listVos = new ArrayList<>(); |
| | | for (Map<String, Object> userCoupon : userCoupons) { |
| | | Integer type = Integer.valueOf(userCoupon.get("type").toString()); |
| | | CouponListVo couponListVo = new CouponListVo(); |
| | | couponListVo.setId(Long.valueOf(userCoupon.get("id").toString())); |
| | | couponListVo.setName(userCoupon.get("name").toString()); |
| | | couponListVo.setType(type); |
| | | couponListVo.setEffectiveTime(userCoupon.get("endTime").toString()); |
| | | String content = userCoupon.get("content").toString(); |
| | | if (type == 1) {//满减{"num1":1,"num2":1} |
| | | JSONObject jsonObject = JSON.parseObject(content); |
| | | Double num1 = jsonObject.getDouble("conditionalAmount"); |
| | | if (price.compareTo(num1) < 0) { |
| | | continue; |
| | | } |
| | | couponListVo.setUseCondition("满" + num1 + "元可用"); |
| | | couponListVo.setFavorable(jsonObject.getString("deductionAmount")); |
| | | } |
| | | if (type == 2) {//代金券{"num1":1} |
| | | JSONObject jsonObject = JSON.parseObject(content); |
| | | Double num1 = jsonObject.getDouble("conditionalAmount"); |
| | | if (num1 == null) { |
| | | num1 = 0d; |
| | | } |
| | | if (price.compareTo(num1) < 0) { |
| | | continue; |
| | | } |
| | | couponListVo.setUseCondition(""); |
| | | couponListVo.setFavorable(num1 + ""); |
| | | } |
| | | if (type == 3) {//体验券{"num1":1} |
| | | JSONObject jsonObject = JSON.parseObject(content); |
| | | couponListVo.setUseCondition(""); |
| | | couponListVo.setFavorable(jsonObject.getString("experienceName")); |
| | | } |
| | | listVos.add(couponListVo); |
| | | } |
| | |
| | | AppUser appUser = appClient.queryAppUser(uid); |
| | | if (null != appUser) { |
| | | List<UserCoupon> userCoupons = this.baseMapper.selectList(new QueryWrapper<UserCoupon>() |
| | | .eq("userId",appUser.getId() ) |
| | | .eq("userId", appUser.getId()) |
| | | .orderByDesc("insertTime")); |
| | | if (userCoupons.size() > 0){ |
| | | if (userCoupons.size() > 0) { |
| | | for (UserCoupon userCoupon : userCoupons) { |
| | | Coupon coupon = couponMapper.selectById(userCoupon.getCouponId()); |
| | | CouponPackageResp packageResp = new CouponPackageResp(); |
| | |
| | | packageResp.setName(coupon.getName()); |
| | | packageResp.setType(coupon.getType()); |
| | | packageResp.setUseCondition(coupon.getUseScope()); |
| | | switch (coupon.getUseScope()){ |
| | | switch (coupon.getUseScope()) { |
| | | case 1: |
| | | packageResp.setAvailable("全国通用"); |
| | | break; |
| | | case 2: |
| | | packageResp.setAvailable("指定城市可用"); |
| | | packageResp.setCityOrStore(""); |
| | | List<CouponCity> couponId = couponCityMapper.selectList(new QueryWrapper<CouponCity>().eq("couponId", coupon.getId())); |
| | | StringBuilder stringBuilder = new StringBuilder(); |
| | | for (CouponCity couponCity : couponId) { |
| | | stringBuilder.append(couponCity.getCity()); |
| | | } |
| | | packageResp.setCityOrStore(String.valueOf(stringBuilder)); |
| | | break; |
| | | case 3: |
| | | packageResp.setAvailable("指定门店可用"); |
| | | CouponStore couponStore = csMapper.selectOne(new QueryWrapper<CouponStore>() |
| | | .eq("couponId",coupon.getId())); |
| | | .eq("couponId", coupon.getId()).last("limit 1")); |
| | | StoreDetailOfCourse courseOfStore = storeClient.getCourseOfStore(couponStore.getStoreId()); |
| | | packageResp.setCityOrStore(courseOfStore.getStoreName()+","+courseOfStore.getStoreAddr()); |
| | | // packageResp.setCityOrStore(courseOfStore.getStoreName()+","+courseOfStore.getStoreAddr()); |
| | | packageResp.setCityOrStore(courseOfStore.getStoreName()); |
| | | break; |
| | | default: |
| | | break; |
| | |
| | | JSONObject jsonObject = JSON.parseObject(coupon.getContent()); |
| | | switch (coupon.getType()) { |
| | | case 1: |
| | | // {"conditionalAmount":50,"deductionAmount":10,"experienceName":""} |
| | | // 满减券 |
| | | Double num1 = jsonObject.getDouble("num1"); |
| | | Double num2 = jsonObject.getDouble("num2"); |
| | | ruleModel.setConditionalAmount("满"+num1+"可用"); |
| | | ruleModel.setDeductionAmount("¥ "+num2); |
| | | Double num1 = jsonObject.getDouble("conditionalAmount"); |
| | | Double num2 = jsonObject.getDouble("deductionAmount"); |
| | | ruleModel.setConditionalAmount("满" + num1 + "可用"); |
| | | ruleModel.setDeductionAmount("¥ " + num2); |
| | | ruleModel.setExperienceName(""); |
| | | break; |
| | | case 2: |
| | | // 代金券 |
| | | Double jsonObjectDouble = jsonObject.getDouble("num1"); |
| | | Double jsonObjectDouble = jsonObject.getDouble("conditionalAmount"); |
| | | ruleModel.setConditionalAmount(""); |
| | | ruleModel.setDeductionAmount("¥ "+jsonObjectDouble); |
| | | ruleModel.setDeductionAmount("¥ " + jsonObjectDouble); |
| | | ruleModel.setExperienceName(""); |
| | | break; |
| | | case 3: |
| | | // 体验券 |
| | | ruleModel.setConditionalAmount(""); |
| | | ruleModel.setDeductionAmount(""); |
| | | ruleModel.setExperienceName(jsonObject.getString("num1")); |
| | | ruleModel.setExperienceName(jsonObject.getString("experienceName")); |
| | | break; |
| | | default: |
| | | break; |
| | |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); |
| | | packageResp.setEffectiveTime(simpleDateFormat.format(coupon.getEndTime())); |
| | | |
| | | if (userCoupon.getStatus() == 1){ |
| | | if (DateUtil.getDate().before(coupon.getEndTime())){ |
| | | if (userCoupon.getStatus() == 1) { |
| | | if (DateUtil.getDate().before(coupon.getEndTime())) { |
| | | packageResp.setUseStatus(1); |
| | | }else { |
| | | } else { |
| | | packageResp.setUseStatus(3); |
| | | } |
| | | } |
| | | if (userCoupon.getStatus() == 2){ |
| | | if (userCoupon.getStatus() == 2) { |
| | | packageResp.setUseStatus(2); |
| | | } |
| | | respList.add(packageResp); |
| | | } |
| | | if (null != req.getCouponType()){ |
| | | if (null != req.getCouponType()) { |
| | | respList = respList.stream() |
| | | .filter(couponPackageResp -> couponPackageResp.getType().equals(req.getCouponType())) |
| | | .collect(Collectors.toList()); |
| | | } |
| | | if (null != req.getUseStatus()){ |
| | | if (null != req.getUseStatus()) { |
| | | respList = respList.stream() |
| | | .filter(couponPackageResp -> couponPackageResp.getUseStatus().equals(req.getUseStatus())) |
| | | .collect(Collectors.toList()); |