KefuValidate.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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\kefu;
  20. use app\common\model\Kefu;
  21. use app\common\validate\BaseValidate;
  22. /**
  23. * 客服验证器
  24. * Class KefuValidate
  25. * @package app\adminapi\validate\kefu
  26. */
  27. class KefuValidate extends BaseValidate
  28. {
  29. protected $rule = [
  30. 'id' => 'require|number',
  31. 'admin_id' => 'require|number|checkIsKefu',
  32. 'avatar' => 'require',
  33. 'nickname' => 'require|unique:' . Kefu::class . ',nickname',
  34. 'disable' => 'require|in:0,1',
  35. 'sort' => 'egt:0'
  36. ];
  37. protected $message = [
  38. 'id.require' => 'id不可为空',
  39. 'id.number' => 'id必须为数字',
  40. 'admin_id.require' => '请选择管理员',
  41. 'admin_id.number' => '管理员选择异常',
  42. 'avatar.require' => '请选择头像',
  43. 'nickname.require' => '请填写客服昵称',
  44. 'nickname.unique' => '该客服昵称已存在',
  45. 'disable.require' => '请选择客服状态',
  46. 'disable.in' => '状态错误',
  47. 'sort.egt' => '排序需大于0',
  48. ];
  49. /**
  50. * @notes 添加客服场景
  51. * @return KefuValidate
  52. * @author 段誉
  53. * @date 2022/3/8 18:31
  54. */
  55. public function sceneAdd()
  56. {
  57. return $this->remove('id', true);
  58. }
  59. /**
  60. * @notes 编辑场景
  61. * @return KefuValidate
  62. * @author 段誉
  63. * @date 2022/3/8 18:31
  64. */
  65. public function sceneEdit()
  66. {
  67. return $this->remove('admin_id', true);
  68. }
  69. /**
  70. * @notes 删除场景
  71. * @return KefuValidate
  72. * @author 段誉
  73. * @date 2022/3/8 18:31
  74. */
  75. public function sceneDel()
  76. {
  77. return $this->only(['id'])->append('id', 'checkIsDel');
  78. }
  79. /**
  80. * @notes 客服详情场景
  81. * @return KefuValidate
  82. * @author 段誉
  83. * @date 2022/3/8 18:55
  84. */
  85. public function sceneDetail()
  86. {
  87. return $this->only(['id']);
  88. }
  89. /**
  90. * @notes 客服状态场景
  91. * @return KefuValidate
  92. * @author 段誉
  93. * @date 2022/3/8 18:32
  94. */
  95. public function sceneStatus()
  96. {
  97. return $this->only(['id', 'disable']);
  98. }
  99. /**
  100. * @notes 校验管理员是否已为客服
  101. * @param $value
  102. * @param $rule
  103. * @param array $data
  104. * @return bool|string
  105. * @author 段誉
  106. * @date 2022/3/8 17:32
  107. */
  108. protected function checkIsKefu($value, $rule, $data = [])
  109. {
  110. $check = Kefu::where(['admin_id' => $value])->findOrEmpty();
  111. if (!$check->isEmpty()) {
  112. return "该管理员已是客服";
  113. }
  114. return true;
  115. }
  116. /**
  117. * @notes 校验客服是否存在
  118. * @param $value
  119. * @param $rule
  120. * @param array $data
  121. * @return bool|string
  122. * @author 段誉
  123. * @date 2022/3/8 17:31
  124. */
  125. protected function checkIsDel($value, $rule, $data = [])
  126. {
  127. $check = Kefu::where(['id' => $value])->findOrEmpty();
  128. if ($check->isEmpty()) {
  129. return "客服信息不存在";
  130. }
  131. return true;
  132. }
  133. }