IndexController.php 8.2 KB
<?php

namespace App\Http\Controllers\Aside\Com;

use App\Enums\Common\Code;
use App\Enums\Common\Common;
use App\Helper\Translate;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\Manage\MenuLogic;
use App\Http\Logic\Bside\User\UserLoginLogic;
use App\Models\Inquiry\InquiryData;
use App\Models\Manage\Manage;
use App\Models\User\User;
use App\Models\WebSetting\WebLanguage;
use App\Services\HumanizeAiTextService;
use App\Services\WordAiService;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Http;

/**
 * Class IndexController
 * @package App\Http\Controllers\Aside
 * @author zbj
 * @date 2023/4/19
 */
class IndexController extends BaseController
{
    /**
     * 用户菜单
     * @param MenuLogic $logic
     * @return \Illuminate\Http\JsonResponse
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     * @author zbj
     * @date 2023/6/21
     */
    public function get_menu(MenuLogic $logic)
    {
        if($this->manage['gid'] == 0){ //超级管理员
            $menus = $logic->getAllMenu();
        }else{
            $menus = $logic->getMenuByGroupId($this->manage['gid']);
        }
        $this->response('success',Code::SUCCESS,$menus);
    }

    /**
     * @remark :修改密码
     * @name   :editPassword
     * @author :lyh
     * @method :post
     * @time   :2023/9/11 9:10
     */
    public function editPassword(){
        $this->request->validate([
//            'oldPassword'=>'required',
            'password' => 'required',
            'confirm'=>'required',
        ], [
//            'oldPassword.required' => '请输入原密码',
            'password.required' => '请输入新密码',
            'confirm.required' => '请再次输入新密码',
        ]);
        //查询员密码是否正确
        $managerModel = new Manage();
        $info = $managerModel->read(['id'=>$this->manage['id']]);
//        if(!Hash::check($this->param['oldPassword'], $info['password'])){
//            $this->response('原密码错误',Code::USER_REGISTER_ERROE);
//        }
        if($this->param['password'] != $this->param['confirm']){
            $this->response('两次密码不一致');
        }
        $rs = $managerModel->edit(['password'=>Hash::make($this->param['password'])],['id'=>$this->manage['id']]);
        if($rs === false){
            $this->response('系统错误',Code::SYSTEM_ERROR);
        }
        Cache::pull(Common::MANAGE_TOKEN . $info['token']);
        $this->response('success');
    }

    /**
     * @remark :同步询盘记录
     * @name   :sync_inquiry
     * @author :lyh
     * @method :post
     * @time   :2023/11/16 9:51
     */
    public function sync_inquiry(){
        $this->request->validate([
            'data' => 'required|array',
            'identifying'=>'required',
        ], [
            'data.required' => '自定义询盘数据不为空',
            'data.array' => '必须为数组',
            'identifying.required' => '唯一标识不为空',
        ]);
        $inquiryModel = new InquiryData();
        $rs = $inquiryModel->add($this->param);
        if($rs === false){
            $this->response('error',Code::SYSTEM_ERROR);
        }
        $this->response('success');
    }

    /**
     * 生成嵌套AICC企微的token
     * @author zbj
     * @date 2024/2/29
     */
    public function generateAiCCToken(){
        $data = [
            'id' => $this->manage['id'],
            'name' => $this->manage['name'],
            'timestamp' => time(),  // 接收到字符串解密出来以后需要 验证时间不超过30秒 超过时间视为无效授权
        ];
        $common = new \App\Helper\Common();
        $str = $common->encrypt($data);
        $this->response('success',Code::SUCCESS,['str'=>$str]);
    }

    /**
     * @remark :模拟登录返回token
     * @name   :getToken
     * @author :lyh
     * @method :post
     * @time   :2024/3/29 16:19
     */
    public function getAutoToken(){
        $this->request->validate([
            'project_id' => 'required',
        ], [
            'project_id.required' => '项目id不能为空',
        ]);
        //获取当前用户的管理员
        $userModel = new User();
        $userInfo = $userModel->read(['project_id'=>$this->param['project_id'],'role_id'=>0]);
        $userLoginLogicModel = new UserLoginLogic();
        $info = $userLoginLogicModel->autoAssembleParam($userInfo);
        //生成新token
        $token = md5(uniqid().'auto'.$info['id']);
        //存储缓存
        $info['token'] = $token;
        Cache::add($token,$info,12 * 3600);
        $languageModel = new WebLanguage();
        $languageInfo = $languageModel->read(['id'=>$info['main_lang_id']],['short','english','chinese']);
        $data = ['token'=>$token,'main_lang_id'=>$info['main_lang_id'],'language_info'=>$languageInfo,'project_seo_type'=>$info['project_seo_type']];
        $this->response('success',Code::SUCCESS,$data);
    }

    /**
     * @remark :获取动态密码
     * @name   :getDynamicPassword
     * @author :lyh
     * @method :post
     * @time   :2024/9/14 16:58
     */
    public function getDynamicPassword(){
        $dynamic_password = Cache::get('dynamic_password');
        if(empty($dynamic_password)){
            $dynamic_password = generateRandomString(16);
            Cache::put('dynamic_password',$dynamic_password,5 * 3600);
        }
        $this->response('success',Code::SUCCESS,['dynamic_password'=>$dynamic_password]);
    }

    /**
     * @remark :去ai痕迹
     * @name   :notAiHumanizer
     * @author :lyh
     * @method :post
     * @time   :2025/5/21 9:08
     */
    public function notAiHumanizer(){
        $this->request->validate([
            'text'=>'required',
            'lang'=>'required'
        ],[
            'text.required' => '文本text不能为空',
            'lang.required' => '语种不能为空',
        ]);
        if($this->param['lang'] == 0){
            $lang = Translate::translateSl($this->param['text']);
            $this->param['lang'] = $lang['texts']['sl'] ?? '';
        }
        if(empty($this->param['lang'])){
            $this->fail('未获取到语种');
        }
        $service = new HumanizeAiTextService();
        $data = $service->humanizer($this->param['text'],$this->param['lang']);
        $this->response('success', Code::SUCCESS, $data);
    }

    /**
     * @remark :去Ai痕迹
     * @name   :notWordAi
     * @author :lyh
     * @method :post
     * @time   :2025/11/19 17:57
     */
    public function notWordAiHumanizer()
    {
        $this->request->validate([
            'text'=>'required',
        ],[
            'text.required' => '文本text不能为空',
        ]);
        $wordAiService = new WordAiService();
        $data = $wordAiService->setApiAvoid($this->param['text']);
        $this->response('success', Code::SUCCESS, $data);
    }

    /**
     * @remark :翻译
     * @name   :stringTranslation
     * @author :lyh
     * @method :post
     * @time   :2025/5/21 9:31
     */
    public function stringTranslation(){
        $data = Translate::translateSl($this->param['text']);
        $this->response('success', Code::SUCCESS, $data);
    }

    /**
     * @remark :pr报告下载
     * @name   :prInfoDownload
     * @author :lyh
     * @method :post
     * @time   :2025/11/18 15:00
     */
    public function prInfoDownload()
    {
        $url = 'http://crawl.scraper.waimaoq.com/export/issuewire';
        $param = [
            'page' => $this->page,
            'pagesize' => $this->row,
            'token' => 'MT0CM7y4tdFTFTm',
            'pr_id' => $this->param['pr_id'],
            'release_time_start'=>$this->param['release_time_start'],
            'release_time_end'=>$this->param['release_time_end'],
        ];
        $param = array_filter($param);
        $response = Http::withHeaders(['Accept' => 'application/json',])->get($url, $param);
        if ($response->successful()) {
            $result = $response->json();
            $this->response('success', Code::SUCCESS, ['url' => $url, 'list' => $result, 'page' => $this->page, 'pagesize' => $this->row]);
        } else {
            $this->response('请求失败', Code::SYSTEM_ERROR, ['status_code' => $response->status(), 'error' => $response->body()]);
        }
    }
}