use of com.ikoori.vip.common.persistence.model.Coupon in project vip by guangdada.
the class CouponController method couponPublish.
/**
* 跳转到发行优惠券
*/
@Permission
@RequestMapping("/coupon_publish/{couponId}")
public String couponPublish(@PathVariable Long couponId, Model model) {
Coupon coupon = couponService.selectById(couponId);
Integer count = couponService.getPublishCount(couponId, coupon.getMerchantId());
Integer leftnum = coupon.getTotal() - count;
model.addAttribute("leftnum", leftnum);
model.addAttribute(coupon);
return PREFIX + "coupon_publish.html";
}
use of com.ikoori.vip.common.persistence.model.Coupon in project vip by guangdada.
the class CouponServiceImpl method publishCoupon.
/**
* 批量发行现金券
* @Title: publish
* @param couponId
* @param num
*s * @date: 2017年10月16日 下午2:02:56
* @author: chengxg
*/
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public void publishCoupon(Long couponId, Integer num) {
Coupon coupon = couponMapper.selectById(couponId);
if (coupon == null) {
throw new BussinessException(500, "现金券不存在");
}
List<CouponCode> codes = getCouponCode(coupon.getMerchantId(), num);
if (CollectionUtils.isEmpty(codes)) {
throw new BussinessException(500, "券码库券码数为0,请先制卡");
}
if (codes.size() < num) {
throw new BussinessException(500, "券码库剩余券码数:" + codes.size() + ",请先制卡");
}
// 已发行数量
Integer count = getPublishCount(couponId, coupon.getMerchantId());
Integer left = coupon.getTotal() - count;
if (left < num) {
throw new BussinessException(500, "已发行:" + count + ",剩余可发行数量:" + left);
}
for (CouponCode code : codes) {
code.setUseStatus(CouponCodeStatus.publish.getCode());
code.setCouponId(couponId);
code.updateById();
}
}
use of com.ikoori.vip.common.persistence.model.Coupon 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;
}
Aggregations