Search in sources :

Example 1 with CouponCode

use of com.ikoori.vip.common.persistence.model.CouponCode in project vip by guangdada.

the class CouponCodeController method couponCodeUpdate.

/**
 * 跳转到修改券码管理
 */
@Permission
@RequestMapping("/couponCode_update/{couponCodeId}")
public String couponCodeUpdate(@PathVariable Long couponCodeId, Model model) {
    CouponCode couponCode = couponCodeService.selectById(couponCodeId);
    model.addAttribute(couponCode);
    return PREFIX + "couponCode_edit.html";
}
Also used : CouponCode(com.ikoori.vip.common.persistence.model.CouponCode) Permission(com.ikoori.vip.common.annotion.Permission) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with CouponCode

use of com.ikoori.vip.common.persistence.model.CouponCode in project vip by guangdada.

the class CouponApiImpl method activeCoupon.

/**
 * 根据券号,激活优惠券
 *
 * @Title: activeCoupon
 * @param verifyCode
 * @param unionid
 * @date: 2017年9月18日 下午4:18:12
 * @author: chengxg
 * @throws Exception
 */
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public JSONObject activeCoupon(String verifyCode, String unionid) throws Exception {
    log.info("进入activeCoupon");
    log.info("进入activeCoupon>>verifyCode=" + verifyCode);
    log.info("进入activeCoupon>>unionid=" + unionid);
    JSONObject obj = new JSONObject();
    obj.put("code", true);
    obj.put("msg", "领取成功");
    // unionid获得会员
    // 判断会员卡是否过期
    Member member = memberDao.getMemberByUnionid(unionid);
    if (member == null) {
        log.error("您还不是会员哦");
        obj.put("msg", "您还不是会员哦");
        throw new Exception(obj.toJSONString());
    }
    if (!member.isIsActive() || StringUtils.isBlank(member.getMobile())) {
        log.error("您还没有激活会员卡哦");
        obj.put("msg", "您还没有激活会员卡哦");
        throw new Exception(obj.toJSONString());
    }
    synchronized (verifyCode.intern()) {
        CouponCode couponCode = getCouponCode(verifyCode);
        if (couponCode == null) {
            log.error("没有找到该现金券哦" + verifyCode);
            obj.put("msg", "没有找到该现金券哦");
            throw new Exception(obj.toJSONString());
        }
        if (couponCode.getUseStatus() != CouponCodeStatus.publish.getCode()) {
            log.error("该现金券还没有发行哦");
            obj.put("msg", "该现金券还没有发行哦");
            throw new Exception(obj.toJSONString());
        }
        Coupon coupon = couponMapper.selectById(couponCode.getCouponId());
        if (coupon == null || !coupon.isIsExpired() || !coupon.isIsInvalid()) {
            log.error("该现金券已经过期啦");
            obj.put("msg", "该现金券已经过期啦");
            throw new Exception(obj.toJSONString());
        }
        // 判断是否符合领取条件
        checkCouponFetch(obj, coupon, member, 1);
        // 保存领取记录
        couponFetchService.saveCouponFetch(member, coupon, couponCode.getVerifyCode());
        // 修改券码状态为“已激活”
        couponCode.setUseStatus(CouponCodeStatus.active.getCode());
        couponCodeMapper.updateById(couponCode);
    }
    log.info("结束activeCoupon");
    return obj;
}
Also used : Coupon(com.ikoori.vip.common.persistence.model.Coupon) CouponCode(com.ikoori.vip.common.persistence.model.CouponCode) JSONObject(com.alibaba.fastjson.JSONObject) Member(com.ikoori.vip.common.persistence.model.Member) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with CouponCode

use of com.ikoori.vip.common.persistence.model.CouponCode in project vip by guangdada.

the class CouponCodeServiceImpl method genarateCode.

/**
 * 生成券码
 *
 * @Title: genarateCode
 * @param merchantId
 * @param num
 * @date: 2017年10月14日 下午1:54:43
 * @author: chengxg
 */
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public String genarateCode(Long merchantId, Integer num) {
    String batchNo = DateUtil.getAllTime();
    if (checkBatchNo(batchNo)) {
        log.info("batchNo重复");
        return null;
    }
    String ms = batchNo.substring(2);
    for (int i = 1; i <= num; i++) {
        CouponCode couponCode = new CouponCode();
        couponCode.setVerifyCode(RandomUtil.generateCouponCode());
        couponCode.setBatchNo(batchNo);
        couponCode.setVerifyNo(ms + RandomUtil.toFixdLengthString(i, 4));
        couponCode.setMerchantId(merchantId);
        couponCode.setUseStatus(CouponCodeStatus.create.getCode());
        couponCodeMapper.insert(couponCode);
    }
    return batchNo;
}
Also used : CouponCode(com.ikoori.vip.common.persistence.model.CouponCode) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with CouponCode

use of com.ikoori.vip.common.persistence.model.CouponCode in project vip by guangdada.

the class CouponCodeServiceImpl method deleteByIds.

/**
 * 批量删除
 * @Title: deleteByIds
 * @param ids
 * @date:   2017年10月15日 下午8:10:04
 * @author: chengxg
 */
@Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public void deleteByIds(Long[] ids) {
    for (Long id : ids) {
        CouponCode code = couponCodeMapper.selectById(id);
        if (code.getUseStatus().intValue() != CouponCodeStatus.create.getCode()) {
            throw new BussinessException(500, code.getVerifyNo() + "已制卡,不能删除");
        }
        couponCodeMapper.deleteById(id);
    }
}
Also used : CouponCode(com.ikoori.vip.common.persistence.model.CouponCode) BussinessException(com.ikoori.vip.common.exception.BussinessException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with CouponCode

use of com.ikoori.vip.common.persistence.model.CouponCode 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)

Aggregations

CouponCode (com.ikoori.vip.common.persistence.model.CouponCode)5 Transactional (org.springframework.transaction.annotation.Transactional)4 BussinessException (com.ikoori.vip.common.exception.BussinessException)2 Coupon (com.ikoori.vip.common.persistence.model.Coupon)2 JSONObject (com.alibaba.fastjson.JSONObject)1 Permission (com.ikoori.vip.common.annotion.Permission)1 Member (com.ikoori.vip.common.persistence.model.Member)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1