Search in sources :

Example 1 with WxUser

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

the class MemberInfoApiImpl method activeMemberByUnionid.

/**
 * 激活会员
 *
 * @Title: activeMemberByUnionid
 * @param unionid
 * @param mobile
 * @param ip
 * @param sendPack 发送红包
 * @return
 * @date: 2017年10月9日 上午10:54:16
 * @author: chengxg
 */
@Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public int activeMemberByUnionid(String unionid, String mobile, String ip, boolean sendPack) {
    synchronized (mobile.intern()) {
        log.info("进入activeMemberByUnionid>>unionid=" + unionid);
        log.info("进入activeMemberByUnionid>>mobile=" + mobile);
        int count = memberDao.registerMember(unionid, mobile);
        if (count > 0) {
            Member receiveMem = memberDao.getMemberByUnionid(unionid);
            shareService.activeShare(receiveMem);
            if (sendPack) {
                Redpack redpack = redpackService.selectByPackType(RedpackType.re.getCode(), receiveMem.getMerchantId());
                if (redpack != null) {
                    Integer amount = redpack.getAmount().multiply(new BigDecimal(100)).intValue();
                    if (redpack.getSendType().intValue() == RedpackSendType.random.getCode()) {
                        int max = redpack.getMaxAmount().multiply(new BigDecimal(100)).intValue();
                        int min = redpack.getMinAmount().multiply(new BigDecimal(100)).intValue();
                        amount = (int) (Math.random() * (max - min + 1) + min);
                    }
                    WxUser wxuser = new WxUser();
                    wxuser.setUnionid(unionid);
                    wxuser = wxUserMapper.selectOne(wxuser);
                    if (wxuser != null) {
                        redpackLogService.saveRedPackLog(amount, unionid, wxuser.getOpenid(), ip, receiveMem.getMerchantId(), redpack.getId(), redpack.getActName(), redpack.getRemark(), redpack.getWishing());
                    }
                }
            }
        }
        log.info("结束activeMemberByUnionid");
        return count;
    }
}
Also used : Redpack(com.ikoori.vip.common.persistence.model.Redpack) WxUser(com.ikoori.vip.common.persistence.model.WxUser) Member(com.ikoori.vip.common.persistence.model.Member) BigDecimal(java.math.BigDecimal) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with WxUser

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

the class MemberServiceImpl method saveMember.

@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public void saveMember(UserInfo userInfo, boolean update) throws Exception {
    log.info("进去saveMember>>userInfo:" + userInfo.toString());
    if (userInfo.getUnionid() == null) {
        log.info("微信用户unionid为空");
        throw new Exception("微信用户unionid为空");
    }
    synchronized (userInfo.getUnionid().intern()) {
        Member member = memberDao.getMemberByUnionid(userInfo.getUnionid());
        if (member == null) {
            // 保存微信用户
            log.info("保存微信用户");
            WxUser wxUser = new WxUser();
            setWxUserInfo(userInfo, wxUser);
            wxUserMapper.insert(wxUser);
            // 保存会员
            log.info("保存会员信息");
            member = new Member();
            member.setUnionid(wxUser.getUnionid());
            member.setIsActive(false);
            // 需要根据appid获得商户id
            member.setMerchantId(gunsProperties.getMerchantId());
            member.setPoints(0);
            member.setSourceType(MemSourceType.wechat.getCode());
            memberMapper.insert(member);
            // 查询获取类型为“关注微信”的会员卡
            log.info("查询获取类型为“关注微信”的会员卡");
            Card card = cardDao.getCardByGrantTypeAndMerchantId(gunsProperties.getMerchantId(), CardGrantType.SUB_WX.getCode());
            if (card == null) {
                log.info("没有找到会员卡类型");
                // throw new Exception(obj.toJSONString());
                throw new Exception("没有找到会员卡类型");
            }
            log.info("保存会员卡领取记录");
            upgradeMemberCard(member, card);
            // 关注微信返回积分
            Point point = pointDao.getSubscribeWx(member.getMerchantId());
            if (point != null) {
                pointTradeService.savePointTrade(true, PointTradeType.SUBSCRIBE_WX.getCode(), point.getPoints(), member.getId(), point.getId(), member.getMerchantId(), null, "");
            }
        } else {
            // 小程序入口,不要更新openid
            if (update) {
                log.info("用户已经存在,开始更新微信账号信息");
                WxUser wxUser = new WxUser();
                wxUser.setUnionid(userInfo.getUnionid());
                wxUser = wxUserMapper.selectOne(wxUser);
                setWxUserInfo(userInfo, wxUser);
                wxUserMapper.updateById(wxUser);
            }
        }
    }
}
Also used : WxUser(com.ikoori.vip.common.persistence.model.WxUser) Point(com.ikoori.vip.common.persistence.model.Point) Member(com.ikoori.vip.common.persistence.model.Member) BussinessException(com.ikoori.vip.common.exception.BussinessException) Card(com.ikoori.vip.common.persistence.model.Card) MemberCard(com.ikoori.vip.common.persistence.model.MemberCard) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Member (com.ikoori.vip.common.persistence.model.Member)2 WxUser (com.ikoori.vip.common.persistence.model.WxUser)2 Transactional (org.springframework.transaction.annotation.Transactional)2 BussinessException (com.ikoori.vip.common.exception.BussinessException)1 Card (com.ikoori.vip.common.persistence.model.Card)1 MemberCard (com.ikoori.vip.common.persistence.model.MemberCard)1 Point (com.ikoori.vip.common.persistence.model.Point)1 Redpack (com.ikoori.vip.common.persistence.model.Redpack)1 BigDecimal (java.math.BigDecimal)1