Search in sources :

Example 16 with Coupon

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";
}
Also used : StoreCoupon(com.ikoori.vip.common.persistence.model.StoreCoupon) Coupon(com.ikoori.vip.common.persistence.model.Coupon) Permission(com.ikoori.vip.common.annotion.Permission) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with Coupon

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();
    }
}
Also used : Coupon(com.ikoori.vip.common.persistence.model.Coupon) CouponCode(com.ikoori.vip.common.persistence.model.CouponCode) BussinessException(com.ikoori.vip.common.exception.BussinessException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 18 with Coupon

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;
}
Also used : Coupon(com.ikoori.vip.common.persistence.model.Coupon) JSONObject(com.alibaba.fastjson.JSONObject) Member(com.ikoori.vip.common.persistence.model.Member) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Coupon (com.ikoori.vip.common.persistence.model.Coupon)18 Permission (com.ikoori.vip.common.annotion.Permission)11 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 Merchant (com.ikoori.vip.common.persistence.model.Merchant)7 HashMap (java.util.HashMap)7 Transactional (org.springframework.transaction.annotation.Transactional)7 BussinessException (com.ikoori.vip.common.exception.BussinessException)6 StoreCoupon (com.ikoori.vip.common.persistence.model.StoreCoupon)6 Card (com.ikoori.vip.common.persistence.model.Card)4 Member (com.ikoori.vip.common.persistence.model.Member)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 JSONObject (com.alibaba.fastjson.JSONObject)2 CardRight (com.ikoori.vip.common.persistence.model.CardRight)2 CouponCode (com.ikoori.vip.common.persistence.model.CouponCode)2 Point (com.ikoori.vip.common.persistence.model.Point)2 Share (com.ikoori.vip.common.persistence.model.Share)2 Store (com.ikoori.vip.common.persistence.model.Store)2 Date (java.util.Date)2 ErrorTip (com.ikoori.vip.common.constant.tips.ErrorTip)1 CouponPayDo (com.ikoori.vip.common.dto.CouponPayDo)1