UserServiceValidate.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\adminapi\validate\agricultural_machinery;
  15. use app\common\validate\BaseValidate;
  16. use app\common\model\agricultural_machinery\ServiceCategory as AgriculturalMachineryServiceCategory;
  17. use app\common\model\agricultural_machinery\UserService;
  18. use app\common\model\user\User;
  19. use app\common\model\asset\AssetArea;
  20. /**
  21. * 服务管理验证
  22. * Class ArticleCateValidate
  23. * @package app\adminapi\validate\article
  24. */
  25. class UserServiceValidate extends BaseValidate
  26. {
  27. protected $rule = [
  28. 'id' => 'require|checkUserServiceInfo',
  29. 'user_id' => 'require|checkUserInfo',
  30. 'name' => 'require|length:1,60',
  31. 'status' => 'requireIf:status,0|in:0,1',
  32. 'sort' => 'egt:0',
  33. 'type' =>'require|in:1,2,3',
  34. 'pay_status' => 'requireIf:pay_status,true|in:1,-1',
  35. 'mobile' => 'require|mobile',
  36. 'cate_id'=>'require|checkCateCode',
  37. 'area_id' => 'require|checkArea',
  38. 'images'=>'require',
  39. 'money' => 'require|float|egt:0',
  40. ];
  41. protected $message = [
  42. 'id.require' => ' 分类id不能为空',
  43. 'user_id.require' => '请选择用户',
  44. 'name.require' => '分类名称不能为空',
  45. 'name.length' => '分类长度须在1-60位字符',
  46. 'sort.egt' => '排序值不正确',
  47. 'type.require' => '类型不能为空',
  48. 'type.in' => '类型值type参数规则错误',
  49. 'pay_status.requireIf' => '请选择支付状态',
  50. 'pay_status.in' => '支付状态值错误',
  51. 'mobile.require' => '联系方式参数缺失',
  52. 'mobile.mobile' => '请填写正确的手机号',
  53. 'cate_id.require' => '分类信息必传',
  54. 'images.require' => '请输入上传服务图片',
  55. 'area_id.require' => '地区信息必传',
  56. 'money.require' =>'服务费用必传',
  57. 'money.float' =>'服务费参数错误',
  58. 'money.egt' =>'服务费参数规则错误',
  59. ];
  60. /**
  61. * @notes 列表
  62. * @return ArticleCateValidate
  63. * @author heshihu
  64. * @date 2022/2/10 15:11
  65. */
  66. public function sceneUserService()
  67. {
  68. return $this->only(['type','pay_status']);
  69. }
  70. /**
  71. * @notes 添加场景
  72. * @return ArticleCateValidate
  73. * @author heshihu
  74. * @date 2022/2/10 15:11
  75. */
  76. public function sceneAdd()
  77. {
  78. return $this->remove(['id'])
  79. ->remove('id', 'require|checkUserServiceInfo');
  80. }
  81. /**
  82. * @notes 详情场景
  83. * @return ArticleCateValidate
  84. * @author heshihu
  85. * @date 2022/2/21 17:55
  86. */
  87. public function sceneDetail()
  88. {
  89. return $this->only(['id']);
  90. }
  91. /**
  92. * @notes 更改状态场景
  93. * @return ArticleCateValidate
  94. * @author heshihu
  95. * @date 2022/2/21 18:02
  96. */
  97. public function sceneStatus()
  98. {
  99. return $this->only(['id', 'status']);
  100. }
  101. public function sceneEdit()
  102. {
  103. return $this
  104. ->remove('type', 'require');
  105. }
  106. /**
  107. * @notes 获取所有农耕分类场景
  108. * @return ArticleCateValidate
  109. * @author heshihu
  110. * @date 2022/2/15 10:05
  111. */
  112. public function sceneSelect()
  113. {
  114. // return $this->only(['type']);
  115. }
  116. /**
  117. * @notes 删除场景
  118. * @return ArticleCateValidate
  119. * @author heshihu
  120. * @date 2022/2/21 17:52
  121. */
  122. public function sceneDelete()
  123. {
  124. return $this->only(['id'])
  125. ->append('id', 'checkDeleteArticleCate');
  126. }
  127. /**
  128. * @notes 场景相关校验
  129. * @param $scene
  130. * @param $rule
  131. * @param $data
  132. * @return bool|string
  133. * @author 段誉
  134. * @date 2022/9/15 14:37
  135. */
  136. public function checkCateCode($scene, $rule, $data)
  137. {
  138. $cate_id_arr = explode(',',$data['cate_id']);
  139. foreach($cate_id_arr as $v){
  140. $info = AgriculturalMachineryServiceCategory::where(['id'=>$v,'type'=>$data['type']])->findOrEmpty();
  141. if($info->isEmpty()){
  142. return '传入的分类id:'.$v.'不存在!';
  143. }
  144. }
  145. return true;
  146. }
  147. /**
  148. * @notes 场景相关校验
  149. * @param $scene
  150. * @param $rule
  151. * @param $data
  152. * @return bool|string
  153. * @author 段誉
  154. * @date 2022/9/15 14:37
  155. */
  156. public function checkArea($scene, $rule, $data)
  157. {
  158. $area_id_arr = explode(',',$data['area_id']);
  159. foreach($area_id_arr as $v){
  160. $info = AssetArea::where(['id'=>$v,'status'=>1])->findOrEmpty();
  161. if($info->isEmpty()){
  162. return '传入的地区id:'.$v.'不存在!';
  163. }
  164. }
  165. return true;
  166. }
  167. /**
  168. * @notes 检查指定服务信息是否存在
  169. * @param $value
  170. * @return bool|string
  171. * @author heshihu
  172. * @date 2022/2/10 15:10
  173. */
  174. public function checkUserServiceInfo($value)
  175. {
  176. $category = UserService::findOrEmpty($value);
  177. if ($category->isEmpty()) {
  178. return '服务信息不存在';
  179. }
  180. return true;
  181. }
  182. public function checkUserInfo($value,$data)
  183. {
  184. $category = User::findOrEmpty($value);
  185. if ($category->isEmpty()) {
  186. return '用户信息不存在';
  187. }
  188. return true;
  189. }
  190. /**
  191. * @notes 删除时验证农耕分类是否已使用
  192. * @param $value
  193. * @return bool|string
  194. * @author heshihu
  195. * @date 2022/2/22 14:45
  196. */
  197. public function checkDeleteArticleCate($value)
  198. {
  199. // $article = Article::where('cid', $value)->findOrEmpty();
  200. // if (!$article->isEmpty()) {
  201. // return '农耕分类已使用,请先删除绑定该农耕分类的农耕服务';
  202. // }
  203. return true;
  204. }
  205. }