123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?php
- namespace app\controller\api;
- use laytp\controller\Api;
- use laytp\library\Random;
- use think\facade\Db;
- use app\service\ConfServiceFacade;
- use app\service\MemberServiceFacade;
- use app\service\api\UserServiceFacade;
- use app\service\BillServiceFacade;
- use app\service\api\ImageCensorServiceFacade;
- use app\service\api\MiniappServiceFacade;//微信小程序服务
- /**
- * AI相关
- * @ApiWeigh (90)
- */
- class Question extends Api
- {
- protected function _initialize()
- {
- $this->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);
- }
- }
- }
|