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
<?php
 
namespace app\operations\model\plus\operations;
 
use app\common\model\plus\operations\Order as OrderModel;
use app\common\model\plus\operations\Operations as OperationsUserModel;
use app\common\service\order\OrderService;
use app\operations\service\order\ExportService;
 
/**
 * 运营中心订单模型
 */
class Order extends OrderModel
{
    // 定义全局的查询范围
    protected $globalScope = ['status'];
    public function scopeStatus($query)
    {
        $region=OperationsUserModel::detail(session('jjjshop_operations')['user']['user_id']);
        $where=['first_user_id|second_user_id|third_user_id'=>$region['user_id']];
        $query->where($where);
    }
    /**
     * 获取运营中心订单列表
     */
    public function getList($user_id = null, $is_settled = -1, $list_rows = 15)
    {
        $model = $this;
        // 检索查询条件
        if ($user_id > 1) {
            $model = $model->where('first_user_id|second_user_id|third_user_id', '=', $user_id);
        }
        if ($is_settled > -1) {
            $model = $model->where('is_settled', '=', $is_settled);
        }
        // 获取运营中心订单列表
        $data = $model->with([
            'agent_first',
            'agent_second',
            'agent_third'
        ])
            ->order(['create_time' => 'desc'])
            ->paginate($list_rows);
        if ($data->isEmpty()) {
            return $data;
        }
        // 获取订单的主信息
        $with = ['product' => ['image', 'refund'], 'address', 'user'];
        return OrderService::getOrderList($data, 'order_master', $with);
    }
 
    /**
     * 订单导出
     */
    public function exportList($user_id = null, $is_settled = -1)
    {
        $model = $this;
        // 检索查询条件
        if ($user_id > 1) {
            $model = $model->where('first_user_id|second_user_id|third_user_id', '=', $user_id);
        }
        if ($is_settled > -1) {
            $model = $model->where('is_settled', '=', $is_settled);
        }
        // 获取运营中心订单列表
        $data = $model->with([
            'agent_first',
            'agent_second',
            'agent_third'
        ])
            ->order(['create_time' => 'desc'])
            ->select();
        if ($data->isEmpty()) {
            return $data;
        }
        // 获取订单的主信息
        $with = ['product' => ['image', 'refund'], 'address', 'user'];
        $list = OrderService::getOrderList($data, 'order_master', $with);
        // 导出excel文件
        (new Exportservice)->operationsOrderList($list);
    }
}