Printer.php 2.1 KB

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