Commit 14e5e4a7 zxt@theyeasy.com

Merge branch 'zxt'

2 个父辈 efbe5f9f 45c809d1
......@@ -4,6 +4,7 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.sql.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -24,6 +25,7 @@ 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.testng.util.Strings;
import org.theyeasy.weixin.model.WxMiniSessionInfo;
import org.theyeasy.weixin.service.WxMiniService;
import org.theyeasy.weixin.util.WxMiniUtil;
......@@ -31,6 +33,7 @@ import org.theyeasy.weixin.util.WxMiniUtil;
import com.beust.jcommander.internal.Maps;
import com.w1hd.zzhnc.controller.pc.BaseController;
import com.w1hd.zzhnc.dao.LotteryLogDao;
import com.w1hd.zzhnc.enums.ChatLogReplyType;
import com.w1hd.zzhnc.model.Activity;
import com.w1hd.zzhnc.model.Articles;
import com.w1hd.zzhnc.model.Banner;
......@@ -114,7 +117,7 @@ public class WxMiniController extends BaseController {
@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 = "lat") double lat) {
logger.info("小程序登录:code=" + code);
logger.info("小程序登录:code=" + code + "分享商品ID:" + shareId + " 分享者ID:" + fansId);
// 取openid
WxMiniSessionInfo sessionInfo = WxMiniUtil.jscode2session(code);
// 添加粉丝记录
......@@ -331,6 +334,18 @@ public class WxMiniController extends BaseController {
@ResponseBody
public Object prizesKill(@RequestParam(value = "openId") String openId) {
Fans fans = fansService.getFansByMiniOpenid(openId);
Activity activity = activityService.getActivitySetting();
String city = activity.getCity();
// 粉丝城市
String fansCity = fans.getCity();
System.out.println("活动城市:"+city+" 粉丝城市:"+fansCity);
if (Strings.isNullOrEmpty(city) || Strings.isNullOrEmpty(fansCity) || !fansCity.startsWith(city)) {
if (null == fansCity || fansCity == "null" || fansCity.length() < 1)
fansCity = "未授权";
String msg = "红包活动仅限【" + city + "】,您的城市【" + fansCity + "】不在本次活动范围内,不能参与抽奖哦~~";
return new Vo_msg(-1, null, msg);
}
// 指定城市范围
Integer changes = prizeService.changes(fans.getId());
if (changes > 0) {
Integer logId = prizeService.randomKill(fans.getId(), 0);
......@@ -344,6 +359,11 @@ public class WxMiniController extends BaseController {
@RequestMapping(value = "/prizes/changes", method = RequestMethod.GET)
@ResponseBody
public Object changes(@RequestParam(value = "openId") String openId) {
Activity activity = activityService.getActivitySetting();
int compareTo = new Date(System.currentTimeMillis()).compareTo(activity.getBeginTime());
if (compareTo < 0) {
return new Vo_msg(-1, 0, "活动还没开始");
}
Fans fans = fansService.getFansByMiniOpenid(openId);
Integer changes = prizeService.changes(fans.getId());
if (changes < 0) {
......@@ -406,16 +426,4 @@ 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");
}
}
......@@ -155,7 +155,6 @@ public class Activity implements Serializable {
public void setP1(Prize p1) {
this.p1 = p1;
p1.setId(1);
}
public Prize getP2() {
......@@ -164,7 +163,6 @@ public class Activity implements Serializable {
public void setP2(Prize p2) {
this.p2 = p2;
p2.setId(2);
}
public Prize getP3() {
......@@ -173,7 +171,6 @@ public class Activity implements Serializable {
public void setP3(Prize p3) {
this.p3 = p3;
p3.setId(3);
}
public Prize getP4() {
......@@ -182,7 +179,6 @@ public class Activity implements Serializable {
public void setP4(Prize p4) {
this.p4 = p4;
p4.setId(4);
}
......
......@@ -129,7 +129,7 @@ public class ArticleService{
public List<Articles> getHomeData() {
Example example = new Example(Articles.class);
example.createCriteria().andEqualTo("deleted", false);
RowBounds row = new RowBounds(0 , 5);
RowBounds row = new RowBounds(0 , 200);
example.setOrderByClause(" id desc ");
List<Articles> list = articleDao.selectByExampleAndRowBounds(example, row);
return list;
......
......@@ -2,6 +2,7 @@ package com.w1hd.zzhnc.service;
import java.sql.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -24,13 +25,12 @@ public class GoodsService {
@Autowired
GoodsDao goodsDao;
final String GOODSID_ = RedisUtil.PROJECTNAME.concat("_").concat("goods");
final String GOODSID_ = RedisUtil.PROJECTNAME.concat("_").concat("goods_id");
public List<Goods> getHomeData() {
Example ex = new Example(Goods.class);
ex.createCriteria().andEqualTo("deleted", false).andEqualTo("isHome", true);
ex.setOrderByClause("page_views desc");
RowBounds r = new RowBounds(0, 10);
return goodsDao.selectByExample(ex);
}
......@@ -120,6 +120,7 @@ public class GoodsService {
}
goods.setPageViews(goods.getPageViews() + 1);
redisTemplate.opsForValue().set(GOODSID_ + id, goods);
redisTemplate.expire(GOODSID_ + id, 5, TimeUnit.DAYS);
list.add(goods);
pageResults.setRows(list);
return pageResults;
......
......@@ -5,6 +5,7 @@ import java.math.RoundingMode;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.RandomUtils;
import org.apache.ibatis.session.RowBounds;
......@@ -145,7 +146,7 @@ public class PrizeService {
System.out.println("抽中一个红包 >" + order);
lotterylog.setPrizeUrl(order);
lotterylog.setMny(mny);
// lotterylog.setStatus(2);
lotterylog.setStatus(1);
// Fans fans = fansService.getFansById(fansId);
// activityService.sendRedPackage(fans.getMiniopenid(), (int) (mny.doubleValue()
......@@ -156,6 +157,7 @@ public class PrizeService {
lotterylog.setTurn(setting.getTurn());
lotteryLogDao.insert(lotterylog);
redisTemplate.opsForValue().set(LotteryLogID_ + lotterylog.getId(), lotterylog);
redisTemplate.expire(LotteryLogID_ + lotterylog.getId(), 5, TimeUnit.DAYS);
return lotterylog.getId();
}
......@@ -204,6 +206,7 @@ public class PrizeService {
lotterylog.setStatus(2);
lotterylog.setUpdatetime(new Date());
lotteryLogDao.updateByPrimaryKey(lotterylog);
redisTemplate.expire(LotteryLogID_ + lotterylog.getId(), 200, TimeUnit.SECONDS);
return lotterylog;
}
......@@ -226,7 +229,6 @@ public class PrizeService {
count = count - 1;
return count;
}
}
if (lotteryLog == null) {
......@@ -237,15 +239,20 @@ public class PrizeService {
Example ex = new Example(Lotterylog.class);
ex.createCriteria().andEqualTo("fansid", fansId);
int lotteryCount = lotteryLogDao.selectCountByExample(ex);
if (lotteryCount > MAX_CHANGES) {
if (lotteryCount >= MAX_CHANGES) {
return 0;
}
int shareCount = activitySetting.getShareCount();
if (shareCount == 0)
if (shareCount == 0) {
shareCount = 1;
}
int changes = fansCount / shareCount;
changes = changes - lotteryCount;
return changes + 1;
changes = changes + 1;
if(changes>MAX_CHANGES) {
changes = MAX_CHANGES;
}
return changes;
}
}
......
......@@ -163,7 +163,6 @@ public class WxMiniServiceImpl implements WxMiniService {
String city = activitySetting.getCity();
// 粉丝城市
String fansCity = fans.getCity();
if (fans.getId() != 7) // TODO 测试
if (Strings.isNullOrEmpty(city) || Strings.isNullOrEmpty(fansCity)
|| !fansCity.startsWith(city)) {
if (null == fansCity || fansCity == "null" || fansCity.length() < 1)
......@@ -268,31 +267,25 @@ public class WxMiniServiceImpl implements WxMiniService {
String eventType = requestMap.get("Event");// 事件类型,未使用
if (eventType.equals("user_enter_tempsession")) // 用户在小程序进入客服面板
{
// 保存进入会话时传入的参数
String sessionFrom = requestMap.get("SessionFrom");
String floorname = getSessionFromValue(sessionFrom, 1);// 楼盘名称
// 保存粉丝最后一次进入会话的时间
fans.setLastEnterTime(DateTime.now().toDate());
fansDao.updateByPrimaryKey(fans);
// 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");
System.out.println("未兑换红包数 :" + list.size());
if (list != null && !list.isEmpty()) {
for (Lotterylog l : list) {
System.out.println(l.getPrizeUrl());
WxMiniUtil.sendCustomMsgLink(fans.getMiniopenid(), "年货会红包", "恭喜您在抽奖中获得红包,请点击领取",
l.getPrizeUrl(), "http://mini.weiyisz.com/dvmini/res/images/redpackage.png");
prizeService.updateLotteryLog(l.getId(), fans.getId());
}
} else {
String welcome = getWelcome(1);
System.out.println("welcome:" + welcome);
WxMiniUtil.sendCustomMsgText(fromUserName, welcome);
}
// 发送欢迎语
}
copyToWxkf = false; // 事件不要转发给客服系统。
......
Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
请先完成此消息的编辑!