liyaozhi
2025-10-28 1320688354fd168c51cf2e05f29a2253f4ed9c00
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
<?php
 
namespace app\common\model\settings;
 
use app\common\enum\settings\PrinterTypeEnum;
use app\common\model\BaseModel;
 
/**
 * 打印机模型
 */
class Printer extends BaseModel
{
    protected $name = 'printer';
    protected $pk = 'printer_id';
    /**
     * 获取打印机类型列表
     */
    public static function getPrinterTypeList()
    {
        static $printerTypeEnum = [];
        if (empty($printerTypeEnum)) {
            $printerTypeEnum = PrinterTypeEnum::getTypeName();
        }
        return $printerTypeEnum;
    }
 
    /**
     * 打印机类型名称
     */
    public function getPrinterTypeAttr($value)
    {
        $printerType = self::getPrinterTypeList();
        return ['value' => $value, 'text' => $printerType[$value]];
    }
 
    /**
     * 自动转换printer_config为array格式
     */
    public function getPrinterConfigAttr($value)
    {
        return json_decode($value, true);
    }
 
    /**
     * 自动转换printer_config为json格式
     */
    public function setPrinterConfigAttr($value)
    {
        return json_encode($value);
    }
 
    /**
     * 获取全部
     */
    public static function getAll($shop_supplier_id=0, $type = false)
    {   
        $where = [];
        if($shop_supplier_id){
            $where['shop_supplier_id'] = $shop_supplier_id;
        }
        // 判断打印机类型 by lyzflash
        if ($type) {
            $where['type'] = $type;
        }
        return (new static)->where('is_delete', '=', 0)
            ->where($where)
            ->order(['sort' => 'asc'])->select();
    }
 
    /**
     * 获取列表
     */
    public function getList($limit = 10,$shop_supplier_id=0)
    {   
        $where = [];
        if($shop_supplier_id){
            $where['shop_supplier_id'] = $shop_supplier_id;
        }
        if (!empty($limit['type'])){
            $where['type'] = $limit['type'];
        }
        return $this->where('is_delete', '=', 0)
            ->where($where)
            ->order(['sort' => 'asc'])
            ->paginate($limit);
    }
 
    /**
     * 物流公司详情
     */
    public static function detail($printer_id)
    {
        return (new static())->find($printer_id);
    }
 
}