SysDept.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace app\model;
  3. use DateTimeInterface;
  4. use support\Model;
  5. class SysDept extends Model
  6. {
  7. // 关联表
  8. protected $table = 'sys_dept';
  9. protected $primaryKey = 'dept_id';
  10. protected $dateFormat = 'U';
  11. const CREATED_AT = 'dept_addtimes';
  12. const UPDATED_AT = null;
  13. public function serializeDate(DateTimeInterface $date)
  14. {
  15. return $date->format('Y-m-d H:i:s');
  16. }
  17. /**
  18. * @Desc 获取子部门
  19. * @Author Gorden
  20. * @Date 2024/3/7 14:03
  21. *
  22. * @param $path
  23. * @return array
  24. */
  25. public static function getAllSubDept($path)
  26. {
  27. return self::where('dept_super_path', 'like', $path . '%')->get()->toArray();
  28. }
  29. /**
  30. * @Desc 验证指定字段指定值是否存在
  31. * @Author Gorden
  32. * @Date 2024/3/22 14:52
  33. *
  34. * @param $category
  35. * @param $field
  36. * @param $value
  37. * @return bool
  38. */
  39. public static function checkExist($category, $field, $value)
  40. {
  41. return self::where('dept_category', $category)
  42. ->where($field, $value)
  43. ->exists();
  44. }
  45. public function premises(){
  46. return $this->hasOne(self::class,'dept_id','dept_super_id');
  47. }
  48. }