Authored by gemingdan

cps邀新下单

... ... @@ -4,6 +4,7 @@ import com.yoho.service.model.union.bo.UnionShareInviteYohoBo;
import com.yoho.unions.dal.model.UnionShareYohoUser;
import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal;
import java.util.List;
import java.util.Set;
... ... @@ -15,6 +16,7 @@ public interface UnionShareYohoUserMapper {
int insertSelective(UnionShareYohoUser record);
UnionShareYohoUser selectByPrimaryKey(Integer id);
UnionShareYohoUser selectByUidAndInviter(@Param("inviterUid") Integer inviterUid,@Param("uid") Integer uid);
Set<Integer> selectByUids(@Param("uids") Set<Integer> uids);
int selectCountByInviterUid(Integer inviterUid);
... ... @@ -25,4 +27,5 @@ public interface UnionShareYohoUserMapper {
int updateByPrimaryKeySelective(UnionShareYohoUser record);
int updateByPrimaryKey(UnionShareYohoUser record);
int updateOrderAmount(@Param("id") Integer id, @Param("type") int type, @Param("orderAmount") BigDecimal orderAmount, @Param("updateTime") int updateTime);
}
\ No newline at end of file
... ...
... ... @@ -14,6 +14,7 @@ public class UnionShareYohoUser {
private Integer date;
private BigDecimal amount;
private BigDecimal orderAmount;
private Integer createTime;
... ... @@ -67,6 +68,14 @@ public class UnionShareYohoUser {
this.amount = amount;
}
public BigDecimal getOrderAmount() {
return orderAmount;
}
public void setOrderAmount(BigDecimal orderAmount) {
this.orderAmount = orderAmount;
}
public Integer getCreateTime() {
return createTime;
}
... ...
... ... @@ -8,11 +8,12 @@
<result column="nickname" property="nickname" jdbcType="VARCHAR" />
<result column="date" property="date" jdbcType="INTEGER" />
<result column="amount" property="amount" jdbcType="DECIMAL" />
<result column="order_amount" property="orderAmount" jdbcType="DECIMAL" />
<result column="create_time" property="createTime" jdbcType="INTEGER" />
<result column="update_time" property="updateTime" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
id, inviter_uid, uid, nickname, date, amount, create_time, update_time
id, inviter_uid, uid, nickname, date, amount,order_amount, create_time, update_time
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
... ... @@ -20,6 +21,12 @@
from union_share_yoho_user
where id = #{id,jdbcType=INTEGER}
</select>
<select id="selectByUidAndInviter" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from union_share_yoho_user
where uid = #{uid,jdbcType=INTEGER} and inviter_uid = #{inviterUid,jdbcType=INTEGER}
</select>
<select id="selectByUids" resultType="java.lang.Integer" >
select uid
from union_share_yoho_user
... ... @@ -53,10 +60,10 @@
</delete>
<insert id="insert" parameterType="com.yoho.unions.dal.model.UnionShareYohoUser" >
insert into union_share_yoho_user (id, inviter_uid, uid,
nickname, date, amount,
nickname, date, amount, order_amount,
create_time, update_time)
values (#{id,jdbcType=INTEGER}, #{inviterUid,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER},
#{nickname,jdbcType=VARCHAR}, #{date,jdbcType=INTEGER}, #{amount,jdbcType=DECIMAL},
#{nickname,jdbcType=VARCHAR}, #{date,jdbcType=INTEGER}, #{amount,jdbcType=DECIMAL}, #{orderAmount,jdbcType=DECIMAL},
#{createTime,jdbcType=INTEGER}, #{updateTime,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="com.yoho.unions.dal.model.UnionShareYohoUser" >
... ... @@ -80,6 +87,9 @@
<if test="amount != null" >
amount,
</if>
<if test="orderAmount != null" >
order_amount,
</if>
<if test="createTime != null" >
create_time,
</if>
... ... @@ -106,6 +116,9 @@
<if test="amount != null" >
#{amount,jdbcType=DECIMAL},
</if>
<if test="orderAmount != null" >
#{orderAmount,jdbcType=DECIMAL},
</if>
<if test="createTime != null" >
#{createTime,jdbcType=INTEGER},
</if>
... ... @@ -132,6 +145,9 @@
<if test="amount != null" >
amount = #{amount,jdbcType=DECIMAL},
</if>
<if test="orderAmount != null" >
order_amount = #{orderAmount,jdbcType=DECIMAL},
</if>
<if test="createTime != null" >
create_time = #{createTime,jdbcType=INTEGER},
</if>
... ... @@ -148,8 +164,22 @@
nickname = #{nickname,jdbcType=VARCHAR},
date = #{date,jdbcType=INTEGER},
amount = #{amount,jdbcType=DECIMAL},
order_amount = #{orderAmount,jdbcType=DECIMAL},
create_time = #{createTime,jdbcType=INTEGER},
update_time = #{updateTime,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateOrderAmount" >
update union_share_yoho_user
set
<if test="type==1">
order_amount = order_amount + #{orderAmount,jdbcType=DECIMAL},
</if>
<if test="type==2">
order_amount = order_amount - #{orderAmount,jdbcType=DECIMAL},
</if>
update_time = #{updateTime,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
... ...
... ... @@ -5,7 +5,7 @@
<parent>
<groupId>com.yoho</groupId>
<artifactId>parent</artifactId>
<version>1.6.3-SNAPSHOT</version>
<version>1.6.5-SNAPSHOT</version>
</parent>
<groupId>com.yoho.dsf</groupId>
<artifactId>yoho-unions</artifactId>
... ...
... ... @@ -1727,8 +1727,8 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
} else {
activityLogBo.setAmountStr("¥"+df1.format(activityLog.getAmount()));
}
//活动类型:1-特殊返,2-订单返利翻x倍,3-额外返,4-cps新人额外返,5-邀新返
if (activity.getType() < 5) {
//活动类型:1-特殊返,2-订单返利翻x倍,3-额外返,4-cps新人额外返,5-邀新返, 6-邀新下单
if (activity.getType() != 5) {
activityLogBo.setOrdercodes(activityLog.getOrders().split(","));
activityLogBo.setTimeStr(DateUtils.int2DateStr(activity.getStartTime(),"yyyy.MM.dd HH:mm:ss")+"-"+DateUtils.int2DateStr(activity.getEndTime(),"yyyy.MM.dd HH:mm:ss"));
}else {//5-邀新返,邀请注册yoho返佣
... ... @@ -2041,7 +2041,6 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
//获取总数
PageResponseBO<UnionShareUserInviteBo> response = new PageResponseBO<>();
//queryTimeType(预估收入实际):1-昨日,2-本月,3-上月
Integer count = unionShareUserInviteMapper.selectCountByInviterUid(req.getInviterUid());
if (count <= 0){
logger.info("UnionShareServiceImpl.queryInviteList count is 0");
... ... @@ -2116,6 +2115,11 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
bo.setDateStr(DateUtil.getDateStrBySecond(bo.getDate(),"yyyy.MM.dd"));
DecimalFormat df = new DecimalFormat("0.00");
bo.setAmountStr("¥"+df.format(bo.getAmount()));
if (bo.getOrderAmount().compareTo(new BigDecimal("0")) > 0) {
bo.setOrderAmountStr("¥" + df.format(bo.getOrderAmount()));
} else {
bo.setOrderAmountStr("-" );
}
unionShareUserInvitesBo.add(bo);
});
response.setList(unionShareUserInvitesBo);
... ... @@ -2354,10 +2358,14 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
}
if (unionShareOrders.getActivityId() != null&&ShareOrdersStatusEnum.isFailOrder(bo.getStatus())){
//该订单参加了加倍返活动,需要把加倍返日志作废
//该订单参加了加倍返或者邀新下单活动,需要把活动日志作废
UnionShareOrdersActivityLogs activityLog = getLogsByOrderId(unionShareOrders.getId());
if (activityLog != null) {
invalidActivityLog(activityLog.getId(), DateUtil.getCurrentTimeSecond());
if (activityLog.getActivityType() == 6) {
//活动类型6-邀新下单,需要把邀新下单活动佣金减去作废部分
invalidInviteYohoActivityAmount(unionShareOrders.getPromoteUid(), unionShareOrders.getOrderUid(), activityLog.getAmount());
}
}
}
... ... @@ -2451,6 +2459,20 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
updatelogs.setUpdateTime(now);
unionShareOrdersActivityLogsMapper.updateByPrimaryKeySelective(updatelogs);
}
//把邀新下单活动该订单增加的佣金部分减去
private void invalidInviteYohoActivityAmount(int inviterUid,int uid,BigDecimal amount) {
logger.info("invalidInviteYohoActivityAmount,inviterUid is {}, uid is {},amount is {}.",inviterUid, uid,amount);
UnionShareYohoUser unionShareYohoUser = unionShareYohoUserMapper.selectByUidAndInviter(inviterUid, uid);
if (unionShareYohoUser == null) {
return;
}
if (unionShareYohoUser.getOrderAmount().compareTo(amount) < 0) {
//数据有误,邀新佣金的下单总额居然小于单条邀新下单的佣金
logger.error("invalidInviteYohoActivityAmount,inviterUid is {}, uid is {},amount is {},orderAmount is {}.", inviterUid, uid, amount, unionShareYohoUser.getOrderAmount());
amount = unionShareYohoUser.getOrderAmount();
}
unionShareYohoUserMapper.updateOrderAmount(unionShareYohoUser.getId(), 2, amount, DateUtil.getCurrentTimeSeconds());
}
private boolean reJoinSomeExtraActivity(UnionShareOrdersActivityLogs activityLog){
logger.info("reJoinSomeExtraActivity,activityLog is {}",activityLog);
... ... @@ -2554,6 +2576,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
logger.info("dealWithWaitActivity,activity is {},selectUidList",activity);
List<UnionShareOrdersUidBo> uids;
//满单返过滤维度:1-下单人满单,2-分享人满单
//todo 过滤掉参加了活动类型6的订单
if (activity.getExtraUidType() == 2) {
uids = unionShareOrdersMapper.selectPromoteUidList(activity.getStartTime(), activity.getEndTime());
} else {
... ... @@ -2618,7 +2641,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
}
//查询某时间为进行中的活动
//type活动类型:1-特殊返,2-订单返利翻x倍,3-额外返,4-cps新人额外返
//type活动类型:1-特殊返,2-订单返利翻x倍,3-额外返,4-cps新人额外返,5-邀新返, 6-邀新下单
private List<UnionShareOrdersActivity> queryActivityByDate(Integer type,int date) {
logger.info("queryActivityByDate.date is {},type is {}.",date,type);
int dateInt=Integer.valueOf(DateUtil.getDateStrBySecond(date, "yyyyMMdd"));
... ... @@ -2635,7 +2658,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
int beginTime = DateUtil.getLastDayStartInt(date, 0);
int endTime = DateUtil.getLastDayEndInt(date, 0);
// activities=unionShareOrdersActivityMapper.selectByDate(date);
//type活动类型:1-特殊返,2-订单返利翻x倍,3-额外返,4-cps新人额外返
//type活动类型:1-特殊返,2-订单返利翻x倍,3-额外返,4-cps新人额外返,5-邀新返, 6-邀新下单
activities = queryLastDaysIngActivity(type,beginTime,endTime);
if (CollectionUtils.isEmpty(activities)) {
return new ArrayList<>();
... ... @@ -3036,11 +3059,12 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
return;
}
//活动返利
int type=2;
try {
//type活动类型:1-特殊返,2-订单返利翻x倍,3-额外返,4-cps新人额外返
List<UnionShareOrdersActivity> activityList = queryActivityByDate(2,order.getOrderTime());
List<UnionShareOrdersActivity> activityList = queryActivityByDate(type,order.getOrderTime());
for (UnionShareOrdersActivity a :activityList ) {
if(participateActivity(order,a)) {
if(participateActivity(order,a,type)) {
//参加了活动,参加一个加返活动就可以了
break;
}
... ... @@ -3053,13 +3077,13 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
/**
* 参加加倍返活动
* 参加加倍返活动、邀新下单
* */
private boolean participateActivity(UnionShareOrders order,UnionShareOrdersActivity activity) {
private boolean participateActivity(UnionShareOrders order,UnionShareOrdersActivity activity,int type) {
logger.info("participateActivity,order is {},activity is {}",order,activity);
//1、判断是否符合活动条件
//活动类型:1-订单返利比例升级,2-订单返利翻x倍,3-额外返
if (activity.getType() != 2) {
if (activity.getType() != type) {
//额外返在活动结束后走定时任务
return false;
}
... ... @@ -3080,14 +3104,11 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
return false;
}
//1.3 订单金额门槛
if (order.getLastOrderAmount().compareTo(activity.getOrderAmount()) < 0) {
return false;
}
//1.4 加倍返,需要报名才可以返佣
UnionShareOrdersActivityPagePre pagePre=unionOrdersActivityPagePreMapper.selectByUidAndActivityId(order.getPromoteUid(), activity.getId());
if (pagePre == null) {
return false;//未报名
//1.4 订单金额门槛
if (type == 2) {
if (order.getLastOrderAmount().compareTo(activity.getOrderAmount()) < 0) {
return false;
}
}
//1.5 拼团订单处理:0-不做处理,1-剔除拼团订单,2-拼团参与
... ... @@ -3111,17 +3132,43 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
}
}
//1.7 判断资格
if (type == 2) {
// 加倍返,需要报名才可以返佣
UnionShareOrdersActivityPagePre pagePre = unionOrdersActivityPagePreMapper.selectByUidAndActivityId(order.getPromoteUid(), activity.getId());
if (pagePre == null) {
return false;//未报名
}
}
Integer id=null;
if (type == 6) {
//邀新下单,需要有邀新记录且注册和下单时间差不超过7天才可以返佣
UnionShareYohoUser unionShareYohoUser = unionShareYohoUserMapper.selectByUidAndInviter(order.getPromoteUid(), order.getOrderUid());
if (unionShareYohoUser == null) {
return false;
}
if (unionShareYohoUser.getDate()+7*24*3600<order.getOrderTime()) {
return false;
}
id = unionShareYohoUser.getId();
}
//2、参加活动
//2.1 返利金额计算
BigDecimal extraAmount = activity.getAmount();
if (activity.getType() == 2) {
//活动类型:2-订单返利翻x倍
extraAmount = order.getAmount().multiply(new BigDecimal(activity.getPercent()).divide(new BigDecimal(10))).setScale(2,BigDecimal.ROUND_DOWN);
if (activity.getAmount().intValue()>0&&extraAmount.compareTo(activity.getAmount())>0) {
//订单返利金额高于封顶金额
extraAmount = activity.getAmount();
}
}
if (activity.getAmount().intValue()>0&&extraAmount.compareTo(activity.getAmount())>0) {
//订单返利金额高于封顶金额
extraAmount = activity.getAmount();
if (activity.getType() == 6&&order.getLastOrderAmount().compareTo(activity.getOrderAmount())<0) {
//活动类型:6-邀新下单,订单⾦额⼤于等于50,给分享⼈amount元返佣;⼩于50,按照订单⾦额percent%返佣
extraAmount = order.getLastOrderAmount().multiply(new BigDecimal(activity.getPercent()).divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN);
}
order.setExtraAmount(extraAmount);
order.setAmount(order.getAmount().add(extraAmount));
... ... @@ -3141,6 +3188,11 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
logger.info("participateActivity,order is {},activity is {},log is {}",order,activity,log);
unionShareOrdersActivityLogsMapper.insertSelective(log);
//2.3 更新邀新下单佣金
if (id != null) {
unionShareYohoUserMapper.updateOrderAmount(id,1,extraAmount,log.getCreateTime());
}
//3 更新订单返利金额
UnionShareOrders updateOrder = new UnionShareOrders();
updateOrder.setId(order.getId());
... ... @@ -3211,14 +3263,27 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
//活动返利
try {
//type活动类型:1-特殊返,2-订单返利翻x倍,3-额外返,4-cps新人额外返
List<UnionShareOrdersActivity> activityList = queryActivityByDate(2,bo.getOrderTime());
for (UnionShareOrdersActivity a :activityList ) {
if(participateActivity(insertReq,a)) {
//参加了活动,参加一个加返活动就可以了
//type活动类型:1-特殊返,2-订单返利翻x倍,3-额外返,4-cps新人额外返,5-邀新返, 6-邀新下单
//优先参加活动类型6
boolean isInviteOrder = false;
List<UnionShareOrdersActivity> inviteActivityList = queryActivityByDate(6,bo.getOrderTime());
for (UnionShareOrdersActivity a :inviteActivityList ) {
if(participateActivity(insertReq,a,6)) {
//参加了活动6-邀新下单
isInviteOrder = true;
break;
}
}
if (!isInviteOrder) {
//不是邀新下单可以参加加倍返活动
List<UnionShareOrdersActivity> activityList = queryActivityByDate(2,bo.getOrderTime());
for (UnionShareOrdersActivity a :activityList ) {
if(participateActivity(insertReq,a,2)) {
//参加了活动,参加一个加返活动就可以了
break;
}
}
}
} catch (Exception e) {
logger.warn("insertOrder warn,fail to handle some activities.bo is {}",bo);
}
... ... @@ -3717,6 +3782,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
redisHashCache.delete(ShareOrdersKeyEnum.USER_SETTLEMENT.getPreKey(),uid);
redisHashCache.delete(ShareOrdersKeyEnum.UNION_TYPE.getPreKey(),uid);
redisHashCache.delete(ShareOrdersKeyEnum.RECENTLY_ORDER_LIMIT_TEN.getPreKey(),uid);
redisHashCache.delete(ShareOrdersKeyEnum.INVITE_YOHO_LIST.getPreKey(),uid);
}
@Override
... ...