Search in sources :

Example 1 with YxUserBill

use of co.yixiang.modules.shop.domain.YxUserBill in project yshopmall by guchengwuyue.

the class YxUserExtractServiceImpl method doExtract.

@Override
public void doExtract(YxUserExtract resources) {
    if (resources.getStatus() == null) {
        throw new BadRequestException("请选择审核状态");
    }
    if (ShopCommonEnum.EXTRACT_0.getValue().equals(resources.getStatus())) {
        throw new BadRequestException("请选择审核状态");
    }
    if (ShopCommonEnum.EXTRACT_MINUS_1.getValue().equals(resources.getStatus())) {
        if (StrUtil.isEmpty(resources.getFailMsg())) {
            throw new BadRequestException("请填写失败原因");
        }
        String mark = "提现失败,退回佣金" + resources.getExtractPrice() + "元";
        YxUserDto userDTO = generator.convert(yxUserService.getOne(new LambdaQueryWrapper<YxUser>().eq(YxUser::getUid, resources.getUid())), YxUserDto.class);
        // 增加流水
        YxUserBill userBill = new YxUserBill();
        userBill.setTitle("提现失败");
        userBill.setUid(resources.getUid());
        userBill.setCategory("now_money");
        userBill.setType("extract");
        userBill.setNumber(resources.getExtractPrice());
        userBill.setLinkId(resources.getId().toString());
        userBill.setBalance(NumberUtil.add(userDTO.getBrokeragePrice(), resources.getExtractPrice()));
        userBill.setMark(mark);
        userBill.setStatus(1);
        userBill.setPm(1);
        billService.save(userBill);
        // 返回提现金额
        yxUserService.incBrokeragePrice(resources.getExtractPrice().doubleValue(), resources.getUid());
        resources.setFailTime(new Date());
    }
    // todo 此处为企业付款,没经过测试
    boolean isTest = true;
    if (!isTest) {
        String openid = this.getUserOpenid(resources.getUid());
        if (StrUtil.isNotBlank(openid)) {
            try {
                payService.entPay(openid, resources.getId().toString(), resources.getRealName(), resources.getExtractPrice().multiply(new BigDecimal(100)).intValue());
            } catch (WxPayException e) {
                throw new BadRequestException(e.getMessage());
            }
        } else {
            throw new BadRequestException("不是微信用户无法退款");
        }
    }
    this.saveOrUpdate(resources);
}
Also used : WxPayException(com.github.binarywang.wxpay.exception.WxPayException) YxUser(co.yixiang.modules.shop.domain.YxUser) BadRequestException(co.yixiang.exception.BadRequestException) YxUserBill(co.yixiang.modules.shop.domain.YxUserBill) Date(java.util.Date) BigDecimal(java.math.BigDecimal) YxUserDto(co.yixiang.modules.shop.service.dto.YxUserDto)

Example 2 with YxUserBill

use of co.yixiang.modules.shop.domain.YxUserBill in project yshopmall by guchengwuyue.

the class YxUserServiceImpl method updateMoney.

@Override
@Transactional(rollbackFor = Exception.class)
public void updateMoney(UserMoneyDto param) {
    YxUserDto userDTO = generator.convert(getById(param.getUid()), YxUserDto.class);
    Double newMoney = 0d;
    String mark = "";
    String type = "system_add";
    Integer pm = 1;
    String title = "系统增加余额";
    if (param.getPtype() == 1) {
        mark = "系统增加了" + param.getMoney() + "余额";
        newMoney = NumberUtil.add(userDTO.getNowMoney(), param.getMoney()).doubleValue();
    } else {
        title = "系统减少余额";
        mark = "系统扣除了" + param.getMoney() + "余额";
        type = "system_sub";
        pm = 0;
        newMoney = NumberUtil.sub(userDTO.getNowMoney(), param.getMoney()).doubleValue();
        if (newMoney < 0) {
            newMoney = 0d;
        }
    }
    YxUser user = new YxUser();
    user.setUid(userDTO.getUid());
    user.setNowMoney(BigDecimal.valueOf(newMoney));
    saveOrUpdate(user);
    YxUserBill userBill = new YxUserBill();
    userBill.setUid(userDTO.getUid());
    userBill.setLinkId("0");
    userBill.setPm(pm);
    userBill.setTitle(title);
    userBill.setCategory("now_money");
    userBill.setType(type);
    userBill.setNumber(BigDecimal.valueOf(param.getMoney()));
    userBill.setBalance(BigDecimal.valueOf(newMoney));
    userBill.setMark(mark);
    userBill.setStatus(1);
    yxUserBillService.save(userBill);
}
Also used : YxUser(co.yixiang.modules.shop.domain.YxUser) YxUserBill(co.yixiang.modules.shop.domain.YxUserBill) YxUserDto(co.yixiang.modules.shop.service.dto.YxUserDto) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

YxUser (co.yixiang.modules.shop.domain.YxUser)2 YxUserBill (co.yixiang.modules.shop.domain.YxUserBill)2 YxUserDto (co.yixiang.modules.shop.service.dto.YxUserDto)2 BadRequestException (co.yixiang.exception.BadRequestException)1 WxPayException (com.github.binarywang.wxpay.exception.WxPayException)1 BigDecimal (java.math.BigDecimal)1 Date (java.util.Date)1 Transactional (org.springframework.transaction.annotation.Transactional)1