Search in sources :

Example 1 with CardRight

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

the class CardServiceImpl method getRigthFromJson.

private void getRigthFromJson(String rights, Long cardId) {
    List<CardRight> crs = new ArrayList<CardRight>();
    JSONArray rs = JSONArray.parseArray(rights);
    if (rs != null) {
        for (int i = 0; i < rs.size(); i++) {
            JSONObject r = rs.getJSONObject(i);
            String type = r.getString("type");
            if (type.equals(RightType.POINTS.getCode())) {
                CardRight cardRight = new CardRight();
                cardRight.setPoints(r.getInteger("points"));
                cardRight.setRightType(RightType.POINTS.getCode());
                cardRight.setCardId(cardId);
                cardRight.setIsAvailable(true);
                crs.add(cardRight);
            } else if (type.equals(RightType.DISCOUNT.getCode())) {
                CardRight cardRight = new CardRight();
                cardRight.setDiscount(r.getInteger("discount"));
                cardRight.setRightType(RightType.DISCOUNT.getCode());
                cardRight.setCardId(cardId);
                cardRight.setIsAvailable(true);
                crs.add(cardRight);
            } else if (type.equals(RightType.COUPON.getCode())) {
                JSONArray coupons = r.getJSONArray("coupon");
                if (coupons != null) {
                    for (int c = 0; c < coupons.size(); c++) {
                        CardRight cardRight = new CardRight();
                        JSONObject coupon = coupons.getJSONObject(c);
                        Long couponId = coupon.getLong("couponId");
                        Integer number = coupon.getInteger("number");
                        cardRight.setCouponId(couponId);
                        cardRight.setNumber(number);
                        cardRight.setRightType(RightType.COUPON.getCode());
                        cardRight.setCardId(cardId);
                        cardRight.setIsAvailable(true);
                        crs.add(cardRight);
                    }
                }
            }
        }
    }
    if (crs.size() >= 0) {
        for (CardRight cardRight : crs) {
            cardRightMapper.insert(cardRight);
        }
    }
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) CardRight(com.ikoori.vip.common.persistence.model.CardRight) ArrayList(java.util.ArrayList) JSONArray(com.alibaba.fastjson.JSONArray)

Example 2 with CardRight

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

the class CardController method cardUpdate.

/**
 * 跳转到修改会员卡
 */
@Permission
@RequestMapping("/card_update/{cardId}")
public String cardUpdate(@PathVariable Long cardId, 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("invalid", true);
    couponCon.put("type", CouponType.YHQ.getCode());
    model.addAttribute("merchantName", merchant.getName());
    List<Coupon> coupons = couponService.selectByCondition(couponCon);
    // 查询优惠群
    model.addAttribute("coupons", coupons);
    // 查询颜色值
    model.addAttribute("colors", ColorType.values());
    model.addAttribute("grantType", CardGrantType.values());
    Map<String, Object> condition = new HashMap<String, Object>();
    condition.put("merchantId", merchant.getId());
    condition.put("grantType", CardGrantType.NO_RULE.getCode());
    condition.put("excludeCardId", cardId);
    List<Card> cards = cardService.selectByCondition(condition);
    // 查询会员卡
    model.addAttribute("cards", cards);
    // 查询商户Logo
    model.addAttribute("logo", merchant.getHeadImg());
    Card card = cardService.selectById(cardId);
    if (StringUtils.isNotBlank(card.getColorCode())) {
        model.addAttribute("colorType", ColorType.valueOf(card.getColorCode()));
    } else {
        model.addAttribute("colorType", ColorType.Color010);
    }
    model.addAttribute(card);
    Map<String, Object> con = new HashMap<String, Object>();
    con.put("cardId", card.getId());
    List<CardRight> cardRights = cardRightService.selectByCondition(con);
    List<CardRight> couponRights = new ArrayList<CardRight>();
    if (CollectionUtils.isNotEmpty(cardRights)) {
        for (CardRight cardRight : cardRights) {
            if (cardRight.getRightType().equals(RightType.DISCOUNT.getCode())) {
                model.addAttribute(RightType.DISCOUNT.getCode(), cardRight);
            } else if (cardRight.getRightType().equals(RightType.POINTS.getCode())) {
                model.addAttribute(RightType.POINTS.getCode(), cardRight);
            } else if (cardRight.getRightType().equals(RightType.COUPON.getCode())) {
                couponRights.add(cardRight);
            }
        }
    }
    model.addAttribute(RightType.COUPON.getCode(), couponRights);
    return PREFIX + "card_edit.html";
}
Also used : Coupon(com.ikoori.vip.common.persistence.model.Coupon) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Card(com.ikoori.vip.common.persistence.model.Card) Merchant(com.ikoori.vip.common.persistence.model.Merchant) CardRight(com.ikoori.vip.common.persistence.model.CardRight) Permission(com.ikoori.vip.common.annotion.Permission) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with CardRight

use of com.ikoori.vip.common.persistence.model.CardRight 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 4 with CardRight

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

the class MemberServiceImpl method initCard.

public JSONObject initCard(Long memberId) {
    // 获得会员的默认会员卡
    Map<String, Object> defaultCard = memberCardDao.selectByMemberId(memberId);
    if (defaultCard == null) {
        log.info("没有找到会员卡>>memberId=" + memberId);
        return null;
    }
    JSONObject obj = new JSONObject();
    obj.put("cardNumber", defaultCard.get("cardNumber"));
    obj.put("name", defaultCard.get("name"));
    obj.put("description", defaultCard.get("description"));
    obj.put("state", MemCardState.USED.getCode());
    // 判断是否生效或过期
    Object grantType = defaultCard.get("grantType");
    Object termType = defaultCard.get("termType");
    Object termDays = defaultCard.get("termDays");
    Object termStartAt = defaultCard.get("termStartAt");
    Object termEndAt = defaultCard.get("termEndAt");
    Object createTime = defaultCard.get("createTime");
    // 按规则升级的会员卡无限期,其他的需要判断期限
    if (grantType != null && CardGrantType.RULE.getCode() != Integer.valueOf(grantType.toString())) {
        if (termType != null) {
            int tt = Integer.valueOf(termType.toString());
            String nowDay = DateUtil.getDay();
            if (CardTermsType.DAYS.getCode() == tt) {
                // 1、有效期为 XX天
                int days = Integer.valueOf(termDays.toString());
                // 计算领取日期和当前日期相隔天数,是否大于设置的天数
                long daySub = DateUtil.getDaySub(createTime.toString(), nowDay);
                if (daySub > days) {
                    obj.put("state", MemCardState.EXPIRED.getCode());
                }
            } else if (CardTermsType.RANGE.getCode() == tt) {
                // 2、有效期开始和结束时间,判断当前日期是否在生效和失效时间内
                if (!DateUtil.compareDate(nowDay, termStartAt.toString())) {
                    // 未到 生效 时间
                    obj.put("state", MemCardState.UN_USED.getCode());
                } else if (!DateUtil.compareDate(termEndAt.toString(), nowDay)) {
                    // 超过失效时间
                    obj.put("state", MemCardState.EXPIRED.getCode());
                }
            }
        }
    }
    // 获得会员卡权益
    Long cardId = Long.valueOf("" + defaultCard.get("cardId"));
    List<CardRight> cardRights = cardRightDao.selectByCardId(cardId);
    JSONArray rights = new JSONArray();
    if (CollectionUtils.isNotEmpty(cardRights)) {
        for (CardRight cardRight : cardRights) {
            if (cardRight.getRightType().equals(RightType.DISCOUNT.getCode())) {
                JSONObject right = new JSONObject();
                right.put(RightType.DISCOUNT.getCode(), cardRight.getDiscount());
                rights.add(right);
            }
        }
    }
    // 超过限额则查询差额后使用的会员卡
    Object amountLimitCardId = defaultCard.get("amountLimitCardId");
    Object tradeAmountLimit = defaultCard.get("tradeAmountLimit");
    if (amountLimitCardId != null && tradeAmountLimit != null) {
        CardRight cardRight = cardRightDao.selectByRightType(Long.valueOf(amountLimitCardId.toString()), RightType.DISCOUNT.getCode());
        if (cardRight != null) {
            // 超额后使用的折扣
            Integer newDiscount = cardRight.getDiscount();
            // 当月总购买金额
            Integer tradeAmount = orderDao.selectMemTradeAmount(memberId);
            obj.put("newDiscount", newDiscount);
            obj.put("limitAmount", tradeAmountLimit);
            obj.put("availableAmount", Integer.valueOf(tradeAmountLimit.toString()) - (tradeAmount == null ? 0 : tradeAmount));
        }
    }
    obj.put("cardRights", rights);
    log.info("查找会员卡initCard>>obj=" + obj.toJSONString());
    return obj;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) CardRight(com.ikoori.vip.common.persistence.model.CardRight) JSONArray(com.alibaba.fastjson.JSONArray) JSONObject(com.alibaba.fastjson.JSONObject) Point(com.ikoori.vip.common.persistence.model.Point)

Aggregations

CardRight (com.ikoori.vip.common.persistence.model.CardRight)4 JSONArray (com.alibaba.fastjson.JSONArray)2 JSONObject (com.alibaba.fastjson.JSONObject)2 Coupon (com.ikoori.vip.common.persistence.model.Coupon)2 Point (com.ikoori.vip.common.persistence.model.Point)2 ArrayList (java.util.ArrayList)2 Permission (com.ikoori.vip.common.annotion.Permission)1 Card (com.ikoori.vip.common.persistence.model.Card)1 MemberCard (com.ikoori.vip.common.persistence.model.MemberCard)1 Merchant (com.ikoori.vip.common.persistence.model.Merchant)1 HashMap (java.util.HashMap)1 Transactional (org.springframework.transaction.annotation.Transactional)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1