UserServiceValidate.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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' => 'checkUserInfo',
  30. 'name' => 'require|length:1,60',
  31. 'status' => 'requireIf:status,0|in:0,1',
  32. 'audit_status'=>'requireIf:audit_status,0|in:0,1,2',
  33. 'sort' => 'egt:0',
  34. 'type' =>'require|in:1,2,3',
  35. 'pay_status' => 'requireIf:pay_status,true|in:1,0',
  36. 'mobile' => 'require|mobile',
  37. 'cate_id'=>'require|checkCateCode',
  38. 'area_id' => 'require|checkArea',
  39. 'money' => 'float|egt:0',
  40. 'agricultural_service'=>'requireIf:agricultural_service,true',
  41. 'disclaimer'=>'require',
  42. // 'driver_image'=>'require',
  43. // 'driving_image'=>'require',
  44. // 'agricultural_image'=>'require',
  45. 'mechanical_cate_id'=>'require',
  46. ];
  47. protected $message = [
  48. 'id.require' => ' 分类id不能为空',
  49. 'user_id.require' => '请选择用户',
  50. 'name.require' => '分类名称不能为空',
  51. 'name.length' => '分类长度须在1-60位字符',
  52. 'sort.egt' => '排序值不正确',
  53. 'type.require' => '类型不能为空',
  54. 'type.in' => '类型值type参数规则错误',
  55. 'pay_status.requireIf' => '请选择支付状态',
  56. 'pay_status.in' => '支付状态值错误',
  57. 'mobile.require' => '联系方式参数缺失',
  58. 'mobile.mobile' => '请填写正确的手机号',
  59. 'cate_id.require' => '分类信息必传',
  60. 'area_id.require' => '地区信息必传',
  61. 'money.float' =>'服务费参数错误',
  62. 'money.egt' =>'服务费参数规则错误',
  63. 'disclaimer.require' =>'免责条款必传',
  64. // 'driver_image.require' => '请上传驾驶证图片',
  65. // 'driving_image.require' => '请上传行驶证图片',
  66. // 'agricultural_image.require' => '请上传农机图片',
  67. 'mechanical_cate_id.require' => '机械分类必传',
  68. ];
  69. public function sceneEditContent(){
  70. return $this->only(['agricultural_service']);
  71. }
  72. public function sceneDisclaimer(){
  73. return $this->only(['disclaimer']);
  74. }
  75. public function sceneMechanical(){
  76. return $this->only(['type']);
  77. }
  78. public function sceneAddMechanicalCate(){
  79. return $this->only(['name','type']);
  80. }
  81. public function sceneEditCate(){
  82. return $this->only(['name']);
  83. }
  84. /**
  85. * @notes 列表
  86. * @return ArticleCateValidate
  87. * @author heshihu
  88. * @date 2022/2/10 15:11
  89. */
  90. public function sceneUserService()
  91. {
  92. return $this->only(['type','pay_status']);
  93. }
  94. /**
  95. * @notes 添加场景
  96. * @return ArticleCateValidate
  97. * @author heshihu
  98. * @date 2022/2/10 15:11
  99. */
  100. public function sceneAdd()
  101. {
  102. return $this->remove(['id','disclaimer'])
  103. ->remove('id', 'require|checkUserServiceInfo')
  104. ->remove('user_id', 'checkUserInfo')
  105. ->remove('disclaimer', 'require');
  106. }
  107. /**
  108. * @notes 编辑场景
  109. * @return ArticleCateValidate
  110. * @author heshihu
  111. * @date 2022/2/10 15:11
  112. */
  113. public function sceneEditUserService()
  114. {
  115. return $this->remove(['disclaimer'])
  116. ->remove('disclaimer', 'require')
  117. ->remove('user_id', 'checkUserInfo');
  118. }
  119. /**
  120. * @notes 详情场景
  121. * @return ArticleCateValidate
  122. * @author heshihu
  123. * @date 2022/2/21 17:55
  124. */
  125. public function sceneDetail()
  126. {
  127. return $this->only(['id']);
  128. }
  129. public function sceneCateDetail(){
  130. return $this->only(['id'])->remove('id', 'checkUserServiceInfo');;
  131. }
  132. /**
  133. * @notes 更改状态场景
  134. * @return ArticleCateValidate
  135. * @author heshihu
  136. * @date 2022/2/21 18:02
  137. */
  138. public function sceneStatus()
  139. {
  140. return $this->only(['id', 'status']);
  141. }
  142. public function sceneAudit(){
  143. return $this->only(['id', 'audit_status']);
  144. }
  145. public function sceneEdit()
  146. {
  147. return $this
  148. ->remove('type', 'require');
  149. }
  150. /**
  151. * @notes 获取所有农耕分类场景
  152. * @return ArticleCateValidate
  153. * @author heshihu
  154. * @date 2022/2/15 10:05
  155. */
  156. public function sceneSelect()
  157. {
  158. // return $this->only(['type']);
  159. }
  160. /**
  161. * @notes 删除场景
  162. * @return ArticleCateValidate
  163. * @author heshihu
  164. * @date 2022/2/21 17:52
  165. */
  166. public function sceneDelete()
  167. {
  168. return $this->only(['id'])
  169. ->append('id', 'checkUserServiceInfo');
  170. }
  171. /**
  172. * @notes 场景相关校验
  173. * @param $scene
  174. * @param $rule
  175. * @param $data
  176. * @return bool|string
  177. * @author 段誉
  178. * @date 2022/9/15 14:37
  179. */
  180. public function checkCateCode($scene, $rule, $data)
  181. {
  182. $cate_id_arr = explode(',',$data['cate_id']);
  183. foreach($cate_id_arr as $v){
  184. $info = AgriculturalMachineryServiceCategory::where(['id'=>$v,'type'=>$data['type']])->findOrEmpty();
  185. if($info->isEmpty()){
  186. return '传入的分类id:'.$v.'不存在!';
  187. }
  188. }
  189. return true;
  190. }
  191. /**
  192. * @notes 场景相关校验
  193. * @param $scene
  194. * @param $rule
  195. * @param $data
  196. * @return bool|string
  197. * @author 段誉
  198. * @date 2022/9/15 14:37
  199. */
  200. public function checkArea($scene, $rule, $data)
  201. {
  202. $area_id_arr = explode(',',$data['area_id']);
  203. foreach($area_id_arr as $v){
  204. $info = AssetArea::where(['id'=>$v,'status'=>1])->findOrEmpty();
  205. if($info->isEmpty()){
  206. return '传入的地区id:'.$v.'不存在!';
  207. }
  208. }
  209. return true;
  210. }
  211. /**
  212. * @notes 检查指定服务信息是否存在
  213. * @param $value
  214. * @return bool|string
  215. * @author heshihu
  216. * @date 2022/2/10 15:10
  217. */
  218. public function checkUserServiceInfo($value)
  219. {
  220. $category = UserService::findOrEmpty($value);
  221. if ($category->isEmpty()) {
  222. return '服务信息不存在';
  223. }
  224. return true;
  225. }
  226. public function checkUserInfo($value,$data)
  227. {
  228. $category = User::findOrEmpty($value);
  229. if ($category->isEmpty()) {
  230. return '用户信息不存在';
  231. }
  232. return true;
  233. }
  234. /**
  235. * @notes 删除时验证农耕分类是否已使用
  236. * @param $value
  237. * @return bool|string
  238. * @author heshihu
  239. * @date 2022/2/22 14:45
  240. */
  241. public function checkDeleteArticleCate($value)
  242. {
  243. // $article = Article::where('cid', $value)->findOrEmpty();
  244. // if (!$article->isEmpty()) {
  245. // return '农耕分类已使用,请先删除绑定该农耕分类的农耕服务';
  246. // }
  247. return true;
  248. }
  249. }