Printer.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace app\common\model\settings;
  3. use app\common\enum\settings\PrinterTypeEnum;
  4. use app\common\model\BaseModel;
  5. /**
  6. * 打印机模型
  7. */
  8. class Printer extends BaseModel
  9. {
  10. protected $name = 'printer';
  11. protected $pk = 'printer_id';
  12. /**
  13. * 获取打印机类型列表
  14. */
  15. public static function getPrinterTypeList()
  16. {
  17. static $printerTypeEnum = [];
  18. if (empty($printerTypeEnum)) {
  19. $printerTypeEnum = PrinterTypeEnum::getTypeName();
  20. }
  21. return $printerTypeEnum;
  22. }
  23. /**
  24. * 打印机类型名称
  25. */
  26. public function getPrinterTypeAttr($value)
  27. {
  28. $printerType = self::getPrinterTypeList();
  29. return ['value' => $value, 'text' => $printerType[$value]];
  30. }
  31. /**
  32. * 自动转换printer_config为array格式
  33. */
  34. public function getPrinterConfigAttr($value)
  35. {
  36. return json_decode($value, true);
  37. }
  38. /**
  39. * 自动转换printer_config为json格式
  40. */
  41. public function setPrinterConfigAttr($value)
  42. {
  43. return json_encode($value);
  44. }
  45. /**
  46. * 获取全部
  47. */
  48. public static function getAll($shop_supplier_id=0)
  49. {
  50. $where = [];
  51. if($shop_supplier_id){
  52. $where['shop_supplier_id'] = $shop_supplier_id;
  53. }
  54. return (new static)->where('is_delete', '=', 0)
  55. ->where($where)
  56. ->order(['sort' => 'asc'])->select();
  57. }
  58. /**
  59. * 获取列表
  60. */
  61. public function getList($limit = 10,$shop_supplier_id=0)
  62. {
  63. $where = [];
  64. if($shop_supplier_id){
  65. $where['shop_supplier_id'] = $shop_supplier_id;
  66. }
  67. return $this->where('is_delete', '=', 0)
  68. ->where($where)
  69. ->order(['sort' => 'asc'])
  70. ->paginate($limit);
  71. }
  72. /**
  73. * 物流公司详情
  74. */
  75. public static function detail($printer_id)
  76. {
  77. return (new static())->find($printer_id);
  78. }
  79. }