123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\admin\controller\special;
- use app\admin\controller\AuthController;
- use app\admin\model\special\Special;
- use app\admin\model\special\Lecturer as LecturerModel;
- use service\JsonService;
- use think\Url;
- /**
- * 讲师控制器
- */
- class Lecturer extends AuthController
- {
- /**
- * 讲师列表展示
- * @return
- * */
- public function index()
- {
- return $this->fetch();
- }
- /**
- * 讲师列表获取
- * @return
- * */
- public function lecturer_list()
- {
- $where = parent::getMore([
- ['page', 1],
- ['is_show', ''],
- ['limit', 20],
- ['title', ''],
- ]);
- return JsonService::successlayui(LecturerModel::getLecturerList($where));
- }
- /**添加/编辑
- * @param int $id
- * @return mixed|void
- * @throws \think\exception\DbException
- */
- public function create($id = 0)
- {
- if ($id) {
- $lecturer= LecturerModel::get($id);
- $lecturer['label'] =json_decode($lecturer['label']);
- $lecturer['introduction'] = htmlspecialchars_decode($lecturer['introduction']);
- if(!$lecturer) return JsonService::fail('讲师信息不存在!');
- }else{
- $lecturer=[];
- }
- $this->assign(['lecturer'=>json_encode($lecturer),'id'=>$id]);
- return $this->fetch();
- }
- /**
- * 添加和修改讲师
- * @param int $id 修改
- * @return JsonService
- * */
- public function save_lecturer($id = 0)
- {
- $data = parent::postMore([
- ['lecturer_name', ''],
- ['lecturer_head', ''],
- ['label', []],
- ['explain', ''],
- ['introduction', ''],
- ['sort', 0],
- ['is_show', 1],
- ]);
- if (!$data['lecturer_name']) return JsonService::fail('请输入讲师名称');
- if (!$data['lecturer_head']) return JsonService::fail('请输入讲师头像');
- if (!count($data['label'])) return JsonService::fail('请输入标签');
- if (!$data['explain']) return JsonService::fail('请编辑讲师说明');
- if (!$data['introduction']) return JsonService::fail('请编辑讲师介绍');
- $data['label']=json_encode($data['label']);
- $data['introduction']=htmlspecialchars($data['introduction']);
- if ($id) {
- LecturerModel::edit($data,$id);
- return JsonService::successful('修改成功');
- } else {
- $data['add_time'] = time();
- if (LecturerModel::set($data))
- return JsonService::successful('添加成功');
- else
- return JsonService::fail('添加失败');
- }
- }
- /**
- * 设置单个产品上架|下架
- * @param int $is_show 是否显示
- * @param int $id 修改的主键
- * @return JsonService
- */
- public function set_show($is_show = '', $id = '')
- {
- ($is_show == '' || $id == '') && JsonService::fail('缺少参数');
- $res = LecturerModel::where(['id' => $id])->update(['is_show' => (int)$is_show]);
- if ($res) {
- return JsonService::successful($is_show == 1 ? '显示成功' : '隐藏成功');
- } else {
- return JsonService::fail($is_show == 1 ? '显示失败' : '隐藏失败');
- }
- }
- /**
- * 快速编辑
- * @param string $field 字段名
- * @param int $id 修改的主键
- * @param string value 修改后的值
- * @return JsonService
- */
- public function set_value($field = '', $id = '', $value = '')
- {
- $field == '' || $id == '' || $value == '' && JsonService::fail('缺少参数');
- if (LecturerModel::where(['id' => $id])->update([$field => $value]))
- return JsonService::successful('保存成功');
- else
- return JsonService::fail('保存失败');
- }
- /**
- * 删除讲师
- * @param int $id 修改的主键
- * @return json
- * */
- public function delete($id = 0)
- {
- if (!$id) return JsonService::fail('缺少参数');
- if (LecturerModel::delLecturer($id))
- return JsonService::successful('删除成功');
- else
- return JsonService::fail(LecturerModel::getErrorInfo('删除失败'));
- }
- /**
- * 讲师课程订单
- */
- public function lecturer_order($id=0)
- {
- $this->assign([
- 'year' => getMonth('h'),
- 'lecturer_id' => $id,
- ]);
- return $this->fetch();
- }
- /**讲师课程购买记录
- * @throws \think\exception\DbException
- */
- public function lecturer_order_list()
- {
- $where = parent::getMore([
- ['lecturer_id', 0],
- ['page', 1],
- ['limit', 10],
- ['data', ''],
- ]);
- if (!$where['lecturer_id']) return JsonService::fail('缺少参数!');
- $lecturer= LecturerModel::get($where['lecturer_id']);
- if (!$lecturer) return JsonService::fail('讲师不存在!');
- $list=LecturerModel::lecturerOrderList($where);
- return JsonService::successlayui($list);
- }
- /**
- * 讲师盈利
- */
- public function getBadge()
- {
- $where = parent::postMore([
- ['lecturer_id', 0],
- ['data', ''],
- ]);
- if (!$where['lecturer_id']) return JsonService::fail('缺少参数!');
- $lecturer= LecturerModel::get($where['lecturer_id']);
- if (!$lecturer) return JsonService::fail('讲师不存在!');
- $list=LecturerModel::getBadge($where);
- return JsonService::successful($list);
- }
- }
|