Printer.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. return (new static)->where('is_delete', '=', 0)
  60. ->order(['sort' => 'asc'])->select();
  61. }
  62. /**
  63. * 获取列表
  64. * @return \think\Paginator
  65. * @throws \think\exception\DbException
  66. */
  67. public function getList()
  68. {
  69. return $this->where('is_delete', '=', 0)
  70. ->order(['sort' => 'asc'])
  71. ->paginate(15, false, [
  72. 'query' => Request::instance()->request()
  73. ]);
  74. }
  75. /**
  76. * 物流公司详情
  77. * @param $printer_id
  78. * @return null|static
  79. * @throws \think\exception\DbException
  80. */
  81. public static function detail($printer_id)
  82. {
  83. return self::get($printer_id);
  84. }
  85. }