GroupModel.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. try {
  83. $this->where('gr_id', $gr_id)->update($data);
  84. return true;
  85. } catch (\Exception $e) {
  86. return false;
  87. }
  88. }
  89. /**
  90. * 更新编辑分组信息
  91. * @param int $id 分组ID
  92. * @param array $data 更新数据
  93. * @return bool 更新成功返回 true,否则返回 false
  94. */
  95. public function updateGroups($id, $data)
  96. {
  97. try {
  98. $this->where('gr_id', $id)->save($data);
  99. return true;
  100. } catch (\Exception $e) {
  101. return false;
  102. }
  103. }
  104. /**
  105. * 删除分组
  106. *
  107. * @param int $id 分组ID
  108. * @return bool
  109. */
  110. public function deleteGroup($id)
  111. {
  112. $result = $this->where('id', $id)->delete();
  113. if ($result > 0) {
  114. return true;
  115. }
  116. return false;
  117. }
  118. }