华南城修改

1 个父辈 14e5e4a7
...@@ -62,15 +62,6 @@ public class ActivityController extends BaseController { ...@@ -62,15 +62,6 @@ public class ActivityController extends BaseController {
@ResponseBody @ResponseBody
public Object editActivitySetting(@RequestBody Activity activity) { public Object editActivitySetting(@RequestBody Activity activity) {
try { try {
Activity setting = activityService.getActivitySetting();
activity.setP1(setting.getP1());
activity.setP2(setting.getP2());
activity.setP3(setting.getP3());
activity.setP4(setting.getP4());
activity.setP5(setting.getP5());
activity.setP6(setting.getP6());
activity.setP7(setting.getP7());
activity.setP8(setting.getP8());
activityService.updateActivity(activity); activityService.updateActivity(activity);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -98,16 +89,13 @@ public class ActivityController extends BaseController { ...@@ -98,16 +89,13 @@ public class ActivityController extends BaseController {
public Object getActivitySetting() { public Object getActivitySetting() {
Activity activity = activityService.getActivitySetting(); Activity activity = activityService.getActivitySetting();
if (null == activity) { if (null == activity) {
return new Vo_msg(-1, "获取失败,数据为空"); return new Vo_msg(-1, "获取失败,数据为空");
} }
BigDecimal currentMny = lotteryLogDao.getSumMny(activity.getTurn(), 1);
activity.setCurrentMny(currentMny);
activityService.updateActivity(activity);
List<Prize> prizeList = activityService.getPrizeList(); List<Prize> prizeList = activityService.getPrizeList();
Map<String,Object> result = Maps.newHashMap(); Map<String, Object> result = Maps.newHashMap();
result.put("activity", activity); result.put("activity", activity);
result.put("prizeList", prizeList); result.put("prizeList", prizeList);
return new Vo_msg(0, result); return new Vo_msg(0, result);
...@@ -132,7 +120,7 @@ public class ActivityController extends BaseController { ...@@ -132,7 +120,7 @@ public class ActivityController extends BaseController {
@RequestParam(value = "pagesize", defaultValue = "10", required = false) Integer pagesize, @RequestParam(value = "pagesize", defaultValue = "10", 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", defaultValue = "1", required = false) Integer status) { @RequestParam(value = "status", required = false) Integer status) {
return new Vo_msg(0, activityService.getLotteryLogList(page, pagesize, turn, keyword, status)); return new Vo_msg(0, activityService.getLotteryLogList(page, pagesize, turn, keyword, status));
} }
} }
...@@ -3,7 +3,6 @@ package com.w1hd.zzhnc.dao; ...@@ -3,7 +3,6 @@ package com.w1hd.zzhnc.dao;
import com.w1hd.zzhnc.model.Prize; import com.w1hd.zzhnc.model.Prize;
import com.w1hd.zzhnc.util.MyMapper; import com.w1hd.zzhnc.util.MyMapper;
@Deprecated
public interface PrizeDao extends MyMapper<Prize>{ public interface PrizeDao extends MyMapper<Prize>{
} }
...@@ -42,15 +42,6 @@ public class Activity implements Serializable { ...@@ -42,15 +42,6 @@ public class Activity implements Serializable {
private String replyFailed2; // 第2次未中奖的提示语 private String replyFailed2; // 第2次未中奖的提示语
private String replySucceed; // 中奖提示语 private String replySucceed; // 中奖提示语
private String badWordsReply; // 不是赞美万小二时的回复 private String badWordsReply; // 不是赞美万小二时的回复
private Prize p1;
private Prize p2;
private Prize p3;
private Prize p4;
private Prize p5;
private Prize p6;
private Prize p7;
private Prize p8;
public Activity() { public Activity() {
super(); super();
...@@ -148,39 +139,6 @@ public class Activity implements Serializable { ...@@ -148,39 +139,6 @@ public class Activity implements Serializable {
public String getUnLotteryReply() { public String getUnLotteryReply() {
return unLotteryReply; return unLotteryReply;
} }
public Prize getP1() {
return p1;
}
public void setP1(Prize p1) {
this.p1 = p1;
}
public Prize getP2() {
return p2;
}
public void setP2(Prize p2) {
this.p2 = p2;
}
public Prize getP3() {
return p3;
}
public void setP3(Prize p3) {
this.p3 = p3;
}
public Prize getP4() {
return p4;
}
public void setP4(Prize p4) {
this.p4 = p4;
}
public void setUnLotteryReply(String unLotteryReply) { public void setUnLotteryReply(String unLotteryReply) {
...@@ -259,38 +217,6 @@ public class Activity implements Serializable { ...@@ -259,38 +217,6 @@ public class Activity implements Serializable {
this.badWordsReply = badWordsReply; this.badWordsReply = badWordsReply;
} }
public Prize getP5() {
return p5;
}
public void setP5(Prize p5) {
this.p5 = p5;
}
public Prize getP6() {
return p6;
}
public void setP6(Prize p6) {
this.p6 = p6;
}
public Prize getP7() {
return p7;
}
public void setP7(Prize p7) {
this.p7 = p7;
}
public Prize getP8() {
return p8;
}
public void setP8(Prize p8) {
this.p8 = p8;
}
public int getShareCount() { public int getShareCount() {
return shareCount; return shareCount;
} }
......
...@@ -5,13 +5,15 @@ import java.util.Date; ...@@ -5,13 +5,15 @@ import java.util.Date;
import javax.persistence.Id; import javax.persistence.Id;
public class Prize implements Serializable {
public class Prize implements Serializable{
/** /**
* *
*/ */
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Id
private Integer id; private Integer id;
private String name; private String name;
private Integer num = 0; private Integer num = 0;
......
...@@ -52,22 +52,6 @@ public class ActivityService { ...@@ -52,22 +52,6 @@ public class ActivityService {
"zhenzhou", "keyworks", "you'r lose", "replay String of activity finished ", "input title pls", "zhenzhou", "keyworks", "you'r lose", "replay String of activity finished ", "input title pls",
"input subtitle pls", 0, "nochance replay", "waitting...", "welcome", "fail", "success", "input subtitle pls", 0, "nochance replay", "waitting...", "welcome", "fail", "success",
"undefind"); "undefind");
Prize prize = new Prize();
prize.setIsMoney(true);
prize.setMaxMoney(200);
prize.setMixMoney(100);
prize.setName("这个是红包奖品");
prize.setNum(10);
prize.setProbability(20);
Prize prize2 = new Prize();
prize2.setIsMoney(false);
prize2.setMaxMoney(0);
prize2.setMixMoney(0);
prize2.setName("这个可能是实物奖品");
prize2.setNum(10);
prize2.setProbability(20);
redisactivity.setP1(prize);
redisactivity.setP2(prize2);
redisTemplate.opsForValue().set(ACTIVITY_SETTING, redisactivity); redisTemplate.opsForValue().set(ACTIVITY_SETTING, redisactivity);
} }
...@@ -85,11 +69,6 @@ public class ActivityService { ...@@ -85,11 +69,6 @@ public class ActivityService {
public String clearActivity() { public String clearActivity() {
Activity activity = getActivitySetting(); Activity activity = getActivitySetting();
activity.setTurn(activity.getTurn() + 1); activity.setTurn(activity.getTurn() + 1);
Prize prize = new Prize();
activity.setP1(prize);
activity.setP2(prize);
activity.setP3(prize);
activity.setP4(prize);
activity.setPlanMny(new BigDecimal(0)); activity.setPlanMny(new BigDecimal(0));
activity.setStatus(0); activity.setStatus(0);
updateActivity(activity); updateActivity(activity);
...@@ -115,7 +94,9 @@ public class ActivityService { ...@@ -115,7 +94,9 @@ public class ActivityService {
int total = logDao.getLotteryLogCount(turn, status); int total = logDao.getLotteryLogCount(turn, status);
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) {
updateCurrentMny(bMny);
}
pageResults.setPage(page); pageResults.setPage(page);
pageResults.setPageSize(pagesize); pageResults.setPageSize(pagesize);
pageResults.setRows(list); pageResults.setRows(list);
...@@ -136,51 +117,16 @@ public class ActivityService { ...@@ -136,51 +117,16 @@ public class ActivityService {
} }
public void updateActivityPrize(Integer type, Prize prize) { public void updateActivityPrize(Integer type, Prize prize) {
Activity setting = getActivitySetting();
prize.setId(type); prize.setId(type);
switch (type) { prizeService.update(prize);
case 1:
setting.setP1(prize);
break;
case 2:
setting.setP2(prize);
break;
case 3:
setting.setP3(prize);
break;
case 4:
setting.setP4(prize);
break;
case 5:
setting.setP5(prize);
break;
case 6:
setting.setP6(prize);
break;
case 7:
setting.setP7(prize);
break;
case 8:
setting.setP8(prize);
break;
default:
break;
}
updateActivity(setting);
} }
@Autowired
PrizeService prizeService;
public List<Prize> getPrizeList() { public List<Prize> getPrizeList() {
Activity setting = getActivitySetting(); PageResults<Prize> search = prizeService.search(null, 1, 10);
List<Prize> newArrayList = Lists.newArrayList(); return search.getRows();
newArrayList.add(setting.getP1());
newArrayList.add(setting.getP2());
newArrayList.add(setting.getP3());
newArrayList.add(setting.getP4());
newArrayList.add(setting.getP5());
newArrayList.add(setting.getP6());
newArrayList.add(setting.getP7());
newArrayList.add(setting.getP8());
return newArrayList;
} }
@Autowired @Autowired
......
...@@ -12,6 +12,7 @@ import org.apache.ibatis.session.RowBounds; ...@@ -12,6 +12,7 @@ import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.testng.collections.Lists; import org.testng.collections.Lists;
import org.testng.util.Strings; import org.testng.util.Strings;
import org.theyeasy.weixin.service.WxMiniService; import org.theyeasy.weixin.service.WxMiniService;
...@@ -81,54 +82,14 @@ public class PrizeService { ...@@ -81,54 +82,14 @@ public class PrizeService {
return prizeDao.deleteByPrimaryKey(id) > 0; return prizeDao.deleteByPrimaryKey(id) > 0;
} }
public Integer insert(Integer fansId, Integer pType, BigDecimal mny, Integer status) { @Transactional
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);
Prize p = null; Prize p = prizeDao.selectByPrimaryKey(pType);
switch (pType) { p.setNum(p.getNum() - 1);
case 1: prizeDao.updateByPrimaryKeySelective(p);
p = setting.getP1();
p.setNum(p.getNum() - 1);
setting.setP1(p);
break;
case 2:
p = setting.getP2();
p.setNum(p.getNum() - 1);
setting.setP2(p);
break;
case 3:
p = setting.getP3();
p.setNum(p.getNum() - 1);
setting.setP4(p);
break;
case 4:
p = setting.getP4();
p.setNum(p.getNum() - 1);
setting.setP4(p);
break;
case 5:
p = setting.getP5();
p.setNum(p.getNum() - 1);
setting.setP5(p);
break;
case 6:
p = setting.getP6();
p.setNum(p.getNum() - 1);
setting.setP6(p);
break;
case 7:
p = setting.getP7();
p.setNum(p.getNum() - 1);
setting.setP7(p);
break;
case 8:
p = setting.getP8();
p.setNum(p.getNum() - 1);
setting.setP8(p);
break;
default:
break;
}
setting.setCurrentMny(setting.getCurrentMny().add(mny)); setting.setCurrentMny(setting.getCurrentMny().add(mny));
activityService.updateActivity(setting); activityService.updateActivity(setting);
Lotterylog lotterylog = new Lotterylog(); Lotterylog lotterylog = new Lotterylog();
...@@ -144,13 +105,14 @@ public class PrizeService { ...@@ -144,13 +105,14 @@ public class PrizeService {
if (mny.doubleValue() >= 1.0) { if (mny.doubleValue() >= 1.0) {
String order = creatOrder(fansId, (int) (mny.doubleValue() * 100)); String order = creatOrder(fansId, (int) (mny.doubleValue() * 100));
System.out.println("抽中一个红包 >" + order); System.out.println("抽中一个红包 >" + order);
lotterylog.setPrizeUrl(order); lotterylog.setPrizeUrl(order);
lotterylog.setMny(mny); lotterylog.setMny(mny);
lotterylog.setStatus(1); lotterylog.setStatus(1);
// Fans fans = fansService.getFansById(fansId); if ("fail".equals(order)) {
lotterylog.setStatus(3);
// activityService.sendRedPackage(fans.getMiniopenid(), (int) (mny.doubleValue() }
// * 100));
} }
} }
...@@ -167,7 +129,7 @@ public class PrizeService { ...@@ -167,7 +129,7 @@ public class PrizeService {
* @return * @return
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Integer insert(Integer fansId, Integer pType, BigDecimal mny) { public Integer insert(Integer fansId, Integer pType, BigDecimal mny) throws Exception {
return insert(fansId, pType, mny, -1); return insert(fansId, pType, mny, -1);
} }
...@@ -249,7 +211,7 @@ public class PrizeService { ...@@ -249,7 +211,7 @@ public class PrizeService {
int changes = fansCount / shareCount; int changes = fansCount / shareCount;
changes = changes - lotteryCount; changes = changes - lotteryCount;
changes = changes + 1; changes = changes + 1;
if(changes>MAX_CHANGES) { if (changes > MAX_CHANGES) {
changes = MAX_CHANGES; changes = MAX_CHANGES;
} }
return changes; return changes;
...@@ -271,7 +233,6 @@ public class PrizeService { ...@@ -271,7 +233,6 @@ public class PrizeService {
return 0; return 0;
} }
redisTemplate.delete(PRIZE_KILL_FANSID + fansId); redisTemplate.delete(PRIZE_KILL_FANSID + fansId);
Activity activity = activityService.getActivitySetting();
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;
...@@ -292,76 +253,37 @@ public class PrizeService { ...@@ -292,76 +253,37 @@ public class PrizeService {
if (nextInt > sumPro) { if (nextInt > sumPro) {
System.out.println("随机数大于总的中奖概率 随机数:" + nextInt + ",中奖总概率" + sumPro); System.out.println("随机数大于总的中奖概率 随机数:" + nextInt + ",中奖总概率" + sumPro);
if (tmp != null) { if (tmp != null) {
if (tmp.getIsMoney()) { try {
mny = RandomUtils.nextInt(tmp.getMixMoney(), tmp.getMaxMoney()); logId = insert(fansId, tmp.getId(), new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP), 3);
} catch (Exception e) {
e.printStackTrace();
return 1;
} }
logId = insert(fansId, tmp.getId(), new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP), 3);
} }
} else { } else {
Prize p8 = activity.getP8(); int probability = 0;
Prize p7 = activity.getP7(); for (Prize e : prizeList) {
Prize p6 = activity.getP6();
Prize p5 = activity.getP5(); if (nextInt < e.getProbability() + probability && e.getNum() > 1) {
Prize p4 = activity.getP4(); if (e.getIsMoney()) {
Prize p3 = activity.getP3(); mny = RandomUtils.nextInt(e.getMixMoney(), e.getMaxMoney());
Prize p2 = activity.getP2(); }
Prize p1 = activity.getP1(); try {
logId = insert(fansId, e.getId(), new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP));
if (p1 != null && nextInt < p1.getProbability() && p1.getNum() > 1) { } catch (Exception e1) {
if (p1.getIsMoney()) { e1.printStackTrace();
mny = RandomUtils.nextInt(p1.getMixMoney(), p1.getMaxMoney()); return 1;
} }
logId = insert(fansId, 1, new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP)); break;
} else if (p2 != null && nextInt < (p2.getProbability() + p1.getProbability()) && p2.getNum() > 1) { } else {
if (p2.getIsMoney()) { System.out.println("不中奖,当前总概率" + probability);
mny = RandomUtils.nextInt(p2.getMixMoney(), p2.getMaxMoney()); probability += e.getProbability();
}
logId = insert(fansId, 2, new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP));
} else if (p3 != null && nextInt < (p3.getProbability() + p2.getProbability() + p1.getProbability())
&& p3.getNum() > 1) {
if (p3.getIsMoney()) {
mny = RandomUtils.nextInt(p3.getMixMoney(), p3.getMaxMoney());
}
logId = insert(fansId, 3, new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP));
} else if (p4 != null
&& nextInt < (p4.getProbability() + p3.getProbability() + p2.getProbability() + p1.getProbability())
&& p4.getNum() > 1) {
if (p4.getIsMoney()) {
mny = RandomUtils.nextInt(p4.getMixMoney(), p4.getMaxMoney());
}
logId = insert(fansId, 4, new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP));
} else if (p5 != null && nextInt < (p5.getProbability() + p4.getProbability() + p3.getProbability()
+ p2.getProbability() + p1.getProbability()) && p5.getNum() > 1) {
if (p5.getIsMoney()) {
mny = RandomUtils.nextInt(p5.getMixMoney(), p5.getMaxMoney());
}
logId = insert(fansId, 5, new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP));
} else if (p6 != null && nextInt < (p6.getProbability() + p5.getProbability() + p4.getProbability()
+ p3.getProbability() + p2.getProbability() + p1.getProbability()) && p6.getNum() > 1) {
if (p6.getIsMoney()) {
mny = RandomUtils.nextInt(p6.getMixMoney(), p6.getMaxMoney());
}
logId = insert(fansId, 6, new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP));
} else if (p7 != null && nextInt < (p7.getProbability() + p6.getProbability() + p5.getProbability()
+ p4.getProbability() + p3.getProbability() + p2.getProbability() + p1.getProbability())
&& p7.getNum() > 1) {
if (p7.getIsMoney()) {
mny = RandomUtils.nextInt(p7.getMixMoney(), p7.getMaxMoney());
}
logId = insert(fansId, 7, new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP));
} else if (p8 != null
&& nextInt < (p8.getProbability() + p7.getProbability() + p6.getProbability() + p5.getProbability()
+ p4.getProbability() + p3.getProbability() + p2.getProbability() + p1.getProbability())
&& p8.getNum() > 1) {
if (p8.getIsMoney()) {
mny = RandomUtils.nextInt(p7.getMixMoney(), p7.getMaxMoney());
}
logId = insert(fansId, 8, new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP));
} else {
if (sumNum > 0) {
return randomKill(fansId, count++);
} }
} }
if (logId == 0 && sumNum > 0) {
return randomKill(fansId, count++);
}
} }
redisTemplate.opsForValue().set(PRIZE_KILL_FANSID + fansId, logId); redisTemplate.opsForValue().set(PRIZE_KILL_FANSID + fansId, logId);
......
package org.theyeasy.weixin.util; package org.theyeasy.weixin.util;
import java.util.ArrayList;
import java.util.List;
import com.google.common.collect.Lists;
import com.w1hd.zzhnc.model.Activity; import com.w1hd.zzhnc.model.Activity;
import com.w1hd.zzhnc.model.Prize;
public class ActivitySettingUtils { public class ActivitySettingUtils {
private int max; private int max;
...@@ -28,25 +23,4 @@ public class ActivitySettingUtils { ...@@ -28,25 +23,4 @@ public class ActivitySettingUtils {
return instance; return instance;
} }
public List<Prize> getPrizes() {
ArrayList<Prize> list = Lists.newArrayList();
if (act.getP1() != null) {
list.add(act.getP1());
max += act.getP1().getProbability();
}
if (act.getP2() != null) {
list.add(act.getP2());
max += act.getP2().getProbability();
}
if (act.getP3() != null) {
list.add(act.getP3());
max += act.getP3().getProbability();
}
if (act.getP4() != null) {
list.add(act.getP4());
max += act.getP4().getProbability();
}
return list;
}
} }
Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
请先完成此消息的编辑!