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
<?php
 
namespace app\operations\model\plus\team;
 
use app\common\model\plus\team\Order as OrderModel;
use app\common\service\order\OrderService;
/**
 * 队长订单模型
 */
class Order extends OrderModel
{
    /**
     * 获取队长订单列表
     */
    public function getList($user_id = null, $is_settled = -1)
    {
        $model = $this;
        // 检索查询条件
        if ($user_id > 1) {
            $model = $model->where('heads_id', '=', $user_id);
        }
        if ($is_settled > -1) {
            $model = $model->where('is_settled', '=', $is_settled);
        }
        // 获取队长订单列表
        $data = $model->with([
            'team_heads'
        ])
            ->order(['create_time' => 'desc'])
            ->paginate(15);
        if ($data->isEmpty()) {
            return $data;
        }
        // 获取订单的主信息
        $with = ['product' => ['image', 'refund'], 'address', 'user'];
        return OrderService::getOrderList($data, 'order_master', $with);
    }
 
    /**
     * 获取队长订单列表
     */
    public function getOrderData($user_id, $startDate, $endDate, $type = 'order_total_price')
    {
        $model = $this;
        !is_null($user_id) && $model = $model->where('heads_id', '=', $user_id);
        !is_null($startDate) && $model = $model->where('create_time', '>=', strtotime($startDate));
        if (is_null($endDate)) {
            !is_null($startDate) && $model = $model->where('create_time', '<', strtotime($startDate) + 86400);
        } else {
            $model = $model->where('create_time', '<', strtotime($endDate) + 86400);
        }
        $model = $model->where('is_invalid', '=', 0)
            ->where('bonus_type', '=', 10);
 
        if ($type == 'order_total') {
            // 订单数量
            return $model->count();
        } else if ($type == 'order_total_price') {
            // 订单总金额
            return $model->sum('order_price');
        } else if ($type == 'order_user_total') {
            // 支付用户数
            return count($model->distinct(true)->column('user_id'));
        }
        return 0;
    }
 
}