SelffetchVerifierValidate.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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\selffetch_shop;
  20. use app\common\model\SelffetchShop;
  21. use app\common\model\SelffetchVerifier;
  22. use app\common\model\User;
  23. use app\common\validate\BaseValidate;
  24. /**
  25. * 核销员验证器
  26. * Class SelffetchVerifierValidate
  27. * @package app\adminapi\validate\selffetch_shop
  28. */
  29. class SelffetchVerifierValidate extends BaseValidate
  30. {
  31. protected $rule = [
  32. 'id' => 'require|checkId',
  33. 'name' => 'require|checkName',
  34. 'user_id' => 'require|checkUserId',
  35. 'selffetch_shop_id' => 'require|checkSelffetchShopId',
  36. 'mobile' => 'require|mobile',
  37. 'status' => 'require|in:0,1',
  38. ];
  39. protected $message = [
  40. 'name.require' => '核销员名称不能为空',
  41. 'user_id.require' => '用户不能为空',
  42. 'selffetch_shop_id.require' => '自提门店不能为空',
  43. 'mobile.require' => '联系电话不能为空',
  44. 'mobile.mobile' => '不是有效的手机号码',
  45. 'status.require' => '核销员状态不能为空',
  46. 'status.in' => '核销员状态取值范围[0,1]',
  47. ];
  48. public function sceneAdd()
  49. {
  50. return $this->only(['selffetch_shop_id','user_id','name','mobile','status'])
  51. ->append('user_id','checkUser');
  52. }
  53. public function sceneEdit()
  54. {
  55. return $this->only(['id','selffetch_shop_id','user_id','name','mobile','status']);
  56. }
  57. public function sceneDetail()
  58. {
  59. return $this->only(['id']);
  60. }
  61. public function sceneStatus()
  62. {
  63. return $this->only(['id','status']);
  64. }
  65. public function sceneDel()
  66. {
  67. return $this->only(['id']);
  68. }
  69. /**
  70. * @notes 检查自提门店是否存在
  71. * @param $value
  72. * @param $rule
  73. * @param $data
  74. * @return bool|string
  75. * @author ljj
  76. * @date 2021/8/11 7:09 下午
  77. */
  78. public function checkSelffetchShopId($value,$rule,$data)
  79. {
  80. $result = SelffetchShop::where('id', $value)->findOrEmpty();
  81. if ($result->isEmpty()) {
  82. return '自提门店不存在';
  83. }
  84. return true;
  85. }
  86. /**
  87. * @notes 检查用户是否存在
  88. * @param $value
  89. * @param $rule
  90. * @param $data
  91. * @return bool|string
  92. * @author ljj
  93. * @date 2021/8/11 7:11 下午
  94. */
  95. public function checkUserId($value,$rule,$data)
  96. {
  97. $result = User::where('id', $value)->findOrEmpty();
  98. if ($result->isEmpty()) {
  99. return '用户不存在';
  100. }
  101. return true;
  102. }
  103. /**
  104. * @notes 检验同一门店是否已存在相同用户
  105. * @param $value
  106. * @param $rule
  107. * @param $data
  108. * @return bool|string
  109. * @author ljj
  110. * @date 2021/9/26 6:56 下午
  111. */
  112. public function checkUser($value,$rule,$data)
  113. {
  114. $where[] = ['user_id', '=', $value];
  115. $where[] = ['selffetch_shop_id', '=', $data['selffetch_shop_id']];
  116. //编辑的情况,要排除自身ID
  117. if (isset($data['id'])) {
  118. $where[] = ['id', '<>', $data['id']];
  119. }
  120. $result = SelffetchVerifier::where($where)->findOrEmpty();
  121. if (!$result->isEmpty()) {
  122. return '同一门店不可存在多个相同用户';
  123. }
  124. return true;
  125. }
  126. /**
  127. * @notes 检查核销员名称是否已存在
  128. * @param $value
  129. * @param $rule
  130. * @param $data
  131. * @return bool|string
  132. * @author ljj
  133. * @date 2021/8/11 7:10 下午
  134. */
  135. public function checkName($value,$rule,$data)
  136. {
  137. $where[] = ['name', '=', $value];
  138. $where[] = ['selffetch_shop_id', '=', $data['selffetch_shop_id']];
  139. //编辑的情况,要排除自身ID
  140. if (isset($data['id'])) {
  141. $where[] = ['id', '<>', $data['id']];
  142. }
  143. $result = SelffetchVerifier::where($where)->findOrEmpty();
  144. if (!$result->isEmpty()) {
  145. return '核销员名称已存在';
  146. }
  147. return true;
  148. }
  149. /**
  150. * @notes 检查核销员ID是否存在
  151. * @param $value
  152. * @param $rule
  153. * @param $data
  154. * @return bool|string
  155. * @author ljj
  156. * @date 2021/8/11 7:30 下午
  157. */
  158. public function checkId($value,$rule,$data)
  159. {
  160. $result = SelffetchVerifier::where('id', $value)->findOrEmpty();
  161. if ($result->isEmpty()) {
  162. return '核销员不存在';
  163. }
  164. return true;
  165. }
  166. }