...
|
...
|
@@ -1063,32 +1063,104 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
if (result == 0) {
|
|
|
logger.info("saveOrUpdateOrder enter,update nothing,req is {}",bo);
|
|
|
//没有更新到数据,应该有并发更新事件,查询新的再试一下
|
|
|
UnionShareOrders unionShareOrdersNew = unionShareOrdersMapper.selectByCode(bo.getOrderCode());
|
|
|
if (unionShareOrdersNew == null) {
|
|
|
unionShareOrders = unionShareOrdersMapper.selectByCode(bo.getOrderCode());
|
|
|
if (unionShareOrders == null) {
|
|
|
logger.info("saveOrUpdateOrder end,can not find the orderCode,req is {}",bo);
|
|
|
//查不到数据,不该出现的情况,目前没有硬删数据的途径
|
|
|
return;
|
|
|
}
|
|
|
if (!checkOrderStatusChangePass(unionShareOrdersNew.getStatus(), bo.getStatus())) {
|
|
|
if (!checkOrderStatusChangePass(unionShareOrders.getStatus(), bo.getStatus())) {
|
|
|
//订单状态不可变更
|
|
|
logger.info("saveOrUpdateOrder end,Second try,status can not be change,oldStatus is {} ,req is {}",unionShareOrdersNew.getStatus(),bo);
|
|
|
logger.info("saveOrUpdateOrder end,Second try,status can not be change,oldStatus is {} ,req is {}",unionShareOrders.getStatus(),bo);
|
|
|
return;
|
|
|
}
|
|
|
unionShareOrdersMapper.updateStatusById(unionShareOrdersNew.getId(), unionShareOrdersNew.getStatus(), bo.getStatus(), DateUtil.getCurrentTimeSecond());
|
|
|
result=unionShareOrdersMapper.updateStatusById(unionShareOrders.getId(), unionShareOrders.getStatus(), bo.getStatus(), DateUtil.getCurrentTimeSecond());
|
|
|
}
|
|
|
if (result > 0 &&ShareOrdersStatusEnum.isFailOrder(unionShareOrders.getStatus())) {
|
|
|
//要作废活动参与记录
|
|
|
UnionShareOrdersActivityLogs updateLogs = new UnionShareOrdersActivityLogs();
|
|
|
updateLogs.setOrderId(unionShareOrders.getId());
|
|
|
updateLogs.setUpdateTime(DateUtil.getCurrentTimeSecond());
|
|
|
updateLogs.setStatus(0);//类型:1-有效,0-作废
|
|
|
unionShareOrdersActivityLogsMapper.updateStatusByOrderId(updateLogs);
|
|
|
//查询是否参与满单返
|
|
|
List<UnionShareOrdersActivityLogs> activityLogs=unionShareOrdersActivityLogsMapper.selectByOrderCode(unionShareOrders.getOrderCode());
|
|
|
if (CollectionUtils.isNotEmpty(activityLogs)) {
|
|
|
//todo 判断满返是否作废
|
|
|
}
|
|
|
}
|
|
|
//清缓存
|
|
|
clearShareOrderRedis(bo.getPromoteUid());
|
|
|
}
|
|
|
|
|
|
|
|
|
//todo 查询进行中的活动
|
|
|
private void queryActivity() {
|
|
|
private List<UnionShareOrdersActivity> queryActivity() {
|
|
|
List<UnionShareOrdersActivity> activities=unionShareOrdersActivityMapper.selectByDate(DateUtil.getCurrentTimeSecond());
|
|
|
return activities;
|
|
|
}
|
|
|
//todo 查询已参加的活动
|
|
|
private void queryUidActivity() {
|
|
|
List<UnionShareOrdersActivity> activities=unionShareOrdersActivityMapper.selectByDate(DateUtil.getCurrentTimeSecond());
|
|
|
//todo 查询分享人已参加的活动
|
|
|
private void queryUidActivity(int uid) {
|
|
|
// List<UnionShareOrdersActivity> activities=unionShareOrdersActivityLogsMapper.selectByOrderIds()
|
|
|
}
|
|
|
|
|
|
//参加活动
|
|
|
private boolean participateActivity(UnionShareOrders order,UnionShareOrdersActivity activity) {
|
|
|
//1、判断是否符合活动条件
|
|
|
//1.1 活动类型:1-订单返利比例升级,2-订单返利翻x倍,3-额外返
|
|
|
if (activity.getType() == 3) {
|
|
|
//额外返在活动结束后走定时任务
|
|
|
return false;
|
|
|
}
|
|
|
//1.2 是否新人专享 1-是
|
|
|
if (activity.getIsNew().intValue() == 1 && !activity.getIsNew().equals(order.getIsNew())) {
|
|
|
//活动为新人专享,但是订单不是首单
|
|
|
return false;
|
|
|
}
|
|
|
//2、参加活动
|
|
|
//2.1 返利金额计算
|
|
|
BigDecimal extraAmount = activity.getAmount();
|
|
|
/* if (activity.getType() == 1) {
|
|
|
//活动类型:1-订单返利比例升级
|
|
|
extraAmount = order.getLastOrderAmount().multiply(new BigDecimal(activity.getPercent()).divide(new BigDecimal(10000))).setScale(2,BigDecimal.ROUND_DOWN);
|
|
|
}else */
|
|
|
if (activity.getType() == 2) {
|
|
|
//活动类型:2-订单返利翻x倍
|
|
|
extraAmount = order.getAmount().multiply(new BigDecimal(activity.getPercent()));
|
|
|
}
|
|
|
if (activity.getAmount().intValue()>0&&extraAmount.compareTo(activity.getAmount())>1) {
|
|
|
//订单返利金额高于封顶金额
|
|
|
extraAmount = activity.getAmount();
|
|
|
}
|
|
|
order.setExtraAmount(extraAmount);
|
|
|
order.setAmount(order.getAmount().add(extraAmount));
|
|
|
|
|
|
//2.2 保存活动日志
|
|
|
UnionShareOrdersActivityLogs log = new UnionShareOrdersActivityLogs();
|
|
|
BeanUtils.copyProperties(order, log);
|
|
|
log.setActivityId(activity.getId());
|
|
|
log.setActivityName(activity.getActivityName());
|
|
|
log.setCreateTime(DateUtil.getCurrentTimeSecond());
|
|
|
log.setUpdateTime(log.getCreateTime());
|
|
|
log.setOrderId(order.getId());
|
|
|
log.setStatus(1);
|
|
|
log.setOrders(order.getOrderCode());
|
|
|
log.setId(null);
|
|
|
unionShareOrdersActivityLogsMapper.insertSelective(log);
|
|
|
|
|
|
//3 更新订单返利金额
|
|
|
UnionShareOrders updateOrder = new UnionShareOrders();
|
|
|
updateOrder.setId(order.getId());
|
|
|
updateOrder.setAmount(order.getAmount());
|
|
|
updateOrder.setExtraAmount(order.getExtraAmount());
|
|
|
updateOrder.setActivityId(activity.getId());
|
|
|
updateOrder.setActivityType(activity.getType());
|
|
|
unionShareOrdersMapper.updateByPrimaryKeySelective(updateOrder);
|
|
|
|
|
|
//4、返回
|
|
|
logger.info("participateActivity success,order is {},activity is {}",order,activity);
|
|
|
return true;
|
|
|
}
|
|
|
//todo 查询可参加的活动
|
|
|
private void getActivity() {
|
|
|
|
...
|
...
|
@@ -1135,9 +1207,22 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
}
|
|
|
//返利金额计算小数位两位后舍弃
|
|
|
insertReq.setAmount((bo.getLastOrderAmount().multiply(new BigDecimal(rebatesRatio).divide(new BigDecimal(100)))).setScale(2,BigDecimal.ROUND_DOWN));
|
|
|
insertReq.setOrderAmount(insertReq.getAmount());
|
|
|
logger.info("insertOrder,orderCode is {},orderAmount is {},rebatesRatio is {},rebates is {}",bo.getOrderCode(),bo.getLastOrderAmount(),rebatesRatio,insertReq.getAmount());
|
|
|
|
|
|
bo.setAmount(insertReq.getAmount());
|
|
|
unionShareOrdersMapper.insertSelective(insertReq);
|
|
|
//活动返利
|
|
|
try {
|
|
|
List<UnionShareOrdersActivity> activityList = queryActivity();
|
|
|
for (UnionShareOrdersActivity a :activityList ) {
|
|
|
if(participateActivity(insertReq,a)) {
|
|
|
//参加了活动
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
logger.warn("insertOrder warn,fail to handle some activities.bo is {}",bo);
|
|
|
}
|
|
|
//新增订单商品信息
|
|
|
bo.getProductList().forEach(p->{
|
|
|
try {
|
...
|
...
|
@@ -1347,23 +1432,27 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
settlementLog.warn("relateSettlementAndOrder end,uid is {},settlementCode is {},totalAmount is {},insert nothing.",uid,settlementCode,totalAmount);
|
|
|
}
|
|
|
|
|
|
Set<String> orderCodes = new HashSet<>();
|
|
|
// Set<String> orderCodes = new HashSet<>();
|
|
|
List<UnionShareOrdersBo> orderList = new ArrayList<>();//该提现对应的订单
|
|
|
int size = 1000;
|
|
|
int page = count % size > 0 ? (count / size) + 1 : count / size;
|
|
|
for (int i = 0; i < page; i++) {
|
|
|
int offset = i * size ;
|
|
|
List<String> periodOrders = unionShareOrdersMapper.selectOrderCodesByCondition(settlementCode, offset, size);
|
|
|
List<UnionShareOrders> periodOrders = unionShareOrdersMapper.selectOrderByCondition(settlementCode, offset, size);
|
|
|
if (CollectionUtils.isEmpty(periodOrders) || periodOrders.get(0) == null) {
|
|
|
break;
|
|
|
}
|
|
|
orderCodes.addAll(periodOrders);
|
|
|
// orderCodes.addAll(periodOrders);
|
|
|
periodOrders.forEach(o->{
|
|
|
UnionShareOrdersBo b = new UnionShareOrdersBo();
|
|
|
BeanUtils.copyProperties(o,b);
|
|
|
orderList.add(b);
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
//查询活动额外返的返利单
|
|
|
List<Integer> ids = unionShareOrdersMapper.selectIdForActivity(settlementCode);
|
|
|
if (CollectionUtils.isEmpty(orderCodes)&&CollectionUtils.isEmpty(ids)) {
|
|
|
//不该查不到订单
|
|
|
settlementLog.warn("relateSettlementAndOrder end,uid is {},settlementCode is {},totalAmount is {},can not find orders and activity.",uid,settlementCode,totalAmount);
|
|
|
throw new ServiceException(ServiceError.UNION_SETTLEMENT_CANNOT_FIND_ORDER_ERROR);
|
|
|
}
|
|
|
List<UnionShareOrdersActivityBo> activityBos = new ArrayList<>();
|
|
|
if(CollectionUtils.isNotEmpty(ids)){
|
|
|
List<UnionShareOrdersActivityLogs> activities = unionShareOrdersActivityLogsMapper.selectByOrderIds(ids);
|
...
|
...
|
@@ -1374,15 +1463,21 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
activityBos.add(bo);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
if (CollectionUtils.isEmpty(orderList)&&CollectionUtils.isEmpty(activityBos)) {
|
|
|
//不该查不到订单
|
|
|
settlementLog.warn("relateSettlementAndOrder end,uid is {},settlementCode is {},totalAmount is {},can not find orders and activity.",uid,settlementCode,totalAmount);
|
|
|
throw new ServiceException(ServiceError.UNION_SETTLEMENT_CANNOT_FIND_ORDER_ERROR);
|
|
|
}
|
|
|
//清缓存
|
|
|
clearShareOrderRedis(uid);
|
|
|
|
|
|
// 发送取现mq给erp SETTLEMENT_TOPIC
|
|
|
ShareSettlementBo bo = new ShareSettlementBo();
|
|
|
BeanUtils.copyProperties(insertReq,bo);
|
|
|
bo.setOrderCodes(orderCodes);
|
|
|
// bo.setOrderCodes(orderCodes);
|
|
|
bo.setOrderList(orderList);
|
|
|
bo.setActivities(activityBos);
|
|
|
System.out.println(JsonUtil.objectToJSON(bo));
|
|
|
mqLog.info("relateSettlementAndOrder,send mq {} to erp,uid is {},settlementCode is {},bo is {}", SETTLEMENT_TOPIC, uid, settlementCode, bo);
|
|
|
yhProducer.send(SETTLEMENT_TOPIC, bo);
|
|
|
settlementLog.info("relateSettlementAndOrder,send mq {} to erp success,uid is {},settlementCode is {},bo is {}", SETTLEMENT_TOPIC, uid, settlementCode, bo);
|
...
|
...
|
|