|
@@ -104,6 +104,7 @@ import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
import javax.annotation.PreDestroy;
|
|
import javax.annotation.PreDestroy;
|
|
|
|
|
|
|
|
import static com.fs.store.constants.StoreConstants.DELIVERY;
|
|
import static com.fs.store.constants.StoreConstants.DELIVERY;
|
|
|
|
|
+import static com.fs.store.enums.BillDetailEnum.CATEGORY_3;
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -179,6 +180,9 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private IFsUserService userService;
|
|
private IFsUserService userService;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IFsUserBillService billService;
|
|
|
|
|
+
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private FsWxExpressTaskMapper fsWxExpressTaskMapper;
|
|
private FsWxExpressTaskMapper fsWxExpressTaskMapper;
|
|
|
|
|
|
|
@@ -3268,7 +3272,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
LiveUserFirstEntry liveUserFirstEntry = liveUserFirstEntryService.selectEntityByLiveIdUserId(liveOrder.getLiveId(), Long.parseLong(liveOrder.getUserId()));
|
|
LiveUserFirstEntry liveUserFirstEntry = liveUserFirstEntryService.selectEntityByLiveIdUserId(liveOrder.getLiveId(), Long.parseLong(liveOrder.getUserId()));
|
|
|
Long companyId = liveUserFirstEntry.getCompanyId();
|
|
Long companyId = liveUserFirstEntry.getCompanyId();
|
|
|
Long companyUserId = liveUserFirstEntry.getCompanyUserId();
|
|
Long companyUserId = liveUserFirstEntry.getCompanyUserId();
|
|
|
- if (companyId != null && companyId == -1L && companyUserId != null && companyUserId == -1L) {
|
|
|
|
|
|
|
+ if ((companyId != null && companyId == -1L && companyUserId != null && companyUserId == -1L) || (companyId != null && companyId == -2L && companyUserId != null && companyUserId == Long.valueOf(liveOrder.getUserId()))) {
|
|
|
StoreConfig storeConfig = loadStoreConfig();
|
|
StoreConfig storeConfig = loadStoreConfig();
|
|
|
companyId = storeConfig.getDefaultLiveCompanyId() != null ? storeConfig.getDefaultLiveCompanyId() : 309L;
|
|
companyId = storeConfig.getDefaultLiveCompanyId() != null ? storeConfig.getDefaultLiveCompanyId() : 309L;
|
|
|
companyUserId = storeConfig.getDefaultLiveCompanyUserId() != null ? storeConfig.getDefaultLiveCompanyUserId() : 8647L;
|
|
companyUserId = storeConfig.getDefaultLiveCompanyUserId() != null ? storeConfig.getDefaultLiveCompanyUserId() : 8647L;
|
|
@@ -3618,4 +3622,126 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
}
|
|
}
|
|
|
return JSONUtil.toBean(configJson, StoreConfig.class);
|
|
return JSONUtil.toBean(configJson, StoreConfig.class);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public R batchManualTuiMoneyByOrderIds(List<Long> orderIds) {
|
|
|
|
|
+ if (orderIds == null || orderIds.isEmpty()) {
|
|
|
|
|
+ return R.error("订单ID列表不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ List<Map<String, Object>> details = new ArrayList<>();
|
|
|
|
|
+ int successCount = 0;
|
|
|
|
|
+ int skipCount = 0;
|
|
|
|
|
+ int failCount = 0;
|
|
|
|
|
+ for (Long orderId : orderIds) {
|
|
|
|
|
+ Map<String, Object> detail = new LinkedHashMap<>();
|
|
|
|
|
+ detail.put("orderId", orderId);
|
|
|
|
|
+ try {
|
|
|
|
|
+ List<String> messages = manualProcessLiveOrderTuiMoney(orderId);
|
|
|
|
|
+ detail.put("messages", messages);
|
|
|
|
|
+ boolean hasFail = messages.stream().anyMatch(msg -> msg.startsWith("失败"));
|
|
|
|
|
+ boolean hasSuccess = messages.stream().anyMatch(msg -> msg.contains("已补录") || msg.contains("已扣佣"));
|
|
|
|
|
+ if (hasFail) {
|
|
|
|
|
+ detail.put("status", "fail");
|
|
|
|
|
+ failCount++;
|
|
|
|
|
+ } else if (hasSuccess) {
|
|
|
|
|
+ detail.put("status", "success");
|
|
|
|
|
+ successCount++;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ detail.put("status", "skip");
|
|
|
|
|
+ skipCount++;
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("批量手动直播订单佣金处理失败, orderId={}", orderId, e);
|
|
|
|
|
+ detail.put("status", "fail");
|
|
|
|
|
+ detail.put("messages", Collections.singletonList("失败:" + e.getMessage()));
|
|
|
|
|
+ failCount++;
|
|
|
|
|
+ }
|
|
|
|
|
+ details.add(detail);
|
|
|
|
|
+ }
|
|
|
|
|
+ return R.ok()
|
|
|
|
|
+ .put("total", orderIds.size())
|
|
|
|
|
+ .put("success", successCount)
|
|
|
|
|
+ .put("skip", skipCount)
|
|
|
|
|
+ .put("fail", failCount)
|
|
|
|
|
+ .put("details", details);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 单笔订单手动分佣/扣佣:按支付成功、确认收货时的原有逻辑补录或回滚。
|
|
|
|
|
+ */
|
|
|
|
|
+ private List<String> manualProcessLiveOrderTuiMoney(Long orderId) {
|
|
|
|
|
+ List<String> messages = new ArrayList<>();
|
|
|
|
|
+ LiveOrder order = liveOrderMapper.selectLiveOrderByOrderId(String.valueOf(orderId));
|
|
|
|
|
+ if (order == null) {
|
|
|
|
|
+ messages.add("失败:订单不存在");
|
|
|
|
|
+ return messages;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!"1".equals(order.getIsPay()) && (order.getStatus() == null || order.getStatus() < 2)) {
|
|
|
|
|
+ messages.add("失败:订单未支付");
|
|
|
|
|
+ return messages;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ boolean hasUserTuiBill = hasLiveOrderUserTuiBill(orderId);
|
|
|
|
|
+ if (!hasUserTuiBill) {
|
|
|
|
|
+ messages.addAll(addLiveOrderSpreadTuiMoney(order));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ messages.add("跳过:推广分佣记录已存在");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (order.getCompanyId() != null && order.getCompanyId() > 0
|
|
|
|
|
+ && order.getPayDelivery() != null
|
|
|
|
|
+ && order.getPayDelivery().compareTo(BigDecimal.ZERO) == 0) {
|
|
|
|
|
+ if (order.getTuiMoneyStatus() == null || order.getTuiMoneyStatus() != 1) {
|
|
|
|
|
+ if (order.getStatus() != null && order.getStatus() >= OrderInfoEnum.STATUS_3.getValue()) {
|
|
|
|
|
+ companyService.addCompanyMoney(order);
|
|
|
|
|
+ messages.add("公司佣金入账-已补录");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ messages.add("跳过:订单未完成,暂不补录公司佣金入账");
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ messages.add("跳过:公司佣金已入账");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return messages;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<String> addLiveOrderSpreadTuiMoney(LiveOrder order) {
|
|
|
|
|
+ List<String> messages = new ArrayList<>();
|
|
|
|
|
+ if (order.getCompanyUserId() != null && order.getCompanyUserId() == -1L) {
|
|
|
|
|
+ companyService.addCompanyTuiLiveMoney(order);
|
|
|
|
|
+ messages.add("推广分佣(公司)-已补录");
|
|
|
|
|
+ return messages;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (order.getCompanyUserId() != null && order.getCompanyUserId() > 0) {
|
|
|
|
|
+ if (StringUtils.isEmpty(order.getItemJson())) {
|
|
|
|
|
+ messages.add("失败:订单商品信息缺失");
|
|
|
|
|
+ return messages;
|
|
|
|
|
+ }
|
|
|
|
|
+ FsStoreProduct product = JSONUtil.toBean(order.getItemJson(), FsStoreProduct.class);
|
|
|
|
|
+ if (product == null || product.getProductId() == null) {
|
|
|
|
|
+ messages.add("失败:订单商品信息无效");
|
|
|
|
|
+ return messages;
|
|
|
|
|
+ }
|
|
|
|
|
+ List<FsStoreProductAttrValue> productAttrValues =
|
|
|
|
|
+ fsStoreProductAttrValueMapper.selectFsStoreProductAttrValueByProductId(product.getProductId());
|
|
|
|
|
+ if (productAttrValues == null || productAttrValues.isEmpty()) {
|
|
|
|
|
+ messages.add("失败:商品规格不存在");
|
|
|
|
|
+ return messages;
|
|
|
|
|
+ }
|
|
|
|
|
+ userService.addTuiLiveMoney(order, productAttrValues);
|
|
|
|
|
+ messages.add("推广分佣(用户)-已补录");
|
|
|
|
|
+ return messages;
|
|
|
|
|
+ }
|
|
|
|
|
+ messages.add("跳过:无推广员信息");
|
|
|
|
|
+ return messages;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean hasLiveOrderUserTuiBill(Long orderId) {
|
|
|
|
|
+ FsUserBill query = new FsUserBill();
|
|
|
|
|
+ query.setCategory(CATEGORY_3.getValue());
|
|
|
|
|
+ query.setBusinessId(String.valueOf(orderId));
|
|
|
|
|
+ query.setBillType(1);
|
|
|
|
|
+ List<FsUserBill> bills = billService.selectFsUserBillList(query);
|
|
|
|
|
+ return bills != null && !bills.isEmpty();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|