作者 邓超

Merge branch 'develop' into dc

正在显示 53 个修改的文件 包含 3567 行增加523 行删除

要显示太多修改。

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

... ... @@ -3,6 +3,7 @@
/public/storage
/storage
/vendor
/uploads
.env
.env.backup
.phpunit.result.cache
... ... @@ -14,4 +15,6 @@ yarn-error.log
/.idea
/.vscode
composer.lock
app/Console/Commands/Test/Demo.php
/public/upload
/public/runtime
... ...
<?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 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 数据
config(['database.connections.custom_mysql.host' => $project->mysqlConfig()->host]);
config(['database.connections.custom_mysql.port' => $project->mysqlConfig()->port]);
config(['database.connections.custom_mysql.database' => $project->databaseName()]);
config(['database.connections.custom_mysql.username' => $project->mysqlConfig()->user]);
config(['database.connections.custom_mysql.password' => $project->mysqlConfig()->password]);
// TODO 创建对应库 初始化数据表
$this->initTable();
return true;
}
/**
* @return bool
*/
public function initTable()
{
// $table = DB::select('show tables');
// $table = array_column($table, 'Tables_in_globalso_dev');
// $table = DB::connection('custom_tmp_mysql')->select('show tables');
// $table_in = DB::connection('custom_tmp_mysql')->getDatabaseName();
// dd($table, $table_in);
$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\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;
}
}
... ...
... ... @@ -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,6 +114,8 @@ 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 = $code->description = Arr::first(Arr::first($exception->errors()));
... ... @@ -131,7 +136,6 @@ class Handler extends ExceptionHandler
//开启debug 错误原样输出
$debub = config('app.debug');
$message = $debub ? $message : ($code->description ?? $message);
$response = [
'code' => $code,
'message' => $message
... ...
<?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'=>$this->profile_key,
];
$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){
//平台参数处理
$this->headers['Accept-Encoding'] = 'gzip';
$this->headers['Authorization'] = $this->headers['Authorization'].$param['profile_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){
$param = [
'file'=>$data['file'],//base64编码
'fileName'=>$data['file_name'],//生成图片名称
'description'=>$data['description'],//描述
];
$this->headers['Authorization'] = $this->headers['Authorization'].$data['profile_key'];
$url = $this->path.'/api/media/upload';
return $this->http_click('posts',$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($multiArray) {
$flatArray = array();
foreach ($multiArray as $item) {
if (is_array($item)) {
$flatArray = array_merge($flatArray, uniqueMultiArray($item));
} else {
$flatArray[] = $item;
}
}
return array_map("unserialize", array_unique(array_map("serialize", $flatArray)));
}
}
... ...
<?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;
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;
define('HTTP_OPENAI_URL','http://openai.waimaoq.com/');
/**
* 生成路由标识
... ... @@ -7,23 +10,46 @@ define('HTTP_OPENAI_URL','http://openai.waimaoq.com/');
* @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)
function http_post($url, $post_data,$header = [])
{
$header = array(
"Accept: application/json",
"Content-Type:application/json;charset=utf-8",
);
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");
... ... @@ -50,10 +76,12 @@ if(!function_exists('http_get')){
* @param type $url
* @return type
*/
function http_get($url)
function http_get($url,$header = [])
{
$header[] = "content-type: application/x-www-form-urlencoded;
if(empty($header)){
$header[] = "content-type: application/json;
charset = UTF-8";
}
$ch1 = curl_init();
$timeout = 5;
curl_setopt($ch1, CURLOPT_URL, $url);
... ... @@ -91,68 +119,28 @@ if(!function_exists('_get_child')){
/**
* 把返回的数据集转换成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];
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);
}
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];
}
}
$host = $urlParts['host'] ?? '';
$scheme = $urlParts['scheme'] ?? 'https';
if(!in_array($scheme, ['http', 'https'])){
return false;
}
}
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));
if (preg_match('/^(?:[-A-Za-z0-9]+\.)+[A-Za-z]{2,6}$/', $host)) {
return $scheme . '://' . $host;
} else {
return false;
}
}
return $lists;
}
... ...
<?php
namespace App\Http\Controllers\Aside;
namespace App\Http\Controllers\Aside\Ai;
use App\Enums\Common\Code;
use App\Http\Controllers\Aside\BaseController;
use App\Models\AiCommand as AiCommandModel;
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
{
/**
... ... @@ -16,18 +22,35 @@ class AiCommandController extends BaseController
* @method
*/
public function lists(AiCommandModel $aiCommandModel){
$lists = $aiCommandModel->lists($this->map);
$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(Request $request,AiCommandLogic $aiCommandLogic){
$request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
$aiCommandLogic->ai_info();
$this->response('success');
}
/**
* @name
* @return void
* @author :liyuhang
* @method
*/
public function add(){
public function add(AiCommandRequest $request,AiCommandLogic $aiCommandLogic){
$request->validated();
$aiCommandLogic->ai_add();
$this->response('success');
}
/**
... ... @@ -36,8 +59,14 @@ class AiCommandController extends BaseController
* @author :liyuhang
* @method
*/
public function edit(){
public function edit(AiCommandRequest $request,AiCommandLogic $aiCommandLogic){
$request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
$aiCommandLogic->ai_edit();
$this->response('success');
}
/**
... ... @@ -46,7 +75,13 @@ class AiCommandController extends BaseController
* @author :liyuhang
* @method
*/
public function del(){
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;
namespace App\Http\Controllers\Aside\Ai;
class ProjectMenuController extends BaseController
use App\Enums\Common\Code;
use App\Http\Controllers\Aside\BaseController;
use App\Models\Ai\AiLog as AiLogModel;
class AiLogController extends BaseController
{
/**
* @name :用户菜单列表
* @name :ai日志列表
* @return void
* @author :liyuhang
* @method
*/
public function lists(){
public function lists(AiLogModel $aiLogModel){
$lists = $aiLogModel->lists($this->map,$this->page,$this->row,$this->order);
$this->response('success',Code::SUCCESS,$lists);
}
}
... ...
... ... @@ -34,20 +34,10 @@ class BaseController extends Controller
$info = Cache::get($this->token);
$this->user = $info;
$this->uid = $info['id'];
}else{
return response(['code'=>Code::USER_ERROR,'msg'=>'当前用户未登录']);
//参数处理
$this->get_param();
}
$this->get_param();
}
/**
* admin端用渲染 不走接口
* @return mixed
* @author zbj
* @date 2023/4/19
*/
public function manage(){
return Session::get('manage');
}
... ... @@ -75,8 +65,7 @@ class BaseController extends Controller
return response()->json($response,200,$this->header);
}
/**
* @name 参数过滤
* @return void
* @name :参数过滤
* @author :liyuhang
* @method
*/
... ... @@ -138,23 +127,12 @@ class BaseController extends Controller
/**
* 菜单权限->得到子级数组
* @param int
* @return array
* @param $data
* @name :返回参数统一处理
* @return array|string
* @author :liyuhang
* @method
*/
public function _get_child($my_id, $arr)
{
$new_arr = array();
foreach ($arr as $k => $v) {
$v = (array)$v;
if ($v['pid'] == $my_id) {
$v['sub'] = $this->_get_child($v['id'],$arr);
$new_arr[] = $v;
}
}
return $new_arr ? $new_arr : false;
}
protected function _extents($data) {
if (empty($data) || !is_array($data)) {
... ... @@ -170,7 +148,7 @@ class BaseController extends Controller
}
switch ((string) $k) {
case 'image':
$v['image_link'] = file_get_contents($v);
$v['image_link'] = url('/a/image/' . $v);
break;
}
}
... ...
<?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;
}
}
... ...
... ... @@ -31,6 +31,9 @@ class LoginController extends BaseController
return $this->success();
}
if($logic->manage()){
return redirect(route('admin.home.white'));
}
return view('admin.login');
}
... ...
<?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');
}
}
... ...
... ... @@ -4,8 +4,8 @@ namespace App\Http\Controllers\Aside\Manage;
use App\Helper\Arr;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\DeptLogic;
use App\Http\Requests\Aside\DeptRequest;
use App\Http\Logic\Aside\Manage\DeptLogic;
use App\Http\Requests\Aside\Manage\DeptRequest;
use App\Rules\Ids;
use Illuminate\Http\Request;
... ...
... ... @@ -4,8 +4,8 @@ namespace App\Http\Controllers\Aside\Manage;
use App\Helper\Arr;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\GroupLogic;
use App\Http\Requests\Aside\GroupRequest;
use App\Http\Logic\Aside\Manage\GroupLogic;
use App\Http\Requests\Aside\Manage\GroupRequest;
use App\Rules\Ids;
use Illuminate\Http\Request;
... ...
... ... @@ -4,8 +4,8 @@ namespace App\Http\Controllers\Aside\Manage;
use App\Helper\Arr;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\ManageLogic;
use App\Http\Requests\Aside\ManageRequest;
use App\Http\Logic\Aside\Manage\ManageLogic;
use App\Http\Requests\Aside\Manage\ManageRequest;
use App\Rules\Ids;
use Illuminate\Http\Request;
... ...
... ... @@ -4,8 +4,8 @@ namespace App\Http\Controllers\Aside\Manage;
use App\Helper\Arr;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\MenuLogic;
use App\Http\Requests\Aside\MenuRequest;
use App\Http\Logic\Aside\Manage\MenuLogic;
use App\Http\Requests\Aside\Manage\MenuRequest;
use App\Rules\Ids;
use Illuminate\Http\Request;
... ...
<?php
namespace App\Http\Controllers\Aside\Project;
use App\Helper\Arr;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\Project\ProjectLogic;
use App\Http\Requests\Aside\Project\ProjectRequest;
use App\Rules\Ids;
use Illuminate\Http\Request;
/**
* 项目管理
* Class ProjectController
* @package App\Http\Controllers\Aside\Project
* @author zbj
* @date 2023/4/25
*/
class ProjectController extends BaseController
{
public function list(ProjectLogic $logic)
{
$map = [];
if(!empty($this->param['search'])){
$map[] = ['title', 'like', "%{$this->param['search']}%"];
}
$sort = ['id' => 'desc'];
$data = $logic->getList($map, $sort);
return view("admin.project", ["list" => $data]);
}
public function info(Request $request, ProjectLogic $logic){
$request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
$data = $logic->getInfo($this->param['id']);
return $this->success($data);
}
public function save(ProjectRequest $request, ProjectLogic $logic)
{
$data = $logic->save($this->param);
return $this->success($data);
}
}
... ...
<?php
namespace App\Http\Controllers\Aside;
class ProjectRoleController extends BaseController
{
/**
* @name :列表
* @return void
* @author :liyuhang
* @method
*/
public function lists (){
}
}
<?php
namespace App\Http\Controllers\Aside\Task;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\Task\TaskFollowLogic;
use App\Http\Logic\Aside\Task\TaskLogic;
use App\Http\Requests\Aside\Task\TaskFollowRequest;
use App\Http\Requests\Aside\Task\TaskRequest;
use App\Models\Task\Task;
use Illuminate\Support\Facades\Request;
use Illuminate\Validation\Rule;
/**
* 工单管理
* Class TaskController
* @package App\Http\Controllers\Aside\Task
* @author zbj
* @date 2023/4/27
*/
class TaskController extends BaseController
{
public function list(TaskLogic $logic)
{
$map = [];
if(!empty($this->param['search'])){
$map[] = ['title', 'like', "%{$this->param['search']}%"];
}
$sort = ['id' => 'desc'];
$data = $logic->getList($map, $sort);
return view("admin.task", ["list" => $data]);
}
public function info(Request $request, TaskLogic $logic){
$request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
$data = $logic->getInfo($this->param['id']);
return $this->success($data);
}
public function save(TaskRequest $request, TaskLogic $logic)
{
$data = $logic->save($this->param);
return $this->success($data);
}
/**
* 修改状态
* @param Request $request
* @param TaskLogic $logic
* @author zbj
* @date 2023/4/27
*/
public function status(Request $request, TaskLogic $logic){
$request->validate([
'id'=>'required',
'status' => ['required', Rule::in(array_keys(Task::statusMap()))]
],[
'id.required' => 'ID不能为空',
'status.required' => '请选择状态',
'status.in' => '状态值不正确',
]);
$data = $logic->status($this->param['id'], $this->param['status']);
return $this->success($data);
}
/**
* 添加跟进记录
* @param TaskFollowRequest $request
* @param TaskFollowLogic $logic
* @author zbj
* @date 2023/4/27
*/
public function save_follow(TaskFollowRequest $request, TaskFollowLogic $logic){
$data = $logic->save($this->param);
return $this->success($data);
}
}
... ...
<?php
namespace App\Http\Controllers\Aside\User;
use App\Enums\Common\Code;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\User\ProjectGroupLogic;
use App\Http\Requests\Aside\User\ProjectGroupRequest;
use App\Models\ProjectGroup as ProjectGroupModel;
class ProjectGroupController extends BaseController
{
/**
* @name:用户组列表
*/
public function lists(ProjectGroupModel $projectGroupModel){
$lists = $projectGroupModel->lists($this->map,$this->page,$this->row,$this->order);
$this->response('success',Code::SUCCESS,$lists);
}
/**
* @name :添加用户组
* @return void
* @author :liyuhang
* @method
*/
public function add(ProjectGroupRequest $request,ProjectGroupLogic $projectGroupLogic){
$request->validated();
$projectGroupLogic->group_add();
$this->response('success');
}
/**
* @name :编辑用户组
* @return void
* @author :liyuhang
* @method
*/
public function edit(ProjectGroupRequest $request,ProjectGroupLogic $projectGroupLogic){
$request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
$projectGroupLogic->group_edit();
$this->response('success');
}
/**
* @name :用户组详情
* @return void
* @author :liyuhang
* @method
*/
public function info(ProjectGroupLogic $projectGroupLogic){
$this->request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
$projectGroupLogic->group_info();
$this->success('success');
}
/**
* @name :删除用户组
* @return void
* @author :liyuhang
* @method
*/
public function del(ProjectGroupLogic $projectGroupLogic){
$this->request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
$projectGroupLogic->group_del();
$this->success('success');
}
}
... ...
<?php
namespace App\Http\Controllers\Aside\User;
use App\Enums\Common\Code;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\User\ProjectMenuLogic;
use App\Http\Requests\Aside\User\ProjectRoleRequest;
use App\Models\User\ProjectMenu;
use App\Models\User\ProjectMenu as ProjectMenuModel;
use Illuminate\Http\Request;
class ProjectMenuController extends BaseController
{
/**
* @name :用户菜单列表
* @return json
* @author :liyuhang
* @method
*/
public function lists(){
$menuModel = new ProjectMenuModel();
$lists = $menuModel->lists($this->map,$this->page,$this->row,$this->order,['*']);
$this->response('success',Code::SUCCESS,$lists);
}
/**
* @name :详情
* @return void
* @author :liyuhang
* @method
*/
public function info(ProjectMenuLogic $projectMenuLogic){
$this->request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
$info = $projectMenuLogic->menu_info();
$this->response('success',Code::SUCCESS,$info);
}
/**
* @name :添加菜单
* @return void
* @author :liyuhang
* @method
*/
public function add(ProjectRoleRequest $request,ProjectMenuLogic $projectMenuLogic){
$request->validated();
$projectMenuLogic->menu_add();
$this->response('success');
}
/**
* @name :编辑菜单
* @return void
* @author :liyuhang
* @method
*/
public function edit(ProjectRoleRequest $request,ProjectMenuLogic $projectMenuLogic){
$request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
$projectMenuLogic->menu_edit();
$this->response('success');
}
/**
* @name :删除菜单
* @return void
* @author :liyuhang
* @method
*/
public function del(ProjectMenuLogic $projectMenuLogic){
$this->request->validate([
'id'=>['required','array'],
],[
'id.required' => 'ID不能为空',
'id.array' => 'ID为数组',
]);
$projectMenuLogic->menu_del();
$this->response('success');
}
}
... ...
<?php
namespace App\Http\Controllers\Aside\User;
use App\Enums\Common\Code;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\User\ProjectRoleLogic;
use App\Http\Requests\Aside\User\ProjectRoleRequest;
use App\Models\User\ProjectRole as ProjectRoleModel;
use Illuminate\Http\Request;
class ProjectRoleController extends BaseController
{
/**
* @name :列表
* @return json
* @author :liyuhang
* @method
*/
public function lists (){
$roleModel = new ProjectRoleModel();
$lists = $roleModel->lists($this->map,$this->page,$this->row,$this->order,['*']);
$this->response('success',Code::SUCCESS,$lists);
}
/**
* @name :详情
* @return void
* @author :liyuhang
* @method
*/
public function info(ProjectRoleLogic $roleLogic){
$this->request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
//TODO::详情
$roleLogic->role_info();
$this->response('success');
}
/**
* @name :添加角色时获取菜单列表
* @return void
* @author :liyuhang
* @method
*/
public function get_menu(ProjectRoleLogic $roleLogic){
$list = $roleLogic->role_get_menu();
$this->response('success',Code::SUCCESS,$list);
}
/**
* @name :添加角色
* @return void
* @author :liyuhang
* @method
*/
public function add(ProjectRoleRequest $request,ProjectRoleLogic $roleLogic){
$request->validated();
//TODO::添加
$roleLogic->role_add();
$this->response('success');
}
/**
* @name :编辑角色
* @return void
* @author :liyuhang
* @method
*/
public function edit(ProjectRoleRequest $request,ProjectRoleLogic $roleLogic){
$request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
//TODO::编辑
$roleLogic->role_edit();
$this->response('success');
}
/**
* @name :删除角色
* @return void
* @author :liyuhang
* @method
*/
public function del(ProjectRoleLogic $roleLogic){
$this->request->validate([
'id'=>['required','array'],
],[
'id.required' => 'ID不能为空',
'id.array' => 'ID为数组',
]);
$roleLogic->role_del();
//TODO::删除
$this->response('success');
}
}
... ...
<?php
namespace App\Http\Controllers\Aside\User;
use App\Enums\Common\Code;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\User\UserLogic;
use App\Http\Requests\Aside\User\UserRequest;
use App\Models\User\User as UserModel;
use Illuminate\Http\Request;
class ProjectUserController extends BaseController
{
/**
* @name :用户列表
* @return void
* @author :liyuhang
* @method
*/
public function lists(){
$userModel = new UserModel();
$lists = $userModel->lists($this->map,$this->page,$this->row,$this->order,
['id','mobile','name','created_at','updated_at','image','operator_id']);
$this->response('列表',Code::SUCCESS,$lists);
}
/**
* @name :详情
* @return void
* @author :liyuhang
* @method
*/
public function info(UserLogic $userLogic){
$this->request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
$userLogic->user_info();
$this->response('success');
}
/**
* @name :添加用户
* @return void
* @author :liyuhang
* @method
*/
public function add(UserRequest $request,UserLogic $userLogic){
$request->validated();
$userLogic->user_add();
$this->response('success');
}
/**
* @name : 编辑
* @return void
* @author :liyuhang
* @method
*/
public function edit(UserRequest $request,UserLogic $userLogic){
$request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
$userLogic->user_edit();
$this->response('success');
}
/**
* @name :批量删除
* @return void
* @author :liyuhang
* @method
*/
public function del(UserLogic $userLogic){
$this->request->validate([
'id'=>['required','array'],
],[
'id.required' => 'ID不能为空',
'id.array' => 'ID为数组',
]);
$userLogic->user_del();
$this->response('success');
}
}
... ...
<?php
namespace App\Http\Controllers\Bside;
namespace App\Http\Controllers\Bside\Ai;
use App\Enums\Common\Code;
use Illuminate\Http\Request;
use App\Helper\Common;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Controllers\Bside\:写入日志;
use App\Models\Ai\AiLog;
class AiCommandController extends BaseController
{
//获取文本内容
public $chat_url = 'v2/openai_chat';
/**
* @name :ai生成
... ... @@ -14,8 +18,8 @@ class AiCommandController extends BaseController
* @author :liyuhang
* @method
*/
public function ai_http_post(Request $request){
$request->validate([
public function ai_http_post(){
$this->request->validate([
'keywords'=>['required'],
'key'=>['required']
],[
... ... @@ -23,7 +27,31 @@ class AiCommandController extends BaseController
'key.required' => '场景不能为空',
]);
#TODO 通过key获取到ai指令对象
$data = $this->send_openai_msg($this->chat_url);
$data = Common::send_openai_msg($this->chat_url,$this->param);
$param = [
'key'=>$this->param['key'],
'keywords'=>$this->param['keywords'],
'remark'=>json_encode($data)
];
$this->set_ai_log($param);
$this->response('success',Code::SUCCESS,$data);
}
/**
* @name :写入日志
* @return void
* @author :liyuhang
* @method
*/
public function set_ai_log($data){
//写入日志
$param = [
'key'=> $this->param['key'],
'keywords'=>$this->param['keywords'],
'remark' =>$data['remark'],
'operator_id'=>$this->uid
];
$aiLog = new AiLog();
return $aiLog->add($param);
}
}
... ...
<?php
namespace App\Http\Controllers\Bside\AyrShare;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\AyrShare\AyrReleaseLogic;
/**
* @name:社交发布
*/
class AyrReleaseController extends BaseController
{
/**
* @name :(发布社交)send_post
* @author :lyh
* @method :post
* @time :2023/5/9 9:36
*/
public function send_post(AyrReleaseLogic $ayrReleaseLogic){
//保存数据库
$ayrReleaseLogic->release_add();
}
}
... ...
<?php
namespace App\Http\Controllers\Bside\AyrShare;
use App\Enums\Common\Code;
use App\Helper\AyrShare as AyrShareHelper;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\AyrShare\AyrShareLogic;
use App\Models\AyrShare\AyrShare as AyrShareModel;
/**
* @name:社交绑定
*/
class AyrShareController extends BaseController
{
/**
* @name :(社交列表)lists
* @author :lyh
* @method :post
* @time :2023/5/5 16:06
*/
public function lists(AyrShareModel $ayrShareModel){
$lists = $ayrShareModel->lists($this->map,$this->page,$this->row,'id',['*']);
$ayrShareHelper = new AyrShareHelper();
foreach ($lists['list'] as $k=>$v){
$lists['list'][$k]['ayr'] = $ayrShareHelper->get_profiles_users($v['profile_key']);
}
$this->response('列表',Code::SUCCESS,$lists);
}
/**
* @name :(创建ayr_share账户)create_account
* @author :lyh
* @method :post
* @time :2023/5/5 16:44
*/
public function create_account(AyrShareLogic $ayrShareLogic){
$param = [
'title'=>md5(uniqid().time()),
];
//发送请求注册社交用户
$ayrShareHelper = new AyrShareHelper();
$res = $ayrShareHelper->post_create_profiles($param);
if($res['status'] == 'fail'){
$this->response('同步绑定失败');
}
//执行数据库操作
$ayrShareLogic->ayr_share_add($res);
$this->response('success');
}
/**
* @name :(删除用户账号并同步ayr_share账号)edit_account
* @author :lyh
* @method :post
* @time :2023/5/6 10:11
*/
public function del_account(AyrShareLogic $ayrShareLogic){
$this->request->validate([
'id'=>['required']
],[
'id.required' => 'ID不能为空'
]);
$info = $ayrShareLogic->ayr_share_info();
$data = [
'title'=>$info['title'],
'profileKey'=>$info['profile_key']
];
//发送请求注册社交用户
$ayrShareHelper = new AyrShareHelper();
$res = $ayrShareHelper->deleted_profiles($data);
if($res['status'] == 'fail'){
$this->response('同步删除失败');
}
$ayrShareLogic->ayr_share_del();
$this->response('success');
}
/**
* @name :(授权绑定第三方平台,生成jwt令牌)ayr_share_bind
* @author :lyh
* @method :post
* @time :2023/5/6 10:24
*/
public function bind_account(AyrShareLogic $ayrShareLogic){
$this->request->validate([
'id'=>['required']
],[
'id.required' => 'ID不能为空'
]);
$info = $ayrShareLogic->ayr_share_info();
//发送请求注册社交用户
$ayrShareHelper = new AyrShareHelper();
$data = [
'profileKey'=>$info['profile_key']
];
$res = $ayrShareHelper->post_generate_jwt($data);
if($res['status'] == 'fail'){
$this->response($res['message'],Code::USER_ERROR);
}
$this->response('success',Code::SUCCESS,$res);
}
}
... ...
... ... @@ -3,8 +3,9 @@
namespace App\Http\Controllers\Bside;
use App\Enums\Common\Code;
use App\Helper\Common;
use App\Http\Controllers\Controller;
use App\Models\AiCommand as AiCommandModel;
use App\Models\User\User as UserModel;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Exceptions\HttpResponseException;
... ... @@ -34,33 +35,21 @@ class BaseController extends Controller
$info = Cache::get($this->token);
$this->user = $info;
$this->uid = $info['id'];
}else{
throw new HttpResponseException(response(['code'=>Code::USER_ERROR,'msg'=>'当前用户未登录']));
//参数处理
$this->get_param();
//日志记录
$this->set_user_log();
}
$this->get_param();
}
/**
* 成功返回
* @param array $data
* @param string $code
* @param bool $objectData
* @return JsonResponse
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
* @name :ceshi
* @author :lyh
* @method :post
* @time :2023/5/9 11:43
*/
function success(array $data = [], string $code = Code::SUCCESS, bool $objectData = false): JsonResponse
{
if ($objectData) {
$data = (object)$data;
}
$code = Code::fromValue($code);
$response = [
'code' => $code->value,
'data' => $data,
'msg' => $code->description,
];
$this->header['token'] = $this->token;
return response()->json($response,200,$this->header);
public function ceshi(){
}
/**
* @name 参数过滤
... ... @@ -84,26 +73,38 @@ class BaseController extends Controller
case 'row':
$this->row = $v;
break;
case "status":
$this->map['status'] = $v;
break;
case "category_id":
$this->map['category_id'] = $v;
break;
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['created_at'] = ['between', $this->_btw];
if(!empty($v)){
$this->_btw[0] = $v;
$this->_btw[1] = date('Y-m-d H:i:s',time());
$this->map['created_at'] = ['between', $this->_btw];
}
break;
case "end_at":
$this->_btw[1] = $v;
$this->map['updated_at'] = ['between', $this->_btw];
if(!empty($v)){
$this->_btw[1] = $v;
$this->map['updated_at'] = ['between', $this->_btw];
}
break;
default:
$this->map[$k] = $v;
if(!empty($v)){
$this->map[$k] = $v;
}
break;
}
}
}
/**
* @name 统一返回参数
* @name :统一返回参数
* @return JsonResponse
* @author :liyuhang
* @method
... ... @@ -122,25 +123,34 @@ class BaseController extends Controller
throw new HttpResponseException($response);
}
/**
* 菜单权限->得到子级数组
* @param int
* @return array
* 成功返回
* @param array $data
* @param string $code
* @param bool $objectData
* @return JsonResponse
*/
public function _get_child($my_id, $arr)
function success(array $data = [], string $code = Code::SUCCESS, bool $objectData = false): JsonResponse
{
$new_arr = array();
foreach ($arr as $k => $v) {
$v = (array)$v;
if ($v['pid'] == $my_id) {
$v['sub'] = $this->_get_child($v['id'],$arr);
$new_arr[] = $v;
}
if ($objectData) {
$data = (object)$data;
}
return $new_arr ? $new_arr : false;
$code = Code::fromValue($code);
$response = [
'code' => $code->value,
'data' => $data,
'msg' => $code->description,
];
$this->header['token'] = $this->token;
return response()->json($response,200,$this->header);
}
/**
* @param $data
* @name :返回参数处理
* @return array|string
* @author :liyuhang
* @method
*/
protected function _extents($data) {
if (empty($data) || !is_array($data)) {
... ... @@ -154,10 +164,20 @@ class BaseController extends Controller
$data[$k] = '';
continue;
}
//获取操作人
switch ((string) $k) {
case 'image':
$data['image_link'] = url('/b/image/' . $v);
break;
case 'file':
$data['file_link'] = url('/b/file_hash/' . $v);
break;
case 'operator_id':
if(!empty($v)){
$name = (new UserModel())->read(['operator_id'=>$v],['id','name']);
$data['operator_name'] = (isset($name['name']) && !empty($name['name'])) ? $name['name'] : '无名称';
}
break;
}
}
}
... ... @@ -165,27 +185,19 @@ class BaseController extends Controller
}
/**
* @name :ai自动生成
* @return mixed
* @name :写入操作日志
* @return void
* @author :liyuhang
* @method
*/
public function send_openai_msg($url){
$url = HTTP_OPENAI_URL.$url;
$aiCommandModel = New AiCommandModel();
//指定库获取指令
$info = $aiCommandModel->read(['key'=>$this->param['key']]);
if($info === false){
$this->response('指令不存在',Code::USER_ERROR);
public function set_user_log(){
//生成日志
$log = config('logging.operator_log');
if(isset($log) && $log['log'] == true){
if(empty($log['action']) || (strpos($log['action'],$this->request->route()->getName()) < 0)){
Common::set_user_log(['model'=>$this->request->route()->getName(),'remark'=>'请求的参数:param = '.json_encode($this->param),'operator_id'=>$this->uid]);
}
}
//替换关键字
$content = str_replace('$keyword$', $this->param['keywords'], $info['ai']);
$data = [
'messages'=>[
['role'=>'system','content'=>$info['scene']],
['role'=>'assistant','content'=>$content],
]
];
return http_post($url,json_encode($data));
return true;
}
}
... ...
... ... @@ -8,7 +8,6 @@ use App\Http\Logic\Bside\Blog\BlogCategoryLogic;
use App\Http\Requests\Bside\Blog\BlogCategoryRequest;
use App\Models\Blog\Blog as BlogModel;
use App\Models\Blog\BlogCategory as BlogCategoryModel;
use Illuminate\Http\Request;
class BlogCategoryController extends BaseController
{
... ... @@ -21,7 +20,15 @@ class BlogCategoryController extends BaseController
public function lists(BlogCategoryModel $blogCategoryModel){
//搜索条件
$this->map['project_id'] = $this->user['project_id'];
$lists = $blogCategoryModel->lists($this->map,$this->page,$this->row);
$lists = $blogCategoryModel->lists($this->map,$this->page,$this->row,$this->order,
['id','pid','name','num','alias','status','sort','remark','created_at','updated_at']);
if(!empty($lists['list'])){
$blogModel = new BlogModel();
foreach ($lists['list'] as $k => $v){
$v['num'] = $blogModel->formatQuery(['category_id'=>['like','%,' . $v['id'] . ',%']])->count();
$lists['list'][$k] = $v;
}
}
$this->response('success',Code::SUCCESS,$lists);
}
... ... @@ -31,8 +38,8 @@ class BlogCategoryController extends BaseController
* @author :liyuhang
* @method
*/
public function info(Request $request,BlogCategoryLogic $blogCategoryLogic){
$request->validate([
public function info(BlogCategoryLogic $blogCategoryLogic){
$this->request->validate([
'id'=>['required']
],[
'id.required' => 'ID不能为空'
... ... @@ -76,8 +83,8 @@ class BlogCategoryController extends BaseController
* @author :liyuhang
* @method
*/
public function status(Request $request,BlogCategoryLogic $blogCategoryLogic){
$request->validate([
public function status(BlogCategoryLogic $blogCategoryLogic){
$this->request->validate([
'id'=>['required'],
],[
'id.required' => 'ID不能为空',
... ... @@ -92,11 +99,12 @@ class BlogCategoryController extends BaseController
* @author :liyuhang
* @method
*/
public function del(Request $request,BlogCategoryLogic $blogCategoryLogic){
$request->validate([
'id'=>['required'],
public function del(BlogCategoryLogic $blogCategoryLogic){
$this->request->validate([
'id'=>['required','array'],
],[
'id.required' => 'ID不能为空',
'id.array' => 'ID为数组',
]);
$blogCategoryLogic->del_blog_category();
//TODO::写入操作日志
... ...
... ... @@ -4,11 +4,12 @@ namespace App\Http\Controllers\Bside\Blog;
use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Blog\BlogCategoryLogic;
use App\Http\Logic\Bside\Blog\BlogLabelLogic;
use App\Http\Logic\Bside\Blog\BlogLogic;
use App\Http\Requests\Bside\Blog\BlogRequest;
use App\Models\Blog\Blog as BlogModel;
use App\Models\Blog\BlogCategory as BlogCategoryModel;
use Illuminate\Http\Request;
class BlogController extends BaseController
{
/**
... ... @@ -17,21 +18,17 @@ class BlogController extends BaseController
* @author :liyuhang
* @method
*/
public function lists(BlogModel $blogModel){
public function lists(BlogModel $blogModel,BlogCategoryLogic $blogCategoryLogic,BlogLabelLogic $blogLabelLogic){
//搜索条件
$this->map['project_id'] = $this->user['project_id'];
$lists = $blogModel->lists($this->map,$this->page,$this->row);
$lists = $blogModel->lists($this->map,$this->page,$this->row,$this->order,
['id','category_id','operator_id','status','created_at','label_id','image','updated_at','name','sort','url']);
if(!empty($lists['list'])){
foreach ($lists['list'] as $k => $v){
$blogCategoryModel= new BlogCategoryModel();
//获取用户已读还是未读
$category_info = $blogCategoryModel->
list(['id'=>['in',explode(',',trim($v['category_id'],','))]],'id',['name']);
$str = '';
foreach ($category_info as $v1){
$str .= $v1['name'].',';
}
$v['category_id'] = trim($str,',');
//获取分类名称
$v = $blogCategoryLogic->get_category_name($v);
//获取标签名称
$v = $blogLabelLogic->get_label_name($v);
$lists['list'][$k] = $v;
}
}
... ... @@ -55,8 +52,8 @@ class BlogController extends BaseController
* @author :liyuhang
* @method
*/
public function info(Request $request,BlogLogic $blogLogic){
$request->validate([
public function info(BlogLogic $blogLogic){
$this->request->validate([
'id'=>['required']
],[
'id.required' => 'ID不能为空'
... ... @@ -95,55 +92,58 @@ class BlogController extends BaseController
}
/**
* @name :编辑博客状态/排序
* @name :编辑新闻seo
* @return void
* @author :liyuhang
* @method
*/
public function status(Request $request,BlogLogic $blogLogic){
$request->validate([
public function edit_seo(BlogLogic $blogLogic){
$this->request->validate([
'id'=>['required'],
'seo_title'=>['required'],
'seo_description'=>['required'],
'seo_keywords'=>['required'],
],[
'id.required' => 'ID不能为空',
'seo_title.required' => 'seo_title不能为空',
'seo_description.required' => 'seo_description不能为空',
'seo_keywords.required' => 'seo_description不能为空',
]);
$blogLogic->blog_status();
//TODO::写入日志
$blogLogic->edit_seo();
$this->response('success');
}
/**
* @name :删除博客(批量逻辑删除)
* @name :编辑博客状态/排序
* @return void
* @author :liyuhang
* @method
*/
public function del(Request $request,BlogLogic $blogLogic){
$request->validate([
public function status(BlogLogic $blogLogic){
$this->request->validate([
'id'=>['required'],
],[
'id.required' => 'ID不能为空',
]);
$blogLogic->blog_del();
$blogLogic->blog_status();
//TODO::写入日志
$this->response('success');
}
/**
* @name :ai生成
* @name :删除博客(批量逻辑删除)
* @return void
* @author :liyuhang
* @method
*/
public function ai_blog(Request $request){
$request->validate([
'keywords'=>['required'],
'key'=>['required']
public function del(BlogLogic $blogLogic){
$this->request->validate([
'id'=>['required','array'],
],[
'keywords.required' => '关键字不能为空',
'key.required' => '场景不能为空',
'id.required' => 'ID不能为空',
'id.array' => 'ID为数组',
]);
#TODO 通过key获取到ai指令对象
$url = 'v2/openai_chat';
$data = $this->send_openai_msg($url);
$this->response('success',Code::SUCCESS,$data);
$blogLogic->blog_del();
$this->response('success');
}
}
... ...
... ... @@ -59,13 +59,13 @@ class BlogLabelController extends BaseController
* @author :liyuhang
* @method
*/
public function status(Request $request,BlogLabelLogic $blogLabelLogic){
$request->validate([
public function status(BlogLabelLogic $blogLabelLogic){
$this->request->validate([
'id'=>['required'],
],[
'id.required' => 'ID不能为空',
]);
$blogLabelLogic->edit_blog_label();
$blogLabelLogic->status_blog_label();
//TODO::写入日志
$this->response('success');
}
... ... @@ -76,11 +76,12 @@ class BlogLabelController extends BaseController
* @author :liyuhang
* @method
*/
public function del(Request $request,BlogLabelLogic $blogLabelLogic){
$request->validate([
'id'=>['required'],
public function del(BlogLabelLogic $blogLabelLogic){
$this->request->validate([
'id'=>['required','array'],
],[
'id.required' => 'ID不能为空',
'id.array' => 'ID为数组',
]);
$blogLabelLogic->del_blog_label();
$this->response('success');
... ...
... ... @@ -3,13 +3,15 @@
namespace App\Http\Controllers\Bside;
use App\Enums\Common\Code;
use App\Models\Project;
use App\Models\Project as ProjectModel;
use App\Models\ProjectMenu as ProjectMenuModel;
use App\Models\ProjectRole as ProjectRoleModel;
use App\Models\User as UserModel;
use App\Helper\Country;
use App\Models\Project\Project;
use App\Models\Project\Project as ProjectModel;
use App\Models\User\ProjectMenu as ProjectMenuModel;
use App\Models\User\ProjectRole as ProjectRoleModel;
use App\Models\User\User as UserModel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
/***
* 当前为公共类 所有方法均不需要验证登录token
*/
... ... @@ -21,8 +23,8 @@ class ComController extends BaseController
* @author :liyuhang
* @method
*/
public function login(Request $request){
$request->validate([
public function login(){
$this->request->validate([
'mobile'=>['required'],
'password'=>['required'],
],[
... ... @@ -56,7 +58,7 @@ class ComController extends BaseController
foreach ($lists as $k => $v){
$v = (array)$v;
if ($v['pid'] == 0) {
$v['sub'] = $this->_get_child($v['id'], $lists);
$v['sub'] = _get_child($v['id'], $lists);
$menu[] = $v;
}
}
... ... @@ -83,8 +85,8 @@ class ComController extends BaseController
* @author :liyuhang
* @method
*/
public function edit_info(Request $request){
$request->validate([
public function edit_info(){
$this->request->validate([
'password'=>['required'],
'name'=>['required'],
],[
... ... @@ -114,4 +116,8 @@ class ComController extends BaseController
$this->response('success');
}
public function get_country(){
$country = new Country();
return $country->set_country();
}
}
... ...
... ... @@ -21,7 +21,7 @@ class FileController extends BaseController
*/
public function upload(Request $request){
// 上传文件
$files = Upload::puts('files', $this->param['config']);
$files = Upload::puts('files', $this->param['config'] ?? 'default');
foreach ($files as &$file){
$file = Upload::path2url($file);
}
... ... @@ -36,7 +36,7 @@ class FileController extends BaseController
* @date 2023/4/20
*/
public function download(Request $request){
$path = Upload::url2path($this->param['url']);
$path = Upload::url2path($this->param['url'] ?? '');
return Storage::disk('upload')->download($path);
}
}
... ...
<?php
namespace App\Http\Controllers\Bside;
use App\Exceptions\BsideGlobalException;
use App\Helper\Arr;
use App\Http\Logic\Bside\InquiryLogic;
use App\Http\Requests\Bside\InquiryRequest;
use App\Rules\Ids;
use App\Services\BatchExportService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Illuminate\Validation\ValidationException;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
/**
* 精准询盘
* Class InquiryController
* @package App\Http\Controllers\Bside
* @author zbj
* @date 2023/5/4
*/
class InquiryController extends BaseController
{
public function index(InquiryLogic $logic)
{
$map = [];
if(!empty($this->param['search'])){
$map[] = ['name|email|content', 'like', "%{$this->param['search']}%"];
}
$sort = ['id' => 'desc'];
$data = $logic->getList($map, $sort, ['id', 'name', 'email', 'phone', 'url', 'ip', 'ip_country', 'status', 'created_at']);
return $this->success($data);
}
public function info(Request $request, InquiryLogic $logic){
$request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
$data = $logic->getInfo($this->param['id']);
return $this->success(Arr::twoKeepKeys($data, ['id', 'name', 'email', 'phone', 'url', 'ip', 'ip_country', 'status', 'content', 'trans_content', 'created_at']));
}
public function delete(Request $request, InquiryLogic $logic)
{
$request->validate([
'ids'=>['required', new Ids()]
],[
'ids.required' => 'ID不能为空'
]);
$data = $logic->delete($this->param['ids']);
return $this->success($data);
}
/**
* 导出
* @param InquiryLogic $logic
* @return \Illuminate\Http\JsonResponse
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
* @author zbj
* @date 2023/5/8
*/
public function export(InquiryLogic $logic)
{
$sort = ['id' => 'desc'];
//最多到1w条
$data = $logic->getList([], $sort, ['name', 'email', 'phone', 'url', 'ip', 'ip_country', 'content', 'created_at'], 10000);
$data = $data['list'] ?? [];
foreach ($data as &$item){
$item['ip_address'] = "{$item['ip_country']}({$item['ip']})";
}
$map = [
'created_at' => '询盘发送时间',
'name' => '姓名',
'email' => '邮箱',
'phone' => '电话',
'ip_address' => '访问国家/地区(IP)',
'url' => '发送页面',
'content' => '询盘内容',
];
//生成文件,发送到客户端
$table = new BatchExportService("询盘数据导出");
$file = $table->head($map)->data($data)->save();
if (!$file) {
throw new \Exception('文件生成失败,请重试');
}
$fileurl = Storage::disk('runtime')->url($file);
// return Storage::disk('runtime')->download($file); //直接下载
return $this->success(['url' => $fileurl]);
}
}
... ...
<?php
namespace App\Http\Controllers\Bside;
namespace App\Http\Controllers\Bside\Mail;
use App\Enums\Common\Code;
use App\Http\Logic\Bside\MailLogic;
use App\Models\Mail as MailModel;
use App\Models\MailUser as MailUserModel;
use Illuminate\Http\Request;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Mail\MailLogic;
use App\Models\Mail\Mail as MailModel;
use App\Models\Mail\MailUser as MailUserModel;
class MailController extends BaseController
{
... ... @@ -22,7 +22,7 @@ class MailController extends BaseController
$mailModel = new MailModel();
//获取当前用户下的所有站内信
$this->map['user_list'] = ['like','%,'.$this->uid.',%'];
$this->map['status'] = $this::STATUS_ZERO;
$this->map['user_list'] = ['or',null];
$lists = $mailModel->lists($this->map,$this->page,$this->row);
if(!empty($lists['list'])){
foreach ($lists['list'] as $k => $v){
... ... @@ -46,8 +46,8 @@ class MailController extends BaseController
* @author :liyuhang
* @method
*/
public function info(Request $request,MailLogic $mailLogic){
$request->validate([
public function info(MailLogic $mailLogic){
$this->request->validate([
'id'=>['required']
],[
'id.required' => 'ID不能为空'
... ...
... ... @@ -6,8 +6,8 @@ use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\News\NewsCategoryLogic;
use App\Http\Requests\Bside\News\NewsCategoryRequest;
use App\Models\News\News as NewsModel;
use App\Models\News\NewsCategory as NewsCategoryModel;
use Illuminate\Http\Request;
class NewsCategoryController extends BaseController
{
... ... @@ -20,7 +20,15 @@ class NewsCategoryController extends BaseController
public function lists(NewsCategoryModel $newsCategory){
//搜索条件
$this->map['project_id'] = $this->user['project_id'];
$lists = $newsCategory->lists($this->map,$this->page,$this->row,'sort');
$lists = $newsCategory->lists($this->map,$this->page,$this->row,$this->order,
['id','pid','name','num','alias','status','sort','remark','created_at','updated_at']);
if(!empty($lists['list'])){
$newsModel = new NewsModel();
foreach ($lists['list'] as $k => $v){
$v['num'] = $newsModel->formatQuery(['category_id'=>['like','%,' . $v['id'] . ',%']])->count();
$lists['list'][$k] = $v;
}
}
$this->response('success',Code::SUCCESS,$lists);
}
... ... @@ -30,8 +38,8 @@ class NewsCategoryController extends BaseController
* @author :liyuhang
* @method
*/
public function info(Request $request,NewsCategoryLogic $newsCategoryLogic){
$request->validate([
public function info(NewsCategoryLogic $newsCategoryLogic){
$this->request->validate([
'id'=>['required']
],[
'id.required' => 'ID不能为空'
... ... @@ -49,8 +57,7 @@ class NewsCategoryController extends BaseController
$request->validated();
//添加时,验证分类上级分类是否有,有则更新到当前分类中,没有时直接添加
$newsCategoryLogic->add_news_category();
//TODO::写入日志
$this->response('success',Code::SUCCESS,[]);
$this->response('success');
}
/**
... ... @@ -66,7 +73,6 @@ class NewsCategoryController extends BaseController
'id.required' => 'ID不能为空'
]);
$newsCategoryLogic->edit_news_category();
//TODO::写入日志
$this->response('success');
}
... ... @@ -76,8 +82,8 @@ class NewsCategoryController extends BaseController
* @author :liyuhang
* @method
*/
public function status(Request $request,NewsCategoryLogic $newsCategoryLogic){
$request->validate([
public function status(NewsCategoryLogic $newsCategoryLogic){
$this->request->validate([
'id'=>['required'],
],[
'id.required' => 'ID不能为空',
... ... @@ -92,11 +98,12 @@ class NewsCategoryController extends BaseController
* @author :liyuhang
* @method
*/
public function del(Request $request,NewsCategoryLogic $newsCategoryLogic){
$request->validate([
'id'=>['required'],
public function del(NewsCategoryLogic $newsCategoryLogic){
$this->request->validate([
'id'=>['required','array'],
],[
'id.required' => 'ID不能为空',
'id.array' => 'ID为数组',
]);
$newsCategoryLogic->del_news_category();
$this->response('success');
... ...
... ... @@ -3,11 +3,12 @@
namespace App\Http\Controllers\Bside\News;
use App\Enums\Common\Code;
use App\Helper\Common;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\News\NewsCategoryLogic;
use App\Http\Logic\Bside\News\NewsLogic;
use App\Http\Requests\Bside\News\NewsRequest;
use App\Models\News\News as NewsModel;
use App\Models\News\NewsCategory as NewsCategoryModel;
use Illuminate\Http\Request;
/**
... ... @@ -21,20 +22,13 @@ class NewsController extends BaseController
* @author :liyuhang
* @method
*/
public function lists(NewsModel $news){
public function lists(NewsModel $news,NewsCategoryLogic $newsCategoryLogic){
$this->map['project_id'] = $this->user['project_id'];
$lists = $news->lists($this->map,$this->page,$this->row,$this->order);
$lists = $news->lists($this->map,$this->page,$this->row,$this->order,
['id','category_id','operator_id','status','created_at','updated_at','image','name','sort','url']);
if(!empty($lists['list'])){
foreach ($lists['list'] as $k => $v){
$newsCategoryModel= new NewsCategoryModel();
//获取用户已读还是未读
$category_info = $newsCategoryModel->
list(['id'=>['in',explode(',',trim($v['category_id'],','))]],'id',['name']);
$str = '';
foreach ($category_info as $v1){
$str .= $v1['name'].',';
}
$v['category_id'] = trim($str,',');
$v = $newsCategoryLogic->get_category_name($v);
$lists['list'][$k] = $v;
}
}
... ... @@ -57,14 +51,13 @@ class NewsController extends BaseController
* @author :liyuhang
* @method
*/
public function info(Request $request,NewsLogic $newsLogic){
$request->validate([
public function info(NewsLogic $newsLogic){
$this->request->validate([
'id'=>['required'],
],[
'id.required' => 'ID不能为空',
]);
$info = $newsLogic->news_info();
//TODO::清空相关资源
$this->response('success',Code::SUCCESS,$info);
}
/**
... ... @@ -76,7 +69,6 @@ class NewsController extends BaseController
public function add(NewsRequest $newsRequest,NewsLogic $newsLogic){
$newsRequest->validated();
$newsLogic->news_add();
//TODO::写入日志
$this->response('success');
}
... ... @@ -93,62 +85,63 @@ class NewsController extends BaseController
'id.required' => 'ID不能为空',
]);
$newsLogic->news_edit();
//TODO::写入日志
$this->response('success',Code::SUCCESS);
$this->response('success');
}
/**
* @name :编辑状态/与排序
* @name :编辑新闻seo
* @return void
* @author :liyuhang
* @method
*/
public function status(Request $request,NewsLogic $newsLogic){
$request->validate([
public function edit_seo(NewsLogic $newsLogic){
$this->request->validate([
'id'=>['required'],
'seo_title'=>['required'],
'seo_description'=>['required'],
'seo_keywords'=>['required'],
],[
'id.required' => 'ID不能为空',
'seo_title.required' => 'seo_title不能为空',
'seo_description.required' => 'seo_description不能为空',
'seo_keywords.required' => 'seo_description不能为空',
]);
$newsLogic->news_status();
//TODO::写入日志
$newsLogic->edit_seo();
$this->response('success');
}
/**
* @name :删除新闻(逻辑删除)
* @name :编辑状态/与排序
* @return void
* @author :liyuhang
* @method
*/
public function del(Request $request,NewsLogic $newsLogic){
$request->validate([
public function status(NewsLogic $newsLogic){
$this->request->validate([
'id'=>['required'],
],[
'id.required' => 'ID不能为空',
]);
$newsLogic->news_del();
//TODO::清空相关资源/写入日志
$newsLogic->news_status();
//TODO::写入日志
$this->response('success');
}
/**
* @name :ai生成
* @name :删除新闻(逻辑删除)
* @return void
* @author :liyuhang
* @method
*/
public function ai_news(Request $request){
# id, key, scene, ai
$request->validate([
'keywords'=>['required'],
'key'=>['required']
public function del(NewsLogic $newsLogic){
$this->request->validate([
'id'=>['required','array'],
],[
'keywords.required' => '关键字不能为空',
'key.required' => '场景不能为空',
'id.required' => 'ID不能为空',
'id.array' => 'ID为数组',
]);
#TODO 通过key获取到ai指令对象
$url = 'v2/openai_chat';
$data = $this->send_openai_msg($url);
$this->response('success',Code::SUCCESS,$data);
$newsLogic->news_del();
//TODO::清空相关资源/写入日志
$this->response('success');
}
}
... ...
... ... @@ -5,7 +5,7 @@ namespace App\Http\Controllers\Bside\Product;
use App\Helper\Arr;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Product\AttrLogic;
use App\Http\Requests\Bside\product\AttrRequest;
use App\Http\Requests\Bside\Product\AttrRequest;
use App\Rules\Ids;
use Illuminate\Http\Request;
... ... @@ -25,7 +25,7 @@ class AttrController extends BaseController
$map[] = ['title', 'like', "%{$this->param['search']}%"];
}
$sort = ['id' => 'desc'];
$data = $logic->getList($map, $sort, ['id', 'title', 'remark', 'value_num']);
$data = $logic->getList($map, $sort, ['id', 'title', 'attrs']);
return $this->success($data);
}
... ... @@ -36,7 +36,7 @@ class AttrController extends BaseController
'id.required' => 'ID不能为空'
]);
$data = $logic->getInfo($this->param['id']);
return $this->success(Arr::twoKeepKeys($data, ['id', 'title', 'remark', 'values']));
return $this->success(Arr::twoKeepKeys($data, ['id', 'title', 'attrs']));
}
public function save(AttrRequest $request, AttrLogic $logic)
... ...
... ... @@ -5,7 +5,7 @@ namespace App\Http\Controllers\Bside\Product;
use App\Helper\Arr;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Product\CategoryLogic;
use App\Http\Requests\Bside\product\CategoryRequest;
use App\Http\Requests\Bside\Product\CategoryRequest;
use App\Rules\Ids;
use Illuminate\Http\Request;
... ... @@ -26,7 +26,13 @@ class CategoryController extends BaseController
}
$sort = ['id' => 'desc'];
$data = $logic->getList($map, $sort, ['id', 'pid', 'title', 'image', 'keywords', 'describe', 'status','created_at'],0);
return $this->success(Arr::listToTree($data));
foreach ($data as &$v){
$v['product_num'] = $logic->getProductNum($v['id']);
}
if(!$map){
$data = Arr::listToTree($data);
}
return $this->success($data);
}
public function info(Request $request, CategoryLogic $logic){
... ...
... ... @@ -5,7 +5,7 @@ namespace App\Http\Controllers\Bside\Product;
use App\Helper\Arr;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Product\DescribeLogic;
use App\Http\Requests\Bside\product\DescribeRequest;
use App\Http\Requests\Bside\Product\DescribeRequest;
use App\Rules\Ids;
use Illuminate\Http\Request;
... ... @@ -25,7 +25,7 @@ class DescribeController extends BaseController
$map[] = ['title', 'like', "%{$this->param['search']}%"];
}
$sort = ['id' => 'desc'];
$data = $logic->getList($map, $sort, ['id', 'title', 'describe', 'status', 'created_at']);
$data = $logic->getList($map, $sort, ['id', 'title', 'text', 'status', 'created_at']);
return $this->success($data);
}
... ... @@ -36,7 +36,7 @@ class DescribeController extends BaseController
'id.required' => 'ID不能为空'
]);
$data = $logic->getInfo($this->param['id']);
return $this->success(Arr::twoKeepKeys($data, ['id', 'title', 'describe', 'created_at']));
return $this->success(Arr::twoKeepKeys($data, ['id', 'title', 'text', 'created_at']));
}
public function save(DescribeRequest $request, DescribeLogic $logic)
... ...
... ... @@ -5,7 +5,8 @@ namespace App\Http\Controllers\Bside\Product;
use App\Helper\Arr;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Product\KeywordLogic;
use App\Http\Requests\Bside\product\KeywordRequest;
use App\Http\Requests\Bside\Product\KeywordRequest;
use App\Models\Project\Project;
use App\Rules\Ids;
use Illuminate\Http\Request;
... ... @@ -25,7 +26,13 @@ class KeywordController extends BaseController
$map[] = ['title', 'like', "%{$this->param['search']}%"];
}
$sort = ['id' => 'desc'];
$data = $logic->getList($map, $sort, ['id', 'title', 'route', 'status', 'created_at']);
$data = $logic->getList($map, $sort, ['id', 'title', 'seo_title', 'seo_keywords', 'seo_description', 'status', 'created_at']);
foreach ($data['list'] as &$v){
$v['product_num'] = $logic->getProductNum($v['id']);
$v['tdk'] = boolval($v['seo_title']) * boolval($v['seo_keywords']) * boolval($v['seo_description']);
//todo 获取域名 拼接链接
$v['url'] = $v['route'];
}
return $this->success($data);
}
... ... @@ -36,7 +43,7 @@ class KeywordController extends BaseController
'id.required' => 'ID不能为空'
]);
$data = $logic->getInfo($this->param['id']);
return $this->success(Arr::twoKeepKeys($data, ['id', 'title', 'route', 'created_at']));
return $this->success(Arr::twoKeepKeys($data, ['id', 'title', 'seo_title', 'seo_keywords', 'seo_description', 'created_at']));
}
public function save(KeywordRequest $request, KeywordLogic $logic)
... ...
... ... @@ -7,7 +7,9 @@ use App\Exceptions\BsideGlobalException;
use App\Helper\Arr;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Product\ProductLogic;
use App\Http\Requests\Bside\product\ProductRequest;
use App\Http\Requests\Bside\Product\ProductRequest;
use App\Models\Product\CategoryRelated;
use App\Models\Product\KeywordRelated;
use App\Rules\Ids;
use Illuminate\Http\Request;
... ... @@ -26,11 +28,22 @@ class ProductController extends BaseController
if(!empty($this->param['search'])){
$map[] = ['title', 'like', "%{$this->param['search']}%"];
}
if(!empty($this->param['created_at'])){
if(!empty($this->param['created_at'][0]) && !empty($this->param['created_at'][1])){
$map[] = ['created_at', 'between', $this->param['created_at']];
}
if(!empty($this->param['category_id'])){
$ids = CategoryRelated::where('cate_id', $this->param['category_id'])->pluck('product_id')->toArray();
$map[] = ['id', 'in', $ids];
}
if(!empty($this->param['keyword_id'])){
$ids = KeywordRelated::where('keyword_id', $this->param['keyword_id'])->pluck('product_id')->toArray();
$map[] = ['id', 'in', $ids];
}
if(isset($this->param['status'])){
$map[] = ['status', $this->param['status']];
}
$sort = ['id' => 'desc'];
$data = $logic->getList($map, $sort, ['id', 'title', 'thumb', 'category_id', 'keywords', 'status', 'created_at', 'updated_at']);
$data = $logic->getList($map, $sort, ['id', 'title', 'thumb', 'category_id', 'keyword_id', 'status', 'created_uid', 'created_at', 'updated_at']);
return $this->success($data);
}
... ... @@ -41,15 +54,12 @@ class ProductController extends BaseController
'id.required' => 'ID不能为空'
]);
$data = $logic->getInfo($this->param['id']);
return $this->success(Arr::twoKeepKeys($data, ['id', 'title', 'gallery', 'attrs', 'category_id', 'keywords', 'intro', 'content',
'describe', 'seo_mate', 'related_product_id', 'status']));
return $this->success(Arr::twoKeepKeys($data, ['id', 'title', 'gallery', 'attrs', 'category_id', 'keyword_id', 'attr_id', 'describe_id', 'intro', 'content',
'describe', 'seo_mate', 'related_product_id', 'status', 'category_id_text', 'keyword_id_text', 'status_text', 'created_uid', 'created_uid_text', 'route']));
}
public function save(ProductRequest $request, ProductLogic $logic)
{
//封面取第一个图片
$this->param['thumb'] = $this->param['gallery'][0] ?? '';
$data = $logic->save($this->param);
return $this->success($data);
}
... ...
<?php
namespace App\Http\Controllers\Aside;
namespace App\Http\Controllers\Bside\Project;
class ProjectUserController extends BaseController
use App\Http\Controllers\Bside\BaseController;
class ProjectController extends BaseController
{
/**
* @name :用户列表
* @return void
* @author :liyuhang
* @method
* @name :lists
* @author :lyh
* @method :post
* @time :2023/4/28 14:48
*/
public function lists(){
... ...
<?php
namespace App\Http\Controllers\Bside;
use App\Helper\Translate;
use App\Models\RouteMap;
use App\Rules\Ids;
use Illuminate\Http\Request;
class RouteController extends BaseController
{
/**
* 生成路由
* @param Request $request
* @return \Illuminate\Http\JsonResponse
* @author zbj
* @date 2023/5/5
*/
public function create(Request $request){
$title = $request->input('title');
$source = $request->input('source');
$source_id = $request->input('source_id');
$project_id = $this->user['project_id'];
$route = RouteMap::generateRoute($title, $source, $source_id, $project_id);
return $this->success(['route' => $route]);
}
}
... ...
<?php
namespace App\Http\Controllers\Bside\Setting;
use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Setting\ProjectCountryLogic;
/**
* @name:项目配置多语言设置
*/
class ProjectCountryController extends BaseController
{
/**
* @name :(当前项目的多语言列表)lists
* @author :lyh
* @method :post
* @time :2023/4/28 14:49
*/
public function info(ProjectCountryLogic $projectCountryLogic){
$lists = $projectCountryLogic->country_info();
$this->response('success',Code::SUCCESS,$lists);
}
/**
* @name :(更新当前项目多语言设置)edit
* @author :lyh
* @method :post
* @time :2023/4/28 17:53
*/
public function edit(ProjectCountryLogic $projectCountryLogic){
$projectCountryLogic->country_edit();
$this->response('success');
}
}
... ...
<?php
namespace App\Http\Controllers\Aside;
namespace App\Http\Controllers\Bside\Setting;
use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Models\Project as ProjectModel;
use App\Http\Logic\Bside\Setting\WebSettingLogic;
/**
* @name:项目信息
* @name:项目首页设置
*/
class ProjectController extends BaseController
class WebSettingController extends BaseController
{
/**
* @name :项目列表
* @name :首页设置
* @return void
* @author :liyuhang
* @method
*/
public function lists(){
$projectModel = new ProjectModel();
$lists = $projectModel->lists($this->map,$this->p,$this->row,$this->order);
$this->response('success',Code::SUCCESS,$lists);
public function lists(WebSettingLogic $webSettingLogic){
$info = $webSettingLogic->setting_read();
$this->response('success',Code::SUCCESS,$info);
}
/**
* @name :添加项目
* @return void
* @author :liyuhang
* @method
* @name :添加数据add
* @author :lyh
* @method :post
* @time :2023/4/28 15:17
*/
public function add(){
$projectModel = new ProjectModel();
public function save(WebSettingLogic $webSettingLogic){
$webSettingLogic->setting_save();
$this->response('success');
}
}
... ...
<?php
namespace App\Http\Controllers\Bside\Setting;
use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Setting\WebSettingCountryLogic;
use App\Models\Project\Country as CountryModel;
/**
* @name:多语言国家配置列
*/
class WebSettingCountryController extends BaseController
{
/**
* @name :列表lists
* @author :lyh
* @method :post
* @time :2023/4/28 14:40
*/
public function lists(WebSettingCountryLogic $webSettingCountryLogic){
$lists = $webSettingCountryLogic->country_list();
$this->response('success',Code::SUCCESS,$lists);
}
}
... ...
<?php
namespace App\Http\Controllers\Bside\Setting;
use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Setting\WebSettingFromLogic;
/**
* @name:表单设置
*/
class WebSettingFromController extends BaseController
{
/**
* @name :(表单设置详情)info
* @author :lyh
* @method :post
* @time :2023/5/4 13:44
*/
public function info(WebSettingFromLogic $webSettingFromLogic){
$info = $webSettingFromLogic->setting_from_info();
$this->response('success',Code::SUCCESS,$info);
}
/**
* @name :(添加或编辑表单设置)lists
* @author :lyh
* @method :post
* @time :2023/4/28 14:41
*/
public function save(WebSettingFromLogic $webSettingFromLogic){
$webSettingFromLogic->setting_from_save();
$this->response('success');
}
}
... ...