fanli/src/main/java/com/yeshi/fanli/dao/mybatis/order/UserOrderWeiQuanRecordMapper.java
@@ -1,8 +1,19 @@ package com.yeshi.fanli.dao.mybatis.order; import org.apache.ibatis.annotations.Param; import com.yeshi.fanli.dao.BaseMapper; import com.yeshi.fanli.entity.order.UserOrderWeiQuanRecord; public interface UserOrderWeiQuanRecordMapper extends BaseMapper<UserOrderWeiQuanRecord> { /** * 根据订单信息与用户ID检索 * @param uid * @param tradeId * @param sourceType * @return */ public UserOrderWeiQuanRecord selectByOrderInfoAndUid(@Param("uid") Long uid,@Param("tradeId") String tradeId,@Param("sourceType") int sourceType); } fanli/src/main/java/com/yeshi/fanli/mapping/order/UserOrderWeiQuanRecordMapper.xml
@@ -2,7 +2,8 @@ <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.yeshi.fanli.dao.mybatis.order.UserOrderWeiQuanRecordMapper"> <resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.order.UserOrderWeiQuanRecord"> <resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.order.UserOrderWeiQuanRecord"> <id column="wr_id" property="id" jdbcType="BIGINT"/> <result column="wr_source_type" property="sourceType" jdbcType="INTEGER"/> <result column="wr_trade_id" property="tradeId" jdbcType="VARCHAR"/> @@ -12,13 +13,37 @@ <result column="wr_create_time" property="createTime" jdbcType="TIMESTAMP"/> <result column="wr_update_time" property="updateTime" jdbcType="TIMESTAMP"/> </resultMap> <sql id="Base_Column_List">wr_id,wr_source_type,wr_trade_id,wr_uid,wr_money,wr_state,wr_create_time,wr_update_time</sql> <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">select <include refid="Base_Column_List"/>from yeshi_ec_user_order_weiquan_record where wr_id = #{id,jdbcType=BIGINT} <sql id="Base_Column_List">wr_id,wr_source_type,wr_trade_id,wr_uid,wr_money,wr_state,wr_create_time,wr_update_time </sql> <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long"> select <include refid="Base_Column_List" /> from yeshi_ec_user_order_weiquan_record where wr_id = #{id,jdbcType=BIGINT} </select> <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from yeshi_ec_user_order_weiquan_record where wr_id = #{id,jdbcType=BIGINT}</delete> <insert id="insert" parameterType="com.yeshi.fanli.entity.order.UserOrderWeiQuanRecord" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_user_order_weiquan_record (wr_id,wr_source_type,wr_trade_id,wr_uid,wr_money,wr_state,wr_create_time,wr_update_time) values (#{id,jdbcType=BIGINT},#{sourceType,jdbcType=INTEGER},#{tradeId,jdbcType=VARCHAR},#{uid,jdbcType=BIGINT},#{money,jdbcType=DECIMAL},#{state,jdbcType=INTEGER},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP})</insert> <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.order.UserOrderWeiQuanRecord" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_user_order_weiquan_record <select id="selectByOrderInfoAndUid" resultMap="BaseResultMap"> select <include refid="Base_Column_List" /> from yeshi_ec_user_order_weiquan_record where wr_trade_id =#{tradeId} and wr_source_type=#{sourceType} and wr_uid=#{uid} </select> <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from yeshi_ec_user_order_weiquan_record where wr_id = #{id,jdbcType=BIGINT} </delete> <insert id="insert" parameterType="com.yeshi.fanli.entity.order.UserOrderWeiQuanRecord" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_user_order_weiquan_record (wr_id,wr_source_type,wr_trade_id,wr_uid,wr_money,wr_state,wr_create_time,wr_update_time) values (#{id,jdbcType=BIGINT},#{sourceType,jdbcType=INTEGER},#{tradeId,jdbcType=VARCHAR},#{uid,jdbcType=BIGINT},#{money,jdbcType=DECIMAL},#{state,jdbcType=INTEGER},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP}) </insert> <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.order.UserOrderWeiQuanRecord" useGeneratedKeys="true" keyProperty="id"> insert into yeshi_ec_user_order_weiquan_record <trim prefix="(" suffix=")" suffixOverrides=","> <if test="id != null">wr_id,</if> <if test="sourceType != null">wr_source_type,</if> @@ -28,7 +53,8 @@ <if test="state != null">wr_state,</if> <if test="createTime != null">wr_create_time,</if> <if test="updateTime != null">wr_update_time,</if> </trim>values </trim> values <trim prefix="(" suffix=")" suffixOverrides=","> <if test="id != null">#{id,jdbcType=BIGINT},</if> <if test="sourceType != null">#{sourceType,jdbcType=INTEGER},</if> @@ -40,8 +66,17 @@ <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if> </trim> </insert> <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.order.UserOrderWeiQuanRecord">update yeshi_ec_user_order_weiquan_record set wr_source_type = #{sourceType,jdbcType=INTEGER},wr_trade_id = #{tradeId,jdbcType=VARCHAR},wr_uid = #{uid,jdbcType=BIGINT},wr_money = #{money,jdbcType=DECIMAL},wr_state = #{state,jdbcType=INTEGER},wr_create_time = #{createTime,jdbcType=TIMESTAMP},wr_update_time = #{updateTime,jdbcType=TIMESTAMP} where wr_id = #{id,jdbcType=BIGINT}</update> <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.order.UserOrderWeiQuanRecord">update yeshi_ec_user_order_weiquan_record <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.order.UserOrderWeiQuanRecord">update yeshi_ec_user_order_weiquan_record set wr_source_type = #{sourceType,jdbcType=INTEGER},wr_trade_id = #{tradeId,jdbcType=VARCHAR},wr_uid = #{uid,jdbcType=BIGINT},wr_money = #{money,jdbcType=DECIMAL},wr_state = #{state,jdbcType=INTEGER},wr_create_time = #{createTime,jdbcType=TIMESTAMP},wr_update_time = #{updateTime,jdbcType=TIMESTAMP} where wr_id = #{id,jdbcType=BIGINT} </update> <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.order.UserOrderWeiQuanRecord"> update yeshi_ec_user_order_weiquan_record <set> <if test="sourceType != null">wr_source_type=#{sourceType,jdbcType=INTEGER},</if> <if test="tradeId != null">wr_trade_id=#{tradeId,jdbcType=VARCHAR},</if> @@ -50,6 +85,7 @@ <if test="state != null">wr_state=#{state,jdbcType=INTEGER},</if> <if test="createTime != null">wr_create_time=#{createTime,jdbcType=TIMESTAMP},</if> <if test="updateTime != null">wr_update_time=#{updateTime,jdbcType=TIMESTAMP},</if> </set> where wr_id = #{id,jdbcType=BIGINT} </set> where wr_id = #{id,jdbcType=BIGINT} </update> </mapper> fanli/src/main/java/com/yeshi/fanli/service/impl/order/UserOrderWeiQuanRecordServiceImpl.java
@@ -1,22 +1,30 @@ package com.yeshi.fanli.service.impl.order; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.Date; import java.util.List; import javax.annotation.Resource; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.yeshi.fanli.dao.mybatis.order.UserOrderWeiQuanRecordMapper; import com.yeshi.fanli.dto.HongBaoDTO; import com.yeshi.fanli.entity.bus.user.HongBaoV2; import com.yeshi.fanli.entity.order.CommonOrder; import com.yeshi.fanli.entity.order.HongBaoOrder; import com.yeshi.fanli.entity.order.UserOrderWeiQuanRecord; import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanDrawBack; import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanOrder; import com.yeshi.fanli.service.inter.money.tb.TaoBaoWeiQuanDrawBackService; import com.yeshi.fanli.service.inter.order.CommonOrderService; import com.yeshi.fanli.service.inter.order.HongBaoOrderService; import com.yeshi.fanli.service.inter.order.HongBaoV2Service; import com.yeshi.fanli.service.inter.order.UserOrderWeiQuanRecordService; import com.yeshi.fanli.service.inter.order.tb.TaoBaoWeiQuanOrderService; import com.yeshi.fanli.util.MoneyBigDecimalUtil; import com.yeshi.fanli.util.Constant; @Service public class UserOrderWeiQuanRecordServiceImpl implements UserOrderWeiQuanRecordService { @@ -33,6 +41,12 @@ @Resource private HongBaoV2Service hongBaoV2Service; @Resource private CommonOrderService commonOrderService; @Resource private HongBaoOrderService hongBaoOrderService; @Override public void syncPrevious() { BigDecimal zero = new BigDecimal(0); @@ -47,7 +61,8 @@ List<HongBaoDTO> listV2 = hongBaoV2Service.listByOrderTradeId(orderItemId); for (HongBaoDTO hongBaoV2: listV2) { Long uid = hongBaoV2.getUserInfo().getId(); TaoBaoWeiQuanDrawBack drawBack= taoBaoWeiQuanDrawBackService.selectByOrderItemIdAndUid(orderItemId, uid); TaoBaoWeiQuanDrawBack drawBack = taoBaoWeiQuanDrawBackService.selectByOrderItemIdAndUid(orderItemId, uid); int state = 0; BigDecimal money = null; @@ -62,8 +77,8 @@ if (money == null) { // (维权金额/结算金额) * 返利金额 BigDecimal wqmoney = weiQuanOrder.getMoney(); money = wqmoney.multiply(hongBaoV2.getMoney()) .divide(hongBaoV2.getSettlement(), 2, BigDecimal.ROUND_DOWN); money = wqmoney.multiply(hongBaoV2.getMoney()).divide(hongBaoV2.getSettlement(), 2, BigDecimal.ROUND_DOWN); // 大于返利金额 则等于返利金额 if (money.compareTo(hongBaoV2.getMoney()) > 0) @@ -83,5 +98,50 @@ } } @Transactional(rollbackFor = Exception.class) @Override public void addTaoBaoWeiQuan(TaoBaoWeiQuanOrder order) { if (!order.getState().contains("维权成功")) return; // 查询是否存在红包 CommonOrder commonOrder = commonOrderService.selectBySourceTypeAndTradeId(Constant.SOURCE_TYPE_TAOBAO, order.getOrderItemId()); if (commonOrder == null) return; HongBaoOrder hongBaoOrder = hongBaoOrderService.selectDetailByCommonOrderId(commonOrder.getId()); if (hongBaoOrder == null || hongBaoOrder.getHongBaoV2() == null) return; BigDecimal settleMoney = hongBaoOrder.getCommonOrder().getSettlement(); HongBaoV2 mainHongBao = hongBaoOrder.getHongBaoV2(); UserOrderWeiQuanRecord ur = userOrderWeiQuanRecordMapper.selectByOrderInfoAndUid( mainHongBao.getUserInfo().getId(), order.getOrderItemId(), Constant.SOURCE_TYPE_TAOBAO); if (ur == null) { UserOrderWeiQuanRecord record = new UserOrderWeiQuanRecord(); record.setCreateTime(new Date()); record.setMoney(hongBaoOrder.getHongBaoV2().getMoney().multiply(order.getMoney()).divide(settleMoney, 2, RoundingMode.UP)); record.setSourceType(Constant.SOURCE_TYPE_TAOBAO); record.setState(0); record.setTradeId(order.getOrderItemId()); record.setUid(hongBaoOrder.getHongBaoV2().getUserInfo().getId()); userOrderWeiQuanRecordMapper.insertSelective(record); } List<HongBaoV2> children = hongBaoV2Service.listChildrenById(mainHongBao.getId()); for (HongBaoV2 v2 : children) { UserOrderWeiQuanRecord record = userOrderWeiQuanRecordMapper.selectByOrderInfoAndUid( v2.getUserInfo().getId(), order.getOrderItemId(), Constant.SOURCE_TYPE_TAOBAO); if (record == null) { record = new UserOrderWeiQuanRecord(); record.setCreateTime(new Date()); record.setMoney(v2.getMoney().multiply(order.getMoney()).divide(settleMoney, 2, RoundingMode.UP)); record.setSourceType(Constant.SOURCE_TYPE_TAOBAO); record.setState(0); record.setTradeId(order.getOrderItemId()); record.setUid(v2.getUserInfo().getId()); userOrderWeiQuanRecordMapper.insertSelective(record); } } } } fanli/src/main/java/com/yeshi/fanli/service/impl/order/tb/TaoBaoWeiQuanOrderServiceImpl.java
@@ -13,6 +13,7 @@ import com.yeshi.fanli.entity.order.CommonOrder; import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanOrder; import com.yeshi.fanli.service.inter.order.CommonOrderService; import com.yeshi.fanli.service.inter.order.UserOrderWeiQuanRecordService; import com.yeshi.fanli.service.inter.order.msg.MsgOrderDetailService; import com.yeshi.fanli.service.inter.order.msg.UserOrderMsgNotificationService; import com.yeshi.fanli.service.inter.order.tb.TaoBaoWeiQuanOrderService; @@ -31,6 +32,9 @@ @Resource private CommonOrderService commonOrderService; @Resource private UserOrderWeiQuanRecordService userOrderWeiQuanRecordService; @Override public void addWeiQuanOrder(TaoBaoWeiQuanOrder order) { @@ -65,6 +69,7 @@ updateCommonOrder.setState(CommonOrder.STATE_WQ); updateCommonOrder.setUpdateTime(new Date()); commonOrderService.updateByPrimaryKeySelective(updateCommonOrder); userOrderWeiQuanRecordService.addTaoBaoWeiQuan(taoBaoWeiQuanOrder); } List<MsgOrderDetail> msgList = msgOrderDetailService.listMsgOrderByOrderId(order.getOrderId()); fanli/src/main/java/com/yeshi/fanli/service/inter/order/UserOrderWeiQuanRecordService.java
@@ -1,5 +1,7 @@ package com.yeshi.fanli.service.inter.order; import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanOrder; public interface UserOrderWeiQuanRecordService { /** @@ -7,4 +9,11 @@ */ public void syncPrevious(); /** * 添加淘宝维权 * * @param order */ public void addTaoBaoWeiQuan(TaoBaoWeiQuanOrder order); }