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,21 +321,30 @@ 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 changes = prizeService.changes(fans.getId());
if (changes > 0) {
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, "你已经中过奖了");
}
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);
}
/** 获取奖品列表 */
......@@ -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,19 +165,45 @@ 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) {
}
redisTemplate.delete(PRIZE_KILL_FANSID + fansId);
Activity activity = activityService.getActivitySetting();
int nextInt = RandomUtils.nextInt(0, 100);
System.out.println("幸运数字 ---》》》" + nextInt);
......@@ -194,6 +223,7 @@ public class PrizeService {
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());
......@@ -226,8 +256,9 @@ public class PrizeService {
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) {
} 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());
}
......@@ -244,17 +275,17 @@ public class PrizeService {
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()
} 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) {
} 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());
}
......@@ -269,8 +300,6 @@ public class PrizeService {
redisTemplate.opsForValue().set(PRIZE_KILL_FANSID + fansId, logId);
return logId;
}
return -1;
}
public Lotterylog getLog(Integer logId) {
return (Lotterylog) redisTemplate.opsForValue().get(LotteryLogID_ + 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,14 +162,16 @@ public class WxMiniServiceImpl implements WxMiniService {
// 指定城市范围
String city = activitySetting.getCity();
// 粉丝城市
String fansCity = fans.getProvince();
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.自动回复, "", "");
saveChatLog(fans.getId(), content, msg, fans.getGoodsId(), ChatLogReplyType.自动回复, "",
"");
return respMessage;
}
......@@ -181,31 +183,32 @@ 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());
}
......@@ -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 到此讨论。请谨慎行事。
请先完成此消息的编辑!