作者 赵彬吉
... ... @@ -63,13 +63,18 @@ class TemplateLog extends Command
* @time :2024/7/10 14:48
*/
public function deleteTemplate(){
$date = date('Y-m-d H:i:s', strtotime('-60 days'));
$date = date('Y-m-d H:i:s', strtotime('-30 days'));
$templateLogModel = new BTemplateLog();
$templateLogModel->del(['created_at'=>['<=',$date],'source'=>['!=',1]]);
//首页保存最新的20条记录
$latestIds = $templateLogModel->where(['source'=>1,'is_custom'=>0])->orderBy('created_at', 'desc')->take(20)->pluck('id'); // 仅提取ID字段
return $templateLogModel->del(['id'=>['not in',$latestIds],'source'=>1,'is_custom'=>0,'is_list'=>0]);
//查询最近20天是否有装修记录,首页保存最新的20条记录
$counts = $templateLogModel->counts(['source'=>1,'source_id'=>0,'is_custom'=>0,'created_at'=>['>=',$date]]);
if($counts == 0){
$latestIds = $templateLogModel->where(['source'=>1,'is_custom'=>0])->orderBy('created_at', 'desc')->take(20)->pluck('id'); // 仅提取ID字段
$templateLogModel->del(['id'=>['not in',$latestIds],'source'=>1,'is_custom'=>0,'is_list'=>0]);
}else{
$templateLogModel->del(['created_at'=>['<=',$date],'source'=>1]);
}
return true;
}
/**
... ...
... ... @@ -102,10 +102,10 @@ class DomainInfo extends Command
$domain_array = parse_url($v['domain']);
$host = $domain_array['host'] ?? $domain_array['path'];
$host_array = explode('.', $host);
if (count($host_array) <= 2) {
array_unshift($host_array, 'm');
} else {
if($host_array[0] == 'www'){
$host_array[0] = 'm';
}else{
array_unshift($host_array,'m');
}
$amp_domain = implode('.', $host_array);
... ... @@ -192,10 +192,10 @@ class DomainInfo extends Command
$domain_array = parse_url($v['domain']);
$host = $domain_array['host'] ?? $domain_array['path'];
$host_array = explode('.', $host);
if (count($host_array) <= 2) {
array_unshift($host_array, 'm');
} else {
if($host_array[0] == 'www'){
$host_array[0] = 'm';
}else{
array_unshift($host_array,'m');
}
$amp_domain = implode('.', $host_array);
... ...
<?php
/**
* @remark :
* @name :CreateProject.php
* @author :lyh
* @method :post
* @time :2025/1/6 10:34
*/
namespace App\Console\Commands\Project;
use App\Helper\Arr;
use App\Models\Channel\Channel;
use App\Models\Com\UpdateLog;
use App\Models\Com\UpdateVisit;
use App\Models\Devops\Servers;
use App\Models\Devops\ServersIp;
use App\Models\Manage\Mobile;
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\User\User as UserModel;
use App\Services\ProjectServer;
use Hashids\Hashids;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class CreateProject extends Command
{
protected $signature = 'create_project';
protected $description = '创建项目';
public function handle(){
return $this->sync();
}
public function sync($is_update = 0){
$title = date('Ymd') . '-广东威美建材科技有限公司';
$data = [
'project'=>[
'title' => $title,
'company' => '广东威美建材科技有限公司',
'lead_name' => '蔡伟文',
'mobile' => '13929953235',
'mysql_id'=>Project::MYSQL_ID,
'serve_id'=>9,
'qq' => '',
'channel' => '{"user_id": "53", "zone_id": "4", "channel_id": "4"}',
'requirement' => '',
'cooperate_date' => '2019-04-01',
'from_order_id' => '',
'type' => $is_update,
'is_upgrade'=>$is_update,
],
'deploy_build' => [
'service_duration' => 0,
'plan' => $this->versionData('标准版'),
'login_mobile'=>'13929953235'
],
'deploy_optimize' => [
// 'api_no' => 0
],
'project_after' => [],
'payment' => [
'amount' => 0,
'contract'=>[],
'bill'=>[]
],
];
DB::beginTransaction();
try {
$id = $this->saveProject($data['project']);
$this->setPostId($data['deploy_build']['plan'],$id);
$this->savePayment($data['payment'],$id);
$this->saveDeployBuild($data['deploy_build'],$id);
$this->saveDeployOptimize($data['deploy_optimize'],$id);
$this->saveAfter($data['project_after'],$id);
$serversIpModel = new ServersIp();
$serversModel = new Servers();
$serversIpModel->where(['id'=>9])->increment('total',1);
$serversModel->where(['id'=>7])->increment('being_number',1);
if($is_update == 1){
//4.0或5.0更新到6.0
//初始化数据库
$this->initializationMysql($id);
//初始账号
$this->createUser($data['project']['mobile'],$id,$data['project']['lead_name']);
}
DB::commit();
}catch (\Exception $e){
DB::rollBack();
throw new \Exception($e->getMessage());
}
}
/**
* @remark :获取版本
* @name :versionData
* @author :lyh
* @method :post
* @time :2023/8/9 14:46
*/
public function versionData($param){
$data = Project::planMap();
$data = array_flip($data);
if(isset($data[$param])){
return $data[$param];
}else{
return 1;
}
}
/**
* @remark :保存项目
* @name :saveProject
* @author :lyh
* @method :post
* @time :2023/8/30 15:53
*/
public function saveProject($param){
$projectModel = new Project();
return $projectModel->addReturnId($param);
}
/**
* @remark :设置post_id
* @name :setPostId
* @author :lyh
* @method :post
* @time :2023/8/9 14:47
*/
public function setPostId($plan,$id){
$length = strlen((string)$id); // 获取变量的位数
$paddingLength = Project::TYPE_FIVE - $length; // 计算填充前面的 0 的位数
$zeros = str_repeat("0", $paddingLength);
$number = Project::TYPE_SIX.$plan.$zeros.$id;
$projectModel = new Project();
$projectModel->edit(['post_id'=>$number],['id'=>$id]);
return true;
}
/**
* 保存优化部署
* @author zbj
* @date 2023/4/26
*/
protected function saveAfter($param,$id){
$param['project_id'] = $id;
//查询数据是否存在
$afterModel = new After();
$info = $afterModel->read(['project_id'=>$id]);
if($info !== false){
$afterModel->edit($param,['id'=>$info['id']]);
}else{
$afterModel->add($param);
}
}
/**
* @remark :保存付款续费
* @name :savePayment
* @author :lyh
* @method :post
* @time :2023/8/29 16:19
*/
protected function savePayment($param,$id){
$param['project_id'] = $id;
$paymentModel= new Payment();
$param['contract'] = Arr::a2s($param['contract']);
$param['bill'] = Arr::a2s($param['bill']);
if(!isset($param['renewal_record'])){
$param['renewal_record'] = Arr::a2s([["amount"=> null, "remark"=> null, "expire_at"=> null]]);
}
$info = $paymentModel->read(['project_id'=>$id]);
if($info !== false){
$paymentModel->edit($param,['id'=>$info['id']]);
}else{
$paymentModel->add($param);
}
}
/**
* @remark :保存建站部署
* @name :saveDeployBuild
* @author :lyh
* @method :post
* @time :2023/8/29 16:19
*/
protected function saveDeployBuild($param,$id){
$param['project_id'] = $id;
$hashids = new Hashids('test_domain', 5, 'abcdefghjkmnpqrstuvwxyz1234567890');
$code = $hashids->encode($id);
$param['test_domain'] = 'https://v6-' . $code . '.globalso.site/';
$deployBuildModel = new DeployBuild();
$info = $deployBuildModel->read(['project_id'=>$id]);
if($info !== false){
$deployBuildModel->edit($param,['id'=>$info['id']]);
}else{
$deployBuildModel->add($param);
}
}
/**
* @remark :保存优化信息
* @name :saveDeployOptimize
* @author :lyh
* @method :post
* @time :2023/8/30 16:11
*/
protected function saveDeployOptimize($param,$id){
$param['project_id'] = $id;
$deployOptimizeModel = new DeployOptimize();
$info = $deployOptimizeModel->read(['project_id'=>$id]);
if($info !== false){
//存在就不处理了
// $deployOptimizeModel->edit($param,['id'=>$info['id']]);
}else{
$deployOptimizeModel->add($param);
}
}
/**
* 初始化数据库
* @param $project_id
* @author Akun
* @date 2023/09/19 15:12
*/
public function initializationMysql($project_id){
//切换数据库配置
$project = ProjectServer::useProject($project_id);
//创建数据库
ProjectServer::createDatabase($project);
//创建表
ProjectServer::initTable();
//初始数据
ProjectServer::saveInitParam($project_id);
}
/**
* 创建用户
* @param $mobile
* @param $project_id
* @param $lead_name
* @author Akun
* @date 2023/09/19 15:12
*/
public function createUser($mobile,$project_id,$lead_name){
$userModel = new UserModel();
//查看当前项目是否存在号码库中
$mobileModel = new Mobile();
$mobileInfo = $mobileModel->read(['mobile'=>$mobile]);
if($mobileInfo === false){
//查看当前用户是否存在
$info = $userModel->read(['mobile'=>$mobile,'project_id'=>$project_id]);
if($info === false){
$data = [
'mobile'=>$mobile,
'password'=>base64_encode(md5('123456')),
'project_id'=>$project_id,
'name'=>$lead_name,
'type'=>UserModel::TYPE_ONE
];
$userModel->add($data);
}
}
return true;
}
}
... ...
... ... @@ -126,65 +126,6 @@ class Temp extends Command
}
/**
* 创建指定服务器所有项目主站生成任务
* @author Akun
* @date 2024/12/19 17:54
*/
public function create_server_update_page()
{
$server_id = 15;
$server_ip_model = new ServersIp();
$server_ip_ids = $server_ip_model->where('servers_id', $server_id)->get()->pluck('id')->toArray();
$project_list = Project::select(['id', 'serve_id'])->whereIn('serve_id', $server_ip_ids)->get();
$domain_model = new DomainInfo();
$notify_model = new Notify();
foreach ($project_list as $value) {
$project_id = $value->id;
$domain_info = $domain_model->read(['project_id' => $project_id, 'status' => 1], ['id', 'domain']);
if (!$domain_info) {
//过滤未绑定正式域名的项目
continue;
}
$domain = $domain_info['domain'];
//获取项目所在服务器
$serve_ip_info = $server_ip_model->read(['id' => $value->serve_id], ['domain', 'ip']);
if (!$serve_ip_info) {
$this->output('项目id:' . $project_id . ' | 未查询到服务器数据');
continue;
}
if (!check_domain_record($domain, $serve_ip_info)) {
$this->output('项目id:' . $project_id . ', domain:' . $domain . ' | 未解析到目标服务器');
continue;
}
$data = [
'project_id' => $project_id,
'type' => 1,
'route' => 1,
'server_id' => $server_id,
'status' => ['!=', Notify::STATUS_FINISH_SITEMAP]
];
$notify = $notify_model->read($data, ['id']);
if (!$notify) {
$data['data'] = Arr::a2s(['domain' => $domain, 'url' => null, 'language' => []]);
$data['status'] = Notify::STATUS_INIT;
$notify_model->add($data);
$this->output('项目id:' . $project_id . ' | success');
}
}
}
/**
* 判断指定服务器项目是否正常访问
* @author Akun
* @date 2024/12/11 10:15
... ... @@ -272,6 +213,7 @@ class Temp extends Command
public function get_all_projects_by_server()
{
$server_id = 1;
$server_name = '240云服务器';
$server_ip_model = new ServersIp();
... ... @@ -297,7 +239,7 @@ class Temp extends Command
}
$map = ['项目id', '名称', '域名'];
if ($data) {
$table = new BatchExportService("240云服务器项目");
$table = new BatchExportService($server_name . '项目');
$file = $table->head($map)->data($data)->save();
if (!$file) {
$this->output('文件生成失败,请重试');
... ... @@ -371,6 +313,7 @@ class Temp extends Command
public function check_no_server_projects()
{
$server_id = 15;
$server_name = '美服1';
$server_ip_model = new ServersIp();
... ... @@ -403,7 +346,7 @@ class Temp extends Command
}
$map = ['项目id', '名称', '域名', 'IP', '服务器ID',];
if ($data) {
$table = new BatchExportService("美服2项目解析未在当前服务器项目");
$table = new BatchExportService($server_name . '解析未在当前服务器项目');
$file = $table->head($map)->data($data)->save();
if (!$file) {
$this->output('文件生成失败,请重试');
... ... @@ -416,6 +359,65 @@ class Temp extends Command
}
/**
* 创建指定服务器所有项目主站生成任务
* @author Akun
* @date 2024/12/19 17:54
*/
public function create_server_update_page()
{
$server_id = 15;
$server_ip_model = new ServersIp();
$server_ip_ids = $server_ip_model->where('servers_id', $server_id)->get()->pluck('id')->toArray();
$project_list = Project::select(['id', 'serve_id'])->whereIn('serve_id', $server_ip_ids)->get();
$domain_model = new DomainInfo();
$notify_model = new Notify();
foreach ($project_list as $value) {
$project_id = $value->id;
$domain_info = $domain_model->read(['project_id' => $project_id, 'status' => 1], ['id', 'domain']);
if (!$domain_info) {
//过滤未绑定正式域名的项目
continue;
}
$domain = $domain_info['domain'];
//获取项目所在服务器
$serve_ip_info = $server_ip_model->read(['id' => $value->serve_id], ['domain', 'ip']);
if (!$serve_ip_info) {
$this->output('项目id:' . $project_id . ' | 未查询到服务器数据');
continue;
}
if (!check_domain_record($domain, $serve_ip_info)) {
$this->output('项目id:' . $project_id . ', domain:' . $domain . ' | 未解析到目标服务器');
continue;
}
$data = [
'project_id' => $project_id,
'type' => 1,
'route' => 1,
'server_id' => $server_id,
'status' => ['!=', Notify::STATUS_FINISH_SITEMAP]
];
$notify = $notify_model->read($data, ['id']);
if (!$notify) {
$data['data'] = Arr::a2s(['domain' => $domain, 'url' => null, 'language' => []]);
$data['status'] = Notify::STATUS_INIT;
$notify_model->add($data);
$this->output('项目id:' . $project_id . ' | success');
}
}
}
/**
* 创建所有amp站页面生成任务
* @author Akun
* @date 2024/09/26 10:48
... ... @@ -435,10 +437,10 @@ class Temp extends Command
$domain_array = parse_url($domain);
$host = $domain_array['host'] ?? $domain_array['path'];
$host_array = explode('.', $host);
if (count($host_array) <= 2) {
array_unshift($host_array, 'm');
} else {
if ($host_array[0] == 'www') {
$host_array[0] = 'm';
} else {
array_unshift($host_array, 'm');
}
$amp_domain = implode('.', $host_array);
... ...
... ... @@ -93,7 +93,7 @@ class OptimizationReportController extends BaseController
'data' => array_values($indexed_pages['data'] ?? []),
];
//月统计报告
$data['month_count'] = $this->currentMonthCount($domain_info['domain'],$this->param['project_id']);
$data['month_count'] = $this->currentMonthCount($this->param['project_id']);
//测速
$speed = Speed::where('project_id', $this->param['project_id'])->first();
$data['speed'] = $speed['data'] ?? [];
... ... @@ -110,107 +110,30 @@ class OptimizationReportController extends BaseController
* @method :post
* @time :2023/7/3 9:55
*/
public function currentMonthCount($domain,$project_id){
// 获取当前月的开始时间
$startTime = date('Y-m-01', strtotime($this->param['date']));
// 获取当前月的结束时间
$endTime = date('Y-m-t', strtotime($this->param['date']));
public function currentMonthCount($project_id){
$arr = [];
$arr = $this->inquiryCount($arr,$startTime,$endTime,$domain,$project_id);
$arr = $this->flowCount($arr,$startTime,$endTime,$project_id);
$arr = $this->sourceCount($arr,$startTime,$endTime,$domain);
$arr['month'] = date('Y-m',time());
return $arr;
}
/**
* @param $domain
* @param $project_id
* @remark :询盘按月统计
* @name :inquiryCount
* @author :lyh
* @method :post
* @time :2023/6/30 14:29
*/
public function inquiryCount(&$arr, &$startTime, $project_id){
$month = date('Y-m',strtotime($startTime));
$date = date('Y-m', strtotime($this->param['date']));
$monthCountModel = new MonthCount();
$info = $monthCountModel->read(['project_id'=>$project_id,'month'=>$month]);
if($info !== false){
$arr['country'] = $info['country'];
$arr['total'] = $info['total'];
$arr['month_total'] = $info['month_total'];
}
return $arr;
}
/**
* @remark :流量统计
* @name :flowCount
* @author :lyh
* @method :post
* @time :2023/6/30 14:31
*/
public function flowCount(&$arr,&$startTime,&$endTime,$project_id){
$pv_ip = DB::table('gl_count')
->where(['project_id'=>$project_id])
->whereBetween('date', [$startTime,$endTime])
->select(DB::raw('SUM(pv_num) as pv_num'), DB::raw('SUM(ip_num) as ip_num'))
->orderBy('id','desc')
->first();
$arr['pv'] = $pv_ip->pv_num;
$arr['ip'] = $pv_ip->ip_num;
$arr['rate'] = 0;
if($arr['ip'] != 0){
$arr['rate'] = round(($arr['month_total'] / $arr['ip']) * 100,2);
$month_info = $monthCountModel->read(['project_id'=>$project_id,'month'=>$date]);
if($month_info !== false){
$arr['country'] = $month_info['country'];
$arr['total'] = $month_info['total'];
$arr['month_total'] = $month_info['month_total'];
$arr['pv'] = $month_info['pv'];
$arr['ip'] = $month_info['ip'];
$arr['rate'] = 0;
if($arr['ip'] != 0){
$arr['rate'] = round(($arr['month_total'] / $arr['ip']) * 100,2);
}
$arr['source'] = json_decode($month_info['source'],true);
$arr['source_country'] = json_decode($month_info['source_country'],true);
$arr['referrer_url'] = json_decode($month_info['referrer_url'],true);
$arr['referrer_port'] = json_decode($month_info['referrer_port'],true);
}
$arr['month'] = date('Y-m',time());
return $arr;
}
/**
* @remark :来源访问前8
* @name :sourceCount
* @author :lyh
* @method :post
* @time :2023/6/30 16:14
*/
public function sourceCount(&$arr,$startTime,$endTime,$domain){
//访问来源前10
$source = DB::connection('custom_mysql')->table('gl_customer_visit')
->select('referrer_url', DB::raw('COUNT(*) as count'))
->groupBy('referrer_url')
->where('referrer_url','!=','')
->whereBetween('updated_date', [$startTime,$endTime])
->orderByDesc('count')->limit(10)->get()->toArray();
$arr['source'] = $source;
//访问国家前15
$query = DB::connection('custom_mysql')->table('gl_customer_visit')
->select('country',DB::raw('COUNT(*) as ip'),DB::raw('SUM(depth) as pv'))
->groupBy('country');
$query->where('country','<>','中国');
$source_country = $query->whereBetween('updated_date', [$startTime,$endTime])
->orderBy('ip','desc')->limit(15)->get()->toArray();
$arr['source_country'] = $source_country;
//受访界面前15
$referrer_url = DB::connection('custom_mysql')->table('gl_customer_visit')
->select('url',DB::raw('COUNT(*) as num'))
->orderBy('num','desc')
->whereBetween('updated_date', [$startTime,$endTime])
->groupBy('url')
->limit(15)->get()->toArray();
$arr['referrer_url'] = $referrer_url;
//访问断后
$referrer_port = DB::connection('custom_mysql')->table('gl_customer_visit')
->select('device_port',DB::raw('COUNT(*) as num'))
->orderBy('num','desc')
->whereBetween('updated_date', [$startTime,$endTime])
->groupBy('device_port')
->limit(15)->get()->toArray();
$arr['referrer_port'] = $referrer_port;
return $arr;
}
public function getApiList($projectInfo,$export = false)
{
... ...
... ... @@ -61,13 +61,18 @@ class CNoticeController extends BaseController
],[
'language.required' => 'language不能为空',
]);
$project_id_arr = explode(',',env('PROJECT_ID')) ?? [];
if(in_array($this->user['project_id'],$project_id_arr)){
$this->response('success');
}
$lang_num = count($this->param['language']);
$keyword_num = (new Keyword())->counts(['route'=>['!=',null]]);
$data_num = $this->productNum() + $this->CustomNum() + $this->newsNum() + $this->blogNum();
$number = $keyword_num * 18 + $lang_num * $data_num;
if($number >= 45000){
$this->response('success',Code::SUCCESS,['msg'=>'翻译数量过多, 大概页面数量:'.$number.', 磁盘空间占用可能会超过40G,请谨慎使用!']);
if($number >= 450000){
$this->response('success',Code::SUCCESS,['msg'=>'翻译数量过多, 大概页面数量:'.$number.', 磁盘空间占用可能会超过40G,请联系管理员操作!']);
}
//? Copyright - 2010-2024 : All Rights Reserved.© Copyright - 2010-2024 : All Rights Reserved.
$this->response('success');
}
... ...
... ... @@ -88,7 +88,6 @@ class MonthReportController extends BaseController
])->count();
$info['service_duration'] = $this->user['service_duration'];//服务天数
$info['ip_total'] = (new Visit())->count();//ip总数
$info['remain_day'] = $this->user['remain_day'];//剩余服务天数
$info['speed'] = round((0.3 + mt_rand()/mt_getrandmax() * (1-0.3)),2);
$info['month_total'] = (int)$info['month_total'];
... ...
... ... @@ -80,7 +80,7 @@ class BaseController extends Controller
case "order":
$this->order = $v;
break;
case "order":
case "order_type":
$this->order_type = $v;
break;
case 'page':
... ...
... ... @@ -12,6 +12,7 @@ use App\Http\Logic\Bside\Product\ProductLogic;
use App\Http\Requests\Bside\Product\ProductRequest;
use App\Models\Product\Category;
use App\Models\Product\CategoryRelated;
use App\Models\Product\Detail;
use App\Models\Product\Extend;
use App\Models\Product\ExtendInfo;
use App\Models\Product\Keyword;
... ... @@ -68,13 +69,12 @@ class ProductController extends BaseController
$v = $this->getHandleFileImage($v);
$lists['list'][$k] = $v;
}
$lists['order_type'] = $this->order_type;
$lists['order'] = $this->order;
}
$this->response('success',Code::SUCCESS,$lists);
}
public function setOrderBy(){
}
/**
* @remark :列表
* @name :index
... ... @@ -679,7 +679,11 @@ class ProductController extends BaseController
$new_content = htmlentities($contents);
}
if (!empty($new_content)){
$productInfo['content'] = $new_content . $productInfo['content'];
$detailModel = new Detail();
$detailInfo = $detailModel->read(['column_id'=>1]);
if($detailInfo !== false && !empty($detailInfo['content'])){
$productInfo['content'] = $new_content . $detailInfo['content']['content'];
}
}
$this->response('success',Code::SUCCESS,$productInfo);
}
... ...
... ... @@ -263,6 +263,7 @@ class UserLoginLogic
$info['upload_config'] = $project['upload_config'];
$info['main_lang_id'] = $project['main_lang_id'];
$info['image_max'] = $project['image_max'];
$info['is_del_inquiry'] = $project['is_del_inquiry'] ?? 0;
$info['uptime_type'] = $this->getHistory($project);
$info['uptime'] = $project['uptime'];
$info['is_update_language'] = $project['is_update_language'];
... ...
... ... @@ -31,7 +31,7 @@ class TextMail extends Mailable
*/
public function build()
{
return $this->subject($this->subject)->view('mail.text', ['text' => $this->text]);
return $this->subject($this->subject)->text('mail.text', ['text' => $this->text])->view('mail.html', ['text' => $this->text]);
}
}
... ...