quanwei
18 hours ago c441dea81bd86bdfb12dff35821fed51f4cc91c2
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
94
95
<?php
 
namespace app\operations\model\branch;
 
use app\common\model\branch\DepositRefund as DepositRefundModel;
use app\branch\model\branch\Branch as BranchModel;
use app\operations\model\branch\Capital as CapitalModel;
 
/**
 * 退押金申请模型类
 */
class DepositRefund extends DepositRefundModel
{
    /**
     * 获取列表数据
     */
    public function getList($params)
    {
        $model = $this;
        if ($params['status'] != '') {
            $model = $model->where('status', '=', $params['status']);
        }
        // 查询列表数据
        return $model->with(['branch'])
            ->order(['create_time' => 'desc'])
            ->paginate($params);
    }
 
    /**
     * 退押金审核
     */
    public function submit($param)
    {
        $this->startTrans();
        try {
            $data = ['status' => $param['state']];
           $data['audit_time'] = time();
            // 更新申请记录
            $this->save($data);
            $branch = BranchModel::detail($this['branch_id']);
 
            if ($param['state'] == 2) {//拒绝退押金
                (new BranchModel())->where(['branch_id' => $this['branch_id']])->update(['status' => 0]);
            } else if ($param['state'] == 1) {//同意退押金
                (new BranchModel())->where(['branch_id' => $this['branch_id']])->update(['status' => 20, 'deposit_money' => 0, 'money' => $branch['money'] + $this['deposit_money'], 'total_money' => $branch['total_money'] + $this['deposit_money']]);
                $add = [
                    'branch_id' => $this['branch_id'],
                    'flow_type' => 10,
                    'money' => $this['deposit_money'],
                    'describe' => '退押金收入',
                ];
                //添加资金明细        
                CapitalModel::add($add);
            }
            $this->commit();
            return true;
        } catch (\Exception $e) {
            $this->error = $e->getMessage();
            $this->rollback();
            return false;
        }
    }
 
    /**
     * 获取退款数
     */
    public static function getRefundCount(){
        return (new static())->where('status', '=', 0)->count();
    }
 
    /**
     * 获取供应商申请统计数量
     */
    public function getRefundData($startDate = null, $endDate = null, $type)
    {
        $model = $this;
        $field = '';
        if($type == 'branch_refund'){
            $field = 'audit_time';
            $model = $model->where('status', '=', 1);
        } else if($type == 'branch_refund_apply'){
            $field = 'create_time';
        }
        if(!is_null($startDate)){
            $model = $model->where($field, '>=', strtotime($startDate));
        }
        if(is_null($endDate)){
            $model = $model->where($field, '<', strtotime($startDate) + 86400);
        }else{
            $model = $model->where($field, '<', strtotime($endDate) + 86400);
        }
 
        return $model->count();
    }
}