Lecturer.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\controller\special;
  12. use app\admin\controller\AuthController;
  13. use app\admin\model\special\Special;
  14. use app\admin\model\special\Lecturer as LecturerModel;
  15. use service\JsonService;
  16. use think\Url;
  17. /**
  18. * 讲师控制器
  19. */
  20. class Lecturer extends AuthController
  21. {
  22. /**
  23. * 讲师列表展示
  24. * @return
  25. * */
  26. public function index()
  27. {
  28. return $this->fetch();
  29. }
  30. /**
  31. * 讲师列表获取
  32. * @return
  33. * */
  34. public function lecturer_list()
  35. {
  36. $where = parent::getMore([
  37. ['page', 1],
  38. ['is_show', ''],
  39. ['limit', 20],
  40. ['title', ''],
  41. ]);
  42. return JsonService::successlayui(LecturerModel::getLecturerList($where));
  43. }
  44. /**添加/编辑
  45. * @param int $id
  46. * @return mixed|void
  47. * @throws \think\exception\DbException
  48. */
  49. public function create($id = 0)
  50. {
  51. if ($id) {
  52. $lecturer= LecturerModel::get($id);
  53. $lecturer['label'] =json_decode($lecturer['label']);
  54. $lecturer['introduction'] = htmlspecialchars_decode($lecturer['introduction']);
  55. if(!$lecturer) return JsonService::fail('讲师信息不存在!');
  56. }else{
  57. $lecturer=[];
  58. }
  59. $this->assign(['lecturer'=>json_encode($lecturer),'id'=>$id]);
  60. return $this->fetch();
  61. }
  62. /**
  63. * 添加和修改讲师
  64. * @param int $id 修改
  65. * @return JsonService
  66. * */
  67. public function save_lecturer($id = 0)
  68. {
  69. $data = parent::postMore([
  70. ['lecturer_name', ''],
  71. ['lecturer_head', ''],
  72. ['label', []],
  73. ['explain', ''],
  74. ['introduction', ''],
  75. ['sort', 0],
  76. ['is_show', 1],
  77. ]);
  78. if (!$data['lecturer_name']) return JsonService::fail('请输入讲师名称');
  79. if (!$data['lecturer_head']) return JsonService::fail('请输入讲师头像');
  80. if (!count($data['label'])) return JsonService::fail('请输入标签');
  81. if (!$data['explain']) return JsonService::fail('请编辑讲师说明');
  82. if (!$data['introduction']) return JsonService::fail('请编辑讲师介绍');
  83. $data['label']=json_encode($data['label']);
  84. $data['introduction']=htmlspecialchars($data['introduction']);
  85. if ($id) {
  86. LecturerModel::edit($data,$id);
  87. return JsonService::successful('修改成功');
  88. } else {
  89. $data['add_time'] = time();
  90. if (LecturerModel::set($data))
  91. return JsonService::successful('添加成功');
  92. else
  93. return JsonService::fail('添加失败');
  94. }
  95. }
  96. /**
  97. * 设置单个产品上架|下架
  98. * @param int $is_show 是否显示
  99. * @param int $id 修改的主键
  100. * @return JsonService
  101. */
  102. public function set_show($is_show = '', $id = '')
  103. {
  104. ($is_show == '' || $id == '') && JsonService::fail('缺少参数');
  105. $res = LecturerModel::where(['id' => $id])->update(['is_show' => (int)$is_show]);
  106. if ($res) {
  107. return JsonService::successful($is_show == 1 ? '显示成功' : '隐藏成功');
  108. } else {
  109. return JsonService::fail($is_show == 1 ? '显示失败' : '隐藏失败');
  110. }
  111. }
  112. /**
  113. * 快速编辑
  114. * @param string $field 字段名
  115. * @param int $id 修改的主键
  116. * @param string value 修改后的值
  117. * @return JsonService
  118. */
  119. public function set_value($field = '', $id = '', $value = '')
  120. {
  121. $field == '' || $id == '' || $value == '' && JsonService::fail('缺少参数');
  122. if (LecturerModel::where(['id' => $id])->update([$field => $value]))
  123. return JsonService::successful('保存成功');
  124. else
  125. return JsonService::fail('保存失败');
  126. }
  127. /**
  128. * 删除讲师
  129. * @param int $id 修改的主键
  130. * @return json
  131. * */
  132. public function delete($id = 0)
  133. {
  134. if (!$id) return JsonService::fail('缺少参数');
  135. if (LecturerModel::delLecturer($id))
  136. return JsonService::successful('删除成功');
  137. else
  138. return JsonService::fail(LecturerModel::getErrorInfo('删除失败'));
  139. }
  140. /**
  141. * 讲师课程订单
  142. */
  143. public function lecturer_order($id=0)
  144. {
  145. $this->assign([
  146. 'year' => getMonth('h'),
  147. 'lecturer_id' => $id,
  148. ]);
  149. return $this->fetch();
  150. }
  151. /**讲师课程购买记录
  152. * @throws \think\exception\DbException
  153. */
  154. public function lecturer_order_list()
  155. {
  156. $where = parent::getMore([
  157. ['lecturer_id', 0],
  158. ['page', 1],
  159. ['limit', 10],
  160. ['data', ''],
  161. ]);
  162. if (!$where['lecturer_id']) return JsonService::fail('缺少参数!');
  163. $lecturer= LecturerModel::get($where['lecturer_id']);
  164. if (!$lecturer) return JsonService::fail('讲师不存在!');
  165. $list=LecturerModel::lecturerOrderList($where);
  166. return JsonService::successlayui($list);
  167. }
  168. /**
  169. * 讲师盈利
  170. */
  171. public function getBadge()
  172. {
  173. $where = parent::postMore([
  174. ['lecturer_id', 0],
  175. ['data', ''],
  176. ]);
  177. if (!$where['lecturer_id']) return JsonService::fail('缺少参数!');
  178. $lecturer= LecturerModel::get($where['lecturer_id']);
  179. if (!$lecturer) return JsonService::fail('讲师不存在!');
  180. $list=LecturerModel::getBadge($where);
  181. return JsonService::successful($list);
  182. }
  183. }