...
|
...
|
@@ -1500,6 +1500,29 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
return true;
|
|
|
}
|
|
|
|
|
|
//处理cps新人额外返活动某时间段数据
|
|
|
@Override
|
|
|
@Database(ForceMaster = true)
|
|
|
public void dealWithCpsNewUserActivity(UnionShareOrdersActivity activity,int beginTime,int endTime,int orderEndTime) {
|
|
|
logger.info("dealWithCpsNewUserActivity,activity is {},beginTime is {},endTime is {},orderEndTime is {}.",activity,beginTime,endTime,orderEndTime);
|
|
|
//查询可以参与活动的uid
|
|
|
Set<Integer> uids=unionShareUserApplyMapper.selectUidListByTime(activity.getStartTime(), activity.getEndTime());
|
|
|
logger.info("dealWithCpsNewUserActivity,activity is {},beginTime is {},endTime is {},orderEndTime is {},selectUidListByTime, uids is {}",activity,beginTime,endTime,orderEndTime,uids);
|
|
|
if (CollectionUtils.isEmpty(uids)) {
|
|
|
return;
|
|
|
}
|
|
|
//查询uid名下分享订单
|
|
|
Map<Integer, List<UnionShareOrders>> uidOrders=unionShareOrdersMapper.selectNewPromoteUidsOrder(uids, orderEndTime);
|
|
|
uids.forEach(u->{
|
|
|
joinNewCpsActivity(u,uidOrders.get(u), activity.getId());
|
|
|
});
|
|
|
|
|
|
//发放完成
|
|
|
logger.info("dealWithCpsNewUserActivity over,activity is {},begin to change status to 2.",activity);
|
|
|
unionShareOrdersActivityMapper.updateStatusById(activity.getId(), 1, 2, DateUtil.getCurrentTimeSecond());
|
|
|
return ;
|
|
|
}
|
|
|
|
|
|
|
|
|
//处理已结束等待发放奖励的活动
|
|
|
@Override
|
...
|
...
|
@@ -1527,7 +1550,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
return ;
|
|
|
}
|
|
|
|
|
|
//查询已结束等待发放奖励的活动
|
|
|
//查询已结束等待发放奖励的普通额外返活动
|
|
|
@Override
|
|
|
public List<UnionShareOrdersActivity> queryWaitActivity() {
|
|
|
logger.info("queryWaitActivity.");
|
...
|
...
|
@@ -1535,6 +1558,18 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
return activities;
|
|
|
}
|
|
|
|
|
|
//查询过去startDays天到过去endDays内有进行中状态的的新人额外返活动(startDays>endDays)
|
|
|
@Override
|
|
|
public List<UnionShareOrdersActivity> queryLastDaysIngActivity(int beginTime,int endTime) {
|
|
|
logger.info("queryLastDaysActivity.beginTime is {},endTime is {}.",beginTime,endTime);
|
|
|
if (beginTime <= endTime) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
List<UnionShareOrdersActivity> activities=unionShareOrdersActivityMapper.selectLastDaysIngActivity(beginTime,endTime);
|
|
|
return activities;
|
|
|
}
|
|
|
|
|
|
//查询进行中的活动
|
|
|
private List<UnionShareOrdersActivity> queryActivity() {
|
|
|
logger.info("queryActivity.");
|
...
|
...
|
@@ -1563,8 +1598,8 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
List<UnionShareOrders> orders = unionShareOrdersMapper.selectListByOrderUidForActivity(beginTime, endTime, orderUid,promoteUid);
|
|
|
return orders;
|
|
|
}
|
|
|
//查询分享人和下单人关联订单参与的满单返活动单
|
|
|
private UnionShareOrders queryOrderActivity(int orderUid,int promoteUid,int activityId) {
|
|
|
//查询分享人分享订单参与的满单返活动单
|
|
|
private UnionShareOrders queryOrderActivity(Integer orderUid,int promoteUid,int activityId) {
|
|
|
logger.info("queryOrderActivity,orderUid is {},promoteUid is {},activityId is {}",orderUid,promoteUid,activityId);
|
|
|
UnionShareOrders activityOrder = unionShareOrdersMapper.selectActivityOrderByUid(activityId, orderUid,promoteUid);
|
|
|
return activityOrder;
|
...
|
...
|
@@ -1683,62 +1718,106 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
for (UnionShareOrdersActivityItem item : items) {
|
|
|
if (orders.size() >= item.getOrderMinNum() && orders.size() <= item.getOrderMaxNum()) {
|
|
|
//满足此项标准
|
|
|
StringBuilder ordersStr = new StringBuilder();
|
|
|
List<Integer> orderIds = new ArrayList<>();
|
|
|
String status=ShareOrdersStatusEnum.CAN_SETTLE.getCode();
|
|
|
for(UnionShareOrders order:orders){
|
|
|
if(ShareOrdersStatusEnum.getLevelByCode(order.getStatus())<ShareOrdersStatusEnum.CAN_SETTLE.getLevel()){
|
|
|
status = order.getStatus();
|
|
|
}
|
|
|
ordersStr.append(order.getOrderCode()).append(',');
|
|
|
orderIds.add(order.getId());
|
|
|
}
|
|
|
//更新订单额外返数据
|
|
|
int now = DateUtil.getCurrentTimeSecond();
|
|
|
logger.info("joinExtraActivity,orderUid is {},promoteUid is {},activityId is {},updateByIdsForExtraActivity,orderIds is {} .",orderUid,promoteUid,activityId,orderIds);
|
|
|
unionShareOrdersMapper.updateByIdsForExtraActivity(orderIds, activityId,now);
|
|
|
|
|
|
//插入额外返利单
|
|
|
UnionShareOrders insertExtraOrder = new UnionShareOrders();
|
|
|
insertExtraOrder.setExtraAmount(item.getAmount());
|
|
|
insertExtraOrder.setAmount(item.getAmount());
|
|
|
insertExtraOrder.setExtraActivityId(activityId);
|
|
|
insertExtraOrder.setActivityId(activityId);
|
|
|
insertExtraOrder.setActivityName(activity.getActivityName());
|
|
|
insertExtraOrder.setPromoteUid(promoteUid);
|
|
|
insertExtraOrder.setOrderUid(orderUid);
|
|
|
insertExtraOrder.setStatus(status);
|
|
|
insertExtraOrder.setOrderTime(now);
|
|
|
insertExtraOrder.setCreateTime(now);
|
|
|
insertExtraOrder.setUpdateTime(now);
|
|
|
logger.info("joinExtraActivity,orderUid is {},promoteUid is {},activityId is {},insertExtraOrder is {} .",orderUid,promoteUid,activityId,insertExtraOrder);
|
|
|
unionShareOrdersMapper.insertSelective(insertExtraOrder);
|
|
|
|
|
|
//记录满单返活动参与日志
|
|
|
UnionShareOrdersActivityLogs logs = new UnionShareOrdersActivityLogs();
|
|
|
logs.setOrders(ordersStr.substring(0,ordersStr.length()-1));
|
|
|
logs.setOrderId(insertExtraOrder.getId());
|
|
|
logs.setActivityId(activityId);
|
|
|
logs.setActivityName(activity.getActivityName());
|
|
|
logs.setActivityType(activity.getType());
|
|
|
logs.setActivityItemId(item.getId());
|
|
|
logs.setAmount(item.getAmount());
|
|
|
logs.setCreateTime(now);
|
|
|
logs.setUpdateTime(now);
|
|
|
logs.setPromoteUid(promoteUid);
|
|
|
logs.setOrderUid(orderUid);
|
|
|
logger.info("joinExtraActivity,orderUid is {},promoteUid is {},activityId is {},logs is {} .",orderUid,promoteUid,activityId,logs);
|
|
|
unionShareOrdersActivityLogsMapper.insertSelective(logs);
|
|
|
//更新用户月统计数据
|
|
|
updateMonthData(logs.getPromoteUid(),new HashSet<String>(){{add(DateUtil.getDateStrBySecond(now,"yyyyMM"));}});
|
|
|
insertJoinDataForActivity(orders, orderUid, promoteUid, activity, item);
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
//参加新cps用户分享满单额外返活动
|
|
|
boolean joinNewCpsActivity(int promoteUid ,List<UnionShareOrders> orders,int activityId){
|
|
|
if (CollectionUtils.isEmpty(orders)) {
|
|
|
return false;
|
|
|
}
|
|
|
//查询是否已参加过此活动
|
|
|
if (hasJoinActivity(null, promoteUid, activityId)) {
|
|
|
//存在有效的参与数据,直接返回
|
|
|
logger.info("joinNewCpsActivity end,hasJoinActivity,promoteUid is {},activityId is {}.",promoteUid,activityId);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
UnionShareOrdersActivity activity = queryActivity(activityId);
|
|
|
if (null == activity || activity.getType() != 4) {
|
|
|
logger.info("joinNewCpsActivity end,activity error,promoteUid is {},activityId is {},activity is {}.",promoteUid,activityId,activity);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
//查询满x单返活动条目(正常状态)
|
|
|
List<UnionShareOrdersActivityItem> items = queryActivityItemList(activityId);
|
|
|
for (UnionShareOrdersActivityItem item : items) {
|
|
|
if (orders.size() >= item.getOrderMinNum() && orders.size() <= item.getOrderMaxNum()) {
|
|
|
//满足此项标准
|
|
|
insertJoinDataForActivity(orders, null, promoteUid, activity, item);
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
//向数据库插入参与某种额外返、新cps额外返活动的数据
|
|
|
boolean insertJoinDataForActivity(List<UnionShareOrders> orders, Integer orderUid , int promoteUid , UnionShareOrdersActivity activity, UnionShareOrdersActivityItem item) {
|
|
|
//满足此项标准
|
|
|
if (orderUid != null && activity.getType() != 3) {
|
|
|
//活动类型:1-订单返利比例升级,2-订单返利翻x倍,3-额外返,4-cps新人额外返
|
|
|
//当类型为3时需要传orderUid,当类型为4时不需要传orderUid
|
|
|
return false;
|
|
|
}
|
|
|
StringBuilder ordersStr = new StringBuilder();
|
|
|
List<Integer> orderIds = new ArrayList<>();
|
|
|
String status=ShareOrdersStatusEnum.CAN_SETTLE.getCode();
|
|
|
for(UnionShareOrders order:orders){
|
|
|
if(ShareOrdersStatusEnum.getLevelByCode(order.getStatus())<ShareOrdersStatusEnum.CAN_SETTLE.getLevel()){
|
|
|
status = order.getStatus();
|
|
|
}
|
|
|
ordersStr.append(order.getOrderCode()).append(',');
|
|
|
orderIds.add(order.getId());
|
|
|
}
|
|
|
//更新订单额外返数据
|
|
|
int now = DateUtil.getCurrentTimeSecond();
|
|
|
if (orderUid != null) {
|
|
|
logger.info("insertJoinDataForActivity,orderUid is {},promoteUid is {},activityId is {},updateByIdsForExtraActivity,orderIds is {} .",orderUid,promoteUid,activity.getId(),orderIds);
|
|
|
unionShareOrdersMapper.updateByIdsForExtraActivity(orderIds, activity.getId(),now);
|
|
|
}
|
|
|
|
|
|
//插入额外返利单
|
|
|
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);
|
|
|
insertExtraOrder.setUpdateTime(now);
|
|
|
logger.info("insertJoinDataForActivity,orderUid is {},promoteUid is {},activityId is {},insertExtraOrder is {} .",orderUid,promoteUid,activity.getId(),insertExtraOrder);
|
|
|
unionShareOrdersMapper.insertSelective(insertExtraOrder);
|
|
|
|
|
|
//记录满单返活动参与日志
|
|
|
UnionShareOrdersActivityLogs logs = new UnionShareOrdersActivityLogs();
|
|
|
logs.setOrders(ordersStr.substring(0,ordersStr.length()-1));
|
|
|
logs.setOrderId(insertExtraOrder.getId());
|
|
|
logs.setActivityId(activity.getId());
|
|
|
logs.setActivityName(activity.getActivityName());
|
|
|
logs.setActivityType(activity.getType());
|
|
|
logs.setActivityItemId(item.getId());
|
|
|
logs.setAmount(item.getAmount());
|
|
|
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);
|
|
|
//更新用户月统计数据
|
|
|
updateMonthData(logs.getPromoteUid(),new HashSet<String>(){{add(DateUtil.getDateStrBySecond(now,"yyyyMM"));}});
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
//是否已参加过此活动
|
|
|
private boolean hasJoinActivity(int orderUid ,int promoteUid ,int activityId) {
|
|
|
private boolean hasJoinActivity(Integer orderUid ,int promoteUid ,int activityId) {
|
|
|
UnionShareOrders unionShareOrders=queryOrderActivity(orderUid, promoteUid, activityId);
|
|
|
if (unionShareOrders == null) {
|
|
|
return false;
|
...
|
...
|
|