UserServiceValidate.php 6.6 KB

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