diff --git a/WebContent/WEB-INF/classes/wx.pay.properties b/WebContent/WEB-INF/classes/wx.pay.properties index 4801f4a..ecbdb3d 100644 --- a/WebContent/WEB-INF/classes/wx.pay.properties +++ b/WebContent/WEB-INF/classes/wx.pay.properties @@ -1,6 +1,5 @@ -mch_appid = wxbe75806d33ab8a2e -mchid = 1496014382 -key = glSPm08OiR82CfXyZ3HQECFeiwS7np5t +mch_appid = wx64e56457ec5c6338 +mchid = 1493581312 +key = Bnzihl9t8zId5qKL70bmKDuUpPklMpXB 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 +cert_file=/theyeasy/weixin_cert/dvmini_apiclient_cert.p12 \ No newline at end of file diff --git a/src/com/w1hd/zzhnc/controller/pc/ActivityController.java b/src/com/w1hd/zzhnc/controller/pc/ActivityController.java index 15cee82..f4100a3 100644 --- a/src/com/w1hd/zzhnc/controller/pc/ActivityController.java +++ b/src/com/w1hd/zzhnc/controller/pc/ActivityController.java @@ -130,7 +130,7 @@ public class ActivityController extends BaseController { @ResponseBody public Object lotterys(@RequestParam(value = "page", defaultValue = "1", required = false) Integer page, @RequestParam(value = "pagesize", defaultValue = "10", required = false) Integer pagesize, - @RequestParam(value = "turn", defaultValue = "1", required = false) Integer turn, + @RequestParam(value = "turn", defaultValue = "0", required = false) Integer turn, @RequestParam(value = "keyword", defaultValue = "", required = false) String keyword, @RequestParam(value = "status", defaultValue = "1", required = false) Integer status) { return new Vo_msg(0, activityService.getLotteryLogList(page, pagesize, turn, keyword, status)); diff --git a/src/com/w1hd/zzhnc/controller/pc/AutoreplyController.java b/src/com/w1hd/zzhnc/controller/pc/AutoreplyController.java index 6b6baaa..16197bc 100644 --- a/src/com/w1hd/zzhnc/controller/pc/AutoreplyController.java +++ b/src/com/w1hd/zzhnc/controller/pc/AutoreplyController.java @@ -106,4 +106,11 @@ public class AutoreplyController extends BaseController { replyService.init(true); return new Vo_msg(0, "ok"); } + + @RequestMapping(value = "/autureply", method = RequestMethod.GET) + @ResponseBody + public Object autureply(@RequestParam(value = "content", required = true)String content) { + Autoreply autoreply = replyService.autoreply(content); + return new Vo_msg(0, autoreply.getContents()); + } } \ No newline at end of file diff --git a/src/com/w1hd/zzhnc/controller/pc/GoodsController.java b/src/com/w1hd/zzhnc/controller/pc/GoodsController.java index c284c47..34b8220 100644 --- a/src/com/w1hd/zzhnc/controller/pc/GoodsController.java +++ b/src/com/w1hd/zzhnc/controller/pc/GoodsController.java @@ -51,8 +51,9 @@ public class GoodsController { @RequestParam(value="id",required=false,defaultValue = "0")Integer id, @RequestParam(value="sellerId",required=false,defaultValue = "0")Integer sellerId, @RequestParam(value="page",required=false,defaultValue = "1")Integer page, - @RequestParam(value="size",required=false,defaultValue = "10")Integer size) { - return new Vo_msg(0,goodsService.seacrh(id,key,sellerId,page,size)); + @RequestParam(value="size",required=false,defaultValue = "10")Integer size, + @RequestParam(value="sort",required=false,defaultValue = "1")Integer sort) { + return new Vo_msg(0,goodsService.seacrh(id,key,sellerId,page,size,sort)); } } diff --git a/src/com/w1hd/zzhnc/controller/wx/WxMiniController.java b/src/com/w1hd/zzhnc/controller/wx/WxMiniController.java index 03aad66..9c377be 100644 --- a/src/com/w1hd/zzhnc/controller/wx/WxMiniController.java +++ b/src/com/w1hd/zzhnc/controller/wx/WxMiniController.java @@ -18,10 +18,12 @@ 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.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.servlet.ModelAndView; import org.theyeasy.weixin.model.WxMiniSessionInfo; import org.theyeasy.weixin.service.WxMiniService; import org.theyeasy.weixin.util.WxMiniUtil; @@ -293,7 +295,7 @@ public class WxMiniController extends BaseController { try { Map result = Maps.newHashMap(); List bannerList = bannerService.getAll(); - PageResults seacrh = goodsService.seacrh(null, key, null, page, size); + PageResults seacrh = goodsService.seacrh(null, key, null, page, size, 1); List rows = seacrh.getRows(); result.put("banner", bannerList); result.put("data", rows); @@ -344,6 +346,9 @@ public class WxMiniController extends BaseController { public Object changes(@RequestParam(value = "openId") String openId) { Fans fans = fansService.getFansByMiniOpenid(openId); Integer changes = prizeService.changes(fans.getId()); + if (changes < 0) { + changes = 0; + } return new Vo_msg(0, changes); } @@ -382,7 +387,7 @@ public class WxMiniController extends BaseController { @RequestMapping(value = "/goods/{id}", method = RequestMethod.GET) @ResponseBody public Object goods(@RequestParam(value = "openId") String openId, @PathVariable(value = "id") Integer id) { - PageResults seacrh = goodsService.seacrh(id, null, null, null, null); + PageResults seacrh = goodsService.seacrh(id, null, null, null, null, 0); return new Vo_msg(0, seacrh); } @@ -390,7 +395,7 @@ public class WxMiniController extends BaseController { @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); + PageResults seacrh = goodsService.seacrh(id, null, null, null, null, 0); Goods goods = seacrh.getRows().get(0); goods.setShareCount(goods.getShareCount() + 1); goodsService.update(goods); @@ -401,4 +406,16 @@ public class WxMiniController extends BaseController { return new Vo_msg(0, null); } + @RequestMapping(value = "/prizes/pass/{id}", method = RequestMethod.GET) + public ModelAndView pass(@RequestParam(value = "openId") String openId, @PathVariable(value = "id") Integer id) { + Fans fans = fansService.getFansByMiniOpenid(openId); + Lotterylog log = prizeService.getLog(id); + System.out.println("log == " + log.getPrizeUrl()); + if (log.getPrizeUrl() != null) { + return new ModelAndView("redirect:" + log.getPrizeUrl()); + } + + return new ModelAndView("redirect:" + "https://dvmini.w1hd.com"); + } + } diff --git a/src/com/w1hd/zzhnc/model/Lotterylog.java b/src/com/w1hd/zzhnc/model/Lotterylog.java index 0a2ad8b..1ad2430 100644 --- a/src/com/w1hd/zzhnc/model/Lotterylog.java +++ b/src/com/w1hd/zzhnc/model/Lotterylog.java @@ -16,7 +16,9 @@ public class Lotterylog implements Serializable { private Integer fansid; private String prizeName; private BigDecimal mny; - private Integer status; + /** 1 未兑奖 2.已对奖 3.谢谢参与*/ + private Integer status; + private Integer turn; private Integer prizeId; private Date createdtime; diff --git a/src/com/w1hd/zzhnc/model/Prize.java b/src/com/w1hd/zzhnc/model/Prize.java index e91d9fe..14b0e76 100644 --- a/src/com/w1hd/zzhnc/model/Prize.java +++ b/src/com/w1hd/zzhnc/model/Prize.java @@ -32,6 +32,9 @@ public class Prize implements Serializable { } public Integer getProbability() { + if (probability == null) { + return 0; + } return probability; } diff --git a/src/com/w1hd/zzhnc/service/ActivityService.java b/src/com/w1hd/zzhnc/service/ActivityService.java index ad313c3..eeea085 100644 --- a/src/com/w1hd/zzhnc/service/ActivityService.java +++ b/src/com/w1hd/zzhnc/service/ActivityService.java @@ -4,11 +4,14 @@ import java.math.BigDecimal; import java.util.Date; import java.util.List; +import org.hamcrest.core.IsInstanceOf; +import org.joda.time.DateTime; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.testng.collections.Lists; import org.testng.util.Strings; +import org.theyeasy.weixin.service.WxPayService; import com.w1hd.zzhnc.dao.LotteryLogDao; import com.w1hd.zzhnc.enums.ActivityStatus; @@ -33,6 +36,8 @@ public class ActivityService { final String ACTIVITY_SETTING = RedisUtil.PROJECTNAME.concat("_").concat("ACTIVITY_SETTING");// 娲诲姩璁剧疆淇濆瓨key + final String SEND_REDPACKAGE_ID = RedisUtil.PROJECTNAME.concat("_").concat("SEND_REDPACKAGE_ID_"); + @Autowired LotteryLogDao logDao; @@ -163,7 +168,7 @@ public class ActivityService { } updateActivity(setting); } - + public List getPrizeList() { Activity setting = getActivitySetting(); List newArrayList = Lists.newArrayList(); @@ -177,6 +182,21 @@ public class ActivityService { newArrayList.add(setting.getP8()); return newArrayList; } - + + @Autowired + WxPayService wxPayService; + + public void sendRedPackage(String miniOpenId, Integer mny) { + Integer count = 1; + Object object = redisTemplate.opsForValue().get(SEND_REDPACKAGE_ID + miniOpenId); + if (object != null && object instanceof Integer) { + count = (Integer) object; + System.out.println("注意 !" + miniOpenId + " 已中过奖 " + count + " 次"); + count++; + + } + wxPayService.payMoney("pay" + DateTime.now().getMillis(), miniOpenId, mny, "来自【东莞万科万小二】的红包奖励"); + redisTemplate.opsForValue().set(SEND_REDPACKAGE_ID + miniOpenId, count); + } } diff --git a/src/com/w1hd/zzhnc/service/AutoreplyService.java b/src/com/w1hd/zzhnc/service/AutoreplyService.java index 2d45364..feafb9f 100644 --- a/src/com/w1hd/zzhnc/service/AutoreplyService.java +++ b/src/com/w1hd/zzhnc/service/AutoreplyService.java @@ -74,21 +74,24 @@ public class AutoreplyService { Logger log = LoggerFactory.getLogger(AutoreplyService.class); @Autowired AutoreplyDao autoreplyDao; + List filterList; - static List filterList = Lists.newArrayList(); static boolean inited = false; public void init(boolean hard) { if (hard) { inited = false; - filterList = Lists.newArrayList(); + } init(); } public void init() { - if (inited) + if (inited) { return; + } + filterList = Lists.newArrayList(); + System.out.println("强制重新获得关键词"); Example example = new Example(Autoreply.class); example.createCriteria().andEqualTo("deleted", 0); List autoreplyList = autoreplyDao.selectByExample(example); @@ -96,6 +99,7 @@ public class AutoreplyService { String[] keys = e.getKeywords().split("\\|"); RegexKeywordFilter filter = new RegexKeywordFilter(); for (String key : keys) { + System.out.println("keys" + key); filter.add(key); } filter.compile(); @@ -107,26 +111,26 @@ public class AutoreplyService { @Autowired RedisTemplate redisTemplate; - - public Autoreply autoreply(String string) { + System.out.println("关键字查找 ————>" + string); List sets = Lists.newArrayList(); for (RegexKeywordFilter filter : filterList) { Set keys = Sets.newHashSet(); filter.replace(string, new ReplaceStrategy() { - + public String replaceWith(String keyword) { keys.add(keyword); sets.add(keys); + return ""; } }); } Collections.sort(sets, new Comparator() { - + public int compare(Set o1, Set o2) { if (o1.size() > o2.size()) { return -1; @@ -137,21 +141,38 @@ public class AutoreplyService { return 1; } }); + boolean eques = false; log.info("sets:{}", sets); - if (sets.isEmpty()) + + if (sets.isEmpty()) { return null; + } + + for (Set s : sets) { + if (s.contains(string)) { + eques = true; + } + } + List list = Lists.newArrayList(); - list.addAll(sets.get(0)); + Set set = sets.get(0); + if (!eques) { + list.addAll(sets.get(0)); + } else { + list.add(string); + } + List autoreplys = autoreplyDao.findByKeys(list, null); - if (autoreplys.isEmpty()) + if (autoreplys.isEmpty()) { return null; + } if (autoreplys.size() == 1) { return autoreplys.get(0); } Collections.sort(autoreplys, new Comparator() { - + public int compare(Autoreply o1, Autoreply o2) { if (o1.getSort() < o2.getSort()) { return -1; @@ -167,7 +188,6 @@ public class AutoreplyService { } - public PageResults getAutoReplyList(Integer page, String keyword, Boolean isRedirectStaff, Integer projectId) { Example example = new Example(Autoreply.class); @@ -220,7 +240,6 @@ public class AutoreplyService { return row > 0 ? "ok" : "添加失败,数据异常"; } - public String updateAutoReply(Integer id, String keywords, boolean isRedirectStaff, String content, Integer projectId, String projectName, Integer sort) { if (StringUtil.isZearoOrNull(id)) @@ -241,7 +260,6 @@ public class AutoreplyService { return row > 0 ? "ok" : "修改失败,数据异常"; } - public String deleteAutoReply(Integer id) { if (StringUtil.isZearoOrNull(id)) return "id 不能为空"; @@ -253,14 +271,12 @@ public class AutoreplyService { return row > 0 ? "ok" : "删除失败,数据异常"; } - public Autoreply getAutoReply(Integer id) { if (StringUtil.isZearoOrNull(id)) return null; return autoreplyDao.selectByPrimaryKey(id); } - public String KeywordsToString() { Example example = new Example(Autoreply.class); Example.Criteria criteria = example.createCriteria(); @@ -291,7 +307,7 @@ public class AutoreplyService { } public HashMap autoreply(String content, Integer projectId, String fromUserName) { - + Autoreply autoreply = null; if (autoreply == null) { autoreply = autoreply(content); diff --git a/src/com/w1hd/zzhnc/service/GoodsService.java b/src/com/w1hd/zzhnc/service/GoodsService.java index 4cc20be..6be2745 100644 --- a/src/com/w1hd/zzhnc/service/GoodsService.java +++ b/src/com/w1hd/zzhnc/service/GoodsService.java @@ -47,7 +47,7 @@ public class GoodsService { } goods.setDeleted(false); Goods old = goods(goods.getId()).getRows().get(0); - if(old!=null) { + if (old != null) { goods.setPageViews(old.getPageViews() + 1); } redisTemplate.delete(GOODSID_ + goods.getId()); @@ -59,17 +59,19 @@ public class GoodsService { @Autowired RedisTemplate redisTemplate; - public PageResults seacrh(Integer id, String key, Integer sellerId, Integer page, Integer size) { + public PageResults seacrh(Integer id, String key, Integer sellerId, Integer page, Integer size, + Integer sort) { 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)) { if ("副食".equals(key) || "小商品".equals(key) || "服装".equals(key) || "汽摩配件".equals(key)) { c.andEqualTo("categoryName", key); } else { - c.andCondition(" (description like \"%" + key + "%\" or name like \"%" + key +"%\" or seller_name like \"%" + key + "%\" or seller_address like \"%" + key +"%\" )"); + c.andCondition(" (description like \"%" + key + "%\" or name like \"%" + key + + "%\" or seller_name like \"%" + key + "%\" or seller_address like \"%" + key + "%\" )"); } } @@ -79,7 +81,21 @@ public class GoodsService { } c.andEqualTo("deleted", false); - ex.setOrderByClause("share_count desc,page_views desc,update_time desc"); + switch (sort) { + case 1:// 根据更新时间排序 + ex.setOrderByClause("update_time desc"); + break; + case 2:// 根据转发数排序 + ex.setOrderByClause("share_count desc"); + break; + case 3:// 根据浏览数排序 + ex.setOrderByClause("page_views desc"); + break; + default: + ex.setOrderByClause("update_time desc,share_count desc,page_views desc"); + break; + } + RowBounds row = new RowBounds((page - 1) * size, size); List list = goodsDao.selectByExampleAndRowBounds(ex, row); int count = goodsDao.selectCountByExample(ex); @@ -99,7 +115,7 @@ public class GoodsService { pageResults.setPageSize(10); List list = Lists.newArrayList(); Goods goods = (Goods) redisTemplate.opsForValue().get(GOODSID_ + id); - if(goods==null) { + if (goods == null) { goods = goodsDao.selectByPrimaryKey(id); } goods.setPageViews(goods.getPageViews() + 1); diff --git a/src/com/w1hd/zzhnc/service/PrizeService.java b/src/com/w1hd/zzhnc/service/PrizeService.java index 2757c33..676b809 100644 --- a/src/com/w1hd/zzhnc/service/PrizeService.java +++ b/src/com/w1hd/zzhnc/service/PrizeService.java @@ -13,10 +13,13 @@ import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.testng.collections.Lists; import org.testng.util.Strings; +import org.theyeasy.weixin.service.WxMiniService; +import org.theyeasy.weixin.util.WxMiniUtil; 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.CommonUtil; @@ -35,6 +38,7 @@ public class PrizeService { final String LotteryLogID_ = RedisUtil.PROJECTNAME.concat("_").concat("lotteryLog_");// 中奖记录 final String PRIZE_KILL_FANSID = RedisUtil.PROJECTNAME.concat("_").concat("PRIZE_KILL_FANSID_");// 保存粉丝中奖的日志 + final String PRIZE_KILL_FANSID_COUNT = RedisUtil.PROJECTNAME.concat("_").concat("PRIZE_KILL_FANSID_COUNT_");// 保存粉丝中奖的日志 @Autowired PrizeDao prizeDao; @@ -76,14 +80,9 @@ public class PrizeService { return prizeDao.deleteByPrimaryKey(id) > 0; } - /** - * 增加一条奖项记录 - * - * @return - */ - @SuppressWarnings("unchecked") - public Integer insert(Integer fansId, Integer pType, BigDecimal mny) { + public Integer insert(Integer fansId, Integer pType, BigDecimal mny, Integer status) { Activity setting = activityService.getActivitySetting(); + System.out.println("中奖id号:" + pType); Prize p = null; switch (pType) { case 1: @@ -126,7 +125,6 @@ public class PrizeService { p.setNum(p.getNum() - 1); setting.setP8(p); break; - default: break; } @@ -135,18 +133,23 @@ public class PrizeService { Lotterylog lotterylog = new Lotterylog(); lotterylog.setCreatedtime(new Date()); lotterylog.setFansid(fansId); - lotterylog.setMny(mny); lotterylog.setPrizeName(p.getName()); lotterylog.setPrizeId(pType); - if ("谢谢".equals(p.getName())) { + lotterylog.setMny(new BigDecimal(0)); + if (p.getName().startsWith("谢谢") || status == 3) { lotterylog.setStatus(3); } else { lotterylog.setStatus(1); - if (mny.doubleValue() > 1.0) { - lotterylog.setStatus(2); + if (mny.doubleValue() >= 1.0) { String order = creatOrder(fansId, (int) (mny.doubleValue() * 100)); System.out.println("抽中一个红包 >" + order); lotterylog.setPrizeUrl(order); + lotterylog.setMny(mny); + // lotterylog.setStatus(2); + // Fans fans = fansService.getFansById(fansId); + + // activityService.sendRedPackage(fans.getMiniopenid(), (int) (mny.doubleValue() + // * 100)); } } @@ -156,6 +159,19 @@ public class PrizeService { return lotterylog.getId(); } + /** + * 增加一条奖项记录 + * + * @return + */ + @SuppressWarnings("unchecked") + public Integer insert(Integer fansId, Integer pType, BigDecimal mny) { + return insert(fansId, pType, mny, -1); + } + + @Autowired + WxMiniService wxMiniService; + /** 获取我的奖品 */ public List getMyLotteryLog(Integer fansId) { @@ -170,6 +186,18 @@ public class PrizeService { return list; } + /** 获取我的红包奖品 */ + public List getMyMnyLog(Integer fansId) { + Example ex = new Example(Lotterylog.class); + Criteria c = ex.createCriteria(); + c.andEqualTo("fansid", fansId); + c.andEqualTo("status", 1); + c.andGreaterThan("mny", 0); + c.andIsNotNull("prizeUrl"); + List list = lotteryLogDao.selectByExample(ex); + return list; + } + /** 核销一个奖品记录 */ public Lotterylog updateLotteryLog(Integer id, Integer fansId) { Lotterylog lotterylog = lotteryLogDao.selectByPrimaryKey(id); @@ -186,8 +214,22 @@ public class PrizeService { RedisTemplate redisTemplate; public Integer changes(Integer fansId) { + Integer lotteryLog = (Integer) redisTemplate.opsForValue().get(PRIZE_KILL_FANSID + fansId); + if (fansId <= 10) { + Integer count = (Integer) redisTemplate.opsForValue().get(PRIZE_KILL_FANSID_COUNT + fansId); + if (count == null) { + count = 99; + } + if (count < 100) { + lotteryLog = null; + count = count - 1; + return count; + } + + } if (lotteryLog == null) { + return 1; } else { Activity activitySetting = activityService.getActivitySetting(); @@ -209,6 +251,14 @@ public class PrizeService { @SuppressWarnings("unchecked") public Integer randomKill(Integer fansId, Integer count) { + if (fansId <= 10) { + Integer changes = (Integer) redisTemplate.opsForValue().get(PRIZE_KILL_FANSID_COUNT + fansId); + if (changes == null) { + changes = 99; + } + changes--; + redisTemplate.opsForValue().set(PRIZE_KILL_FANSID_COUNT + fansId, changes); + } if (count == 8) { return 0; @@ -225,7 +275,7 @@ public class PrizeService { if (p != null) { sumNum += p.getNum(); sumPro += p.getProbability(); - if (p.getName().contains("谢谢")) { + if (!Strings.isNullOrEmpty(p.getName()) && p.getName().contains("谢谢")) { tmp = p; } } @@ -238,7 +288,7 @@ public class PrizeService { 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)); + logId = insert(fansId, tmp.getId(), new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP), 3); } } else { Prize p8 = activity.getP8(); @@ -318,18 +368,19 @@ public class PrizeService { public static String getAuthorizeUrl(String orderId, String activityId, int fansId) { String url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd06aec668fe359d1&redirect_uri=http://www.w1hd.com/api/wx/wxd06aec668fe359d1/payWxMpUser2/" - + orderId + "/" + activityId + "/nmamtf&response_type=code&scope=snsapi_userinfo&state=" + fansId + + orderId + "/" + activityId + "/nmamtf&response_type=code&scope=snsapi_base&state=" + fansId + "&component_appid=wx79ad5a35526f26fb&connect_redirect=1#wechat_redirect"; return url; } - public static String creatOrder(Integer fansId, Integer mny) { -// /** 测试的 */ -// String merchatId = "161"; -// String activityId = "1290"; + public String creatOrder(Integer fansId, Integer mny) { + // /** 测试的 */ + // String merchatId = "161"; + // String activityId = "1290"; + Fans fans = fansService.getFansById(fansId); /** 正式的 */ - String merchatId = "228"; - String activityId = "1444"; + String merchatId = "228"; + String activityId = "1444"; String sendGet = CommonUtil.sendGet("http://www.w1hd.com/api/wx/createOrder", "merchantid=" + merchatId + "&wxactivityId=" + activityId + "&mny=" + mny); @@ -342,8 +393,8 @@ public class PrizeService { return "fail"; } - return getAuthorizeUrl(map.get("data").toString(), activityId, fansId); - + String url = getAuthorizeUrl(map.get("data").toString(), activityId, fansId); + return url; } } diff --git a/src/org/theyeasy/weixin/service/WxMiniService.java b/src/org/theyeasy/weixin/service/WxMiniService.java index a76dc94..5dc85ed 100644 --- a/src/org/theyeasy/weixin/service/WxMiniService.java +++ b/src/org/theyeasy/weixin/service/WxMiniService.java @@ -46,12 +46,6 @@ public interface WxMiniService { public String getImgReply(); /** - * 用户进入聊天面板的欢迎语 - * @param first:是否获取第一次进入的欢迎语 - */ - public String getWelcome(boolean firstEnter); - - /** * 在小程序会话面板发送登录链接 * @param saleid * @param wxMiniOpenId diff --git a/src/org/theyeasy/weixin/service/impl/WxMiniServiceImpl.java b/src/org/theyeasy/weixin/service/impl/WxMiniServiceImpl.java index 52c01ce..1848ab3 100644 --- a/src/org/theyeasy/weixin/service/impl/WxMiniServiceImpl.java +++ b/src/org/theyeasy/weixin/service/impl/WxMiniServiceImpl.java @@ -68,7 +68,7 @@ public class WxMiniServiceImpl implements WxMiniService { ChatLogService chatLogService; @Autowired - AutoreplyService AutoreplyService; + AutoreplyService autoreplyService; @Autowired ActivityService activityService; @@ -180,56 +180,41 @@ public class WxMiniServiceImpl implements WxMiniService { ChatLogReplyType.自动回复, "", ""); Thread.sleep(1000); - Prize temp = null; Lotterylog log = null; /** 执行抽奖核心 */ Integer changes = prizeService.changes(fans.getId()); if (changes > 0) { + sussess = true; Integer randomKill = prizeService.randomKill(fans.getId(), 0); 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()) { - 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()); - - } - if (sussess) { // 已中奖 - 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.自动回复, "", ""); - } + // 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.自动回复, "", ""); + // } + + WxMiniUtil.sendCustomMsgText(fromUserName, + "恭喜获得[" + log.getPrizeName() + "] 请到【我的奖品出兑换奖品】"); + saveChatLog(fans.getId(), content, activitySetting.getReplySucceed(), fans.getGoodsId(), + ChatLogReplyType.自动回复, "", ""); return respMessage; } else { // 未中奖 @@ -252,10 +237,9 @@ public class WxMiniServiceImpl implements WxMiniService { return respMessage; } - HashMap data = AutoreplyService.autoreply(content, cache(toUserName), fromUserName); + HashMap data = autoreplyService.autoreply(content, 0, fromUserName); Autoreply auto = (Autoreply) data.get("autoreply"); - // 判断是否需要发送小程序卡片 add by lcc 2017-12-11 if (auto.getContents().startsWith("【发送小程序卡片】")) { Vo_msg vo = SendMiniProgram(fromUserName); System.out.println("发送小程序卡片:" + vo.msg); @@ -286,29 +270,30 @@ public class WxMiniServiceImpl implements WxMiniService { { // 保存进入会话时传入的参数 String sessionFrom = requestMap.get("SessionFrom"); - cache(fromUserName, getSessionFromValue(sessionFrom, 0)); String floorname = getSessionFromValue(sessionFrom, 1);// 楼盘名称 // 保存粉丝最后一次进入会话的时间 - boolean firstEnter = (fans.getLastEnterTime() == null); fans.setLastEnterTime(DateTime.now().toDate()); fansDao.updateByPrimaryKey(fans); - // 发送欢迎语 - String welcome = getWelcome(firstEnter); - if (firstEnter) { - // 如果红包活动正在进行中,发送红包活动的提醒文字 - Activity activitySetting = activityService.getActivitySetting(); - if (activitySetting != null - && activitySetting.getStatus() == ActivityStatus.RUNNING.getIndex()) { - welcome = activitySetting.getReplyWelcome(); +// for (int i = 1; i < 4; i++) { +// String welcome = getWelcome(1); +// +// sendResult = WxMiniUtil.sendCustomMsgText(fromUserName, welcome); +// saveChatLog(fans.getId(), "进入会话:" + floorname, welcome, fans.getGoodsId(), +// ChatLogReplyType.进入会话, "", ""); +// } + + List list = prizeService.getMyMnyLog(fans.getId()); + if(list!=null && !list.isEmpty()) { + for(Lotterylog l:list) { + WxMiniUtil.sendCustomMsgLink(fans.getMiniopenid(), "请领取红包", "年货会获得的红包,请尽快领取。过期无效。", l.getPrizeUrl(), + "http://mini.weiyisz.com/dvmini/res/images/redpackage.png"); + prizeService.updateLotteryLog(l.getId(), fans.getId()); } } + // 发送欢迎语 - sendResult = WxMiniUtil.sendCustomMsgText(fromUserName, welcome); - - saveChatLog(fans.getId(), "进入会话:" + floorname, welcome, fans.getGoodsId(), ChatLogReplyType.进入会话, - "", ""); } copyToWxkf = false; // 事件不要转发给客服系统。 } @@ -488,29 +473,9 @@ public class WxMiniServiceImpl implements WxMiniService { return reply; } - @Override - public String getWelcome(boolean firstEnter) { - String keyword = firstEnter ? "first_enter_session" : "second_enter_session"; - String reply = RedisUtil.get(keyword); - if (null == reply || reply.length() < 1) // redis中没有欢迎语 - { - Example example = new Example(Autoreply.class); - Criteria criteria = example.createCriteria(); - criteria.andEqualTo("keywords", keyword).andEqualTo("deleted", false); - List list = autoreplyDao.selectByExample(example); - if (null != list && list.size() > 0) { - reply = list.get(0).getContents(); - RedisUtil.set(keyword, reply, 60 * 5); // 在redis内存中保留5分钟 - } - } - - if (null == reply) - return ""; - - String[] randomMsg = reply.split("\\|"); - int index = WxMiniUtil.getRandom(randomMsg.length); - - return randomMsg[index]; + public String getWelcome(int index) { + Autoreply autoreply = autoreplyService.autoreply("welcome" + index); + return autoreply.getContents(); } @Override @@ -559,35 +524,11 @@ public class WxMiniServiceImpl implements WxMiniService { return new Vo_msg(0, null, result); } - public static void main(String[] arg) { - - } - public static String getAuthorizeUrl(String orderId, String activityId, int fansId) { - String url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd06aec668fe359d1&redirect_uri=http://www.w1hd.com/api/wx/wxd06aec668fe359d1/payWxMpUser2/" + orderId + "/" + activityId + "/nmamtf&response_type=code&scope=snsapi_userinfo&state=" + fansId + "&component_appid=wx79ad5a35526f26fb&connect_redirect=1#wechat_redirect"; return url; } - private void cache(String fromUserName, String projectId) { - System.out.println("当前进入的楼盘projectId:" + projectId); - if (Strings.isNullOrEmpty(projectId)) { - RedisUtil.set("zzhnc_cache_project_" + fromUserName, 0 + "", 30 * RedisUtil.EXRP_MINUTE); // Edit by lcc - } else { - RedisUtil.set("zzhnc_cache_project_" + fromUserName, projectId + "", 30 * RedisUtil.EXRP_MINUTE); - } - } - - private Integer cache(String fromUserName) { - String string = RedisUtil.get("zzhnc_cache_project_" + fromUserName); - if (Strings.isNullOrEmpty(string)) { - return 0; - } else { - return Integer.parseInt(string); - } - - } - }