Commit af2ce877 沈姿.前端(已离职)
2 个父辈 c18928b3 fc7befd4
mch_appid = wxbe75806d33ab8a2e mch_appid = wx64e56457ec5c6338
mchid = 1496014382 mchid = 1493581312
key = glSPm08OiR82CfXyZ3HQECFeiwS7np5t key = Bnzihl9t8zId5qKL70bmKDuUpPklMpXB
spbill_create_ip=127.0.0.1 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 \ No newline at end of file
cert_file=/theyeasy/weixin_cert/dvmini_apiclient_cert.p12
\ No newline at end of file \ No newline at end of file
...@@ -130,7 +130,7 @@ public class ActivityController extends BaseController { ...@@ -130,7 +130,7 @@ public class ActivityController extends BaseController {
@ResponseBody @ResponseBody
public Object lotterys(@RequestParam(value = "page", defaultValue = "1", required = false) Integer page, public Object lotterys(@RequestParam(value = "page", defaultValue = "1", required = false) Integer page,
@RequestParam(value = "pagesize", defaultValue = "10", required = false) Integer pagesize, @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 = "keyword", defaultValue = "", required = false) String keyword,
@RequestParam(value = "status", defaultValue = "1", required = false) Integer status) { @RequestParam(value = "status", defaultValue = "1", 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));
......
...@@ -106,4 +106,11 @@ public class AutoreplyController extends BaseController { ...@@ -106,4 +106,11 @@ public class AutoreplyController extends BaseController {
replyService.init(true); replyService.init(true);
return new Vo_msg(0, "ok"); 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 \ No newline at end of file
...@@ -51,8 +51,9 @@ public class GoodsController { ...@@ -51,8 +51,9 @@ public class GoodsController {
@RequestParam(value="id",required=false,defaultValue = "0")Integer id, @RequestParam(value="id",required=false,defaultValue = "0")Integer id,
@RequestParam(value="sellerId",required=false,defaultValue = "0")Integer sellerId, @RequestParam(value="sellerId",required=false,defaultValue = "0")Integer sellerId,
@RequestParam(value="page",required=false,defaultValue = "1")Integer page, @RequestParam(value="page",required=false,defaultValue = "1")Integer page,
@RequestParam(value="size",required=false,defaultValue = "10")Integer size) { @RequestParam(value="size",required=false,defaultValue = "10")Integer size,
return new Vo_msg(0,goodsService.seacrh(id,key,sellerId,page,size)); @RequestParam(value="sort",required=false,defaultValue = "1")Integer sort) {
return new Vo_msg(0,goodsService.seacrh(id,key,sellerId,page,size,sort));
} }
} }
...@@ -18,10 +18,12 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -18,10 +18,12 @@ 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.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable; 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.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.theyeasy.weixin.model.WxMiniSessionInfo; import org.theyeasy.weixin.model.WxMiniSessionInfo;
import org.theyeasy.weixin.service.WxMiniService; import org.theyeasy.weixin.service.WxMiniService;
import org.theyeasy.weixin.util.WxMiniUtil; import org.theyeasy.weixin.util.WxMiniUtil;
...@@ -293,7 +295,7 @@ public class WxMiniController extends BaseController { ...@@ -293,7 +295,7 @@ public class WxMiniController extends BaseController {
try { try {
Map<String, Object> result = Maps.newHashMap(); Map<String, Object> result = Maps.newHashMap();
List<Banner> bannerList = bannerService.getAll(); List<Banner> bannerList = bannerService.getAll();
PageResults<Goods> seacrh = goodsService.seacrh(null, key, null, page, size); PageResults<Goods> seacrh = goodsService.seacrh(null, key, null, page, size, 1);
List<Goods> rows = seacrh.getRows(); List<Goods> rows = seacrh.getRows();
result.put("banner", bannerList); result.put("banner", bannerList);
result.put("data", rows); result.put("data", rows);
...@@ -344,6 +346,9 @@ public class WxMiniController extends BaseController { ...@@ -344,6 +346,9 @@ public class WxMiniController extends BaseController {
public Object changes(@RequestParam(value = "openId") String openId) { public Object changes(@RequestParam(value = "openId") String openId) {
Fans fans = fansService.getFansByMiniOpenid(openId); Fans fans = fansService.getFansByMiniOpenid(openId);
Integer changes = prizeService.changes(fans.getId()); Integer changes = prizeService.changes(fans.getId());
if (changes < 0) {
changes = 0;
}
return new Vo_msg(0, changes); return new Vo_msg(0, changes);
} }
...@@ -382,7 +387,7 @@ public class WxMiniController extends BaseController { ...@@ -382,7 +387,7 @@ public class WxMiniController extends BaseController {
@RequestMapping(value = "/goods/{id}", method = RequestMethod.GET) @RequestMapping(value = "/goods/{id}", method = RequestMethod.GET)
@ResponseBody @ResponseBody
public Object goods(@RequestParam(value = "openId") String openId, @PathVariable(value = "id") Integer id) { public Object goods(@RequestParam(value = "openId") String openId, @PathVariable(value = "id") Integer id) {
PageResults<Goods> seacrh = goodsService.seacrh(id, null, null, null, null); PageResults<Goods> seacrh = goodsService.seacrh(id, null, null, null, null, 0);
return new Vo_msg(0, seacrh); return new Vo_msg(0, seacrh);
} }
...@@ -390,7 +395,7 @@ public class WxMiniController extends BaseController { ...@@ -390,7 +395,7 @@ public class WxMiniController extends BaseController {
@ResponseBody @ResponseBody
public Object goodsShare(@RequestParam(value = "openId") String openId, @PathVariable(value = "id") Integer id) { public Object goodsShare(@RequestParam(value = "openId") String openId, @PathVariable(value = "id") Integer id) {
if (id > 0) { if (id > 0) {
PageResults<Goods> seacrh = goodsService.seacrh(id, null, null, null, null); PageResults<Goods> seacrh = goodsService.seacrh(id, null, null, null, null, 0);
Goods goods = seacrh.getRows().get(0); Goods goods = seacrh.getRows().get(0);
goods.setShareCount(goods.getShareCount() + 1); goods.setShareCount(goods.getShareCount() + 1);
goodsService.update(goods); goodsService.update(goods);
...@@ -401,4 +406,16 @@ public class WxMiniController extends BaseController { ...@@ -401,4 +406,16 @@ public class WxMiniController extends BaseController {
return new Vo_msg(0, null); 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");
}
} }
...@@ -16,7 +16,9 @@ public class Lotterylog implements Serializable { ...@@ -16,7 +16,9 @@ public class Lotterylog implements Serializable {
private Integer fansid; private Integer fansid;
private String prizeName; private String prizeName;
private BigDecimal mny; private BigDecimal mny;
/** 1 未兑奖 2.已对奖 3.谢谢参与*/
private Integer status; private Integer status;
private Integer turn; private Integer turn;
private Integer prizeId; private Integer prizeId;
private Date createdtime; private Date createdtime;
......
...@@ -32,6 +32,9 @@ public class Prize implements Serializable { ...@@ -32,6 +32,9 @@ public class Prize implements Serializable {
} }
public Integer getProbability() { public Integer getProbability() {
if (probability == null) {
return 0;
}
return probability; return probability;
} }
......
...@@ -4,11 +4,14 @@ import java.math.BigDecimal; ...@@ -4,11 +4,14 @@ import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import org.hamcrest.core.IsInstanceOf;
import org.joda.time.DateTime;
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.testng.collections.Lists; import org.testng.collections.Lists;
import org.testng.util.Strings; import org.testng.util.Strings;
import org.theyeasy.weixin.service.WxPayService;
import com.w1hd.zzhnc.dao.LotteryLogDao; import com.w1hd.zzhnc.dao.LotteryLogDao;
import com.w1hd.zzhnc.enums.ActivityStatus; import com.w1hd.zzhnc.enums.ActivityStatus;
...@@ -33,6 +36,8 @@ public class ActivityService { ...@@ -33,6 +36,8 @@ public class ActivityService {
final String ACTIVITY_SETTING = RedisUtil.PROJECTNAME.concat("_").concat("ACTIVITY_SETTING");// 娲诲姩璁剧疆淇濆瓨key final String ACTIVITY_SETTING = RedisUtil.PROJECTNAME.concat("_").concat("ACTIVITY_SETTING");// 娲诲姩璁剧疆淇濆瓨key
final String SEND_REDPACKAGE_ID = RedisUtil.PROJECTNAME.concat("_").concat("SEND_REDPACKAGE_ID_");
@Autowired @Autowired
LotteryLogDao logDao; LotteryLogDao logDao;
...@@ -178,5 +183,20 @@ public class ActivityService { ...@@ -178,5 +183,20 @@ public class ActivityService {
return newArrayList; 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);
}
} }
...@@ -74,21 +74,24 @@ public class AutoreplyService { ...@@ -74,21 +74,24 @@ public class AutoreplyService {
Logger log = LoggerFactory.getLogger(AutoreplyService.class); Logger log = LoggerFactory.getLogger(AutoreplyService.class);
@Autowired @Autowired
AutoreplyDao autoreplyDao; AutoreplyDao autoreplyDao;
List<RegexKeywordFilter> filterList;
static List<RegexKeywordFilter> filterList = Lists.newArrayList();
static boolean inited = false; static boolean inited = false;
public void init(boolean hard) { public void init(boolean hard) {
if (hard) { if (hard) {
inited = false; inited = false;
filterList = Lists.newArrayList();
} }
init(); init();
} }
public void init() { public void init() {
if (inited) if (inited) {
return; return;
}
filterList = Lists.newArrayList();
System.out.println("强制重新获得关键词");
Example example = new Example(Autoreply.class); Example example = new Example(Autoreply.class);
example.createCriteria().andEqualTo("deleted", 0); example.createCriteria().andEqualTo("deleted", 0);
List<Autoreply> autoreplyList = autoreplyDao.selectByExample(example); List<Autoreply> autoreplyList = autoreplyDao.selectByExample(example);
...@@ -96,6 +99,7 @@ public class AutoreplyService { ...@@ -96,6 +99,7 @@ public class AutoreplyService {
String[] keys = e.getKeywords().split("\\|"); String[] keys = e.getKeywords().split("\\|");
RegexKeywordFilter filter = new RegexKeywordFilter(); RegexKeywordFilter filter = new RegexKeywordFilter();
for (String key : keys) { for (String key : keys) {
System.out.println("keys" + key);
filter.add(key); filter.add(key);
} }
filter.compile(); filter.compile();
...@@ -107,10 +111,9 @@ public class AutoreplyService { ...@@ -107,10 +111,9 @@ public class AutoreplyService {
@Autowired @Autowired
RedisTemplate<String, String> redisTemplate; RedisTemplate<String, String> redisTemplate;
public Autoreply autoreply(String string) { public Autoreply autoreply(String string) {
System.out.println("关键字查找 ————>" + string);
List<Set> sets = Lists.newArrayList(); List<Set> sets = Lists.newArrayList();
for (RegexKeywordFilter filter : filterList) { for (RegexKeywordFilter filter : filterList) {
...@@ -120,6 +123,7 @@ public class AutoreplyService { ...@@ -120,6 +123,7 @@ public class AutoreplyService {
public String replaceWith(String keyword) { public String replaceWith(String keyword) {
keys.add(keyword); keys.add(keyword);
sets.add(keys); sets.add(keys);
return ""; return "";
} }
}); });
...@@ -137,14 +141,31 @@ public class AutoreplyService { ...@@ -137,14 +141,31 @@ public class AutoreplyService {
return 1; return 1;
} }
}); });
boolean eques = false;
log.info("sets:{}", sets); log.info("sets:{}", sets);
if (sets.isEmpty())
if (sets.isEmpty()) {
return null; return null;
}
for (Set s : sets) {
if (s.contains(string)) {
eques = true;
}
}
List<String> list = Lists.newArrayList(); List<String> list = Lists.newArrayList();
Set<String> set = sets.get(0);
if (!eques) {
list.addAll(sets.get(0)); list.addAll(sets.get(0));
} else {
list.add(string);
}
List<Autoreply> autoreplys = autoreplyDao.findByKeys(list, null); List<Autoreply> autoreplys = autoreplyDao.findByKeys(list, null);
if (autoreplys.isEmpty()) if (autoreplys.isEmpty()) {
return null; return null;
}
if (autoreplys.size() == 1) { if (autoreplys.size() == 1) {
return autoreplys.get(0); return autoreplys.get(0);
...@@ -167,7 +188,6 @@ public class AutoreplyService { ...@@ -167,7 +188,6 @@ public class AutoreplyService {
} }
public PageResults<Autoreply> getAutoReplyList(Integer page, String keyword, Boolean isRedirectStaff, public PageResults<Autoreply> getAutoReplyList(Integer page, String keyword, Boolean isRedirectStaff,
Integer projectId) { Integer projectId) {
Example example = new Example(Autoreply.class); Example example = new Example(Autoreply.class);
...@@ -220,7 +240,6 @@ public class AutoreplyService { ...@@ -220,7 +240,6 @@ public class AutoreplyService {
return row > 0 ? "ok" : "添加失败,数据异常"; return row > 0 ? "ok" : "添加失败,数据异常";
} }
public String updateAutoReply(Integer id, String keywords, boolean isRedirectStaff, String content, public String updateAutoReply(Integer id, String keywords, boolean isRedirectStaff, String content,
Integer projectId, String projectName, Integer sort) { Integer projectId, String projectName, Integer sort) {
if (StringUtil.isZearoOrNull(id)) if (StringUtil.isZearoOrNull(id))
...@@ -241,7 +260,6 @@ public class AutoreplyService { ...@@ -241,7 +260,6 @@ public class AutoreplyService {
return row > 0 ? "ok" : "修改失败,数据异常"; return row > 0 ? "ok" : "修改失败,数据异常";
} }
public String deleteAutoReply(Integer id) { public String deleteAutoReply(Integer id) {
if (StringUtil.isZearoOrNull(id)) if (StringUtil.isZearoOrNull(id))
return "id 不能为空"; return "id 不能为空";
...@@ -253,14 +271,12 @@ public class AutoreplyService { ...@@ -253,14 +271,12 @@ public class AutoreplyService {
return row > 0 ? "ok" : "删除失败,数据异常"; return row > 0 ? "ok" : "删除失败,数据异常";
} }
public Autoreply getAutoReply(Integer id) { public Autoreply getAutoReply(Integer id) {
if (StringUtil.isZearoOrNull(id)) if (StringUtil.isZearoOrNull(id))
return null; return null;
return autoreplyDao.selectByPrimaryKey(id); return autoreplyDao.selectByPrimaryKey(id);
} }
public String KeywordsToString() { public String KeywordsToString() {
Example example = new Example(Autoreply.class); Example example = new Example(Autoreply.class);
Example.Criteria criteria = example.createCriteria(); Example.Criteria criteria = example.createCriteria();
......
...@@ -47,7 +47,7 @@ public class GoodsService { ...@@ -47,7 +47,7 @@ public class GoodsService {
} }
goods.setDeleted(false); goods.setDeleted(false);
Goods old = goods(goods.getId()).getRows().get(0); Goods old = goods(goods.getId()).getRows().get(0);
if(old!=null) { if (old != null) {
goods.setPageViews(old.getPageViews() + 1); goods.setPageViews(old.getPageViews() + 1);
} }
redisTemplate.delete(GOODSID_ + goods.getId()); redisTemplate.delete(GOODSID_ + goods.getId());
...@@ -59,17 +59,19 @@ public class GoodsService { ...@@ -59,17 +59,19 @@ public class GoodsService {
@Autowired @Autowired
RedisTemplate redisTemplate; RedisTemplate redisTemplate;
public PageResults<Goods> seacrh(Integer id, String key, Integer sellerId, Integer page, Integer size) { public PageResults<Goods> seacrh(Integer id, String key, Integer sellerId, Integer page, Integer size,
Integer sort) {
Example ex = new Example(Goods.class); Example ex = new Example(Goods.class);
Criteria c = ex.createCriteria(); Criteria c = ex.createCriteria();
if (id != null && id>0 ) { if (id != null && id > 0) {
return goods(id); return goods(id);
} else { } else {
if (!Strings.isNullOrEmpty(key)) { if (!Strings.isNullOrEmpty(key)) {
if ("副食".equals(key) || "小商品".equals(key) || "服装".equals(key) || "汽摩配件".equals(key)) { if ("副食".equals(key) || "小商品".equals(key) || "服装".equals(key) || "汽摩配件".equals(key)) {
c.andEqualTo("categoryName", key); c.andEqualTo("categoryName", key);
} else { } 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 { ...@@ -79,7 +81,21 @@ public class GoodsService {
} }
c.andEqualTo("deleted", false); 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); RowBounds row = new RowBounds((page - 1) * size, size);
List<Goods> list = goodsDao.selectByExampleAndRowBounds(ex, row); List<Goods> list = goodsDao.selectByExampleAndRowBounds(ex, row);
int count = goodsDao.selectCountByExample(ex); int count = goodsDao.selectCountByExample(ex);
...@@ -99,7 +115,7 @@ public class GoodsService { ...@@ -99,7 +115,7 @@ public class GoodsService {
pageResults.setPageSize(10); pageResults.setPageSize(10);
List<Goods> list = Lists.newArrayList(); List<Goods> list = Lists.newArrayList();
Goods goods = (Goods) redisTemplate.opsForValue().get(GOODSID_ + id); Goods goods = (Goods) redisTemplate.opsForValue().get(GOODSID_ + id);
if(goods==null) { if (goods == null) {
goods = goodsDao.selectByPrimaryKey(id); goods = goodsDao.selectByPrimaryKey(id);
} }
goods.setPageViews(goods.getPageViews() + 1); goods.setPageViews(goods.getPageViews() + 1);
......
...@@ -13,10 +13,13 @@ import org.springframework.data.redis.core.RedisTemplate; ...@@ -13,10 +13,13 @@ import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
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.util.WxMiniUtil;
import com.w1hd.zzhnc.dao.LotteryLogDao; import com.w1hd.zzhnc.dao.LotteryLogDao;
import com.w1hd.zzhnc.dao.PrizeDao; import com.w1hd.zzhnc.dao.PrizeDao;
import com.w1hd.zzhnc.model.Activity; import com.w1hd.zzhnc.model.Activity;
import com.w1hd.zzhnc.model.Fans;
import com.w1hd.zzhnc.model.Lotterylog; import com.w1hd.zzhnc.model.Lotterylog;
import com.w1hd.zzhnc.model.Prize; import com.w1hd.zzhnc.model.Prize;
import com.w1hd.zzhnc.util.CommonUtil; import com.w1hd.zzhnc.util.CommonUtil;
...@@ -35,6 +38,7 @@ public class PrizeService { ...@@ -35,6 +38,7 @@ public class PrizeService {
final String LotteryLogID_ = RedisUtil.PROJECTNAME.concat("_").concat("lotteryLog_");// 中奖记录 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 = RedisUtil.PROJECTNAME.concat("_").concat("PRIZE_KILL_FANSID_");// 保存粉丝中奖的日志
final String PRIZE_KILL_FANSID_COUNT = RedisUtil.PROJECTNAME.concat("_").concat("PRIZE_KILL_FANSID_COUNT_");// 保存粉丝中奖的日志
@Autowired @Autowired
PrizeDao prizeDao; PrizeDao prizeDao;
...@@ -76,14 +80,9 @@ public class PrizeService { ...@@ -76,14 +80,9 @@ public class PrizeService {
return prizeDao.deleteByPrimaryKey(id) > 0; return prizeDao.deleteByPrimaryKey(id) > 0;
} }
/** public Integer insert(Integer fansId, Integer pType, BigDecimal mny, Integer status) {
* 增加一条奖项记录
*
* @return
*/
@SuppressWarnings("unchecked")
public Integer insert(Integer fansId, Integer pType, BigDecimal mny) {
Activity setting = activityService.getActivitySetting(); Activity setting = activityService.getActivitySetting();
System.out.println("中奖id号:" + pType);
Prize p = null; Prize p = null;
switch (pType) { switch (pType) {
case 1: case 1:
...@@ -126,7 +125,6 @@ public class PrizeService { ...@@ -126,7 +125,6 @@ public class PrizeService {
p.setNum(p.getNum() - 1); p.setNum(p.getNum() - 1);
setting.setP8(p); setting.setP8(p);
break; break;
default: default:
break; break;
} }
...@@ -135,18 +133,23 @@ public class PrizeService { ...@@ -135,18 +133,23 @@ public class PrizeService {
Lotterylog lotterylog = new Lotterylog(); Lotterylog lotterylog = new Lotterylog();
lotterylog.setCreatedtime(new Date()); lotterylog.setCreatedtime(new Date());
lotterylog.setFansid(fansId); lotterylog.setFansid(fansId);
lotterylog.setMny(mny);
lotterylog.setPrizeName(p.getName()); lotterylog.setPrizeName(p.getName());
lotterylog.setPrizeId(pType); lotterylog.setPrizeId(pType);
if ("谢谢".equals(p.getName())) { lotterylog.setMny(new BigDecimal(0));
if (p.getName().startsWith("谢谢") || status == 3) {
lotterylog.setStatus(3); lotterylog.setStatus(3);
} else { } else {
lotterylog.setStatus(1); lotterylog.setStatus(1);
if (mny.doubleValue() > 1.0) { if (mny.doubleValue() >= 1.0) {
lotterylog.setStatus(2);
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.setStatus(2);
// Fans fans = fansService.getFansById(fansId);
// activityService.sendRedPackage(fans.getMiniopenid(), (int) (mny.doubleValue()
// * 100));
} }
} }
...@@ -156,6 +159,19 @@ public class PrizeService { ...@@ -156,6 +159,19 @@ public class PrizeService {
return lotterylog.getId(); 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<Lotterylog> getMyLotteryLog(Integer fansId) { public List<Lotterylog> getMyLotteryLog(Integer fansId) {
...@@ -170,6 +186,18 @@ public class PrizeService { ...@@ -170,6 +186,18 @@ public class PrizeService {
return list; return list;
} }
/** 获取我的红包奖品 */
public List<Lotterylog> 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<Lotterylog> list = lotteryLogDao.selectByExample(ex);
return list;
}
/** 核销一个奖品记录 */ /** 核销一个奖品记录 */
public Lotterylog updateLotteryLog(Integer id, Integer fansId) { public Lotterylog updateLotteryLog(Integer id, Integer fansId) {
Lotterylog lotterylog = lotteryLogDao.selectByPrimaryKey(id); Lotterylog lotterylog = lotteryLogDao.selectByPrimaryKey(id);
...@@ -186,8 +214,22 @@ public class PrizeService { ...@@ -186,8 +214,22 @@ public class PrizeService {
RedisTemplate redisTemplate; RedisTemplate redisTemplate;
public Integer changes(Integer fansId) { public Integer changes(Integer fansId) {
Integer lotteryLog = (Integer) redisTemplate.opsForValue().get(PRIZE_KILL_FANSID + 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) { if (lotteryLog == null) {
return 1; return 1;
} else { } else {
Activity activitySetting = activityService.getActivitySetting(); Activity activitySetting = activityService.getActivitySetting();
...@@ -209,6 +251,14 @@ public class PrizeService { ...@@ -209,6 +251,14 @@ public class PrizeService {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Integer randomKill(Integer fansId, Integer count) { 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) { if (count == 8) {
return 0; return 0;
...@@ -225,7 +275,7 @@ public class PrizeService { ...@@ -225,7 +275,7 @@ public class PrizeService {
if (p != null) { if (p != null) {
sumNum += p.getNum(); sumNum += p.getNum();
sumPro += p.getProbability(); sumPro += p.getProbability();
if (p.getName().contains("谢谢")) { if (!Strings.isNullOrEmpty(p.getName()) && p.getName().contains("谢谢")) {
tmp = p; tmp = p;
} }
} }
...@@ -238,7 +288,7 @@ public class PrizeService { ...@@ -238,7 +288,7 @@ public class PrizeService {
if (tmp.getIsMoney()) { if (tmp.getIsMoney()) {
mny = RandomUtils.nextInt(tmp.getMixMoney(), tmp.getMaxMoney()); 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 { } else {
Prize p8 = activity.getP8(); Prize p8 = activity.getP8();
...@@ -318,15 +368,16 @@ public class PrizeService { ...@@ -318,15 +368,16 @@ public class PrizeService {
public static String getAuthorizeUrl(String orderId, String activityId, int fansId) { 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/" 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"; + "&component_appid=wx79ad5a35526f26fb&connect_redirect=1#wechat_redirect";
return url; return url;
} }
public static String creatOrder(Integer fansId, Integer mny) { public String creatOrder(Integer fansId, Integer mny) {
// /** 测试的 */ // /** 测试的 */
// String merchatId = "161"; // String merchatId = "161";
// String activityId = "1290"; // String activityId = "1290";
Fans fans = fansService.getFansById(fansId);
/** 正式的 */ /** 正式的 */
String merchatId = "228"; String merchatId = "228";
String activityId = "1444"; String activityId = "1444";
...@@ -342,8 +393,8 @@ public class PrizeService { ...@@ -342,8 +393,8 @@ public class PrizeService {
return "fail"; return "fail";
} }
return getAuthorizeUrl(map.get("data").toString(), activityId, fansId); String url = getAuthorizeUrl(map.get("data").toString(), activityId, fansId);
return url;
} }
} }
...@@ -46,12 +46,6 @@ public interface WxMiniService { ...@@ -46,12 +46,6 @@ public interface WxMiniService {
public String getImgReply(); public String getImgReply();
/** /**
* 用户进入聊天面板的欢迎语
* @param first:是否获取第一次进入的欢迎语
*/
public String getWelcome(boolean firstEnter);
/**
* 在小程序会话面板发送登录链接 * 在小程序会话面板发送登录链接
* @param saleid * @param saleid
* @param wxMiniOpenId * @param wxMiniOpenId
......
...@@ -68,7 +68,7 @@ public class WxMiniServiceImpl implements WxMiniService { ...@@ -68,7 +68,7 @@ public class WxMiniServiceImpl implements WxMiniService {
ChatLogService chatLogService; ChatLogService chatLogService;
@Autowired @Autowired
AutoreplyService AutoreplyService; AutoreplyService autoreplyService;
@Autowired @Autowired
ActivityService activityService; ActivityService activityService;
...@@ -180,56 +180,41 @@ public class WxMiniServiceImpl implements WxMiniService { ...@@ -180,56 +180,41 @@ public class WxMiniServiceImpl implements WxMiniService {
ChatLogReplyType.自动回复, "", ""); ChatLogReplyType.自动回复, "", "");
Thread.sleep(1000); Thread.sleep(1000);
Prize temp = null;
Lotterylog log = null; Lotterylog log = null;
/** 执行抽奖核心 */ /** 执行抽奖核心 */
Integer changes = prizeService.changes(fans.getId()); Integer changes = prizeService.changes(fans.getId());
if (changes > 0) { if (changes > 0) {
sussess = true;
Integer randomKill = prizeService.randomKill(fans.getId(), 0); Integer randomKill = prizeService.randomKill(fans.getId(), 0);
log = prizeService.getLog(randomKill); 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 (sussess) { // 已中奖
if (temp.getIsMoney()) { // if (temp.getIsMoney()) {
RedisUtil.set("zzhnc_lottery_fansid_" + fans.getId(), "1", 10 * 60); // RedisUtil.set("zzhnc_lottery_fansid_" + fans.getId(), "1", 10 * 60);
// 发送中奖提示语 // // 发送中奖提示语
WxMiniUtil.sendCustomMsgText(fromUserName, activitySetting.getReplySucceed()); // WxMiniUtil.sendCustomMsgText(fromUserName,
saveChatLog(fans.getId(), content, activitySetting.getReplySucceed(), fans.getGoodsId(), // activitySetting.getReplySucceed());
ChatLogReplyType.自动回复, "", ""); // saveChatLog(fans.getId(), content, activitySetting.getReplySucceed(),
// 推送中奖链接 // fans.getGoodsId(),
String url = "http://mini.weiyisz.com/zzhnc/wx/redpackage?mny=" + mny * 0.01; // ChatLogReplyType.自动回复, "", "");
WxMiniUtil.sendCustomMsgLink(fromUserName, activitySetting.getLotteryTitle(), // // 推送中奖链接
activitySetting.getLotterySubTitle(), url, // String url = "http://mini.weiyisz.com/zzhnc/wx/redpackage?mny=" + mny * 0.01;
"http://mini.weiyisz.com/zzhnc/res/images/redpackage.png"); // WxMiniUtil.sendCustomMsgLink(fromUserName, activitySetting.getLotteryTitle(),
} else { // 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, WxMiniUtil.sendCustomMsgText(fromUserName,
"恭喜获得[" + temp.getName() + "] 请到【我的奖品出兑换奖品】"); "恭喜获得[" + log.getPrizeName() + "] 请到【我的奖品出兑换奖品】");
saveChatLog(fans.getId(), content, activitySetting.getReplySucceed(), fans.getGoodsId(), saveChatLog(fans.getId(), content, activitySetting.getReplySucceed(), fans.getGoodsId(),
ChatLogReplyType.自动回复, "", ""); ChatLogReplyType.自动回复, "", "");
}
return respMessage; return respMessage;
} else { // 未中奖 } else { // 未中奖
...@@ -252,10 +237,9 @@ public class WxMiniServiceImpl implements WxMiniService { ...@@ -252,10 +237,9 @@ public class WxMiniServiceImpl implements WxMiniService {
return respMessage; return respMessage;
} }
HashMap<Object, Object> data = AutoreplyService.autoreply(content, cache(toUserName), fromUserName); HashMap<Object, Object> data = autoreplyService.autoreply(content, 0, fromUserName);
Autoreply auto = (Autoreply) data.get("autoreply"); Autoreply auto = (Autoreply) data.get("autoreply");
// 判断是否需要发送小程序卡片 add by lcc 2017-12-11
if (auto.getContents().startsWith("【发送小程序卡片】")) { if (auto.getContents().startsWith("【发送小程序卡片】")) {
Vo_msg vo = SendMiniProgram(fromUserName); Vo_msg vo = SendMiniProgram(fromUserName);
System.out.println("发送小程序卡片:" + vo.msg); System.out.println("发送小程序卡片:" + vo.msg);
...@@ -286,29 +270,30 @@ public class WxMiniServiceImpl implements WxMiniService { ...@@ -286,29 +270,30 @@ public class WxMiniServiceImpl implements WxMiniService {
{ {
// 保存进入会话时传入的参数 // 保存进入会话时传入的参数
String sessionFrom = requestMap.get("SessionFrom"); String sessionFrom = requestMap.get("SessionFrom");
cache(fromUserName, getSessionFromValue(sessionFrom, 0));
String floorname = getSessionFromValue(sessionFrom, 1);// 楼盘名称 String floorname = getSessionFromValue(sessionFrom, 1);// 楼盘名称
// 保存粉丝最后一次进入会话的时间 // 保存粉丝最后一次进入会话的时间
boolean firstEnter = (fans.getLastEnterTime() == null);
fans.setLastEnterTime(DateTime.now().toDate()); fans.setLastEnterTime(DateTime.now().toDate());
fansDao.updateByPrimaryKey(fans); fansDao.updateByPrimaryKey(fans);
// 发送欢迎语 // for (int i = 1; i < 4; i++) {
String welcome = getWelcome(firstEnter); // String welcome = getWelcome(1);
if (firstEnter) { //
// 如果红包活动正在进行中,发送红包活动的提醒文字 // sendResult = WxMiniUtil.sendCustomMsgText(fromUserName, welcome);
Activity activitySetting = activityService.getActivitySetting(); // saveChatLog(fans.getId(), "进入会话:" + floorname, welcome, fans.getGoodsId(),
if (activitySetting != null // ChatLogReplyType.进入会话, "", "");
&& activitySetting.getStatus() == ActivityStatus.RUNNING.getIndex()) { // }
welcome = activitySetting.getReplyWelcome();
List<Lotterylog> 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; // 事件不要转发给客服系统。 copyToWxkf = false; // 事件不要转发给客服系统。
} }
...@@ -488,29 +473,9 @@ public class WxMiniServiceImpl implements WxMiniService { ...@@ -488,29 +473,9 @@ public class WxMiniServiceImpl implements WxMiniService {
return reply; return reply;
} }
@Override public String getWelcome(int index) {
public String getWelcome(boolean firstEnter) { Autoreply autoreply = autoreplyService.autoreply("welcome" + index);
String keyword = firstEnter ? "first_enter_session" : "second_enter_session"; return autoreply.getContents();
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<Autoreply> 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];
} }
@Override @Override
...@@ -559,35 +524,11 @@ public class WxMiniServiceImpl implements WxMiniService { ...@@ -559,35 +524,11 @@ public class WxMiniServiceImpl implements WxMiniService {
return new Vo_msg(0, null, result); return new Vo_msg(0, null, result);
} }
public static void main(String[] arg) {
}
public static String getAuthorizeUrl(String orderId, String activityId, int fansId) { 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/" 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_userinfo&state=" + fansId
+ "&component_appid=wx79ad5a35526f26fb&connect_redirect=1#wechat_redirect"; + "&component_appid=wx79ad5a35526f26fb&connect_redirect=1#wechat_redirect";
return url; 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);
}
}
} }
Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
请先完成此消息的编辑!