'require|checkId', 'city_id' => 'require|checkCity', 'taxi' => 'require|in:0,1|checkTaxi', 'bus' => 'require|in:0,1|checkBus', ]; protected $message = [ 'id.require' => '参数错误', 'city_id.require' => '请选择城市', 'taxi.require' => '请选择滴滴/出租状态', 'taxi.in' => '滴滴/出租状态错误', 'bus.require' => '请选择公交/地铁状态', 'bus.in' => '公交/地铁状态错误', ]; public function sceneAdd() { return $this->remove(['id'=>true]); } public function sceneId() { return $this->only(['id']); } /** * @notes 检验ID * @param $value * @param $rule * @param $data * @return bool|string * @author ljj * @date 2022/2/8 4:32 下午 */ public function checkId($value,$rule,$data) { $result = City::where('id',$value)->findOrEmpty(); if ($result->isEmpty()) { return '数据不存在'; } return true; } /** * @notes 检验名称 * @param $value * @param $rule * @param $data * @return bool|string * @author ljj * @date 2022/2/8 4:36 下午 */ public function checkCity($value,$rule,$data) { $cityWhere[] = ['city_id','=',$value]; if(isset($data['id'])){ $cityWhere[] = ['id','<>',$data['id']]; } $city = City::where($cityWhere)->findOrEmpty(); if(!$city->isEmpty()){ return '该城市已添加'; } $city = Region::where(['id'=>$value])->findOrEmpty(); if($city->isEmpty()){ return '城市不存在,请重新选择'; } return true; } /** * @notes 验证出租车价格 * @param $value * @param $rule * @param $data * @return string|true * @author cjhao * @date 2024/8/27 13:14 */ public function checkTaxi($value,$rule,$data) { if(!$data['taxi']){ return true; } if('' == $data['start_km'] && $data['start_km'] < 0){ return '请输入起步里程数'; } if( '' == $data['start_price'] && $data['start_price'] < 0){ return '请输入起步价格'; } if('' == $data['continue_price'] && $data['continue_price'] < 0){ return '请输入每增加1公里价格'; } return true; } /** * @notes 验证出租车价格 * @param $value * @param $rule * @param $data * @return string|true * @author cjhao * @date 2024/8/27 13:14 */ public function checkBus($value,$rule,$data) { if(!$data['bus']){ return true; } if('' == $data['bus_start_time']){ return '请输入公交/地铁开启时间'; } if( '' == $data['bus_end_time'] ){ return '请输入公交/地铁结束时间'; } if('' == $data['bus_fare'] && $data['continue_price'] < 0){ return '请输入固定车费'; } return true; } }