作者 赵彬吉
... ... @@ -263,6 +263,7 @@ class HtmlCollect extends Command
//判断资源是否需要下载
protected function url_check($url, $project_id, $domain, $web_url_domain, $home_url)
{
$url = trim($url);
if ($url) {
$url = str_replace('"', '', $url);
$arr = parse_url($url);
... ...
... ... @@ -279,6 +279,7 @@ class HtmlLanguageCollect extends Command
//判断资源是否需要下载
protected function url_check($url, $project_id, $domain, $web_url_domain, $home_url)
{
$url = trim($url);
if ($url) {
$url = str_replace('"', '', $url);
$arr = parse_url($url);
... ...
<?php
/**
* @remark :
* @name :CopyProject.php
* @author :lyh
* @method :post
* @time :2024/1/9 16:01
*/
namespace App\Events;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class CopyProject
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $data;
/**
* 监听更新HTML静态页
*/
public function __construct($data)
{
$this->data = $data;
}
}
... ...
... ... @@ -216,7 +216,9 @@ class OptimizeController extends BaseController
$query = $query->where('gl_project_deploy_build.test_domain','like','%'.$this->map['test_domain'].'%');
}
$query = $query->whereIn('gl_project.type',[2,4]);//TODO::2,4代表优化项目
$query = $query->where('gl_project_online_check.qa_status',1);
$query->where(function ($subQuery) {
$subQuery->orwhere('gl_project_online_check.qa_status',1)->orwhere('gl_project.is_upgrade',1);
});
return $query;
}
... ...
... ... @@ -240,6 +240,7 @@ class ProductController extends BaseController
}
$v['status_text'] = Product::statusMap()[$v['status']] ?? '';
//获取当前用户选择的模版
$v['video'] = json_decode($v['video']);
$template_id = $this->getTemplateId(BTemplate::SOURCE_PRODUCT,BTemplate::IS_DETAIL);
$v['is_renovation'] = $this->getIsRenovation(BTemplate::SOURCE_PRODUCT,BTemplate::IS_DETAIL,$template_id,$v['id']);
$v['url'] = $this->user['domain'].$v['route'];
... ...
... ... @@ -3,6 +3,7 @@
namespace App\Http\Logic\Aside\Project;
use App\Enums\Common\Code;
use App\Events\CopyProject;
use App\Exceptions\AsideGlobalException;
use App\Models\Com\NoticeLog;
use App\Models\Com\UpdateLog;
... ... @@ -567,128 +568,8 @@ class ProjectLogic extends BaseLogic
* @time :2023/11/8 14:23
*/
public function copyProject(){
DB::beginTransaction();
try {
//复制初始项目
$data = $this->model::where('id', $this->param['project_id'])->first();
$data = $data->getAttributes();
$type = $data['type'];
$data['type'] = 0;
$data['title'] = $data['title'].'-copy';
unset($data['id']);
$project_id = $this->model->insertGetId($data);
//复制部署表
$buildModel = new DeployBuild();
$buildData = $buildModel::where('project_id', $this->param['project_id'])->first();
if(!empty($buildData)){
$buildData = $buildData->getAttributes();
$buildData['project_id'] = $project_id;
$hashids = new Hashids('test_domain', 5, 'abcdefghjkmnpqrstuvwxyz1234567890');
$code = $hashids->encode($project_id);
$buildData['test_domain'] = 'https://v6-' . $code . '.globalso.site/';
unset($buildData['id']);
$buildModel->insert($buildData);
}
//复制优化表
$optimizeModel = new DeployOptimize();
$optimizeData = $optimizeModel::where('project_id', $this->param['project_id'])->first();
if(!empty($optimizeData)){
$optimizeData = $optimizeData->getAttributes();
unset($optimizeData['id'],$optimizeData['domain']);
$optimizeData['project_id'] = $project_id;
$optimizeModel->insert($optimizeData);
}
//复制付费表
$paymentModel = new Payment();
$paymentData = $paymentModel::where('project_id', $this->param['project_id'])->first();
if(!empty($paymentData)){
$paymentData = $paymentData->getAttributes();
unset($paymentData['id']);
$paymentData['project_id'] = $project_id;
$paymentModel->insert($paymentData);
}
//复制售后表
$afterModel = new After();
$afterData = $afterModel::where('project_id', $this->param['project_id'])->first();
if(!empty($afterData)){
$afterData = $afterData->getAttributes();
unset($afterData['id']);
$afterData['project_id'] = $project_id;
$afterModel->insert($afterData);
}
//复制用户
$userModel = new UserModel();
$userData = $userModel::where('project_id', $this->param['project_id'])->where('role_id',0)->first();
if(!empty($userData)){
$userData = $userData->getAttributes();
unset($userData['id']);
$userData['project_id'] = $project_id;
$userModel->insert($userData);
}
//复制设置的模版
$settingTemplateModel = new Setting();
$settingData = $settingTemplateModel::where('project_id', $this->param['project_id'])->first();
if(!empty($settingData)){
$settingData = $settingData->getAttributes();
unset($settingData['id']);
$settingData['project_id'] = $project_id;
$settingTemplateModel->insert($settingData);
}
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('error');
}
if($type != 0){
$this->copyMysql($this->param['project_id'],$project_id);
}
return $this->success($data);
}
//复制数据库
public function copyMysql($project_id,$new_project_id){
//切换数据库配置
$project = ProjectServer::useProject($new_project_id);
//创建数据库
ProjectServer::createDatabase($project);
//创建表
$this->initTable($project_id,$new_project_id);
}
/**
* @remark :创建数据库
* @name :initTable
* @author :lyh
* @method :post
* @time :2023/12/11 10:09
*/
public function initTable($project_id,$news_project_id)
{
config(['database.connections.custom_tmp_mysql_copy.database' => 'gl_data_'.$project_id]);
$database_name = DB::connection('custom_tmp_mysql_copy')->getDatabaseName();
$tables = Schema::connection('custom_tmp_mysql_copy')->getAllTables();
$tables = array_column($tables, 'Tables_in_' . $database_name);
foreach ($tables as $table) {
$has_table = Schema::connection('custom_mysql')->hasTable($table);
if (!$has_table) {
$sql = DB::connection('custom_tmp_mysql_copy')->select("SHOW CREATE TABLE {$table}");
DB::connection('custom_mysql')->statement(get_object_vars($sql[0])['Create Table']);
}
DB::connection('custom_mysql')->table($table)->truncate(); // 清空目标表数据
DB::connection('custom_mysql')->table($table)->insertUsing(
[], // 列名数组,留空表示插入所有列
function ($query) use ($table,$project_id) {
$name = 'gl_data_'.$project_id.'.'.$table;
$query->select('*')->from("{$name}");
}
);
if (Schema::connection('custom_mysql')->hasColumn($table, 'project_id')) {
DB::connection('custom_mysql')->table($table)->update(['project_id' => $news_project_id]);
}
}
return true;
CopyProject::dispatch(['project_id'=>$this->param['project_id']]);
return $this->success();
}
/**
... ...
... ... @@ -29,7 +29,7 @@ class CustomTemplateLogic extends BaseLogic
* @time :2023/6/29 15:46
*/
public function customTemplateLists($map,$page,$row,$order = 'created_at'){
$filed = ['id','name','status','url','title','keywords','description','project_id','is_upgrade','six_read','created_at','updated_at'];
$filed = ['id','name','status','url','title','keywords','description','project_id','is_upgrade','six_read','is_visualization','created_at','updated_at'];
$map['deleted_status'] = 0;
$map['project_id'] = $this->user['project_id'];
$lists = $this->model->lists($map,$page,$row,$order,$filed);
... ...
... ... @@ -214,6 +214,9 @@ class CustomModuleCategoryLogic extends BaseLogic
public function delRoute($id)
{
$info = $this->model->read(['id' => $id], ['id', 'route','module_id']);
if($info === false){
return $this->success();
}
RouteMap::delRoute(RouteMap::SOURCE_MODULE_CATE, $id, $this->user['project_id']);
//通知
$this->curlDelRoute(['route'=>$info['route']]);
... ...
... ... @@ -275,6 +275,11 @@ class ProductLogic extends BaseLogic
$param['gallery'] = Arr::a2s([]);
$param['thumb'] = Arr::a2s([]);
}
if(isset($param['video']) && !empty($param['video'])){
$param['video'] = Arr::a2s($param['video'] ?? []);
}else{
$param['video'] = Arr::a2s([]);
}
$param['attrs'] = Arr::a2s($param['attrs'] ?? []);
$param['attr_id'] = Arr::arrToSet($param['attr_id'] ?? '');
if(isset($param['keyword_id']) && !empty($param['keyword_id'])){
... ...
... ... @@ -24,7 +24,7 @@ class CustomTemplateRequest extends FormRequest
public function rules()
{
return [
'name'=>'required',
'name'=>'required|max:255',
'url'=>'required',
'keywords'=>'max:1000',
// 'description'=>'max:500',
... ...
<?php
namespace App\Listeners;
use App\Events\CopyProject;
use App\Events\UpdateHtml;
use App\Jobs\updateHtmlJob;
use App\Models\Project\After;
use App\Models\Project\DeployBuild;
use App\Models\Project\DeployOptimize;
use App\Models\Project\Payment;
use App\Models\Project\Project;
use App\Models\Template\Setting;
use App\Models\User\User as UserModel;
use App\Services\ProjectServer;
use Hashids\Hashids;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class CopyProjectListener implements ShouldQueue
{
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param UpdateHtml $event
* @return void
*/
public function handle(CopyProject $event)
{
$this->param = $event->data;
$this->model = new Project();
DB::beginTransaction();
try {
//复制初始项目
$data = $this->model::where('id', $this->param['project_id'])->first();
$data = $data->getAttributes();
$type = $data['type'];
$data['type'] = 0;
$data['title'] = $data['title'].'-copy';
unset($data['id']);
$project_id = $this->model->insertGetId($data);
//复制部署表
$buildModel = new DeployBuild();
$buildData = $buildModel::where('project_id', $this->param['project_id'])->first();
if(!empty($buildData)){
$buildData = $buildData->getAttributes();
$buildData['project_id'] = $project_id;
$hashids = new Hashids('test_domain', 5, 'abcdefghjkmnpqrstuvwxyz1234567890');
$code = $hashids->encode($project_id);
$buildData['test_domain'] = 'https://v6-' . $code . '.globalso.site/';
unset($buildData['id']);
$buildModel->insert($buildData);
}
//复制优化表
$optimizeModel = new DeployOptimize();
$optimizeData = $optimizeModel::where('project_id', $this->param['project_id'])->first();
if(!empty($optimizeData)){
$optimizeData = $optimizeData->getAttributes();
unset($optimizeData['id'],$optimizeData['domain']);
$optimizeData['project_id'] = $project_id;
$optimizeModel->insert($optimizeData);
}
//复制付费表
$paymentModel = new Payment();
$paymentData = $paymentModel::where('project_id', $this->param['project_id'])->first();
if(!empty($paymentData)){
$paymentData = $paymentData->getAttributes();
unset($paymentData['id']);
$paymentData['project_id'] = $project_id;
$paymentModel->insert($paymentData);
}
//复制售后表
$afterModel = new After();
$afterData = $afterModel::where('project_id', $this->param['project_id'])->first();
if(!empty($afterData)){
$afterData = $afterData->getAttributes();
unset($afterData['id']);
$afterData['project_id'] = $project_id;
$afterModel->insert($afterData);
}
//复制用户
$userModel = new UserModel();
$userData = $userModel::where('project_id', $this->param['project_id'])->where('role_id',0)->first();
if(!empty($userData)){
$userData = $userData->getAttributes();
unset($userData['id']);
$userData['project_id'] = $project_id;
$userModel->insert($userData);
}
//复制设置的模版
$settingTemplateModel = new Setting();
$settingData = $settingTemplateModel::where('project_id', $this->param['project_id'])->first();
if(!empty($settingData)){
$settingData = $settingData->getAttributes();
unset($settingData['id']);
$settingData['project_id'] = $project_id;
$settingTemplateModel->insert($settingData);
}
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('error');
}
if($type != 0){
$this->copyMysql($this->param['project_id'],$project_id);
}
return true;
}
//复制数据库
public function copyMysql($project_id,$new_project_id){
//切换数据库配置
$project = ProjectServer::useProject($new_project_id);
//创建数据库
ProjectServer::createDatabase($project);
//创建表
$this->initTable($project_id,$new_project_id);
}
/**
* @remark :创建数据库
* @name :initTable
* @author :lyh
* @method :post
* @time :2023/12/11 10:09
*/
public function initTable($project_id,$news_project_id)
{
config(['database.connections.custom_tmp_mysql_copy.database' => 'gl_data_'.$project_id]);
$database_name = DB::connection('custom_tmp_mysql_copy')->getDatabaseName();
$tables = Schema::connection('custom_tmp_mysql_copy')->getAllTables();
$tables = array_column($tables, 'Tables_in_' . $database_name);
foreach ($tables as $table) {
$has_table = Schema::connection('custom_mysql')->hasTable($table);
if (!$has_table) {
$sql = DB::connection('custom_tmp_mysql_copy')->select("SHOW CREATE TABLE {$table}");
DB::connection('custom_mysql')->statement(get_object_vars($sql[0])['Create Table']);
}
DB::connection('custom_mysql')->table($table)->truncate(); // 清空目标表数据
DB::connection('custom_mysql')->table($table)->insertUsing(
[], // 列名数组,留空表示插入所有列
function ($query) use ($table,$project_id) {
$name = 'gl_data_'.$project_id.'.'.$table;
$query->select('*')->from("{$name}");
}
);
if (Schema::connection('custom_mysql')->hasColumn($table, 'project_id')) {
DB::connection('custom_mysql')->table($table)->update(['project_id' => $news_project_id]);
}
}
return true;
}
}
... ...
... ... @@ -56,7 +56,7 @@ class CollectTask extends Base
$new_domain = implode('.', $domain_arr);
} else {
//二级目录
$new_domain = $url_arr['host'] ?? $domain . '/' . $v_lan;
$new_domain = ($url_arr['host'] ?? $domain) . '/' . $v_lan;
}
$data[] = [
... ...
... ... @@ -52,16 +52,8 @@ class Category extends Base
*/
public static function getProductNum($cate_id){
$cate_ids = self::getChildIdsArr($cate_id);
$str = 0;
foreach ($cate_ids as $v){
$info = self::where('pid',$v)->first();
if($info){
continue;
}else{
$count = Product::where('category_id','like','%,'.$v.',%')->count();
$str = $str+$count;
}
}
return $str;
$count = CategoryRelated::whereIn('cate_id',$cate_ids)->count();
// $str = 0;
return $count;
}
}
... ...
... ... @@ -2,6 +2,8 @@
namespace App\Providers;
use App\Events\CopyProject;
use App\Listeners\CopyProjectListener;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
... ... @@ -22,6 +24,7 @@ class EventServiceProvider extends ServiceProvider
'Illuminate\Database\Events\QueryExecuted' => [
'App\Listeners\QueryListener',
],
CopyProject::class => [CopyProjectListener::class],
];
/**
... ...
... ... @@ -205,7 +205,7 @@ return [
'Date' => Illuminate\Support\Facades\Date::class,
'DB' => Illuminate\Support\Facades\DB::class,
'Eloquent' => Illuminate\Database\Eloquent\Model::class,
'Event' => Illuminate\Support\Facades\Event::class,
'Events' => Illuminate\Support\Facades\Event::class,
'File' => Illuminate\Support\Facades\File::class,
'Gate' => Illuminate\Support\Facades\Gate::class,
'Hash' => Illuminate\Support\Facades\Hash::class,
... ...