12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- namespace app\common\validate;
- use think\Db;
- use think\Validate;
- class AttendanceClass extends Validate{
- protected $rule = [
- 'name|名称' => 'require|checkUnique',
- 'content' => 'require|checkContent',
- ];
- protected $message = [
- ];
- protected $scene = [
- ];
- protected function checkUnique($value,$rule,$data=[])
- {
- $info = Db::name('attendance_class')
- ->where('name',$value)
- ->where('org_id',$data['org_id'])
- ->where('del',0)
- ->find();
- if($data['id'] <= 0 && $info){
- return '名称已被使用';
- }
- if($info && $data['id'] > 0 && $info['id'] != $data['id']){
- return '名称已被使用';
- }
- return true;
- }
- protected function checkContent($value,$rule,$data=[])
- {
- if(!$data['content']){
- return '参数错误';
- }
- $json = json_decode($data['content'],true);
- if(!$json){
- return '参数错误';
- }
- if(!isset($json['type']) || !in_array($json['type'],[1,2,3])){
- return '未选择打卡类型';
- }
- $dates = $json['dates'];
- foreach ($dates as $k=>$v){
- if(!$v['stime']||!$v['etime']){
- return '打卡时段未设置时间';
- }
- }
- return true;
- }
- }
|