SystemConfigClassify.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace app\admin\model;
  3. use support\Model;
  4. /**
  5. * 系统配置分类表模型
  6. * Class SystemConfigClassify
  7. * @package app\api\model
  8. */
  9. class SystemConfigClassify extends Model
  10. {
  11. const WAIT = '0';
  12. const DONE = '1';
  13. const MEMBER_AUTH_STATUS = [
  14. self::WAIT => '停用',
  15. self::DONE => '启用',
  16. ];
  17. /**
  18. * The table associated with the model.
  19. *
  20. * @var string
  21. */
  22. protected $table = 'system_config_classify';
  23. public $timestamps = false;
  24. /**
  25. * Notes:子集模型关联
  26. * @return \Illuminate\Database\Eloquent\Relations\HasMany
  27. * User: yym
  28. * Date: 2022/10/10
  29. */
  30. public function children()
  31. {
  32. return $this->hasMany(SystemConfigClassify::class, 'classify_pid', 'classify_id');
  33. }
  34. /**
  35. * Notes:设置分类列表
  36. * @return array
  37. * User: yym
  38. * Date: 2022/10/10
  39. */
  40. public static function getClassifyList()
  41. {
  42. return static::where(['classify_pid' => 0])
  43. ->with(['children'])
  44. ->orderBy('classify_sort', 'desc')
  45. ->get()
  46. ->toArray();
  47. }
  48. /**
  49. * Notes:插入数据
  50. * @param array $data
  51. * @return false|int
  52. * User: yym
  53. * Date: 2022/10/10
  54. */
  55. public static function insertData(array $data)
  56. {
  57. if(empty($data))
  58. {
  59. return false;
  60. }
  61. return static::insertGetId($data);
  62. }
  63. /**
  64. * Notes:根据主键获取单个信息
  65. * @param int $classify_id
  66. * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
  67. * User: yym
  68. * Date: 2022/10/10
  69. */
  70. public static function getInfo(int $classify_id)
  71. {
  72. return static::where(['classify_id' => $classify_id])->first();
  73. }
  74. /**
  75. * Notes:根据主键更新信息
  76. * @param int $classify_id
  77. * @param array $data
  78. * @return false|int
  79. * User: yym
  80. * Date: 2022/10/10
  81. */
  82. public static function updateData(int $classify_id, array $data)
  83. {
  84. if(empty($classify_id) || empty($data))
  85. {
  86. return false;
  87. }
  88. return static::where(['classify_id' => $classify_id])->update($data);
  89. }
  90. }