|
|
@@ -28,10 +28,13 @@ import com.fs.his.utils.ConfigUtil;
|
|
|
import com.fs.hisStore.domain.*;
|
|
|
import com.fs.hisStore.dto.DateComparisonConfigDTO;
|
|
|
import com.fs.hisStore.enums.ShipperCodeEnum;
|
|
|
+import com.fs.his.enums.FsUserIntegralLogTypeEnum;
|
|
|
import com.fs.hisStore.mapper.FsStoreOrderItemScrmMapper;
|
|
|
import com.fs.hisStore.mapper.FsStoreOrderScrmMapper;
|
|
|
import com.fs.hisStore.mapper.FsStorePaymentScrmMapper;
|
|
|
import com.fs.hisStore.mapper.FsStoreProductAttrValueScrmMapper;
|
|
|
+import com.fs.hisStore.mapper.FsUserScrmMapper;
|
|
|
+import com.fs.hisStore.mapper.FsUserIntegralLogsScrmMapper;
|
|
|
import com.fs.hisStore.param.*;
|
|
|
import com.fs.hisStore.service.*;
|
|
|
import com.fs.huifuPay.domain.HuiFuQueryOrderResult;
|
|
|
@@ -43,6 +46,7 @@ import com.fs.pay.pay.dto.OrderQueryDTO;
|
|
|
import com.fs.pay.service.IPayService;
|
|
|
import com.fs.store.config.StoreConfig;
|
|
|
import com.fs.system.service.ISysConfigService;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.fs.ybPay.domain.OrderResult;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
@@ -154,6 +158,12 @@ public class MallStoreTask
|
|
|
@Autowired
|
|
|
private ConfigUtil configUtil;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private FsUserScrmMapper fsUserScrmMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsUserIntegralLogsScrmMapper fsUserIntegralLogsScrmMapper;
|
|
|
+
|
|
|
@Autowired
|
|
|
private FsCourseRedPacketLogMapper fsCourseRedPacketLogMapper;
|
|
|
|
|
|
@@ -748,4 +758,66 @@ public class MallStoreTask
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 购物积分发放定时任务
|
|
|
+ * 查询条件:订单状态为已收货(2)或交易完成(3),超过7天,创建时间在2026-05-1以后,
|
|
|
+ * 是否领取购物积分=0,已支付,商城订单(order_type=1)
|
|
|
+ * 积分规则:用户实际支付金额(pay_money) 1:1 向下取整折算积分(eg: 19.9元=19积分)
|
|
|
+ */
|
|
|
+ public void grantShoppingPoints() {
|
|
|
+ // 检查配置开关
|
|
|
+ String storeConfigJson = configService.selectConfigByKey("his.store");
|
|
|
+ if (StringUtils.isBlank(storeConfigJson)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ com.fs.hisStore.config.StoreConfig storeConfig = JSONUtil.toBean(storeConfigJson, com.fs.hisStore.config.StoreConfig.class);
|
|
|
+ if (storeConfig == null || !Boolean.TRUE.equals(storeConfig.getEnableShoppingPoints())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询符合条件的订单(SQL直接过滤)
|
|
|
+ String cutoffDate = "2026-05-01 00:00:00";
|
|
|
+ String sevenDaysAgo = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(DateUtils.addDays(new Date(), -7));
|
|
|
+ List<FsStoreOrderScrm> orders = fsStoreOrderMapper.selectShoppingPointsPendingOrders(cutoffDate, sevenDaysAgo);
|
|
|
+
|
|
|
+ int count = 0;
|
|
|
+ for (FsStoreOrderScrm order : orders) {
|
|
|
+ // 用户ID为空跳过
|
|
|
+ if (order.getUserId() == null) continue;
|
|
|
+
|
|
|
+ // 计算积分:pay_money 向下取整
|
|
|
+ long points = order.getPayMoney().setScale(0, BigDecimal.ROUND_DOWN).longValue();
|
|
|
+ if (points <= 0) continue;
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 发放积分
|
|
|
+ fsUserScrmMapper.incrIntegral(order.getUserId(), BigDecimal.valueOf(points));
|
|
|
+
|
|
|
+ // 记录积分日志 logType=5 购物积分
|
|
|
+ FsUserIntegralLogsScrm logs = new FsUserIntegralLogsScrm();
|
|
|
+ logs.setUserId(order.getUserId());
|
|
|
+ logs.setIntegral(BigDecimal.valueOf(points));
|
|
|
+ logs.setLogType(FsUserIntegralLogTypeEnum.TYPE_30.getValue()); // 购物积分发放
|
|
|
+ logs.setStatus(1);
|
|
|
+ logs.setBusinessId(String.valueOf(order.getId()));
|
|
|
+ logs.setBusinessType(1); // 商城订单
|
|
|
+ logs.setCreateTime(new Date());
|
|
|
+ FsUserScrm user = fsUserScrmMapper.selectFsUserByUserId(order.getUserId());
|
|
|
+ logs.setBalance(user != null && user.getIntegral() != null ? BigDecimal.valueOf(user.getIntegral()) : BigDecimal.valueOf(points));
|
|
|
+ fsUserIntegralLogsScrmMapper.insertFsUserIntegralLogs(logs);
|
|
|
+
|
|
|
+ // 更新订单为已领取
|
|
|
+ FsStoreOrderScrm updateOrder = new FsStoreOrderScrm();
|
|
|
+ updateOrder.setId(order.getId());
|
|
|
+ updateOrder.setShoppingPointsClaimed(1);
|
|
|
+ fsStoreOrderMapper.updateFsStoreOrder(updateOrder);
|
|
|
+
|
|
|
+ count++;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("购物积分发放异常,订单ID={}", order.getId(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("购物积分发放完成,本次发放{}笔订单", count);
|
|
|
+ }
|
|
|
+
|
|
|
}
|