AttendanceClass.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace app\common\validate;
  3. use think\Db;
  4. use think\Validate;
  5. class AttendanceClass extends Validate{
  6. protected $rule = [
  7. 'name|名称' => 'require|checkUnique',
  8. 'content' => 'require|checkContent',
  9. ];
  10. protected $message = [
  11. ];
  12. protected $scene = [
  13. ];
  14. protected function checkUnique($value,$rule,$data=[])
  15. {
  16. $info = Db::name('attendance_class')
  17. ->where('name',$value)
  18. ->where('org_id',$data['org_id'])
  19. ->where('del',0)
  20. ->find();
  21. if($data['id'] <= 0 && $info){
  22. return '名称已被使用';
  23. }
  24. if($info && $data['id'] > 0 && $info['id'] != $data['id']){
  25. return '名称已被使用';
  26. }
  27. return true;
  28. }
  29. protected function checkContent($value,$rule,$data=[])
  30. {
  31. if(!$data['content']){
  32. return '参数错误';
  33. }
  34. $json = json_decode($data['content'],true);
  35. if(!$json){
  36. return '参数错误';
  37. }
  38. if(!isset($json['type']) || !in_array($json['type'],[1,2,3])){
  39. return '未选择打卡类型';
  40. }
  41. $dates = $json['dates'];
  42. foreach ($dates as $k=>$v){
  43. if(!$v['stime']||!$v['etime']){
  44. return '打卡时段未设置时间';
  45. }
  46. }
  47. return true;
  48. }
  49. }