Commit fbd40a9a zxt@theyeasy.com

Merge branch 'zxt'

2 个父辈 f110d8d6 ef39e9b8
...@@ -243,7 +243,7 @@ public class UploadController extends BaseController { ...@@ -243,7 +243,7 @@ public class UploadController extends BaseController {
FileCopyUtils.copy(mf.getBytes(), path); // 把图片复制到本地 FileCopyUtils.copy(mf.getBytes(), path); // 把图片复制到本地
} }
returnPath = "http://mini.weiyisz.com/zzhnc/res/upload/" + imageType + "/" + newFileName; returnPath = "http://dvmini.w1hd.com/zzhnc/res/upload/" + imageType + "/" + newFileName;
System.out.println(returnPath); System.out.println(returnPath);
/* } */ /* } */
} catch (Exception e) { } catch (Exception e) {
......
...@@ -7,12 +7,14 @@ import java.net.URLEncoder; ...@@ -7,12 +7,14 @@ import java.net.URLEncoder;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
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.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.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -41,11 +43,14 @@ import com.w1hd.zzhnc.service.PrizeService; ...@@ -41,11 +43,14 @@ import com.w1hd.zzhnc.service.PrizeService;
import com.w1hd.zzhnc.util.PageResults; import com.w1hd.zzhnc.util.PageResults;
import com.w1hd.zzhnc.util.RedisUtil; import com.w1hd.zzhnc.util.RedisUtil;
import com.w1hd.zzhnc.vo.Vo_msg; import com.w1hd.zzhnc.vo.Vo_msg;
import com.wordnik.swagger.annotations.ApiOperation;
@Controller @Controller
@RequestMapping("/wxmini") @RequestMapping("/wxmini")
public class WxMiniController extends BaseController { public class WxMiniController extends BaseController {
public static final String PRIZE_KEY_TIME = RedisUtil.PROJECTNAME.concat("_").concat("PRIZE_KEY_TIME_");
@Autowired @Autowired
FansService fansService; FansService fansService;
@Autowired @Autowired
...@@ -100,17 +105,18 @@ public class WxMiniController extends BaseController { ...@@ -100,17 +105,18 @@ 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 = "logo") String logo, @RequestParam(value = "lng") double lng, @RequestParam(value = "nickname") String nickname, @RequestParam(value = "logo") String logo,
@RequestParam(value = "lat") double lat) { @RequestParam(value = "lng") double lng, @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());
map.put("fansId", fans.getId());
return new Vo_msg(0, map); return new Vo_msg(0, map);
} else { } else {
return new Vo_msg(-1, "登录失败,服务器异常"); return new Vo_msg(-1, "登录失败,服务器异常");
...@@ -294,7 +300,7 @@ public class WxMiniController extends BaseController { ...@@ -294,7 +300,7 @@ public class WxMiniController extends BaseController {
} }
/** 查看我的奖品 */ /** 查看我的奖品 */
@RequestMapping(value = "/prizes", method = RequestMethod.GET) @RequestMapping(value = "/prizes/my", method = RequestMethod.GET)
@ResponseBody @ResponseBody
public Object prizes(@RequestParam(value = "openId") String openId) { public Object prizes(@RequestParam(value = "openId") String openId) {
Fans fans = fansService.getFansByMiniOpenid(openId); Fans fans = fansService.getFansByMiniOpenid(openId);
...@@ -316,12 +322,12 @@ public class WxMiniController extends BaseController { ...@@ -316,12 +322,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);
...@@ -336,10 +342,26 @@ public class WxMiniController extends BaseController { ...@@ -336,10 +342,26 @@ public class WxMiniController extends BaseController {
return prizeList; return prizeList;
} }
@Autowired
RedisTemplate<String, Long> redisTemplate;
/** 核销奖品 */
@ApiOperation( value = "二维码地址")
@RequestMapping(value = "/prizes/sqr", method = RequestMethod.GET)
@ResponseBody
public Object scanQr() {
long timeMillis = System.currentTimeMillis();
redisTemplate.opsForValue().set(PRIZE_KEY_TIME + timeMillis, timeMillis);
redisTemplate.expire(PRIZE_KEY_TIME + timeMillis, 300, TimeUnit.SECONDS);
return timeMillis;
}
/** 核销奖品 */ /** 核销奖品 */
@RequestMapping(value = "/prizes/{id}", method = RequestMethod.GET) @RequestMapping(value = "/prizes/{id}", method = RequestMethod.GET)
@ResponseBody @ResponseBody
public Object prizes(@RequestParam(value = "openId") String openId, @PathVariable(value = "id") Integer id) { public Object prizes(@RequestParam(value = "openId") String openId,
@RequestParam(value = "timeMillis") Long timeMillis, @RequestParam(value = "localMillis") Long localMillis,
@PathVariable(value = "id") Integer id) {
Fans fans = fansService.getFansByMiniOpenid(openId); Fans fans = fansService.getFansByMiniOpenid(openId);
return prizeService.updateLotteryLog(id, fans.getId()); return prizeService.updateLotteryLog(id, fans.getId());
} }
...@@ -351,4 +373,19 @@ public class WxMiniController extends BaseController { ...@@ -351,4 +373,19 @@ 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) {
if (id > 0) {
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, null);
}
} }
...@@ -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;
}
} }
...@@ -62,7 +62,7 @@ public class GoodsService { ...@@ -62,7 +62,7 @@ public class GoodsService {
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) {
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)) {
......
...@@ -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++);
} }
} }
} }
......
...@@ -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 到此讨论。请谨慎行事。
请先完成此消息的编辑!