GroupModel.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace app\model\api;
  3. use think\model;
  4. use think\db;
  5. class GroupModel extends Model
  6. {
  7. protected $table = 'table_education_gr';
  8. protected $pk = 'gr_id';
  9. /**
  10. *
  11. * 获取分组列表
  12. *
  13. * @return mixed
  14. */
  15. public function getList()
  16. {
  17. $list = $this->order('gr_id ASC')->select();
  18. return $list;
  19. }
  20. /**
  21. * 添加分组
  22. *
  23. * @param array $data 数据
  24. * @return bool
  25. */
  26. public function add($data)
  27. {
  28. $db = new Db();
  29. $result = $db->name('group')->insert($data);
  30. if ($result) {
  31. return true;
  32. }
  33. return false;
  34. }
  35. /**
  36. * 获取分组信息
  37. *
  38. * @param int $id 分组ID
  39. * @return array|null
  40. */
  41. public function getGroup($id)
  42. {
  43. $group = $this->find($id);
  44. if ($group) {
  45. return $group->toArray();
  46. }
  47. return null;
  48. }
  49. /**
  50. * 更新分组信息
  51. *
  52. * @param int $id 分组ID
  53. * @param array $data 数据
  54. * @return bool
  55. */
  56. public function updateGroup($id, $data)
  57. {
  58. $result = $this->where('id', $id)->update($data);
  59. if ($result !== false) {
  60. return true;
  61. }
  62. return false;
  63. }
  64. /**
  65. * 编辑分组
  66. *
  67. * @param int $id 分组ID
  68. * @param array $data 分组数据
  69. * @return bool
  70. */
  71. public function edit($id, $data)
  72. {
  73. $result = $this->where('gr_id', $id)->update($data);
  74. return $result !== false;
  75. }
  76. /**
  77. * 删除分组
  78. *
  79. * @param int $id 分组ID
  80. * @return bool
  81. */
  82. public function deleteGroup($id)
  83. {
  84. $result = $this->where('id', $id)->delete();
  85. if ($result > 0) {
  86. return true;
  87. }
  88. return false;
  89. }
  90. }