Authored by Lixiaodi

增加首次绑定送有货币功能

... ... @@ -111,6 +111,25 @@ public class LotteryController {
return new ApiResponse(respData);
}
/**
* 首次绑定送50有货币
*
* @param userId 用户id
*/
@RequestMapping("/giveBindPrize")
@ResponseBody
public ApiResponse giveBindPrize(Integer userId) {
logger.info("Start giveBindPrize with userId {} ", userId);
checkUserId(userId);
LotteryRespData respData = lotteryService.giveBindPrize(userId);
clearPrize(respData.getPrize());
logger.info("End giveBindPrize with userId {} ", userId);
return new ApiResponse(respData);
}
private void checkLotteryId(Integer lotteryId) {
if (lotteryId == null|| lotteryId <= 0) {
logger.warn("LotteryId is invalid {}", lotteryId);
... ...
package com.yoho.lottery.dal;
import com.yoho.lottery.dal.model.WeixinBindPrize;
import java.util.List;
public interface WeixinBindPrizeMapper {
int deleteByPrimaryKey(Integer id);
int insert(WeixinBindPrize record);
WeixinBindPrize selectByPrimaryKey(Integer id);
WeixinBindPrize selectByUid(Integer uid);
List<WeixinBindPrize> selectAll();
int updateByPrimaryKey(WeixinBindPrize record);
}
\ No newline at end of file
... ...
package com.yoho.lottery.dal.model;
public class WeixinBindPrize {
private Integer id;
private Integer createTime;
private Integer uid;
private String remark;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getCreateTime() {
return createTime;
}
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
public Integer getUid() {
return uid;
}
public void setUid(Integer uid) {
this.uid = uid;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
}
\ No newline at end of file
... ...
<?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.yoho.lottery.dal.WeixinBindPrizeMapper">
<resultMap id="BaseResultMap" type="com.yoho.lottery.dal.model.WeixinBindPrize">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="create_time" jdbcType="INTEGER" property="createTime" />
<result column="uid" jdbcType="INTEGER" property="uid" />
<result column="remark" jdbcType="VARCHAR" property="remark" />
</resultMap>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from weixin_bind_prize
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yoho.lottery.dal.model.WeixinBindPrize">
insert into weixin_bind_prize (id, create_time, uid,
remark)
values (#{id,jdbcType=INTEGER}, #{createTime,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER},
#{remark,jdbcType=VARCHAR})
</insert>
<update id="updateByPrimaryKey" parameterType="com.yoho.lottery.dal.model.WeixinBindPrize">
update weixin_bind_prize
set create_time = #{createTime,jdbcType=INTEGER},
uid = #{uid,jdbcType=INTEGER},
remark = #{remark,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select id, create_time, uid, remark
from weixin_bind_prize
where id = #{id,jdbcType=INTEGER}
</select>
<select id="selectByUid" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select id, create_time, uid, remark
from weixin_bind_prize
where uid = #{uid,jdbcType=INTEGER}
</select>
<select id="selectAll" resultMap="BaseResultMap">
select id, create_time, uid, remark
from weixin_bind_prize
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -52,7 +52,16 @@ public interface ILotteryService {
*/
List<LotteryOrderVO> getValidOrderList(Integer userId, Integer limit, Integer page);
/**
* 首次绑定送有货币
*
* @param userId 用户id
* @return
*/
LotteryRespData giveBindPrize(Integer userId);
boolean hasRealPrize(Prize prize);
LotteryRecord[] getLotteryRecordByIds(List<Integer> ids, int shardFactor);
OrderInfoResponse getOrderInfo(Integer userId, String orderCode);
}
... ...
... ... @@ -40,9 +40,11 @@ import com.yoho.error.exception.ServiceException;
import com.yoho.lottery.dal.LotteryMapper;
import com.yoho.lottery.dal.LotteryRecordMapper;
import com.yoho.lottery.dal.PrizeMapper;
import com.yoho.lottery.dal.WeixinBindPrizeMapper;
import com.yoho.lottery.dal.model.Lottery;
import com.yoho.lottery.dal.model.LotteryRecord;
import com.yoho.lottery.dal.model.Prize;
import com.yoho.lottery.dal.model.WeixinBindPrize;
import com.yoho.product.model.GoodsImagesBo;
import com.yoho.service.model.order.request.OrderDetailRequest;
import com.yoho.service.model.order.request.OrderListRequest;
... ... @@ -67,6 +69,13 @@ public class LotteryServiceImpl implements ILotteryService , ApplicationContextA
private static final int STATE_MULTI = 3;
/** 不符合抽奖条件. */
private static final int STATE_NOT = 4;
/** 首次绑定送有货币成功. */
private static final int STATE_BIND_PRIZE_OK = 5;
/** 首次绑定送有货币失败. */
private static final int STATE_BIND_PRIZE_WRONG = 6;
/** 不是首次绑定. */
private static final int STATE_BIND_PRIZE_BAD = 6;
private static final String MSG_NO_PRIZE = "差一点就中奖啦!";
private static final String MSG_HAVE_PRIZE = "恭喜您,中奖啦!";
... ... @@ -84,6 +93,9 @@ public class LotteryServiceImpl implements ILotteryService , ApplicationContextA
@Resource
private LotteryRecordMapper lotteryRecordMapper;
@Resource
private WeixinBindPrizeMapper weixinBindPrizeMapper;
@Autowired
private SendCouponHelper sendCouponHelper;
... ... @@ -297,6 +309,32 @@ public class LotteryServiceImpl implements ILotteryService , ApplicationContextA
}
}
@Override
public LotteryRespData giveBindPrize(Integer userId) {
WeixinBindPrize prize = weixinBindPrizeMapper.selectByUid(userId);
LotteryRespData state = new LotteryRespData();
if (prize == null) {
logger.info("用户{}首次绑定发送50有货币奖励!", userId);
try {
WeixinBindPrize bindPrize = new WeixinBindPrize();
bindPrize.setUid(userId);
bindPrize.setRemark("用户首次绑定送50有货币");
bindPrize.setCreateTime((int) (System.currentTimeMillis() / 1000));
weixinBindPrizeMapper.insert(bindPrize);
sendCouponHelper.sendYOHOBi(userId, 50);
state.setOrderLotteryCode(STATE_BIND_PRIZE_OK);
} catch (Exception e) {
logger.error("用户{}首次绑定送50有货币出错,msg={}!", userId, e.getMessage());
state.setOrderLotteryCode(STATE_BIND_PRIZE_WRONG);
}
} else {
logger.info("用户{}不是首次绑定,不发送50有货币奖励!", userId);
state.setOrderLotteryCode(STATE_BIND_PRIZE_BAD);
}
return state;
}
@Cacheable(expireTime = CacheKeyAndTime.LOTTERY_USER_LOTTERY)
public LotteryRecord[] getLotteryRecordByIds(List<Integer> ids, int shardFactor) {
if (ids.isEmpty()) {
... ... @@ -556,4 +594,5 @@ public class LotteryServiceImpl implements ILotteryService , ApplicationContextA
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
lotteryService = (ILotteryService) applicationContext.getBean("lotteryServiceImpl");
}
}
... ...
... ... @@ -21,5 +21,6 @@ datasources:
- com.yoho.lottery.dal.WeixinLotteryListMapper
- com.yoho.lottery.dal.WeixinOrderListMapper
- com.yoho.lottery.dal.LotteryRecordMapper
- com.yoho.lottery.dal.WeixinBindPrizeMapper
readOnlyInSlave: true
\ No newline at end of file
... ...
... ... @@ -21,5 +21,6 @@ datasources:
- com.yoho.lottery.dal.WeixinLotteryListMapper
- com.yoho.lottery.dal.WeixinOrderListMapper
- com.yoho.lottery.dal.LotteryRecordMapper
- com.yoho.lottery.dal.WeixinBindPrizeMapper
readOnlyInSlave: ${readOnlyInSlave}
\ No newline at end of file
... ...