quanwei
2025-11-01 121b714d710cf3c865f4a1b5efe81abec11056d1
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
96
97
98
99
100
101
102
103
104
<?php
 
namespace app\branch\model\order;
 
use app\common\model\order\OrderRefund as OrderRefundModel;
 
/**
 * 售后管理模型
 */
class OrderRefund extends OrderRefundModel
{
    /**
     * 获取售后单列表
     */
    public function getList($query = [],$branch_id=0)
    {
 
        $model = $this;
        // 查询条件:订单号
        if (isset($query['order_no']) && !empty($query['order_no'])) {
            $model = $model->where('order.order_no', 'like', "%{$query['order_no']}%");
        }
        // 查询条件:起始日期
        if (isset($query['create_time']) && !empty($query['create_time'])) {
            $sta_time = array_shift($query['create_time']);
            $end_time = array_pop($query['create_time']);
            $model = $model->whereBetweenTime('m.create_time', $sta_time, date('Y-m-d 23:59:59', strtotime($end_time)));
        }
        // 售后类型
        if (isset($query['type']) && $query['type'] > 0) {
            $model = $model->where('m.type', '=', $query['type']);
        }
 
        // 售后单状态(选项卡)
        if (isset($query['status']) && $query['status'] >= 0) {
            $model = $model->where('m.status', '=', $query['status']);
        }
        if ($branch_id) {
            $model = $model->where('m.branch_id', '=', $branch_id);
        }
 
        // 获取列表数据
        $list = $model->alias('m')
            ->field('m.*, order.order_no')
            ->with(['orderproduct.image', 'orderMaster.advance', 'user'])
            ->join('order', 'order.order_id = m.order_id')
            ->order(['m.create_time' => 'desc'])
            ->paginate($query);
        foreach ($list as &$item) {
            if ($item['orderMaster']['order_source'] == 70) {
                $item['orderproduct']['total_pay_price'] = round($item['orderproduct']['total_pay_price'] + $item['orderMaster']['advance']['pay_price'], 2);
            }
        }
        return $list;
    }
 
    public function groupCount($query, $branch_id = 0)
    {
        $model = $this;
        // 查询条件:订单号
        if (isset($query['order_no']) && !empty($query['order_no'])) {
            $model = $model->where('order.order_no', 'like', "%{$query['order_no']}%");
        }
        // 查询条件:起始日期
        if (isset($query['create_time']) && !empty($query['create_time'])) {
            $sta_time = array_shift($query['create_time']);
            $end_time = array_pop($query['create_time']);
            $model = $model->whereBetweenTime('m.create_time', $sta_time, $end_time);
        }
        // 售后类型
        if (isset($query['type']) && $query['type'] > 0) {
            $model = $model->where('m.type', '=', $query['type']);
        }
        if ($branch_id) {
            $model = $model->where('m.branch_id', '=', $branch_id);
        }
        // 获取列表数据
        return $model->alias('m')
            ->field('m.status,COUNT(*) as total')
            ->join('order', 'order.order_id = m.order_id')
            ->group('m.status')->select()->toArray();
    }
 
    /**
     * 统计售后订单
     */
    public function getRefundOrderTotal($branch_id)
    {
        $filter['is_agree'] = 0;
        $filter['branch_id'] = $branch_id;
        return $this->where($filter)->count();
    }
 
    /**
     * 已同意的退款
     */
    public function getRefundMoney($branch_id)
    {
        // 退款金额
        return $this->where('is_agree', '=', 10)
            ->where('branch_id', '=', $branch_id)
            ->sum('refund_money');
    }
}