quanwei
3 days ago 73b874c72ad55eb9eef21c36160ac0de58f0189e
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
<?php
 
namespace app\common\model\settings;
 
use think\facade\Request;
use app\common\enum\settings\StallTypeEnum;
use app\common\model\BaseModel;
 
/**
 * 档口模型 by lyzflash
 */
class Stall extends BaseModel
{
    protected $name = 'stall';
    protected $pk = 'stall_id';
 
    /**
     * 关联打印机表
     */
    public function printer()
    {
        return $this->hasOne('app\\common\\model\\settings\\Printer', 'printer_id', 'printer_id');
    }
 
 
    /**
     * 获取档口类型列表
     */
    public static function getStallTypeList()
    {
        static $stallTypeEnum = [];
        if (empty($stallTypeEnum)) {
            $stallTypeEnum = StallTypeEnum::data();
        }
        return $stallTypeEnum;
    }
 
    /**
     * 获取全部
     * $is_printer 是否必须配置了打印机
     */
    public static function getAll($shop_supplier_id = 0, $is_printer = false, $stallTypeArr = [])
    {   
        $model = new static();
        if ($shop_supplier_id) {
            $model = $model->where('shop_supplier_id', '=', $shop_supplier_id);
        }
        if ($is_printer) {
            $model = $model->where('printer_id', '>', 0)->where('status', '=', 1);
        }
        if ($stallTypeArr) {
            $model = $model->where('stall_type', 'in', $stallTypeArr);
        }
        return $model->where('is_delete', '=', 0)
            ->order(['sort' => 'asc'])->select();
    }
 
    /**
     * 获取列表
     */
    public function getList($params, $shop_supplier_id = 0)
    {   
        $where = [];
        if ($shop_supplier_id){
            $where['shop_supplier_id'] = $shop_supplier_id;
        }
        if (isset($params['stall_type'])) {
            $where['stall_type'] = $params['stall_type'];
        }
        return $this->with(['printer'])
            ->where('is_delete', '=', 0)
            ->where($where)
            ->order(['sort' => 'asc'])
            ->paginate($params);
    }
 
    /**
     * 物流公司详情
     */
    public static function detail($stall_id)
    {
        return self::find($stall_id);
    }
 
}