yujian
2019-10-28 9319c42fe02d041cee260ca0db8df67bcdf1ea0a
免单券激活方式调整
5个文件已修改
4个文件已添加
348 ■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/UserCouponControllerV2.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/user/UserSystemCouponActivateMapper.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/user/UserSystemCouponMapper.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/user/UserSystemCouponActivateMapper.xml 50 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/user/UserSystemCouponMapper.xml 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserSystemCouponActivateServiceImpl.java 60 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserSystemCouponServiceImpl.java 172 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/user/UserSystemCouponActivateService.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/user/UserSystemCouponService.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/UserCouponControllerV2.java
@@ -110,7 +110,7 @@
    
            long count = UserSystemCouponService.countUserCouponList(uid);
            
            List<UserSystemCouponVO> resultList = UserSystemCouponService.getCouponList((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, uid);
            List<UserSystemCouponVO> resultList = UserSystemCouponService.getCouponList(acceptData,(page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, uid);
            if (resultList == null) {
                resultList = new ArrayList<UserSystemCouponVO>();
            }
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/user/UserSystemCouponActivateMapper.java
New file
@@ -0,0 +1,17 @@
package com.yeshi.fanli.dao.mybatis.user;
import org.apache.ibatis.annotations.Param;
import com.yeshi.fanli.dao.BaseMapper;
import com.yeshi.fanli.entity.bus.user.UserSystemCouponActivate;
public interface UserSystemCouponActivateMapper extends BaseMapper<UserSystemCouponActivate> {
    /**
     * 添加数量
     * @param id
     * @param count
     */
    void addCount(@Param("id")Long id, @Param("count") Integer count);
}
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/user/UserSystemCouponMapper.java
@@ -122,4 +122,13 @@
     */
    List<UserSystemCoupon> getFreeCouponByType(@Param("uid") Long uid, @Param("type") String type);
    
    /**
     *  查询需要激活的免券
     * @param uid
     * @param source
     * @return
     */
    List<UserSystemCoupon> getNeedActivateFreeCouponByType(@Param("uid") Long uid, @Param("type") String type);
}
fanli/src/main/java/com/yeshi/fanli/mapping/user/UserSystemCouponActivateMapper.xml
New file
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-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.user.UserSystemCouponActivateMapper">
  <resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.bus.user.UserSystemCouponActivate">
    <id column="usca_id" property="id" jdbcType="BIGINT"/>
    <result column="usca_count" property="count" jdbcType="INTEGER"/>
    <result column="usca_state" property="state" jdbcType="INTEGER"/>
    <result column="usca_create_time" property="createTime" jdbcType="TIMESTAMP"/>
    <result column="usca_update_time" property="updateTime" jdbcType="TIMESTAMP"/>
  </resultMap>
  <sql id="Base_Column_List">usca_id,usca_count,usca_state,usca_create_time,usca_update_time</sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">select
    <include refid="Base_Column_List"/>from yeshi_ec_user_system_coupon_activate where usca_id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from yeshi_ec_user_system_coupon_activate where usca_id = #{id,jdbcType=BIGINT}</delete>
  <insert id="insert" parameterType="com.yeshi.fanli.entity.bus.user.UserSystemCouponActivate" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_user_system_coupon_activate (usca_id,usca_count,usca_state,usca_create_time,usca_update_time) values (#{id,jdbcType=BIGINT},#{count,jdbcType=INTEGER},#{state,jdbcType=INTEGER},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP})</insert>
  <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.bus.user.UserSystemCouponActivate" useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_user_system_coupon_activate
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">usca_id,</if>
      <if test="count != null">usca_count,</if>
      <if test="state != null">usca_state,</if>
      <if test="createTime != null">usca_create_time,</if>
      <if test="updateTime != null">usca_update_time,</if>
    </trim>values
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">#{id,jdbcType=BIGINT},</if>
      <if test="count != null">#{count,jdbcType=INTEGER},</if>
      <if test="state != null">#{state,jdbcType=INTEGER},</if>
      <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
      <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.bus.user.UserSystemCouponActivate">update yeshi_ec_user_system_coupon_activate set usca_count = #{count,jdbcType=INTEGER},usca_state = #{state,jdbcType=INTEGER},usca_create_time = #{createTime,jdbcType=TIMESTAMP},usca_update_time = #{updateTime,jdbcType=TIMESTAMP} where usca_id = #{id,jdbcType=BIGINT}</update>
  <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.bus.user.UserSystemCouponActivate">update yeshi_ec_user_system_coupon_activate
    <set>
      <if test="count != null">usca_count=#{count,jdbcType=INTEGER},</if>
      <if test="state != null">usca_state=#{state,jdbcType=INTEGER},</if>
      <if test="createTime != null">usca_create_time=#{createTime,jdbcType=TIMESTAMP},</if>
      <if test="updateTime != null">usca_update_time=#{updateTime,jdbcType=TIMESTAMP},</if>
    </set> where usca_id = #{id,jdbcType=BIGINT}
  </update>
  <select id="addCount">
      UPDATE yeshi_ec_user_system_coupon_activate
      SET usca_count = usca_count + #{count},usca_update_time = NOW()
      WHERE usca_id = #{id}
  </select>
</mapper>
fanli/src/main/java/com/yeshi/fanli/mapping/user/UserSystemCouponMapper.xml
@@ -216,9 +216,17 @@
            separator=",">#{item}</foreach>
  </select>
  
 <select id="getFreeCouponByType" resultMap="BaseResultMap">
  <select id="getFreeCouponByType" resultMap="BaseResultMap">
     SELECT * FROM `yeshi_ec_user_system_coupon` t
    LEFT JOIN `yeshi_ec_system_coupon` c ON t.`usc_coupon_id` = c.`sc_id`
    WHERE t.usc_uid = #{uid} AND c.`sc_type`= #{type} 
  </select>
  <select id="getNeedActivateFreeCouponByType" resultMap="BaseResultMap">
     SELECT * FROM `yeshi_ec_user_system_coupon` t
    LEFT JOIN `yeshi_ec_system_coupon` c ON t.`usc_coupon_id` = c.`sc_id`
    WHERE t.usc_uid = #{uid} AND c.`sc_type`= #{type}  AND (t.usc_state_activate = 0 OR t.usc_state_activate is null)
    ORDER BY usc_id
  </select>
</mapper>
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserSystemCouponActivateServiceImpl.java
New file
@@ -0,0 +1,60 @@
package com.yeshi.fanli.service.impl.user;
import java.util.Date;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.yeshi.fanli.dao.mybatis.user.UserSystemCouponActivateMapper;
import com.yeshi.fanli.entity.bus.user.UserSystemCouponActivate;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.user.UserSystemCouponActivateService;
@Service
public class UserSystemCouponActivateServiceImpl implements UserSystemCouponActivateService{
    @Resource
    private UserSystemCouponActivateMapper userSystemCouponActivateMapper;
    @Resource
    private ConfigService configService;
    @Override
    public boolean addActivateCount(Long cpid, int limitNum) {
        UserSystemCouponActivate coupon = userSystemCouponActivateMapper.selectByPrimaryKey(cpid);
        if (coupon != null) {
            userSystemCouponActivateMapper.addCount(cpid, 1);
            coupon.setCount(coupon.getCount() + 1);
        } else {
            coupon = new UserSystemCouponActivate();
            coupon.setId(cpid);
            coupon.setCount(1);
            coupon.setState(UserSystemCouponActivate.STATE_INIT);
            coupon.setCreateTime(new Date());
            coupon.setUpdateTime(new Date());
            userSystemCouponActivateMapper.insertSelective(coupon);
        }
        // 是否满足激活条件
        Integer state = coupon.getState();
        if (state != UserSystemCouponActivate.STATE_END && coupon.getCount().intValue() >= limitNum) {
            UserSystemCouponActivate record = new UserSystemCouponActivate();
            record.setId(coupon.getId());
            record.setState(UserSystemCouponActivate.STATE_END);
            userSystemCouponActivateMapper.updateByPrimaryKeySelective(record);
            return true;
        }
        return false;
    }
    @Override
    public int getActivateCount(Long id) {
        UserSystemCouponActivate coupon = userSystemCouponActivateMapper.selectByPrimaryKey(id);
        if (coupon != null)
            return coupon.getCount();
        return 0;
    }
}
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserSystemCouponServiceImpl.java
@@ -45,7 +45,6 @@
import com.yeshi.fanli.entity.system.SystemCoupon.CouponTypeEnum;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.exception.money.UserMoneyDetailException;
import com.yeshi.fanli.exception.order.HongBaoException;
import com.yeshi.fanli.exception.user.UserInfoExtraException;
import com.yeshi.fanli.exception.user.UserSystemCouponException;
import com.yeshi.fanli.log.LogHelper;
@@ -66,6 +65,7 @@
import com.yeshi.fanli.service.inter.user.TokenRecordService;
import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.service.inter.user.UserSystemCouponActivateService;
import com.yeshi.fanli.service.inter.user.UserSystemCouponGiveRecordService;
import com.yeshi.fanli.service.inter.user.UserSystemCouponRecordService;
import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
@@ -78,7 +78,6 @@
import com.yeshi.fanli.util.VersionUtil;
import com.yeshi.fanli.util.factory.UserMoneyDetailFactory;
import com.yeshi.fanli.util.factory.msg.MsgOtherSystemGiveDTOFactory;
import com.yeshi.fanli.util.rocketmq.MQTagConstant;
import com.yeshi.fanli.util.rocketmq.MQTopicName;
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
import com.yeshi.fanli.vo.msg.ClientTextStyleVO;
@@ -164,6 +163,10 @@
    @Resource(name = "orderTransactionProducer")
    private TransactionProducer orderTransactionProducer;
    @Resource
    private UserSystemCouponActivateService userSystemCouponActivateService;
    @Override
    public int insertSelective(UserSystemCoupon record) {
@@ -1701,7 +1704,7 @@
    @Transactional
    @Override
    public List<UserSystemCouponVO> getCouponList(long start, int count, Long uid)
    public List<UserSystemCouponVO> getCouponList(AcceptData acceptData, long start, int count, Long uid)
            throws UserSystemCouponException, Exception {
        // 过期券
@@ -1796,15 +1799,12 @@
                        listTip.add("满足条件后,系统将自动激活,并在消息-其它消息中提醒。");
                        userCouponVO.setTips(listTip);
                        userCouponVO.setPopup(true);
                        // 验证是否已累计3单
                        executor.execute(new Runnable() {
                            @Override
                            public void run() {
                                freeCouponActivate(userCouponVO.getId(), uid, userCouponVO.getCreateTime());
                            }
                        });
                        // 统计待激活数量
                        if (VersionUtil.greaterThan_2_0_2(acceptData.getPlatform(), acceptData.getVersion())) {
                            int activateCount = userSystemCouponActivateService.getActivateCount(userCouponVO.getId());
                            String activateNum = configService.get("free_coupon_activate_num");
                            userCouponVO.setCouponEffect("(" + activateCount + "/"+ Integer.parseInt(activateNum) +")待激活");
                        }
                    } else if (CouponTypeEnum.welfareFreeCoupon == type) {
                        jumpBtn = new HashMap<String, Object>();
                        if (inviteCode != null && inviteCode.trim().length() > 0) {
@@ -2079,80 +2079,6 @@
        return userCouponVO;
    }
    /**
     * 免单券激活
     *
     * @param uid
     */
    public void freeCouponActivate(Long id, Long uid, Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long count = commonOrderCountService.countValidOrderByDate(uid, sdf.format(date));
        String activateNum = configService.get("free_coupon_activate_num");
        int num = Integer.parseInt(activateNum);
        if (count >= num) {
            UserSystemCoupon coupon = userSystemCouponMapper.selectByPrimaryKey(id);
            if (coupon == null || coupon.getState() != UserSystemCoupon.STATE_CAN_USE
                    || coupon.getStateActivated() != 0)
                return;
            Date nowDate = new Date();
            Date endTime2 = coupon.getEndTime();
            if (endTime2 != null && endTime2.getTime() <= nowDate.getTime())
                return;
            SystemCoupon systemCoupon = coupon.getSystemCoupon();
            if (systemCoupon == null)
                return;
            systemCoupon = systemCouponService.selectByPrimaryKey(systemCoupon.getId());
            if (systemCoupon == null || systemCoupon.getType() != CouponTypeEnum.freeCoupon)
                return;
            try {
                Integer expiryDay = systemCoupon.getExpiryDay();
                String endDay = DateUtil.plusDay(expiryDay - 1, nowDate);
                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                if (endDay != null && endDay.trim().length() > 0) {
                    endDay += " 23:59:59";
                }
                Date endTime = format.parse(endDay);
                UserSystemCoupon userCoupon = new UserSystemCoupon();
                userCoupon.setId(coupon.getId());
                userCoupon.setStateActivated(1);
                userCoupon.setEndTime(endTime);
                userCoupon.setStartTime(nowDate);
                userCoupon.setUpdateTime(new Date());
                userSystemCouponMapper.updateByPrimaryKeySelective(userCoupon);
                // 赠送记录
                UserSystemCouponGiveRecord giveRecord = userSystemCouponGiveRecordService.getByReceiveId(id);
                if (giveRecord == null)
                    return;
                Long giveUid = giveRecord.getGiveUid();
                UserInfo userInfo = userInfoService.selectByPKey(giveUid);
                if (userInfo == null)
                    return;
                String beiZhu = "请到我的-福利中心中查看";
                SimpleDateFormat sd = new SimpleDateFormat("yyyy.MM.dd HH:mm");
                MsgOtherCouponActivateDTO msgOther = new MsgOtherCouponActivateDTO();
                msgOther.setTitle("免单券激活");
                msgOther.setType("免单券系统已自动激活");
                msgOther.setExplain("满足" + systemCoupon.getActivateDay() + "天内产生" + num + "笔已到账返利订单");
                msgOther.setGiveUser("昵称:" + userInfo.getNickName() + " ID:" + giveUid);
                msgOther.setReceiveTime(sd.format(giveRecord.getReceiveTime()));
                msgOther.setValidityTime(expiryDay + "天");
                userOtherMsgNotificationService.giveCouponActivateMsg(uid, beiZhu, msgOther);
            } catch (Exception e) {
                e.printStackTrace();
                LogHelper.errorDetailInfo(e);
            }
        }
    }
    @Transactional
    @Override
@@ -2496,4 +2422,78 @@
        return userSystemCouponMapper.getFreeCouponByType(uid, type);
    }
    @Override
    @Transactional
    public void activateFreeCoupon(Long uid) {
        List<UserSystemCoupon> list = userSystemCouponMapper.getNeedActivateFreeCouponByType(uid, CouponTypeEnum.freeCoupon.name());
        if (list == null || list.size() == 0)
            return;
        UserSystemCoupon coupon = list.get(0);
        Date nowDate = new Date();
        Date endTime2 = coupon.getEndTime();
        if (endTime2 != null && endTime2.getTime() <= nowDate.getTime())
            return; // 已失效
        SystemCoupon systemCoupon = coupon.getSystemCoupon();
        if (systemCoupon == null)
            return; // 券已不存在
        systemCoupon = systemCouponService.selectByPrimaryKey(systemCoupon.getId());
        if (systemCoupon == null || systemCoupon.getType() != CouponTypeEnum.freeCoupon)
            return; // 券类型不匹配
        // 添加激活数量
        String activateNum = configService.get("free_coupon_activate_num");
        boolean activate = userSystemCouponActivateService.addActivateCount(coupon.getId(), Integer.parseInt(activateNum));
        // 激活券
        if (activate) {
            try {
                Integer expiryDay = systemCoupon.getExpiryDay();
                String endDay = DateUtil.plusDay(expiryDay - 1, nowDate);
                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                if (endDay != null && endDay.trim().length() > 0) {
                    endDay += " 23:59:59";
                }
                Date endTime = format.parse(endDay);
                UserSystemCoupon userCoupon = new UserSystemCoupon();
                userCoupon.setId(coupon.getId());
                userCoupon.setStateActivated(1);
                userCoupon.setEndTime(endTime);
                userCoupon.setStartTime(nowDate);
                userCoupon.setUpdateTime(new Date());
                userSystemCouponMapper.updateByPrimaryKeySelective(userCoupon);
                // 赠送记录
                UserSystemCouponGiveRecord giveRecord = userSystemCouponGiveRecordService.getByReceiveId(coupon.getId());
                if (giveRecord == null)
                    return;
                Long giveUid = giveRecord.getGiveUid();
                UserInfo userInfo = userInfoService.selectByPKey(giveUid);
                if (userInfo == null)
                    return;
                String beiZhu = "请到我的-福利中心中查看";
                SimpleDateFormat sd = new SimpleDateFormat("yyyy.MM.dd HH:mm");
                MsgOtherCouponActivateDTO msgOther = new MsgOtherCouponActivateDTO();
                msgOther.setTitle("免单券激活");
                msgOther.setType("免单券系统已自动激活");
                msgOther.setExplain("满足" + systemCoupon.getActivateDay() + "天内产生" + activateNum + "笔已到账返利订单");
                msgOther.setGiveUser("昵称:" + userInfo.getNickName() + " ID:" + giveUid);
                msgOther.setReceiveTime(sd.format(giveRecord.getReceiveTime()));
                msgOther.setValidityTime(expiryDay + "天");
                userOtherMsgNotificationService.giveCouponActivateMsg(uid, beiZhu, msgOther);
            } catch (Exception e) {
                e.printStackTrace();
                LogHelper.errorDetailInfo(e);
            }
        }
    }
}
fanli/src/main/java/com/yeshi/fanli/service/inter/user/UserSystemCouponActivateService.java
New file
@@ -0,0 +1,20 @@
package com.yeshi.fanli.service.inter.user;
public interface UserSystemCouponActivateService {
    /**
     * 更新待激活数量,并返回是否可以激活
     * @param cpid  用户券id
     * @param num   限制数量
     * @return
     */
    public boolean addActivateCount(Long cpid, int num);
    /**
     * 查询满足条件的数量
     * @param id
     * @return
     */
    public int getActivateCount(Long id);
}
fanli/src/main/java/com/yeshi/fanli/service/inter/user/UserSystemCouponService.java
@@ -238,7 +238,7 @@
     * @throws UserSystemCouponException
     * @throws Exception
     */
    public List<UserSystemCouponVO> getCouponList(long start, int count, Long uid) throws UserSystemCouponException, Exception;
    public List<UserSystemCouponVO> getCouponList(AcceptData acceptData, long start, int count, Long uid) throws UserSystemCouponException, Exception;
    
    /**
@@ -326,4 +326,10 @@
     */
    public List<UserSystemCoupon> getFreeCouponByType(Long uid, String type);
    /**
     * 激活免单券---订单已到账      TODO 待调用
     * @param uid
     */
    public void activateFreeCoupon(Long uid);
}