<?php
|
|
namespace app\api\logic;
|
|
use think\Db;
|
use app\common\logic\Basic as BasicLogic;
|
use app\common\model\user\Withdrawal as ModelUserWithdrawal;
|
use app\common\model\User as ModelUser;
|
|
|
class UserWithdrawal extends BasicLogic
|
{
|
|
protected $model;
|
|
protected function initialize()
|
{
|
$this->model = new ModelUserWithdrawal();
|
}
|
|
/**
|
* 提现操作
|
*
|
* @param [type] $user_id 用户ID
|
* @param [type] $amount 提现金额
|
* @param [type] $true_name 真实姓名
|
* @param [type] $zfb_account 支付宝账号
|
* @return void
|
*/
|
public function doWithdrawal($user_id,$amount,$true_name,$zfb_account)
|
{
|
Db::startTrans();
|
$save_data = [
|
'user_id' => $user_id,
|
'change_money' => $amount,
|
'status' => 0,
|
'service_charge' => config('site.service_charge'),
|
'actual_amount' => $amount - config('site.service_charge'),
|
'truename' => $true_name,
|
'zfb_account' => $zfb_account,
|
'create_time' => time()
|
];
|
$res_1 = $this->model->insert($save_data);
|
if(!$res_1){
|
Db::rollback();
|
fault('提现申请失败,请重试(-1)');
|
}
|
$ModelUser = new ModelUser();
|
ModelUser::money('dec',$amount,$user_id,'提现');
|
Db::commit();
|
return true;
|
}
|
|
|
/**
|
* 获取提现记录
|
*
|
* @return void
|
*/
|
public function getList($user_id,$page,$pageSize)
|
{
|
$list = $this->model->field('id,title,change_money,actual_amount,status,create_time')->where(['user_id'=>$user_id])->page($page,$pageSize)->order('id desc')->select();
|
return empty($list) ? [] : $list;
|
}
|
|
|
|
|
|
|
}
|