UserServiceValidate.php 7.2 KB

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