| | |
| | | import com.xiaopeng.account.model.vo.XpAppUserCouponVo; |
| | | import com.xiaopeng.account.service.IXpAppUserCouponService; |
| | | import com.xiaopeng.account.util.holiday.HolidayUtil; |
| | | import com.xiaopeng.api.dto.account.UserResourcesDto; |
| | | import com.xiaopeng.api.feignClient.account.UserResourcesClient; |
| | | import com.xiaopeng.api.feignClient.operation.XpCouponClient; |
| | | import com.xiaopeng.api.feignClient.operation.XpWhiteListClient; |
| | | import com.xiaopeng.api.model.account.XpAppUserCoupon; |
| | | import com.xiaopeng.api.model.operation.XpCoupon; |
| | | import com.xiaopeng.api.model.operation.XpWhitelist; |
| | | import com.xiaopeng.common.core.domain.R; |
| | | import com.xiaopeng.common.core.utils.DateUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.concurrent.CompletableFuture; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Autowired |
| | | private XpWhiteListClient xpWhiteListClient; |
| | | |
| | | @Autowired |
| | | private UserResourcesClient userResourcesClient; |
| | | |
| | | |
| | | /** |
| | | * 获取用户优惠券列表 |
| | | * @param query |
| | | * @param phone |
| | | * @param uid |
| | | * @return |
| | | */ |
| | | @Override |
| | | public XpAppUserCouponVo userCouponList(XpUserCouponListQuery query, String phone) { |
| | | public XpAppUserCouponVo userCouponList(XpUserCouponListQuery query, String uid) { |
| | | Page<XpAppUserCouponListVo> page = new Page<>(query.getPageNum(), query.getPageSize()); |
| | | Page<XpAppUserCouponListVo> list = baseMapper.userCouponList(page, query, phone); |
| | | Page<XpAppUserCouponListVo> list = baseMapper.userCouponList(page, query, uid); |
| | | XpAppUserCouponVo vo = new XpAppUserCouponVo(); |
| | | vo.setTotal((int) page.getTotal()); |
| | | vo.setList(list.getRecords()); |
| | |
| | | |
| | | /** |
| | | * 获取用户优惠券数量total |
| | | * @param phone |
| | | * @param uid |
| | | * @return |
| | | */ |
| | | @Override |
| | | public XpAppUserCouponTotalVo userCouponTotal(String phone) { |
| | | List<XpAppUserCoupon> couponList = baseMapper.selectList(new LambdaQueryWrapper<XpAppUserCoupon>().eq(XpAppUserCoupon::getPhone, phone)); |
| | | public XpAppUserCouponTotalVo userCouponTotal(String uid) { |
| | | List<XpAppUserCoupon> couponList = baseMapper.selectList(new LambdaQueryWrapper<XpAppUserCoupon>().eq(XpAppUserCoupon::getAppUserId, uid)); |
| | | XpAppUserCouponTotalVo vo = new XpAppUserCouponTotalVo(); |
| | | vo.setAvailableNum((int) couponList.stream().filter(e -> e.getStatus() == 1).count()); |
| | | vo.setUsedNum((int) couponList.stream().filter(e -> e.getStatus() == 2).count()); |
| | |
| | | @Override |
| | | public boolean receive(ReceiveCouponDto dto, String uid) { |
| | | XpAppUserCoupon coupon = baseMapper.selectById(dto.getCouponId()); |
| | | if(coupon.getAppUserId().toString().equals(uid)){ |
| | | if (coupon.getAppUserId().toString().equals(uid)) { |
| | | coupon.setStatus(1); |
| | | return updateById(coupon); |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public List<XpAppUserCoupon> timeRule(List<XpAppUserCoupon> couponList) { |
| | | List<XpAppUserCoupon> xpAppUserCoupons = new ArrayList<>(); |
| | | List<XpAppUserCoupon> xpAppUserCoupons = new ArrayList<>(); |
| | | |
| | | for (XpAppUserCoupon coupon : couponList) { |
| | | String timeJson = coupon.getTimeJson(); |
| | | Boolean inOperationTime = isInOperationTime(timeJson); |
| | | if(inOperationTime){ |
| | | if (inOperationTime) { |
| | | xpAppUserCoupons.add(coupon); |
| | | } |
| | | } |
| | |
| | | |
| | | /** |
| | | * 发送优惠券 |
| | | * |
| | | * @param dto |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Async("couponSendExecutor") |
| | | public R<String> send(SendCouponDto dto) { |
| | | |
| | | R<XpCoupon> coupon = xpCouponClient.getCouponById(dto.getCouponId()); |
| | | if(coupon!=null){ |
| | | if (coupon != null) { |
| | | XpCoupon xpCoupon = coupon.getData(); |
| | | if(dto.getPhone()==null){ |
| | | if (dto.getPhone() == null) { |
| | | // 全部发放 |
| | | R<List<String>> allWhiteList = xpWhiteListClient.getAllWhiteList(); |
| | | if(allWhiteList!=null){ |
| | | if (allWhiteList != null) { |
| | | List<String> phoneList = allWhiteList.getData(); |
| | | dto.setPhone(phoneList); |
| | | |
| | | } |
| | | } |
| | | for (String phone : dto.getPhone()) { |
| | | XpAppUserCoupon xpAppUserCoupon = new XpAppUserCoupon(); |
| | | xpAppUserCoupon.setFullMoney(xpCoupon.getConditionalAmount()); |
| | | xpAppUserCoupon.setMoney(xpCoupon.getAmount()); |
| | | xpAppUserCoupon.setCouponId(dto.getCouponId()); |
| | | UserResourcesDto userByMobile = userResourcesClient.getUserByMobile(phone); |
| | | if (userByMobile != null) { |
| | | Long uid = JSONObject.parseObject(userByMobile.getData().toString()).getLong("uid"); |
| | | XpAppUserCoupon xpAppUserCoupon = new XpAppUserCoupon(); |
| | | xpAppUserCoupon.setFullMoney(xpCoupon.getConditionalAmount()); |
| | | xpAppUserCoupon.setMoney(xpCoupon.getAmount()); |
| | | xpAppUserCoupon.setCouponId(dto.getCouponId()); |
| | | xpAppUserCoupon.setAppUserId(uid); |
| | | xpAppUserCoupon.setExpirationTime(LocalDateTime.now().plusDays(100)); |
| | | xpAppUserCoupon.setStatus(0); |
| | | xpAppUserCoupon.setCouponType(xpCoupon.getCouponType()); |
| | | xpAppUserCoupon.setPhone(phone); |
| | | |
| | | xpAppUserCoupon.setExpirationTime(LocalDateTime.now().plusDays(100)); |
| | | xpAppUserCoupon.setStatus(0); |
| | | xpAppUserCoupon.setCouponType(xpCoupon.getCouponType()); |
| | | xpAppUserCoupon.setPhone( phone); |
| | | xpAppUserCoupon.setCouponName(xpCoupon.getCouponName()); |
| | | xpAppUserCoupon.setOpenCityId("0"); |
| | | xpAppUserCoupon.setTimeJson("[{\"time\": [\"00:00-23:59\"], \"type\": 3, \"typeStr\": 0}]"); |
| | | baseMapper.insert(xpAppUserCoupon); |
| | | }else { |
| | | Long uid = 1l; |
| | | XpAppUserCoupon xpAppUserCoupon = new XpAppUserCoupon(); |
| | | xpAppUserCoupon.setFullMoney(xpCoupon.getConditionalAmount()); |
| | | xpAppUserCoupon.setMoney(xpCoupon.getAmount()); |
| | | xpAppUserCoupon.setCouponId(dto.getCouponId()); |
| | | xpAppUserCoupon.setAppUserId(uid); |
| | | xpAppUserCoupon.setExpirationTime(LocalDateTime.now().plusDays(100)); |
| | | xpAppUserCoupon.setStatus(0); |
| | | xpAppUserCoupon.setCouponType(xpCoupon.getCouponType()); |
| | | xpAppUserCoupon.setPhone(phone); |
| | | |
| | | xpAppUserCoupon.setCouponName(xpCoupon.getCouponName()); |
| | | xpAppUserCoupon.setOpenCityId("0"); |
| | | xpAppUserCoupon.setTimeJson("[{\"time\": [\"00:00-23:59\"], \"type\": 3, \"typeStr\": 0}]"); |
| | | baseMapper.insert(xpAppUserCoupon); |
| | | xpAppUserCoupon.setCouponName(xpCoupon.getCouponName()); |
| | | xpAppUserCoupon.setOpenCityId("0"); |
| | | xpAppUserCoupon.setTimeJson("[{\"time\": [\"00:00-23:59\"], \"type\": 3, \"typeStr\": 0}]"); |
| | | baseMapper.insert(xpAppUserCoupon); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | JSONArray jsonArray = JSONArray.parseArray(timeJson); |
| | | Integer holidayToday = holidayUtil.isHolidayToday(); |
| | | for (Object o : jsonArray) { |
| | | JSONObject jsonObject =JSONObject.parseObject(o.toString()); |
| | | JSONObject jsonObject = JSONObject.parseObject(o.toString()); |
| | | String type = jsonObject.getString("type"); |
| | | if(type.equals(holidayToday.toString())){ |
| | | if (type.equals(holidayToday.toString())) { |
| | | JSONArray time = jsonObject.getJSONArray("time"); |
| | | // 判断当前时间 是否在time时间段中 |
| | | for (Object object : time) { |
| | |
| | | String startTime = timeArray[0]; |
| | | String endTime = timeArray[1]; |
| | | boolean currentTimeInRange = DateUtils.isCurrentTimeInRange(startTime, endTime); |
| | | if(currentTimeInRange){ |
| | | if (currentTimeInRange) { |
| | | return true; |
| | | } |
| | | } |
| | | }else if(type.equals("3")){ |
| | | } else if (type.equals("3")) { |
| | | // 判断是什么类型 0每天 1-7 想起 |
| | | String typeStr = jsonObject.getString("typeStr"); |
| | | // 查看今天周几 |
| | | Integer week = DateUtils.getWeek(); |
| | | // 包含每天 或者 包含当天 |
| | | if(typeStr.contains("0") || typeStr.contains(week.toString())){ |
| | | if (typeStr.contains("0") || typeStr.contains(week.toString())) { |
| | | JSONArray time = jsonObject.getJSONArray("time"); |
| | | // 判断当前时间 是否在time时间段中 |
| | | for (Object object : time) { |
| | |
| | | String startTime = timeArray[0]; |
| | | String endTime = timeArray[1]; |
| | | boolean currentTimeInRange = DateUtils.isCurrentTimeInRange(startTime, endTime); |
| | | if(currentTimeInRange){ |
| | | if (currentTimeInRange) { |
| | | return true; |
| | | } |
| | | } |