Search in sources :

Example 1 with AlipayFundTransUniTransferRequest

use of com.alipay.api.request.AlipayFundTransUniTransferRequest in project Ant-Live by PinTeh.

the class AlipayServiceImpl method trans.

@Override
public void trans(String outTradeNo, Integer virtualAmount, String uid, String identity, String identityName) throws AlipayApiException {
    /* 开心果 与 金豆 转换率 10:1  提现比例 2 : 1 */
    int realTransAmount = Math.abs(virtualAmount / 10 / 2);
    AlipayFundTransUniTransferRequest request = new AlipayFundTransUniTransferRequest();
    request.setBizContent("{" + "\"out_biz_no\":\"" + outTradeNo + "\"," + "\"trans_amount\":" + realTransAmount + "," + "\"product_code\":\"TRANS_ACCOUNT_NO_PWD\"," + "\"biz_scene\":\"DIRECT_TRANSFER\"," + "\"order_title\":\"Live直播开心果提现\"," + "\"payee_info\":{" + "\"identity\":\"" + identity + "\"," + "\"identity_type\":\"ALIPAY_LOGON_ID\"," + "\"name\":\"" + identityName + "\"," + "    }," + "\"remark\":\"Live直播提现备注\"," + "\"business_params\":\"{\\\"payer_show_name\\\":\\\"PinTeh Live\\\"}\"," + "  }");
    AlipayFundTransUniTransferResponse response = client.certificateExecute(request);
    if (response.isSuccess()) {
        // Bill (insert record)
        Bill last = billMapper.selectOne(new QueryWrapper<Bill>().eq("user_id", uid).orderByDesc("id").last("limit 0,1"));
        BigDecimal virtualBigDecimal = new BigDecimal(virtualAmount);
        BigDecimal ret = last.getBalance().subtract(virtualBigDecimal);
        if (ret.compareTo(BigDecimal.ZERO) < 0) {
            // Balance not enough
            return;
        }
        Bill bill = new Bill();
        bill.setBillChange(virtualBigDecimal.negate());
        bill.setType(1);
        bill.setUserId(Integer.valueOf(uid));
        bill.setBalance(ret);
        bill.setMark("提现");
        bill.setOrderNo(outTradeNo);
        billMapper.insert(bill);
        log.info("[billMapper] insert success");
        // Settle account info (insert)
        Withdrawal withdrawal = new Withdrawal();
        withdrawal.setIdentity(identity);
        withdrawal.setIdentityName(identityName);
        withdrawal.setMark("提现");
        withdrawal.setStatus(1);
        withdrawal.setType(Constants.PayPlatform.ALIPAY.getDesc());
        withdrawal.setVirtualAmount(virtualBigDecimal);
        withdrawal.setRealAmount(new BigDecimal(realTransAmount));
        withdrawal.setUserId(Integer.valueOf(uid));
        withdrawalMapper.insert(withdrawal);
        log.info("[withdrawalMapper] insert success");
        log.info("[alipay] call success");
    } else {
        log.info("[alipay] call fail");
    }
}
Also used : AlipayFundTransUniTransferResponse(com.alipay.api.response.AlipayFundTransUniTransferResponse) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) Withdrawal(cn.imhtb.antlive.entity.database.Withdrawal) AlipayFundTransUniTransferRequest(com.alipay.api.request.AlipayFundTransUniTransferRequest) Bill(cn.imhtb.antlive.entity.Bill) BigDecimal(java.math.BigDecimal)

Aggregations

Bill (cn.imhtb.antlive.entity.Bill)1 Withdrawal (cn.imhtb.antlive.entity.database.Withdrawal)1 AlipayFundTransUniTransferRequest (com.alipay.api.request.AlipayFundTransUniTransferRequest)1 AlipayFundTransUniTransferResponse (com.alipay.api.response.AlipayFundTransUniTransferResponse)1 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)1 BigDecimal (java.math.BigDecimal)1