update

1 个父辈 fbd40a9a
mch_appid = wx64e56457ec5c6338
mchid = 1493581312
key = Bnzihl9t8zId5qKL70bmKDuUpPklMpXB
mch_appid = wxbe75806d33ab8a2e
mchid = 1496014382
key = glSPm08OiR82CfXyZ3HQECFeiwS7np5t
spbill_create_ip=127.0.0.1
cert_file=/theyeasy/weixin_cert/zzhnc_apiclient_cert.p12
#cert_file=C:\\weixin_cert\\zzhnc_apiclient_cert.p12
\ No newline at end of file
......@@ -13,6 +13,7 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hslf.record.Sound;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
......@@ -27,6 +28,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.model.Activity;
import com.w1hd.zzhnc.model.Articles;
import com.w1hd.zzhnc.model.Banner;
......@@ -45,6 +47,8 @@ import com.w1hd.zzhnc.util.RedisUtil;
import com.w1hd.zzhnc.vo.Vo_msg;
import com.wordnik.swagger.annotations.ApiOperation;
import tk.mybatis.mapper.entity.Example;
@Controller
@RequestMapping("/wxmini")
public class WxMiniController extends BaseController {
......@@ -317,23 +321,32 @@ public class WxMiniController extends BaseController {
}
@Autowired
LotteryLogDao lotteryLogDao;
/** 中奖 */
@RequestMapping(value = "/prizes/kill", method = RequestMethod.GET)
@ResponseBody
public Object prizesKill(@RequestParam(value = "openId") String openId) {
Fans fans = fansService.getFansByMiniOpenid(openId);
Integer logId = prizeService.randomKill(fans.getId(), 0);
if (logId == 0) {
return new Vo_msg(-1, null, "不好意思你没中奖");
}
if (logId == -1) {
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);
}
Lotterylog log = prizeService.getLog(logId);
return new Vo_msg(0, log);
return new Vo_msg(-1, null, "你没有抽奖机会了");
}
@RequestMapping(value = "/prizes/changes", method = RequestMethod.GET)
@ResponseBody
public Object changes(@RequestParam(value = "openId") String openId) {
Fans fans = fansService.getFansByMiniOpenid(openId);
Integer changes = prizeService.changes(fans.getId());
return new Vo_msg(0, changes);
}
/** 获取奖品列表 */
@RequestMapping(value = "/prizes/all", method = RequestMethod.GET)
@ResponseBody
......@@ -346,14 +359,14 @@ public class WxMiniController extends BaseController {
RedisTemplate<String, Long> redisTemplate;
/** 核销奖品 */
@ApiOperation( value = "二维码地址")
@ApiOperation(value = "二维码地址")
@RequestMapping(value = "/prizes/sqr", method = RequestMethod.GET)
@ResponseBody
public Object scanQr() {
long timeMillis = System.currentTimeMillis();
redisTemplate.opsForValue().set(PRIZE_KEY_TIME + timeMillis, timeMillis);
redisTemplate.expire(PRIZE_KEY_TIME + timeMillis, 300, TimeUnit.SECONDS);
return timeMillis;
return new Vo_msg(0, timeMillis, "这个二维码是真的");
}
/** 核销奖品 */
......
......@@ -20,6 +20,15 @@ public class Lotterylog implements Serializable {
private Integer turn;
private Integer prizeId;
private Date createdtime;
private Date updatetime;
public Date getUpdatetime() {
return updatetime;
}
public void setUpdatetime(Date updatetime) {
this.updatetime = updatetime;
}
public Integer getId() {
return id;
......
......@@ -109,7 +109,7 @@ public class ActivityService {
List<Lotterylog_Vo> list = logDao.getLotteryLogList((page - 1) * pagesize, pagesize, turn, keyword, status);
int total = logDao.getLotteryLogCount(turn, status);
BigDecimal bMny = logDao.getSumMny(turn, status);
int mny = bMny == null ? 0 : bMny.intValue();
double mny = bMny == null ? 0 : bMny.doubleValue();
pageResults.setPage(page);
pageResults.setPageSize(pagesize);
......
......@@ -69,7 +69,7 @@ public class GoodsService {
if ("副食".equals(key) || "小商品".equals(key) || "服装".equals(key) || "汽摩配件".equals(key)) {
c.andEqualTo("categoryName", key);
} else {
c.andCondition(" (description like \"%" + key + "%\" or name like \"%" + key + "%\")");
c.andCondition(" (description like \"%" + key + "%\" or name like \"%" + key +"%\" or seller_name like \"%" + key + "%\" or seller_address like \"%" + key +"%\" )");
}
}
......@@ -79,6 +79,7 @@ public class GoodsService {
}
c.andEqualTo("deleted", false);
ex.setOrderByClause("share_count desc,page_views desc");
RowBounds row = new RowBounds((page - 1) * size, size);
List<Goods> list = goodsDao.selectByExampleAndRowBounds(ex, row);
int count = goodsDao.selectCountByExample(ex);
......
......@@ -16,6 +16,7 @@ import org.testng.util.Strings;
import com.w1hd.zzhnc.dao.LotteryLogDao;
import com.w1hd.zzhnc.dao.PrizeDao;
import com.w1hd.zzhnc.model.Activity;
import com.w1hd.zzhnc.model.Fans;
import com.w1hd.zzhnc.model.Lotterylog;
import com.w1hd.zzhnc.model.Prize;
import com.w1hd.zzhnc.util.PageResults;
......@@ -27,6 +28,8 @@ import tk.mybatis.mapper.entity.Example.Criteria;
@Service
public class PrizeService {
private static final int MAX_CHANGES = 4; // 无条件最大可抽奖次数
final String LotteryLogID_ = RedisUtil.PROJECTNAME.concat("_").concat("lotteryLog_");// 中奖记录
final String PRIZE_KILL_FANSID = RedisUtil.PROJECTNAME.concat("_").concat("PRIZE_KILL_FANSID_");// 保存粉丝中奖的日志
......@@ -162,114 +165,140 @@ public class PrizeService {
public Lotterylog updateLotteryLog(Integer id, Integer fansId) {
Lotterylog lotterylog = lotteryLogDao.selectByPrimaryKey(id);
lotterylog.setStatus(2);
lotterylog.setUpdatetime(new Date());
lotteryLogDao.updateByPrimaryKey(lotterylog);
return lotterylog;
}
@Autowired
FansService fansService;
@Autowired
RedisTemplate redisTemplate;
public Integer changes(Integer fansId) {
Integer lotteryLog = (Integer) redisTemplate.opsForValue().get(PRIZE_KILL_FANSID + fansId);
if (lotteryLog == null) {
return 1;
} else {
Activity activitySetting = activityService.getActivitySetting();
int fansCount = fansService.getCountParentFansId(fansId);
Example ex = new Example(Lotterylog.class);
ex.createCriteria().andEqualTo("fansid", fansId);
int lotteryCount = lotteryLogDao.selectCountByExample(ex);
if (lotteryCount > MAX_CHANGES) {
return 0;
}
int shareCount = activitySetting.getShareCount();
if (shareCount == 0)
shareCount = 1;
int changes = fansCount / shareCount;
changes = changes - lotteryCount;
return changes + 1;
}
}
@SuppressWarnings("unchecked")
public Integer randomKill(Integer fansId, Integer count) {
if (count == 8)
if (count == 8) {
return 0;
Integer lotteryLog = (Integer) redisTemplate.opsForValue().get(PRIZE_KILL_FANSID + fansId);
if (lotteryLog == null) {
Activity activity = activityService.getActivitySetting();
int nextInt = RandomUtils.nextInt(0, 100);
System.out.println("幸运数字 ---》》》" + nextInt);
int sumNum = 0;
int sumPro = 0;
Prize tmp = null;
List<Prize> prizeList = activityService.getPrizeList();
for (Prize p : prizeList) {
if (p != null) {
sumNum += p.getNum();
sumPro += p.getProbability();
if (p.getName().contains("谢谢")) {
tmp = p;
}
}
redisTemplate.delete(PRIZE_KILL_FANSID + fansId);
Activity activity = activityService.getActivitySetting();
int nextInt = RandomUtils.nextInt(0, 100);
System.out.println("幸运数字 ---》》》" + nextInt);
int sumNum = 0;
int sumPro = 0;
Prize tmp = null;
List<Prize> prizeList = activityService.getPrizeList();
for (Prize p : prizeList) {
if (p != null) {
sumNum += p.getNum();
sumPro += p.getProbability();
if (p.getName().contains("谢谢")) {
tmp = p;
}
}
}
int mny = 0;
Integer logId = 0;
if (nextInt > sumPro) {
System.out.println("随机数大于总的中奖概率 随机数:" + nextInt + ",中奖总概率" + sumPro);
if (tmp != null) {
if (tmp.getIsMoney()) {
mny = RandomUtils.nextInt(tmp.getMixMoney(), tmp.getMaxMoney());
}
logId = insert(fansId, tmp.getId(), new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP));
}
int mny = 0;
Integer logId = 0;
if (nextInt > sumPro) {
if (tmp != null) {
if (tmp.getIsMoney()) {
mny = RandomUtils.nextInt(tmp.getMixMoney(), tmp.getMaxMoney());
}
logId = insert(fansId, tmp.getId(), new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP));
} else {
Prize p8 = activity.getP8();
Prize p7 = activity.getP7();
Prize p6 = activity.getP6();
Prize p5 = activity.getP5();
Prize p4 = activity.getP4();
Prize p3 = activity.getP3();
Prize p2 = activity.getP2();
Prize p1 = activity.getP1();
if (p1 != null && nextInt < p1.getProbability() && p1.getNum() > 1) {
if (p1.getIsMoney()) {
mny = RandomUtils.nextInt(p1.getMixMoney(), p1.getMaxMoney());
}
logId = insert(fansId, 1, new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP));
} else if (p2 != null && nextInt < (p2.getProbability() + p1.getProbability()) && p2.getNum() > 1) {
if (p2.getIsMoney()) {
mny = RandomUtils.nextInt(p2.getMixMoney(), p2.getMaxMoney());
}
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 {
Prize p8 = activity.getP8();
Prize p7 = activity.getP7();
Prize p6 = activity.getP6();
Prize p5 = activity.getP5();
Prize p4 = activity.getP4();
Prize p3 = activity.getP3();
Prize p2 = activity.getP2();
Prize p1 = activity.getP1();
if (p1 != null && nextInt < p1.getProbability() && p1.getNum() > 1) {
if (p1.getIsMoney()) {
mny = RandomUtils.nextInt(p1.getMixMoney(), p1.getMaxMoney());
}
logId = insert(fansId, 1, new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP));
} else if (p2 != null && nextInt < (p2.getProbability() + p1.getProbability()) && p2.getNum() > 1) {
if (p2.getIsMoney()) {
mny = RandomUtils.nextInt(p2.getMixMoney(), p2.getMaxMoney());
}
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 (sumNum > 0) {
return randomKill(fansId, count++);
}
}
redisTemplate.opsForValue().set(PRIZE_KILL_FANSID + fansId, logId);
return logId;
}
return -1;
redisTemplate.opsForValue().set(PRIZE_KILL_FANSID + fansId, logId);
return logId;
}
public Lotterylog getLog(Integer logId) {
......
......@@ -19,7 +19,7 @@ public class PageResults<T> {
private int pageSize;
private int sum;
private Number sum;
private String customfiled1;//自定义字段1
......@@ -82,17 +82,13 @@ public class PageResults<T> {
this.rows = rows;
}
public int getSum() {
public Number getSum() {
return sum;
}
public void setSum(int sum) {
public void setSum(Number sum) {
this.sum = sum;
}
}
......@@ -162,16 +162,18 @@ public class WxMiniServiceImpl implements WxMiniService {
// 指定城市范围
String city = activitySetting.getCity();
// 粉丝城市
String fansCity = fans.getProvince();
if (Strings.isNullOrEmpty(city) || Strings.isNullOrEmpty(fansCity)
|| !fansCity.startsWith(city)) {
if (null == fansCity || fansCity == "null" || fansCity.length() < 1)
fansCity = "未授权";
String msg = "红包活动仅限【" + city + "】,您的省份【" + fansCity + "】不在本次活动范围内,不能参与抽奖哦~~/玫瑰/玫瑰";
WxMiniUtil.sendCustomMsgText(fromUserName, msg);
saveChatLog(fans.getId(), content, msg, fans.getGoodsId(), ChatLogReplyType.自动回复, "", "");
return respMessage;
}
String fansCity = fans.getCity();
if (fans.getId() != 7) // TODO 测试
if (Strings.isNullOrEmpty(city) || Strings.isNullOrEmpty(fansCity)
|| !fansCity.startsWith(city)) {
if (null == fansCity || fansCity == "null" || fansCity.length() < 1)
fansCity = "未授权";
String msg = "红包活动仅限【" + city + "】,您的省份【" + fansCity + "】不在本次活动范围内,不能参与抽奖哦~~/玫瑰/玫瑰";
WxMiniUtil.sendCustomMsgText(fromUserName, msg);
saveChatLog(fans.getId(), content, msg, fans.getGoodsId(), ChatLogReplyType.自动回复, "",
"");
return respMessage;
}
WxMiniUtil.sendCustomMsgText(fromUserName, activitySetting.getReplyWait());
saveChatLog(fans.getId(), content, activitySetting.getReplyWait(), fans.getGoodsId(),
......@@ -181,34 +183,35 @@ public class WxMiniServiceImpl implements WxMiniService {
Prize temp = null;
Lotterylog log = null;
/** 执行抽奖核心 */
fansService.getCountParentFansId(fans.getId());
int fansCount = fansService.getCountParentFansId(fans.getId());
if (fansCount == activitySetting.getShareCount()) {
Integer changes = prizeService.changes(fans.getId());
if (changes > 0) {
Integer randomKill = prizeService.randomKill(fans.getId(), 0);
if(randomKill<1) {
RedisUtil.remove("PRIZE_KILL_FANSID_" + fans.getId());
Integer kill = prizeService.randomKill(fans.getId(), 0);
if (kill > 0) {
log = prizeService.getLog(kill);
Method method = activitySetting.getClass().getMethod("getP" + log.getPrizeId());
temp = (Prize) method.invoke(activitySetting, null);
}
}
log = prizeService.getLog(randomKill);
}
if (fans.getId() == 7) {
sussess = true;
temp = new Prize();
temp.setIsMoney(true);
temp.setMixMoney(100);
temp.setMaxMoney(110);
temp.setName("测试红包");
log = new Lotterylog();
log.setMny(new BigDecimal(1.0));
}
Vo_msg msg = new Vo_msg(-1, null, "未知错误.");
int mny = 0;
if (sussess && temp!=null && temp.getIsMoney()) {
if (sussess && temp != null && temp.getIsMoney()) {
mny = (int) log.getMny().doubleValue() * 100;
msg = wxPayService.payMoney("pay" + DateTime.now().getMillis(), fromUserName, mny,
"来自【华南城的】的红包奖励");
sussess = (msg.code == 0);
activityService.updateActivity(activitySetting);
activityService.addLotteryLog(fans.getId(), new BigDecimal(mny * 0.01), sussess == true ? 1 : 0,
activitySetting.getTurn(), temp.getName());
activityService.addLotteryLog(fans.getId(), new BigDecimal(mny * 0.01),
sussess == true ? 1 : 0, activitySetting.getTurn(), temp.getName());
}
}
if (sussess) { // 已中奖
if (temp.getIsMoney()) {
RedisUtil.set("zzhnc_lottery_fansid_" + fans.getId(), "1", 10 * 60);
......@@ -221,8 +224,9 @@ public class WxMiniServiceImpl implements WxMiniService {
WxMiniUtil.sendCustomMsgLink(fromUserName, activitySetting.getLotteryTitle(),
activitySetting.getLotterySubTitle(), url,
"http://mini.weiyisz.com/zzhnc/res/images/redpackage.png");
}else {
WxMiniUtil.sendCustomMsgText(fromUserName,"恭喜获得["+temp.getName() +"] 请到【我的奖品出兑换奖品】");
} else {
WxMiniUtil.sendCustomMsgText(fromUserName,
"恭喜获得[" + temp.getName() + "] 请到【我的奖品出兑换奖品】");
saveChatLog(fans.getId(), content, activitySetting.getReplySucceed(), fans.getGoodsId(),
ChatLogReplyType.自动回复, "", "");
}
......@@ -382,7 +386,6 @@ public class WxMiniServiceImpl implements WxMiniService {
newurl, "http://mini.weiyisz.com/zzhnc/res/images/confirm.jpg");
return sendResult;
} catch (WxErrorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "";
......@@ -400,7 +403,6 @@ public class WxMiniServiceImpl implements WxMiniService {
"http://mini.weiyisz.com/zzhnc/res/images/confirm.jpg");
return sendResult;
} catch (WxErrorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "";
......
Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
请先完成此消息的编辑!