zhaojs
2023-07-18 4fa2a021dcc80ae0ec294e183a90c30e77bd565c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?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;
    }
 
 
 
 
   
 
}