Printer.php 2.1 KB

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