PrinterTemplateValidate.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 PrinterTemplateValidate extends BaseValidate
  24. {
  25. protected $rule = [
  26. 'template_name' => 'require|max:30|checkTempateName',
  27. 'ticket_name' => 'require|max:30',
  28. 'show_shop_name' => 'require|in:0,1',
  29. 'type' => [ 'require', 'in' => [ 0, 1 ] ],
  30. 'consignee_info' => 'require|checkConsigneeInfo',
  31. 'selffetch_shop' => 'require|checkSelffetchShop',
  32. 'verification_info' => 'require|checkVerificationInfo',
  33. 'show_buyer_message' => 'require|in:0,1',
  34. 'show_qrcode' => 'require|in:0,1',
  35. 'bottom' => 'require|max:120',
  36. 'id' => 'require|checkId',
  37. ];
  38. protected $message = [
  39. 'template_name.require' => '请输入模板名称',
  40. 'template_name.max' => '模板名称不能超过30个字符',
  41. 'ticket_name.require' => '请输入小票名称',
  42. 'ticket_name.max' => '小票名称不能超过30个字符',
  43. 'show_shop_name.require' => '请选择是否显示商城名称',
  44. 'type.require' => '请选择配送方式',
  45. 'type.in' => '配送方式错误',
  46. 'selffetch_shop.require' => '请选择门店信息',
  47. 'show_shop_name.in' => 'show_shop_name状态值错误',
  48. 'show_buyer_message.require' => '请选择是否显示买家留言',
  49. 'show_buyer_message.in' => 'show_buyer_message状态值错误',
  50. 'consignee_info.require' => '请选择收货信息',
  51. 'verification_info.require' => '请选择提货信息',
  52. 'show_qrcode.require' => '请选择是否显示二维码',
  53. 'show_qrcode.in' => 'show_qrcode状态值错误',
  54. 'bottom.require' => '请输入底部信息',
  55. 'bottom.max' => '底部信息不能超过120个字符',
  56. 'id.require' => '参数缺失',
  57. ];
  58. public function sceneAddTemplate()
  59. {
  60. return $this->only(['template_name', 'ticket_name', 'show_shop_name', 'type', 'selffetch_shop', 'show_buyer_message', 'consignee_info', 'show_qrcode', 'bottom','verification_info']);
  61. }
  62. public function sceneEditTemplate()
  63. {
  64. return $this->only(['template_name', 'ticket_name', 'show_shop_name', 'type', 'selffetch_shop', 'show_buyer_message', 'consignee_info', 'show_qrcode', 'bottom', 'id','verification_info']);
  65. }
  66. public function sceneDeleteTemplate()
  67. {
  68. return $this->only(['id'])
  69. ->append('id', "checkTempateUsed");
  70. }
  71. public function sceneTemplateDetail()
  72. {
  73. return $this->only(['id']);
  74. }
  75. /**
  76. * @notes 校验模板ID
  77. * @param $id
  78. * @return bool|string
  79. * @author Tab
  80. * @date 2021/11/15 17:30
  81. */
  82. public function checkId($id)
  83. {
  84. $template = PrinterTemplate::findOrEmpty($id);
  85. if ($template->isEmpty()) {
  86. return '模板不存在';
  87. }
  88. return true;
  89. }
  90. /**
  91. * @notes 校验模板名称
  92. * @param $name
  93. * @param $rule
  94. * @param $data
  95. * @return bool|string
  96. * @author Tab
  97. * @date 2021/11/15 17:54
  98. */
  99. public function checkTempateName($templateName, $rule, $data)
  100. {
  101. $where = [
  102. ['template_name', '=', $templateName]
  103. ];
  104. if (isset($data['id'])) {
  105. // 编辑
  106. $where[] = ['id', '<>', $data['id']];
  107. }
  108. $template = PrinterTemplate::where($where)->findOrEmpty();
  109. if (!$template->isEmpty()) {
  110. return '该模板名称已被使用,请重新输入';
  111. }
  112. return true;
  113. }
  114. /**
  115. * @notes 校验门店信息参数
  116. * @param $value
  117. * @return string|void
  118. * @author Tab
  119. * @date 2021/11/15 18:14
  120. */
  121. public function checkSelffetchShop($value)
  122. {
  123. if (!is_array($value)) {
  124. return '门店信息须为数组格式';
  125. }
  126. if (!isset($value['shop_name']) || !isset($value['contacts']) || !isset($value['shop_address'])) {
  127. return '门店信息参数不完整';
  128. }
  129. return true;
  130. }
  131. /**
  132. * @notes 校验收货信息参数
  133. * @param $value
  134. * @return string|void
  135. * @author Tab
  136. * @date 2021/11/15 18:14
  137. */
  138. public function checkConsigneeInfo($value)
  139. {
  140. if (!is_array($value)) {
  141. return '收货信息须为数组格式';
  142. }
  143. if (!isset($value['name']) || !isset($value['mobile']) || !isset($value['address'])) {
  144. return '收货信息参数不完整';
  145. }
  146. return true;
  147. }
  148. /**
  149. * @notes 校验提货信息参数
  150. * @param $value
  151. * @return string|void
  152. * @author Tab
  153. * @date 2021/11/15 18:14
  154. */
  155. public function checkVerificationInfo($value)
  156. {
  157. if (!is_array($value)) {
  158. return '提货信息须为数组格式';
  159. }
  160. if (!isset($value['contacts']) || !isset($value['mobile']) || !isset($value['pickup_code'])) {
  161. return '提货信息参数不完整';
  162. }
  163. return true;
  164. }
  165. /**
  166. * @notes 校验模板是否被打印机使用
  167. * @param $value
  168. * @return bool|string
  169. * @author Tab
  170. * @date 2021/11/16 9:50
  171. */
  172. public function checkTempateUsed($value)
  173. {
  174. $printer = Printer::where('template_id', $value)->findOrEmpty();
  175. if (!$printer->isEmpty()) {
  176. return '有打印机正在使用该模板,不允许删除';
  177. }
  178. return true;
  179. }
  180. }