GroupModel.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. public function updateAuditStatus($gr_id, $data)
  89. {
  90. try {
  91. $this->where('gr_id', $gr_id)->update($data);
  92. return true;
  93. } catch (\Exception $e) {
  94. return false;
  95. }
  96. }
  97. /**
  98. * 编辑分组
  99. *
  100. * @param int $id 分组ID
  101. * @param array $data 分组数据
  102. * @return bool
  103. */
  104. public function edit($id, $data)
  105. {
  106. $result = $this->where('gr_id', $id)->update($data);
  107. return $result !== false;
  108. }
  109. /**
  110. * 删除分组
  111. *
  112. * @param int $id 分组ID
  113. * @return bool
  114. */
  115. public function deleteGroup($id)
  116. {
  117. $result = $this->where('id', $id)->delete();
  118. if ($result > 0) {
  119. return true;
  120. }
  121. return false;
  122. }
  123. }