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
105
106
107
108
109
110
111
112
113
114
115
116
<?php
 
 
namespace app\common\model\store;
 
use app\common\model\BaseModel;
 
use app\common\enum\order\OrderTypeEnum;
use app\common\service\order\OrderService;
/**
 * 商家门店核销订单记录模型
 */
class Order extends BaseModel
{
    protected $pk = 'id';
    protected $name = 'store_order';
    protected $updateTime = false;
 
    /**
     * 关联门店表
     */
    public function store()
    {
        return $this->BelongsTo("app\\common\\model\\store\\Store", 'store_id', 'store_id');
    }
 
    /**
     * 关联店员表
     */
    public function clerk()
    {
        return $this->BelongsTo("app\\common\\model\\store\\Clerk", 'clerk_id', 'clerk_id');
    }
 
    /**
     * 关联订单表
     */
    public function order()
    {
        return $this->BelongsTo("app\\common\\model\\order\\Order", 'order_id', 'order_id');
    }
 
    /**
     * 关联供应商表
     */
    public function supplier()
    {
        return $this->belongsTo('app\\common\\model\\supplier\\Supplier', 'shop_supplier_id', 'shop_supplier_id')->field(['shop_supplier_id', 'name','supplier_type','gift_type']);
    }
 
    /**
     * 订单类型
     * @param $value
     * @return array
     */
    public function getOrderTypeAttr($value)
    {
        $types = OrderTypeEnum::getTypeName();
        return ['text' => $types[$value], 'value' => $value];
    }
 
    /**
     * 新增核销记录
     */
    public static function add(
        $order_id,
        $store_id,
        $clerk_id,
        $shop_supplier_id,
        $order_type = OrderTypeEnum::MASTER,
        $commission,
        $delivery_fee
    )
    {
        return (new static)->save([
            'order_id' => $order_id,
            'order_type' => $order_type,
            'store_id' => $store_id,
            'clerk_id' => $clerk_id,
            'shop_supplier_id' => $shop_supplier_id,
            'commission'=>$commission,
            'delivery_fee'=>$delivery_fee,
            'app_id' => self::$app_id
        ]);
    }
    /**
     * 核销订单详情
     */
    public static function detail($where)
    {
        $filter = is_array($where) ? $where : ['order_id' => $where];
        return (new static())->where($filter)->find();
    }
    
    /**
     * 获取队长订单列表
     */
    public function getSettled($store_id, $clerk_id = -1)
    {
        $model = $this;
        if($clerk_id>0){
            //只查门店配送的订单
            $model=$model->where('clerk_id', '=', $clerk_id)->where('delivery_fee','>=','0.01');
        }
        $data = $model->with(['store'])
            ->where('store_id', '=', $store_id)
            ->order(['create_time' => 'desc'])
            ->paginate(15);
        if ($data->isEmpty()) {
            return $data;
        }
        // 整理订单信息
        $with = ['product' => ['image', 'refund'], 'address', 'user'];
        return OrderService::getOrderList($data, 'order_master', $with);
    }
}