model = new \app\model\Question(); } public $noNeedLogin = [ "list" ]; // 使用记录 public function list() { global $_GPC; $order = ['id' => 'desc']; $data = $this->model->where('uniacid','=',$_GPC['uniacid'])->order($order)->select()->toArray(); if(!$data){ return $this->error('数据获取失败'); } return $this->success('数据获取成功', $data); } public function add() { global $_GPC; $isValidity = 0; $post = $this->request->post(); $question = $this->request->post('question',''); $answer = $this->request->post('answer',''); $platform = $this->request->header('platform','H5'); $conf = ConfServiceFacade::groupGet('system.config', 0); $type = $this->request->post('type','gpt35'); $loginUserInfo = UserServiceFacade::getUserInfo(); if(!$question){ return $this->error('记录失败,请上传问题',2); } if(!$answer){ return $this->error('记录失败,请上传回答',2); } if($type =='gpt35'){ $coin = ConfServiceFacade::get('system.plan.unlock_gpt3',1); }else{ $coin = ConfServiceFacade::get('system.plan.lock_gpt4',0); } $checkMember = MemberServiceFacade::check($loginUserInfo,$type,$coin,$conf); if(isset($checkMember['status']) && !$checkMember['status']){ return $this->error($checkMember['msg'],2); } if($platform == 'wxMiniProgram'){ $check = MiniappServiceFacade::msgSecCheck($answer,$loginUserInfo['openid_miniapp']); if(!$check){ return $this->error('失败,文字内容安全检测不通过!'); } }elseif($platform == 'wxOfficialAccount' || $platform == 'H5'){ if(!empty($conf) && !empty($conf['is_h5_filter']) && $conf['is_h5_filter'] == 1){ $check = ImageCensorServiceFacade::textCensorUserDefined($answer); if(!empty($check['conclusion']) && $check['conclusion'] == '不合规' ){ return $this->error('失败,文字内容安全检测不通过!'); } } } if($coin >0){ $checkMember = MemberServiceFacade::cash($loginUserInfo,$type,$coin,$conf); if(isset($checkMember['status']) && !$checkMember['status']){ return $this->error($checkMember['msg'],2); } } $a = $this->model->save(['uid'=>$loginUserInfo['id'],'question'=>$question,'answer'=>$answer,'uniacid'=>$_GPC['uniacid'] ]); if(!$a){ return $this->error('数据保存失败',2); } return $this->success('数据获取成功', $a); } // 使用记录 public function my() { global $_GPC; $loginUserInfo = UserServiceFacade::getUserInfo(); $order = ['id' => 'desc']; $where = ['uid' => $loginUserInfo['id'],'uniacid'=>$_GPC['uniacid']]; $limit = $this->request->param('limit', 10); $data = $this->model->order($order)->where($where)->paginate($limit)->toArray(); if(!$data){ return $this->error('数据获取失败'); } return $this->success('数据获取成功', $data); } public function del(){ global $_GPC; $loginUserInfo = UserServiceFacade::getUserInfo(); $id = $this->request->post('id'); if (!$id) { return $this->error('参数id不能为空',2); } $jobUid = $this->model->where('id',$id)->value('uid'); if($jobUid != $loginUserInfo['id']){ return $this->error('您没有删除的权限'); } try{ $delRes = $this->model->destroy($id); if (!$delRes) { return $this->error('删除失败'); } return $this->success('删除成功'); }catch (\Exception $e){ return $this->exceptionError($e); } } }