SmartDevicesCategory.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace app\model;
  3. use support\Model;
  4. class SmartDevicesCategory extends Model
  5. {
  6. protected $table = 'smart_devices_category';
  7. protected $primaryKey = 'category_id';
  8. protected $dateFormat = 'U';
  9. const CREATED_AT = 'category_add_time';
  10. const UPDATED_AT = 'category_update_time';
  11. /**
  12. * @Desc 获取父级
  13. * @Author Gorden
  14. * @Date 2024/3/8 9:12
  15. *
  16. * @param $pid
  17. * @return array
  18. */
  19. public function getParent($pid)
  20. {
  21. $parent = self::where('category_id', $pid)->first();
  22. return $parent ? $parent->toArray() : [];
  23. }
  24. /**
  25. * @Desc 获取所有子集
  26. * @Author Gorden
  27. * @Date 2024/3/8 9:39
  28. *
  29. * @param $id
  30. * @return array
  31. */
  32. public function getDirectSub($id)
  33. {
  34. return self::where('category_pid', $id)->get()->toArray();
  35. }
  36. /**
  37. * @Desc 更新path
  38. * @Author Gorden
  39. * @Date 2024/3/8 9:46
  40. *
  41. * @param $id
  42. * @param $path
  43. * @return int
  44. */
  45. public function updatePath($id, $path)
  46. {
  47. return self::where('category_id', $id)->update(['category_path' => $path]);
  48. }
  49. }