...
|
...
|
@@ -1365,15 +1365,25 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
result=unionShareOrdersMapper.updateStatusById(unionShareOrders.getId(), unionShareOrders.getStatus(), bo.getStatus(), DateUtil.getCurrentTimeSecond());
|
|
|
}
|
|
|
logger.info("saveOrUpdateOrder ,req is {},unionShareOrders is {},update result is {}.",bo,unionShareOrders,result);
|
|
|
if (result > 0 && unionShareOrders.getExtraActivityId() != null) {
|
|
|
if (result > 0 && (unionShareOrders.getExtraActivityId() != null||unionShareOrders.getExtraActivityId() != null)) {
|
|
|
if (ShareOrdersStatusEnum.isFailOrder(bo.getStatus())) {
|
|
|
//订单不可参与活动,重新处理该单参与的满单返
|
|
|
rehandExtraActivity(unionShareOrders);
|
|
|
if (unionShareOrders.getExtraActivityId() != null) {
|
|
|
rehandSomeExtraActivity(unionShareOrders.getOrderUid(),unionShareOrders.getPromoteUid(),unionShareOrders.getExtraActivityId());
|
|
|
}
|
|
|
if (unionShareOrders.getCpsExtraActivityId() != null) {
|
|
|
rehandSomeExtraActivity(null,unionShareOrders.getPromoteUid(),unionShareOrders.getCpsExtraActivityId());
|
|
|
}
|
|
|
}
|
|
|
if (ShareOrdersStatusEnum.CAN_SETTLE.getCode().equals(bo.getStatus())
|
|
|
|| ShareOrdersStatusEnum.getLevelByCode(bo.getStatus()) > ShareOrdersStatusEnum.CAN_SETTLE.getLevel()) {
|
|
|
//有效订单已完结,判断是否需要把该单的满返活动状态改成可结算
|
|
|
changeExtraActivityStatus(unionShareOrders);
|
|
|
if (unionShareOrders.getExtraActivityId() != null) {
|
|
|
changeSomeExtraActivityStatus(unionShareOrders.getOrderUid(),unionShareOrders.getPromoteUid(),unionShareOrders.getExtraActivityId());
|
|
|
}
|
|
|
if (unionShareOrders.getCpsExtraActivityId() != null) {
|
|
|
changeSomeExtraActivityStatus(null,unionShareOrders.getPromoteUid(),unionShareOrders.getCpsExtraActivityId());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
...
|
...
|
@@ -1391,14 +1401,14 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
/**
|
|
|
* 获取订单参与的满单返活动返利单
|
|
|
* */
|
|
|
private UnionShareOrders getRelatedActivityOrder(UnionShareOrders unionShareOrders) {
|
|
|
logger.info("getRelatedActivityOrder,unionShareOrders is {}.",unionShareOrders);
|
|
|
UnionShareOrdersActivity activity = queryActivity(unionShareOrders.getExtraActivityId());
|
|
|
private UnionShareOrders getRelatedActivityOrder(Integer orderUid,int promoteUid,int activityId) {
|
|
|
logger.info("getRelatedActivityOrder,orderUid is {},,promoteUid is {},activityId is {}.",orderUid,promoteUid,activityId);
|
|
|
UnionShareOrdersActivity activity = queryActivity(activityId);
|
|
|
if (null == activity || activity.getType() != 3) {
|
|
|
return null;
|
|
|
}
|
|
|
//
|
|
|
UnionShareOrders activityOrder = queryOrderActivity(unionShareOrders.getOrderUid(), unionShareOrders.getPromoteUid(), unionShareOrders.getExtraActivityId());
|
|
|
UnionShareOrders activityOrder = queryOrderActivity(orderUid, promoteUid, activityId);
|
|
|
if (null == activityOrder) {
|
|
|
return null;
|
|
|
}
|
...
|
...
|
@@ -1408,9 +1418,9 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
/**
|
|
|
* 获取订单参与的满单返活动日志
|
|
|
* */
|
|
|
private UnionShareOrdersActivityLogs getRelatedActivityLogs(UnionShareOrders unionShareOrders) {
|
|
|
logger.info("getRelatedActivityLogs,unionShareOrders is {}.",unionShareOrders);
|
|
|
UnionShareOrders activityOrder = getRelatedActivityOrder(unionShareOrders);
|
|
|
private UnionShareOrdersActivityLogs getRelatedActivityLogs(Integer orderUid,int promoteUid,int activityId) {
|
|
|
logger.info("getRelatedActivityLogs,orderUid is {},promoteUid is {},activityId is {}.",orderUid,promoteUid,activityId);
|
|
|
UnionShareOrders activityOrder = getRelatedActivityOrder(orderUid,promoteUid,activityId);
|
|
|
if (null == activityOrder) {
|
|
|
return null;
|
|
|
}
|
...
|
...
|
@@ -1429,20 +1439,20 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
/**
|
|
|
* 判断是否需要重新处理订单相关的满单返活动
|
|
|
* */
|
|
|
private void rehandExtraActivity(UnionShareOrders unionShareOrders) {
|
|
|
logger.info("rehandExtraActivity,unionShareOrders is {}.",unionShareOrders);
|
|
|
private void rehandSomeExtraActivity(Integer orderUid, int promoteUid, int activityId) {
|
|
|
logger.info("rehandSomeExtraActivity,orderUid is {},promoteUid is {},activityId is {}.",orderUid,promoteUid,activityId);
|
|
|
//判断满返是否作废,若作废,查询是否满足该活动其他门槛条件
|
|
|
UnionShareOrdersActivityLogs activityLog = getRelatedActivityLogs(unionShareOrders);
|
|
|
UnionShareOrdersActivityLogs activityLog = getRelatedActivityLogs(orderUid,promoteUid,activityId);
|
|
|
if (null == activityLog) {
|
|
|
return;
|
|
|
}
|
|
|
List<String> orderCodeList = Arrays.stream(activityLog.getOrders().split(",")).collect(Collectors.toList());
|
|
|
// 获取参与此活动的有效订单
|
|
|
logger.info("rehandExtraActivity,unionShareOrders is {},selectListByOrderCodesForActivity,orderCodeList is {}.",unionShareOrders,orderCodeList);
|
|
|
logger.info("rehandSomeExtraActivity,orderUid is {},promoteUid is {},activityId is {},selectListByOrderCodesForActivity,orderCodeList is {}.",orderUid,promoteUid,activityId,orderCodeList);
|
|
|
List<UnionShareOrders> orderList = unionShareOrdersMapper.selectListByOrderCodesForActivity(orderCodeList);
|
|
|
UnionShareOrdersActivityItem item = queryActivityItem(activityLog.getActivityId(),activityLog.getActivityItemId());
|
|
|
if (orderList.size() <item.getOrderMinNum()) {
|
|
|
reJoinExtraActivity(activityLog);
|
|
|
reJoinSomeExtraActivity(activityLog);
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -1456,15 +1466,23 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
unionShareOrdersActivityLogsMapper.updateByPrimaryKeySelective(updatelogs);
|
|
|
}
|
|
|
|
|
|
private boolean reJoinExtraActivity(UnionShareOrdersActivityLogs activityLog){
|
|
|
logger.info("reJoinExtraActivity,activityLog is {}",activityLog);
|
|
|
private boolean reJoinSomeExtraActivity(UnionShareOrdersActivityLogs activityLog){
|
|
|
logger.info("reJoinSomeExtraActivity,activityLog is {}",activityLog);
|
|
|
int now = DateUtil.getCurrentTimeSecond();
|
|
|
//作废已参加的满单活动
|
|
|
invalidActivityLog(activityLog.getId(), now);
|
|
|
unionShareOrdersMapper.updateStatusById(activityLog.getOrderId(), ShareOrdersStatusEnum.PAY.getCode(), ShareOrdersStatusEnum.ACTIVITY_DISCARD.getCode(), now);
|
|
|
|
|
|
//尝试重新参加活动
|
|
|
boolean joinResult = joinExtraActivity(activityLog.getOrderUid(), activityLog.getPromoteUid(), activityLog.getActivityId());
|
|
|
boolean joinResult = false;
|
|
|
if (activityLog.getActivityType() == 3) {
|
|
|
joinResult = joinExtraActivity(activityLog.getOrderUid(), activityLog.getPromoteUid(), activityLog.getActivityId());
|
|
|
} else if (activityLog.getActivityType() == 4) {
|
|
|
int endTime = DateUtil.getLastDayInt(activityLog.getCreateTime(),1);
|
|
|
List<UnionShareOrders> orders=unionShareOrdersMapper.selectNewPromoteUidOrder(activityLog.getPromoteUid(), endTime);
|
|
|
joinResult = joinNewCpsActivity(activityLog.getPromoteUid(), orders, activityLog.getActivityId());
|
|
|
}
|
|
|
|
|
|
if (!joinResult) {
|
|
|
//已不满足此活动条件
|
|
|
// clearOrderRelated(orderCodeList);
|
...
|
...
|
@@ -1476,16 +1494,16 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
/**
|
|
|
* 尝试更新订单参与的,满返活动单的状态
|
|
|
* */
|
|
|
private boolean changeExtraActivityStatus(UnionShareOrders unionShareOrders) {
|
|
|
logger.info("changeExtraActivityStatus,unionShareOrders is {}.",unionShareOrders);
|
|
|
UnionShareOrdersActivityLogs activityLog = getRelatedActivityLogs(unionShareOrders);
|
|
|
private boolean changeSomeExtraActivityStatus(Integer orderUid, int promoteUid, int activityId) {
|
|
|
logger.info("changeSomeExtraActivityStatus,orderUid is {},promoteUid is {},activityId is {}.",orderUid,promoteUid,activityId);
|
|
|
UnionShareOrdersActivityLogs activityLog = getRelatedActivityLogs(orderUid,promoteUid,activityId);
|
|
|
if (null == activityLog) {
|
|
|
return false;
|
|
|
}
|
|
|
int now = DateUtil.getCurrentTimeSecond();
|
|
|
List<String> orderCodeList = Arrays.stream(activityLog.getOrders().split(",")).collect(Collectors.toList());
|
|
|
// 获取参与此活动的有效订单
|
|
|
logger.info("changeExtraActivityStatus,unionShareOrders is {},selectListByOrderCodesForActivity orderCodeList is {}.",unionShareOrders,orderCodeList);
|
|
|
logger.info("changeSomeExtraActivityStatus,orderUid is {},promoteUid is {},activityId is {},selectListByOrderCodesForActivity orderCodeList is {}.",orderUid,promoteUid,activityId,orderCodeList);
|
|
|
List<UnionShareOrders> orderList = unionShareOrdersMapper.selectListByOrderCodesForActivity(orderCodeList);
|
|
|
for(UnionShareOrders order :orderList ) {
|
|
|
if (order.getStatus().equals(ShareOrdersStatusEnum.PAY.getCode())) {
|
...
|
...
|
@@ -1496,10 +1514,10 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
UnionShareOrdersActivityItem item = queryActivityItem(activityLog.getActivityId(),activityLog.getActivityItemId());
|
|
|
if (orderList.size() < item.getOrderMinNum()) {
|
|
|
//订单有效数不符合参加的满单活动,warn
|
|
|
return reJoinExtraActivity(activityLog);
|
|
|
return reJoinSomeExtraActivity(activityLog);
|
|
|
}
|
|
|
//更新满返单状态为可结算
|
|
|
logger.info("changeExtraActivityStatus,try to change status,unionShareOrders is {}.",unionShareOrders);
|
|
|
logger.info("changeSomeExtraActivityStatus,try to change status,orderUid is {},promoteUid is {},activityId is {}.",orderUid,promoteUid,activityId);
|
|
|
unionShareOrdersMapper.updateStatusById(activityLog.getOrderId(), ShareOrdersStatusEnum.PAY.getCode(), ShareOrdersStatusEnum.CAN_SETTLE.getCode(), now);
|
|
|
//清缓存
|
|
|
return true;
|
...
|
...
|
@@ -1523,8 +1541,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
});
|
|
|
|
|
|
//发放完成
|
|
|
logger.info("dealWithCpsNewUserActivity over,activity is {},begin to change status to 2.",activity);
|
|
|
unionShareOrdersActivityMapper.updateStatusById(activity.getId(), 1, 2, DateUtil.getCurrentTimeSecond());
|
|
|
logger.info("dealWithCpsNewUserActivity over,activity is {}.",activity);
|
|
|
return ;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -1723,14 +1740,15 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
for (UnionShareOrdersActivityItem item : items) {
|
|
|
if (orders.size() >= item.getOrderMinNum() && orders.size() <= item.getOrderMaxNum()) {
|
|
|
//满足此项标准
|
|
|
insertJoinDataForActivity(orders, orderUid, promoteUid, activity, item);
|
|
|
return true;
|
|
|
return insertJoinDataForActivity(orders, orderUid, promoteUid, activity, item);
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
//参加新cps用户分享满单额外返活动
|
|
|
/**
|
|
|
* 参加新cps用户分享满单额外返活动
|
|
|
* */
|
|
|
boolean joinNewCpsActivity(int promoteUid ,List<UnionShareOrders> orders,int activityId){
|
|
|
if (CollectionUtils.isEmpty(orders)) {
|
|
|
return false;
|
...
|
...
|
@@ -1753,8 +1771,8 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
for (UnionShareOrdersActivityItem item : items) {
|
|
|
if (orders.size() >= item.getOrderMinNum() && orders.size() <= item.getOrderMaxNum()) {
|
|
|
//满足此项标准
|
|
|
insertJoinDataForActivity(orders, null, promoteUid, activity, item);
|
|
|
return true;
|
|
|
boolean result = insertJoinDataForActivity(orders, null, promoteUid, activity, item);
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
return false;
|
...
|
...
|
@@ -1780,20 +1798,33 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
}
|
|
|
//更新订单额外返数据
|
|
|
int now = DateUtil.getCurrentTimeSecond();
|
|
|
UnionShareOrders insertExtraOrder = new UnionShareOrders();
|
|
|
UnionShareOrdersActivityLogs logs = new UnionShareOrdersActivityLogs();
|
|
|
if (orderUid != null) {
|
|
|
//3-额外返
|
|
|
logger.info("insertJoinDataForActivity,orderUid is {},promoteUid is {},activityId is {},updateByIdsForExtraActivity,orderIds is {} .",orderUid,promoteUid,activity.getId(),orderIds);
|
|
|
unionShareOrdersMapper.updateByIdsForExtraActivity(orderIds, activity.getId(),now);
|
|
|
insertExtraOrder.setOrderUid(orderUid);
|
|
|
logs.setOrderUid(orderUid);
|
|
|
insertExtraOrder.setExtraActivityId(activity.getId());
|
|
|
}else {
|
|
|
//4-cps新人n天额外返
|
|
|
int updateNum = unionShareUserMapper.updateCpsActByUid(promoteUid, activity.getId(), now);
|
|
|
if (updateNum < 1) {
|
|
|
//没有更新成功,说明已参与过新人n天返活动
|
|
|
return false;
|
|
|
}
|
|
|
//更新关联订单
|
|
|
unionShareOrdersMapper.updateByIdsForCpsUserActivity(orderIds, activity.getId(),now);
|
|
|
insertExtraOrder.setCpsExtraActivityId(activity.getId());
|
|
|
}
|
|
|
|
|
|
//插入额外返利单
|
|
|
UnionShareOrders insertExtraOrder = new UnionShareOrders();
|
|
|
insertExtraOrder.setExtraAmount(item.getAmount());
|
|
|
insertExtraOrder.setAmount(item.getAmount());
|
|
|
insertExtraOrder.setExtraActivityId(activity.getId());
|
|
|
insertExtraOrder.setActivityId(activity.getId());
|
|
|
insertExtraOrder.setActivityName(activity.getActivityName());
|
|
|
insertExtraOrder.setPromoteUid(promoteUid);
|
|
|
insertExtraOrder.setOrderUid(orderUid);
|
|
|
insertExtraOrder.setStatus(status);
|
|
|
insertExtraOrder.setOrderTime(now);
|
|
|
insertExtraOrder.setCreateTime(now);
|
...
|
...
|
@@ -1802,7 +1833,6 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
unionShareOrdersMapper.insertSelective(insertExtraOrder);
|
|
|
|
|
|
//记录满单返活动参与日志
|
|
|
UnionShareOrdersActivityLogs logs = new UnionShareOrdersActivityLogs();
|
|
|
logs.setOrders(ordersStr.substring(0,ordersStr.length()-1));
|
|
|
logs.setOrderId(insertExtraOrder.getId());
|
|
|
logs.setActivityId(activity.getId());
|
...
|
...
|
@@ -1813,7 +1843,6 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
logs.setCreateTime(now);
|
|
|
logs.setUpdateTime(now);
|
|
|
logs.setPromoteUid(promoteUid);
|
|
|
logs.setOrderUid(orderUid);
|
|
|
logger.info("insertJoinDataForActivity,orderUid is {},promoteUid is {},activityId is {},logs is {} .",orderUid,promoteUid,activity.getId(),logs);
|
|
|
unionShareOrdersActivityLogsMapper.insertSelective(logs);
|
|
|
//更新用户月统计数据
|
...
|
...
|
|