华南城小程序修改

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