use of com.ikoori.vip.common.persistence.model.Member in project vip by guangdada.
the class SignApiImpl method signIn.
/**
* 每日签到方法
*
* @Title: signIn
* @param unionid
* @return
* @throws Exception
* @date: 2017年9月29日 下午4:07:58
* @author: chengxg
*/
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
@Override
public JSONObject signIn(String unionid) throws Exception {
log.info("进入signIn>>unionid=" + unionid);
JSONObject obj = new JSONObject();
obj.put("code", true);
obj.put("msg", "签到成功");
// unionid获得会员
Member member = memberDao.getMemberByUnionid(unionid);
if (member == null) {
obj.put("msg", "您还不是会员哦");
throw new Exception(obj.toJSONString());
}
// 当前时间
Date nowDate = new Date();
Date yesDate = DateUtil.getAfterDayDate(-1);
String nowDateStr = DateUtil.getDay(new Date());
String yesDateStr = DateUtil.getDay(yesDate);
synchronized (unionid.intern()) {
// 最后签到日期
Date signDate = member.getSignDate();
// 如果最后签到日期为null,表示历史第一次签到,修改连续签到天数=1,修改最后签到日期为今天
if (signDate == null) {
member.setSignDays(1);
}
String signDateStr = signDate == null ? "" : DateUtil.getDay(signDate);
// 如果最后签到日期是今天,提示今天已经签到过, 不做后续处理
if (nowDateStr.equals(signDateStr)) {
obj.put("msg", "今天已经签到过了");
throw new Exception(obj.toJSONString());
} else {
// 如果最后签到日期不是今天,保存今天的签到记录
SignLog signLog = new SignLog();
signLog.setMemberId(member.getId());
signLog.setMerchantId(member.getMerchantId());
signLogMapper.insert(signLog);
// 如果最后签到日期是昨天,修改连续签到天数+1
if (signDateStr.equals(yesDateStr)) {
member.setSignDays(member.getSignDays() + 1);
} else {
// 如果最后签到日期不是昨天,修改连续签到天数=1
member.setSignDays(1);
}
// 修改签到信息
member.setSignDate(nowDate);
member.setSignTotalDays(member.getSignTotalDays() + 1);
memberMapper.updateById(member);
// 连续签到天数
Integer signDays = member.getSignDays();
// 获得签到规则
boolean getPoint = false;
List<Sign> signs = getSignList(member.getMerchantId());
for (Sign sign : signs) {
if (!sign.isOnce()) {
Integer times = sign.getTimes();
Integer score = sign.getScore();
// times 等于1表示不需要连续, 每天签都能得积分
if (signDays % times == 0) {
boolean result = pointTradeService.savePointTrade(true, PointTradeType.MARK.getCode(), score, member.getId(), null, member.getMerchantId(), null, "签到");
if (!result) {
obj.put("msg", "签到失败!");
throw new Exception(obj.toJSONString());
}
// 连续签到为1天的情况, 可以同其他规则一起生效,不管是不是设置了“仅领一次”
if (times != 1) {
// 领取过后 , “仅领一次”的规则就不处理了
getPoint = true;
}
}
}
}
// 处理“仅领一次”的规则
if (!getPoint) {
for (Sign sign : signs) {
if (sign.isOnce()) {
Integer times = sign.getTimes();
Integer score = sign.getScore();
if (signDays % times == 0) {
boolean result = pointTradeService.savePointTrade(true, PointTradeType.MARK.getCode(), score, member.getId(), null, member.getMerchantId(), null, "签到");
if (!result) {
obj.put("msg", "签到失败!");
throw new Exception(obj.toJSONString());
}
// 获取一次便退出
break;
}
}
}
}
}
}
log.info("结束signIn" + unionid);
return obj;
}
use of com.ikoori.vip.common.persistence.model.Member in project vip by guangdada.
the class CouponApiImpl method fetchCoupon.
/**
* 领取优惠券
*
* @Title: fetchCoupon
* @param alias
* @param unionid
* @return
* @date: 2017年9月14日 下午10:59:05
* @author: chengxg
* @throws Exception
*/
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
@Override
public JSONObject fetchCoupon(String alias, String unionid) throws Exception {
log.info("进入getCoupon");
log.info("进入getCoupon >> alias=" + alias);
log.info("进入getCoupon >> unionid=" + unionid);
JSONObject obj = new JSONObject();
obj.put("code", true);
obj.put("msg", "领取成功");
// 根据alia获得优惠券
// 判断优惠券是否有效
Coupon coupon = couponDao.getCouponByAlias(alias);
if (coupon == null || !coupon.isIsExpired() || !coupon.isIsInvalid()) {
log.error("该优惠券已经过期啦");
obj.put("msg", "该优惠券已经过期啦");
throw new Exception(obj.toJSONString());
}
// unionid获得会员
// 判断会员卡是否过期
Member member = memberDao.getMemberByUnionid(unionid);
if (member == null) {
log.error("您还不是会员哦");
obj.put("msg", "您还不是会员哦");
throw new Exception(obj.toJSONString());
}
// 判断是否满足领取条件
checkCouponFetch(obj, coupon, member, 1);
// 保存领取记录
couponFetchService.saveCouponFetch(member, coupon, null);
log.info("结束getCoupon");
return obj;
}
use of com.ikoori.vip.common.persistence.model.Member in project vip by guangdada.
the class WebMemberController method getCards.
@ApiOperation("根据手机号获得会员卡")
@RequestMapping(value = "getCards", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> getCards(@ApiParam(value = "店铺编号", required = true) @RequestParam(required = true) String storeNo, @ApiParam(value = "手机号", required = true) @RequestParam(required = true) String mobile, @ApiParam(value = "签名", required = true) @RequestParam(required = true) String sign) {
Map<String, Object> result = new HashMap<String, Object>();
result.put("code", "200");
result.put("msg", "请求成功");
try {
boolean isSign = true;
if (gunsProperties.isCheckSign()) {
Map<String, String> data = new HashMap<String, String>();
data.put("storeNo", storeNo);
data.put("mobile", mobile);
data.put("sign", sign);
isSign = WXPayUtil.isSignatureValid(data, gunsProperties.getSignKey());
if (!isSign) {
result.put("code", "500");
result.put("msg", "签名失败");
}
}
if (isSign) {
Member member = memberService.selectByMobile(mobile);
if (member == null) {
result.put("code", "500");
result.put("msg", "没有找到会员信息");
} else {
JSONObject card = memberService.initCard(member.getId());
result.put("content", card);
}
}
} catch (Exception e) {
log.error("", e);
result.put("code", "500");
result.put("msg", "请求失败");
}
return result;
}
Aggregations