...
|
...
|
@@ -18,6 +18,9 @@ import java.util.stream.Collectors; |
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
import com.yoho.service.model.union.bo.*;
|
|
|
import com.yoho.unions.dal.*;
|
|
|
import com.yoho.unions.dal.model.*;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.elasticsearch.common.collect.Maps;
|
...
|
...
|
@@ -37,17 +40,6 @@ import com.yoho.core.dal.datasource.annotation.Database; |
|
|
import com.yoho.core.rabbitmq.YhProducer;
|
|
|
import com.yoho.error.ServiceError;
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yoho.service.model.union.bo.IdOrIdsBo;
|
|
|
import com.yoho.service.model.union.bo.ShareOrderBo;
|
|
|
import com.yoho.service.model.union.bo.ShareOrdersProductBo;
|
|
|
import com.yoho.service.model.union.bo.ShareSettlementBo;
|
|
|
import com.yoho.service.model.union.bo.ShareUserSettlementInfoBo;
|
|
|
import com.yoho.service.model.union.bo.SocialMediaBo;
|
|
|
import com.yoho.service.model.union.bo.UnionShareBankBo;
|
|
|
import com.yoho.service.model.union.bo.UnionShareOrderSearchBo;
|
|
|
import com.yoho.service.model.union.bo.UnionShareOrdersActivityBo;
|
|
|
import com.yoho.service.model.union.bo.UnionShareUserBankBo;
|
|
|
import com.yoho.service.model.union.bo.UnionShareUserBo;
|
|
|
import com.yoho.service.model.union.request.UnionShareOrderReqBO;
|
|
|
import com.yoho.service.model.union.request.UnionShareOrderSearchReqBO;
|
|
|
import com.yoho.service.model.union.request.UnionShareUserApplyListReqBo;
|
...
|
...
|
@@ -74,28 +66,6 @@ import com.yoho.unions.common.utils.RandomUtil; |
|
|
import com.yoho.unions.common.utils.StringHideUtils;
|
|
|
import com.yoho.unions.convert.BeanConvert;
|
|
|
import com.yoho.unions.convert.Convert;
|
|
|
import com.yoho.unions.dal.IMktMarketingUrlDAO;
|
|
|
import com.yoho.unions.dal.UnionShareBigDataClickMapper;
|
|
|
import com.yoho.unions.dal.UnionShareOrdersActivityLogsMapper;
|
|
|
import com.yoho.unions.dal.UnionShareOrdersActivityMapper;
|
|
|
import com.yoho.unions.dal.UnionShareOrdersMapper;
|
|
|
import com.yoho.unions.dal.UnionShareOrdersMonthMapper;
|
|
|
import com.yoho.unions.dal.UnionShareOrdersProductMapper;
|
|
|
import com.yoho.unions.dal.UnionShareSettlementMapper;
|
|
|
import com.yoho.unions.dal.UnionShareUserApplyMapper;
|
|
|
import com.yoho.unions.dal.UnionShareUserBankMapper;
|
|
|
import com.yoho.unions.dal.UnionShareUserMapper;
|
|
|
import com.yoho.unions.dal.model.MktMarketingUrl;
|
|
|
import com.yoho.unions.dal.model.UnionShareBigDataClick;
|
|
|
import com.yoho.unions.dal.model.UnionShareOrders;
|
|
|
import com.yoho.unions.dal.model.UnionShareOrdersActivity;
|
|
|
import com.yoho.unions.dal.model.UnionShareOrdersActivityLogs;
|
|
|
import com.yoho.unions.dal.model.UnionShareOrdersListBO;
|
|
|
import com.yoho.unions.dal.model.UnionShareOrdersProduct;
|
|
|
import com.yoho.unions.dal.model.UnionShareSettlement;
|
|
|
import com.yoho.unions.dal.model.UnionShareUser;
|
|
|
import com.yoho.unions.dal.model.UnionShareUserApply;
|
|
|
import com.yoho.unions.dal.model.UnionShareUserBank;
|
|
|
import com.yoho.unions.server.service.IUnionShareService;
|
|
|
import com.yoho.unions.utils.DateUtils;
|
|
|
import com.yoho.unions.utils.ImagesHelper;
|
...
|
...
|
@@ -131,6 +101,8 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
@Autowired
|
|
|
UnionShareOrdersActivityMapper unionShareOrdersActivityMapper;
|
|
|
@Autowired
|
|
|
UnionShareOrdersActivityItemMapper unionShareOrdersActivityItemMapper;
|
|
|
@Autowired
|
|
|
UnionShareOrdersMonthMapper unionShareOrdersMonthMapper;
|
|
|
@Autowired
|
|
|
UnionShareBigDataClickMapper unionShareBigDataClickMapper;
|
...
|
...
|
@@ -1037,6 +1009,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
* 订单插入或更新
|
|
|
*/
|
|
|
@Override
|
|
|
@Database(ForceMaster = true)
|
|
|
public void saveOrUpdateOrder(ShareOrderBo bo) {
|
|
|
logger.info("saveOrUpdateOrder enter,req is {}",bo);
|
|
|
if (bo == null) {
|
...
|
...
|
@@ -1077,34 +1050,137 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
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 判断满返是否作废
|
|
|
}
|
|
|
rehandExtraActivity(unionShareOrders);
|
|
|
}
|
|
|
//清缓存
|
|
|
clearShareOrderRedis(bo.getPromoteUid());
|
|
|
}
|
|
|
|
|
|
//重新处理订单相关的满单返活动
|
|
|
private void rehandExtraActivity(UnionShareOrders unionShareOrders) {
|
|
|
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.isEmpty(activityLogs)) {
|
|
|
return;
|
|
|
}
|
|
|
for(UnionShareOrdersActivityLogs activityLog:activityLogs){
|
|
|
//活动类型:1-订单返利比例升级,2-订单返利翻x倍,3-额外返
|
|
|
if (activityLog.getActivityType() != 3) {
|
|
|
continue;
|
|
|
}
|
|
|
String[] orders=activityLog.getOrders().split(",");
|
|
|
for (int i = 0; i < orders.length; i++) {
|
|
|
if (orders[i].equals(unionShareOrders.getOrderCode())) {
|
|
|
//判断满返是否作废,若作废,查询是否满足该活动低一阶段条件
|
|
|
// 获取某时间段可参与活动的单数
|
|
|
List<String> orderCodeList = Arrays.stream(orders).collect(Collectors.toList());
|
|
|
List<UnionShareOrders> orderList = unionShareOrdersMapper.selectListByOrderCodesForActivity(orderCodeList);
|
|
|
UnionShareOrdersActivityItem item = unionShareOrdersActivityItemMapper.selectByPrimaryKey(activityLog.getActivityItemId());
|
|
|
if (orderList.size() <item.getOrderMinNum()) {
|
|
|
//作废已参加的满单活动
|
|
|
UnionShareOrdersActivityLogs updatelogs = new UnionShareOrdersActivityLogs();
|
|
|
updatelogs.setId(activityLog.getId());
|
|
|
updatelogs.setStatus(0);//类型:1-有效,0-作废
|
|
|
updateLogs.setUpdateTime(DateUtil.getCurrentTimeSecond());
|
|
|
unionShareOrdersActivityLogsMapper.updateByPrimaryKeySelective(updatelogs);
|
|
|
|
|
|
//重新参加活动
|
|
|
boolean joinResult = joinExtraActivity(activityLog.getOrderUid(), activityLog.getPromoteUid(), activityLog.getActivityId());
|
|
|
if (!joinResult) {
|
|
|
//已不满足此活动条件
|
|
|
// clearOrderRelated(orderCodeList);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//一个订单最多可以参加一个满单返活动
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//todo 查询进行中的活动
|
|
|
//查询进行中的活动
|
|
|
private List<UnionShareOrdersActivity> queryActivity() {
|
|
|
List<UnionShareOrdersActivity> activities=unionShareOrdersActivityMapper.selectByDate(DateUtil.getCurrentTimeSecond());
|
|
|
return activities;
|
|
|
}
|
|
|
//todo 查询分享人已参加的活动
|
|
|
private void queryUidActivity(int uid) {
|
|
|
// List<UnionShareOrdersActivity> activities=unionShareOrdersActivityLogsMapper.selectByOrderIds()
|
|
|
//获取某时间段可参与活动的单数
|
|
|
private List<UnionShareOrders> queryUidActivity(int orderUid,int promoteUid,int beginTime,int endTime) {
|
|
|
List<UnionShareOrders> orders = unionShareOrdersMapper.selectListByOrderUidForActivity(beginTime, endTime, orderUid,promoteUid);
|
|
|
return orders;
|
|
|
}
|
|
|
// 参加满x单返活动
|
|
|
private boolean joinExtraActivity(int orderUid ,int promoteUid ,int activityId){
|
|
|
UnionShareOrdersActivity activity = unionShareOrdersActivityMapper.selectByPrimaryKey(activityId);
|
|
|
if (activity == null || activity.getType() != 3) {
|
|
|
return false;
|
|
|
}
|
|
|
List<UnionShareOrders> orders = queryUidActivity(orderUid,promoteUid, activity.getStartTime(), activity.getEndTime());
|
|
|
if (orders.size() == 0) {
|
|
|
return false;
|
|
|
}
|
|
|
//查询满x单返活动条目
|
|
|
List<UnionShareOrdersActivityItem> items = unionShareOrdersActivityItemMapper.selectByActivityId(activityId);
|
|
|
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())<2){
|
|
|
status = order.getStatus();
|
|
|
}
|
|
|
ordersStr.append(order.getOrderCode()).append(',');
|
|
|
orderIds.add(order.getId());
|
|
|
}
|
|
|
//更新订单额外返数据
|
|
|
int now = DateUtil.getCurrentTimeSecond();
|
|
|
unionShareOrdersMapper.updateByIdsForExtraActivity(orderIds, activityId,now);
|
|
|
|
|
|
//插入额外返利单
|
|
|
UnionShareOrders insertExtraOrder = new UnionShareOrders();
|
|
|
insertExtraOrder.setExtraAmount(item.getAmount());
|
|
|
insertExtraOrder.setAmount(item.getAmount());
|
|
|
insertExtraOrder.setExtraActivityId(activityId);
|
|
|
insertExtraOrder.setActivityId(activityId);
|
|
|
insertExtraOrder.setPromoteUid(promoteUid);
|
|
|
insertExtraOrder.setOrderUid(orderUid);
|
|
|
insertExtraOrder.setStatus(status);
|
|
|
insertExtraOrder.setCreateTime(now);
|
|
|
insertExtraOrder.setUpdateTime(now);
|
|
|
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);
|
|
|
unionShareOrdersActivityLogsMapper.insertSelective(logs);
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//参加活动
|
|
|
return false;
|
|
|
}
|
|
|
// 是否可以参与满单返活动
|
|
|
private boolean canJoinExtraActivity(){
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
//参加加倍返活动
|
|
|
private boolean participateActivity(UnionShareOrders order,UnionShareOrdersActivity activity) {
|
|
|
//1、判断是否符合活动条件
|
|
|
//1.1 活动类型:1-订单返利比例升级,2-订单返利翻x倍,3-额外返
|
...
|
...
|
@@ -1154,22 +1230,12 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
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() {
|
|
|
|
|
|
}
|
|
|
//todo 判断是否达标
|
|
|
private boolean canJoin(){
|
|
|
return false;
|
|
|
}
|
|
|
//todo 汇总月统计数据
|
|
|
|
|
|
/**
|
|
|
* 保存订单信息
|
...
|
...
|
|