作者 zhl

Merge branch 'develop' of 47.244.231.31:zhl/globalso-v6 into develop

<?php
namespace App\Console\Commands\Import;
use App\Http\Logic\Bside\News\NewsLogic;
use App\Models\Import\ImportTask;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
/**
* Class GoogleRank
* @package App\Console\Commands
* @author Akun
* @date 2023/9/20 15:18
*/
class ProjectImport extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'project_import';
/**
* The console command description.
*
* @var string
*/
protected $description = '执行项目导入任务';
public function handle()
{
while (true) {
$this->start_import();
}
}
protected function start_import()
{
$task = ImportTask::where('status', ImportTask::STATUS_UN)->first();
if (!$task) {
sleep(2);
return true;
}
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', import start' . PHP_EOL;
//读取csv文件
$line_of_text = [];
try {
$file_handle = fopen($task->file_url, 'r');
while (!feof($file_handle)) {
$line_of_text[] = fgetcsv($file_handle, 0, ',');
}
fclose($file_handle);
} catch (\Exception $e) {
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', import fail, error: ' . $e->getMessage() . PHP_EOL;
$task->status = ImportTask::STATUS_COM;//导入完成
$task->save();
return true;
}
$success_count = 0; //成功导入条数
$count_line = count($line_of_text); //总条数
if ($count_line > 1) {
$task->status = ImportTask::STATUS_ING;//导入中
$task->total_count = $count_line - 1;
$task->save();
//设置数据库
$project = ProjectServer::useProject($task->project_id);
if ($project) {
foreach ($line_of_text as $k => $v) {
if ($k > 0) {
if ($task->type == ImportTask::TYPE_NEWS) {
if ((new NewsLogic())->importNews($task->project_id, $task->user_id, $v)) {
$success_count += 1;
}
}
}
}
}
//关闭数据库
DB::disconnect('custom_mysql');
}
$task->status = ImportTask::STATUS_COM;//导入完成
$task->success_count = $success_count;
$task->save();
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', import end, total count: ' . ($count_line - 1) . ', success count: ' . $success_count . PHP_EOL;
sleep(2);
}
}
... ...
... ... @@ -9,6 +9,7 @@ use App\Helper\QuanqiusouApi;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Aside\Project\ProjectLogic;
use App\Http\Logic\Bside\RankData\RankDataLogic;
use App\Models\Domain\DomainInfo;
use App\Models\RankData\RankData;
use App\Models\RankData\Speed as GoogleSpeedModel;
use App\Services\BatchExportService;
... ... @@ -58,7 +59,7 @@ class RankDataController extends BaseController
public function speed(ProjectLogic $projectLogic, GoogleSpeedApi $googleSpeedApi){
$project_id = $this->user['project_id'];
$project = $projectLogic->getProjectInfo($project_id);
$domain = $project['deploy_optimize']['domain'] ?? '';
$domain = (!empty($project['deploy_optimize']['domain']) ? ((new DomainInfo())->getDomain($project['deploy_optimize']['domain'])) : '');
$data = $googleSpeedApi->run($domain);
if($data){
$model = GoogleSpeedModel::where('project_id', $project_id)->first();
... ...
... ... @@ -19,7 +19,7 @@ class DomainInfoLogic extends BaseLogic
public function getDomainInfo($project_id)
{
$project = app(ProjectLogic::class)->getInfo($project_id);
$domain = $project['deploy_optimize']['domain'] ?? '';
$domain = (!empty($project['deploy_optimize']['domain']) ? ((new \App\Models\Domain\DomainInfo())->getDomain($project['deploy_optimize']['domain'])) : '');
$info = $this->model->where('project_id', $project_id)->first();
//不存在或时间过期了 重新获取信息
$expiration_date = $info['domain_info']['expiration_date'] ?? '';
... ...
... ... @@ -4,6 +4,7 @@ namespace App\Http\Logic\Aside\Project;
use App\Http\Logic\Aside\BaseLogic;
use App\Models\Domain\DomainInfo;
use App\Models\Project\ProcessRecords;
use App\Models\Project\Project;
... ... @@ -30,7 +31,7 @@ class ProcessRecordsLogic extends BaseLogic
$data['project_company'] = $project['company'] ?? '';
$data['project_plan'] = Project::planMap()[$project['deploy_build']['plan']];
$data['project_service_duration'] = $project['deploy_build']['service_duration'] ?? '';
$data['domain'] = $project['deploy_optimize']['domain'] ?? '';
$data['domain'] = (!empty($project['deploy_optimize']['domain']) ? ((new DomainInfo())->getDomain($project['deploy_optimize']['domain'])) : '');;
$data['test_domain'] = $project['deploy_build']['test_domain'] ?? '';
$data['login_mobile'] = $project['deploy_build']['login_mobile'] ?? '';
$data['data_source'] = [
... ...
... ... @@ -408,7 +408,7 @@ class ProjectLogic extends BaseLogic
{
$project = $this->getCacheInfo($param['project_id']);
//同步到接口
$domain = parse_url($project['deploy_optimize']['domain'])['host'];
$domain = parse_url((!empty($project['deploy_optimize']['domain']) ? ((new DomainInfo())->getDomain($project['deploy_optimize']['domain'])) : ''))['host'];
$emails = Arr::arrToSet($param['emails']??'', 'trim');
$phones = Arr::arrToSet($param['phones']??'', 'trim');
$form_global_api = new FormGlobalsoApi();
... ...
... ... @@ -46,8 +46,8 @@ class BlogCategoryLogic extends BaseLogic
public function categorySave(){
//验证名称是否存在
$this->verifyParamName($this->param['name']);
DB::beginTransaction();
try {
// DB::beginTransaction();
// try {
if(isset($this->param['id']) && !empty($this->param['id'])){
//验证参数是否可编辑
$this->verifyParamEdit($this->param['id'],$this->param['pid']);
... ... @@ -65,11 +65,11 @@ class BlogCategoryLogic extends BaseLogic
$route = RouteMap::setRoute(isset($this->param['alias']) ? $this->param['alias'] : $this->param['name'],
RouteMap::SOURCE_BLOG_CATE, $id, $this->user['project_id']);
$this->edit(['alias'=>$route],['id'=>$id]);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('error');
}
// DB::commit();
// }catch (\Exception $e){
// DB::rollBack();
// $this->fail('error');
// }
//通知更新
$this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_BLOG_CATE, 'route'=>$route]);
return $this->success();
... ...
... ... @@ -7,6 +7,7 @@ use App\Helper\FormGlobalsoApi;
use App\Helper\Translate;
use App\Http\Logic\Aside\Project\ProjectLogic;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Domain\DomainInfo;
/**
* Class InquiryLogic
... ... @@ -31,7 +32,8 @@ class InquiryLogic extends BaseLogic
$search = $this->request['search'] ?: '';
$page = $this->request['page'] ?: 1;
$project = (new ProjectLogic())->getProjectInfo($this->user['project_id']);
$domain = $project['deploy_optimize']['domain'] ?? '';
$domain = (!empty(
$project['deploy_optimize']['domain']) ? ((new DomainInfo())->getDomain($project['deploy_optimize']['domain'])) : '');
$list = $this->form_globalso_api->getInquiryList($domain, $search, $page, $page_size);
//处理格式 免得前端又改
$data = [
... ... @@ -54,7 +56,7 @@ class InquiryLogic extends BaseLogic
public function getInfo($id)
{
$project = (new ProjectLogic())->getProjectInfo($this->user['project_id']);
$domain = $project['deploy_optimize']['domain'] ?: '';
$domain = (!empty($project['deploy_optimize']['domain']) ? ((new DomainInfo())->getDomain($project['deploy_optimize']['domain'])) : '');
//修改状态为已读
if($this->request['read_status']){
$this->form_globalso_api->saveInquiryRead($domain, $id);
... ... @@ -70,7 +72,7 @@ class InquiryLogic extends BaseLogic
public function delete($ids, $map = [])
{
$project = (new ProjectLogic())->getProjectInfo($this->user['project_id']);
$domain = $project['deploy_optimize']['domain'] ?: '';
$domain = (!empty($project['deploy_optimize']['domain']) ? ((new DomainInfo())->getDomain($project['deploy_optimize']['domain'])) : '');
$ids = array_filter(Arr::splitFilterToArray($ids), 'intval');
if(!$ids){
$this->fail('ID不能为空');
... ...
... ... @@ -59,9 +59,9 @@ class NewsCategoryLogic extends BaseLogic
*/
public function newsCategorySave(){
//验证名称是否存在
$this->verifyParamName($this->param['name']);
DB::beginTransaction();
try {
// $this->verifyParamName($this->param['name']);
// DB::beginTransaction();
// try {
if(isset($this->param['id']) && !empty($this->param['id'])){
//验证是否可编辑
$this->verifyEditParam($this->param['id'],$this->param['pid']);
... ... @@ -77,11 +77,11 @@ class NewsCategoryLogic extends BaseLogic
}
$route = RouteMap::setRoute(isset($this->param['alias']) ? $this->param['alias'] : $this->param['name'], RouteMap::SOURCE_NEWS_CATE, $id, $this->user['project_id']);
$this->model->edit(['alias'=>$route],['id'=>$id]);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('error');
}
// DB::commit();
// }catch (\Exception $e){
// DB::rollBack();
// $this->fail('error');
// }
//更新通知记录表
$this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_NEWS_CATE, 'route'=>$route]);
return $this->success();
... ... @@ -270,4 +270,38 @@ class NewsCategoryLogic extends BaseLogic
$this->setRouteDeleteSave($data);
return $this->success();
}
public function importNewsCategory($project_id,$user_id,$category){
$return = [];
$cate_arr = explode('/',$category);
$p_cate = $cate_arr[0];
$c_cate = $cate_arr[1];
$p_category = $this->model->read(['name'=>$p_cate,'pid'=>0]);
if(!$p_category){
$p_id = $this->model->addReturnId(['name'=>$p_cate,'project_id'=>$project_id,'operator_id'=>$user_id,'create_id'=>$user_id]);
$route = RouteMap::setRoute($p_cate, RouteMap::SOURCE_NEWS_CATE, $p_id, $project_id);
$this->model->edit(['alias'=>$route],['id'=>$p_id]);
}else{
$p_id = $p_category['id'];
}
$return[] = $p_id;
if($c_cate){
$c_category = $this->model->read(['name'=>$c_cate,'pid'=>$p_id]);
if(!$c_category){
$c_id = $this->model->addReturnId(['name'=>$c_cate,'pid'=>$p_id,'project_id'=>$project_id,'operator_id'=>$user_id,'create_id'=>$user_id]);
$route = RouteMap::setRoute($c_cate, RouteMap::SOURCE_NEWS_CATE, $c_id, $project_id);
$this->model->edit(['alias'=>$route],['id'=>$c_id]);
}else{
$c_id = $c_category['id'];
}
$return[] = $c_id;
}
return ','.implode(',',$return).',';
}
}
... ...
... ... @@ -28,20 +28,21 @@ class NewsLogic extends BaseLogic
* @author :liyuhang
* @method
*/
public function news_get_category_list(){
public function news_get_category_list()
{
$this->map['status'] = 0;
$this->map['project_id'] = $this->user['project_id'];
$newsCategoryModel = new NewsCategoryModel();
$cate_list = $newsCategoryModel->list($this->map,'sort');
if($cate_list === false){
$this->fail('error',Code::USER_ERROR);
$cate_list = $newsCategoryModel->list($this->map, 'sort');
if ($cate_list === false) {
$this->fail('error', Code::USER_ERROR);
}
$list = [];
foreach ($cate_list as $v){
foreach ($cate_list as $v) {
$v = (array)$v;
if ($v['pid'] == 0) {
$v['sub'] = _get_child($v['id'], $cate_list);
$list[] = $v;
$list[] = $v;
}
}
return $this->success($list);
... ... @@ -54,28 +55,29 @@ class NewsLogic extends BaseLogic
* @method :post
* @time :2023/9/7 11:02
*/
public function newsSave(){
public function newsSave()
{
//拼接参数
DB::beginTransaction();
try {
$this->param = $this->paramProcessing($this->param);
if(isset($this->param['id']) && !empty($this->param['id'])){
if (isset($this->param['id']) && !empty($this->param['id'])) {
//是否更新路由
$id = $this->editNewsRoute($this->param['id'],$this->param['url']);
$this->edit($this->param,['id'=>$this->param['id']]);
}else{
$id = $this->editNewsRoute($this->param['id'], $this->param['url']);
$this->edit($this->param, ['id' => $this->param['id']]);
} else {
$id = $this->model->addReturnId($this->param);
}
//更新路由
$route = RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $id, $this->user['project_id']);
$this->edit(['url'=>$route],['id'=>$id]);
$this->edit(['url' => $route], ['id' => $id]);
DB::commit();
}catch (\Exception $e){
} catch (\Exception $e) {
DB::rollBack();
$this->fail('添加失败');
}
//通知更新
$this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_NEWS, 'route'=>$route]);
$this->updateNotify(['project_id' => $this->user['project_id'], 'type' => RouteMap::SOURCE_NEWS, 'route' => $route]);
return $this->success();
}
... ... @@ -86,13 +88,14 @@ class NewsLogic extends BaseLogic
* @method :post
* @time :2023/9/7 11:05
*/
public function editNewsRoute($id,$route){
public function editNewsRoute($id, $route)
{
//生成一条删除路由记录
$info = $this->model->read(['id'=>$id],['id','url']);
if($info['url'] != $route){
$info = $this->model->read(['id' => $id], ['id', 'url']);
if ($info['url'] != $route) {
$data = [
'source'=>RouteMap::SOURCE_NEWS,
'route'=>$info['url'],
'source' => RouteMap::SOURCE_NEWS,
'route' => $info['url'],
];
$this->setRouteDeleteSave($data);
}
... ... @@ -106,10 +109,11 @@ class NewsLogic extends BaseLogic
* @author :liyuhang
* @method
*/
public function edit_seo(){
public function edit_seo()
{
$this->param['operator_id'] = $this->user['id'];
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$rs = $this->model->edit($this->param, ['id' => $this->param['id']]);
if ($rs === false) {
$this->fail('error');
}
return $this->success();
... ... @@ -122,10 +126,11 @@ class NewsLogic extends BaseLogic
* @author :liyuhang
* @method
*/
public function news_status(){
public function news_status()
{
$this->param['operator_id'] = $this->user['id'];
$rs = $this->model->edit($this->param,['id'=>['in',$this->param['id']]]);
if($rs === false){
$rs = $this->model->edit($this->param, ['id' => ['in', $this->param['id']]]);
if ($rs === false) {
$this->fail('error');
}
return $this->success();
... ... @@ -138,7 +143,8 @@ class NewsLogic extends BaseLogic
* @author :liyuhang
* @method
*/
public function newsInfo(){
public function newsInfo()
{
$info = $this->model->read($this->param);
$info['image_link'] = getImageUrl($info['image']);
$newsCategoryLogic = new NewsCategoryLogic();
... ... @@ -152,15 +158,16 @@ class NewsLogic extends BaseLogic
* @author :liyuhang
* @method
*/
public function newsDel(){
public function newsDel()
{
DB::beginTransaction();
try {
foreach ($this->param['id'] as $id){
foreach ($this->param['id'] as $id) {
$this->delRoute($id);
$this->model->del(['id'=>$id]);
$this->model->del(['id' => $id]);
}
DB::commit();
}catch (Exception $e){
} catch (Exception $e) {
DB::rollBack();
$this->fail('error');
}
... ... @@ -173,18 +180,19 @@ class NewsLogic extends BaseLogic
* @method :post
* @time :2023/6/13 11:30
*/
public function paramProcessing($param){
if(isset($this->param['id'])){
public function paramProcessing($param)
{
if (isset($this->param['id'])) {
$param['operator_id'] = $this->user['id'];
if(isset($param['category_id']) && !empty($param['category_id'])){
$param['category_id'] = ','.trim($param['category_id'],',').',';
if (isset($param['category_id']) && !empty($param['category_id'])) {
$param['category_id'] = ',' . trim($param['category_id'], ',') . ',';
}
}else{
} else {
$param['create_id'] = $this->user['id'];
$param['operator_id'] = $this->user['id'];
$param['project_id'] = $this->user['project_id'];
if(isset($param['category_id']) && !empty($param['category_id'])){
$param['category_id'] = ','.$param['category_id'].',';
if (isset($param['category_id']) && !empty($param['category_id'])) {
$param['category_id'] = ',' . $param['category_id'] . ',';
}
}
return $this->success($param);
... ... @@ -197,14 +205,15 @@ class NewsLogic extends BaseLogic
* @method :post
* @time :2023/6/19 9:42
*/
public function getStatusNumber(){
public function getStatusNumber()
{
//三种状态 0:草稿 1:发布 2:回收站
$data = ['dra'=>0,'pub'=>1,'del'=>2,'tal'=>3];
foreach ($data as $k => $v){
if($v == 3){
$data[$k] = $this->model->where(['project_id'=>$this->user['project_id']])->count();
}else{
$data[$k] = $this->model->where(['status'=>$v,'project_id'=>$this->user['project_id']])->count();
$data = ['dra' => 0, 'pub' => 1, 'del' => 2, 'tal' => 3];
foreach ($data as $k => $v) {
if ($v == 3) {
$data[$k] = $this->model->where(['project_id' => $this->user['project_id']])->count();
} else {
$data[$k] = $this->model->where(['status' => $v, 'project_id' => $this->user['project_id']])->count();
}
}
return $this->success($data);
... ... @@ -217,9 +226,10 @@ class NewsLogic extends BaseLogic
* @method :post
* @time :2023/8/19 11:16
*/
public function setSort(){
$rs = $this->model->edit(['sort'=>$this->param['sort']],['id'=>$this->param['id']]);
if($rs === false){
public function setSort()
{
$rs = $this->model->edit(['sort' => $this->param['sort']], ['id' => $this->param['id']]);
if ($rs === false) {
$this->fail('error');
}
return $this->success();
... ... @@ -232,16 +242,28 @@ class NewsLogic extends BaseLogic
* @method :post
* @time :2023/9/7 10:50
*/
public function delRoute($id){
public function delRoute($id)
{
//删除路由映射
RouteMap::delRoute(RouteMap::SOURCE_NEWS, $id, $this->user['project_id']);
//生成一条删除路由记录
$info = $this->model->read(['id'=>$id],['id','url']);
$info = $this->model->read(['id' => $id], ['id', 'url']);
$data = [
'source'=>RouteMap::SOURCE_NEWS,
'route'=>$info['url'],
'source' => RouteMap::SOURCE_NEWS,
'route' => $info['url'],
];
$this->setRouteDeleteSave($data);
return $this->success();
}
public function importNews($project_id, $user_id, $data)
{
$category_id = '';
if (!empty($data[2])) {
//处理分类
$newsCategoryLogic = new NewsCategoryLogic();
$category_id = $newsCategoryLogic->importNewsCategory($project_id, $user_id, $data[2]);
}
dd($category_id);
}
}
... ...
... ... @@ -9,6 +9,7 @@ use App\Helper\Translate;
use App\Http\Logic\Aside\Project\DomainInfoLogic;
use App\Http\Logic\Aside\Project\ProjectLogic;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Domain\DomainInfo;
use App\Models\Project\DeployBuild;
use App\Models\Project\DeployOptimize;
use App\Models\Project\Project;
... ... @@ -59,7 +60,7 @@ class RankDataLogic extends BaseLogic
//项目信息
$data['project'] = [
'company' => $project['company'],
'domain' => $project['deploy_optimize']['domain'] ?? '',
'domain' => (!empty($project['deploy_optimize']['domain']) ? ((new DomainInfo())->getDomain($project['deploy_optimize']['domain'])) : ''),
'domain_info' => ($domain_info['domain_info']['creation_date'] ?? '') . ' - ' . ($domain_info['domain_info']['expiration_date'] ?? ''),
'cert_info' => ($domain_info['ssl']['start_time'] ?? '') . ' - ' . ($domain_info['ssl']['end_time'] ?? ''),
'plan' => Project::planMap()[$project['deploy_build']['plan']],
... ... @@ -144,7 +145,7 @@ class RankDataLogic extends BaseLogic
$project_id = $this->user['project_id'];
$project = app(ProjectLogic::class)->getInfo($project_id);
$api_no = $project['deploy_optimize']['api_no'] ?? '';
$domain = $project['deploy_optimize']['domain'] ?? '';
$domain = (!empty($project['deploy_optimize']['domain']) ? ((new DomainInfo())->getDomain($project['deploy_optimize']['domain'])) : '');
$domain_arr = parse_url($domain);
$domain = $domain_arr['host'] ?? $domain_arr['path'];
//复制站点域名
... ...
... ... @@ -164,8 +164,7 @@ class UserLoginLogic
$info['aicc'] = $project['aicc'] ?? '';
$info['hagro'] = $project['hagro'] ?? '';
$info['plan'] = Project::planMap()[$project['deploy_build']['plan']];
$info['domain'] = (!empty($project['deploy_optimize']['domain']) ?
((new DomainInfo())->getDomain($project['deploy_optimize']['domain'])) : ($project['deploy_build']['test_domain'] ?? ''));
$info['domain'] = (!empty($project['deploy_optimize']['domain']) ? ((new DomainInfo())->getDomain($project['deploy_optimize']['domain'])) : ($project['deploy_build']['test_domain'] ?? ''));
//保存项目缓存
Cache::put('user-'.$info['project_id'],$project,$minutes = null);
return $this->success($info);
... ... @@ -188,8 +187,7 @@ class UserLoginLogic
$info['aicc'] = $project['aicc'] ?? '';
$info['hagro'] = $project['hagro'] ?? '';
$info['plan'] = Project::planMap()[$project['deploy_build']['plan']];
$info['domain'] = (!empty($project['deploy_optimize']['domain']) ?
((new DomainInfo())->getDomain($project['deploy_optimize']['domain'])) : ($project['deploy_build']['test_domain'] ?? ''));
$info['domain'] = (!empty($project['deploy_optimize']['domain']) ? ((new DomainInfo())->getDomain($project['deploy_optimize']['domain'])) : ($project['deploy_build']['test_domain'] ?? ''));
//保存项目缓存
Cache::put('user-'.$info['project_id'],$project,$minutes = null);
return $this->success($info);
... ...