model = new \app\model\Gallery(); } //查看和搜索列表 public function index(){ global $_W; // $where = $this->buildSearchParams(); $order = $this->buildOrder(); $where[] = ['uniacid','=',$_W['uniacid']]; $where[] = ['done','=',1]; $order = ['sort'=>'desc','id'=>'desc']; $data = $this->model->order($order)->where($where)->with(['userInfo','modelsInfo']); $paging = $this->request->param('paging', false); if ($paging) { $limit = $this->request->param('limit', Config::get('paginate.limit')); $data = $data->paginate($limit)->toArray(); $data['data'] = $this->getSelectedData($data['data']); } else { $data = $data->select()->toArray(); } return $this->success('数据获取成功', $data); } //查看详情 public function info() { $id = $this->request->param('id'); $info = $this->model->with(['img_file'])->find($id); return $this->success('获取成功', $info); } //设置排序 public function setSort() { $id = $this->request->post('id'); $fieldVal = $this->request->post('field_val'); $isRecycle = $this->request->post('is_recycle'); $update['sort'] = $fieldVal; try { if($isRecycle) { $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update); } else { $updateRes = $this->model->where('id', '=', $id)->update($update); } if ($updateRes) { return $this->success('操作成功'); } else if ($updateRes === 0) { return $this->success('未作修改'); } else { return $this->error('操作失败'); } } catch (\Exception $e) { return $this->error('数据库异常,操作失败'); } } //设置账号状态 public function setStatus() { $id = $this->request->post('id'); $fieldVal = $this->request->post('field_val'); $isRecycle = $this->request->post('is_recycle'); $update['status'] = $fieldVal; try { if($isRecycle) { $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update); } else { $updateRes = $this->model->where('id', '=', $id)->update($update); } if ($updateRes) { return $this->success('操作成功'); } else if ($updateRes === 0) { return $this->success('未作修改'); } else { return $this->error('操作失败'); } } catch (\Exception $e) { return $this->error('数据库异常,操作失败'); } } //设置账号状态 public function setIsOpen() { $id = $this->request->post('id'); $fieldVal = $this->request->post('field_val'); $isRecycle = $this->request->post('is_recycle'); $update['is_open'] = $fieldVal; try { if($isRecycle) { $updateRes = $this->model->onlyTrashed()->where('id', '=', $id)->update($update); } else { $updateRes = $this->model->where('id', '=', $id)->update($update); } if ($updateRes) { return $this->success('操作成功'); } else if ($updateRes === 0) { return $this->success('未作修改'); } else { return $this->error('操作失败'); } } catch (\Exception $e) { return $this->error('数据库异常,操作失败'); } } //初始化 public function init(){ global $_W; $where = ['uniacid' => $_W['uniacid']]; try{ if ($this->model->destroy($where)) { $list = [ ['uniacid' => $_W['uniacid'],'title'=>'你可以这样对AI说:','type'=>'sentence'] ]; $this->model->saveAll($list); return $this->success('初始化成功'); } else { return $this->error('数据删除失败'); } }catch (\Exception $e){ return $this->exceptionError($e); } // return $this->success('获取成功', $_W); } }