修改红包发放功能

1 个父辈 fdd6d1b0
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
......@@ -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
......@@ -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<String, Object> result = Maps.newHashMap();
List<Banner> bannerList = bannerService.getAll();
PageResults<Goods> seacrh = goodsService.seacrh(null, key, null, page, size,1);
PageResults<Goods> seacrh = goodsService.seacrh(null, key, null, page, size, 1);
List<Goods> 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<Goods> seacrh = goodsService.seacrh(id, null, null, null, null,0);
PageResults<Goods> 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<Goods> seacrh = goodsService.seacrh(id, null, null, null, null,0);
PageResults<Goods> 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");
}
}
......@@ -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;
......
......@@ -32,6 +32,9 @@ public class Prize implements Serializable {
}
public Integer getProbability() {
if (probability == null) {
return 0;
}
return probability;
}
......
......@@ -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<Prize> getPrizeList() {
Activity setting = getActivitySetting();
List<Prize> 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);
}
}
......@@ -74,21 +74,24 @@ public class AutoreplyService {
Logger log = LoggerFactory.getLogger(AutoreplyService.class);
@Autowired
AutoreplyDao autoreplyDao;
List<RegexKeywordFilter> filterList;
static List<RegexKeywordFilter> 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<Autoreply> 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<String, String> redisTemplate;
public Autoreply autoreply(String string) {
System.out.println("关键字查找 ————>" + string);
List<Set> sets = Lists.newArrayList();
for (RegexKeywordFilter filter : filterList) {
Set<String> 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<Set>() {
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<String> list = Lists.newArrayList();
list.addAll(sets.get(0));
Set<String> set = sets.get(0);
if (!eques) {
list.addAll(sets.get(0));
} else {
list.add(string);
}
List<Autoreply> 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<Autoreply>() {
public int compare(Autoreply o1, Autoreply o2) {
if (o1.getSort() < o2.getSort()) {
return -1;
......@@ -167,7 +188,6 @@ public class AutoreplyService {
}
public PageResults<Autoreply> 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<Object, Object> autoreply(String content, Integer projectId, String fromUserName) {
Autoreply autoreply = null;
if (autoreply == null) {
autoreply = autoreply(content);
......
......@@ -38,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;
......@@ -79,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:
......@@ -140,16 +136,20 @@ public class PrizeService {
lotterylog.setPrizeName(p.getName());
lotterylog.setPrizeId(pType);
lotterylog.setMny(new BigDecimal(0));
if ("谢谢".equals(p.getName())) {
if (p.getName().startsWith("谢谢") || status == 3) {
lotterylog.setStatus(3);
} else {
lotterylog.setStatus(1);
if (mny.doubleValue() >= 1.0) {
lotterylog.setStatus(2);
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));
}
}
......@@ -159,10 +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<Lotterylog> getMyLotteryLog(Integer fansId) {
......@@ -177,6 +186,18 @@ public class PrizeService {
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) {
Lotterylog lotterylog = lotteryLogDao.selectByPrimaryKey(id);
......@@ -196,10 +217,19 @@ public class PrizeService {
Integer lotteryLog = (Integer) redisTemplate.opsForValue().get(PRIZE_KILL_FANSID + fansId);
if (fansId <= 10) {
lotteryLog = null;
}
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();
......@@ -221,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;
......@@ -237,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;
}
}
......@@ -250,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();
......@@ -330,12 +368,12 @@ 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 String creatOrder(Integer fansId, Integer mny) {
public String creatOrder(Integer fansId, Integer mny) {
// /** 测试的 */
// String merchatId = "161";
// String activityId = "1290";
......@@ -355,9 +393,7 @@ public class PrizeService {
return "fail";
}
String url = getAuthorizeUrl(map.get("data").toString(), activityId, fansId);
WxMiniUtil.sendCustomMsgLink(fans.getMiniopenid(), "点我领红包", "点这里!点这里!点这里进行抽奖!", url,
"http://mini.weiyisz.com/dvmini/res/images/hongbao.png");
String url = getAuthorizeUrl(map.get("data").toString(), activityId, fansId);
return url;
}
......
......@@ -276,14 +276,22 @@ public class WxMiniServiceImpl implements WxMiniService {
fans.setLastEnterTime(DateTime.now().toDate());
fansDao.updateByPrimaryKey(fans);
for (int i = 1; i < 4; i++) {
String welcome = getWelcome(i);
sendResult = WxMiniUtil.sendCustomMsgText(fromUserName, welcome);
saveChatLog(fans.getId(), "进入会话:" + floorname, welcome, fans.getGoodsId(),
ChatLogReplyType.进入会话, "", "");
// 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<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());
}
}
// 发送欢迎语
}
......@@ -516,12 +524,7 @@ 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";
......
Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
请先完成此消息的编辑!