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
<?php
 
namespace app\operations\model\branch;
 
use app\common\model\branch\Capital as BranchCapitalModel;
use app\common\model\branch\Branch as BranchModel;
use app\operations\service\order\ExportService;
 
/**
 * 供应商资金明细模型
 */
class Capital extends BranchCapitalModel
{
    /**
     * 获取列表数据
     */
    public function getList($params,$page = true)
    {
        $model = $this;
        if(isset($params['flow_type']) && $params['flow_type'] != 0){
            $model = $model->where('flow_type', '=', $params['flow_type']);
        }
        if(isset($params['start_day']) && !empty($params['start_day'])){
            $model = $model->where('create_time', '>=', strtotime($params['start_day']));
        }
        if(isset($params['end_day']) && !empty($params['end_day'])){
            $end_day =  strtotime($params['end_day']) + 86400;
            $model = $model->where('create_time', '<', $end_day);
        }
        if(!empty($params['search'])){
            //获取商户id
            $branch_id = BranchModel::getBranchIdByName($params['search']);
            $model = $model->where('branch_id', '=', $branch_id);
        }
        if(!empty($params['branch_name'])){
            //获取商户id
            $branch_id = BranchModel::getBranchIdByName($params['branch_name']);
            $model = $model->where('branch_id', '=', $branch_id);
        }
        if(isset($params['is_settled']) && $params['is_settled'] >= 0){
            //提现状态
            $model = $model->where('is_settled', '=', $params['is_settled']);
        }
        // 查询列表数据
        if($page){
            $data["list"] = $model->with(["branch"])->order(['create_time' => 'desc'])->paginate($params);
        }else{
            $data["list"] = $model->with(["branch"])->order(['create_time' => 'desc'])->select();
        }
 
        $data["total_money"] = $model->sum("money");
        return $data;
    }
 
    /**
     * 修改状态
     */
    public static function editStatus($branch_id, $start_day,$end_day,$is_settled=1)
    {
        $model = new static();
        $end_day = $end_day + 86400;
        // 查询列表数据
        return $model->where('branch_id', '=', $branch_id)
            ->where('create_time', '>=', $start_day)
            ->where('create_time', '<', $end_day)
            ->where('flow_type', '=', 10)
            ->where('is_settled', '=', 1)
            ->update(["is_settled"=>$is_settled]);
    }
 
    /**
     * 订单导出
     */
    public function exportList($query)
    {
        // 获取订单列表
        $list = $this->getList($query,false);
        // 导出excel文件
        return (new Exportservice)->branchCapitalList($list);
    }
 
    /**
     * 订单导出
     */
    public function exportCashList($query)
    {
        // 获取订单列表
        $query["flow_type"] = 10;//收入
        $list = $this->getList($query,false);
        // 导出excel文件
        return (new Exportservice)->branchCashList($list);
    }
    
}