初始版本
This commit is contained in:
167
server/app/adminapi/validate/coach/CoachValidate.php
Executable file
167
server/app/adminapi/validate/coach/CoachValidate.php
Executable file
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
namespace app\adminapi\validate\coach;
|
||||
use app\adminapi\logic\coach\CoachLogic;
|
||||
use app\common\model\coach\Coach;
|
||||
use app\common\model\coach\CoachUser;
|
||||
use app\common\model\skill\Skill;
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
/**
|
||||
* 技师验证类
|
||||
* Class CoachValidate
|
||||
* @package app\adminapi\validate\coach
|
||||
*/
|
||||
class CoachValidate extends BaseValidate
|
||||
{
|
||||
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
// 'coach_user_id' => 'require|checkCoachUserId',
|
||||
'name' => 'require|max:64',
|
||||
'gender' => 'require|in:1,2',
|
||||
'age' => 'require',
|
||||
'mobile' => 'require|mobile',
|
||||
'id_card' => 'require|idCard',
|
||||
'education' => 'require',
|
||||
'nation' => 'require',
|
||||
'province_id' => 'require',
|
||||
'city_id' => 'require',
|
||||
// 'region_id' => 'require',
|
||||
'address_detail' => 'require',
|
||||
'skill_id' => 'require|checkSkill',
|
||||
'goods_ids' => 'require|array|checkGoods',
|
||||
'id_card_back' => 'require',
|
||||
'id_card_front' => 'require',
|
||||
'portrait_shooting' => 'require',
|
||||
'work_photo' => 'require',
|
||||
// 'certification' => 'require',
|
||||
// 'health_certificate'=> 'require',
|
||||
// 'life_photo' => 'require|array',
|
||||
'work_status' => 'require|in:0,1',
|
||||
'server_status' => 'require|in:0,1',
|
||||
// 'longitude' => 'require',
|
||||
// 'latitude' => 'require',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'id.require' => '请选择技师',
|
||||
'coach_user_id.require' => '请选择账号',
|
||||
'name.require' => '请输入名称',
|
||||
'name.max' => '名称不能超过64个字符',
|
||||
'gender.require' => '请输入性别',
|
||||
'gender.in' => '性别错误',
|
||||
'mobile.require' => '请输入联系电话',
|
||||
'mobile.mobile' => '联系电话格式错误',
|
||||
'id_card.require' => '请输入身份证',
|
||||
'id_card.idCard' => '身份证格式错误',
|
||||
'education.require' => '请输入学历',
|
||||
'nation.require' => '请输入民族',
|
||||
'province_id.require' => '请选择省份',
|
||||
'city_id.require' => '请选择城市',
|
||||
'region_id.require' => '请选择地区',
|
||||
'address_detail.require' => '请输入详情地址',
|
||||
'skill_id.require' => '请选择技能',
|
||||
'goods_ids.require' => '请选择服务',
|
||||
'goods_ids.array' => '服务数据错误',
|
||||
'id_card_back.require' => '请上传身份证人像照',
|
||||
'id_card_front,require' => '请上传身份证国徽照',
|
||||
'portrait_shooting,require' => '请上传人像实拍照',
|
||||
'work_photo.require' => '请上传工作照',
|
||||
'work_status.require' => '请选择工作状态',
|
||||
'work_status.in' => '工作状态错误',
|
||||
'server_status.require' => '请选择服务状态',
|
||||
'server_status.in' => '服务状态错误',
|
||||
'longitude.require' => '请在地图上标记位置',
|
||||
'latitude.require' => '请在地图上标记位置',
|
||||
];
|
||||
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->remove(['id'=>true]);
|
||||
}
|
||||
|
||||
public function sceneId()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 验证账号完整
|
||||
* @param $value
|
||||
* @param $rule
|
||||
* @param $data
|
||||
* @return string|true
|
||||
* @author cjhao
|
||||
* @date 2024/8/20 18:55
|
||||
*/
|
||||
public function checkCoachUserId($value,$rule,$data)
|
||||
{
|
||||
|
||||
// $coachUser = CoachUser::where(['id'=>$value])->findOrEmpty();
|
||||
// if($coachUser->isEmpty()){
|
||||
// return '账号不存在';
|
||||
// }
|
||||
// $where[] = ['coach_user_id','=',$value];
|
||||
// if(isset($data['id'])){
|
||||
// $where[] = ['id','<>',$data['id']];
|
||||
// }
|
||||
// $coach = Coach::where($where)->findOrEmpty();
|
||||
// if(!$coach->isEmpty()){
|
||||
// return '账号已关联了技师';
|
||||
// }
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* @notes 验证技能
|
||||
* @param $value
|
||||
* @param $rule
|
||||
* @param $data
|
||||
* @return string|true
|
||||
* @author cjhao
|
||||
* @date 2024/8/20 17:44
|
||||
*/
|
||||
public function checkSkill($value,$rule,$data)
|
||||
{
|
||||
$skill = Skill::where(['id'=>$value])->findOrEmpty();
|
||||
if($skill->isEmpty()){
|
||||
return '服务技能不存在,请重新刷新';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes
|
||||
* @param $value
|
||||
* @param $rule
|
||||
* @param $data
|
||||
* @return string|true
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author cjhao
|
||||
* @date 2024/8/20 18:15
|
||||
*/
|
||||
public function checkGoods($value,$rule,$data)
|
||||
{
|
||||
$shopId = 0;
|
||||
$coachId = $data['id'] ?? 0;
|
||||
if($coachId){
|
||||
$shopId = Coach::where(['id'=>$coachId])->value('shop_id');
|
||||
}
|
||||
$skillLists = (new CoachLogic())->skillLists($shopId);
|
||||
$skillLists = array_column($skillLists,null,'id');
|
||||
$goodsLists = $skillLists[$data['skill_id']]['goods_list'] ?? [];
|
||||
if(empty($goodsLists)){
|
||||
return '请选择服务';
|
||||
}
|
||||
$goodsIds = array_column($goodsLists,'id');
|
||||
foreach ($value as $id) {
|
||||
if(!in_array($id,$goodsIds)){
|
||||
return '服务数据错误,请刷新技能重新选择';
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user