IndexController.php 5.0 KB
<?php

namespace App\Http\Controllers\Aside\Com;

use App\Enums\Common\Code;
use App\Enums\Common\Common;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\Manage\MenuLogic;
use App\Http\Logic\Bside\User\UserLoginLogic;
use App\Models\Domain\DomainInfo;
use App\Models\Inquiry\InquiryData;
use App\Models\Manage\Manage;
use App\Models\Product\Keyword;
use App\Models\Product\Product;
use App\Models\Project\Project;
use App\Models\RouteMap\RouteMap;
use App\Models\User\User;
use App\Models\WebSetting\WebLanguage;
use App\Services\ProjectServer;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Log;

/**
 * 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];
        $this->response('success',Code::SUCCESS,$data);
    }
}