quanwei
2025-12-25 a47b138c7455dee981af9b4fac431a16c0eee675
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
 
namespace app\supplier\model\supplier;
 
use app\common\model\supplier\Cash as SupplierCashModel;
use app\supplier\model\supplier\Supplier as SupplierModel;
use app\common\model\supplier\Account as SupplierAccountModel;
use app\common\exception\BaseException;
use app\supplier\model\user\UserAuth;
use app\supplier\model\supplier\Capital as SupplierCapitalModel;
 
/**
 * 供应商提现账号模型
 */
class Cash extends SupplierCashModel
{
    public function getList($shop_supplier_id, $data){
        // 获取数据列表
        return $this->where('shop_supplier_id', '=', $shop_supplier_id)
            ->order(['create_time' => 'desc'])
            ->paginate($data);
    }
 
    /**
     * 提交申请
     */
    public function submit($shop_supplier_id, $data)
    {
        $supplier = SupplierModel::detail($shop_supplier_id);
        $account = SupplierAccountModel::detail($shop_supplier_id);
        if(!$account){
            throw new BaseException(['msg' => '请填写提现账户信息']);
        }
        // 数据验证
        $this->validation($supplier, $data, $account);
        if(!empty($data["start_day"])){
            $data["start_day"] = strtotime($data["start_day"]);
        }
        if(!empty($data["end_day"])){
            $data["end_day"] = strtotime($data["end_day"]);
        }
        // 新增申请记录
        $this->save(array_merge($data, [
            'shop_supplier_id' => $shop_supplier_id,
            'apply_status' => 10,
            'app_id' => self::$app_id,
        ]));
        // 冻结用户资金
        $supplier->freezeMoney($data['money']);
        //修改提现状态
        if(!empty($data["start_day"]) && !empty($data["end_day"])){
            SupplierCapitalModel::editStatus($shop_supplier_id,$data["start_day"],$data["end_day"]);
 
        }
        return true;
    }
 
    /**
     * 数据验证
     */
    private function validation($supplier, $data, $account)
    {
        // 最低提现佣金
        if ($data['money'] <= 0) {
            throw new BaseException(['msg' => '提现金额不正确']);
        }
        if ($supplier['money'] <= 0) {
            throw new BaseException(['msg' => '没有可提现金额']);
        }
        if ($data['money'] > $supplier['money']) {
            throw new BaseException(['msg' => '提现金额不能大于可提现金额']);
        }
        if ($data['pay_type'] == '10') {
            if (empty($account['alipay_name']) || empty($account['alipay_account'])) {
                //throw new BaseException(['msg' => '请补全提现信息']);
            }
        } elseif ($data['pay_type'] == '20') {
            if (empty($account['bank_name']) || $account['bank_account'] || $account['bank_card']) {
                //throw new BaseException(['msg' => '请补全提现信息']);
            }
        }elseif ($data['pay_type'] == '30') {
            //微信支付需要实名认证
            $auth = UserAuth::detail($supplier['user_id']);
            if(empty($auth)){
                throw new BaseException(['msg' => '请先到小程序个人中心->设置->实名认证']);
            }elseif(!empty($auth) && $auth["auth_status"] != 1){
                throw new BaseException(['msg' => '您的实名认证还未审核通过']);
            }
        } else{
            throw new BaseException(['msg' => '提现方式不正确']);
        }
    }
}