修改商品核销接口

1 个父辈 2e6cbf3d
......@@ -243,7 +243,7 @@ public class UploadController extends BaseController {
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);
/* } */
} catch (Exception e) {
......
......@@ -7,12 +7,14 @@ import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
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.RequestMapping;
......@@ -41,11 +43,14 @@ import com.w1hd.zzhnc.service.PrizeService;
import com.w1hd.zzhnc.util.PageResults;
import com.w1hd.zzhnc.util.RedisUtil;
import com.w1hd.zzhnc.vo.Vo_msg;
import com.wordnik.swagger.annotations.ApiOperation;
@Controller
@RequestMapping("/wxmini")
public class WxMiniController extends BaseController {
public static final String PRIZE_KEY_TIME = RedisUtil.PROJECTNAME.concat("_").concat("PRIZE_KEY_TIME_");
@Autowired
FansService fansService;
@Autowired
......@@ -100,19 +105,18 @@ public class WxMiniController extends BaseController {
@RequestMapping(value = "/login", method = RequestMethod.GET) // 购房助手登录 double lng,double lat
public @ResponseBody Vo_msg login(@RequestParam(value = "code") String code,
@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) {
@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);
// 取openid
WxMiniSessionInfo sessionInfo = WxMiniUtil.jscode2session(code);
// 添加粉丝记录
Fans fans = fansService.addFans(sessionInfo, shareId, nickname, logo, lng, lat,fansId);
Fans fans = fansService.addFans(sessionInfo, shareId, nickname, logo, lng, lat, fansId);
if (fans != null) {
Map<String, Object> map = new HashMap<>();
map.put("miniOpenId", sessionInfo.getOpenid());
map.put("fansId", fans.getId());
return new Vo_msg(0, map);
} else {
return new Vo_msg(-1, "登录失败,服务器异常");
......@@ -296,7 +300,7 @@ public class WxMiniController extends BaseController {
}
/** 查看我的奖品 */
@RequestMapping(value = "/prizes", method = RequestMethod.GET)
@RequestMapping(value = "/prizes/my", method = RequestMethod.GET)
@ResponseBody
public Object prizes(@RequestParam(value = "openId") String openId) {
Fans fans = fansService.getFansByMiniOpenid(openId);
......@@ -318,7 +322,7 @@ public class WxMiniController extends BaseController {
@ResponseBody
public Object prizesKill(@RequestParam(value = "openId") String openId) {
Fans fans = fansService.getFansByMiniOpenid(openId);
Integer logId = prizeService.randomKill(fans.getId(),0);
Integer logId = prizeService.randomKill(fans.getId(), 0);
if (logId == 0) {
return new Vo_msg(-1, null, "不好意思你没中奖");
}
......@@ -338,10 +342,26 @@ public class WxMiniController extends BaseController {
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)
@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);
return prizeService.updateLotteryLog(id, fans.getId());
}
......@@ -356,14 +376,16 @@ public class WxMiniController extends BaseController {
@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);
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, seacrh);
return new Vo_msg(0, null);
}
}
......@@ -62,7 +62,7 @@ public class GoodsService {
public PageResults<Goods> seacrh(Integer id, String key, Integer sellerId, Integer page, Integer size) {
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)) {
......
......@@ -184,30 +184,31 @@ public class WxMiniServiceImpl implements WxMiniService {
fansService.getCountParentFansId(fans.getId());
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);
Integer randomKill = prizeService.randomKill(fans.getId(), 0);
if(randomKill<1) {
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, "未知错误.");
int mny = 0;
if (temp.getIsMoney()) {
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());
} else {
sussess = true;
}
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);
......
Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
请先完成此消息的编辑!