发红包实现

1 个父辈 8803b0d9
......@@ -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));
......
......@@ -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));
}
}
......@@ -293,7 +293,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);
PageResults<Goods> seacrh = goodsService.seacrh(null, key, null, page, size,1);
List<Goods> rows = seacrh.getRows();
result.put("banner", bannerList);
result.put("data", rows);
......@@ -382,7 +382,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);
PageResults<Goods> seacrh = goodsService.seacrh(id, null, null, null, null,0);
return new Vo_msg(0, seacrh);
}
......@@ -390,7 +390,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);
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);
......
......@@ -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<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);
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<Goods> list = goodsDao.selectByExampleAndRowBounds(ex, row);
int count = goodsDao.selectCountByExample(ex);
......@@ -99,7 +115,7 @@ public class GoodsService {
pageResults.setPageSize(10);
List<Goods> 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);
......
......@@ -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;
......@@ -126,7 +129,6 @@ public class PrizeService {
p.setNum(p.getNum() - 1);
setting.setP8(p);
break;
default:
break;
}
......@@ -135,18 +137,19 @@ public class PrizeService {
Lotterylog lotterylog = new Lotterylog();
lotterylog.setCreatedtime(new Date());
lotterylog.setFansid(fansId);
lotterylog.setMny(mny);
lotterylog.setPrizeName(p.getName());
lotterylog.setPrizeId(pType);
lotterylog.setMny(new BigDecimal(0));
if ("谢谢".equals(p.getName())) {
lotterylog.setStatus(3);
} else {
lotterylog.setStatus(1);
if (mny.doubleValue() > 1.0) {
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);
}
}
......@@ -156,6 +159,10 @@ public class PrizeService {
return lotterylog.getId();
}
@Autowired
WxMiniService wxMiniService;
/** 获取我的奖品 */
public List<Lotterylog> getMyLotteryLog(Integer fansId) {
......@@ -186,7 +193,12 @@ public class PrizeService {
RedisTemplate redisTemplate;
public Integer changes(Integer fansId) {
Integer lotteryLog = (Integer) redisTemplate.opsForValue().get(PRIZE_KILL_FANSID + fansId);
if (fansId <= 10) {
lotteryLog = null;
}
if (lotteryLog == null) {
return 1;
} else {
......@@ -323,13 +335,14 @@ public class PrizeService {
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 +355,10 @@ public class PrizeService {
return "fail";
}
return getAuthorizeUrl(map.get("data").toString(), activityId, fansId);
String url = getAuthorizeUrl(map.get("data").toString(), activityId, fansId);
WxMiniUtil.sendCustomMsgLink(fans.getMiniopenid(), "点我领红包", "点这里!点这里!点这里进行抽奖!", url,
"http://mini.weiyisz.com/dvmini/res/images/hongbao.png");
return url;
}
}
......@@ -46,12 +46,6 @@ public interface WxMiniService {
public String getImgReply();
/**
* 用户进入聊天面板的欢迎语
* @param first:是否获取第一次进入的欢迎语
*/
public String getWelcome(boolean firstEnter);
/**
* 在小程序会话面板发送登录链接
* @param saleid
* @param wxMiniOpenId
......
......@@ -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<Object, Object> data = AutoreplyService.autoreply(content, cache(toUserName), fromUserName);
HashMap<Object, Object> 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,22 @@ 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(i);
sendResult = WxMiniUtil.sendCustomMsgText(fromUserName, welcome);
saveChatLog(fans.getId(), "进入会话:" + floorname, welcome, fans.getGoodsId(),
ChatLogReplyType.进入会话, "", "");
}
sendResult = WxMiniUtil.sendCustomMsgText(fromUserName, welcome);
// 发送欢迎语
saveChatLog(fans.getId(), "进入会话:" + floorname, welcome, fans.getGoodsId(), ChatLogReplyType.进入会话,
"", "");
}
copyToWxkf = false; // 事件不要转发给客服系统。
}
......@@ -488,29 +465,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<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];
public String getWelcome(int index) {
Autoreply autoreply = autoreplyService.autoreply("welcome" + index);
return autoreply.getContents();
}
@Override
......@@ -571,23 +528,4 @@ public class WxMiniServiceImpl implements WxMiniService {
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 到此讨论。请谨慎行事。
请先完成此消息的编辑!