|
|
@@ -12,11 +12,13 @@ import com.kym.entity.admin.Station;
|
|
|
import com.kym.entity.admin.queryParams.ActivityQueryParam;
|
|
|
import com.kym.entity.admin.vo.ActivityVo;
|
|
|
import com.kym.entity.common.PageBean;
|
|
|
+import com.kym.entity.miniapp.UserRechargeRights;
|
|
|
import com.kym.mapper.admin.ActivityMapper;
|
|
|
import com.kym.service.admin.ActivityService;
|
|
|
import com.kym.service.admin.ActivityStationService;
|
|
|
import com.kym.service.admin.RechargeRightsService;
|
|
|
import com.kym.service.admin.StationService;
|
|
|
+import com.kym.service.miniapp.UserRechargeRightsService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -42,11 +44,13 @@ public class ActivityServiceImpl extends ServiceImpl<ActivityMapper, Activity> i
|
|
|
|
|
|
private final ActivityStationService activityStationService;
|
|
|
private final RechargeRightsService rechargeRightsService;
|
|
|
+ private final UserRechargeRightsService userRechargeRightsService;
|
|
|
private final StationService stationService;
|
|
|
|
|
|
- public ActivityServiceImpl(ActivityStationService activityStationService, RechargeRightsService rechargeRightsService, StationService stationService) {
|
|
|
+ public ActivityServiceImpl(ActivityStationService activityStationService, RechargeRightsService rechargeRightsService, UserRechargeRightsService userRechargeRightsService, StationService stationService) {
|
|
|
this.activityStationService = activityStationService;
|
|
|
this.rechargeRightsService = rechargeRightsService;
|
|
|
+ this.userRechargeRightsService = userRechargeRightsService;
|
|
|
this.stationService = stationService;
|
|
|
}
|
|
|
|
|
|
@@ -129,4 +133,45 @@ public class ActivityServiceImpl extends ServiceImpl<ActivityMapper, Activity> i
|
|
|
lambdaUpdate().set(Activity::getStatus, Activity.STATUS_已结束).eq(Activity::getId, activityId).update();
|
|
|
rechargeRightsService.lambdaUpdate().set(RechargeRights::getStatus, Activity.STATUS_已结束).eq(RechargeRights::getActivityId, activityId).update();
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 异步处理充值活动
|
|
|
+ *
|
|
|
+ * @param userId
|
|
|
+ * @param rechargeAmount
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void handleRechargeActivity(long userId, int rechargeAmount) {
|
|
|
+ new Thread(new RechargeActivityTask(userId, rechargeAmount)).start();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理充值活动
|
|
|
+ */
|
|
|
+ private class RechargeActivityTask implements Runnable {
|
|
|
+ private final long useId;
|
|
|
+ private final int rechargeAmount;
|
|
|
+
|
|
|
+ public RechargeActivityTask(long userId, int rechargeAmount) {
|
|
|
+ this.useId = userId;
|
|
|
+ this.rechargeAmount = rechargeAmount;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ // 进行中的充值权益活动
|
|
|
+ var activity = lambdaQuery().eq(Activity::getDiscountType, DISCOUNT_TYPE_服务费折扣权益).eq(Activity::getStatus, Activity.STATUS_进行中).one();
|
|
|
+ // 充值金额,匹配到到具体的充值权益,生成用户权益
|
|
|
+ if (activity != null) {
|
|
|
+ var rechargeRights = rechargeRightsService.lambdaQuery().eq(RechargeRights::getActivityId, activity.getId())
|
|
|
+ .ge(RechargeRights::getAmountMin, rechargeAmount)
|
|
|
+ .le(RechargeRights::getAmountMax, rechargeAmount) // 最后一档最大值设置成10000
|
|
|
+ .one();
|
|
|
+ var userRechargeRights = new UserRechargeRights().setUserId(this.useId).setRightsBalance(rechargeAmount);
|
|
|
+ BeanUtils.copyProperties(rechargeRights, userRechargeRights, "id");
|
|
|
+ userRechargeRightsService.save(userRechargeRights);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|