作者 李美松

Merge remote-tracking branch 'origin/develop' into lms

# Conflicts:
#	composer.lock
正在显示 42 个修改的文件 包含 4357 行增加321 行删除

要显示太多修改。

为保证性能只显示 42 of 42+ 个文件。

APP_NAME=Laravel
APP_ENV=test
APP_KEY=base64:+ouoKlz2sFDOisnROMRpxT/u9xkZJVrXlzP4cfTqPow=
APP_DEBUG=false
APP_URL=http://localhost
LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=globalso
DB_USERNAME=debian-sys-maint
DB_PASSWORD=WtujxV73XIclQet0
BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DRIVER=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
MEMCACHED_HOST=127.0.0.1
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
... ... @@ -3,6 +3,7 @@
/public/storage
/storage
/vendor
/uploads
.env
.env.backup
.phpunit.result.cache
... ... @@ -15,3 +16,5 @@ yarn-error.log
/.vscode
composer.lock
app/Console/Commands/Test/Demo.php
/public/upload
/public/runtime
... ...
<?php
namespace App\Console\Commands\AyrShare;
use App\Helper\AyrShare as AyrShareHelper;
use App\Models\AyrShare\AyrShare as AyrShareModel;
use Illuminate\Console\Command;
class ShareConfig extends Command
{
public $error = 0;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'share_config';
/**
* The console command description.
*
* @var string
*/
protected $description = '更新用户Ayr_share配置';
/**
* @name :(定时执行更新用户配置)handle
* @author :lyh
* @method :post
* @time :2023/5/12 14:48
*/
public function handle()
{
$ayrShareModel = new AyrShareModel();
//更新用户配置
$lists = $ayrShareModel->lists($this->map,$this->page,$this->row,'id',['id','profile_key','bind_plat_from']);
foreach ($lists['list'] as $k => $v){
if(empty($v['profile_key'])){
continue;
}
//获取当前用户配置
$ayrShareHelper = new AyrShareHelper();
$share_info = $ayrShareHelper->get_profiles_users($v['profile_key']);
if(!isset($share_info['activeSocialAccounts'])){
$ayrShareModel->edit(['bind_plat_from'=>''],['id'=>$v['id']]);
continue;
}
$str = json_encode($share_info['activeSocialAccounts']);
if($str != $v['bind_plat_from']){
$rs = $ayrShareModel->edit(['bind_plat_from'=>$str],['id'=>$v['id']]);
if($rs === false){
$this->error++;
}
}
}
echo $this->error;
}
}
... ...
<?php
namespace App\Console\Commands\AyrShare;
use App\Helper\AyrShare as AyrShareHelper;
use App\Models\AyrShare\AyrRelease as AyrReleaseModel;
use Carbon\Carbon;
use App\Models\AyrShare\AyrShare as AyrShareModel;
use Illuminate\Console\Command;
class ShareUser extends Command
{
public $error = 0;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'share_user';
/**
* The console command description.
*
* @var string
*/
protected $description = '用户一周内无记录清除Ayr_share';
/**
* @name :(定时执行)handle
* @author :lyh
* @method :post
* @time :2023/5/12 14:48
*/
public function handle()
{
echo $this->user_operator_record();
}
/**
* @name : 检测用户是否无操作记录
* @author :lyh
* @method :post
* @time :2023/5/12 14:55
*/
protected function user_operator_record(){
//获取所有ayr_share用户
$ayr_share_model = new AyrShareModel();
$ayr_share_list = $ayr_share_model->list();
foreach ($ayr_share_list as $k => $v){
//查询当前用户是否有未推送的博文
$ayr_release = new AyrReleaseModel();
$release_info = $ayr_release->read(['idempotency_key'=>['>',date('Y-m-d H:i:s',time())],'share_id'=>$v['id']]);
//有推文时,直接跳出循环
if($release_info !== false){
continue;
}
//查看用户是否在一周内有发送博客
$start_at = Carbon::now()->modify('-7 days')->toDateString();
$end_at = Carbon::now()->toDateString();
$release_info = $ayr_release->read(['created_at'=>['between',[$start_at,$end_at]]]);
//有发送博文,则跳出循环
if($release_info == false){
continue;
}
//删除用户第三方配置
$ayr_share_helper = new AyrShareHelper();
$data_profiles = [
'title'=>$v['title'],
'profileKey'=>$v['profile_key']
];
$res = $ayr_share_helper->deleted_profiles($data_profiles);
if($res['status'] == 'fail'){
$this->error++;
continue;
}
//更新数据库
$data = [
'title'=>null,
'bind_plat_from'=>null,
'profile_key'=>null,
'ref_id'=>null,
];
$res = $ayr_share_model->edit($data,['id'=>$v['id']]);
if($res == false){
$this->error++;
}
}
return $this->error;
}
}
... ...
<?php
namespace App\Console\Commands;
use App\Models\Devops\DevopsTaskLog;
use App\Models\Project\Project;
use Illuminate\Console\Command;
use App\Models\Devops\DevopsTask as DevopsTaskModel;
/**
* Class DevopsTask
* @package App\Console\Commands
* @author zbj
* @date 2023/4/25
*/
class DevopsTask extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'devops_task';
/**
* The console command description.
*
* @var string
*/
protected $description = '运维任务执行';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* @return bool
*/
public function handle()
{
while (true){
$tasks = DevopsTaskModel::where('status', DevopsTaskModel::STATUS_PENDING)->get();
foreach ($tasks as $task){
echo "Start task " . $task->id . PHP_EOL;
if($task->type == DevopsTaskModel::TYPE_MYSQL){
$this->updateTable($task);
}
echo "End task " . $task->id . PHP_EOL;
}
sleep(10);
}
}
public function updateTable($task){
$projects = Project::all();
foreach ($projects as $project){
echo "project " . $project->id;
$log = DevopsTaskLog::addLog($task->id, $project->id);
if($log->status == DevopsTaskModel::STATUS_ACTIVE){
continue;
}
if(!$project->mysqlConfig){
$log->status = DevopsTaskLog::STATUS_ERROR;
$log->remark = '未配置数据库';
$log->save();
continue;
}
//DB类是单例模式,生命周期内修改配置不会生效
$conn = new \mysqli(
$project->mysqlConfig->host,
$project->mysqlConfig->user,
$project->mysqlConfig->password,
$project->databaseName(),
$project->mysqlConfig->port,
);
$res = $conn->query($task->sql);
$log->status = $res ? DevopsTaskLog::STATUS_ACTIVE : DevopsTaskLog::STATUS_ERROR;
$log->remark = $res ? '成功' : 'sql执行失败';
$log->save();
echo '-->' . $log->remark . PHP_EOL;
}
$task->status = DevopsTaskModel::STATUS_ACTIVE;
$task->save();
}
}
... ...
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2023/4/12
* Time: 15:33
*/
namespace App\Console\Commands;
use App\Models\Project;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
/**
* Class ProjectInitDatabase
* @package App\Console\Commands
*/
class ProjectInit extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'project:init';
/**
* The console command description.
*
* @var string
*/
protected $description = '项目数据库初始化';
protected $connect = null;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* @return bool
*/
public function handle()
{
#TODO 通过项目ID获取项目部署数据库配置, 创建数据库, 同步数据表
$project_id = 102;
$project = Project::getProjectById($project_id);
if (empty($project) || empty($project->mysqlConfig()))
return true;
$this->initDatabase($project);
return true;
}
/**
* @param Project $project
* @return bool
*/
public function initDatabase($project)
{
$create_flag = $this->createDatabase($project);
if (!$create_flag) {
// 创建数据库失败 添加通知以及再次处理
}
// 设置 database.connections.custom_mysql 数据
ProjectServer::useProject($project->id);
// TODO 创建对应库 初始化数据表
$this->initTable();
return true;
}
/**
* @return bool
*/
public function initTable()
{
$database_name = DB::connection('custom_tmp_mysql')->getDatabaseName();
$table = Schema::connection('custom_tmp_mysql')->getAllTables();
$table = array_column($table, 'Tables_in_' . $database_name);
foreach ($table as $v) {
$has_table = Schema::connection('custom_mysql')->hasTable($v);
if ($has_table)
continue;
$connection = DB::connection('custom_tmp_mysql');
$sql = $connection->getDoctrineSchemaManager()
->getDatabasePlatform()
->getCreateTableSQL($connection->getDoctrineSchemaManager()->listTableDetails($v));
DB::connection('custom_mysql')->select($sql[0]);
}
return true;
}
/**
* 创建数据库
* 链接mysql 查询数据库是否存在 创建数据库
* @param Project $project
* @return bool|\mysqli_result|null
*/
public function createDatabase($project)
{
# 该方法需要:composer require parity-bit/laravel-db-commands
// $result = Artisan::call('db:create', [
// '--database' => $database_name,
// ]);
//
// return $result;
if ($this->connect)
return $this->connect;
//连接到 MySQL 服务器
$servername = $project->mysqlConfig()->host;
$username = $project->mysqlConfig()->user;
$password = $project->mysqlConfig()->password;
$conn = new \mysqli($servername, $username, $password);
//检查连接是否成功
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}
$this->connect = $conn;
// $result = $conn->query('SHOW DATABASES LIKE \'' . $database_name . '\';');
// if ($result)
// return true;
$result = $conn->query('CREATE DATABASE ' . $project->databaseName() . ';');
return $result;
}
}
<?php
namespace App\Console\Commands\RankData;
use Illuminate\Console\Command;
/**
* Class BaseCommands
* @package App\Console\Commands\RankData
* @author zbj
* @date 2023/5/11
*/
abstract class BaseCommands extends Command
{
/**
* @author zbj
* @date 2023/5/11
*/
public function handle()
{
$try = 3;
do{
$try--;
if($try == 0){
break;
}
$error = 0;
try {
if(!$this->do()){
$error = 1;
}
}catch (\Exception $e){
errorLog($this->signature . ' error', [], $e);
$error = 1;
}
if($error){
echo 'error';
}
$error && sleep(60);
}while($error);
}
abstract function do();
}
... ...
<?php
namespace App\Console\Commands\RankData;
use App\Helper\Arr;
use App\Helper\SemrushApi;
use App\Models\RankData\ExternalLinks as ExternalLinksModel;
use App\Models\Project\DeployOptimize;
/**
* Class ExternalLinks
* @package App\Console\Commands
* @author zbj
* @date 2023/5/9
*/
class ExternalLinks extends BaseCommands
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'rank_data_external_links';
/**
* The console command description.
*
* @var string
*/
protected $description = '排名数据-外链数据';
/**
* @author zbj
* @date 2023/5/6
*/
public function do()
{
$error = 0;
$semrushApi = new SemrushApi();
//有排名api编号的项目
$list = DeployOptimize::where('api_no', '>', 0)->pluck('domain', 'project_id')->toArray();
foreach ($list as $project_id => $domain) {
if(!$domain){
continue;
}
$model = ExternalLinksModel::where('project_id', $project_id)->first();
if ($model && $model->updated_date == getThisWeekStarDate()) {
continue;
}
if (!$model) {
$model = new ExternalLinksModel();
}
//外链数据
$res = $semrushApi->backlinks_overview($domain);
if (!$res) {
$error++;
continue;
}
$data = $this->_data($project_id, $res['total']);
$model->project_id = $project_id;
$model->total = $data['total'];
$model->data = $data['data'];
$model->updated_date = date('Y-m-d');
$model->save();
}
return !$error;
}
/**
* 构造chat数据
* @param $project_id
* @param $total
* @return array|mixed
* @author zbj
* @date 2023/5/10
*/
public function _data($project_id, $total)
{
// //外链数
$data['total'] = intval($total);
$model = ExternalLinksModel::where('project_id', $project_id)->first();
if ($model) {
//特殊处理的外链数
// $data['total'] = ($total > $model->total) ? intval($total) : $model->total; //特殊处理的
//chat数据
$chat_data = Arr::s2a($model['data']);
if (empty($chat_data[date('Y-m-d')])) {
array_shift($chat_data);
}
} else {
//chat数据
for ($i = 1; $i < 12; $i++) {
$date = date("Y-m-d", strtotime(-7 * $i . 'days'));
$chat_data[$date] = ceil($total - ($total * rand(5, 10) / 100));
}
}
$chat_data[date('Y-m-d')] = $data['total'];
$data['data'] = $chat_data;
return $data;
}
}
... ...
<?php
namespace App\Console\Commands\RankData;
use App\Helper\QuanqiusouApi;
use App\Models\Project\DeployOptimize;
use App\Models\RankData\IndexedPages as IndexedPagesModel;
/**
* Class IndexedPages
* @package App\Console\Commands
* @author zbj
* @date 2023/5/11
*/
class IndexedPages extends BaseCommands
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'rank_data_indexed_pages';
/**
* The console command description.
*
* @var string
*/
protected $description = '排名数据-页面收录数';
/**
* @throws \Exception
* @author zbj
* @date 2023/5/11
*/
public function do(){
$error = 0;
$api = new QuanqiusouApi();
//有排名api编号的项目
$list = DeployOptimize::where('api_no', '>', 0)->pluck('api_no', 'project_id')->toArray();
foreach ($list as $project_id => $api_no) {
$model = IndexedPagesModel::where('project_id', $project_id)->first();
if($model && $model->updated_date == getThisWeekStarDate()){
continue;
}
if(!$model){
$model = new IndexedPagesModel();
}
$res = $api->getSiteResPer($api_no);
if(!$res){
$error++;
continue;
}
$model->project_id = $project_id;
$model->data = $res['data'];
$model->updated_date = date('Y-m-d');
$model->save();
}
return !$error;
}
}
... ...
<?php
namespace App\Console\Commands\RankData;
use App\Helper\Arr;
use App\Helper\QuanqiusouApi;
use App\Models\Project\DeployBuild;
use App\Models\Project\DeployOptimize;
use App\Models\RankData\RankData as GoogleRankModel;
/**
* Class GoogleRank
* @package App\Console\Commands
* @author zbj
* @date 2023/5/6
*/
class RankData extends BaseCommands
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'rank_data';
/**
* The console command description.
*
* @var string
*/
protected $description = '谷歌排名数据';
/**
* @author zbj
* @date 2023/5/6
*/
public function do()
{
$error = 0;
$api = new QuanqiusouApi();
//有排名api编号的项目
$list = DeployOptimize::where('api_no', '>' , 0)->select('api_no','minor_languages','project_id')->get();
//当日所有站点谷歌收录数据
$site_res = $api->getSiteRes();
if(!$site_res){
return false;
}
foreach ($list as $item){
$model = GoogleRankModel::where('project_id', $item['project_id'])->where('lang', '')->first();
if (!$model || $model->updated_date != date('Y-m-d')) {
$res = $api->getGoogleRank($item['api_no']);
if(!$res){
$error++;
continue;
}
//收录数
$indexed_pages_num = $site_res[$item['api_no']];
$this->save_rank($item['project_id'], $res, $indexed_pages_num);
}
//有小语种的
$lang_list = $api->getLangList();
if(!empty($lang_list[$item['api_no']])){
$model = GoogleRankModel::where('project_id', $item['project_id'])->where('lang', '<>', '')->first();
if (!$model || $model->updated_date != date('Y-m-d')) {
$res = $api->getGoogleRank($item['api_no'], 1);
if(!$res){
$error++;
continue;
}
$data = [];
//不同的小语种取出来
foreach ($res as $keyword => $v){
$data[Arr::last($v)['lang']][$keyword] = $v;
}
foreach ($data as $lang => $rank){
$this->save_rank($item['project_id'], $rank, 0, $lang);
}
}
}
}
return !$error;
}
/**
* @param $project_id
* @param int $indexed_pages_num
* @param $data
* @param string $lang
* @author zbj
* @date 2023/5/8
*/
public function save_rank($project_id, $data, int $indexed_pages_num = 0, string $lang = ''){
$without_project_ids = []; //不用处理排名的项目
$first_num = $first_page_num = $first_three_pages_num = $first_five_pages_num = $first_ten_pages_num = 0;
if(!$lang){
foreach ($data as &$ranks){
ksort($ranks);
foreach ($ranks as &$rank){
//处理排名
if(!in_array($project_id, $without_project_ids)){
if($rank['position'] >= 10){
$rank['position'] -= 5;
}
//todo 需要特殊处理排名的项目
}
}
$last = Arr::last($ranks);
//第一名
if($last['position'] == 1){
$first_num ++;
}
//排名第一页
if($last['position'] > 0 && $last['position'] <= 10){
$first_page_num ++;
}
//排名前三页
if($last['position'] > 0 && $last['position'] <= 30){
$first_three_pages_num ++;
}
//排名前五页
if($last['position'] > 0 && $last['position'] <= 50){
$first_five_pages_num ++;
}
//排名前十页
if($last['position'] > 0 && $last['position'] <= 100){
$first_ten_pages_num ++;
}
}
}
$where = [
'project_id' => $project_id,
'lang' => $lang
];
$model = GoogleRankModel::where($where)->first();
if(!$model){
$model = new GoogleRankModel();
}
//关键词达标天数
if($model->updated_date != date('Y-m-d')){
//保证关键词数
$keyword_num = DeployBuild::where('project_id', $project_id)->value('keyword_num');
if($first_page_num >= $keyword_num){
$model->compliance_day = $model->compliance_day + 1;
}
}
$model->project_id = $project_id;
$model->first_num = $first_num;
$model->first_page_num = $first_page_num;
$model->first_three_pages_num = $first_three_pages_num;
$model->first_five_pages_num = $first_five_pages_num;
$model->first_ten_pages_num = $first_ten_pages_num;
$model->indexed_pages_num = $indexed_pages_num;
$model->lang = $lang;
$model->data = $data;
$model->updated_date = date('Y-m-d');
$model->save();
}
}
... ...
<?php
namespace App\Console\Commands\RankData;
use App\Helper\Arr;
use App\Helper\QuanqiusouApi;
use App\Models\Project\DeployOptimize;
use App\Models\RankData\RankWeek as RankWeekModel;
/**
* Class WeekRank
* @package App\Console\Commands
* @author zbj
* @date 2023/5/11
*/
class RankWeek extends BaseCommands
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'rank_data_week';
/**
* The console command description.
*
* @var string
*/
protected $description = '排名数据-每周排名数据';
/**
* @author zbj
* @date 2023/5/6
*/
public function do()
{
$error = 0;
//获取每周排名数据
$api = new QuanqiusouApi();
$res = $api->getGoogleRankWeek();
if (!$res) {
return false;
}
$res = Arr::s2a($res);
//有排名api编号的项目
$list = DeployOptimize::where('api_no', '>', 0)->pluck('api_no', 'project_id')->toArray();
foreach ($list as $project_id => $api_no) {
$rank_week = RankWeekModel::where('project_id', $project_id)->first();
if ($rank_week && $rank_week->updated_date == getThisWeekStarDate()) {
//本周数据已更新
continue;
}
if (!$rank_week) {
$rank_week = new RankWeekModel();
}
$rank_week->project_id = $project_id;
$rank_week->data = $res['data'][$api_no];
$rank_week->date = $res['date'];
$rank_week->updated_date = date('Y-m-d');
$rank_week->save();
}
return !$error;
}
}
... ...
<?php
namespace App\Console\Commands\RankData;
use App\Helper\SemrushApi;
use App\Models\RankData\RecommDomain as RecommDomainModel;
use App\Models\Project\DeployOptimize;
/**
* Class RecommDomain
* @package App\Console\Commands
* @author zbj
* @date 2023/5/9
*/
class RecommDomain extends BaseCommands
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'rank_data_recomm_domain';
/**
* The console command description.
*
* @var string
*/
protected $description = '排名数据-外链引荐域名数据';
/**
* @author zbj
* @date 2023/5/6
*/
public function do()
{
$error = 0;
$semrushApi = new SemrushApi();
//有排名api编号的项目
$list = DeployOptimize::where('api_no', '>', 0)->pluck('domain', 'project_id')->toArray();
foreach ($list as $project_id => $domain) {
if(!$domain){
continue;
}
$model = RecommDomainModel::where('project_id', $project_id)->first();
if ($model && $model->updated_date == getThisWeekStarDate()) {
continue;
}
if (!$model) {
$model = new RecommDomainModel();
}
//外链引荐域名
$data = $semrushApi->backlinks_refdomains($domain);
if (!$data) {
$error++;
continue;
}
$model->project_id = $project_id;
$model->data = $data;
$model->updated_date = date('Y-m-d');
$model->save();
}
return !$error;
}
}
... ...
<?php
namespace App\Console\Commands\RankData;
use App\Helper\Arr;
use App\Helper\GoogleSpeedApi;
use App\Models\Project\DeployOptimize;
use App\Models\RankData\Speed as GoogleSpeedModel;
/**
* Class GoogleSpeed
* @package App\Console\Commands
* @author zbj
* @date 2023/5/10
*/
class Speed extends BaseCommands
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'rank_data_speed';
/**
* The console command description.
*
* @var string
*/
protected $description = '排名数据-测速数据';
/**
* @author zbj
* @date 2023/5/10
*/
public function do()
{
$error = 0;
$googleSpeedApi = new GoogleSpeedApi();
//有排名api编号的项目
$list = DeployOptimize::where('api_no', '>', 0)->pluck('domain', 'project_id')->toArray();
foreach ($list as $project_id => $domain) {
$model = GoogleSpeedModel::where('project_id', $project_id)->first();
if ($model && $model->updated_date == getThisWeekStarDate()) {
//今周已更新 跳过
continue;
}
$res = $googleSpeedApi->run($domain);
if (!$res) {
$error++;
}
if (!$model) {
$model = new GoogleSpeedModel;
}
$model->project_id = $project_id;
$model->data = $res;
$model->updated_date = date('Y-m-d');
$model->save();
}
return !$error;
}
}
... ...
... ... @@ -7,6 +7,8 @@
*/
namespace App\Console\Commands\Test;
use App\Models\Devops\ServerConfig;
use App\Services\ProjectServer;
use GuzzleHttp\Client;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
... ... @@ -42,10 +44,11 @@ class Demo extends Command
*/
public function handle()
{
$sql = 'CREATE DATABASE database_name;';
$results = DB::select($sql);
dd($results);
return true;
preg_match_all("/\@include\(\"([a-z0-9_]+)\"\)/i",'
@include("asdf")@include("")@include("asdtrw2erf")
',$include);
print_r($include);
}
public function printMessage()
... ...
<?php
namespace App\Console\Commands\Test;
use App\Helper\Arr;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class DiffDb extends Command
{
protected $signature = 'project:diff_db';
/**
* The console command description.
*
* @var string
*/
protected $description = '对比数据库结构';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
public function handle()
{
$custom_mysql_config = [
'database.connections.custom_mysql.host' => '127.0.0.1',
'database.connections.custom_mysql.port' => '3306',
'database.connections.custom_mysql.database' => 'globalso_project_1',
'database.connections.custom_mysql.username' => 'root',
'database.connections.custom_mysql.password' => 'root',
];
config($custom_mysql_config);
$this->output->writeln("开始进行数据表对比!");
$tablesSource = DB::select("show tables");
$tablesRemote = DB::connection('custom_mysql')->select("show tables");
$tablesSource = array_map(function($item){
return Arr::first($item);
}, $tablesSource);
$tablesRemote = array_map(function($item){
return Arr::first($item);
}, $tablesRemote);
$tablesNotInRemote = [];
$tablesInRemote = [];
foreach ($tablesSource as $t) {
if (!in_array($t, $tablesRemote)) {
$tablesNotInRemote[] = $t;
} else {
$tablesInRemote[] = $t;
}
}
//print reports
echo "本地存在,但是不在custom_mysql中的表:" . PHP_EOL;
echo ">>>>>>==================================<<<<<<" . PHP_EOL;
foreach ($tablesNotInRemote as $t) {
echo $t . PHP_EOL;
}
echo ">>>>>>==================================<<<<<<" . PHP_EOL . PHP_EOL . PHP_EOL;
echo "本地与custom_mysql结构不一致的表:" . PHP_EOL;
echo ">>>>>>==================================<<<<<<" . PHP_EOL;
$only127 = $onlyRemote = $modify127 = [];
foreach ($tablesInRemote as $t) {
$columns127 = DB::select("show columns from `{$t}`");
foreach ($columns127 as &$item){
$item = get_object_vars($item);
}
$columnsRemote = DB::connection('custom_mysql')->select("show columns from `{$t}`");
foreach ($columnsRemote as &$item){
$item = get_object_vars($item);
}
$fields127 = $fieldsRemote = [];
foreach ($columns127 as $v) {
$fields127[$v['Field']] = $v;
}
foreach ($columnsRemote as $v) {
$fieldsRemote[$v['Field']] = $v;
}
foreach ($fields127 as $f => $column) {
if (!isset($fieldsRemote[$f])) {
$only127[$t][] = $f;
} else if ($column !== $fieldsRemote[$f]) {
dump($column);
dump($fieldsRemote[$f]);
$modify127[$t][] = $f;
}
}
foreach ($fieldsRemote as $f => $column) {
if (!isset($fields127[$f])) {
$onlyRemote[$t][] = $f;
}
}
}
if (!empty($only127)) {
echo "只本地存在:" . PHP_EOL;
foreach ($only127 as $t => $columns) {
echo $t . ":";
foreach ($columns as $field) {
echo $field . "\t";
}
echo PHP_EOL;
}
}
if (!empty($onlyRemote)) {
echo "只custom_mysql存在:" . PHP_EOL;
foreach ($onlyRemote as $t => $columns) {
echo $t . ":";
foreach ($columns as $field) {
echo $field . "\t";
}
echo PHP_EOL;
}
}
if (!empty($modify127)) {
echo "本地更新:" . PHP_EOL;
foreach ($modify127 as $t => $columns) {
echo $t . ":";
foreach ($columns as $field) {
echo $field . "\t";
}
echo PHP_EOL;
}
}
echo ">>>>>>==================================<<<<<<" . PHP_EOL . PHP_EOL . PHP_EOL;
}
}
... ...
... ... @@ -16,6 +16,13 @@ class Kernel extends ConsoleKernel
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')->hourly();
$schedule->command('rank_data')->dailyAt('01:00')->withoutOverlapping(1); // 排名数据,每天凌晨执行一次
$schedule->command('rank_data_speed')->weeklyOn(1, '01:00')->withoutOverlapping(1); // 排名数据-测速数据,每周一凌晨执行一次
$schedule->command('rank_data_external_links')->weeklyOn(1, '01:00')->withoutOverlapping(1); // 排名数据-外链,每周一凌晨执行一次
$schedule->command('rank_data_indexed_pages')->weeklyOn(1, '01:00')->withoutOverlapping(1); // 排名数据-页面收录,每周一凌晨执行一次
$schedule->command('rank_data_recomm_domain')->weeklyOn(1, '01:00')->withoutOverlapping(1); // 排名数据-引荐域名,每周一凌晨执行一次
$schedule->command('rank_data_week')->weeklyOn(1, '01:00')->withoutOverlapping(1); // 排名数据,每周一凌晨执行一次
$schedule->command('share_user')->dailyAt('01:00')->withoutOverlapping(1); // 清除用户ayr_share数据,每天凌晨1点执行一次
}
/**
... ...
... ... @@ -18,4 +18,5 @@ final class Common extends Enum
//端
const A='a';
const B='b';
const C='c';
}
... ...
<?php
namespace App\Exceptions;
use App\Enums\Common\Code;
use Exception;
use Throwable;
/**
* @notes: C端接口统一错误格式
* Class CsideGlobalException
* @package App\Exceptions
*/
class CsideGlobalException extends Exception
{
public function __construct($code = 0, $message = "", Throwable $previous = null)
{
$this->code = $code;
$this->message = $message;
if (empty($this->message)) {
$this->message = Code::fromValue($code)->description;
}
}
}
... ...
... ... @@ -3,13 +3,13 @@
namespace App\Exceptions;
use App\Enums\Common\Code;
use App\Enums\Common\Common;
use App\Services\DingService;
use App\Utils\EncryptUtils;
use App\Utils\LogUtils;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Route;
use Illuminate\Validation\ValidationException;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
... ... @@ -59,7 +59,6 @@ class Handler extends ExceptionHandler
*/
public function report(Throwable $exception)
{
//日志记录
$exceptionMessage = "错误CODE:" . $exception->getCode() .
"-----错误message:" . $exception->getMessage() .
... ... @@ -73,6 +72,10 @@ class Handler extends ExceptionHandler
elseif($exception instanceof BsideGlobalException) {
LogUtils::error("BsideGlobalException", [], $exceptionMessage);
}
//C端错误
elseif($exception instanceof CsideGlobalException) {
LogUtils::error("CsideGlobalException", [], $exceptionMessage);
}
//验证错误(非手动抛出)
elseif ($exception instanceof ValidationException) {
LogUtils::error("参数验证失败", [], $exceptionMessage);
... ... @@ -111,31 +114,28 @@ class Handler extends ExceptionHandler
$code = $exception->getCode();
}elseif ($exception instanceof BsideGlobalException) {
$code = $exception->getCode();
}elseif ($exception instanceof CsideGlobalException) {
$code = $exception->getCode();
} elseif ($exception instanceof ValidationException) {
$code = Code::USER_PARAMS_ERROE();
$message = Arr::first(Arr::first($exception->errors()));
$message = $code->description = Arr::first(Arr::first($exception->errors()));
} elseif ($exception instanceof NotFoundHttpException || $exception instanceof MethodNotAllowedHttpException) {
return response('404 Not Found', 404);
} else {
$code = Code::SYSTEM_ERROR();
}
//钉钉通知错误信息
if (in_array(config('app.env'), ['test', 'production']) && (in_array(substr($code, 0, 1), ['B', 'C']))) {
$exceptionMessage = "路由:" . Route::current()->uri .
"-----错误CODE:" . $exception->getCode() .
"-----错误message:" . $exception->getMessage() .
'------错误文件:' . $exception->getFile() . '-------错误行数:' .
$exception->getLine();
(new DingService())->handle(['keyword' => "ERROR", 'msg' => config('app.env') . '环境报错:' . $exceptionMessage, 'isAtAll' => false]);
}
//开启debug 错误原样输出
$debub = config('app.debug');
$message = $debub ? $message : ($code->description ?? $message);
$response = [
'code' => $code,
'message' => $message
];
// 调试模式
if(env('app_debug')){
$response['trace'] = $exception->getTrace();
}
//加密返回
if (config('app.params_encrypt')) {
$k = config('app.params_encrypt_key');
... ...
<?php
namespace App\Files;
use Illuminate\Http\Request;
class Image
{
protected $request = [];
public function __construct(Request $request)
{
$this->request = $request;
}
/**
* @name :上传图片
* @return void
* @author :liyuhang
* @method
*/
public function uploads(){
$url = './uploads/images/';
$param = $this->request->post();
if($this->request->hasFile('image') && $this->request->file('image')->isValid()){
$filename = date('ymdHis').rand(10000,99999).$this->request->file('image');
$this->request->file('image')->move('./uploads/images/',$filename);
}else{
return false;
}
return $url.$filename;
}
}
... ... @@ -3,6 +3,8 @@
namespace App\Helper;
use Illuminate\Support\Collection;
/**
* 数组类函数
* Class Arrays
... ... @@ -125,4 +127,89 @@ class Arr extends \Illuminate\Support\Arr
return $signle ? $rows[0] : $rows;
}
/**
* 数组转字符串
* @param $arr
* @return string
* @author zbj
* @date 2023/4/17
*/
public static function a2s($arr): string
{
return json_encode($arr, JSON_UNESCAPED_UNICODE);
}
/**
* 字符串转数组
* @param $str
* @return array|mixed
* @author zbj
* @date 2023/4/17
*/
public static function s2a($str)
{
if (is_array($str)) {
return $str;
}
return is_object($str) ? (array)$str : json_decode($str, true);
}
/**
* 数组转set形式字符串
* @param $arr
* @param string $format
* @return string
* @author zbj
* @date 2023/4/17
*/
public static function arrToSet($arr, string $format = 'intval'): string
{
$arr = array_unique(array_filter(Arr::splitFilterToArray($arr, $format, ',')));
return $arr ? implode(',', $arr) : '';
}
/**
* set形式字符串转数组
* @param $str
* @param string $format
* @return array
* @author zbj
* @date 2023/4/17
*/
public static function setToArr($str, string $format = 'intval')
{
if (is_string($str)) {
return Arr::splitFilterToArray($str, $format, ',');
}
return $str ?: [];
}
/**
* 将数组设置成某个键的值
* @param $arr
* @param $key
* @return array
* @author zbj
* @date 2023/5/16
*/
public static function setValueToKey($arr, $key)
{
$data = [];
if (!$arr) {
return $data;
}
foreach ($arr as $v) {
$data[$v[$key]] = $v;
}
if ($arr instanceof Collection) {
$data = new Collection($data);
}
return $data;
}
}
... ...
<?php
namespace App\Helper;
use GuzzleHttp\Client;
/**
* @name: ayr_share社交绑定
*/
class AyrShare
{
public $path = 'https://app.ayrshare.com';
//api_key
public $api_key = 'G8GQW3X-XBTMGXW-QPDDZ9A-WE1Z5SB';
//系统设置
public $config = [
'facebook'=>'#best https://www.facebook.com',
'google'=>'#best https://www.google.com',
'instagram'=>'#best https://www.instagram.com',
'linkedin'=>'#best https://www.linkedin.com',
'twitter'=>'#best https://www.twitter.com',
'telegram'=>'#best https://www.telegram.com',
'tiktok'=>'#bestvideo',
];
//profile_key
public $profile_key = '';
//设置请求头
public $headers = [
'Authorization' => 'Bearer ',
'Content-Type' => 'application/json',
];
//私钥
private $private_key = "-----BEGIN RSA PRIVATE KEY-----
MIICWgIBAAKBgGFatMeBeaw7QJrqmylMLZlwuuO0FA/EZg5/g7Rrqu+FgpwvFkJq
9twEZJY+aIdDH8/RVrCZQGR/xUxKw9v4ows+sLwi4g41m8KRKDXUcJwQvSlwsHAi
h9hPGZxDsRK0Nv4pZ7XqGgh0Wb0VypX/+Q1dhX9BnXQmvEKayk8GQWQxAgMBAAEC
gYAFqOJNnudV7fPpja4LjpQwEW+sATIRYJeWTC9587ByUE6xicM/hTxouhCm82Xc
Rzi4OjFR/vbRYOQ1dTtBtIi18fdRrseQNyR/N2NZjw1X8n5aZcw5NVaa3d3YTQNa
uzjnYF5eYSOD4pNKKIDc35VHdmvGCV/JXwQKMTgu1+4AAQJBAL5jjN3kvMKFF8vG
DyYR8k+wPG9iXAdR0HjVNB3OzxKVW0MTwM32pJBXCmF1MOziL8WC48VHQL48hVRa
52xRqAECQQCC53rrrOPhPCLIb6kBfgqnxCojqlUK9paFL7NYTPtLYcOajY6+NiKT
CG1gaOwZh4r34HF7I59l/Ds98Z4nQDwxAkAC4/oIiGeBQIoK8vfZ6R3XreJNAp5J
EinrG7mN1kz4iEH5c7xSpDL9agTjU+cpQYneIs2Yeit2d+7CSBsJXvgBAkBDFsfU
yYLxCJT7DN8dOK/VU6AVL1Luj3qNP+k2tB2GgNBzAWHK8ou9t2/3HU8DtofuikUe
yx8Cccca9B4OF8nBAkAgIUZKGmVNFcGnFFo55vSJInNXFo4HCJ2o4DunBORVtQ/j
zFePUMXy1bFghAfzNKlrc5XgH4ixeeMh3cDtU97K
-----END RSA PRIVATE KEY-----";
/**
* @name :(创建子账户配置文件)post_create_profiles
* @author :lyh
* @method :post
* @time :2023/5/5 15:16
*/
public function post_create_profiles($data){
$param = [
'title'=>$data['title'],
];
$url = $this->path.'/api/profiles/profile';
return $this->http_click('post',$url,$param);
}
/**
* @name :(删除子账户配置文件)deleted_profiles
* @author :lyh
* @method :post
* @time :2023/5/5 15:16
*/
public function deleted_profiles($data){
$param = [
// 'title'=>$data['title'],
'profileKey'=>$data['profileKey'],
];
$url = $this->path.'/api/profiles/profile';
return $this->http_click('delete',$url,$param);
}
/**
* @name :(跳转第三方生成jwt令牌)post_generate_jwt
* @author :lyh
* @method :post
* @time :2023/5/5 18:07 https://app.ayrshare.com/api/profiles/generateJWT
*/
public function post_generate_jwt($data,$domain = 'globalso'){
$param = [
'domain'=>$domain,
'privateKey'=>$this->private_key,
'profileKey'=>$data['profileKey'],
// 'logout'=>true
];
$url = $this->path.'/api/profiles/generateJWT';
return $this->http_click('post',$url,$param);
}
/**
* @name :(获取指定api_key的配置文件)get_profiles_users
* @author :lyh
* @method :post
* @time :2023/5/6 16:44
*/
public function get_profiles_users($api_key){
$this->headers['Authorization'] = $this->headers['Authorization'].$api_key;
$url = $this->path.'/api/user';
return $this->http_click('get',$url,[],$this->headers);
}
/**
* @name :(发帖)post_send_msg
* @author :lyh
* @method :post
* @time :2023/5/8 9:22
* @param :platforms: "facebook", "fbg", "twitter",
* "linkedin", "instagram","youtube", "reddit" ,"telegram""
*/
public function post_send_msg($param,$api_key){
//平台参数处理
$this->headers['Accept-Encoding'] = 'gzip';
$this->headers['Authorization'] = $this->headers['Authorization'].$api_key;
$url = $this->path.'/api/post';
return $this->http_click('posts',$url,$param,$this->headers);
}
/**
* @name :(上传图片或视频到ayr_share)post_media_upload
* @author :lyh
* @method :post
* @time :2023/5/8 9:47
* https://app.ayrshare.com/api/media/upload
*/
public function post_media_upload($data,$api_key){
$param = [
'file'=>$data['file'],//base64编码
];
$this->headers['Authorization'] = $this->headers['Authorization'].$api_key;
$url = $this->path.'/api/media/upload';
return $this->http_click('post',$url,$param,$this->headers);
}
/**
* @name :获取过去30天发布的历史记录(1-30)
* @author :lyh
* @method :get
* @time :2023/5/5 10:00
*/
public function get_analytics_links($to_day){
$last_days = (string)$to_day;
$url = $this->path.'/analytics/links?lastDays='.$last_days;
return $this->http_click('get',$url);
}
/**
* @name :(通过 Ayrshare 获取给定帖子的实时分析,例如点赞、印象、转推等)post_analytics
* @author :lyh
* @method :post
* @time :2023/5/5 11:56
*/
public function post_analytics($id){
$param = [
'id'=>$id,
'platforms' => ['facebook', 'instagram', 'twitter', 'linkedin', 'pinterest', 'youtube', 'tiktok'],
];
$url = $this->path.'/api/analytics/post';
return $this->http_click('post', $url, $param);
}
/**
* @name :(获取特定用户个人资料)analytics_post
* @author :lyh
* @method :post
* @time :2023/5/5 10:43
*/
public function post_analytics_social(){
$post_data = [
'platforms' => ['facebook', 'instagram', 'twitter', 'linkedin', 'pinterest', 'youtube', 'tiktok'],
];
$url = $this->path.'/api/analytics/social';
return $this->http_click('post',$url,$post_data);
}
/**
* @name :(设置自动计划)post_schedule_set
* @author :lyh
* @method :post
* @time :2023/5/5 13:58
*/
public function post_schedule_set($data){
$param = [
'schedule'=>["13:05Z", "20:14Z"],
'title'=>$data['title'],
];
$url = $this->path.'/api/auto-schedule/set';
return $this->http_click('post',$url,$param);
}
/**
* @name :(删除自动计划)delete_schedule
* @author :lyh
* @method :post
* @time :2023/5/5 14:04
*/
public function delete_schedule($data){
$param = [
'title'=>$data['title'],
];
$url = $this->path.'/api/auto-schedule/delete';
return $this->http_click('delete',$url,$param);
}
/**
* @name :(列出自动计划)get_schedule_list
* @author :lyh
* @method :post
* @time :2023/5/5 14:08
*/
public function get_schedule_list(){
$url = $this->path.'/api/auto-schedule/list';
return $this->http_click('get',$url);
}
/**
* @name :(发布到用户个人资料)post_user
* @author :lyh
* @method :post
* @time :2023/5/5 15:00
*/
public function post_profiles($data){
$param = [
'post'=>$data['post'],
'platforms'=>$data['platforms'],
'profileKey'=>$this->profile_key,
'mediaUrls'=>$data['mediaUrls']
];
$url = $this->path.'/api/post';
return $this->http_click('post',$url,$param);
}
/**
* 发送http post,get,put,delete请求
* @param type $url
* @param type $post_data
*/
function http_click($method = 'post',$url, $param = [],$header = [])
{
if(!empty($param)){
$post_data['json'] = $param;
}
if(empty($header)){
$this->headers['Authorization'] = $this->headers['Authorization'].$this->api_key;
}
$post_data['headers'] = !empty($header) ? $header : $this->headers;
$client = new Client();
try {
$res = $client->request(strtoupper($method), $url, $post_data)->getBody()->getContents();
return (array)json_decode($res);
} catch (\Exception $e) {
return ["status"=>"fail","message"=>$e->getMessage()];
}
}
}
... ...
<?php
namespace App\Helper;
use App\Models\Ai\AiCommand as AiCommandModel;
use App\Models\User\UserLog as UserLogModel;
use App\Models\User\UserLogin as UserLoginModel;
use Illuminate\Support\Facades\Cache;
/**
* @name:
*/
class Common
{
/**
* @name :生成用户操作日志
* @return void
* @author :liyuhang
* @method
*/
public static function set_user_log($param = []){
$data = [
'operator_id'=>$param['operator_id'],
'model'=>$param['model'],
'remark'=>$param['remark']
];
$model = new UserLogModel();
return $model->add($data);
}
/**
* @name :写入登录日志
* @return void
* @author :liyuhang
* @method
*/
public static function set_user_login($param = []){
$data = [
'user_id'=>$param['user_id'],
'ip'=>$param['ip']
];
$model = new UserLoginModel();
return $model->add($data);
}
/**
* @name :ai自动生成
* @return mixed
* @author :liyuhang
* @method
*/
public static function send_openai_msg($url,$param){
$url = HTTP_OPENAI_URL.$url;
$aiCommandModel = New AiCommandModel();
//指定库获取指令
$info = $aiCommandModel->read(['key'=>$param['key']]);
if($info === false){
response('指令不存在',400);
}
//替换关键字
$content = str_replace('$keyword$', $param['keywords'], $info['ai']);
$data = [
'messages'=>[
['role'=>'system','content'=>$info['scene']],
['role'=>'assistant','content'=>$content],
]
];
return http_post($url,json_encode($data));
}
/**
* @name :获取缓存
* @return void
* @author :liyuhang
* @method
*/
public static function get_user_cache($table,$id,$type = 'B'){
$data = [];
$cache = config('cache.user_is_cache');
if(isset($cache) && ($cache['is_cache'] == true)){
$key = 'cache_'.$table.'_'.$id.'_type';
$data = Cache::store('file')->get($key);
}
return $data;
}
/**
* @name :写入缓存
* @return bool
* @author :liyuhang
* @method
*/
public static function set_user_cache($data = [],$table,$id,$type = 'B'){
$cache = config('cache.user_is_cache');
if(isset($cache) && ($cache['is_cache'] == true)){
$key = 'cache_'.$table.'_'.$id.'_type';
Cache::store('file')->set($key,$data,3600);
}
return true;
}
/**
* @name :清除缓存
* @return bool
* @author :liyuhang
* @method
*/
public static function del_user_cache($table,$id,$type = 'B'){
$cache = config('cache.user_is_cache');
if(isset($cache) && ($cache['is_cache'] == true)){
if(is_array($id)){
foreach ($id as $v){
$key = 'cache_'.$table.'_'.$v.'_type';
Cache::store('file')->pull($key);
}
}else{
$key = 'cache_'.$table.'_'.$id.'_type';
}
Cache::store('file')->pull($key);
}
return true;
}
/**
* @name :(多维数组去重)array_deduplication
* @author :lyh
* @method :post
* @time :2023/5/9 10:47
*/
public static function uniqueMultiArray($arr) {
$arr = array_map('serialize', $arr);
$arr = array_unique($arr);
$arr = array_map('unserialize', $arr);
return $arr;
}
}
... ...
<?php
namespace App\Helper;
use App\Models\WebSetting\WebSettingCountry;
/**
* @name:多语言国家设置
*/
class Country
{
public $tls_list = [
'en' => [
'text' => '英语',
'lang_text' => 'English',
'con_flag' => 'con_flag/en.jfif',
'shop_lang' => 'en-gb',
],
'zh' => [
'text' => '中文',
'lang_text' => '简体中文',
'con_flag' => 'con_flag/zh.jfif',
'shop_lang' => 'zh-cn',
],
'fr' => [
'text' => '法语',
'lang_text' => 'En français',
'con_flag' => '',
],
'de' => [
'text' => '德语',
'lang_text' => 'Das ist Deutsch.',
'con_flag' => '',
],
'ko' => [
'text' => '韩语',
'lang_text' => '',
'con_flag' => '',
],
'ja' => [
'text' => '日语',
'lang_text' => '',
'con_flag' => '',
],
'es' => [
'text' => '西班牙语',
'lang_text' => 'Español.',
'con_flag' => '',
],
'ar' => [
'text' => '阿拉伯语',
'lang_text' => '',
'con_flag' => '',
],
'pt' => [
'text' => '葡萄牙语(葡萄牙、巴西)',
'lang_text' => 'Língua portuguesa',
'con_flag' => '',
],
'ru' => [
'text' => '俄语',
'lang_text' => '',
'con_flag' => '',
],
'af' => [
'text' => '南非荷兰语',
'lang_text' => '',
'con_flag' => '',
],
'sq' => [
'text' => '阿尔巴尼亚语',
'lang_text' => '',
'con_flag' => '',
],
'am' => [
'text' => '阿姆哈拉语',
'lang_text' => '',
'con_flag' => '',
],
'hy' => [
'text' => '亚美尼亚语',
'lang_text' => '',
'con_flag' => '',
],
'az' => [
'text' => '阿塞拜疆语',
'lang_text' => '',
'con_flag' => '',
],
'eu' => [
'text' => '巴斯克语',
'lang_text' => '',
'con_flag' => '',
],
'be' => [
'text' => '白俄罗斯语',
'lang_text' => '',
'con_flag' => '',
],
'bn' => [
'text' => '孟加拉语',
'lang_text' => '',
'con_flag' => '',
],
'bs' => [
'text' => '波斯尼亚语',
'lang_text' => '',
'con_flag' => '',
],
'bg' => [
'text' => '保加利亚语',
'lang_text' => '',
'con_flag' => '',
],
'ca' => [
'text' => '加泰罗尼亚语',
'lang_text' => '',
'con_flag' => '',
],
'ceb' => [
'text' => '宿务语',
'lang_text' => '',
'con_flag' => '',
],
'zh-CN' => [
'text' => '中文(简体)',
'lang_text' => '简体中文',
'con_flag' => 'con_flag/zh.jfif',
'shop_lang' => 'zh-cn',
],
'zh-TW' => [
'text' => '中文(繁体)',
'lang_text' => '繁体中文',
'con_flag' => 'con_flag/zh.jfif',
],
'co' => [
'text' => '科西嘉语',
'lang_text' => '',
'con_flag' => '',
],
'hr' => [
'text' => '克罗地亚语',
'lang_text' => '',
'con_flag' => '',
],
'cs' => [
'text' => '捷克语',
'lang_text' => '',
'con_flag' => '',
],
'da' => [
'text' => '丹麦语',
'lang_text' => '',
'con_flag' => '',
],
'nl' => [
'text' => '荷兰语',
'lang_text' => '',
'con_flag' => '',
],
'eo' => [
'text' => '世界语',
'lang_text' => '',
'con_flag' => '',
],
'et' => [
'text' => '爱沙尼亚语',
'lang_text' => '',
'con_flag' => '',
],
'fi' => [
'text' => '芬兰语',
'lang_text' => '',
'con_flag' => '',
],
'fy' => [
'text' => '弗里斯兰语',
'lang_text' => '',
'con_flag' => '',
],
'gl' => [
'text' => '加利西亚语',
'lang_text' => '',
'con_flag' => '',
],
'ka' => [
'text' => '格鲁吉亚语',
'lang_text' => '',
'con_flag' => '',
],
'el' => [
'text' => '希腊语',
'lang_text' => '',
'con_flag' => '',
],
'gu' => [
'text' => '古吉拉特语',
'lang_text' => '',
'con_flag' => '',
],
'ht' => [
'text' => '海地克里奥尔语',
'lang_text' => '',
'con_flag' => '',
],
'ha' => [
'text' => '豪萨语',
'lang_text' => '',
'con_flag' => '',
],
'haw' => [
'text' => '夏威夷语',
'lang_text' => '',
'con_flag' => '',
],
'iw' => [
'text' => '希伯来语',
'lang_text' => '',
'con_flag' => '',
],
'hi' => [
'text' => '印地语',
'lang_text' => '',
'con_flag' => '',
],
'hmn' => [
'text' => '苗语',
'lang_text' => '',
'con_flag' => '',
],
'hu' => [
'text' => '匈牙利语',
'lang_text' => '',
'con_flag' => '',
],
'is' => [
'text' => '冰岛语',
'lang_text' => '',
'con_flag' => '',
],
'ig' => [
'text' => '伊博语',
'lang_text' => '',
'con_flag' => '',
],
'id' => [
'text' => '印度尼西亚语',
'lang_text' => 'Bahasa Indonesia',
'con_flag' => 'con_flag/id.jfif',
'shop_lang' => 'id',
],
'ga' => [
'text' => '爱尔兰语',
'lang_text' => '',
'con_flag' => '',
],
'it' => [
'text' => '意大利语',
'lang_text' => 'Lingua italiana',
'con_flag' => '',
],
'jw' => [
'text' => '爪哇语',
'lang_text' => '',
'con_flag' => '',
],
'kn' => [
'text' => '卡纳达语',
'lang_text' => '',
'con_flag' => '',
],
'kk' => [
'text' => '哈萨克语',
'lang_text' => '',
'con_flag' => '',
],
'km' => [
'text' => '高棉语',
'lang_text' => '',
'con_flag' => '',
],
'rw' => [
'text' => '卢旺达语',
'lang_text' => '',
'con_flag' => '',
],
'ku' => [
'text' => '库尔德语',
'lang_text' => '',
'con_flag' => '',
],
'ky' => [
'text' => '吉尔吉斯语',
'lang_text' => '',
'con_flag' => '',
],
'lo' => [
'text' => '老挝文',
'lang_text' => '',
'con_flag' => '',
],
'la' => [
'text' => '拉丁文',
'lang_text' => '',
'con_flag' => '',
],
'lv' => [
'text' => '拉脱维亚语',
'lang_text' => '',
'con_flag' => '',
],
'lt' => [
'text' => '立陶宛语',
'lang_text' => '',
'con_flag' => '',
],
'lb' => [
'text' => '卢森堡语',
'lang_text' => '',
'con_flag' => '',
],
'mk' => [
'text' => '马其顿语',
'lang_text' => '',
'con_flag' => '',
],
'mg' => [
'text' => '马尔加什语',
'lang_text' => '',
'con_flag' => '',
],
'ms' => [
'text' => '马来语',
'lang_text' => 'Bahasa Melayu',
'con_flag' => 'con_flag/ms.jfif',
'shop_lang' => 'ms-my',
],
'ml' => [
'text' => '马拉雅拉姆文',
'lang_text' => '',
'con_flag' => '',
],
'mt' => [
'text' => '马耳他语',
'lang_text' => '',
'con_flag' => '',
],
'mi' => [
'text' => '毛利语',
'lang_text' => '',
'con_flag' => '',
],
'mr' => [
'text' => '马拉地语',
'lang_text' => '',
'con_flag' => '',
],
'mn' => [
'text' => '蒙古文',
'lang_text' => '',
'con_flag' => '',
],
'my' => [
'text' => '缅甸语',
'lang_text' => '',
'con_flag' => '',
],
'ne' => [
'text' => '尼泊尔语',
'lang_text' => '',
'con_flag' => '',
],
'no' => [
'text' => '挪威语',
'lang_text' => '',
'con_flag' => '',
],
'ny' => [
'text' => '尼杨扎语(齐切瓦语)',
'lang_text' => '',
'con_flag' => '',
],
'or' => [
'text' => '奥里亚语(奥里亚)',
'lang_text' => '',
'con_flag' => '',
],
'ps' => [
'text' => '普什图语',
'lang_text' => '',
'con_flag' => '',
],
'fa' => [
'text' => '波斯语',
'lang_text' => '',
'con_flag' => '',
],
'pl' => [
'text' => '波兰语',
'lang_text' => '',
'con_flag' => '',
],
'pa' => [
'text' => '旁遮普语',
'lang_text' => '',
'con_flag' => '',
],
'ro' => [
'text' => '罗马尼亚语',
'lang_text' => '',
'con_flag' => '',
],
'sm' => [
'text' => '萨摩亚语',
'lang_text' => '',
'con_flag' => '',
],
'gd' => [
'text' => '苏格兰盖尔语',
'lang_text' => '',
'con_flag' => '',
],
'sr' => [
'text' => '塞尔维亚语',
'lang_text' => '',
'con_flag' => '',
],
'st' => [
'text' => '塞索托语',
'lang_text' => '',
'con_flag' => '',
],
'sn' => [
'text' => '修纳语',
'lang_text' => '',
'con_flag' => '',
],
'sd' => [
'text' => '信德语',
'lang_text' => '',
'con_flag' => '',
],
'si' => [
'text' => '僧伽罗语',
'lang_text' => '',
'con_flag' => '',
],
'sk' => [
'text' => '斯洛伐克语',
'lang_text' => '',
'con_flag' => '',
],
'sl' => [
'text' => '斯洛文尼亚语',
'lang_text' => '',
'con_flag' => '',
],
'so' => [
'text' => '索马里语',
'lang_text' => '',
'con_flag' => '',
],
'su' => [
'text' => '巽他语',
'lang_text' => '',
'con_flag' => '',
],
'sw' => [
'text' => '斯瓦希里语',
'lang_text' => '',
'con_flag' => '',
],
'sv' => [
'text' => '瑞典语',
'lang_text' => '',
'con_flag' => '',
],
'tl' => [
'text' => '塔加路语(菲律宾语)',
'lang_text' => 'Pilipino',
'con_flag' => 'con_flag/tl.jfif',
'shop_lang' => 'tl',
],
'tg' => [
'text' => '塔吉克语',
'lang_text' => '',
'con_flag' => '',
],
'ta' => [
'text' => '泰米尔语',
'lang_text' => '',
'con_flag' => '',
],
'tt' => [
'text' => '鞑靼语',
'lang_text' => '',
'con_flag' => '',
],
'te' => [
'text' => '泰卢固语',
'lang_text' => '',
'con_flag' => '',
],
'th' => [
'text' => '泰文',
'lang_text' => 'ไทย',
'con_flag' => 'con_flag/th.jfif',
'shop_lang' => 'th',
],
'tr' => [
'text' => '土耳其语',
'lang_text' => '',
'con_flag' => '',
],
'tk' => [
'text' => '土库曼语',
'lang_text' => '',
'con_flag' => '',
],
'uk' => [
'text' => '乌克兰语',
'lang_text' => '',
'con_flag' => '',
],
'ur' => [
'text' => '乌尔都语',
'lang_text' => '',
'con_flag' => '',
],
'ug' => [
'text' => '维吾尔语',
'lang_text' => '',
'con_flag' => '',
],
'uz' => [
'text' => '乌兹别克语',
'lang_text' => '',
'con_flag' => '',
],
'vi' => [
'text' => '越南语',
'lang_text' => '',
'con_flag' => '',
],
'cy' => [
'text' => '威尔士语',
'lang_text' => '',
'con_flag' => '',
],
'xh' => [
'text' => '班图语',
'lang_text' => '',
'con_flag' => '',
],
'yi' => [
'text' => '意第绪语',
'lang_text' => '',
'con_flag' => '',
],
'yo' => [
'text' => '约鲁巴语',
'lang_text' => '',
'con_flag' => '',
],
'zu' => [
'text' => '祖鲁语',
'lang_text' => '',
'con_flag' => '',
],
];
/**
* @name :(获取翻译国家)set_country
* @author :lyh
* @method :post
* @time :2023/5/4 17:57
*/
public function set_country(){
$data = [];
foreach ($this->tls_list as $k=>$v){
$data[] = ['name'=>$v['text'],'alias'=>$k];
}
$webCountry = new WebSettingCountry();
$webCountry->insert($data);
return true;
}
}
... ...
<?php
namespace App\Helper;
/**
* 计算文件hash
*
* 七牛云的计算规则
*/
class FileEtag
{
const BLOCK_SIZE = 4194304; //4*1024*1024 分块上传块大小,该参数为接口规格,不能修改
private static function packArray($v, $a)
{
return call_user_func_array('pack', array_merge(array($v), (array)$a));
}
private static function blockCount($fsize)
{
return intval(($fsize + (self::BLOCK_SIZE - 1)) / self::BLOCK_SIZE);
}
private static function calcSha1($data)
{
$sha1Str = sha1($data, true);
$err = error_get_last();
if ($err !== null) {
return array(null, $err);
}
$byteArray = unpack('C*', $sha1Str);
return array($byteArray, null);
}
private static function base64_urlSafeEncode($data)
{
$find = array('+', '/');
$replace = array('-', '_');
return str_replace($find, $replace, base64_encode($data));
}
public static function sum($filename)
{
$fhandler = fopen($filename, 'r');
$err = error_get_last();
if ($err !== null) {
return array(null, $err);
}
$fstat = fstat($fhandler);
$fsize = $fstat['size'];
if ((int)$fsize === 0) {
fclose($fhandler);
return array('Fto5o-5ea0sNMlW_75VgGJCv2AcJ', null);
}
$blockCnt = self::blockCount($fsize);
$sha1Buf = array();
if ($blockCnt <= 1) {
array_push($sha1Buf, 0x16);
$fdata = fread($fhandler, self::BLOCK_SIZE);
if ($err !== null) {
fclose($fhandler);
return array(null, $err);
}
list($sha1Code,) = self::calcSha1($fdata);
$sha1Buf = array_merge($sha1Buf, $sha1Code);
} else {
array_push($sha1Buf, 0x96);
$sha1BlockBuf = array();
for ($i = 0; $i < $blockCnt; $i++) {
$fdata = fread($fhandler, self::BLOCK_SIZE);
list($sha1Code, $err) = self::calcSha1($fdata);
if ($err !== null) {
fclose($fhandler);
return array(null, $err);
}
$sha1BlockBuf = array_merge($sha1BlockBuf, $sha1Code);
}
$tmpData = self::packArray('C*', $sha1BlockBuf);
list($sha1Final,) = self::calcSha1($tmpData);
$sha1Buf = array_merge($sha1Buf, $sha1Final);
}
$etag = self::base64_urlSafeEncode(self::packArray('C*', $sha1Buf));
return array($etag, null);
}
}
... ...
<?php
namespace App\Helper;
use App\Utils\HttpUtils;
use GuzzleHttp\Exception\GuzzleException;
/**
* Class PageSpeed
* @package App\Helper
* @author zbj
* @date 2023/5/10
*/
class GoogleSpeedApi
{
protected $areas = [
[
"area" => "洛杉矶",
"numericValue" => 0,
],
[
"area" => "圣地亚哥",
"numericValue" => 0,
],
[
"area" => "伦敦",
"numericValue" => 0,
],
[
"area" => "西雅图",
"numericValue" => 0,
],
[
"area" => "吉隆坡",
"numericValue" => 0,
],
[
"area" => "雅加达",
"numericValue" => 0,
],
[
"area" => "孟买",
"numericValue" => 0,
],
[
"area" => "迪拜",
"numericValue" => 0,
],
[
"area" => "法兰克福",
"numericValue" => 0,
],
[
"area" => "新加坡",
"numericValue" => 0,
],
[
"area" => "悉尼",
"numericValue" => 0,
],
[
"area" => "东京",
"numericValue" => 0,
],
[
"area" => "硅谷",
"numericValue" => 0,
],
[
"area" => "弗吉尼亚",
"numericValue" => 0,
],
[
"area" => "香港",
"numericValue" => 0,
],
[
"area" => "圣保罗",
"numericValue" => 0,
],
[
"area" => "雅典",
"numericValue" => 0,
],
[
"area" => "巴黎",
"numericValue" => 0,
],
[
"area" => "罗马",
"numericValue" => 0,
],
[
"area" => "马德里",
"numericValue" => 0,
],
];
/**
* @param $url
* @return array|false
* @author zbj
* @date 2023/5/10
*/
function run($url)
{
try {
$params = [
'url' => $url
];
$res = HttpUtils::get('http://45.136.131.72/api.php', $params);
if ($res) {
$res = Arr::s2a($res);
$area_data = Arr::s2a($res['area_data']);
}
$numericValue = $area_data[0]['numericValue'] ?? rand(500, 1000);
foreach ($this->areas as &$area) {
$start = -$numericValue * 0.5;
$end = $numericValue * 0.5;
$numer = rand($start, $end);
$area["numericValue"] = ceil($numericValue - $numer);
}
return [
"url" => $url,
"area_data" => $this->areas,
"created_at" => date("Y-m-d H:i:s")
];
} catch (\Exception | GuzzleException $e) {
errorLog('测速失败', $params, $e);
return false;
}
}
}
... ...
<?php
namespace App\Helper;
use App\Utils\HttpUtils;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Support\Facades\Cache;
/**
* Class QuanqiusouApi
* @package App\Helper
* @author zbj
* @date 2023/5/11
*/
class QuanqiusouApi
{
//接口地址
protected $url = 'http://api.quanqiusou.cn';
/**
* 所有站点收录页面数
* @author zbj
* @date 2023/5/11
*/
public function getSiteRes()
{
$key = 'quanqiusou_api_site_res_' . date('Y-m-d');
$res = Cache::get($key);
if (!$res) {
$api_url = $this->url . '/google-rank/echo_site_res.php';
try {
$res = HttpUtils::get($api_url, []);
if($res){
$res = Arr::s2a($res);
Cache::put($key, $res, 24 * 3600);
}
} catch (\Exception | GuzzleException $e) {
errorLog('获取站点收录页面数', [], $e);
return false;
}
}
return $res;
}
/**
* 指定站点收录页面数
* @param $api_no
* @return array|false|mixed
* @author zbj
* @date 2023/5/11
*/
public function getSiteResPer($api_no){
$key = 'quanqiusou_api_site_res_per_' . $api_no . '_' . date('Y-m-d');
$res = Cache::get($key);
if (!$res) {
$api_url = $this->url . '/google-rank/echo_site_res_per.php';
try {
$res = HttpUtils::get($api_url, ['apino' => $api_no]);
if($res){
$res = Arr::s2a($res);
Cache::put($key, $res, 24 * 3600);
}
} catch (\Exception | GuzzleException $e) {
errorLog('获取站点收录页面数', [], $e);
return false;
}
}
return $res;
}
/**
* 获取谷歌排名数据
* @param $api_no
* @param int $lang
* @param int $day
* @return array|false|mixed
* @author zbj
* @date 2023/5/11
*/
public function getGoogleRank($api_no, int $lang = 0, int $day = 7)
{
$key = "quanqiusou_api_rank_{$api_no}_{$lang}_{$day}_" . date('Y-m-d');
$res = Cache::get($key);
if (!$res) {
$param = [
'key' => '289c1fc81c89d79c04ed4fd72822948e',
'w' => $api_no,
'type' => $day
];
if ($lang) {
$param['lang'] = $lang;
}
$api_url = $this->url . '/api';
try {
$res = HttpUtils::get($api_url, $param);
if($res){
$res = Arr::s2a($res);
Cache::put($key, $res, 24 * 3600);
}
} catch (\Exception | GuzzleException $e) {
errorLog('获取谷歌排名数据失败', $api_no, $e);
return false;
}
}
return $res;
}
/**
* 获取每周谷歌排名数据
* @return array|false|mixed
* @author zbj
* @date 2023/5/11
*/
public function getGoogleRankWeek()
{
$key = "quanqiusou_api_week_data_" . date('Y-m-d');
$res = Cache::get($key);
if (!$res) {
$api_url = $this->url . '/google-rank/echo_week_data.php';
try {
$res = HttpUtils::get($api_url, []);
if($res){
$res = Arr::s2a($res);
Cache::put($key, $res, 24 * 3600);
}
} catch (\Exception | GuzzleException $e) {
errorLog('获取每周谷歌排名数据失败', [], $e);
return false;
}
}
return $res;
}
/**
* 获取历史排名统计数据
* @param $api_no
* @param string $lang
* @return array|false|int|mixed|null
* @author zbj
* @date 2023/5/15
*/
public function getHistoryCount($api_no, $lang = '')
{
$key = "quanqiusou_api_history_count_{$api_no}_{$lang}_" . date('Y-m-d');
$res = Cache::get($key);
if (!$res) {
$api_url = $this->url . '/google-rank/history_count.php';
$param = [
'apino' => $api_no,
];
if ($lang) {
$param['lang'] = $lang;
}
try {
$res = HttpUtils::get($api_url, $param);
if($res){
$res = Arr::s2a($res);
Cache::put($key, $res, 24 * 3600);
}
} catch (\Exception | GuzzleException $e) {
errorLog('获取历史排名统计数据失败', [], $e);
return false;
}
}
return $res;
}
/**
* 获取小语种项目
* @return array|false|int|mixed|null
* @author zbj
* @date 2023/5/15
*/
public function getLangList()
{
$key = "quanqiusou_api_lang_list_" . date('Y-m-d');
$res = Cache::get($key);
if (!$res) {
$api_url = $this->url . '/api/index/langlist';
$param = [
'key' => '289c1fc81c89d79c04ed4fd72822948e',
];
try {
$res = HttpUtils::get($api_url, $param);
if($res){
$res = Arr::s2a($res);
Cache::put($key, $res, 2 * 3600);
}
} catch (\Exception | GuzzleException $e) {
errorLog('获取小语种项目数据失败', [], $e);
return false;
}
}
return $res;
}
/**
* 获取项目小语种信息
* @return array|false|int|mixed|null
* @author zbj
* @date 2023/5/15
*/
public function getLangRankData($api_no)
{
$key = "quanqiusou_get_language_rank_data_{$api_no}_" . date('Y-m-d');
$res = Cache::get($key);
if (!$res) {
$api_url = $this->url . '/api/index/get_language_rank_data';
$param = [
'apino' => $api_no,
];
try {
$res = HttpUtils::get($api_url, $param);
if($res){
$res = Arr::s2a($res);
Cache::put($key, $res, 24 * 3600);
}
} catch (\Exception | GuzzleException $e) {
errorLog('获取项目小语种数据失败', [], $e);
return false;
}
}
return $res;
}
}
... ...
<?php
namespace App\Helper;
use App\Utils\HttpUtils;
use GuzzleHttp\Exception\GuzzleException;
/**
* Class SemrushApi
* @package App\Helper
* @author zbj
* @date 2023/5/9
*/
class SemrushApi
{
//接口地址
protected $url = 'https://api.semrush.com';
protected $key = '2927058317c47207e4a8c4cacf10acfd';
/**
* 反链概述
*/
function backlinks_overview($target,$target_type = "root_domain"){
if($target){
$url = $this->url."/analytics/v1/?";
$params = [
"type"=>"backlinks_overview",
"key"=>$this->key,
"target"=>$target,
"target_type"=>$target_type,
"export_columns"=>"ascore,total,domains_num,urls_num,ips_num,ipclassc_num,follows_num,nofollows_num,sponsored_num,ugc_num,texts_num,images_num,forms_num,frames_num"
];
try {
$res = HttpUtils::get($url, $params);
return $this->data($res)[0];
}catch (\Exception|GuzzleException $e){
errorLog('获取站点外链数据', $params, $e);
return false;
}
}
return [];
}
/**
* 引荐域名
*/
public function backlinks_refdomains($target,$target_type = "root_domain",$offset = 0){
if($target){
$url = $this->url."/analytics/v1/?";
$params = [
"type"=>"backlinks_refdomains",
"key"=>$this->key,
"target"=>$target,
"target_type"=>$target_type,
"export_columns"=>"domain_ascore,domain,backlinks_num,ip,country,first_seen,last_seen",
"display_limit"=>10,
"display_offset"=>$offset
];
try {
$res = HttpUtils::get($url, $params);
return $this->data($res);
}catch (\Exception|GuzzleException $e){
errorLog('获取站点外链数据', $params, $e);
return false;
}
}
return [];
}
/**
* 处理结果
* @param $res
* @return array
* @author zbj
* @date 2023/5/9
*/
protected function data($res){
$temp = explode("\n",$res);
$arr =array_map(function ($v){
return explode(";",$v);
}, $temp);
$data = [];
for ($i = 1; $i < count($arr) - 1; $i++) {
$tmp = [];
foreach($arr[0] as $k =>$v){
$tmp[trim($v)] = trim($arr[$i][$k]);
}
$data[] = $tmp;
}
return $data;
}
}
... ...
<?php
namespace App\Helper;
use Illuminate\Support\Facades\Http;
/**
* 翻译接口
* Class Translate
* @package App\Service
* @author zbj
* @date 2023/2/7
*/
class Translate
{
//接口地址
public static $url = 'https://translate.hbb618.cn/translates';
public static $tls_list = [
'en' => [
'text' => '英语',
'lang_text' => 'English',
'con_flag' => 'con_flag/en.jfif',
'shop_lang' => 'en-gb',
],
'zh' => [
'text' => '中文',
'lang_text' => '简体中文',
'con_flag' => 'con_flag/zh.jfif',
'shop_lang' => 'zh-cn',
],
'fr' => [
'text' => '法语',
'lang_text' => 'En français',
'con_flag' => '',
],
'de' => [
'text' => '德语',
'lang_text' => 'Das ist Deutsch.',
'con_flag' => '',
],
'ko' => [
'text' => '韩语',
'lang_text' => '',
'con_flag' => '',
],
'ja' => [
'text' => '日语',
'lang_text' => '',
'con_flag' => '',
],
'es' => [
'text' => '西班牙语',
'lang_text' => 'Español.',
'con_flag' => '',
],
'ar' => [
'text' => '阿拉伯语',
'lang_text' => '',
'con_flag' => '',
],
'pt' => [
'text' => '葡萄牙语(葡萄牙、巴西)',
'lang_text' => 'Língua portuguesa',
'con_flag' => '',
],
'ru' => [
'text' => '俄语',
'lang_text' => '',
'con_flag' => '',
],
'af' => [
'text' => '南非荷兰语',
'lang_text' => '',
'con_flag' => '',
],
'sq' => [
'text' => '阿尔巴尼亚语',
'lang_text' => '',
'con_flag' => '',
],
'am' => [
'text' => '阿姆哈拉语',
'lang_text' => '',
'con_flag' => '',
],
'hy' => [
'text' => '亚美尼亚语',
'lang_text' => '',
'con_flag' => '',
],
'az' => [
'text' => '阿塞拜疆语',
'lang_text' => '',
'con_flag' => '',
],
'eu' => [
'text' => '巴斯克语',
'lang_text' => '',
'con_flag' => '',
],
'be' => [
'text' => '白俄罗斯语',
'lang_text' => '',
'con_flag' => '',
],
'bn' => [
'text' => '孟加拉语',
'lang_text' => '',
'con_flag' => '',
],
'bs' => [
'text' => '波斯尼亚语',
'lang_text' => '',
'con_flag' => '',
],
'bg' => [
'text' => '保加利亚语',
'lang_text' => '',
'con_flag' => '',
],
'ca' => [
'text' => '加泰罗尼亚语',
'lang_text' => '',
'con_flag' => '',
],
'ceb' => [
'text' => '宿务语',
'lang_text' => '',
'con_flag' => '',
],
'zh-CN' => [
'text' => '中文(简体)',
'lang_text' => '简体中文',
'con_flag' => 'con_flag/zh.jfif',
'shop_lang' => 'zh-cn',
],
'zh-TW' => [
'text' => '中文(繁体)',
'lang_text' => '繁体中文',
'con_flag' => 'con_flag/zh.jfif',
],
'co' => [
'text' => '科西嘉语',
'lang_text' => '',
'con_flag' => '',
],
'hr' => [
'text' => '克罗地亚语',
'lang_text' => '',
'con_flag' => '',
],
'cs' => [
'text' => '捷克语',
'lang_text' => '',
'con_flag' => '',
],
'da' => [
'text' => '丹麦语',
'lang_text' => '',
'con_flag' => '',
],
'nl' => [
'text' => '荷兰语',
'lang_text' => '',
'con_flag' => '',
],
'eo' => [
'text' => '世界语',
'lang_text' => '',
'con_flag' => '',
],
'et' => [
'text' => '爱沙尼亚语',
'lang_text' => '',
'con_flag' => '',
],
'fi' => [
'text' => '芬兰语',
'lang_text' => '',
'con_flag' => '',
],
'fy' => [
'text' => '弗里斯兰语',
'lang_text' => '',
'con_flag' => '',
],
'gl' => [
'text' => '加利西亚语',
'lang_text' => '',
'con_flag' => '',
],
'ka' => [
'text' => '格鲁吉亚语',
'lang_text' => '',
'con_flag' => '',
],
'el' => [
'text' => '希腊语',
'lang_text' => '',
'con_flag' => '',
],
'gu' => [
'text' => '古吉拉特语',
'lang_text' => '',
'con_flag' => '',
],
'ht' => [
'text' => '海地克里奥尔语',
'lang_text' => '',
'con_flag' => '',
],
'ha' => [
'text' => '豪萨语',
'lang_text' => '',
'con_flag' => '',
],
'haw' => [
'text' => '夏威夷语',
'lang_text' => '',
'con_flag' => '',
],
'iw' => [
'text' => '希伯来语',
'lang_text' => '',
'con_flag' => '',
],
'hi' => [
'text' => '印地语',
'lang_text' => '',
'con_flag' => '',
],
'hmn' => [
'text' => '苗语',
'lang_text' => '',
'con_flag' => '',
],
'hu' => [
'text' => '匈牙利语',
'lang_text' => '',
'con_flag' => '',
],
'is' => [
'text' => '冰岛语',
'lang_text' => '',
'con_flag' => '',
],
'ig' => [
'text' => '伊博语',
'lang_text' => '',
'con_flag' => '',
],
'id' => [
'text' => '印度尼西亚语',
'lang_text' => 'Bahasa Indonesia',
'con_flag' => 'con_flag/id.jfif',
'shop_lang' => 'id',
],
'ga' => [
'text' => '爱尔兰语',
'lang_text' => '',
'con_flag' => '',
],
'it' => [
'text' => '意大利语',
'lang_text' => 'Lingua italiana',
'con_flag' => '',
],
'jw' => [
'text' => '爪哇语',
'lang_text' => '',
'con_flag' => '',
],
'kn' => [
'text' => '卡纳达语',
'lang_text' => '',
'con_flag' => '',
],
'kk' => [
'text' => '哈萨克语',
'lang_text' => '',
'con_flag' => '',
],
'km' => [
'text' => '高棉语',
'lang_text' => '',
'con_flag' => '',
],
'rw' => [
'text' => '卢旺达语',
'lang_text' => '',
'con_flag' => '',
],
'ku' => [
'text' => '库尔德语',
'lang_text' => '',
'con_flag' => '',
],
'ky' => [
'text' => '吉尔吉斯语',
'lang_text' => '',
'con_flag' => '',
],
'lo' => [
'text' => '老挝文',
'lang_text' => '',
'con_flag' => '',
],
'la' => [
'text' => '拉丁文',
'lang_text' => '',
'con_flag' => '',
],
'lv' => [
'text' => '拉脱维亚语',
'lang_text' => '',
'con_flag' => '',
],
'lt' => [
'text' => '立陶宛语',
'lang_text' => '',
'con_flag' => '',
],
'lb' => [
'text' => '卢森堡语',
'lang_text' => '',
'con_flag' => '',
],
'mk' => [
'text' => '马其顿语',
'lang_text' => '',
'con_flag' => '',
],
'mg' => [
'text' => '马尔加什语',
'lang_text' => '',
'con_flag' => '',
],
'ms' => [
'text' => '马来语',
'lang_text' => 'Bahasa Melayu',
'con_flag' => 'con_flag/ms.jfif',
'shop_lang' => 'ms-my',
],
'ml' => [
'text' => '马拉雅拉姆文',
'lang_text' => '',
'con_flag' => '',
],
'mt' => [
'text' => '马耳他语',
'lang_text' => '',
'con_flag' => '',
],
'mi' => [
'text' => '毛利语',
'lang_text' => '',
'con_flag' => '',
],
'mr' => [
'text' => '马拉地语',
'lang_text' => '',
'con_flag' => '',
],
'mn' => [
'text' => '蒙古文',
'lang_text' => '',
'con_flag' => '',
],
'my' => [
'text' => '缅甸语',
'lang_text' => '',
'con_flag' => '',
],
'ne' => [
'text' => '尼泊尔语',
'lang_text' => '',
'con_flag' => '',
],
'no' => [
'text' => '挪威语',
'lang_text' => '',
'con_flag' => '',
],
'ny' => [
'text' => '尼杨扎语(齐切瓦语)',
'lang_text' => '',
'con_flag' => '',
],
'or' => [
'text' => '奥里亚语(奥里亚)',
'lang_text' => '',
'con_flag' => '',
],
'ps' => [
'text' => '普什图语',
'lang_text' => '',
'con_flag' => '',
],
'fa' => [
'text' => '波斯语',
'lang_text' => '',
'con_flag' => '',
],
'pl' => [
'text' => '波兰语',
'lang_text' => '',
'con_flag' => '',
],
'pa' => [
'text' => '旁遮普语',
'lang_text' => '',
'con_flag' => '',
],
'ro' => [
'text' => '罗马尼亚语',
'lang_text' => '',
'con_flag' => '',
],
'sm' => [
'text' => '萨摩亚语',
'lang_text' => '',
'con_flag' => '',
],
'gd' => [
'text' => '苏格兰盖尔语',
'lang_text' => '',
'con_flag' => '',
],
'sr' => [
'text' => '塞尔维亚语',
'lang_text' => '',
'con_flag' => '',
],
'st' => [
'text' => '塞索托语',
'lang_text' => '',
'con_flag' => '',
],
'sn' => [
'text' => '修纳语',
'lang_text' => '',
'con_flag' => '',
],
'sd' => [
'text' => '信德语',
'lang_text' => '',
'con_flag' => '',
],
'si' => [
'text' => '僧伽罗语',
'lang_text' => '',
'con_flag' => '',
],
'sk' => [
'text' => '斯洛伐克语',
'lang_text' => '',
'con_flag' => '',
],
'sl' => [
'text' => '斯洛文尼亚语',
'lang_text' => '',
'con_flag' => '',
],
'so' => [
'text' => '索马里语',
'lang_text' => '',
'con_flag' => '',
],
'su' => [
'text' => '巽他语',
'lang_text' => '',
'con_flag' => '',
],
'sw' => [
'text' => '斯瓦希里语',
'lang_text' => '',
'con_flag' => '',
],
'sv' => [
'text' => '瑞典语',
'lang_text' => '',
'con_flag' => '',
],
'tl' => [
'text' => '塔加路语(菲律宾语)',
'lang_text' => 'Pilipino',
'con_flag' => 'con_flag/tl.jfif',
'shop_lang' => 'tl',
],
'tg' => [
'text' => '塔吉克语',
'lang_text' => '',
'con_flag' => '',
],
'ta' => [
'text' => '泰米尔语',
'lang_text' => '',
'con_flag' => '',
],
'tt' => [
'text' => '鞑靼语',
'lang_text' => '',
'con_flag' => '',
],
'te' => [
'text' => '泰卢固语',
'lang_text' => '',
'con_flag' => '',
],
'th' => [
'text' => '泰文',
'lang_text' => 'ไทย',
'con_flag' => 'con_flag/th.jfif',
'shop_lang' => 'th',
],
'tr' => [
'text' => '土耳其语',
'lang_text' => '',
'con_flag' => '',
],
'tk' => [
'text' => '土库曼语',
'lang_text' => '',
'con_flag' => '',
],
'uk' => [
'text' => '乌克兰语',
'lang_text' => '',
'con_flag' => '',
],
'ur' => [
'text' => '乌尔都语',
'lang_text' => '',
'con_flag' => '',
],
'ug' => [
'text' => '维吾尔语',
'lang_text' => '',
'con_flag' => '',
],
'uz' => [
'text' => '乌兹别克语',
'lang_text' => '',
'con_flag' => '',
],
'vi' => [
'text' => '越南语',
'lang_text' => '',
'con_flag' => '',
],
'cy' => [
'text' => '威尔士语',
'lang_text' => '',
'con_flag' => '',
],
'xh' => [
'text' => '班图语',
'lang_text' => '',
'con_flag' => '',
],
'yi' => [
'text' => '意第绪语',
'lang_text' => '',
'con_flag' => '',
],
'yo' => [
'text' => '约鲁巴语',
'lang_text' => '',
'con_flag' => '',
],
'zu' => [
'text' => '祖鲁语',
'lang_text' => '',
'con_flag' => '',
],
];
/**
* 获取语种列表
* @return array|string
* @author:dc
* @time 2022/3/30 13:52
*/
public static function getTls($lang = null){
$tls = array_combine(array_keys(static::$tls_list),array_column(static::$tls_list, 'text'));
if($lang === null){
return $tls;
}
if (is_array($lang)){
foreach ($lang as $key=>$item){
unset($lang[$key]);
$lang[$item] = $tls[$item]??'';
}
return $lang;
}
return $tls[$lang]??'';
}
/**
* 翻译
* @param $texts
* @param $tls
* @return \Illuminate\Http\Client\Response
* @time 2022/3/30 15:58
*/
public static function translate($texts, $tls)
{
if (is_string($texts)) {
$texts = [$texts];
}
if (is_string($tls)) {
$tls = [$tls];
}
$data = [
'texts' => $texts,
'sl' => 'auto',
'tls' => $tls,
];
return Http::post(self::$url, $data);
}
/**
* @param $texts
* @param $tls
* @return string|array
* @author:dc
* @time 2022/3/30 15:59
*/
public static function tran($texts, $tls)
{
if (!$texts) {
return '';
}
$retsult = self::translate($texts, $tls)->json();
return $retsult[0]['texts'] ?? '';
}
}
... ...
<?php
use App\Utils\LogUtils;
use Illuminate\Support\Carbon;
define('HTTP_OPENAI_URL','http://openai.waimaoq.com/');
/**
* 生成路由标识
* @param $string
... ... @@ -7,6 +11,215 @@
* @author zbj
* @date 2023/4/15
*/
function generateRoute($string){
return trim(strtolower(preg_replace( '/[\W]+/', '-', trim($string))), '-');
if (!function_exists('generateRoute')) {
function generateRoute($string)
{
return trim(strtolower(preg_replace('/[\W]+/', '-', trim($string))), '-');
}
}
/**
* 手动记录错误日志
* @param $title
* @param $params
* @param Throwable $exception
* @author zbj
* @date 2023/4/27
*/
function errorLog($title, $params, Throwable $exception){
$exceptionMessage = "错误CODE:" . $exception->getCode() .
"-----错误message:" . $exception->getMessage() .
'------错误文件:' . $exception->getFile() .
'-------错误行数:' . $exception->getLine();
LogUtils::error($title, $params, $exceptionMessage);
}
if(!function_exists('http_post')){
/**
* 发送http post请求
* @param type $url
* @param type $post_data
*/
function http_post($url, $post_data,$header = [])
{
if(empty($header)){
$header = array(
"Accept: application/json",
"Content-Type:application/json;charset=utf-8",
);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$res = curl_exec($ch);
if (curl_errno($ch)) {
Log::write(print_r(curl_errno($ch),1),'debug---1');
}
curl_close($ch);
return json_decode($res, true);
}
}
if(!function_exists('http_get')){
/**
* 发送http get请求
* @param type $url
* @return type
*/
function http_get($url,$header = [])
{
if(empty($header)){
$header[] = "content-type: application/json;
charset = UTF-8";
}
$ch1 = curl_init();
$timeout = 5;
curl_setopt($ch1, CURLOPT_URL, $url);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch1, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch1, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch1, CURLOPT_SSL_VERIFYHOST, false);
$access_txt = curl_exec($ch1);
curl_close($ch1);
return json_decode($access_txt, true);
}
}
if(!function_exists('_get_child')){
/**
* 菜单权限->得到子级数组
* @param int
* @return array
*/
function _get_child($my_id, $arr)
{
$new_arr = array();
foreach ($arr as $k => $v) {
$v = (array)$v;
if ($v['pid'] == $my_id) {
$v['sub'] = _get_child($v['id'],$arr);
$new_arr[] = $v;
}
}
return $new_arr ? $new_arr : false;
}
}
if (!function_exists('checkDomain')) {
/**
* 检查并补全域名协议
* @return false|string
* @author zbj
* @date 2023/5/5
*/
function checkDomain($value)
{
$urlParts = parse_url(strtolower($value));
if(empty($urlParts['host'])){
$urlParts = parse_url('https://' . $value);
}
$host = $urlParts['host'] ?? '';
$scheme = $urlParts['scheme'] ?? 'https';
if(!in_array($scheme, ['http', 'https'])){
return false;
}
if (preg_match('/^(?:[-A-Za-z0-9]+\.)+[A-Za-z]{2,6}$/', $host)) {
return $scheme . '://' . $host;
} else {
return false;
}
}
}
/**
* 把返回的数据集转换成Tree
* @param $list array 数据列表
* @param string|int $pk 主键|root
* @param string $pid 父id
* @param string $child 子键
* @param int $root 获取哪个id下面
* @param bool $empty_child 当子数据不存在,是否要返回空子数据
* @return array
*/
function list_to_tree($list, $pk='id',$pid = 'pid',$child = '_child',$root=0,$empty_child=true) {
// 如果是数字,则是root
if(is_numeric($pk)){
$root = $pk;
$pk = 'id';
}
// 创建Tree
$tree = array();
if(is_array($list)) {
// 创建基于主键的数组引用
$refer = array();
foreach ($list as $key => $data) {
if($empty_child){
$list[$key][$child] = [];
}
$refer[$data[$pk]] =& $list[$key];
}
foreach ($list as $key => $data) {
// 判断是否存在parent
$parentId = $data[$pid];
if ($root == $parentId) {
$tree[] =& $list[$key];
}else{
if (isset($refer[$parentId])) {
$refer[$parentId][$child][] = & $list[$key];
}
}
}
}
return $tree;
}
/**
* tree数据转list
* @param $tree
* @param string $child
* @return array
* @author:dc
* @time 2022/1/11 10:13
*/
function tree_to_list($tree, $child='_child'){
$lists = [];
foreach ($tree as $item){
$c = $item[$child]??[];
unset($item[$child]);
$lists[] = $item;
if ($c){
$lists = array_merge($lists,tree_to_list($c, $child));
}
}
return $lists;
}
if (!function_exists('getThisWeekStarDate')) {
/**
* 获取本周一的日期
* @return mixed
* @author zbj
* @date 2023/5/11
*/
function getThisWeekStarDate()
{
return Carbon::now()->startOfWeek()->toDateString();
}
}
... ...
<?php
namespace App\Http\Controllers\Aside\Ai;
use App\Enums\Common\Code;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\Ai\AiCommandLogic;
use App\Http\Requests\Aside\Ai\AiCommandRequest;
use App\Models\Ai\AiCommand as AiCommandModel;
use Illuminate\Http\Request;
use function App\Helper\send_openai_msg;
/**
* @name:ai指令
*/
class AiCommandController extends BaseController
{
/**
* @name :指令列表
* @return void
* @author :liyuhang
* @method
*/
public function lists(AiCommandModel $aiCommandModel){
$lists = $aiCommandModel->lists($this->map,$this->page,$this->row,$this->order);
$this->response('success',Code::SUCCESS,$lists);
}
/**
* @name :详情
* @return void
* @author :liyuhang
* @method
*/
public function info(AiCommandLogic $aiCommandLogic){
$this->request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
$aiCommandLogic->ai_info();
$this->response('success');
}
/**
* @name
* @return void
* @author :liyuhang
* @method
*/
public function add(AiCommandRequest $request,AiCommandLogic $aiCommandLogic){
$request->validated();
$aiCommandLogic->ai_add();
$this->response('success');
}
/**
* @name
* @return void
* @author :liyuhang
* @method
*/
public function edit(AiCommandRequest $request,AiCommandLogic $aiCommandLogic){
$request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
$aiCommandLogic->ai_edit();
$this->response('success');
}
/**
* @name
* @return void
* @author :liyuhang
* @method
*/
public function del(AiCommandLogic $aiCommandLogic){
$this->request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
$aiCommandLogic->ai_del();
$this->response('success');
}
}
... ...
<?php
namespace App\Http\Controllers\Aside\Ai;
use App\Enums\Common\Code;
use App\Http\Controllers\Aside\BaseController;
use App\Models\Ai\AiLog as AiLogModel;
class AiLogController extends BaseController
{
/**
* @name :ai日志列表
* @return void
* @author :liyuhang
* @method
*/
public function lists(AiLogModel $aiLogModel){
$lists = $aiLogModel->lists($this->map,$this->page,$this->row,$this->order);
$this->response('success',Code::SUCCESS,$lists);
}
}
... ...
... ... @@ -4,19 +4,18 @@ namespace App\Http\Controllers\Aside;
use App\Enums\Common\Code;
use App\Http\Controllers\Controller;
use App\Utils\EncryptUtils;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Session;
class BaseController extends Controller
{
protected $param = [];//所有请求参数
protected $token = ''; //token
protected $request = [];//助手函数
protected $p = 1;//当前页
protected $page = 1;//当前页
protected $row = 20;//每页条数
protected $header = [];//设置请求头参数
protected $order = 'id';
... ... @@ -31,23 +30,17 @@ class BaseController extends Controller
$this->request = $request;
$this->param = $this->request->all();
$this->token = $this->request->header('token');
$this->get_param();
$this->auth_token();
}
/**
* @name
* @return void
* @author :liyuhang
* @method
*/
public function auth_token(){
if(!empty($this->token) && !empty(Cache::get($this->token))){
$info = Cache::get($this->token);
if(isset($info) && !empty($info)){
$this->user = $info;
$this->uid = $info['id'];
//参数处理
$this->get_param();
}
}
/**
* 成功返回
* @param array $data
... ... @@ -68,19 +61,11 @@ class BaseController extends Controller
'data' => $data,
'msg' => $code->description,
];
//加密-返回数据
if (config('app.params_encrypt')) {
$k = config('app.params_encrypt_key');
$i = config('app.params_encrypt_iv');
$response = [
'p' => (new EncryptUtils())->openssl_en($response, $k, $i)];
}
$this->header['token'] = $this->token;
return response()->json($response,200,$this->header);
}
/**
* @name 参数过滤
* @return void
* @name :参数过滤
* @author :liyuhang
* @method
*/
... ... @@ -94,20 +79,23 @@ class BaseController extends Controller
case "order":
$this->order = $v;
break;
case 'p':
$this->p = $v;
case 'page':
$this->page = $v;
break;
case 'row':
$this->row = $v;
break;
case "created_at":
case "name":
$this->map['name'] = ['like','%'.$v.'%'];
break;
case "start_at":
$this->_btw[0] = $v;
$this->_btw[1] = date('Y-m-d H:i:s',time());
$this->map['create_at'] = ['between', $this->_btw];
$this->map['created_at'] = ['between', $this->_btw];
break;
case "updated_at":
case "end_at":
$this->_btw[1] = $v;
$this->map['update_at'] = ['between', $this->_btw];
$this->map['updated_at'] = ['between', $this->_btw];
break;
default:
if (!empty($v)) {
... ... @@ -116,20 +104,20 @@ class BaseController extends Controller
break;
}
}
}
/**
* @name 统一返回参数
* @return void
* @return JsonResponse
* @author :liyuhang
* @method
*/
public function response($msg,$code = 200,$data = [],$result_code = null,$type = 'application/json'){
$result_code === null && $result_code = $code;
public function response($msg = null,string $code = Code::SUCCESS,$data = [],$result_code = 200,$type = 'application/json'): JsonResponse
{
$code = Code::fromValue($code);
$result = [
'msg' =>$msg,
'code'=>$result_code,
'data'=>$data
'msg' => $msg == ' ' ? $code->description : $msg,
'code' => $code->value,
'data' => $this->_extents($data),
];
$this->header['Content-Type'] = $type;
$this->header['token'] = $this->token;
... ... @@ -137,25 +125,40 @@ class BaseController extends Controller
throw new HttpResponseException($response);
}
/**
* @name :上传图片
* @return void
* @param $data
* @name :返回参数统一处理
* @return array|string
* @author :liyuhang
* @method
*/
public function uploads(){
$files = $this->request->file('file');
if(empty($files)){
return $this->response('没有上传文件',Code::USER_ERROR);
protected function _extents($data) {
if (empty($data) || !is_array($data)) {
return empty($data) ? is_array($data) ? [] : '' : $data;
}
foreach ($data as $k => $v) {
if (is_array($v)) {
$data[$k] = $this->_extents($v);
} else {
if (is_null($v)) {
$data[$k] = '';
continue;
}
switch ((string) $k) {
case 'image':
$v['image_link'] = url('/a/image/' . $v);
break;
}
}
$url = './uploads/images/';
$param = $this->request->post();
if($this->request->hasFile('image') && $files->isValid()){
$filename = date('ymdHis').rand(10000,99999).$this->request->file('image');
$this->request->file('image')->move('./uploads/images/',$filename);
}else{
return false;
}
return $url.$filename;
return $data;
}
}
... ...
<?php
namespace App\Http\Controllers\Aside;
use App\Http\Logic\Aside\DemoLogic;
use App\Http\Requests\Aside\DemoRequest;
class DemoController extends BaseController
{
/**
* Deom控制器
* @param DemoRequest $request
* @param DemoLogic $logic
* @return \Illuminate\Http\JsonResponse
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
public function test(DemoRequest $request,DemoLogic $logic)
{
$request->validated();
$data=$logic->testLogic();
return $this->success($data);
}
}
<?php
namespace App\Http\Controllers\Aside\Devops;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\Devops\ServerConfigLogic;
use App\Http\Requests\Aside\Devops\ServerConfigRequest;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Illuminate\Validation\Rule;
/**
* 项目服务器、数据库配置
* Class ServerConfigController
* @package App\Http\Controllers\Aside
* @author zbj
* @date 2023/4/24
*/
class ServerConfigController extends BaseController
{
/**
* 保存配置
* @param ServerConfigRequest $request
* @param ServerConfigLogic $logic
* @author zbj
* @date 2023/4/23
*/
public function save(ServerConfigRequest $request, ServerConfigLogic $logic){
$data = $logic->save($this->param);
return $this->success($data);
}
/**
* 更新表结构
* @param ServerConfigLogic $logic
* @author zbj
* @date 2023/4/24
*/
public function updateDatabase(Request $request, ServerConfigLogic $logic){
$request->validate([
'type' => 'in:1,2,3',
'id'=> Rule::requiredIf($request->type == 1),
'sql' => ['required', function ($attribute, $value, $fail) {
if(Str::contains(Str::lower($value), ['drop', 'delete', 'truncate'])){
$fail('危险操作');
}
}]
],[
'id.required' => 'ID不能为空',
'sql.required' => '请输入Sql语句',
]);
switch ($this->param['type']){
case "1":
$data = $logic->updateTable($this->param);
break;
case "2":
$data = $logic->updateLocalTable($this->param);
break;
case "3":
$data = $logic->updateAllTable($this->param);
break;
}
return $this->success($data);
}
/**
* 更新代码
* @param ServerConfigLogic $logic
* @author zbj
* @date 2023/4/24
*/
public function updateCode(){
//todo
//C端
// $process = new Process(['git', 'pull']);
// $process->run();
// dump($process->getExitCodeText());
// dump($process->getExitCode());
// dump($process->getErrorOutput());
// $output = explode(PHP_EOL, $process->getOutput());
// dump($output);
// exit;
}
}
... ...
<?php
namespace App\Http\Controllers\Aside;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
/**
* Class IndexController
* @package App\Http\Controllers\Aside
* @author zbj
* @date 2023/4/19
*/
class IndexController extends Controller
{
/**
* 首页
* @param Request $request
* @return \Illuminate\Http\JsonResponse
*/
public function index(Request $request)
{
}
}
... ...
<?php
namespace App\Http\Controllers\Aside;
use App\Http\Logic\Aside\LoginLogic;
use App\Rules\Mobile;
use Illuminate\Http\Request;
/**
* Class LoginController
* @package App\Http\Controllers\Aside
* @author zbj
* @date 2023/4/19
*/
class LoginController extends BaseController
{
function login(Request $request, LoginLogic $logic)
{
if ($request->isMethod('POST')) {
$request->validate([
'mobile' => ['required', new Mobile()],
'password' => 'required',
], [
'mobile.required' => '请输入手机号',
'password.required' => '请输入密码',
]);
$logic->login();
return $this->success();
}
if($logic->manage()){
return redirect(route('admin.home.white'));
}
return view('admin.login');
}
public function logout(LoginLogic $logic)
{
return $logic->logout();
}
}
... ...
<?php
namespace App\Http\Controllers\Aside\Mail;
use App\Enums\Common\Code;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\Mail\MailLogic;
use App\Http\Requests\Aside\Mail\MailRequest;
use App\Models\Mail\Mail as MailModel;
/**
* @name:站内信
*/
class MailController extends BaseController
{
public function lists(){
$mailModel = new MailModel();
$lists = $mailModel->lists($this->map,$this->page,$this->row,$this->order);
$this->response('列表',Code::SUCCESS,$lists);
}
/**
* @name :详情
* @return void
* @author :liyuhang
* @method
*/
public function info(MailLogic $mailLogic){
$this->request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
$info = $mailLogic->mail_info();
$this->response('success',Code::SUCCESS,$info);
}
/**
* @name :添加站内信
* @return void
* @author :liyuhang
* @method
*/
public function add(MailRequest $mailRequest,MailLogic $mailLogic){
$mailRequest->validated();
$mailLogic->mail_add();
$this->response('success');
}
/**
* @name :编辑站内信
* @return void
* @author :liyuhang
* @method
*/
public function edit(MailRequest $mailRequest,MailLogic $mailLogic){
$mailRequest->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
$mailLogic->mail_edit();
$this->response('success');
}
/**
* @name :逻辑删除站内信
* @return void
* @author :liyuhang
* @method
*/
public function del(MailLogic $mailLogic){
$this->request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
$mailLogic->mail_del();
$this->response('success');
}
}
... ...
<?php
namespace App\Http\Controllers\Aside\Manage;
use App\Helper\Arr;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\Manage\DeptLogic;
use App\Http\Requests\Aside\Manage\DeptRequest;
use App\Rules\Ids;
use Illuminate\Http\Request;
/**
* Class DeptController
* @package App\Http\Controllers\Aside
* @author zbj
* @date 2023/4/20
*/
class DeptController extends BaseController
{
public function list(DeptLogic $logic)
{
$map = [];
if(!empty($this->param['search'])){
$map[] = ['title', 'like', "%{$this->param['search']}%"];
}
$sort = ['id' => 'desc'];
$data = $logic->getList($map, $sort, ['id', 'pid', 'title'],0);
return view("admin.dept", ["list" => Arr::listToTree($data)]);
}
public function info(Request $request, DeptLogic $logic){
$request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
$data = $logic->getInfo($this->param['id']);
return $this->success(Arr::twoKeepKeys($data, ['id', 'pid', 'title', 'manager_uids', 'remark']));
}
public function save(DeptRequest $request, DeptLogic $logic)
{
$data = $logic->save($this->param);
return $this->success($data);
}
public function delete(Request $request, DeptLogic $logic)
{
$request->validate([
'ids'=>['required', new Ids()]
],[
'ids.required' => 'ID不能为空'
]);
$data = $logic->delete($this->param['ids']);
return $this->success($data);
}
}
... ...
<?php
namespace App\Http\Controllers\Aside\Manage;
use App\Helper\Arr;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\Manage\GroupLogic;
use App\Http\Requests\Aside\Manage\GroupRequest;
use App\Rules\Ids;
use Illuminate\Http\Request;
/**
* 用户组
* Class Group
* @package App\Http\Controllers\Aside
* @author zbj
* @date 2023/4/19
*/
class GroupController extends BaseController
{
public function list(Request $request, GroupLogic $logic)
{
$list = $logic->getList();
return view("admin.group", ["list" => $list]);
}
public function info(Request $request, GroupLogic $logic){
$request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
$data = $logic->getInfo($this->param['id']);
return $this->success($data);
}
public function save(GroupRequest $request, GroupLogic $logic){
$data = $logic->save($this->param);
return $this->success($data);
}
public function delete(Request $request, GroupLogic $logic){
$request->validate([
'ids'=>['required', new Ids()]
],[
'ids.required' => 'ID不能为空'
]);
$data = $logic->delete($this->param['ids']);
return $this->success($data);
}
}
... ...
<?php
namespace App\Http\Controllers\Aside\Manage;
use App\Helper\Arr;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\Manage\ManageLogic;
use App\Http\Requests\Aside\Manage\ManageRequest;
use App\Rules\Ids;
use Illuminate\Http\Request;
/**
* 后台用户
* Class ManageController
* @package App\Http\Controllers\Aside
* @author zbj
* @date 2023/4/20
*/
class ManageController extends BaseController
{
public function list(Request $request, ManageLogic $logic)
{
$list = $logic->getList();
return view("admin.manage", ["list" => $list]);
}
public function info(Request $request, ManageLogic $logic){
$request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
$data = $logic->getInfo($this->param['id']);
return $this->success($data);
}
public function save(ManageRequest $request, ManageLogic $logic){
$data = $logic->save($this->param);
return $this->success($data);
}
public function delete(Request $request, ManageLogic $logic){
$request->validate([
'ids'=>['required', new Ids()]
],[
'ids.required' => 'ID不能为空'
]);
$data = $logic->delete($this->param['ids']);
return $this->success($data);
}
}
... ...
<?php
namespace App\Http\Controllers\Aside\Manage;
use App\Helper\Arr;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\Manage\MenuLogic;
use App\Http\Requests\Aside\Manage\MenuRequest;
use App\Rules\Ids;
use Illuminate\Http\Request;
/**
* 后台菜单
* Class MenuController
* @package App\Http\Controllers\Aside
* @author zbj
* @date 2023/4/19
*/
class MenuController extends BaseController
{
public function list(Request $request, MenuLogic $logic)
{
$map = [];
$sort = ['id' => 'desc'];
$list = $logic->getList($map, $sort, ['*'],0);
return view("admin.menu", ["list" => Arr::listToTree($list)]);
}
public function info(Request $request, MenuLogic $logic){
$request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
$data = $logic->getInfo($this->param['id']);
return $this->success($data);
}
public function save(MenuRequest $request, MenuLogic $logic){
$data = $logic->save($this->param);
return $this->success($data);
}
public function delete(Request $request, MenuLogic $logic){
$request->validate([
'ids'=>['required', new Ids()]
],[
'ids.required' => 'ID不能为空'
]);
$data = $logic->delete($this->param['ids']);
return $this->success($data);
}
}
... ...