华南城小程序修改

1 个父辈 754854d0
<?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.w1hd.zzhnc.dao.LotteryLogDao">
<select id="getLotteryLogList" resultType="com.w1hd.zzhnc.vo.Lotterylog_Vo">
select a.*,b.nickname,b.logo from lotterylog a
left join fans b on a.fansid=b.id
<where>
<if test="status != null">
and a.status=#{status}
</if>
<if test="keyword !=null and keyword!='' ">
and b.nickname like CONCAT(CONCAT('%',#{keyword}),'%')
</if>
<if test="turn != null and turn>0">
and a.turn=#{turn}
</if>
</where>
<select id="getLotteryLogList" resultType="com.w1hd.zzhnc.vo.Lotterylog_Vo">
select a.*,b.nickname,b.logo from lotterylog a
left join fans b on a.fansid=b.id
<where>
<if test="status != null">
and a.status=#{status}
</if>
<if test="keyword !=null and keyword!='' ">
and (b.nickname like CONCAT(CONCAT('%',#{keyword}),'%') or a.prize_name
like CONCAT(CONCAT('%',#{keyword}),'%') )
</if>
<if test="turn != null and turn>0">
and a.turn=#{turn}
</if>
<if test="type !=null and type >0">
and a.mny > 0
</if>
</where>
ORDER BY a.createdtime desc
limit #{0},#{1}
</select>
<select id="getLotteryLogCount" resultType="java.lang.Integer">
select count(*) from lotterylog
<where>
<if test="status != null">
and status=#{status}
</if>
<if test="turn != null and turn>0">
and turn=#{turn}
</if>
</where>
</select>
<select id="getSumMny" resultType="java.math.BigDecimal">
select sum(mny) from lotterylog
<where>
<if test="status != null">
and status=#{status}
</if>
<if test="turn != null and turn>0">
and turn=#{turn}
</if>
</where>
</select>
</select>
<select id="getLotteryLogCount" resultType="java.lang.Integer">
select count(*) from lotterylog
<where>
<if test="status != null">
and status=#{status}
</if>
<if test="turn != null and turn>0">
and turn=#{turn}
</if>
<if test="type !=null and type >0">
and mny > 0
</if>
</where>
</select>
<select id="getSumMny" resultType="java.math.BigDecimal">
select sum(mny) from lotterylog
<where>
<if test="status != null">
and status=#{status}
</if>
<if test="turn != null and turn>0">
and turn=#{turn}
</if>
</where>
</select>
</mapper>
\ No newline at end of file
......@@ -117,10 +117,11 @@ public class ActivityController extends BaseController {
@RequestMapping(value = "/lotterys", method = { RequestMethod.POST, RequestMethod.GET })
@ResponseBody
public Object lotterys(@RequestParam(value = "page", defaultValue = "1", required = false) Integer page,
@RequestParam(value = "pagesize", defaultValue = "10", required = false) Integer pagesize,
@RequestParam(value = "pagesize", defaultValue = "20", required = false) Integer pagesize,
@RequestParam(value = "turn", defaultValue = "0", required = false) Integer turn,
@RequestParam(value = "keyword", defaultValue = "", required = false) String keyword,
@RequestParam(value = "status", required = false) Integer status) {
return new Vo_msg(0, activityService.getLotteryLogList(page, pagesize, turn, keyword, status));
@RequestParam(value = "status", required = false) Integer status,
@RequestParam(value = "type", required = false) Integer type) {
return new Vo_msg(0, activityService.getLotteryLogList(page, pagesize, turn, keyword, status,type));
}
}
......@@ -17,7 +17,9 @@ public class FansController {
FansService fansService;
@RequestMapping(value="/search",method= RequestMethod.GET)
public Object search(@RequestParam(value="page",defaultValue ="1")int page,@RequestParam(value="keyword",required=false) String keyword) {
return fansService.getFansList(page, keyword);
public Object search(@RequestParam(value="page",defaultValue ="1")int page,
@RequestParam(value="keyword",required=false) String keyword,
@RequestParam(value = "size", required = false, defaultValue = "20") Integer size) {
return fansService.getFansList(page, keyword,size);
}
}
......@@ -51,7 +51,7 @@ public class GoodsController {
@RequestParam(value="id",required=false,defaultValue = "0")Integer id,
@RequestParam(value="sellerId",required=false,defaultValue = "0")Integer sellerId,
@RequestParam(value="page",required=false,defaultValue = "1")Integer page,
@RequestParam(value="size",required=false,defaultValue = "10")Integer size,
@RequestParam(value="size",required=false,defaultValue = "20")Integer size,
@RequestParam(value="sort",required=false,defaultValue = "1")Integer sort) {
return new Vo_msg(0,goodsService.seacrh(id,key,sellerId,page,size,sort));
}
......
......@@ -33,6 +33,7 @@ import org.theyeasy.weixin.util.WxMiniUtil;
import com.beust.jcommander.internal.Maps;
import com.w1hd.zzhnc.controller.pc.BaseController;
import com.w1hd.zzhnc.dao.LotteryLogDao;
import com.w1hd.zzhnc.enums.ActivityStatus;
import com.w1hd.zzhnc.enums.ChatLogReplyType;
import com.w1hd.zzhnc.model.Activity;
import com.w1hd.zzhnc.model.Articles;
......@@ -333,8 +334,24 @@ public class WxMiniController extends BaseController {
@RequestMapping(value = "/prizes/kill", method = RequestMethod.GET)
@ResponseBody
public Object prizesKill(@RequestParam(value = "openId") String openId) {
String key = "prizeskill_openid_" + openId;
if (redisTemplate.hasKey(key)) {
System.out.println("注意:重复抽奖");
return new Vo_msg(-1, null, "本次活动已结束~请期待下次抽奖活动");
}
redisTemplate.opsForValue().set(key,1L);
redisTemplate.expire(key, 3, TimeUnit.SECONDS);
Fans fans = fansService.getFansByMiniOpenid(openId);
Activity activity = activityService.getActivitySetting();
if(activity.getStatus() != ActivityStatus.RUNNING.getIndex() ) {
if(activity.getStatus() == ActivityStatus.FINISH.getIndex()) {
new Vo_msg(-1, null, "活动已经结束了");
}else {
new Vo_msg(-1, null, "活动还没有开始");
}
}
String city = activity.getCity();
// 粉丝城市
String fansCity = fans.getCity();
......@@ -345,12 +362,22 @@ public class WxMiniController extends BaseController {
String msg = "红包活动仅限【" + city + "】,您的城市【" + fansCity + "】不在本次活动范围内,不能参与抽奖哦~~";
return new Vo_msg(-1, null, msg);
}
int compareTo = activity.getPlanMny().compareTo(activity.getCurrentMny());
if(compareTo<0) {
return new Vo_msg(-1, null, "本次活动已结束~请期待下次抽奖活动");
}
// 指定城市范围
Integer changes = prizeService.changes(fans.getId());
if (changes > 0) {
Integer logId = prizeService.randomKill(fans.getId(), 0);
Lotterylog log = prizeService.getLog(logId);
return new Vo_msg(0, log);
if(logId<0) {
return new Vo_msg(-1, null, "系统繁忙,请稍后再试");
}else {
Lotterylog log = prizeService.getLog(logId);
return new Vo_msg(0, log);
}
}
return new Vo_msg(-1, null, "你没有抽奖机会了");
......@@ -364,6 +391,7 @@ public class WxMiniController extends BaseController {
if (compareTo < 0) {
return new Vo_msg(-1, 0, "活动还没开始");
}
Fans fans = fansService.getFansByMiniOpenid(openId);
Integer changes = prizeService.changes(fans.getId());
if (changes < 0) {
......
......@@ -13,9 +13,9 @@ import com.w1hd.zzhnc.vo.Lotterylog_Vo;
public interface LotteryLogDao extends MyMapper<Lotterylog> {
List<Lotterylog_Vo> getLotteryLogList(Integer page,Integer pagesize,@Param("turn") Integer turn,
@Param("keyword")String keyword,@Param("status")Integer status);
@Param("keyword")String keyword,@Param("status")Integer status,@Param("type")Integer type);
int getLotteryLogCount(@Param("turn") Integer turn,@Param("status")Integer status);
int getLotteryLogCount(@Param("turn") Integer turn,@Param("status")Integer status,@Param("type")Integer type);
BigDecimal getSumMny(@Param("turn") Integer turn,@Param("status")Integer status);
}
......@@ -87,11 +87,11 @@ public class ActivityService {
}
public PageResults<Lotterylog_Vo> getLotteryLogList(Integer page, Integer pagesize, Integer turn, String keyword,
Integer status) {
Integer status,Integer type) {
PageResults<Lotterylog_Vo> pageResults = new PageResults<>();
List<Lotterylog_Vo> list = logDao.getLotteryLogList((page - 1) * pagesize, pagesize, turn, keyword, status);
int total = logDao.getLotteryLogCount(turn, status);
List<Lotterylog_Vo> list = logDao.getLotteryLogList((page - 1) * pagesize, pagesize, turn, keyword, status,type);
int total = logDao.getLotteryLogCount(turn, status,type);
BigDecimal bMny = logDao.getSumMny(turn, status);
double mny = bMny == null ? 0 : bMny.doubleValue();
if (status!=null && status == 2) {
......
......@@ -35,18 +35,19 @@ public class FansService {
@Autowired
FansDao fansDao;
public PageResults<Fans> getFansList(Integer page, String keyword) {
public PageResults<Fans> getFansList(Integer page, String keyword,Integer pageSize) {
Example ex = new Example(Fans.class);
Criteria criteria = ex.createCriteria();
if (!Strings.isNullOrEmpty(keyword)) {
criteria.andCondition(" ( nickname like \"%" + keyword + "%\")");
}
RowBounds row = new RowBounds((page - 1) * 10, 10);
ex.setOrderByClause("id desc");
RowBounds row = new RowBounds((page - 1) * 10, pageSize);
List<Fans> list = fansDao.selectByExampleAndRowBounds(ex, row);
int total = fansDao.selectCountByExample(ex);
PageResults<Fans> pageresult = new PageResults<>();
pageresult.setPage(page);
pageresult.setPageSize(10);
pageresult.setPageSize(pageSize);
pageresult.setRows(list);
pageresult.setTotal(total);
return pageresult;
......
......@@ -85,7 +85,7 @@ public class PrizeService {
@Transactional
public Integer insert(Integer fansId, Integer pType, BigDecimal mny, Integer status) throws Exception {
Activity setting = activityService.getActivitySetting();
System.out.println("中奖id号:" + pType);
System.out.println("中奖id号:" + pType + "粉丝id:" + fansId);
Prize p = prizeDao.selectByPrimaryKey(pType);
p.setNum(p.getNum() - 1);
prizeDao.updateByPrimaryKeySelective(p);
......@@ -112,7 +112,7 @@ public class PrizeService {
if ("fail".equals(order)) {
lotterylog.setStatus(3);
}
}
}
......@@ -210,7 +210,10 @@ public class PrizeService {
}
int changes = fansCount / shareCount;
changes = changes - lotteryCount;
changes = changes + 1;
if (shareCount == 1) {
changes = changes + 1;
}
if (changes > MAX_CHANGES) {
changes = MAX_CHANGES;
}
......@@ -220,19 +223,24 @@ public class PrizeService {
@SuppressWarnings("unchecked")
public Integer randomKill(Integer fansId, Integer count) {
if (fansId <= 10) {
Integer changes = (Integer) redisTemplate.opsForValue().get(PRIZE_KILL_FANSID_COUNT + fansId);
if (changes == null) {
changes = 99;
}
changes--;
redisTemplate.opsForValue().set(PRIZE_KILL_FANSID_COUNT + fansId, changes);
}
// if (fansId <= 10) {
// Integer changes = (Integer)
// redisTemplate.opsForValue().get(PRIZE_KILL_FANSID_COUNT + fansId);
// if (changes == null) {
// changes = 99;
// }
// changes--;
// redisTemplate.opsForValue().set(PRIZE_KILL_FANSID_COUNT + fansId, changes);
// }
if (count == 8) {
return 0;
}
redisTemplate.delete(PRIZE_KILL_FANSID + fansId);
if (redisTemplate.hasKey(PRIZE_KILL_FANSID + fansId)) {
Integer id = (Integer) redisTemplate.opsForValue().get(PRIZE_KILL_FANSID + fansId);
return -1;
}
int nextInt = RandomUtils.nextInt(0, 100);
System.out.println("幸运数字 ---》》》" + nextInt);
int sumNum = 0;
......@@ -254,13 +262,15 @@ public class PrizeService {
System.out.println("随机数大于总的中奖概率 随机数:" + nextInt + ",中奖总概率" + sumPro);
if (tmp != null) {
try {
logId = insert(fansId, tmp.getId(), new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP), 3);
logId = insert(fansId, tmp.getId(), new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP),
3);
} catch (Exception e) {
e.printStackTrace();
return 1;
return -1;
}
}
} else {
int probability = 0;
for (Prize e : prizeList) {
......@@ -269,10 +279,24 @@ public class PrizeService {
mny = RandomUtils.nextInt(e.getMixMoney(), e.getMaxMoney());
}
try {
RedisUtil.incr(PRIZE_KILL_FANSID_COUNT + fansId);
String countStr = RedisUtil.get(PRIZE_KILL_FANSID_COUNT + fansId);
if (Strings.isNullOrEmpty(countStr)) {
RedisUtil.set(PRIZE_KILL_FANSID_COUNT + fansId, "1");
} else {
Integer sum = Integer.parseInt(countStr);
System.out.println("当前抽奖次数 >>>>" + sum);
if (sum > 3) {
return -1;
} else {
}
}
logId = insert(fansId, e.getId(), new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP));
} catch (Exception e1) {
e1.printStackTrace();
return 1;
return -1;
}
break;
} else {
......
Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
请先完成此消息的编辑!