Authored by caoyan

Merge branch 'dev_180724_cps四期' of http://git.yoho.cn/yoho30/yohobuy-union into dev_180724_cps四期

@@ -50,6 +50,9 @@ public enum ShareOrdersStatusEnum { @@ -50,6 +50,9 @@ public enum ShareOrdersStatusEnum {
50 return null; 50 return null;
51 } 51 }
52 52
  53 + public static boolean isFailOrder(String status) {
  54 + return (!status.equals(ShareOrdersStatusEnum.CAN_SETTLE)) && (ShareOrdersStatusEnum.getLevelByCode(status)==2);
  55 + }
53 public int getLevel() { 56 public int getLevel() {
54 return level; 57 return level;
55 } 58 }
1 package com.yoho.unions.dal; 1 package com.yoho.unions.dal;
2 2
3 import com.yoho.unions.dal.model.UnionShareOrdersActivityLogs; 3 import com.yoho.unions.dal.model.UnionShareOrdersActivityLogs;
  4 +import org.apache.ibatis.annotations.Param;
4 5
5 import java.util.List; 6 import java.util.List;
6 7
@@ -12,9 +13,12 @@ public interface UnionShareOrdersActivityLogsMapper { @@ -12,9 +13,12 @@ public interface UnionShareOrdersActivityLogsMapper {
12 int insertSelective(UnionShareOrdersActivityLogs record); 13 int insertSelective(UnionShareOrdersActivityLogs record);
13 14
14 UnionShareOrdersActivityLogs selectByPrimaryKey(Integer id); 15 UnionShareOrdersActivityLogs selectByPrimaryKey(Integer id);
15 - List<UnionShareOrdersActivityLogs> selectByOrderIds(List<Integer> ids); 16 + List<UnionShareOrdersActivityLogs> selectByOrderIds(@Param("orderIds") List<Integer> orderIds);
  17 + List<UnionShareOrdersActivityLogs> selectByOrderId(@Param("orderId") Integer orderId);
  18 + List<UnionShareOrdersActivityLogs> selectByOrderCode(@Param("orderCode") String orderCode);
16 19
17 int updateByPrimaryKeySelective(UnionShareOrdersActivityLogs record); 20 int updateByPrimaryKeySelective(UnionShareOrdersActivityLogs record);
  21 + int updateStatusByOrderId(UnionShareOrdersActivityLogs record);
18 22
19 int updateByPrimaryKey(UnionShareOrdersActivityLogs record); 23 int updateByPrimaryKey(UnionShareOrdersActivityLogs record);
20 } 24 }
@@ -35,6 +35,7 @@ public interface UnionShareOrdersMapper { @@ -35,6 +35,7 @@ public interface UnionShareOrdersMapper {
35 List<UnionShareOrders> selectListByCondition(@Param("promoteUid")int promoteUid, @Param("status")String status,@Param("updateTime")int updateTime, @Param("offset") int offset, @Param("rows") int rows); 35 List<UnionShareOrders> selectListByCondition(@Param("promoteUid")int promoteUid, @Param("status")String status,@Param("updateTime")int updateTime, @Param("offset") int offset, @Param("rows") int rows);
36 36
37 List<String> selectOrderCodesByCondition(@Param("settlementCode")String settlementCode, @Param("offset") int offset, @Param("rows") int rows); 37 List<String> selectOrderCodesByCondition(@Param("settlementCode")String settlementCode, @Param("offset") int offset, @Param("rows") int rows);
  38 + List<UnionShareOrders> selectOrderByCondition(@Param("settlementCode")String settlementCode, @Param("offset") int offset, @Param("rows") int rows);
38 List<Integer> selectIdForActivity(@Param("settlementCode")String settlementCode); 39 List<Integer> selectIdForActivity(@Param("settlementCode")String settlementCode);
39 40
40 int updateByPrimaryKeySelective(UnionShareOrders record); 41 int updateByPrimaryKeySelective(UnionShareOrders record);
@@ -6,6 +6,7 @@ public class UnionShareOrdersActivityLogs { @@ -6,6 +6,7 @@ public class UnionShareOrdersActivityLogs {
6 private Integer id; 6 private Integer id;
7 7
8 private Integer activityId; 8 private Integer activityId;
  9 + private Integer activityType;
9 10
10 private String activityName; 11 private String activityName;
11 12
@@ -112,4 +113,12 @@ public class UnionShareOrdersActivityLogs { @@ -112,4 +113,12 @@ public class UnionShareOrdersActivityLogs {
112 public void setUpdateTime(Integer updateTime) { 113 public void setUpdateTime(Integer updateTime) {
113 this.updateTime = updateTime; 114 this.updateTime = updateTime;
114 } 115 }
  116 +
  117 + public Integer getActivityType() {
  118 + return activityType;
  119 + }
  120 +
  121 + public void setActivityType(Integer activityType) {
  122 + this.activityType = activityType;
  123 + }
115 } 124 }
@@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
4 <resultMap id="BaseResultMap" type="com.yoho.unions.dal.model.UnionShareOrdersActivityLogs" > 4 <resultMap id="BaseResultMap" type="com.yoho.unions.dal.model.UnionShareOrdersActivityLogs" >
5 <id column="id" property="id" jdbcType="INTEGER" /> 5 <id column="id" property="id" jdbcType="INTEGER" />
6 <result column="activity_id" property="activityId" jdbcType="INTEGER" /> 6 <result column="activity_id" property="activityId" jdbcType="INTEGER" />
  7 + <result column="activity_type" property="activityType" jdbcType="INTEGER" />
7 <result column="activity_name" property="activityName" jdbcType="INTEGER" /> 8 <result column="activity_name" property="activityName" jdbcType="INTEGER" />
8 <result column="activity_item_id" property="activityItemId" jdbcType="INTEGER" /> 9 <result column="activity_item_id" property="activityItemId" jdbcType="INTEGER" />
9 <result column="promote_uid" property="promoteUid" jdbcType="INTEGER" /> 10 <result column="promote_uid" property="promoteUid" jdbcType="INTEGER" />
@@ -15,7 +16,7 @@ @@ -15,7 +16,7 @@
15 <result column="update_time" property="updateTime" jdbcType="INTEGER" /> 16 <result column="update_time" property="updateTime" jdbcType="INTEGER" />
16 </resultMap> 17 </resultMap>
17 <sql id="Base_Column_List" > 18 <sql id="Base_Column_List" >
18 - id, activity_id, activity_name, activity_item_id, promote_uid, order_id, amount, status, orders, create_time, 19 + id, activity_id, activity_type, activity_name, activity_item_id, promote_uid, order_id, amount, status, orders, create_time,
19 update_time 20 update_time
20 </sql> 21 </sql>
21 <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" > 22 <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
@@ -29,20 +30,32 @@ @@ -29,20 +30,32 @@
29 <include refid="Base_Column_List" /> 30 <include refid="Base_Column_List" />
30 from union_share_orders_activity_logs 31 from union_share_orders_activity_logs
31 where order_id IN 32 where order_id IN
32 - <foreach collection="ids" item="item" separator="," index="index" open="(" close=")"> 33 + <foreach collection="orderIds" item="item" separator="," index="index" open="(" close=")">
33 #{item} 34 #{item}
34 </foreach> 35 </foreach>
35 </select> 36 </select>
  37 + <select id="selectByOrderId" resultMap="BaseResultMap" >
  38 + select
  39 + <include refid="Base_Column_List" />
  40 + from union_share_orders_activity_logs
  41 + where order_id = #{orderId,jdbcType=INTEGER}
  42 + </select>
  43 + <select id="selectByOrderCode" resultMap="BaseResultMap" >
  44 + select
  45 + <include refid="Base_Column_List" />
  46 + from union_share_orders_activity_logs
  47 + where orders like CONCAT('%', #{orderCode}, '%')
  48 + </select>
36 <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" > 49 <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
37 delete from union_share_orders_activity_logs 50 delete from union_share_orders_activity_logs
38 where id = #{id,jdbcType=INTEGER} 51 where id = #{id,jdbcType=INTEGER}
39 </delete> 52 </delete>
40 <insert id="insert" parameterType="com.yoho.unions.dal.model.UnionShareOrdersActivityLogs" > 53 <insert id="insert" parameterType="com.yoho.unions.dal.model.UnionShareOrdersActivityLogs" >
41 - insert into union_share_orders_activity_logs (id, activity_id, activity_name, activity_item_id, 54 + insert into union_share_orders_activity_logs (id, activity_id,activity_type, activity_name, activity_item_id,
42 promote_uid, order_id, amount, 55 promote_uid, order_id, amount,
43 status, orders, create_time, 56 status, orders, create_time,
44 update_time) 57 update_time)
45 - values (#{id,jdbcType=INTEGER}, #{activityId,jdbcType=INTEGER}, #{activityName,jdbcType=INTEGER}, #{activityItemId,jdbcType=INTEGER}, 58 + values (#{id,jdbcType=INTEGER}, #{activityId,jdbcType=INTEGER},#{activityType,jdbcType=INTEGER}, #{activityName,jdbcType=INTEGER}, #{activityItemId,jdbcType=INTEGER},
46 #{promoteUid,jdbcType=INTEGER}, #{orderId,jdbcType=INTEGER}, #{amount,jdbcType=DECIMAL}, 59 #{promoteUid,jdbcType=INTEGER}, #{orderId,jdbcType=INTEGER}, #{amount,jdbcType=DECIMAL},
47 #{status,jdbcType=INTEGER}, #{orders,jdbcType=VARCHAR}, #{createTime,jdbcType=INTEGER}, 60 #{status,jdbcType=INTEGER}, #{orders,jdbcType=VARCHAR}, #{createTime,jdbcType=INTEGER},
48 #{updateTime,jdbcType=INTEGER}) 61 #{updateTime,jdbcType=INTEGER})
@@ -56,6 +69,9 @@ @@ -56,6 +69,9 @@
56 <if test="activityId != null" > 69 <if test="activityId != null" >
57 activity_id, 70 activity_id,
58 </if> 71 </if>
  72 + <if test="activityType != null" >
  73 + activity_type,
  74 + </if>
59 <if test="activityName != null" > 75 <if test="activityName != null" >
60 activity_name, 76 activity_name,
61 </if> 77 </if>
@@ -91,6 +107,9 @@ @@ -91,6 +107,9 @@
91 <if test="activityId != null" > 107 <if test="activityId != null" >
92 #{activityId,jdbcType=INTEGER}, 108 #{activityId,jdbcType=INTEGER},
93 </if> 109 </if>
  110 + <if test="activityType != null" >
  111 + #{activityType,jdbcType=INTEGER},
  112 + </if>
94 <if test="activityName != null" > 113 <if test="activityName != null" >
95 #{activityName,jdbcType=INTEGER}, 114 #{activityName,jdbcType=INTEGER},
96 </if> 115 </if>
@@ -126,6 +145,9 @@ @@ -126,6 +145,9 @@
126 <if test="activityId != null" > 145 <if test="activityId != null" >
127 activity_id = #{activityId,jdbcType=INTEGER}, 146 activity_id = #{activityId,jdbcType=INTEGER},
128 </if> 147 </if>
  148 + <if test="activityType != null" >
  149 + activity_type = #{activityType,jdbcType=INTEGER},
  150 + </if>
129 <if test="activityName != null" > 151 <if test="activityName != null" >
130 activity_name = #{activityName,jdbcType=INTEGER}, 152 activity_name = #{activityName,jdbcType=INTEGER},
131 </if> 153 </if>
@@ -156,9 +178,16 @@ @@ -156,9 +178,16 @@
156 </set> 178 </set>
157 where id = #{id,jdbcType=INTEGER} 179 where id = #{id,jdbcType=INTEGER}
158 </update> 180 </update>
  181 + <update id="updateStatusByOrderId" parameterType="com.yoho.unions.dal.model.UnionShareOrdersActivityLogs" >
  182 + update union_share_orders_activity_logs
  183 + set status = #{status,jdbcType=INTEGER},
  184 + update_time = #{updateTime,jdbcType=INTEGER}
  185 + where order_id = #{orderId,jdbcType=INTEGER}
  186 + </update>
159 <update id="updateByPrimaryKey" parameterType="com.yoho.unions.dal.model.UnionShareOrdersActivityLogs" > 187 <update id="updateByPrimaryKey" parameterType="com.yoho.unions.dal.model.UnionShareOrdersActivityLogs" >
160 update union_share_orders_activity_logs 188 update union_share_orders_activity_logs
161 set activity_id = #{activityId,jdbcType=INTEGER}, 189 set activity_id = #{activityId,jdbcType=INTEGER},
  190 + activity_type = #{activityType,jdbcType=INTEGER},
162 activity_name = #{activityName,jdbcType=INTEGER}, 191 activity_name = #{activityName,jdbcType=INTEGER},
163 activity_item_id = #{activityItemId,jdbcType=INTEGER}, 192 activity_item_id = #{activityItemId,jdbcType=INTEGER},
164 promote_uid = #{promoteUid,jdbcType=INTEGER}, 193 promote_uid = #{promoteUid,jdbcType=INTEGER},
@@ -26,6 +26,13 @@ @@ -26,6 +26,13 @@
26 from union_share_orders_activity 26 from union_share_orders_activity
27 where id = #{id,jdbcType=INTEGER} 27 where id = #{id,jdbcType=INTEGER}
28 </select> 28 </select>
  29 + <select id="selectByDate" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
  30 + select
  31 + <include refid="Base_Column_List" />
  32 + from union_share_orders_activity
  33 + where status=1 and start_time &lt; #{time,jdbcType=INTEGER} and end_time &gt; #{time,jdbcType=INTEGER}
  34 + order by priority desc
  35 + </select>
29 <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" > 36 <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
30 delete from union_share_orders_activity 37 delete from union_share_orders_activity
31 where id = #{id,jdbcType=INTEGER} 38 where id = #{id,jdbcType=INTEGER}
1 <?xml version="1.0" encoding="UTF-8" ?> 1 <?xml version="1.0" encoding="UTF-8" ?>
2 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > 2 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
3 <mapper namespace="com.yoho.unions.dal.UnionShareOrdersMapper" > 3 <mapper namespace="com.yoho.unions.dal.UnionShareOrdersMapper" >
4 - <resultMap id="BaseResultMap" type="com.yoho.unions.dal.com.yoho.unions.dal.model.UnionShareOrders" > 4 + <resultMap id="BaseResultMap" type="com.yoho.unions.dal.model.UnionShareOrders" >
5 <id column="id" property="id" jdbcType="INTEGER" /> 5 <id column="id" property="id" jdbcType="INTEGER" />
6 <result column="order_code" property="orderCode" jdbcType="VARCHAR" /> 6 <result column="order_code" property="orderCode" jdbcType="VARCHAR" />
7 <result column="settlement_code" property="settlementCode" jdbcType="VARCHAR" /> 7 <result column="settlement_code" property="settlementCode" jdbcType="VARCHAR" />
@@ -72,6 +72,13 @@ @@ -72,6 +72,13 @@
72 where settlement_code = #{settlementCode,jdbcType=VARCHAR} and order_code is not null 72 where settlement_code = #{settlementCode,jdbcType=VARCHAR} and order_code is not null
73 limit #{offset}, #{rows} 73 limit #{offset}, #{rows}
74 </select> 74 </select>
  75 + <select id="selectOrderByCondition" resultMap="BaseResultMap">
  76 + select
  77 + <include refid="Base_Column_List" />
  78 + from union_share_orders
  79 + where settlement_code = #{settlementCode,jdbcType=VARCHAR} and order_code is not null
  80 + limit #{offset}, #{rows}
  81 + </select>
75 <select id="selectIdForActivity" resultType="java.lang.Integer"> 82 <select id="selectIdForActivity" resultType="java.lang.Integer">
76 select id from union_share_orders 83 select id from union_share_orders
77 where settlement_code = #{settlementCode,jdbcType=VARCHAR} and order_code is null 84 where settlement_code = #{settlementCode,jdbcType=VARCHAR} and order_code is null
@@ -80,7 +87,7 @@ @@ -80,7 +87,7 @@
80 delete from union_share_orders 87 delete from union_share_orders
81 where id = #{id,jdbcType=INTEGER} 88 where id = #{id,jdbcType=INTEGER}
82 </delete> 89 </delete>
83 - <insert id="insert" parameterType="com.yoho.unions.dal.model.UnionShareOrders" > 90 + <insert id="insert" useGeneratedKeys="true" keyProperty="id" parameterType="com.yoho.unions.dal.model.UnionShareOrders" >
84 insert into union_share_orders (id, order_code, promote_uid, 91 insert into union_share_orders (id, order_code, promote_uid,
85 order_uid, settlement_code, status, 92 order_uid, settlement_code, status,
86 last_order_amount, order_time, is_new, 93 last_order_amount, order_time, is_new,
@@ -94,7 +101,7 @@ @@ -94,7 +101,7 @@
94 #{activityType,jdbcType=INTEGER}, #{activityId,jdbcType=INTEGER}, #{extraAmount,jdbcType=DECIMAL}, 101 #{activityType,jdbcType=INTEGER}, #{activityId,jdbcType=INTEGER}, #{extraAmount,jdbcType=DECIMAL},
95 #{orderAmount,jdbcType=DECIMAL}) 102 #{orderAmount,jdbcType=DECIMAL})
96 </insert> 103 </insert>
97 - <insert id="insertSelective" parameterType="com.yoho.unions.dal.model.UnionShareOrders" > 104 + <insert id="insertSelective" useGeneratedKeys="true" keyProperty="id" parameterType="com.yoho.unions.dal.model.UnionShareOrders" >
98 insert into union_share_orders 105 insert into union_share_orders
99 <trim prefix="(" suffix=")" suffixOverrides="," > 106 <trim prefix="(" suffix=")" suffixOverrides="," >
100 <if test="id != null" > 107 <if test="id != null" >
@@ -1063,32 +1063,104 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport @@ -1063,32 +1063,104 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
1063 if (result == 0) { 1063 if (result == 0) {
1064 logger.info("saveOrUpdateOrder enter,update nothing,req is {}",bo); 1064 logger.info("saveOrUpdateOrder enter,update nothing,req is {}",bo);
1065 //没有更新到数据,应该有并发更新事件,查询新的再试一下 1065 //没有更新到数据,应该有并发更新事件,查询新的再试一下
1066 - UnionShareOrders unionShareOrdersNew = unionShareOrdersMapper.selectByCode(bo.getOrderCode());  
1067 - if (unionShareOrdersNew == null) { 1066 + unionShareOrders = unionShareOrdersMapper.selectByCode(bo.getOrderCode());
  1067 + if (unionShareOrders == null) {
1068 logger.info("saveOrUpdateOrder end,can not find the orderCode,req is {}",bo); 1068 logger.info("saveOrUpdateOrder end,can not find the orderCode,req is {}",bo);
1069 //查不到数据,不该出现的情况,目前没有硬删数据的途径 1069 //查不到数据,不该出现的情况,目前没有硬删数据的途径
1070 return; 1070 return;
1071 } 1071 }
1072 - if (!checkOrderStatusChangePass(unionShareOrdersNew.getStatus(), bo.getStatus())) { 1072 + if (!checkOrderStatusChangePass(unionShareOrders.getStatus(), bo.getStatus())) {
1073 //订单状态不可变更 1073 //订单状态不可变更
1074 - logger.info("saveOrUpdateOrder end,Second try,status can not be change,oldStatus is {} ,req is {}",unionShareOrdersNew.getStatus(),bo); 1074 + logger.info("saveOrUpdateOrder end,Second try,status can not be change,oldStatus is {} ,req is {}",unionShareOrders.getStatus(),bo);
1075 return; 1075 return;
1076 } 1076 }
1077 - unionShareOrdersMapper.updateStatusById(unionShareOrdersNew.getId(), unionShareOrdersNew.getStatus(), bo.getStatus(), DateUtil.getCurrentTimeSecond()); 1077 + result=unionShareOrdersMapper.updateStatusById(unionShareOrders.getId(), unionShareOrders.getStatus(), bo.getStatus(), DateUtil.getCurrentTimeSecond());
  1078 + }
  1079 + if (result > 0 &&ShareOrdersStatusEnum.isFailOrder(unionShareOrders.getStatus())) {
  1080 + //要作废活动参与记录
  1081 + UnionShareOrdersActivityLogs updateLogs = new UnionShareOrdersActivityLogs();
  1082 + updateLogs.setOrderId(unionShareOrders.getId());
  1083 + updateLogs.setUpdateTime(DateUtil.getCurrentTimeSecond());
  1084 + updateLogs.setStatus(0);//类型:1-有效,0-作废
  1085 + unionShareOrdersActivityLogsMapper.updateStatusByOrderId(updateLogs);
  1086 + //查询是否参与满单返
  1087 + List<UnionShareOrdersActivityLogs> activityLogs=unionShareOrdersActivityLogsMapper.selectByOrderCode(unionShareOrders.getOrderCode());
  1088 + if (CollectionUtils.isNotEmpty(activityLogs)) {
  1089 + //todo 判断满返是否作废
  1090 + }
1078 } 1091 }
1079 //清缓存 1092 //清缓存
1080 clearShareOrderRedis(bo.getPromoteUid()); 1093 clearShareOrderRedis(bo.getPromoteUid());
1081 } 1094 }
1082 1095
  1096 +
1083 //todo 查询进行中的活动 1097 //todo 查询进行中的活动
1084 - private void queryActivity() { 1098 + private List<UnionShareOrdersActivity> queryActivity() {
1085 List<UnionShareOrdersActivity> activities=unionShareOrdersActivityMapper.selectByDate(DateUtil.getCurrentTimeSecond()); 1099 List<UnionShareOrdersActivity> activities=unionShareOrdersActivityMapper.selectByDate(DateUtil.getCurrentTimeSecond());
  1100 + return activities;
1086 } 1101 }
1087 - //todo 查询已参加的活动  
1088 - private void queryUidActivity() {  
1089 - List<UnionShareOrdersActivity> activities=unionShareOrdersActivityMapper.selectByDate(DateUtil.getCurrentTimeSecond()); 1102 + //todo 查询分享人已参加的活动
  1103 + private void queryUidActivity(int uid) {
  1104 +// List<UnionShareOrdersActivity> activities=unionShareOrdersActivityLogsMapper.selectByOrderIds()
1090 } 1105 }
1091 1106
  1107 + //参加活动
  1108 + private boolean participateActivity(UnionShareOrders order,UnionShareOrdersActivity activity) {
  1109 + //1、判断是否符合活动条件
  1110 + //1.1 活动类型:1-订单返利比例升级,2-订单返利翻x倍,3-额外返
  1111 + if (activity.getType() == 3) {
  1112 + //额外返在活动结束后走定时任务
  1113 + return false;
  1114 + }
  1115 + //1.2 是否新人专享 1-是
  1116 + if (activity.getIsNew().intValue() == 1 && !activity.getIsNew().equals(order.getIsNew())) {
  1117 + //活动为新人专享,但是订单不是首单
  1118 + return false;
  1119 + }
  1120 + //2、参加活动
  1121 + //2.1 返利金额计算
  1122 + BigDecimal extraAmount = activity.getAmount();
  1123 + /* if (activity.getType() == 1) {
  1124 + //活动类型:1-订单返利比例升级
  1125 + extraAmount = order.getLastOrderAmount().multiply(new BigDecimal(activity.getPercent()).divide(new BigDecimal(10000))).setScale(2,BigDecimal.ROUND_DOWN);
  1126 + }else */
  1127 + if (activity.getType() == 2) {
  1128 + //活动类型:2-订单返利翻x倍
  1129 + extraAmount = order.getAmount().multiply(new BigDecimal(activity.getPercent()));
  1130 + }
  1131 + if (activity.getAmount().intValue()>0&&extraAmount.compareTo(activity.getAmount())>1) {
  1132 + //订单返利金额高于封顶金额
  1133 + extraAmount = activity.getAmount();
  1134 + }
  1135 + order.setExtraAmount(extraAmount);
  1136 + order.setAmount(order.getAmount().add(extraAmount));
  1137 +
  1138 + //2.2 保存活动日志
  1139 + UnionShareOrdersActivityLogs log = new UnionShareOrdersActivityLogs();
  1140 + BeanUtils.copyProperties(order, log);
  1141 + log.setActivityId(activity.getId());
  1142 + log.setActivityName(activity.getActivityName());
  1143 + log.setCreateTime(DateUtil.getCurrentTimeSecond());
  1144 + log.setUpdateTime(log.getCreateTime());
  1145 + log.setOrderId(order.getId());
  1146 + log.setStatus(1);
  1147 + log.setOrders(order.getOrderCode());
  1148 + log.setId(null);
  1149 + unionShareOrdersActivityLogsMapper.insertSelective(log);
  1150 +
  1151 + //3 更新订单返利金额
  1152 + UnionShareOrders updateOrder = new UnionShareOrders();
  1153 + updateOrder.setId(order.getId());
  1154 + updateOrder.setAmount(order.getAmount());
  1155 + updateOrder.setExtraAmount(order.getExtraAmount());
  1156 + updateOrder.setActivityId(activity.getId());
  1157 + updateOrder.setActivityType(activity.getType());
  1158 + unionShareOrdersMapper.updateByPrimaryKeySelective(updateOrder);
  1159 +
  1160 + //4、返回
  1161 + logger.info("participateActivity success,order is {},activity is {}",order,activity);
  1162 + return true;
  1163 + }
1092 //todo 查询可参加的活动 1164 //todo 查询可参加的活动
1093 private void getActivity() { 1165 private void getActivity() {
1094 1166
@@ -1135,9 +1207,22 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport @@ -1135,9 +1207,22 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
1135 } 1207 }
1136 //返利金额计算小数位两位后舍弃 1208 //返利金额计算小数位两位后舍弃
1137 insertReq.setAmount((bo.getLastOrderAmount().multiply(new BigDecimal(rebatesRatio).divide(new BigDecimal(100)))).setScale(2,BigDecimal.ROUND_DOWN)); 1209 insertReq.setAmount((bo.getLastOrderAmount().multiply(new BigDecimal(rebatesRatio).divide(new BigDecimal(100)))).setScale(2,BigDecimal.ROUND_DOWN));
  1210 + insertReq.setOrderAmount(insertReq.getAmount());
1138 logger.info("insertOrder,orderCode is {},orderAmount is {},rebatesRatio is {},rebates is {}",bo.getOrderCode(),bo.getLastOrderAmount(),rebatesRatio,insertReq.getAmount()); 1211 logger.info("insertOrder,orderCode is {},orderAmount is {},rebatesRatio is {},rebates is {}",bo.getOrderCode(),bo.getLastOrderAmount(),rebatesRatio,insertReq.getAmount());
1139 - 1212 + bo.setAmount(insertReq.getAmount());
1140 unionShareOrdersMapper.insertSelective(insertReq); 1213 unionShareOrdersMapper.insertSelective(insertReq);
  1214 + //活动返利
  1215 + try {
  1216 + List<UnionShareOrdersActivity> activityList = queryActivity();
  1217 + for (UnionShareOrdersActivity a :activityList ) {
  1218 + if(participateActivity(insertReq,a)) {
  1219 + //参加了活动
  1220 + break;
  1221 + }
  1222 + }
  1223 + } catch (Exception e) {
  1224 + logger.warn("insertOrder warn,fail to handle some activities.bo is {}",bo);
  1225 + }
1141 //新增订单商品信息 1226 //新增订单商品信息
1142 bo.getProductList().forEach(p->{ 1227 bo.getProductList().forEach(p->{
1143 try { 1228 try {
@@ -1347,23 +1432,27 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport @@ -1347,23 +1432,27 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
1347 settlementLog.warn("relateSettlementAndOrder end,uid is {},settlementCode is {},totalAmount is {},insert nothing.",uid,settlementCode,totalAmount); 1432 settlementLog.warn("relateSettlementAndOrder end,uid is {},settlementCode is {},totalAmount is {},insert nothing.",uid,settlementCode,totalAmount);
1348 } 1433 }
1349 1434
1350 - Set<String> orderCodes = new HashSet<>(); 1435 +// Set<String> orderCodes = new HashSet<>();
  1436 + List<UnionShareOrdersBo> orderList = new ArrayList<>();//该提现对应的订单
1351 int size = 1000; 1437 int size = 1000;
1352 int page = count % size > 0 ? (count / size) + 1 : count / size; 1438 int page = count % size > 0 ? (count / size) + 1 : count / size;
1353 for (int i = 0; i < page; i++) { 1439 for (int i = 0; i < page; i++) {
1354 int offset = i * size ; 1440 int offset = i * size ;
1355 - List<String> periodOrders = unionShareOrdersMapper.selectOrderCodesByCondition(settlementCode, offset, size); 1441 + List<UnionShareOrders> periodOrders = unionShareOrdersMapper.selectOrderByCondition(settlementCode, offset, size);
1356 if (CollectionUtils.isEmpty(periodOrders) || periodOrders.get(0) == null) { 1442 if (CollectionUtils.isEmpty(periodOrders) || periodOrders.get(0) == null) {
1357 break; 1443 break;
1358 } 1444 }
1359 - orderCodes.addAll(periodOrders); 1445 +// orderCodes.addAll(periodOrders);
  1446 + periodOrders.forEach(o->{
  1447 + UnionShareOrdersBo b = new UnionShareOrdersBo();
  1448 + BeanUtils.copyProperties(o,b);
  1449 + orderList.add(b);
  1450 + });
  1451 +
1360 } 1452 }
  1453 +
  1454 + //查询活动额外返的返利单
1361 List<Integer> ids = unionShareOrdersMapper.selectIdForActivity(settlementCode); 1455 List<Integer> ids = unionShareOrdersMapper.selectIdForActivity(settlementCode);
1362 - if (CollectionUtils.isEmpty(orderCodes)&&CollectionUtils.isEmpty(ids)) {  
1363 - //不该查不到订单  
1364 - settlementLog.warn("relateSettlementAndOrder end,uid is {},settlementCode is {},totalAmount is {},can not find orders and activity.",uid,settlementCode,totalAmount);  
1365 - throw new ServiceException(ServiceError.UNION_SETTLEMENT_CANNOT_FIND_ORDER_ERROR);  
1366 - }  
1367 List<UnionShareOrdersActivityBo> activityBos = new ArrayList<>(); 1456 List<UnionShareOrdersActivityBo> activityBos = new ArrayList<>();
1368 if(CollectionUtils.isNotEmpty(ids)){ 1457 if(CollectionUtils.isNotEmpty(ids)){
1369 List<UnionShareOrdersActivityLogs> activities = unionShareOrdersActivityLogsMapper.selectByOrderIds(ids); 1458 List<UnionShareOrdersActivityLogs> activities = unionShareOrdersActivityLogsMapper.selectByOrderIds(ids);
@@ -1374,15 +1463,21 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport @@ -1374,15 +1463,21 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
1374 activityBos.add(bo); 1463 activityBos.add(bo);
1375 }); 1464 });
1376 } 1465 }
1377 - 1466 + if (CollectionUtils.isEmpty(orderList)&&CollectionUtils.isEmpty(activityBos)) {
  1467 + //不该查不到订单
  1468 + settlementLog.warn("relateSettlementAndOrder end,uid is {},settlementCode is {},totalAmount is {},can not find orders and activity.",uid,settlementCode,totalAmount);
  1469 + throw new ServiceException(ServiceError.UNION_SETTLEMENT_CANNOT_FIND_ORDER_ERROR);
  1470 + }
1378 //清缓存 1471 //清缓存
1379 clearShareOrderRedis(uid); 1472 clearShareOrderRedis(uid);
1380 1473
1381 // 发送取现mq给erp SETTLEMENT_TOPIC 1474 // 发送取现mq给erp SETTLEMENT_TOPIC
1382 ShareSettlementBo bo = new ShareSettlementBo(); 1475 ShareSettlementBo bo = new ShareSettlementBo();
1383 BeanUtils.copyProperties(insertReq,bo); 1476 BeanUtils.copyProperties(insertReq,bo);
1384 - bo.setOrderCodes(orderCodes); 1477 +// bo.setOrderCodes(orderCodes);
  1478 + bo.setOrderList(orderList);
1385 bo.setActivities(activityBos); 1479 bo.setActivities(activityBos);
  1480 + System.out.println(JsonUtil.objectToJSON(bo));
1386 mqLog.info("relateSettlementAndOrder,send mq {} to erp,uid is {},settlementCode is {},bo is {}", SETTLEMENT_TOPIC, uid, settlementCode, bo); 1481 mqLog.info("relateSettlementAndOrder,send mq {} to erp,uid is {},settlementCode is {},bo is {}", SETTLEMENT_TOPIC, uid, settlementCode, bo);
1387 yhProducer.send(SETTLEMENT_TOPIC, bo); 1482 yhProducer.send(SETTLEMENT_TOPIC, bo);
1388 settlementLog.info("relateSettlementAndOrder,send mq {} to erp success,uid is {},settlementCode is {},bo is {}", SETTLEMENT_TOPIC, uid, settlementCode, bo); 1483 settlementLog.info("relateSettlementAndOrder,send mq {} to erp success,uid is {},settlementCode is {},bo is {}", SETTLEMENT_TOPIC, uid, settlementCode, bo);