Search in sources :

Example 11 with Coupon

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

the class ShareController method shareUpdate.

/**
 * 跳转到修改分享规则
 */
@Permission
@RequestMapping("/share_update/{shareId}")
public String shareUpdate(@PathVariable Long shareId, Model model) {
    Long userId = Long.valueOf(ShiroKit.getUser().getId());
    Merchant merchant = merchantService.getMerchantUserId(userId);
    Map<String, Object> couponCon = new HashMap<String, Object>();
    couponCon.put("merchantId", merchant.getId());
    couponCon.put("type", CouponType.YHQ.getCode());
    couponCon.put("invalid", true);
    List<Coupon> coupons = couponService.selectByCondition(couponCon);
    Share share = shareService.selectById(shareId);
    model.addAttribute(share);
    // 查询优惠群
    model.addAttribute("coupons", coupons);
    return PREFIX + "share_edit.html";
}
Also used : Coupon(com.ikoori.vip.common.persistence.model.Coupon) Merchant(com.ikoori.vip.common.persistence.model.Merchant) HashMap(java.util.HashMap) Share(com.ikoori.vip.common.persistence.model.Share) Permission(com.ikoori.vip.common.annotion.Permission) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with Coupon

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

the class ShareController method shareAdd.

/**
 * 跳转到添加分享规则
 */
@Permission
@RequestMapping("/share_add")
public String shareAdd(Model model) {
    Long userId = Long.valueOf(ShiroKit.getUser().getId());
    Merchant merchant = merchantService.getMerchantUserId(userId);
    Map<String, Object> couponCon = new HashMap<String, Object>();
    couponCon.put("merchantId", merchant.getId());
    couponCon.put("type", CouponType.YHQ.getCode());
    couponCon.put("invalid", true);
    List<Coupon> coupons = couponService.selectByCondition(couponCon);
    // 查询优惠群
    model.addAttribute("coupons", coupons);
    return PREFIX + "share_add.html";
}
Also used : Coupon(com.ikoori.vip.common.persistence.model.Coupon) Merchant(com.ikoori.vip.common.persistence.model.Merchant) HashMap(java.util.HashMap) Permission(com.ikoori.vip.common.annotion.Permission) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with Coupon

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

the class MemberServiceImpl method upgradeMemberCard.

/**
 * 升级会员卡和权益
 * @Title: upgradeMemCard
 * @param member
 * @param card
 * @date:   2017年9月18日 下午1:51:33
 * @author: chengxg
 */
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public void upgradeMemberCard(Member member, Card card) {
    MemberCard mc = getMemberCard(member.getId(), card.getId());
    if (mc != null) {
        log.info("已经有该级别会员卡");
        // 已经有该级别会员卡
        mc.setIsDefault(true);
        memberCardMapper.updateById(mc);
    } else {
        log.info("没有该级别会员卡,发送一张");
        // 没有该级别会员卡
        MemberCard memCard = new MemberCard();
        memCard.setCardId(card.getId());
        memCard.setCardNumber(RandomUtil.generateCardNum(card.getCardNumberPrefix()));
        memCard.setMemberId(member.getId());
        memCard.setMerchantId(member.getMerchantId());
        memCard.setState(MemCardState.USED.getCode());
        memCard.setIsDefault(true);
        memberCardMapper.insert(memCard);
        // 获取会员卡权益
        log.info("获取会员卡权益");
        List<CardRight> cardRights = cardRightDao.selectByCardId(card.getId());
        if (CollectionUtils.isNotEmpty(cardRights)) {
            for (CardRight cardRight : cardRights) {
                if (RightType.COUPON.getCode().equals(cardRight.getRightType())) {
                    log.info("赠送id=" + cardRight.getCouponId() + "的优惠券");
                    Coupon coupon = couponMapper.selectById(cardRight.getCouponId());
                    Integer number = cardRight.getNumber();
                    log.info("赠送数量为:" + number);
                    log.info("剩余数量为:" + coupon.getStock());
                    if (number != null) {
                        // 更新库存数
                        int us = couponDao.updateStock(coupon.getId(), number);
                        if (us == 0) {
                            log.info("修改库存失败");
                            continue;
                        }
                        // 跟新领取人数
                        int uu = couponDao.updateGetCountUser(coupon.getId(), member.getId());
                        if (uu == 0) {
                            log.info("修改领取人数失败:" + uu);
                        }
                        log.info("保存优惠券领取记录");
                        for (int i = 0; i < number.intValue(); i++) {
                            // 保存领取记录
                            couponFetchService.saveCouponFetch(member, coupon, null);
                        }
                    }
                } else if (RightType.POINTS.getCode().equals(cardRight.getRightType())) {
                    log.info("赠送积分:" + cardRight.getPoints());
                    pointTradeService.savePointTrade(true, PointTradeType.CARD.getCode(), cardRight.getPoints(), member.getId(), null, member.getMerchantId(), null, "");
                }
            }
        }
    // 获得关注微信的积分规则
    }
    // 修改会员的默认会员卡
    log.info("修改会员的默认会员卡");
    updateDefaultCard(card.getId(), member.getId());
}
Also used : Coupon(com.ikoori.vip.common.persistence.model.Coupon) MemberCard(com.ikoori.vip.common.persistence.model.MemberCard) CardRight(com.ikoori.vip.common.persistence.model.CardRight) Point(com.ikoori.vip.common.persistence.model.Point) Transactional(org.springframework.transaction.annotation.Transactional)

Example 14 with Coupon

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

the class CouponServiceImpl method saveCoupon.

/**
 * 优惠券保存
 * @Title: saveCoupon
 * @param coupon
 * @date:   2017年9月18日 下午2:34:36
 * @author: chengxg
 */
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public void saveCoupon(Coupon coupon, String storeIds) {
    if (coupon.getValue() != null) {
        coupon.setOriginValue(coupon.getValue() * 100);
    }
    if (!coupon.isIsAtLeast()) {
        coupon.setAtLeast(null);
        coupon.setOriginAtLeast(null);
        coupon.setUseCondition("不限制");
    }
    if (coupon.getAtLeast() != null) {
        coupon.setOriginAtLeast(coupon.getAtLeast() * 100);
        coupon.setUseCondition("满" + coupon.getAtLeast() + "元使用");
    }
    coupon.setStartTime(coupon.getStartAt().getTime());
    coupon.setEndTime(coupon.getEndAt().getTime());
    coupon.setLimitStore(StringUtils.isBlank(storeIds) ? false : true);
    if (coupon.getId() != null) {
        Coupon couponDb = couponMapper.selectById(coupon.getId());
        if (coupon.getTotal() < couponDb.getGetCount()) {
            throw new BussinessException(500, "发放总量不能小于领取数量" + couponDb.getGetCount());
        }
        int stock = coupon.getTotal() - couponDb.getTotal();
        couponDb.setStock(couponDb.getStock() + stock);
        couponDb.setName(coupon.getName());
        couponDb.setTotal(coupon.getTotal());
        couponDb.setValue(coupon.getValue());
        couponDb.setType(coupon.getType());
        couponDb.setIsAtLeast(coupon.isIsAtLeast());
        couponDb.setIsShare(coupon.isIsShare());
        couponDb.setAtLeast(coupon.getAtLeast());
        couponDb.setCardId(coupon.getCardId());
        couponDb.setQuota(coupon.getQuota());
        couponDb.setDescription(coupon.getDescription());
        couponDb.setServicePhone(coupon.getServicePhone());
        couponDb.setStartAt(coupon.getStartAt());
        couponDb.setEndAt(coupon.getEndAt());
        couponDb.setUpdateTime(new Date());
        couponMapper.updateAllColumnById(couponDb);
    } else {
        // 优惠券别名,用于领取的时候替代ID
        coupon.setAlias(UUID.randomUUID().toString().replaceAll("-", ""));
        coupon.setUrl(gunsProperties.getClientUrl() + "/coupon/tofetch/" + coupon.getAlias());
        couponMapper.insert(coupon);
    }
    // 保存优惠券可用店铺
    storeCouponService.saveStoreCoupon(coupon.getId(), storeIds);
}
Also used : Coupon(com.ikoori.vip.common.persistence.model.Coupon) BussinessException(com.ikoori.vip.common.exception.BussinessException) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with Coupon

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

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