PrinterValidate.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\adminapi\validate\printer;
  20. use app\common\model\Printer;
  21. use app\common\model\PrinterTemplate;
  22. use app\common\validate\BaseValidate;
  23. class PrinterValidate extends BaseValidate
  24. {
  25. protected $rule = [
  26. 'name' => 'require|max:30|checkName',
  27. 'type' => 'require|in:1',
  28. 'machine_code' => 'require|max:120',
  29. 'private_key' => 'require|max:120',
  30. 'client_id' => 'require|max:120',
  31. 'client_secret' => 'require|max:120',
  32. 'template_id' => 'require|checkTemplate',
  33. 'print_number' => 'require|in:1,2,3,4',
  34. 'auto_print' => 'require|in:0,1',
  35. 'status' => 'require|in:0,1',
  36. 'id' => 'require|checkId',
  37. ];
  38. protected $message = [
  39. 'name.require' => '请输入打印机名称',
  40. 'name.max' => '打印机名称不能超过30个字符',
  41. 'type.require' => '请选择设备类型',
  42. 'type.in' => '设备类型值错误',
  43. 'machine_code.require' => '请输入终端号',
  44. 'machine_code.max' => '终端号不能超过120个字符',
  45. 'private_key.require' => '请输入打印机密钥',
  46. 'private_key.max' => '打印机秘钥不能超过120个字符',
  47. 'client_id.require' => '请输入应用ID',
  48. 'client_id.max' => '应用ID不能超过120个字符',
  49. 'client_secret.require' => '请输入应用秘钥',
  50. 'client_secret.max' => '应用秘钥不能超过120个字符',
  51. 'template_id.require' => '请选择模板ID',
  52. 'print_number.require' => '请选择打印联数',
  53. 'print_number.in' => '联数值错误',
  54. 'auto_print.require' => '请选择自动打印状态',
  55. 'auto_print.in' => '自动打印状态值错误',
  56. 'status.require' => '请选择启动状态',
  57. 'status.in' => '启动状态值错误',
  58. 'id.require' => '参数缺失',
  59. ];
  60. public function sceneAddPrinter()
  61. {
  62. return $this->only(['name', 'type', 'machine_code', 'private_key', 'client_id', 'client_secret', 'template_id', 'print_number', 'auto_print', 'status']);
  63. }
  64. public function sceneEditPrinter()
  65. {
  66. return $this->only(['name', 'type', 'machine_code', 'private_key', 'client_id', 'client_secret', 'template_id', 'print_number', 'auto_print', 'status', 'id']);
  67. }
  68. public function sceneDeletePrinter()
  69. {
  70. return $this->only(['id']);
  71. }
  72. public function scenePrinterDetail()
  73. {
  74. return $this->only(['id']);
  75. }
  76. public function sceneTestPrinter()
  77. {
  78. return $this->only(['id']);
  79. }
  80. public function sceneAutoPrint()
  81. {
  82. return $this->only(['id']);
  83. }
  84. /**
  85. * @notes 校验模板ID
  86. * @param $templateId
  87. * @return bool|string
  88. * @author Tab
  89. * @date 2021/11/15 17:01
  90. */
  91. public function checkTemplate($templateId)
  92. {
  93. $template = PrinterTemplate::findOrEmpty($templateId);
  94. if ($template->isEmpty()) {
  95. return '模板不存在';
  96. }
  97. return true;
  98. }
  99. /**
  100. * @notes 校验打印机ID
  101. * @param $id
  102. * @return bool|string
  103. * @author Tab
  104. * @date 2021/11/15 17:30
  105. */
  106. public function checkId($id)
  107. {
  108. $printer = Printer::findOrEmpty($id);
  109. if ($printer->isEmpty()) {
  110. return '打印机不存在';
  111. }
  112. return true;
  113. }
  114. /**
  115. * @notes 校验打印机名称
  116. * @param $name
  117. * @param $rule
  118. * @param $data
  119. * @return bool|string
  120. * @author Tab
  121. * @date 2021/11/15 17:54
  122. */
  123. public function checkName($name, $rule, $data)
  124. {
  125. $where = [
  126. ['name', '=', $name]
  127. ];
  128. if (isset($data['id'])) {
  129. // 编辑
  130. $where[] = ['id', '<>', $data['id']];
  131. }
  132. $printer = Printer::where($where)->findOrEmpty();
  133. if (!$printer->isEmpty()) {
  134. return '该名称已被使用,请重新输入';
  135. }
  136. return true;
  137. }
  138. }