model = new QuestionAnswerModel; } public function createWhere() { $data = $this->request->param(); $where = []; $whereOr = []; 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([])->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([])->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([])->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; $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 = [ ]; return res(1,'获取成功',$data); } public function doLike(int $id = 0) { $user_id = $this->userinfo->user_id; $info = $this->model->find($id); $likes = $info->likes; $dislikes = $info->dislikes; $likes[] = $user_id; $likes = array_unique($likes); if(($key = array_search($user_id,$dislikes))!==false){ unset($dislikes[$key]); } $info->likes = $likes; $info->dislikes = array_values($dislikes); $info->save(); return res(1,"点赞成功"); } public function doDislike(int $id = 0) { $user_id = $this->userinfo->user_id; $info = $this->model->find($id); $likes = $info->likes; $dislikes = $info->dislikes; $dislikes[] = $user_id; $dislikes = array_unique($dislikes); if(($key = array_search($user_id,$likes))!==false){ unset($likes[$key]); } $info->likes = array_values($likes); $info->dislikes = $dislikes; $info->save(); return res(1,"点踩成功"); } public function __call($name,$arguments) { return res(2,"方法{$name}不存在"); } }