SysDept.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. public function getByPrimaryKey($id)
  18. {
  19. return self::where('dept_id', $id)->first();
  20. }
  21. /**
  22. * @Desc 获取子部门
  23. * @Author Gorden
  24. * @Date 2024/3/7 14:03
  25. *
  26. * @param $path
  27. * @return array
  28. */
  29. public static function getAllSubDept($path)
  30. {
  31. return self::where('dept_super_path', 'like', $path . '%')->get()->toArray();
  32. }
  33. /**
  34. * @Desc 验证指定字段指定值是否存在
  35. * @Author Gorden
  36. * @Date 2024/3/22 14:52
  37. *
  38. * @param $category
  39. * @param $field
  40. * @param $value
  41. * @return bool
  42. */
  43. public static function checkExist($category, $field, $value)
  44. {
  45. return self::where('dept_category', $category)
  46. ->where($field, $value)
  47. ->exists();
  48. }
  49. public function premises(){
  50. return $this->hasOne(self::class,'dept_id','dept_super_id');
  51. }
  52. }