Authored by mingdan.ge

新cps用户活动奖励

... ... @@ -207,6 +207,13 @@ public class DateUtil {
time.set(time.get(Calendar.YEAR),time.get(Calendar.MONTH),time.get(Calendar.HOUR_OF_DAY),0,0,0);
return (int) (time.getTime().getTime()/1000);
}
public static int getLastDayInt(int time,int lastDay) {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(time*1000);
calendar.add(Calendar.DAY_OF_YEAR,1-lastDay);
calendar.set(calendar.get(Calendar.YEAR),calendar.get(Calendar.MONTH),calendar.get(Calendar.HOUR_OF_DAY),0,0,0);
return (int) (calendar.getTime().getTime()/1000);
}
/**
* 日期格式转换
... ...
... ... @@ -53,6 +53,7 @@ public interface UnionShareOrdersMapper {
int updateByPrimaryKeySelective(UnionShareOrders record);
int updateByIdsForExtraActivity(@Param("ids")List<Integer> id,@Param("extraActivityId")Integer extraActivityId,@Param("updateTime")Integer updateTime);
int updateByIdsForCpsUserActivity(@Param("ids")List<Integer> id,@Param("cpsExtraActivityId")Integer cpsExtraActivityId,@Param("updateTime")Integer updateTime);
int updateStatusById(@Param("id")int id,@Param("oldStatus")String oldStatus,@Param("newStatus")String newStatus,@Param("updateTime")int updateTime);
... ... @@ -73,4 +74,6 @@ public interface UnionShareOrdersMapper {
@MapKey("uid")
Map<Integer, List<UnionShareOrders>> selectNewPromoteUidsOrder(@Param("promoteUids") Set<Integer> promoteUids, @Param("endTime") int endTime);
List<UnionShareOrders> selectNewPromoteUidOrder(@Param("promoteUid") int promoteUid, @Param("endTime") int endTime);
}
\ No newline at end of file
... ...
... ... @@ -28,6 +28,8 @@ public interface UnionShareUserMapper {
Integer selectUidByUnionType(String unionType);
int updateCpsActByUid(@Param("uid")int uid,@Param("activityId") int activityId,@Param("updateTime") int updateTime);
@MapKey("uid")
Map<Integer,UnionShareUser> selectByUids(@Param("uids") Set<Integer> uids);
}
\ No newline at end of file
... ...
... ... @@ -34,6 +34,7 @@ public class UnionShareOrders extends BaseBO {
private Integer updateTime;
private Integer cpsExtraActivityId;//新cps用户专享活动id
private Integer extraActivityId;
private Integer activityId;
private String activityName;
... ... @@ -219,6 +220,14 @@ public class UnionShareOrders extends BaseBO {
this.paymentType = paymentType;
}
public Integer getCpsExtraActivityId() {
return cpsExtraActivityId;
}
public void setCpsExtraActivityId(Integer cpsExtraActivityId) {
this.cpsExtraActivityId = cpsExtraActivityId;
}
@Override
public String toString() {
return "UnionShareOrders{" +
... ... @@ -237,6 +246,7 @@ public class UnionShareOrders extends BaseBO {
", amountStr='" + amountStr + '\'' +
", createTime=" + createTime +
", updateTime=" + updateTime +
", cpsExtraActivityId=" + cpsExtraActivityId +
", extraActivityId=" + extraActivityId +
", activityId=" + activityId +
", activityName=" + activityName +
... ...
... ... @@ -11,6 +11,8 @@ public class UnionShareUser {
private Integer createTime;
private Integer applyId;
private Integer status;
private Integer specialStatus;
private Integer cpsActivityId;
private String imageUrl;
... ... @@ -88,6 +90,22 @@ public class UnionShareUser {
this.status = status;
}
public Integer getSpecialStatus() {
return specialStatus;
}
public void setSpecialStatus(Integer specialStatus) {
this.specialStatus = specialStatus;
}
public Integer getCpsActivityId() {
return cpsActivityId;
}
public void setCpsActivityId(Integer cpsActivityId) {
this.cpsActivityId = cpsActivityId;
}
@Override
public String toString() {
return "UnionShareUser{" +
... ... @@ -98,6 +116,8 @@ public class UnionShareUser {
", updateTime=" + updateTime +
", status=" + status +
", applyId=" + applyId +
", specialStatus=" + specialStatus +
", cpsActivityId=" + cpsActivityId +
", imageUrl='" + imageUrl + '\'' +
", shareId='" + shareId + '\'' +
'}';
... ...
... ... @@ -303,6 +303,15 @@
#{item}
</foreach>
</update>
<update id="updateByIdsForCpsUserActivity" >
update union_share_orders
set update_time = #{updateTime,jdbcType=INTEGER},
extra_activity_id = #{cpsExtraActivityId,jdbcType=INTEGER}
where id in
<foreach collection="ids" separator="," item="item" index="index" close=")" open="(">
#{item}
</foreach>
</update>
<update id="updateByPrimaryKey" parameterType="com.yoho.unions.dal.model.UnionShareOrders" >
update union_share_orders
set order_code = #{orderCode,jdbcType=VARCHAR},
... ... @@ -550,5 +559,19 @@
and order_time &lt;#{endTime}
</if>
</select>
<select id="selectNewPromoteUidsOrder" resultMap="BaseResultMap">
select <include refid="Base_Column_List" />
from union_share_orders
where promote_uid in
<foreach collection="promoteUids" separator="," item="item" index="index" close=")" open="(">
#{item}
</foreach>
and order_time &lt;#{endTime} and status in (10,20,30,40)
</select>
<select id="selectNewPromoteUidOrder" resultMap="BaseResultMap">
select <include refid="Base_Column_List" />
from union_share_orders
where promote_uid = #{promoteUid} and order_time &lt;#{endTime} and status in (10,20,30,40)
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -7,11 +7,13 @@
<result column="union_type" property="unionType" jdbcType="VARCHAR" />
<result column="status" property="status" jdbcType="INTEGER" />
<result column="apply_id" property="applyId" jdbcType="INTEGER" />
<result column="special_status" property="specialStatus" jdbcType="INTEGER" />
<result column="cps_activity_id" property="cpsActivityId" jdbcType="INTEGER" />
<result column="create_time" property="createTime" jdbcType="INTEGER" />
<result column="update_time" property="updateTime" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
id, uid, union_type, update_time,create_time,status,apply_id
id, uid, union_type, update_time,create_time,status,apply_id,special_status,cps_activity_id
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
... ... @@ -155,4 +157,10 @@
apply_id = #{applyId,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateCpsActByUid" >
update union_share_user
set cps_activity_id = #{activityId,jdbcType=INTEGER},
update_time = #{updateTime,jdbcType=INTEGER},
where uid = #{uid,jdbcType=INTEGER} and cps_activity_id is NULL
</update>
</mapper>
\ No newline at end of file
... ...
... ... @@ -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);
//更新用户月统计数据
... ...