Search in sources :

Example 1 with Redpack

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

the class RedpackServiceImpl method saveRedPack.

@Override
public void saveRedPack(Redpack redpack) {
    // 根据发放类型,清除金额
    BigDecimal cleanAmount = new BigDecimal("0");
    if (redpack.getSendType().intValue() == RedpackSendType.fixed.getCode()) {
        redpack.setMinAmount(cleanAmount);
        redpack.setMaxAmount(cleanAmount);
    } else {
        redpack.setAmount(cleanAmount);
    }
    // 根据红包类型查找红包规则记录
    Redpack rpack = new Redpack();
    rpack.setPackType(redpack.getPackType());
    rpack.setStatus(1);
    rpack = redpackMapper.selectOne(rpack);
    if (redpack.getId() == null) {
        if (rpack != null) {
            throw new BussinessException(BizExceptionEnum.EXISTED_PACKTYPE);
        } else {
            redpackMapper.insert(redpack);
        }
    } else {
        Redpack repack = this.selectById(redpack.getId());
        if (redpack.getPackType() == repack.getPackType()) {
            redpackMapper.updateById(redpack);
        } else {
            if (rpack == null) {
                redpackMapper.updateById(redpack);
            } else {
                throw new BussinessException(BizExceptionEnum.EXISTED_PACKTYPE);
            }
        }
    }
}
Also used : Redpack(com.ikoori.vip.common.persistence.model.Redpack) BigDecimal(java.math.BigDecimal) BussinessException(com.ikoori.vip.common.exception.BussinessException)

Example 2 with Redpack

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

the class RedpackLogController method index.

/**
 * 跳转到红包记录首页
 */
@RequestMapping("")
@Permission
public String index(Model model) {
    Long userId = Long.valueOf(ShiroKit.getUser().getId());
    Merchant merchant = merchantService.getMerchantUserId(userId);
    List<Redpack> redpacks = redpackService.selectByMerchantId(merchant.getId());
    model.addAttribute("sendStatus", RedPackSendStatus.values());
    model.addAttribute("redpacks", redpacks);
    return PREFIX + "redpackLog.html";
}
Also used : Merchant(com.ikoori.vip.common.persistence.model.Merchant) Redpack(com.ikoori.vip.common.persistence.model.Redpack) Permission(com.ikoori.vip.common.annotion.Permission) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with Redpack

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

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

the class RedpackController method redpackUpdate.

/**
 * 跳转到修改红包
 */
@RequestMapping("/redpack_update/{redpackId}")
public String redpackUpdate(@PathVariable Long redpackId, Model model) {
    Redpack redpack = redpackService.selectById(redpackId);
    if (redpack == null) {
        throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
    }
    // model.addAttribute("amount", redpack.getAmount() == null ? "" : redpack.getAmount() / 100);
    // model.addAttribute("minAmount", redpack.getMinAmount() == null ? "" : redpack.getMinAmount() / 100);
    // model.addAttribute("maxAmount", redpack.getMaxAmount() == null ? "" : redpack.getMaxAmount() / 100);
    model.addAttribute("packType", RedpackType.values());
    model.addAttribute(redpack);
    return PREFIX + "redpack_edit.html";
}
Also used : Redpack(com.ikoori.vip.common.persistence.model.Redpack) BussinessException(com.ikoori.vip.common.exception.BussinessException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Redpack (com.ikoori.vip.common.persistence.model.Redpack)4 BussinessException (com.ikoori.vip.common.exception.BussinessException)2 BigDecimal (java.math.BigDecimal)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Permission (com.ikoori.vip.common.annotion.Permission)1 Member (com.ikoori.vip.common.persistence.model.Member)1 Merchant (com.ikoori.vip.common.persistence.model.Merchant)1 WxUser (com.ikoori.vip.common.persistence.model.WxUser)1 Transactional (org.springframework.transaction.annotation.Transactional)1