添加粉丝配置数量

1 个父辈 980ac755
...@@ -100,14 +100,16 @@ public class WxMiniController extends BaseController { ...@@ -100,14 +100,16 @@ public class WxMiniController extends BaseController {
@RequestMapping(value = "/login", method = RequestMethod.GET) // 购房助手登录 double lng,double lat @RequestMapping(value = "/login", method = RequestMethod.GET) // 购房助手登录 double lng,double lat
public @ResponseBody Vo_msg login(@RequestParam(value = "code") String code, public @ResponseBody Vo_msg login(@RequestParam(value = "code") String code,
@RequestParam(value = "shareId") Integer shareId, @RequestParam(value = "nickname") String nickname, @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 = "logo") String logo, @RequestParam(value = "lng") double lng,
@RequestParam(value = "lat") double lat) { @RequestParam(value = "lat") double lat) {
logger.info("小程序登录:code=" + code); logger.info("小程序登录:code=" + code);
// 取openid // 取openid
WxMiniSessionInfo sessionInfo = WxMiniUtil.jscode2session(code); 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) { if (fans != null) {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("miniOpenId", sessionInfo.getOpenid()); map.put("miniOpenId", sessionInfo.getOpenid());
...@@ -316,12 +318,12 @@ public class WxMiniController extends BaseController { ...@@ -316,12 +318,12 @@ public class WxMiniController extends BaseController {
@ResponseBody @ResponseBody
public Object prizesKill(@RequestParam(value = "openId") String openId) { public Object prizesKill(@RequestParam(value = "openId") String openId) {
Fans fans = fansService.getFansByMiniOpenid(openId); Fans fans = fansService.getFansByMiniOpenid(openId);
Integer logId = prizeService.randomKill(fans.getId()); Integer logId = prizeService.randomKill(fans.getId(),0);
if(logId == 0) { if (logId == 0) {
return new Vo_msg(-1, null,"不好意思你没中奖"); return new Vo_msg(-1, null, "不好意思你没中奖");
} }
if(logId ==-1) { if (logId == -1) {
return new Vo_msg(-1, null,"你已经中过奖了"); return new Vo_msg(-1, null, "你已经中过奖了");
} }
Lotterylog log = prizeService.getLog(logId); Lotterylog log = prizeService.getLog(logId);
return new Vo_msg(0, log); return new Vo_msg(0, log);
...@@ -351,4 +353,17 @@ public class WxMiniController extends BaseController { ...@@ -351,4 +353,17 @@ public class WxMiniController extends BaseController {
return new Vo_msg(0, seacrh); 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) {
PageResults<Goods> 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, seacrh);
}
} }
...@@ -25,7 +25,7 @@ public class Activity implements Serializable { ...@@ -25,7 +25,7 @@ public class Activity implements Serializable {
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date endTime;// 活动结束时间 private Date endTime;// 活动结束时间
private int shareCount; // 下属粉丝达到一定数量可以再次抽奖
private int status;// 活动状态 private int status;// 活动状态
private BigDecimal planMny;// 发放红包预算 private BigDecimal planMny;// 发放红包预算
private BigDecimal currentMny; private BigDecimal currentMny;
...@@ -295,5 +295,12 @@ public class Activity implements Serializable { ...@@ -295,5 +295,12 @@ public class Activity implements Serializable {
this.p8 = p8; this.p8 = p8;
} }
public int getShareCount() {
return shareCount;
}
public void setShareCount(int shareCount) {
this.shareCount = shareCount;
}
} }
\ No newline at end of file \ No newline at end of file
package com.w1hd.zzhnc.model; package com.w1hd.zzhnc.model;
import java.io.Serializable;
import java.util.Date; import java.util.Date;
import javax.persistence.Id; import javax.persistence.Id;
import org.joda.time.DateTime; import org.joda.time.DateTime;
public class Fans { public class Fans implements Serializable{
/**
*
*/
private static final long serialVersionUID = -418002994563516320L;
@Id @Id
private Integer id; private Integer id;
...@@ -44,6 +50,8 @@ public class Fans { ...@@ -44,6 +50,8 @@ public class Fans {
private boolean readed=false; private boolean readed=false;
private String remarkName; private String remarkName;
private Integer shareCount;
public Integer getId() { public Integer getId() {
return id; return id;
} }
...@@ -213,9 +221,12 @@ public class Fans { ...@@ -213,9 +221,12 @@ public class Fans {
this.remarkName = remarkName; this.remarkName = remarkName;
} }
public Integer getShareCount() {
return shareCount;
}
public void setShareCount(Integer shareCount) {
this.shareCount = shareCount;
}
} }
\ No newline at end of file \ No newline at end of file
...@@ -4,6 +4,7 @@ import java.util.List; ...@@ -4,6 +4,7 @@ import java.util.List;
import org.apache.ibatis.session.RowBounds; import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.theyeasy.weixin.model.WxMiniSessionInfo; import org.theyeasy.weixin.model.WxMiniSessionInfo;
import org.theyeasy.weixin.util.CusAccessObjectUtil2; import org.theyeasy.weixin.util.CusAccessObjectUtil2;
...@@ -14,6 +15,7 @@ import com.w1hd.zzhnc.dao.FansDao; ...@@ -14,6 +15,7 @@ import com.w1hd.zzhnc.dao.FansDao;
import com.w1hd.zzhnc.model.Fans; import com.w1hd.zzhnc.model.Fans;
import com.w1hd.zzhnc.util.CommonUtil; import com.w1hd.zzhnc.util.CommonUtil;
import com.w1hd.zzhnc.util.PageResults; import com.w1hd.zzhnc.util.PageResults;
import com.w1hd.zzhnc.util.RedisUtil;
import jodd.util.URLDecoder; import jodd.util.URLDecoder;
import tk.mybatis.mapper.entity.Example; import tk.mybatis.mapper.entity.Example;
...@@ -29,14 +31,15 @@ import tk.mybatis.mapper.entity.Example.Criteria; ...@@ -29,14 +31,15 @@ import tk.mybatis.mapper.entity.Example.Criteria;
@Service @Service
public class FansService { public class FansService {
public static final String FANS_KEY_OPENID = RedisUtil.PROJECTNAME.concat("_").concat("FANS_KEY_OPENID_");
@Autowired @Autowired
FansDao fansDao; FansDao fansDao;
public PageResults<Fans> getFansList(Integer page, String keyword) { public PageResults<Fans> getFansList(Integer page, String keyword) {
Example ex = new Example(Fans.class); Example ex = new Example(Fans.class);
Criteria criteria = ex.createCriteria(); Criteria criteria = ex.createCriteria();
if(!Strings.isNullOrEmpty(keyword)) { if (!Strings.isNullOrEmpty(keyword)) {
criteria.andCondition(" ( nickname like \"%" + keyword +"%\")"); criteria.andCondition(" ( nickname like \"%" + keyword + "%\")");
} }
RowBounds row = new RowBounds((page - 1) * 10, 10); RowBounds row = new RowBounds((page - 1) * 10, 10);
List<Fans> list = fansDao.selectByExampleAndRowBounds(ex, row); List<Fans> list = fansDao.selectByExampleAndRowBounds(ex, row);
...@@ -49,14 +52,24 @@ public class FansService { ...@@ -49,14 +52,24 @@ public class FansService {
return pageresult; return pageresult;
} }
@Autowired
RedisTemplate redisTemplate;
@SuppressWarnings("unchecked")
public Fans getFansByMiniOpenid(String miniOpenid) { public Fans getFansByMiniOpenid(String miniOpenid) {
Example example = new Example(Fans.class);
example.createCriteria().andEqualTo("miniopenid", miniOpenid); Fans fans = (Fans) redisTemplate.opsForValue().get(FANS_KEY_OPENID + miniOpenid);
List<Fans> list = fansDao.selectByExample(example); if (fans == null) {
if (list != null && list.size() > 0) { Example example = new Example(Fans.class);
return list.get(0); example.createCriteria().andEqualTo("miniopenid", miniOpenid);
List<Fans> 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) { public Fans getFansById(Integer id) {
...@@ -77,13 +90,14 @@ public class FansService { ...@@ -77,13 +90,14 @@ public class FansService {
fans.setLogo(""); fans.setLogo("");
fans.setNickname(""); fans.setNickname("");
fans.setParentfansid(0); fans.setParentfansid(0);
fans.setShareCount(0);
int flag = fansDao.insertSelective(fans); int flag = fansDao.insertSelective(fans);
return fans;// 插入成功后会返回新的id; return fans;// 插入成功后会返回新的id;
} }
public Fans addFans(WxMiniSessionInfo info, Integer shareFansId, String nickname, String logo, double lng, public Fans addFans(WxMiniSessionInfo info, Integer shareFansId, String nickname, String logo, double lng,
double lat) { double lat, Integer fansId) {
if (info == null) if (info == null)
return null; return null;
...@@ -108,6 +122,7 @@ public class FansService { ...@@ -108,6 +122,7 @@ public class FansService {
fans.setFanstype(1); fans.setFanstype(1);
fans.setLng(lng); fans.setLng(lng);
fans.setLat(lat); fans.setLat(lat);
fans.setParentfansid(fansId);
JSONObject locationResult = CusAccessObjectUtil2.locationResult(lng, lat); JSONObject locationResult = CusAccessObjectUtil2.locationResult(lng, lat);
if (null != locationResult) { if (null != locationResult) {
fans.setProvince(CusAccessObjectUtil2.getProvince(locationResult)); fans.setProvince(CusAccessObjectUtil2.getProvince(locationResult));
...@@ -133,16 +148,28 @@ public class FansService { ...@@ -133,16 +148,28 @@ public class FansService {
fansDao.updateByPrimaryKeySelective(fans); fansDao.updateByPrimaryKeySelective(fans);
} }
} catch (Exception e) { } catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
System.out.println("新增粉丝失败:" + e.getMessage());
return null; return null;
} }
return fans; return fans;
} }
@SuppressWarnings("unchecked")
public void updateFans(Fans fans) { public void updateFans(Fans fans) {
redisTemplate.delete(FANS_KEY_OPENID + fans.getMiniopenid());
fansDao.updateByPrimaryKeySelective(fans); 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;
}
} }
...@@ -125,6 +125,7 @@ public class PrizeService { ...@@ -125,6 +125,7 @@ public class PrizeService {
default: default:
break; break;
} }
setting.setCurrentMny(setting.getCurrentMny().add(mny));
activityService.updateActivity(setting); activityService.updateActivity(setting);
Lotterylog lotterylog = new Lotterylog(); Lotterylog lotterylog = new Lotterylog();
lotterylog.setCreatedtime(new Date()); lotterylog.setCreatedtime(new Date());
...@@ -169,7 +170,9 @@ public class PrizeService { ...@@ -169,7 +170,9 @@ public class PrizeService {
RedisTemplate redisTemplate; RedisTemplate redisTemplate;
@SuppressWarnings("unchecked") @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); Integer lotteryLog = (Integer) redisTemplate.opsForValue().get(PRIZE_KILL_FANSID + fansId);
if (lotteryLog == null) { if (lotteryLog == null) {
Activity activity = activityService.getActivitySetting(); Activity activity = activityService.getActivitySetting();
...@@ -258,7 +261,7 @@ public class PrizeService { ...@@ -258,7 +261,7 @@ public class PrizeService {
logId = insert(fansId, 8, new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP)); logId = insert(fansId, 8, new BigDecimal(mny * 0.01).setScale(2, RoundingMode.HALF_UP));
} else { } else {
if (sumNum > 0) { if (sumNum > 0) {
return randomKill(fansId); return randomKill(fansId, count++);
} }
} }
} }
......
package org.theyeasy.weixin.service.impl; package org.theyeasy.weixin.service.impl;
import java.lang.reflect.Method;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.Collections; import java.util.Collections;
...@@ -42,6 +43,7 @@ import com.w1hd.zzhnc.service.ActivityService; ...@@ -42,6 +43,7 @@ import com.w1hd.zzhnc.service.ActivityService;
import com.w1hd.zzhnc.service.AutoreplyService; import com.w1hd.zzhnc.service.AutoreplyService;
import com.w1hd.zzhnc.service.ChatLogService; import com.w1hd.zzhnc.service.ChatLogService;
import com.w1hd.zzhnc.service.FansService; import com.w1hd.zzhnc.service.FansService;
import com.w1hd.zzhnc.service.PrizeService;
import com.w1hd.zzhnc.util.CommonUtil; import com.w1hd.zzhnc.util.CommonUtil;
import com.w1hd.zzhnc.util.JsonMapper; import com.w1hd.zzhnc.util.JsonMapper;
import com.w1hd.zzhnc.util.QQFaceUtil; import com.w1hd.zzhnc.util.QQFaceUtil;
...@@ -82,6 +84,8 @@ public class WxMiniServiceImpl implements WxMiniService { ...@@ -82,6 +84,8 @@ public class WxMiniServiceImpl implements WxMiniService {
@Autowired @Autowired
WxPayService wxPayService; WxPayService wxPayService;
@Autowired
PrizeService prizeService;
@Override @Override
public String processRequest(HttpServletRequest request) { public String processRequest(HttpServletRequest request) {
...@@ -102,9 +106,6 @@ public class WxMiniServiceImpl implements WxMiniService { ...@@ -102,9 +106,6 @@ public class WxMiniServiceImpl implements WxMiniService {
// 消息时间 // 消息时间
String msgTime = requestMap.get("CreateTime"); String msgTime = requestMap.get("CreateTime");
/****************
* 微信消息去重处理(重要!!!服务器繁忙时微信会重复3次推送同一条消息 add by lcc 2017-10-30
****************************/
String key = "WxMiniMsgKey_"; String key = "WxMiniMsgKey_";
key += fromUserName + msgTime; key += fromUserName + msgTime;
...@@ -121,25 +122,16 @@ public class WxMiniServiceImpl implements WxMiniService { ...@@ -121,25 +122,16 @@ public class WxMiniServiceImpl implements WxMiniService {
fans = fansService.addFans(fromUserName); fans = fansService.addFans(fromUserName);
System.out.println("会话事件中添加了粉丝,id=" + fans.getId()); System.out.println("会话事件中添加了粉丝,id=" + fans.getId());
} }
int saleid = fans.getGoodsId(); int goodsId = fans.getGoodsId();
if (saleid < 1) // 没有销售的就分配一个万小二给他。
{
fansDao.updateByPrimaryKeySelective(fans);
}
String sendResult = "";// String sendResult = "";//
if (msgType.equals(WxMessageUtil.REQ_MESSAGE_TYPE_TEXT)) { if (msgType.equals(WxMessageUtil.REQ_MESSAGE_TYPE_TEXT)) {
String content = requestMap.get("Content").trim(); // 用户发送的内容 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); content = QQFaceUtil.regix(content);
Activity activitySetting = activityService.getActivitySetting(); Activity activitySetting = activityService.getActivitySetting();
if (activitySetting != null && activitySetting.getStatus() > ActivityStatus.UNSTART.getIndex() if (activitySetting != null && activitySetting.getStatus() > ActivityStatus.UNSTART.getIndex()) {
&& !content.equals("人工万小二")) {
String[] keywords = activitySetting.getKeyword().split("\\|"); String[] keywords = activitySetting.getKeyword().split("\\|");
boolean containKeyword = false; boolean containKeyword = false;
for (String keyword : keywords) { for (String keyword : keywords) {
...@@ -147,16 +139,14 @@ public class WxMiniServiceImpl implements WxMiniService { ...@@ -147,16 +139,14 @@ public class WxMiniServiceImpl implements WxMiniService {
containKeyword = true; containKeyword = true;
break; break;
} }
} }
// 金额比较 Edit by lcc 171207
BigDecimal currentMny = activitySetting.getCurrentMny(); BigDecimal currentMny = activitySetting.getCurrentMny();
int compareTo = 0; int compareTo = 0;
if (currentMny != null) { if (currentMny != null) {
compareTo = activitySetting.getPlanMny().compareTo(activitySetting.getCurrentMny()); compareTo = activitySetting.getPlanMny().compareTo(activitySetting.getCurrentMny());
} }
// 抽奖活动已结束或红包预算已经发放完毕的回复.. add by lcc 171207
if (containKeyword && (activitySetting.getStatus() > 2 || compareTo < 0)) { if (containKeyword && (activitySetting.getStatus() > 2 || compareTo < 0)) {
WxMiniUtil.sendCustomMsgText(fromUserName, activitySetting.getFinishReply()); WxMiniUtil.sendCustomMsgText(fromUserName, activitySetting.getFinishReply());
saveChatLog(fans.getId(), content, activitySetting.getFinishReply(), fans.getGoodsId(), saveChatLog(fans.getId(), content, activitySetting.getFinishReply(), fans.getGoodsId(),
...@@ -167,54 +157,17 @@ public class WxMiniServiceImpl implements WxMiniService { ...@@ -167,54 +157,17 @@ public class WxMiniServiceImpl implements WxMiniService {
// 抽奖活动进行中 // 抽奖活动进行中
if (!Strings.isNullOrEmpty(activitySetting.getKeyword()) && containKeyword if (!Strings.isNullOrEmpty(activitySetting.getKeyword()) && containKeyword
&& activitySetting.getStatus() == 2) { && 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; boolean sussess = false;
// 指定城市范围 // 指定城市范围
String city = activitySetting.getCity(); String city = activitySetting.getCity();
// 粉丝城市 // 粉丝城市
String fansCity = fansByMiniOpenid.getProvince(); String fansCity = fans.getProvince();
if (Strings.isNullOrEmpty(city) || Strings.isNullOrEmpty(fansCity) if (Strings.isNullOrEmpty(city) || Strings.isNullOrEmpty(fansCity)
|| !fansCity.startsWith(city)) { || !fansCity.startsWith(city)) {
if (null == fansCity || fansCity == "null" || fansCity.length() < 1) if (null == fansCity || fansCity == "null" || fansCity.length() < 1)
fansCity = "未授权"; fansCity = "未授权";
String msg = "红包活动仅限【" + city + "】,您的省份【" + fansCity + "】不在本次活动范围内,不能参与抽奖哦~~/玫瑰/玫瑰"; String msg = "红包活动仅限【" + city + "】,您的省份【" + fansCity + "】不在本次活动范围内,不能参与抽奖哦~~/玫瑰/玫瑰";
// if(null==fansCity || fansCity=="") msg="红包活动仅限【" + city + "】,您的省份【" +
// fansCity+ "】可能是您未授权,小二无法判断您是否在本次活动范围内,所以不能参与抽奖哦~~";
WxMiniUtil.sendCustomMsgText(fromUserName, msg); WxMiniUtil.sendCustomMsgText(fromUserName, msg);
saveChatLog(fans.getId(), content, msg, fans.getGoodsId(), ChatLogReplyType.自动回复, "", ""); saveChatLog(fans.getId(), content, msg, fans.getGoodsId(), ChatLogReplyType.自动回复, "", "");
return respMessage; return respMessage;
...@@ -225,129 +178,72 @@ public class WxMiniServiceImpl implements WxMiniService { ...@@ -225,129 +178,72 @@ public class WxMiniServiceImpl implements WxMiniService {
ChatLogReplyType.自动回复, "", ""); ChatLogReplyType.自动回复, "", "");
Thread.sleep(1000); Thread.sleep(1000);
/** 取100-200内的数值,单位为分 */
List<Prize> prizes = ActivitySettingUtils.getInstance(activitySetting).getPrizes();
Collections.sort(prizes, new Comparator<Prize>() {
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; Prize temp = null;
for (Prize p : prizes) { Lotterylog log = null;
if (nextInt < p.getProbability()) { /** 执行抽奖核心 */
if (p.getNum() > 0) { fansService.getCountParentFansId(fans.getId());
temp = p; int fansCount = fansService.getCountParentFansId(fans.getId());
} if (fansCount == activitySetting.getShareCount()) {
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, "未知错误."); Vo_msg msg = new Vo_msg(-1, null, "未知错误.");
int mny = 0; int mny = 0;
if (temp.getIsMoney()) { if (temp.getIsMoney()) {
mny = RandomUtils.nextInt(temp.getMixMoney(), temp.getMaxMoney()); mny = (int) log.getMny().doubleValue() * 100;
msg = wxPayService.payMoney("pay" + DateTime.now().getMillis(), fromUserName, mny, msg = wxPayService.payMoney("pay" + DateTime.now().getMillis(), fromUserName, mny,
"来自【东莞万科万小二】的红包奖励"); "来自【华南城的】的红包奖励");
sussess = (msg.code == 0); sussess = (msg.code == 0);
activitySetting
.setCurrentMny(activitySetting.getCurrentMny().add(new BigDecimal(mny * 0.01)));
} else { } 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; sussess = true;
} }
activityService.updateActivity(activitySetting); activityService.updateActivity(activitySetting);
activityService.addLotteryLog(fansByMiniOpenid.getId(), new BigDecimal(mny * 0.01), activityService.addLotteryLog(fans.getId(), new BigDecimal(mny * 0.01), sussess == true ? 1 : 0,
sussess == true ? 1 : 0, activitySetting.getTurn(),temp.getName()); activitySetting.getTurn(), temp.getName());
if (sussess) { // 已中奖 if (sussess) { // 已中奖
// 扣减红包预算总额 if (temp.getIsMoney()) {
RedisUtil.set("zzhnc_lottery_fansid_" + fans.getId(), "1", 10 * 60);
// 已中奖的推送到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(),
WxMiniUtil.sendCustomMsgText(fromUserName, activitySetting.getReplySucceed()); ChatLogReplyType.自动回复, "", "");
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(),
String url = "http://mini.weiyisz.com/zzhnc/wx/redpackage?mny=" + mny * 0.01; activitySetting.getLotterySubTitle(), url,
WxMiniUtil.sendCustomMsgLink(fromUserName, activitySetting.getLotteryTitle(), "http://mini.weiyisz.com/zzhnc/res/images/redpackage.png");
activitySetting.getLotterySubTitle(), url, }else {
"http://mini.weiyisz.com/zzhnc/res/images/redpackage.png"); WxMiniUtil.sendCustomMsgText(fromUserName,"恭喜获得["+temp.getName() +"] 请到【我的奖品出兑换奖品】");
// 推送小程序卡片 saveChatLog(fans.getId(), content, activitySetting.getReplySucceed(), fans.getGoodsId(),
SendMiniProgram(fromUserName); ChatLogReplyType.自动回复, "", "");
}
return respMessage; return respMessage;
} else { // 未中奖 } else { // 未中奖
// 发送未中奖提示语 // 发送未中奖提示语
String failedReply = count == 0 ? activitySetting.getUnLotteryReply() String failedReply = activitySetting.getUnLotteryReply(); // 第一次和第二次未中奖的提示语有区别
: activitySetting.getReplyFailed2(); // 第一次和第二次未中奖的提示语有区别
WxMiniUtil.sendCustomMsgText(fromUserName, failedReply); WxMiniUtil.sendCustomMsgText(fromUserName, failedReply);
saveChatLog(fans.getId(), content, failedReply, fans.getGoodsId(), ChatLogReplyType.自动回复, saveChatLog(fans.getId(), content, failedReply, fans.getGoodsId(), ChatLogReplyType.自动回复,
"", ""); "", "");
// 两次未中奖时推送小程序卡片
if (count > 0) {
SendMiniProgram(fromUserName);
}
return respMessage; 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); String faces = WxMiniUtil.sponseQqFace(content);
if (faces.startsWith("[") && faces.endsWith("]")) if (faces.startsWith("[") && faces.endsWith("]"))
faces = faces.substring(1, faces.length() - 1); faces = faces.substring(1, faces.length() - 1);
if (faces.length() > 0) { if (faces.length() > 0) {
WxMiniUtil.sendCustomMsgText(fromUserName, faces); WxMiniUtil.sendCustomMsgText(fromUserName, faces);
saveChatLog(fans.getId(), content, faces, saleid, ChatLogReplyType.自动回复, "", ""); saveChatLog(fans.getId(), content, faces, goodsId, ChatLogReplyType.自动回复, "", "");
return respMessage; return respMessage;
} }
...@@ -361,27 +257,19 @@ public class WxMiniServiceImpl implements WxMiniService { ...@@ -361,27 +257,19 @@ public class WxMiniServiceImpl implements WxMiniService {
return respMessage; return respMessage;
} }
WxMiniUtil.sendCustomMsgText(fromUserName, auto.getContents()); 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.自动回复 Integer.parseInt(data.get("type").toString()) == 2 ? ChatLogReplyType.自动回复
: ChatLogReplyType.机器人, : ChatLogReplyType.机器人,
"", ""); "", "");
// 判断是否需要通知人工客服 --add by lcc 171207
if (auto.getIsredirectstaff()) {
nofitySalesIncludeVanker(saleid, content, fans);
}
return respMessage; return respMessage;
} else if (msgType.equals(WxMessageUtil.REQ_MESSAGE_TYPE_IMAGE)) {// 图片消息 } else if (msgType.equals(WxMessageUtil.REQ_MESSAGE_TYPE_IMAGE)) {// 图片消息
String fansImgUrl = requestMap.get("PicUrl"); String fansImgUrl = requestMap.get("PicUrl");
boolean handle = false; String imgReply = getImgReply();
if (!handle) { WxMiniUtil.sendCustomMsgText(fromUserName, imgReply);// 还没办法自动回复图片
String imgReply = getImgReply(); saveChatLog(fans.getId(), "", imgReply, goodsId, ChatLogReplyType.机器人, fansImgUrl, "");
WxMiniUtil.sendCustomMsgText(fromUserName, imgReply);// 还没办法自动回复图片
saveChatLog(fans.getId(), "", imgReply, saleid, ChatLogReplyType.机器人, fansImgUrl, "");
}
} else if (msgType.equals(WxMessageUtil.REQ_MESSAGE_TYPE_LOCATION)) {// 地理位置消息 } else if (msgType.equals(WxMessageUtil.REQ_MESSAGE_TYPE_LOCATION)) {// 地理位置消息
} else if (msgType.equals(WxMessageUtil.REQ_MESSAGE_TYPE_LINK)) {// 链接消息 } else if (msgType.equals(WxMessageUtil.REQ_MESSAGE_TYPE_LINK)) {// 链接消息
...@@ -653,15 +541,6 @@ public class WxMiniServiceImpl implements WxMiniService { ...@@ -653,15 +541,6 @@ public class WxMiniServiceImpl implements WxMiniService {
// redis中如果不存在,则重新上传临时素材 // redis中如果不存在,则重新上传临时素材
if (null == media_id || media_id.length() < 1 || null == thumb_url || thumb_url.length() < 1) { 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<Postertemplet> 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); Vo_msg imgMsg = WxMiniUtil.uploadImage(thumb_url, false);
if (imgMsg.code != 0) if (imgMsg.code != 0)
......
...@@ -23,8 +23,8 @@ public class ActivitySettingUtils { ...@@ -23,8 +23,8 @@ public class ActivitySettingUtils {
public static ActivitySettingUtils getInstance(Activity act) { public static ActivitySettingUtils getInstance(Activity act) {
if (instance == null) { if (instance == null) {
instance = new ActivitySettingUtils(); instance = new ActivitySettingUtils();
ActivitySettingUtils.act = act;
} }
ActivitySettingUtils.act = act;
return instance; return instance;
} }
......
Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
请先完成此消息的编辑!