123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- namespace app\admin\controller\base\question;
- use app\admin\controller\Base;
- use app\common\model\base\question\Question as QuestionModel;
- class Question extends Base
- {
- public function initialize()
- {
- parent::initialize();
- $this->model = new QuestionModel;
- }
- public function createWhere()
- {
- $data = $this->request->param();
- $where = [];
- $whereOr = [];
- if(!empty($data['type'])){
- $where[] = ['type_id','=',$data['type']];
- }
- if(!empty($data['keyword'])){
- $keyword = $data['keyword'];
- $where[] = ['content','LIKE',"%$keyword%"];
- }
- return ['where'=>$where,'whereOr'=>$whereOr];
- }
- public function getList(int $pageNo=0,int $pageSize=10)
- {
- $whereAry = $this->createWhere();
- if(!empty($pageNo)){
- $res = $this->model->where($whereAry['where'])->where(function($query)use($whereAry){
- $query->where($whereAry['whereOr']);
- })->with(['user','answers'=>function($query){$query->with(['user']);}])->paginate(['page'=>$pageNo,'list_rows'=>$pageSize]);
- return pageRes(1,'获取成功',$res->total(),$res->items());
- }else{
- $list = $this->model->where($whereAry['where'])->where(function($query)use($whereAry){
- $query->where($whereAry['whereOr']);
- })->with(['user','answers'=>function($query){$query->with(['user']);}])->select();
- return res(1,'获取成功',$list);
- }
- }
- /**
- * @title:选择器数据
- * @desc: 描述
- * @return {*}
- * @author: 系统开发
- * @method: POST
- * @Date: 2024-06-12 16:37:22
- */
- public function getTree($labelField='content')
- {
- $fields = ['id',$labelField];
- $where = [];
- $list = $this->model->where($where)->field($fields)->select();
- return res(1,"获取成功",$list);
- }
- /**
- * @title:查询信息
- * @desc: 描述
- * @param {int} {id} {} {信息ID}
- * @return {*}
- * @author: 系统开发
- * @method: POST
- * @Date: 2024-06-12 16:37:22
- */
- public function getInfo(int $id=0)
- {
- $info = $this->model->with(['answers'])->find($id);
- return res(1,'获取成功',$info);
- }
- /**
- * @title:新增/编辑信息
- * @desc: 描述
- * @param {int} {id} {} {主键ID,不传或传0表示新增,大于0表示修改}
- * @param {varchar} {content} {} {问题内容}
- * @param {int} {type_id} {} {问题类型}
- * @return {*}
- * @author: 系统开发
- * @method: POST
- * @Date: 2024-06-12 16:37:22
- */
- public function doEdit()
- {
- $data = $this->request->param();
- $data['uid'] = $this->userinfo->user_id;
- $data['status'] = 1;//默认待回复
- $res = $this->model->replace()->save($data);
- return res(1,'编辑成功');
- }
- /**
- * @title:删除信息
- * @desc: 描述
- * @param {int} {id} {} {信息ID}
- * @return {*}
- * @author: 系统开发
- * @method: POST
- * @Date: 2024-06-12 16:37:22
- */
- public function doDelete(int $id=0)
- {
- $info = $this->model->find($id);
- $info->delete();
- return res(1,'删除成功');
- }
- /**
- * @title:获取可选项
- * @desc: 描述
- * @return {*}
- * @author: 系统开发
- * @method: POST
- * @Date: 2023-07-06 16:37:22
- */
- public function getOptions()
- {
- $data = [
- 'statusList' => QuestionModel::statusList(),
- 'typeList' => QuestionModel::typeList(),
- ];
- return res(1,'获取成功',$data);
- }
- public function __call($name,$arguments)
- {
- return res(2,"方法{$name}不存在");
- }
- }
|