Search in sources :

Example 1 with Member

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

the class WebMemberController method getCoupon.

@ApiOperation("根据手机号获得优惠券")
@RequestMapping(value = "getCoupon", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> getCoupon(@ApiParam(value = "店铺编号", required = true) @RequestParam(required = true) String storeNo, @ApiParam(value = "手机号", required = true) @RequestParam(required = true) String mobile, @ApiParam(value = "签名", required = true) @RequestParam(required = true) String sign) {
    Map<String, Object> result = new HashMap<String, Object>();
    result.put("code", "200");
    result.put("msg", "请求成功");
    try {
        boolean isSign = true;
        if (gunsProperties.isCheckSign()) {
            Map<String, String> data = new HashMap<String, String>();
            data.put("storeNo", storeNo);
            data.put("mobile", mobile);
            data.put("sign", sign);
            isSign = WXPayUtil.isSignatureValid(data, gunsProperties.getSignKey());
            if (!isSign) {
                result.put("code", "500");
                result.put("msg", "签名失败");
            }
        }
        if (isSign) {
            Member member = memberService.selectByMobile(mobile);
            JSONArray content = initCoupon(member.getId(), storeNo);
            result.put("content", content);
        }
    } catch (Exception e) {
        log.error("", e);
        result.put("code", "500");
        result.put("msg", "请求失败");
    }
    return result;
}
Also used : HashMap(java.util.HashMap) JSONArray(com.alibaba.fastjson.JSONArray) JSONObject(com.alibaba.fastjson.JSONObject) Member(com.ikoori.vip.common.persistence.model.Member) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with Member

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

the class WebMemberController method info.

@ApiOperation("根据手机号获得优惠券、积分、会员卡")
@RequestMapping(value = "info", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> info(@ApiParam(value = "店铺编号", required = true) @RequestParam(required = true) String storeNo, @ApiParam(value = "手机号", required = true) @RequestParam(required = true) String mobile, @ApiParam(value = "签名", required = true) @RequestParam(required = true) String sign) {
    Map<String, Object> result = new HashMap<String, Object>();
    result.put("code", "200");
    result.put("msg", "请求成功");
    try {
        boolean isSign = true;
        if (gunsProperties.isCheckSign()) {
            Map<String, String> data = new HashMap<String, String>();
            data.put("storeNo", storeNo);
            data.put("mobile", mobile);
            data.put("sign", sign);
            isSign = WXPayUtil.isSignatureValid(data, gunsProperties.getSignKey());
            if (!isSign) {
                result.put("code", "500");
                result.put("msg", "签名失败");
            }
        }
        if (isSign) {
            JSONObject content = new JSONObject();
            Member member = memberService.selectByMobile(mobile);
            JSONObject card = memberService.initCard(member.getId());
            JSONArray coupons = initCoupon(member.getId(), storeNo);
            content.put("mobile", member.getMobile());
            content.put("point", member.getPoints());
            content.put("card", card);
            content.put("coupon", coupons);
            result.put("content", content);
        }
    } catch (Exception e) {
        log.error("", e);
        result.put("code", "500");
        result.put("msg", "请求失败");
    }
    return result;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) HashMap(java.util.HashMap) JSONArray(com.alibaba.fastjson.JSONArray) JSONObject(com.alibaba.fastjson.JSONObject) Member(com.ikoori.vip.common.persistence.model.Member) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with Member

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

the class WebMemberController method getPoints.

@ApiOperation("根据手机号获得会员积分")
@RequestMapping(value = "getPoints", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> getPoints(@ApiParam(value = "店铺编号", required = true) @RequestParam(required = true) String storeNo, @ApiParam(value = "手机号", required = true) @RequestParam(required = true) String mobile, @ApiParam(value = "签名", required = true) @RequestParam(required = true) String sign) {
    Map<String, Object> result = new HashMap<String, Object>();
    result.put("code", "200");
    result.put("msg", "请求成功");
    try {
        boolean isSign = true;
        if (gunsProperties.isCheckSign()) {
            Map<String, String> data = new HashMap<String, String>();
            data.put("storeNo", storeNo);
            data.put("mobile", mobile);
            data.put("sign", sign);
            isSign = WXPayUtil.isSignatureValid(data, gunsProperties.getSignKey());
            if (!isSign) {
                result.put("code", "500");
                result.put("msg", "签名失败");
            }
        }
        if (isSign) {
            JSONObject obj = new JSONObject();
            Member member = memberService.selectByMobile(mobile);
            obj.put("mobile", member.getMobile());
            obj.put("point", member.getPoints());
            result.put("content", obj);
        }
    } catch (Exception e) {
        log.error("", e);
        result.put("code", "500");
        result.put("msg", "请求失败");
    }
    return result;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) HashMap(java.util.HashMap) JSONObject(com.alibaba.fastjson.JSONObject) Member(com.ikoori.vip.common.persistence.model.Member) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with Member

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

the class OrderServiceImpl method saveOrder.

/**
 * 保存门店订单数据
 * 扣减使用的优惠券
 * 扣减 使用的积分
 * 根据积分规则累加积分
 * 根据会员卡规则升级会员卡
 */
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public void saveOrder(OrderPayDo orderPayDo) throws Exception {
    log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>保存门店订单数据>>>>>>>>>>>>>>>>>>>>>>>>");
    Store store = storeDao.selectByStoreNo(orderPayDo.getStoreNo());
    if (store == null) {
        log.error("没有找到店铺信息,店铺编号:" + orderPayDo.getStoreNo());
        throw new BussinessException(500, "没有找到店铺信息");
    }
    // 判断积分是否足够
    Member member = null;
    if (StringUtils.isNotBlank(orderPayDo.getMobile())) {
        member = memberDao.selectByMobile(orderPayDo.getMobile());
    } else if (StringUtils.isNotBlank(orderPayDo.getOpenid())) {
        member = memberDao.getMemberByOpenid(orderPayDo.getOpenid());
    }
    if (member == null) {
        log.error("没有找到该会员信息>>" + orderPayDo.getMobile());
        throw new BussinessException(500, "没有找到该会员信息");
    }
    // 修改会员交易笔数和交易金额
    member.setLastTradeTime(new Date());
    member.setTradeAmount(member.getTradeAmount().add(new BigDecimal(orderPayDo.getPayment()).divide(new BigDecimal(100))));
    member.setTradeCount(member.getTradeCount() + 1);
    memberMapper.updateById(member);
    log.info("保存订单");
    // 保存order
    Order order = new Order();
    order.setPayOrderNo(orderPayDo.getOrderNo());
    order.setOrderNo(RandomUtil.generateOrderNo());
    order.setStoreId(store.getId());
    order.setBalanceDue(orderPayDo.getBalanceDue());
    order.setPayment(orderPayDo.getPayment());
    order.setDiscount(orderPayDo.getDiscount());
    order.setPayStatus(1);
    order.setMemberId(member.getId());
    order.setProductNum(orderPayDo.getOrderItems().size());
    order.setOrderSource(orderPayDo.getOrderSource());
    // order.setDiscountInfo(discountInfo);
    orderMapper.insert(order);
    log.info("保存订单明细");
    // 保存orderItem
    List<OrderItemPayDo> itemPayDos = orderPayDo.getOrderItems();
    if (itemPayDos != null) {
        for (OrderItemPayDo itemPayDo : itemPayDos) {
            OrderItem orderItem = new OrderItem();
            orderItem.setOrderId(order.getId());
            orderItem.setOrderNo(order.getOrderNo());
            orderItem.setGoodsName(itemPayDo.getGoodsName());
            orderItem.setQuantity(itemPayDo.getQuantity());
            orderItem.setGoodsNo(itemPayDo.getGoodsNo());
            orderItem.setCasePrice(itemPayDo.getCasePrice());
            orderItem.setModel(itemPayDo.getModel());
            orderItem.setOriginalPrice(itemPayDo.getOriginalPrice());
            orderItemMapper.insert(orderItem);
        }
    }
    log.info("扣减使用的积分:" + orderPayDo.getPoint());
    // 扣减使用的积分
    if (orderPayDo.getPoint() != null && (orderPayDo.getPoint() > 0)) {
        if (member.getPoints() < orderPayDo.getPoint()) {
            log.error("积分不足,剩余积分" + member.getPoints());
            throw new BussinessException(500, "积分不足,剩余积分" + member.getPoints());
        }
        log.error("生成积分使用记录");
        boolean result = pointTradeService.savePointTrade(false, PointTradeType.PAY_ORDER.getCode(), -orderPayDo.getPoint(), member.getId(), null, member.getMerchantId(), store.getId(), "");
        if (!result) {
            log.error("扣减积分失败");
            throw new BussinessException(500, "扣减积分失败");
        }
    }
    log.info("扣减使用现金券");
    // 扣减使用现金券
    if (orderPayDo.getCoupons() != null) {
        for (CouponPayDo couPayDo : orderPayDo.getCoupons()) {
            Integer usedValue = couPayDo.getUsedValue();
            String verifyCode = couPayDo.getVerifyCode();
            String msg = "优惠券:" + verifyCode;
            // 根据券码获得优惠券
            log.info("根据券码获得优惠券:" + verifyCode);
            // CouponFetch cf = couponFetchDao.selectByVerifyCodeJoinCoupon(verifyCode);
            CouponFetch cf = couponFetchDao.selectByVerifyCode(verifyCode);
            if (cf == null) {
                throw new BussinessException(500, msg + ",没有找到");
            }
            Coupon coupon = couponMapper.selectById(cf.getCouponId());
            if (coupon.isIsAtLeast()) {
                if (coupon.getOriginAtLeast() < orderPayDo.getBalanceDue()) {
                    throw new BussinessException(500, msg + ",购物满" + coupon.getAtLeast() + "元才能使用");
                }
            }
            // 代金券判断是否已经使用,改成已使用
            if (!cf.getIsInvalid()) {
                throw new BussinessException(500, msg + ",已经失效");
            }
            if (cf.getIsUsed().intValue() == CouponUseState.USED.getCode()) {
                throw new BussinessException(500, msg + ",已经被使用");
            }
            if (!cf.getMemberId().toString().equals(member.getId().toString())) {
                throw new BussinessException(500, msg + ",不是本人的");
            }
            if (usedValue > cf.getValue()) {
                throw new BussinessException(500, msg + "面值为" + cf.getValue() / 100 + "元,余额不足");
            }
            /*只精确到天*/
            /*String validTime = DateUtil.format(cf.getValidTime(), DateUtil.dateFormat);
				String expireTime = DateUtil.format(cf.getExpireTime(), DateUtil.dateFormat);
				// 是否已生效
				if(!DateUtil.compareDate(DateUtil.getDay(),validTime)){
					throw new BussinessException(500,msg + ",还未生效");
				}
				// 是否已过期
				if(!DateUtil.compareDate(expireTime,DateUtil.getDay())){
					throw new BussinessException(500,msg + ",已经过期");
				}*/
            /*精确到秒*/
            Date now = new Date();
            // 是否已生效
            if (!DateUtil.compareWithLongTime(now, cf.getValidTime())) {
                throw new BussinessException(500, msg + ",还未生效");
            }
            // 是否已过期
            if (!DateUtil.compareWithLongTime(cf.getExpireTime(), now)) {
                throw new BussinessException(500, msg + ",已经过期");
            }
            // 现金券扣减使用金额、没使用完改成部分使用,判断余额是否足够
            if (coupon.getType().intValue() == CouponType.XJQ.getCode()) {
                if (usedValue > cf.getAvailableValue()) {
                    throw new BussinessException(500, msg + "可用金额为" + cf.getAvailableValue() / 100 + "元,余额不足");
                }
                // 扣减现金券使用金额
                cf.setUsedValue(cf.getUsedValue() + usedValue);
                cf.setAvailableValue(cf.getAvailableValue() - usedValue);
                // 使用完了
                if (cf.getAvailableValue() == 0) {
                    cf.setIsUsed(CouponUseState.USED.getCode());
                    cf.setIsInvalid(false);
                } else {
                    cf.setIsUsed(CouponUseState.PART_USED.getCode());
                }
            } else {
                // 优惠券修改为已使用状态
                cf.setIsUsed(CouponUseState.USED.getCode());
                cf.setIsInvalid(false);
            }
            cf.setVersion(cf.getVersion());
            int count = couponFetchMapper.updateById(cf);
            if (count == 0) {
                throw new BussinessException(500, "优惠券使用失败");
            }
            log.info("生成优惠券使用记录");
            // 生成优惠券使用记录
            CouponTrade couponTrade = new CouponTrade();
            couponTrade.setCouponId(coupon.getId());
            couponTrade.setMemberId(member.getId());
            couponTrade.setStoreId(store.getId());
            couponTrade.setMerchantId(member.getMerchantId());
            couponTrade.setUsedValue(usedValue);
            couponTrade.setUsedOrderNo(order.getOrderNo());
            couponTrade.setUsedOrderId(order.getId());
            couponTrade.setVerifyCode(verifyCode);
            couponTrade.setUsedTime(new Date());
            couponTradeMapper.insert(couponTrade);
            // 更新优惠券使用次数
            log.info("更新优惠券使用次数");
            couponDao.updateUseCount(coupon.getId(), 1);
        }
    }
    // 根据积分规则返还积分
    log.info("根据积分规则返还积分");
    List<Point> points = pointDao.selectByMerchantId(member.getMerchantId());
    if (points != null) {
        for (Point point : points) {
            // 生成积分使用记录
            PointTrade pointTrade = new PointTrade();
            int p = point.getPoints();
            if (point.getRuleType().intValue() == PointType.PAY_MONEY.getCode()) {
                // 求当前订单金额和限制金额的除数
                int due = orderPayDo.getPayment() / point.getPointsLimit();
                // 比如每购买10元送1积分,当前订单金额为100的话,得到的除数为10*奖励分值,即为要返还的积分数
                pointTrade.setPoint(p * due);
                pointTrade.setTradeType(PointTradeType.ORDER_MONEY.getCode());
            }
            if (point.getRuleType().intValue() == PointType.PAY_ORDER.getCode()) {
                // 查询上一次按购买数量获得积分的记录id
                Long lastOrderId = getLastOrderId(member.getId());
                // 获得之后的购买次数+1(当前算一次)
                int orderCount = getMemOrderCount(member.getId(), lastOrderId);
                // 判断累加后的数量是否大于等于限制条件
                if ((orderCount + 1) >= point.getPointsLimit()) {
                    pointTrade.setPoint(p);
                    pointTrade.setTradeType(PointTradeType.ORDER_COUNT.getCode());
                }
            }
            if (pointTrade.getPoint() != null && pointTrade.getPoint() > 0) {
                log.info("返还积分:" + pointTrade.getPoint());
                pointTrade.setPointId(point.getId());
                pointTrade.setMemberId(member.getId());
                pointTrade.setOrderId(order.getId());
                pointTrade.setInOut(true);
                pointTrade.setMerchantId(member.getMerchantId());
                pointTrade.setStoreId(store.getId());
                pointTradeMapper.insert(pointTrade);
                int count = memberDao.updatePoint(member.getId(), pointTrade.getPoint());
                // 修改会员积分
                log.info("累加会员积分");
                if (count == 0) {
                    throw new BussinessException(500, "累加积分失败");
                }
            }
        }
    }
    // 判断是否满足会员卡升级条件
    // 查询所有的"按规则"类别的会员卡,按等级升序排序后,逐个判断是否满足升级到改卡
    log.info("判断是否满足会员卡升级条件");
    List<Card> cards = cardDao.selectByMerchantId(member.getMerchantId());
    if (CollectionUtils.isNotEmpty(cards)) {
        // 获得累计订单数量
        int orderCount = getMemOrderCount(member.getId(), 0L);
        // 获得累计交易金额
        Integer totalPayment = getMemPaymemt(member.getId(), 0L);
        // 获得累计积分
        Member mem = memberMapper.selectById(member.getId());
        Integer point = mem.getPoints();
        for (Card card : cards) {
            Integer tradeLimit = card.getTradeLimit();
            Integer pointsLimit = card.getPointsLimit();
            Integer amountLimit = card.getAmountLimit();
            boolean upgrade = false;
            if (tradeLimit != null && orderCount >= tradeLimit) {
                upgrade = true;
            } else if (pointsLimit != null && point >= pointsLimit) {
                upgrade = true;
            } else if (amountLimit != null && totalPayment >= (amountLimit * 100)) {
                upgrade = true;
            }
            // 满足升级条件,升级到该会员卡
            if (upgrade) {
                log.info("升级会员:" + mem.getId() + "到会员卡" + card.getId());
                memberService.upgradeMemberCard(member, card);
                // 满足最高等级会员卡升级条件则退出
                break;
            }
        }
    }
    log.info("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<保存门店订单数据<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
}
Also used : Order(com.ikoori.vip.common.persistence.model.Order) Coupon(com.ikoori.vip.common.persistence.model.Coupon) CouponFetch(com.ikoori.vip.common.persistence.model.CouponFetch) CouponTrade(com.ikoori.vip.common.persistence.model.CouponTrade) OrderItemPayDo(com.ikoori.vip.common.dto.OrderItemPayDo) Store(com.ikoori.vip.common.persistence.model.Store) Point(com.ikoori.vip.common.persistence.model.Point) BussinessException(com.ikoori.vip.common.exception.BussinessException) Date(java.util.Date) BigDecimal(java.math.BigDecimal) Point(com.ikoori.vip.common.persistence.model.Point) Card(com.ikoori.vip.common.persistence.model.Card) CouponPayDo(com.ikoori.vip.common.dto.CouponPayDo) OrderItem(com.ikoori.vip.common.persistence.model.OrderItem) PointTrade(com.ikoori.vip.common.persistence.model.PointTrade) Member(com.ikoori.vip.common.persistence.model.Member) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with Member

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

the class ShareServiceImpl method activeShare.

/**
 * 受邀人激活成功后,奖励邀请人
 *
 * @Title: activeShare
 * @param receiveMem 受邀人
 * @date: 2017年10月9日 上午10:04:53
 * @author: chengxg
 */
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public void activeShare(Member receiveMem) {
    log.info("进入activeShare" + receiveMem.getUnionid());
    // Member receiveMem = memberDao.getMemberByUnionid(receiveUnionid);
    // 获得分享规则
    Share share = getShare(receiveMem.getMerchantId());
    if (share == null) {
        log.info("没有设置分享规则");
        return;
    }
    // 获得邀请记录,得到邀请人信息
    ShareLog shareLog = getShareLog(receiveMem.getUnionid());
    if (shareLog == null) {
        log.info("没有找到邀请记录");
        return;
    }
    // 判断邀请人当月已经邀请人数(激活成功为准)是否已经超过限制
    if (share.getShareCount() != null) {
        int shareCount = shareLogDao.getShareCount(shareLog.getShareUnionid(), DateUtil.getDay(shareLog.getCreateTime()));
        if (shareCount >= share.getShareCount()) {
            log.info("邀请人当月邀请人数为:" + shareCount + "超过限制的:" + share.getShareCount());
            return;
        }
    }
    // 同一IP仅限第一个注册的好友加积分
    int shareIpCount = getShareCountByIp(shareLog.getShareUnionid(), shareLog.getReceiveIp());
    if (shareIpCount >= 1) {
        log.info("邀请人已经邀请过ip:" + shareLog.getReceiveIp() + "获得奖励");
        return;
    }
    // 邀请人
    Member shareMem = memberDao.getMemberByUnionid(shareLog.getShareUnionid());
    if (shareMem == null) {
        log.info("没有找到unionid:" + shareLog.getShareUnionid() + "的邀请人");
        return;
    }
    // 赠送邀请人积分或优惠券
    Integer point = share.getPoint();
    if (point != null) {
        log.info("奖励邀请人积分:" + point);
        pointTradeService.savePointTrade(true, PointTradeType.SHARE.getCode(), point, shareMem.getId(), null, shareMem.getMerchantId(), null, "");
    }
    Long couponId = share.getCouponId();
    if (couponId != null) {
        Coupon coupon = couponMapper.selectById(couponId);
        log.info("奖励邀请人优惠券:" + coupon.getName());
        couponFetchService.saveCouponFetch(shareMem, coupon, null);
    }
    // 修改邀请记录状态为“邀请成功”
    shareLog.setReceiveStatus(true);
    shareLogMapper.updateById(shareLog);
    log.info("结束activeShare");
}
Also used : ShareLog(com.ikoori.vip.common.persistence.model.ShareLog) Coupon(com.ikoori.vip.common.persistence.model.Coupon) Share(com.ikoori.vip.common.persistence.model.Share) Member(com.ikoori.vip.common.persistence.model.Member) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Member (com.ikoori.vip.common.persistence.model.Member)23 JSONObject (com.alibaba.fastjson.JSONObject)12 Transactional (org.springframework.transaction.annotation.Transactional)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 Card (com.ikoori.vip.common.persistence.model.Card)5 MemberCard (com.ikoori.vip.common.persistence.model.MemberCard)5 HashMap (java.util.HashMap)5 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)5 BussinessException (com.ikoori.vip.common.exception.BussinessException)4 Coupon (com.ikoori.vip.common.persistence.model.Coupon)4 ApiOperation (io.swagger.annotations.ApiOperation)4 JSONArray (com.alibaba.fastjson.JSONArray)3 Date (java.util.Date)3 EntityWrapper (com.baomidou.mybatisplus.mapper.EntityWrapper)2 Permission (com.ikoori.vip.common.annotion.Permission)2 Merchant (com.ikoori.vip.common.persistence.model.Merchant)2 Point (com.ikoori.vip.common.persistence.model.Point)2 ShareLog (com.ikoori.vip.common.persistence.model.ShareLog)2 WxUser (com.ikoori.vip.common.persistence.model.WxUser)2 BigDecimal (java.math.BigDecimal)2