GroupModel.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. * @param string $title
  13. * @param int $page
  14. * @param int $pagesize
  15. * @return mixed
  16. */
  17. public function getList($title = '', $page = 1, $pagesize = 10)
  18. {
  19. $query = $this->order('gr_id ASC');
  20. if (!empty($title)) {
  21. $query->whereLike('title', '%' . $title . '%');
  22. }
  23. $list = $query->paginate([
  24. 'page' => $page,
  25. 'list_rows' => $pagesize,
  26. ]);
  27. return $list;
  28. }
  29. /**
  30. * 添加分组
  31. *
  32. * @param array $data 数据
  33. * @return bool
  34. */
  35. public function add($data)
  36. {
  37. $db = new Db();
  38. $result = $db->name('group')->insert($data);
  39. if ($result) {
  40. return true;
  41. }
  42. return false;
  43. }
  44. /**
  45. * 获取分组信息
  46. *
  47. * @param int $id 分组ID
  48. * @return array|null
  49. */
  50. public function getGroup($id)
  51. {
  52. $group = $this->find($id);
  53. if ($group) {
  54. return $group->toArray();
  55. }
  56. return null;
  57. }
  58. /**
  59. * 更新分组信息
  60. *
  61. * @param int $id 分组ID
  62. * @param array $data 数据
  63. * @return bool
  64. */
  65. public function updateGroup($id, $data)
  66. {
  67. $result = $this->where('id', $id)->update($data);
  68. if ($result !== false) {
  69. return true;
  70. }
  71. return false;
  72. }
  73. /**
  74. * 更新审核状态
  75. *
  76. * @param int $gr_id 课程ID
  77. * @param array $data 数据
  78. * @return bool
  79. */
  80. public function updateAuditStatus($gr_id, $data)
  81. {
  82. $result = $this->where('gr_id', $gr_id)->update($data);
  83. if ($result !== false) {
  84. return true;
  85. }
  86. return false;
  87. }
  88. /**
  89. * 编辑分组
  90. *
  91. * @param int $id 分组ID
  92. * @param array $data 分组数据
  93. * @return bool
  94. */
  95. public function edit($id, $data)
  96. {
  97. $result = $this->where('gr_id', $id)->update($data);
  98. return $result !== false;
  99. }
  100. /**
  101. * 删除分组
  102. *
  103. * @param int $id 分组ID
  104. * @return bool
  105. */
  106. public function deleteGroup($id)
  107. {
  108. $result = $this->where('id', $id)->delete();
  109. if ($result > 0) {
  110. return true;
  111. }
  112. return false;
  113. }
  114. }