diff --git a/src/com/w1hd/zzhnc/controller/pc/UploadController.java b/src/com/w1hd/zzhnc/controller/pc/UploadController.java index 22aadf4..0dc2567 100644 --- a/src/com/w1hd/zzhnc/controller/pc/UploadController.java +++ b/src/com/w1hd/zzhnc/controller/pc/UploadController.java @@ -243,7 +243,7 @@ public class UploadController extends BaseController { FileCopyUtils.copy(mf.getBytes(), path); // 把图片复制到本地 } - returnPath = "http://mini.weiyisz.com/zzhnc/res/upload/" + imageType + "/" + newFileName; + returnPath = "http://dvmini.w1hd.com/zzhnc/res/upload/" + imageType + "/" + newFileName; System.out.println(returnPath); /* } */ } catch (Exception e) { diff --git a/src/com/w1hd/zzhnc/controller/wx/WxMiniController.java b/src/com/w1hd/zzhnc/controller/wx/WxMiniController.java index 7b9ab75..31481e1 100644 --- a/src/com/w1hd/zzhnc/controller/wx/WxMiniController.java +++ b/src/com/w1hd/zzhnc/controller/wx/WxMiniController.java @@ -7,12 +7,14 @@ import java.net.URLEncoder; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.TimeUnit; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; @@ -41,11 +43,14 @@ import com.w1hd.zzhnc.service.PrizeService; import com.w1hd.zzhnc.util.PageResults; import com.w1hd.zzhnc.util.RedisUtil; import com.w1hd.zzhnc.vo.Vo_msg; +import com.wordnik.swagger.annotations.ApiOperation; @Controller @RequestMapping("/wxmini") public class WxMiniController extends BaseController { + public static final String PRIZE_KEY_TIME = RedisUtil.PROJECTNAME.concat("_").concat("PRIZE_KEY_TIME_"); + @Autowired FansService fansService; @Autowired @@ -100,17 +105,18 @@ public class WxMiniController extends BaseController { @RequestMapping(value = "/login", method = RequestMethod.GET) // 购房助手登录 double lng,double lat public @ResponseBody Vo_msg login(@RequestParam(value = "code") String code, - @RequestParam(value = "shareId") Integer shareId, @RequestParam(value = "nickname") String nickname, - @RequestParam(value = "logo") String logo, @RequestParam(value = "lng") double lng, - @RequestParam(value = "lat") double lat) { + @RequestParam(value = "shareId") Integer shareId, @RequestParam(value = "fansId") Integer fansId, + @RequestParam(value = "nickname") String nickname, @RequestParam(value = "logo") String logo, + @RequestParam(value = "lng") double lng, @RequestParam(value = "lat") double lat) { logger.info("小程序登录:code=" + code); // 取openid WxMiniSessionInfo sessionInfo = WxMiniUtil.jscode2session(code); // 添加粉丝记录 - Fans fans = fansService.addFans(sessionInfo, shareId, nickname, logo, lng, lat); + Fans fans = fansService.addFans(sessionInfo, shareId, nickname, logo, lng, lat, fansId); if (fans != null) { Map map = new HashMap<>(); map.put("miniOpenId", sessionInfo.getOpenid()); + map.put("fansId", fans.getId()); return new Vo_msg(0, map); } else { return new Vo_msg(-1, "登录失败,服务器异常"); @@ -294,7 +300,7 @@ public class WxMiniController extends BaseController { } /** 查看我的奖品 */ - @RequestMapping(value = "/prizes", method = RequestMethod.GET) + @RequestMapping(value = "/prizes/my", method = RequestMethod.GET) @ResponseBody public Object prizes(@RequestParam(value = "openId") String openId) { Fans fans = fansService.getFansByMiniOpenid(openId); @@ -316,12 +322,12 @@ public class WxMiniController extends BaseController { @ResponseBody public Object prizesKill(@RequestParam(value = "openId") String openId) { Fans fans = fansService.getFansByMiniOpenid(openId); - Integer logId = prizeService.randomKill(fans.getId()); - if(logId == 0) { - return new Vo_msg(-1, null,"不好意思你没中奖"); + 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,"你已经中过奖了"); + if (logId == -1) { + return new Vo_msg(-1, null, "你已经中过奖了"); } Lotterylog log = prizeService.getLog(logId); return new Vo_msg(0, log); @@ -336,10 +342,26 @@ public class WxMiniController extends BaseController { return prizeList; } + @Autowired + RedisTemplate redisTemplate; + + /** 核销奖品 */ + @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; + } + /** 核销奖品 */ @RequestMapping(value = "/prizes/{id}", method = RequestMethod.GET) @ResponseBody - public Object prizes(@RequestParam(value = "openId") String openId, @PathVariable(value = "id") Integer id) { + public Object prizes(@RequestParam(value = "openId") String openId, + @RequestParam(value = "timeMillis") Long timeMillis, @RequestParam(value = "localMillis") Long localMillis, + @PathVariable(value = "id") Integer id) { Fans fans = fansService.getFansByMiniOpenid(openId); return prizeService.updateLotteryLog(id, fans.getId()); } @@ -351,4 +373,19 @@ public class WxMiniController extends BaseController { return new Vo_msg(0, seacrh); } + @RequestMapping(value = "/goods/share/{id}", method = RequestMethod.GET) + @ResponseBody + public Object goodsShare(@RequestParam(value = "openId") String openId, @PathVariable(value = "id") Integer id) { + if (id > 0) { + PageResults seacrh = goodsService.seacrh(id, null, null, null, null); + Goods goods = seacrh.getRows().get(0); + goods.setShareCount(goods.getShareCount() + 1); + goodsService.update(goods); + } + Fans fans = fansService.getFansByMiniOpenid(openId); + fans.setShareCount(fans.getShareCount() + 1); + fansService.updateFans(fans); + return new Vo_msg(0, null); + } + } diff --git a/src/com/w1hd/zzhnc/model/Activity.java b/src/com/w1hd/zzhnc/model/Activity.java index 2c27a7d..c02de9d 100644 --- a/src/com/w1hd/zzhnc/model/Activity.java +++ b/src/com/w1hd/zzhnc/model/Activity.java @@ -25,7 +25,7 @@ public class Activity implements Serializable { @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date endTime;// 活动结束时间 - + private int shareCount; // 下属粉丝达到一定数量可以再次抽奖 private int status;// 活动状态 private BigDecimal planMny;// 发放红包预算 private BigDecimal currentMny; @@ -295,5 +295,12 @@ public class Activity implements Serializable { this.p8 = p8; } + public int getShareCount() { + return shareCount; + } + + public void setShareCount(int shareCount) { + this.shareCount = shareCount; + } } \ No newline at end of file diff --git a/src/com/w1hd/zzhnc/model/Fans.java b/src/com/w1hd/zzhnc/model/Fans.java index ccb6c8f..7c3713f 100644 --- a/src/com/w1hd/zzhnc/model/Fans.java +++ b/src/com/w1hd/zzhnc/model/Fans.java @@ -1,12 +1,18 @@ package com.w1hd.zzhnc.model; +import java.io.Serializable; import java.util.Date; import javax.persistence.Id; import org.joda.time.DateTime; -public class Fans { +public class Fans implements Serializable{ + /** + * + */ + private static final long serialVersionUID = -418002994563516320L; + @Id private Integer id; @@ -44,6 +50,8 @@ public class Fans { private boolean readed=false; private String remarkName; + private Integer shareCount; + public Integer getId() { return id; } @@ -213,9 +221,12 @@ public class Fans { this.remarkName = remarkName; } - - - - + public Integer getShareCount() { + return shareCount; + } + public void setShareCount(Integer shareCount) { + this.shareCount = shareCount; + } + } \ No newline at end of file diff --git a/src/com/w1hd/zzhnc/service/FansService.java b/src/com/w1hd/zzhnc/service/FansService.java index fab8df9..cd9182e 100644 --- a/src/com/w1hd/zzhnc/service/FansService.java +++ b/src/com/w1hd/zzhnc/service/FansService.java @@ -4,6 +4,7 @@ import java.util.List; import org.apache.ibatis.session.RowBounds; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.theyeasy.weixin.model.WxMiniSessionInfo; import org.theyeasy.weixin.util.CusAccessObjectUtil2; @@ -14,6 +15,7 @@ import com.w1hd.zzhnc.dao.FansDao; import com.w1hd.zzhnc.model.Fans; import com.w1hd.zzhnc.util.CommonUtil; import com.w1hd.zzhnc.util.PageResults; +import com.w1hd.zzhnc.util.RedisUtil; import jodd.util.URLDecoder; import tk.mybatis.mapper.entity.Example; @@ -29,14 +31,15 @@ import tk.mybatis.mapper.entity.Example.Criteria; @Service public class FansService { + public static final String FANS_KEY_OPENID = RedisUtil.PROJECTNAME.concat("_").concat("FANS_KEY_OPENID_"); @Autowired FansDao fansDao; public PageResults getFansList(Integer page, String keyword) { Example ex = new Example(Fans.class); Criteria criteria = ex.createCriteria(); - if(!Strings.isNullOrEmpty(keyword)) { - criteria.andCondition(" ( nickname like \"%" + keyword +"%\")"); + if (!Strings.isNullOrEmpty(keyword)) { + criteria.andCondition(" ( nickname like \"%" + keyword + "%\")"); } RowBounds row = new RowBounds((page - 1) * 10, 10); List list = fansDao.selectByExampleAndRowBounds(ex, row); @@ -49,14 +52,24 @@ public class FansService { return pageresult; } + @Autowired + RedisTemplate redisTemplate; + + @SuppressWarnings("unchecked") public Fans getFansByMiniOpenid(String miniOpenid) { - Example example = new Example(Fans.class); - example.createCriteria().andEqualTo("miniopenid", miniOpenid); - List list = fansDao.selectByExample(example); - if (list != null && list.size() > 0) { - return list.get(0); + + Fans fans = (Fans) redisTemplate.opsForValue().get(FANS_KEY_OPENID + miniOpenid); + if (fans == null) { + Example example = new Example(Fans.class); + example.createCriteria().andEqualTo("miniopenid", miniOpenid); + List list = fansDao.selectByExample(example); + if (list != null && list.size() > 0) { + fans = list.get(0); + redisTemplate.opsForValue().set(FANS_KEY_OPENID + miniOpenid, fans); + return fans; + } } - return null; + return fans; } public Fans getFansById(Integer id) { @@ -77,13 +90,14 @@ public class FansService { fans.setLogo(""); fans.setNickname(""); fans.setParentfansid(0); + fans.setShareCount(0); int flag = fansDao.insertSelective(fans); return fans;// 插入成功后会返回新的id; } public Fans addFans(WxMiniSessionInfo info, Integer shareFansId, String nickname, String logo, double lng, - double lat) { + double lat, Integer fansId) { if (info == null) return null; @@ -108,6 +122,7 @@ public class FansService { fans.setFanstype(1); fans.setLng(lng); fans.setLat(lat); + fans.setParentfansid(fansId); JSONObject locationResult = CusAccessObjectUtil2.locationResult(lng, lat); if (null != locationResult) { fans.setProvince(CusAccessObjectUtil2.getProvince(locationResult)); @@ -133,16 +148,28 @@ public class FansService { fansDao.updateByPrimaryKeySelective(fans); } } catch (Exception e) { - // TODO Auto-generated catch block e.printStackTrace(); - System.out.println("新增粉丝失败:" + e.getMessage()); return null; } return fans; } + @SuppressWarnings("unchecked") public void updateFans(Fans fans) { + redisTemplate.delete(FANS_KEY_OPENID + fans.getMiniopenid()); fansDao.updateByPrimaryKeySelective(fans); } + + public Integer getCountParentFansId(Integer id) { + try { + Example ex = new Example(Fans.class); + ex.createCriteria().andEqualTo("parentfansid", id).andNotEqualTo("parentfansid", 0); + return fansDao.selectCountByExample(ex); + } catch (Exception e) { + e.printStackTrace(); + } + return 0; + + } } diff --git a/src/com/w1hd/zzhnc/service/GoodsService.java b/src/com/w1hd/zzhnc/service/GoodsService.java index a3d09e5..ecd7d1b 100644 --- a/src/com/w1hd/zzhnc/service/GoodsService.java +++ b/src/com/w1hd/zzhnc/service/GoodsService.java @@ -62,7 +62,7 @@ public class GoodsService { public PageResults seacrh(Integer id, String key, Integer sellerId, Integer page, Integer size) { Example ex = new Example(Goods.class); Criteria c = ex.createCriteria(); - if (id != null && id > 0) { + if (id != null && id>0 ) { return goods(id); } else { if (!Strings.isNullOrEmpty(key)) { diff --git a/src/com/w1hd/zzhnc/service/PrizeService.java b/src/com/w1hd/zzhnc/service/PrizeService.java index 05b128f..9cab120 100644 --- a/src/com/w1hd/zzhnc/service/PrizeService.java +++ b/src/com/w1hd/zzhnc/service/PrizeService.java @@ -125,6 +125,7 @@ public class PrizeService { default: break; } + setting.setCurrentMny(setting.getCurrentMny().add(mny)); activityService.updateActivity(setting); Lotterylog lotterylog = new Lotterylog(); lotterylog.setCreatedtime(new Date()); @@ -169,7 +170,9 @@ public class PrizeService { RedisTemplate redisTemplate; @SuppressWarnings("unchecked") - public Integer randomKill(Integer fansId) { + public Integer randomKill(Integer fansId, Integer count) { + if (count == 8) + return 0; Integer lotteryLog = (Integer) redisTemplate.opsForValue().get(PRIZE_KILL_FANSID + fansId); if (lotteryLog == null) { Activity activity = activityService.getActivitySetting(); @@ -258,7 +261,7 @@ public class PrizeService { logId = insert(fansId, 8, new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP)); } else { if (sumNum > 0) { - return randomKill(fansId); + return randomKill(fansId, count++); } } } diff --git a/src/org/theyeasy/weixin/service/impl/WxMiniServiceImpl.java b/src/org/theyeasy/weixin/service/impl/WxMiniServiceImpl.java index 0b88312..d2fd28c 100644 --- a/src/org/theyeasy/weixin/service/impl/WxMiniServiceImpl.java +++ b/src/org/theyeasy/weixin/service/impl/WxMiniServiceImpl.java @@ -1,5 +1,6 @@ package org.theyeasy.weixin.service.impl; +import java.lang.reflect.Method; import java.math.BigDecimal; import java.net.URLEncoder; import java.util.Collections; @@ -42,6 +43,7 @@ import com.w1hd.zzhnc.service.ActivityService; import com.w1hd.zzhnc.service.AutoreplyService; import com.w1hd.zzhnc.service.ChatLogService; import com.w1hd.zzhnc.service.FansService; +import com.w1hd.zzhnc.service.PrizeService; import com.w1hd.zzhnc.util.CommonUtil; import com.w1hd.zzhnc.util.JsonMapper; import com.w1hd.zzhnc.util.QQFaceUtil; @@ -82,6 +84,8 @@ public class WxMiniServiceImpl implements WxMiniService { @Autowired WxPayService wxPayService; + @Autowired + PrizeService prizeService; @Override public String processRequest(HttpServletRequest request) { @@ -102,9 +106,6 @@ public class WxMiniServiceImpl implements WxMiniService { // 消息时间 String msgTime = requestMap.get("CreateTime"); - /**************** - * 微信消息去重处理(重要!!!服务器繁忙时微信会重复3次推送同一条消息 add by lcc 2017-10-30 - ****************************/ String key = "WxMiniMsgKey_"; key += fromUserName + msgTime; @@ -121,25 +122,16 @@ public class WxMiniServiceImpl implements WxMiniService { fans = fansService.addFans(fromUserName); System.out.println("会话事件中添加了粉丝,id=" + fans.getId()); } - int saleid = fans.getGoodsId(); - if (saleid < 1) // 没有销售的就分配一个万小二给他。 - { - fansDao.updateByPrimaryKeySelective(fans); - } + int goodsId = fans.getGoodsId(); String sendResult = "";// if (msgType.equals(WxMessageUtil.REQ_MESSAGE_TYPE_TEXT)) { String content = requestMap.get("Content").trim(); // 用户发送的内容 - // if (content.equals("TEST_WXMSG_BUSY_SLEEP_6")) - // Thread.currentThread().sleep(6000); // 测试重复消息的过滤功能(add by lcc - // 171030); - content = QQFaceUtil.regix(content); Activity activitySetting = activityService.getActivitySetting(); - if (activitySetting != null && activitySetting.getStatus() > ActivityStatus.UNSTART.getIndex() - && !content.equals("人工万小二")) { + if (activitySetting != null && activitySetting.getStatus() > ActivityStatus.UNSTART.getIndex()) { String[] keywords = activitySetting.getKeyword().split("\\|"); boolean containKeyword = false; for (String keyword : keywords) { @@ -147,16 +139,14 @@ public class WxMiniServiceImpl implements WxMiniService { containKeyword = true; break; } - } - // 金额比较 Edit by lcc 171207 BigDecimal currentMny = activitySetting.getCurrentMny(); int compareTo = 0; if (currentMny != null) { compareTo = activitySetting.getPlanMny().compareTo(activitySetting.getCurrentMny()); } - // 抽奖活动已结束或红包预算已经发放完毕的回复.. add by lcc 171207 + if (containKeyword && (activitySetting.getStatus() > 2 || compareTo < 0)) { WxMiniUtil.sendCustomMsgText(fromUserName, activitySetting.getFinishReply()); saveChatLog(fans.getId(), content, activitySetting.getFinishReply(), fans.getGoodsId(), @@ -167,54 +157,17 @@ public class WxMiniServiceImpl implements WxMiniService { // 抽奖活动进行中 if (!Strings.isNullOrEmpty(activitySetting.getKeyword()) && containKeyword && activitySetting.getStatus() == 2) { - Fans fansByMiniOpenid = fansService.getFansByMiniOpenid(fromUserName); - Example example = new Example(Lotterylog.class); - - // 从redis判断是否此人已中过奖 - String hasLottery = RedisUtil.get("zzhnc_lottery_fansid_" + fans.getId()); - if (null != hasLottery && hasLottery.equals("1")) { - WxMiniUtil.sendCustomMsgText(fromUserName, activitySetting.getNoChanceReply()); - saveChatLog(fans.getId(), content, activitySetting.getNoChanceReply(), fans.getGoodsId(), - ChatLogReplyType.自动回复, "", ""); - return respMessage; - } - - // 判断本轮的总抽奖次数,最多两次抽奖机会 add by lcc 171207 - example.createCriteria().andEqualTo("fansid", fansByMiniOpenid.getId()).andEqualTo("turn", - activitySetting.getTurn()); - int count = lotteryLogDao.selectCountByExample(example); - if (count >= 2) { - WxMiniUtil.sendCustomMsgText(fromUserName, activitySetting.getNoChanceReply()); - saveChatLog(fans.getId(), content, activitySetting.getNoChanceReply(), fans.getGoodsId(), - ChatLogReplyType.自动回复, "", ""); - return respMessage; - } - - // 判断是否中奖过,最多一次中奖机会 add by lcc 171207 - example.clear(); - example.createCriteria().andEqualTo("fansid", fansByMiniOpenid.getId()) - .andEqualTo("turn", activitySetting.getTurn()).andGreaterThan("status", "0"); - int succeedCount = lotteryLogDao.selectCountByExample(example); - if (succeedCount > 0) { - WxMiniUtil.sendCustomMsgText(fromUserName, activitySetting.getNoChanceReply()); - saveChatLog(fans.getId(), content, activitySetting.getNoChanceReply(), fans.getGoodsId(), - ChatLogReplyType.自动回复, "", ""); - return respMessage; - } - boolean sussess = false; // 指定城市范围 String city = activitySetting.getCity(); // 粉丝城市 - String fansCity = fansByMiniOpenid.getProvince(); + 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 + "】不在本次活动范围内,不能参与抽奖哦~~/玫瑰/玫瑰"; - // if(null==fansCity || fansCity=="") msg="红包活动仅限【" + city + "】,您的省份【" + - // fansCity+ "】可能是您未授权,小二无法判断您是否在本次活动范围内,所以不能参与抽奖哦~~"; WxMiniUtil.sendCustomMsgText(fromUserName, msg); saveChatLog(fans.getId(), content, msg, fans.getGoodsId(), ChatLogReplyType.自动回复, "", ""); return respMessage; @@ -225,129 +178,73 @@ public class WxMiniServiceImpl implements WxMiniService { ChatLogReplyType.自动回复, "", ""); Thread.sleep(1000); - - /** 取100-200内的数值,单位为分 */ - List prizes = ActivitySettingUtils.getInstance(activitySetting).getPrizes(); - Collections.sort(prizes, new Comparator() { - - public int compare(Prize o1, Prize o2) { - if (o1.getProbability() > o2.getProbability()) { - return -1; - } - if (o1.getProbability() == o2.getProbability()) { - return 0; - } - return 1; - } - }); - int max = ActivitySettingUtils.getInstance(activitySetting).max(); - int nextInt = RandomUtils.nextInt(0, max); Prize temp = null; - for (Prize p : prizes) { - if (nextInt < p.getProbability()) { - if (p.getNum() > 0) { - temp = p; - } + Lotterylog log = null; + /** 执行抽奖核心 */ + fansService.getCountParentFansId(fans.getId()); + int fansCount = fansService.getCountParentFansId(fans.getId()); + if (fansCount == activitySetting.getShareCount()) { + 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); + } } } Vo_msg msg = new Vo_msg(-1, null, "未知错误."); int mny = 0; - if (temp.getIsMoney()) { - mny = RandomUtils.nextInt(temp.getMixMoney(), temp.getMaxMoney()); + 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); - activitySetting - .setCurrentMny(activitySetting.getCurrentMny().add(new BigDecimal(mny * 0.01))); - } else { - temp.setNum(temp.getNum() - 1); - switch (temp.getId()) { - case 1: - activitySetting.setP1(temp); - break; - case 2: - activitySetting.setP2(temp); - break; - case 3: - activitySetting.setP3(temp); - break; - case 4: - activitySetting.setP4(temp); - break; - default: - break; - } - sussess = true; - } - activityService.updateActivity(activitySetting); - activityService.addLotteryLog(fansByMiniOpenid.getId(), new BigDecimal(mny * 0.01), - sussess == true ? 1 : 0, activitySetting.getTurn(),temp.getName()); + activityService.updateActivity(activitySetting); + activityService.addLotteryLog(fans.getId(), new BigDecimal(mny * 0.01), sussess == true ? 1 : 0, + activitySetting.getTurn(), temp.getName()); + + } + if (sussess) { // 已中奖 - // 扣减红包预算总额 - - // 已中奖的推送到Redis中进行缓存,避免出现sql并发重复参与抽奖 - RedisUtil.set("zzhnc_lottery_fansid_" + fans.getId(), "1", 10 * 60); - // 发送中奖提示语 - WxMiniUtil.sendCustomMsgText(fromUserName, activitySetting.getReplySucceed()); - saveChatLog(fans.getId(), content, activitySetting.getReplySucceed(), fans.getGoodsId(), - ChatLogReplyType.自动回复, "", ""); - // 推送中奖链接 - String url = "http://mini.weiyisz.com/zzhnc/wx/redpackage?mny=" + mny * 0.01; - WxMiniUtil.sendCustomMsgLink(fromUserName, activitySetting.getLotteryTitle(), - activitySetting.getLotterySubTitle(), url, - "http://mini.weiyisz.com/zzhnc/res/images/redpackage.png"); - // 推送小程序卡片 - SendMiniProgram(fromUserName); + if (temp.getIsMoney()) { + RedisUtil.set("zzhnc_lottery_fansid_" + fans.getId(), "1", 10 * 60); + // 发送中奖提示语 + WxMiniUtil.sendCustomMsgText(fromUserName, activitySetting.getReplySucceed()); + saveChatLog(fans.getId(), content, activitySetting.getReplySucceed(), fans.getGoodsId(), + ChatLogReplyType.自动回复, "", ""); + // 推送中奖链接 + String url = "http://mini.weiyisz.com/zzhnc/wx/redpackage?mny=" + mny * 0.01; + WxMiniUtil.sendCustomMsgLink(fromUserName, activitySetting.getLotteryTitle(), + activitySetting.getLotterySubTitle(), url, + "http://mini.weiyisz.com/zzhnc/res/images/redpackage.png"); + }else { + WxMiniUtil.sendCustomMsgText(fromUserName,"恭喜获得["+temp.getName() +"] 请到【我的奖品出兑换奖品】"); + saveChatLog(fans.getId(), content, activitySetting.getReplySucceed(), fans.getGoodsId(), + ChatLogReplyType.自动回复, "", ""); + } return respMessage; } else { // 未中奖 // 发送未中奖提示语 - String failedReply = count == 0 ? activitySetting.getUnLotteryReply() - : activitySetting.getReplyFailed2(); // 第一次和第二次未中奖的提示语有区别 + String failedReply = activitySetting.getUnLotteryReply(); // 第一次和第二次未中奖的提示语有区别 WxMiniUtil.sendCustomMsgText(fromUserName, failedReply); saveChatLog(fans.getId(), content, failedReply, fans.getGoodsId(), ChatLogReplyType.自动回复, "", ""); - - // 两次未中奖时推送小程序卡片 - if (count > 0) { - SendMiniProgram(fromUserName); - } return respMessage; } } } - // 人工客服未接管,但是与客服正在聊天,无论如何都要发模板消息 - if (RedisUtil.getFansChatStatus(fans.getId()) > 1) { - nofitySalesIncludeVanker(saleid, content, fans); - } else - // 人工客服未接管:判断是否需要给后台客服人员发送模板消息 - if (needNotifySales(content)) { - // 用模板消息通过对应的销售,没有对应销售时发送给所有万小二。 - nofitySalesIncludeVanker(saleid, content, fans); - - // 自动随机回复客户 - String randomReply = getRandomReplyAfterNotify(); - WxMiniUtil.sendCustomMsgText(fromUserName, randomReply); - if (saleid == 0) { - String vankerId = RedisUtil.get("zzhnc_vanke"); - if (Strings.isNullOrEmpty(vankerId)) { - int id = Integer.parseInt(vankerId); - saleid = id; - } - } - saveChatLog(fans.getId(), content, randomReply, saleid, ChatLogReplyType.自动回复, "", ""); - - return respMessage; - } - String faces = WxMiniUtil.sponseQqFace(content); if (faces.startsWith("[") && faces.endsWith("]")) faces = faces.substring(1, faces.length() - 1); if (faces.length() > 0) { WxMiniUtil.sendCustomMsgText(fromUserName, faces); - saveChatLog(fans.getId(), content, faces, saleid, ChatLogReplyType.自动回复, "", ""); + saveChatLog(fans.getId(), content, faces, goodsId, ChatLogReplyType.自动回复, "", ""); return respMessage; } @@ -361,27 +258,19 @@ public class WxMiniServiceImpl implements WxMiniService { return respMessage; } WxMiniUtil.sendCustomMsgText(fromUserName, auto.getContents()); - saveChatLog(fans.getId(), content, auto.getContents(), saleid, + saveChatLog(fans.getId(), content, auto.getContents(), goodsId, Integer.parseInt(data.get("type").toString()) == 2 ? ChatLogReplyType.自动回复 : ChatLogReplyType.机器人, "", ""); - // 判断是否需要通知人工客服 --add by lcc 171207 - if (auto.getIsredirectstaff()) { - nofitySalesIncludeVanker(saleid, content, fans); - } - return respMessage; } else if (msgType.equals(WxMessageUtil.REQ_MESSAGE_TYPE_IMAGE)) {// 图片消息 String fansImgUrl = requestMap.get("PicUrl"); - boolean handle = false; - if (!handle) { - String imgReply = getImgReply(); - WxMiniUtil.sendCustomMsgText(fromUserName, imgReply);// 还没办法自动回复图片 - saveChatLog(fans.getId(), "", imgReply, saleid, ChatLogReplyType.机器人, fansImgUrl, ""); - } + String imgReply = getImgReply(); + WxMiniUtil.sendCustomMsgText(fromUserName, imgReply);// 还没办法自动回复图片 + saveChatLog(fans.getId(), "", imgReply, goodsId, ChatLogReplyType.机器人, fansImgUrl, ""); } else if (msgType.equals(WxMessageUtil.REQ_MESSAGE_TYPE_LOCATION)) {// 地理位置消息 } else if (msgType.equals(WxMessageUtil.REQ_MESSAGE_TYPE_LINK)) {// 链接消息 @@ -653,15 +542,6 @@ public class WxMiniServiceImpl implements WxMiniService { // redis中如果不存在,则重新上传临时素材 if (null == media_id || media_id.length() < 1 || null == thumb_url || thumb_url.length() < 1) { - // 获取默认首页的海报 - // Example example = new Example(Postertemplet.class); - // example.createCriteria().andEqualTo("postertype", 3).andEqualTo("deleted", - // false); - // java.util.List posterList = - // postertempletDao.selectByExample(example); - // if (posterList.size() < 1) - // return new Vo_msg(-1, null, "小程序卡片对应的海报模板不存在"); - // thumb_url = posterList.get(0).getImgurl(); Vo_msg imgMsg = WxMiniUtil.uploadImage(thumb_url, false); if (imgMsg.code != 0) diff --git a/src/org/theyeasy/weixin/util/ActivitySettingUtils.java b/src/org/theyeasy/weixin/util/ActivitySettingUtils.java index a377f6c..8c9f706 100644 --- a/src/org/theyeasy/weixin/util/ActivitySettingUtils.java +++ b/src/org/theyeasy/weixin/util/ActivitySettingUtils.java @@ -23,8 +23,8 @@ public class ActivitySettingUtils { public static ActivitySettingUtils getInstance(Activity act) { if (instance == null) { instance = new ActivitySettingUtils(); - ActivitySettingUtils.act = act; } + ActivitySettingUtils.act = act; return instance; }