| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- <?php
- // +----------------------------------------------------------------------
- // | likeadmin快速开发前后端分离管理后台(PHP版)
- // +----------------------------------------------------------------------
- // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
- // | 开源版本可自由商用,可去除界面版权logo
- // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
- // | github下载:https://github.com/likeshop-github/likeadmin
- // | 访问官网:https://www.likeadmin.cn
- // | likeadmin团队 版权所有 拥有最终解释权
- // +----------------------------------------------------------------------
- // | author: likeadminTeam
- // +----------------------------------------------------------------------
- namespace app\adminapi\validate\agricultural_machinery;
- use app\common\validate\BaseValidate;
- use app\common\model\agricultural_machinery\ServiceCategory as AgriculturalMachineryServiceCategory;
- use app\common\model\agricultural_machinery\UserService;
- use app\common\model\user\User;
- use app\common\model\asset\AssetArea;
- /**
- * 服务管理验证
- * Class ArticleCateValidate
- * @package app\adminapi\validate\article
- */
- class UserServiceValidate extends BaseValidate
- {
- protected $rule = [
- 'id' => 'require|checkUserServiceInfo',
- 'user_id' => 'require|checkUserInfo',
- 'name' => 'require|length:1,60',
- 'status' => 'requireIf:status,0|in:0,1',
- 'audit_status'=>'requireIf:audit_status,0|in:0,1,2',
- 'sort' => 'egt:0',
- 'type' =>'require|in:1,2,3',
- 'pay_status' => 'requireIf:pay_status,true|in:1,0',
- 'mobile' => 'require|mobile',
- 'cate_id'=>'require|checkCateCode',
- 'area_id' => 'require|checkArea',
- 'images'=>'require',
- 'money' => 'require|float|egt:0',
- 'agricultural_service'=>'requireIf:agricultural_service,true',
- 'disclaimer'=>'require'
- ];
- protected $message = [
- 'id.require' => ' 分类id不能为空',
- 'user_id.require' => '请选择用户',
- 'name.require' => '分类名称不能为空',
- 'name.length' => '分类长度须在1-60位字符',
- 'sort.egt' => '排序值不正确',
- 'type.require' => '类型不能为空',
- 'type.in' => '类型值type参数规则错误',
- 'pay_status.requireIf' => '请选择支付状态',
- 'pay_status.in' => '支付状态值错误',
- 'mobile.require' => '联系方式参数缺失',
- 'mobile.mobile' => '请填写正确的手机号',
- 'cate_id.require' => '分类信息必传',
- 'images.require' => '请输入上传服务图片',
- 'area_id.require' => '地区信息必传',
- 'money.require' =>'服务费用必传',
- 'money.float' =>'服务费参数错误',
- 'money.egt' =>'服务费参数规则错误',
- 'disclaimer.require' =>'免责条款必传',
- ];
- public function sceneEditContent(){
- return $this->only(['agricultural_service']);
- }
- public function sceneDisclaimer(){
- return $this->only(['disclaimer']);
- }
- public function sceneAddMechanicalCate(){
- return $this->only(['name']);
- }
- /**
- * @notes 列表
- * @return ArticleCateValidate
- * @author heshihu
- * @date 2022/2/10 15:11
- */
- public function sceneUserService()
- {
- return $this->only(['type','pay_status']);
- }
- /**
- * @notes 添加场景
- * @return ArticleCateValidate
- * @author heshihu
- * @date 2022/2/10 15:11
- */
- public function sceneAdd()
- {
- return $this->remove(['id'])
- ->remove('id', 'require|checkUserServiceInfo');
- }
- /**
- * @notes 详情场景
- * @return ArticleCateValidate
- * @author heshihu
- * @date 2022/2/21 17:55
- */
- public function sceneDetail()
- {
- return $this->only(['id']);
- }
- /**
- * @notes 更改状态场景
- * @return ArticleCateValidate
- * @author heshihu
- * @date 2022/2/21 18:02
- */
- public function sceneStatus()
- {
- return $this->only(['id', 'status']);
- }
- public function sceneAudit(){
- return $this->only(['id', 'audit_status']);
- }
- public function sceneEdit()
- {
- return $this
- ->remove('type', 'require');
- }
- /**
- * @notes 获取所有农耕分类场景
- * @return ArticleCateValidate
- * @author heshihu
- * @date 2022/2/15 10:05
- */
- public function sceneSelect()
- {
- // return $this->only(['type']);
- }
- /**
- * @notes 删除场景
- * @return ArticleCateValidate
- * @author heshihu
- * @date 2022/2/21 17:52
- */
- public function sceneDelete()
- {
- return $this->only(['id'])
- ->append('id', 'checkUserServiceInfo');
- }
- /**
- * @notes 场景相关校验
- * @param $scene
- * @param $rule
- * @param $data
- * @return bool|string
- * @author 段誉
- * @date 2022/9/15 14:37
- */
- public function checkCateCode($scene, $rule, $data)
- {
- $cate_id_arr = explode(',',$data['cate_id']);
- foreach($cate_id_arr as $v){
- $info = AgriculturalMachineryServiceCategory::where(['id'=>$v,'type'=>$data['type']])->findOrEmpty();
- if($info->isEmpty()){
- return '传入的分类id:'.$v.'不存在!';
- }
- }
- return true;
- }
- /**
- * @notes 场景相关校验
- * @param $scene
- * @param $rule
- * @param $data
- * @return bool|string
- * @author 段誉
- * @date 2022/9/15 14:37
- */
- public function checkArea($scene, $rule, $data)
- {
- $area_id_arr = explode(',',$data['area_id']);
- foreach($area_id_arr as $v){
- $info = AssetArea::where(['id'=>$v,'status'=>1])->findOrEmpty();
- if($info->isEmpty()){
- return '传入的地区id:'.$v.'不存在!';
- }
- }
- return true;
- }
- /**
- * @notes 检查指定服务信息是否存在
- * @param $value
- * @return bool|string
- * @author heshihu
- * @date 2022/2/10 15:10
- */
- public function checkUserServiceInfo($value)
- {
- $category = UserService::findOrEmpty($value);
- if ($category->isEmpty()) {
- return '服务信息不存在';
- }
- return true;
- }
- public function checkUserInfo($value,$data)
- {
- $category = User::findOrEmpty($value);
- if ($category->isEmpty()) {
- return '用户信息不存在';
- }
- return true;
- }
- /**
- * @notes 删除时验证农耕分类是否已使用
- * @param $value
- * @return bool|string
- * @author heshihu
- * @date 2022/2/22 14:45
- */
- public function checkDeleteArticleCate($value)
- {
- // $article = Article::where('cid', $value)->findOrEmpty();
- // if (!$article->isEmpty()) {
- // return '农耕分类已使用,请先删除绑定该农耕分类的农耕服务';
- // }
- return true;
- }
- }
|