正在显示
49 个修改的文件
包含
3051 行增加
和
732 行删除
| @@ -44,9 +44,9 @@ class ShareUser extends Command | @@ -44,9 +44,9 @@ class ShareUser extends Command | ||
| 44 | //获取所有ayr_share用户 | 44 | //获取所有ayr_share用户 |
| 45 | $ayr_share_model = new AyrShareModel(); | 45 | $ayr_share_model = new AyrShareModel(); |
| 46 | $ayr_release = new AyrReleaseModel(); | 46 | $ayr_release = new AyrReleaseModel(); |
| 47 | - $ayr_share_list = $ayr_share_model->list(['profile_key'=>['!=','']]); | 47 | + $ayr_share_list = $ayr_share_model->list(['profile_key'=>['!=',''],'project_id'=>410]); |
| 48 | foreach ($ayr_share_list as $v){ | 48 | foreach ($ayr_share_list as $v){ |
| 49 | - $time = Carbon::now()->modify('-7 days')->toDateString(); | 49 | + $time = Carbon::now()->modify('-1 days')->toDateString(); |
| 50 | //创建时间小于7天前的当前时间 | 50 | //创建时间小于7天前的当前时间 |
| 51 | if($v['created_at'] > $time){ | 51 | if($v['created_at'] > $time){ |
| 52 | continue; | 52 | continue; |
| @@ -5,6 +5,7 @@ namespace App\Console\Commands\DayCount; | @@ -5,6 +5,7 @@ namespace App\Console\Commands\DayCount; | ||
| 5 | use App\Helper\Common; | 5 | use App\Helper\Common; |
| 6 | use App\Helper\FormGlobalsoApi; | 6 | use App\Helper\FormGlobalsoApi; |
| 7 | use App\Models\Domain\DomainInfo; | 7 | use App\Models\Domain\DomainInfo; |
| 8 | +use App\Models\Inquiry\InquiryForm; | ||
| 8 | use App\Models\Inquiry\InquiryFormData; | 9 | use App\Models\Inquiry\InquiryFormData; |
| 9 | use App\Models\Project\DeployBuild; | 10 | use App\Models\Project\DeployBuild; |
| 10 | use App\Models\Project\DeployOptimize; | 11 | use App\Models\Project\DeployOptimize; |
| @@ -42,18 +43,18 @@ class Count extends Command | @@ -42,18 +43,18 @@ class Count extends Command | ||
| 42 | public function handle() | 43 | public function handle() |
| 43 | { | 44 | { |
| 44 | $list = DB::table('gl_project')->where('gl_project.extend_type','=',0) | 45 | $list = DB::table('gl_project')->where('gl_project.extend_type','=',0) |
| 45 | - ->where('gl_project.type','!=',0) | 46 | + ->whereIn('gl_project.type',[1,2,3,4,6]) |
| 46 | ->leftJoin('gl_project_deploy_build', 'gl_project.id', '=', 'gl_project_deploy_build.project_id') | 47 | ->leftJoin('gl_project_deploy_build', 'gl_project.id', '=', 'gl_project_deploy_build.project_id') |
| 47 | ->leftJoin('gl_project_deploy_optimize', 'gl_project.id', '=', 'gl_project_deploy_optimize.project_id') | 48 | ->leftJoin('gl_project_deploy_optimize', 'gl_project.id', '=', 'gl_project_deploy_optimize.project_id') |
| 48 | ->select($this->selectParam())->get(); | 49 | ->select($this->selectParam())->get(); |
| 49 | try { | 50 | try { |
| 50 | if(!empty($list)){ | 51 | if(!empty($list)){ |
| 51 | $list = $list->toArray(); | 52 | $list = $list->toArray(); |
| 52 | - $data = []; | ||
| 53 | $yesterday = Carbon::yesterday()->toDateString(); | 53 | $yesterday = Carbon::yesterday()->toDateString(); |
| 54 | $domainInfo = new DomainInfo(); | 54 | $domainInfo = new DomainInfo(); |
| 55 | foreach ($list as $v){ | 55 | foreach ($list as $v){ |
| 56 | $v = (array)$v; | 56 | $v = (array)$v; |
| 57 | + echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL; | ||
| 57 | if($v['type'] == Project::TYPE_ZERO){ | 58 | if($v['type'] == Project::TYPE_ZERO){ |
| 58 | continue; | 59 | continue; |
| 59 | } | 60 | } |
| @@ -75,23 +76,31 @@ class Count extends Command | @@ -75,23 +76,31 @@ class Count extends Command | ||
| 75 | //服务达标天数 | 76 | //服务达标天数 |
| 76 | $arr['compliance_day'] = $v['finish_remain_day']; | 77 | $arr['compliance_day'] = $v['finish_remain_day']; |
| 77 | //剩余服务时常 | 78 | //剩余服务时常 |
| 78 | - $arr['service_day'] = $v['remain_day'] - 1; | 79 | + $arr['service_day'] = ($v['remain_day'] - 1) < 0 ? 0: $v['remain_day'] - 1; |
| 79 | //项目id | 80 | //项目id |
| 80 | $arr['project_id'] = $v['project_id']; | 81 | $arr['project_id'] = $v['project_id']; |
| 81 | $arr['created_at'] = date('Y-m-d H:i:s'); | 82 | $arr['created_at'] = date('Y-m-d H:i:s'); |
| 82 | $arr['updated_at'] = date('Y-m-d H:i:s'); | 83 | $arr['updated_at'] = date('Y-m-d H:i:s'); |
| 83 | //询盘统计 | 84 | //询盘统计 |
| 84 | $arr = $this->inquiry($arr,$v['test_domain'], $v['id']); | 85 | $arr = $this->inquiry($arr,$v['test_domain'], $v['id']); |
| 85 | - echo date('Y-m-d H:i:s') . json_encode($arr) . '->' . PHP_EOL; | ||
| 86 | - $data[] = $arr; | 86 | + if($arr === false){ |
| 87 | + continue; | ||
| 88 | + } | ||
| 89 | + //查询当天数据是否存在 存在则更新 | ||
| 90 | + $countModel = new \App\Models\HomeCount\Count(); | ||
| 91 | + $info = $countModel->read(['date'=>$arr['date'],'project_id'=>$v['id']]); | ||
| 92 | + if($info === false){ | ||
| 93 | + DB::table('gl_count')->insert($arr); | ||
| 94 | + }else{ | ||
| 95 | + $countModel->edit($arr,['id'=>$info['id']]); | ||
| 96 | + } | ||
| 97 | + Log::channel('day_count')->error('日期:'.$arr['created_at'].'success: ' .$v['test_domain']); | ||
| 87 | } | 98 | } |
| 88 | - //判断数据是否存在 | ||
| 89 | - DB::table('gl_count')->insert($data); | ||
| 90 | } | 99 | } |
| 91 | }catch (\Exception $e){ | 100 | }catch (\Exception $e){ |
| 92 | - echo date('Y-m-d H:i:s') . ' error: ' . '->' . $e->getMessage() . PHP_EOL; | 101 | + Log::channel('day_count')->error('day_count:->error ' . $e->getMessage()); |
| 93 | } | 102 | } |
| 94 | - echo date('Y-m-d H:i:s') . ' end: ' . PHP_EOL; | 103 | + Log::channel('day_count')->error('success:end'); |
| 95 | echo $this->error; | 104 | echo $this->error; |
| 96 | } | 105 | } |
| 97 | 106 | ||
| @@ -127,6 +136,9 @@ class Count extends Command | @@ -127,6 +136,9 @@ class Count extends Command | ||
| 127 | */ | 136 | */ |
| 128 | public function inquiry($arr,$domain,$project_id){ | 137 | public function inquiry($arr,$domain,$project_id){ |
| 129 | $inquiry_list = (new FormGlobalsoApi())->getInquiryList($domain,'',1,100000000); | 138 | $inquiry_list = (new FormGlobalsoApi())->getInquiryList($domain,'',1,100000000); |
| 139 | + if($inquiry_list == false){ | ||
| 140 | + return false; | ||
| 141 | + } | ||
| 130 | if($inquiry_list['status'] == self::STATUS_ERROR){ | 142 | if($inquiry_list['status'] == self::STATUS_ERROR){ |
| 131 | $arr['inquiry_num'] = 0; | 143 | $arr['inquiry_num'] = 0; |
| 132 | $countryArr = []; | 144 | $countryArr = []; |
| @@ -143,7 +155,6 @@ class Count extends Command | @@ -143,7 +155,6 @@ class Count extends Command | ||
| 143 | } | 155 | } |
| 144 | } | 156 | } |
| 145 | } | 157 | } |
| 146 | - | ||
| 147 | //加上其他询盘 | 158 | //加上其他询盘 |
| 148 | ProjectServer::useProject($project_id); | 159 | ProjectServer::useProject($project_id); |
| 149 | $arr['inquiry_num'] += InquiryFormData::getCount(); | 160 | $arr['inquiry_num'] += InquiryFormData::getCount(); |
| @@ -155,8 +166,6 @@ class Count extends Command | @@ -155,8 +166,6 @@ class Count extends Command | ||
| 155 | $countryArr[$v1['country']] = $v1['count']; | 166 | $countryArr[$v1['country']] = $v1['count']; |
| 156 | } | 167 | } |
| 157 | } | 168 | } |
| 158 | - | ||
| 159 | - | ||
| 160 | arsort($countryArr); | 169 | arsort($countryArr); |
| 161 | $top20 = array_slice($countryArr, 0, 20, true); | 170 | $top20 = array_slice($countryArr, 0, 20, true); |
| 162 | $arr['country'] = json_encode($top20); | 171 | $arr['country'] = json_encode($top20); |
| 1 | <?php | 1 | <?php |
| 2 | /** | 2 | /** |
| 3 | * @remark : | 3 | * @remark : |
| 4 | - * @name :UpgradeProjectCount.php | 4 | + * @name :CountProject.php |
| 5 | * @author :lyh | 5 | * @author :lyh |
| 6 | * @method :post | 6 | * @method :post |
| 7 | * @time :2024/1/8 9:03 | 7 | * @time :2024/1/8 9:03 |
| @@ -9,6 +9,8 @@ | @@ -9,6 +9,8 @@ | ||
| 9 | 9 | ||
| 10 | namespace App\Console\Commands\DayCount; | 10 | namespace App\Console\Commands\DayCount; |
| 11 | 11 | ||
| 12 | +use App\Helper\FormGlobalsoApi; | ||
| 13 | +use App\Models\Inquiry\InquiryFormData; | ||
| 12 | use App\Models\Project\Project; | 14 | use App\Models\Project\Project; |
| 13 | use App\Models\Visit\Visit; | 15 | use App\Models\Visit\Visit; |
| 14 | use App\Services\ProjectServer; | 16 | use App\Services\ProjectServer; |
| @@ -16,14 +18,16 @@ use Illuminate\Console\Command; | @@ -16,14 +18,16 @@ use Illuminate\Console\Command; | ||
| 16 | use Illuminate\Support\Facades\DB; | 18 | use Illuminate\Support\Facades\DB; |
| 17 | use App\Models\HomeCount\Count; | 19 | use App\Models\HomeCount\Count; |
| 18 | 20 | ||
| 19 | -class UpgradeCount extends Command | 21 | +class CountAll extends Command |
| 20 | { | 22 | { |
| 23 | + const STATUS_ERROR = 400; | ||
| 24 | + public $error = 0; | ||
| 21 | /** | 25 | /** |
| 22 | * The name and signature of the console command. | 26 | * The name and signature of the console command. |
| 23 | * | 27 | * |
| 24 | * @var string | 28 | * @var string |
| 25 | */ | 29 | */ |
| 26 | - protected $signature = 'upgrade_counts'; | 30 | + protected $signature = 'count_all'; |
| 27 | 31 | ||
| 28 | /** | 32 | /** |
| 29 | * The console command description. | 33 | * The console command description. |
| @@ -34,7 +38,7 @@ class UpgradeCount extends Command | @@ -34,7 +38,7 @@ class UpgradeCount extends Command | ||
| 34 | 38 | ||
| 35 | public function handle(){ | 39 | public function handle(){ |
| 36 | $projectModel = new Project(); | 40 | $projectModel = new Project(); |
| 37 | - $list = $projectModel->list(['is_upgrade'=>1,'delete_status'=>0]); | 41 | + $list = $projectModel->list(['delete_status'=>0,'type'=>['in',[1,2,3,4,6]]]); |
| 38 | foreach ($list as $v) { | 42 | foreach ($list as $v) { |
| 39 | echo date('Y-m-d H:i:s') . '项目id:'.$v['id'] . PHP_EOL; | 43 | echo date('Y-m-d H:i:s') . '项目id:'.$v['id'] . PHP_EOL; |
| 40 | ProjectServer::useProject($v['id']); | 44 | ProjectServer::useProject($v['id']); |
| @@ -90,6 +94,52 @@ class UpgradeCount extends Command | @@ -90,6 +94,52 @@ class UpgradeCount extends Command | ||
| 90 | } | 94 | } |
| 91 | 95 | ||
| 92 | /** | 96 | /** |
| 97 | + * @param $arr | ||
| 98 | + * @param $domain | ||
| 99 | + * @name :(询盘统计)inquiry | ||
| 100 | + * @author :lyh | ||
| 101 | + * @method :post | ||
| 102 | + * @time :2023/6/14 15:44 | ||
| 103 | + */ | ||
| 104 | + public function inquiry($arr,$domain,$project_id){ | ||
| 105 | + $inquiry_list = (new FormGlobalsoApi())->getInquiryList($domain,'',1,100000000); | ||
| 106 | + if($inquiry_list == false){ | ||
| 107 | + return false; | ||
| 108 | + } | ||
| 109 | + if($inquiry_list['status'] == self::STATUS_ERROR){ | ||
| 110 | + $arr['inquiry_num'] = 0; | ||
| 111 | + $countryArr = []; | ||
| 112 | + }else{ | ||
| 113 | + $arr['inquiry_num'] = $inquiry_list['data']['total']; | ||
| 114 | + //询盘国家统计 | ||
| 115 | + $countryData = $inquiry_list['data']['data']; | ||
| 116 | + $countryArr = []; | ||
| 117 | + foreach ($countryData as $v1){ | ||
| 118 | + if(isset($countryArr[$v1['country']])){ | ||
| 119 | + $countryArr[$v1['country']]++; | ||
| 120 | + }else{ | ||
| 121 | + $countryArr[$v1['country']] = 1; | ||
| 122 | + } | ||
| 123 | + } | ||
| 124 | + } | ||
| 125 | + //加上其他询盘 | ||
| 126 | + ProjectServer::useProject($project_id); | ||
| 127 | + $arr['inquiry_num'] += InquiryFormData::getCount(); | ||
| 128 | + $countryData = InquiryFormData::getCountryCount(); | ||
| 129 | + foreach ($countryData as $v1){ | ||
| 130 | + if(isset($countryArr[$v1['country']])){ | ||
| 131 | + $countryArr[$v1['country']] += $v1['count']; | ||
| 132 | + }else{ | ||
| 133 | + $countryArr[$v1['country']] = $v1['count']; | ||
| 134 | + } | ||
| 135 | + } | ||
| 136 | + arsort($countryArr); | ||
| 137 | + $top20 = array_slice($countryArr, 0, 20, true); | ||
| 138 | + $arr['country'] = json_encode($top20); | ||
| 139 | + return $arr; | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + /** | ||
| 93 | * @remark :询盘数量 | 143 | * @remark :询盘数量 |
| 94 | * @name :inquiry_num | 144 | * @name :inquiry_num |
| 95 | * @author :lyh | 145 | * @author :lyh |
| 1 | <?php | 1 | <?php |
| 2 | /** | 2 | /** |
| 3 | * @remark : | 3 | * @remark : |
| 4 | - * @name :UpgradeProjectCount.php | 4 | + * @name :CountProject.php |
| 5 | * @author :lyh | 5 | * @author :lyh |
| 6 | * @method :post | 6 | * @method :post |
| 7 | * @time :2024/1/8 9:03 | 7 | * @time :2024/1/8 9:03 |
| @@ -9,6 +9,10 @@ | @@ -9,6 +9,10 @@ | ||
| 9 | 9 | ||
| 10 | namespace App\Console\Commands\DayCount; | 10 | namespace App\Console\Commands\DayCount; |
| 11 | 11 | ||
| 12 | +use App\Helper\FormGlobalsoApi; | ||
| 13 | +use App\Models\Domain\DomainInfo; | ||
| 14 | +use App\Models\Inquiry\InquiryFormData; | ||
| 15 | +use App\Models\Project\DeployOptimize; | ||
| 12 | use App\Models\Project\Project; | 16 | use App\Models\Project\Project; |
| 13 | use App\Models\Visit\Visit; | 17 | use App\Models\Visit\Visit; |
| 14 | use App\Services\ProjectServer; | 18 | use App\Services\ProjectServer; |
| @@ -16,14 +20,16 @@ use Illuminate\Console\Command; | @@ -16,14 +20,16 @@ use Illuminate\Console\Command; | ||
| 16 | use Illuminate\Support\Facades\DB; | 20 | use Illuminate\Support\Facades\DB; |
| 17 | use App\Models\HomeCount\Count; | 21 | use App\Models\HomeCount\Count; |
| 18 | 22 | ||
| 19 | -class UpgradeProjectCount extends Command | 23 | +class CountProject extends Command |
| 20 | { | 24 | { |
| 25 | + const STATUS_ERROR = 400; | ||
| 26 | + public $error = 0; | ||
| 21 | /** | 27 | /** |
| 22 | * The name and signature of the console command. | 28 | * The name and signature of the console command. |
| 23 | * | 29 | * |
| 24 | * @var string | 30 | * @var string |
| 25 | */ | 31 | */ |
| 26 | - protected $signature = 'upgrade_count {project_id}'; | 32 | + protected $signature = 'count_project {project_id}'; |
| 27 | 33 | ||
| 28 | /** | 34 | /** |
| 29 | * The console command description. | 35 | * The console command description. |
| @@ -51,6 +57,19 @@ class UpgradeProjectCount extends Command | @@ -51,6 +57,19 @@ class UpgradeProjectCount extends Command | ||
| 51 | ->groupBy('updated_date')->get()->toArray(); | 57 | ->groupBy('updated_date')->get()->toArray(); |
| 52 | $project = new Project(); | 58 | $project = new Project(); |
| 53 | $projectInfo = $project->read(['id'=>$project_id]); | 59 | $projectInfo = $project->read(['id'=>$project_id]); |
| 60 | + $projectOptimizeModel = new DeployOptimize(); | ||
| 61 | + $optimizeInfo = $projectOptimizeModel->read(['project_id'=>$project_id]); | ||
| 62 | + $domain = ''; | ||
| 63 | + if(!empty($optimizeInfo['domain'])){ | ||
| 64 | + $domainInfoModel = new DomainInfo(); | ||
| 65 | + $domainInfo = $domainInfoModel->read(['id'=>$optimizeInfo['domain']]); | ||
| 66 | + if($domainInfo !== false){ | ||
| 67 | + $domain = $domainInfo['domain']; | ||
| 68 | + } | ||
| 69 | + } | ||
| 70 | + if(empty($domain)){ | ||
| 71 | + return false; | ||
| 72 | + } | ||
| 54 | if(!empty($list)){ | 73 | if(!empty($list)){ |
| 55 | $arr = []; | 74 | $arr = []; |
| 56 | foreach ($list as $k=>$v){ | 75 | foreach ($list as $k=>$v){ |
| @@ -64,12 +83,11 @@ class UpgradeProjectCount extends Command | @@ -64,12 +83,11 @@ class UpgradeProjectCount extends Command | ||
| 64 | $arr['date'] = $v['updated_date']; | 83 | $arr['date'] = $v['updated_date']; |
| 65 | $arr['pv_num'] = $this->pv_num($v['updated_date']); | 84 | $arr['pv_num'] = $this->pv_num($v['updated_date']); |
| 66 | $arr['ip_num'] = $this->ip_num($v['updated_date']); | 85 | $arr['ip_num'] = $this->ip_num($v['updated_date']); |
| 67 | - $arr['inquiry_num'] = $this->inquiry_num($v['updated_date']); | ||
| 68 | //服务达标天数 | 86 | //服务达标天数 |
| 69 | $arr['compliance_day'] = $projectInfo['finish_remain_day']; | 87 | $arr['compliance_day'] = $projectInfo['finish_remain_day']; |
| 70 | //剩余服务时常 | 88 | //剩余服务时常 |
| 71 | $arr['service_day'] = $projectInfo['remain_day']; | 89 | $arr['service_day'] = $projectInfo['remain_day']; |
| 72 | - $arr['country'] = json_encode([]); | 90 | + $arr = $this->inquiry($arr,$domain, $project_id); |
| 73 | //查询当天数据是否存在 存在则更新 | 91 | //查询当天数据是否存在 存在则更新 |
| 74 | $info = $count->read(['date'=>$v['updated_date'],'project_id'=>$project_id]); | 92 | $info = $count->read(['date'=>$v['updated_date'],'project_id'=>$project_id]); |
| 75 | if($info === false){ | 93 | if($info === false){ |
| @@ -103,7 +121,6 @@ class UpgradeProjectCount extends Command | @@ -103,7 +121,6 @@ class UpgradeProjectCount extends Command | ||
| 103 | * @time :2023/6/14 15:40 | 121 | * @time :2023/6/14 15:40 |
| 104 | */ | 122 | */ |
| 105 | public function pv_num($day){ | 123 | public function pv_num($day){ |
| 106 | - //$pv = DB::connection('custom_mysql')->table('gl_customer_visit_item')->whereDate('updated_date', $day)->count(); | ||
| 107 | $pv = DB::connection('custom_mysql')->table('gl_customer_visit')->whereDate('updated_date', $day)->sum('depth'); | 124 | $pv = DB::connection('custom_mysql')->table('gl_customer_visit')->whereDate('updated_date', $day)->sum('depth'); |
| 108 | return $pv; | 125 | return $pv; |
| 109 | } | 126 | } |
| @@ -119,6 +136,50 @@ class UpgradeProjectCount extends Command | @@ -119,6 +136,50 @@ class UpgradeProjectCount extends Command | ||
| 119 | return $ip; | 136 | return $ip; |
| 120 | } | 137 | } |
| 121 | 138 | ||
| 122 | - | 139 | + /** |
| 140 | + * @param $arr | ||
| 141 | + * @param $domain | ||
| 142 | + * @name :(询盘统计)inquiry | ||
| 143 | + * @author :lyh | ||
| 144 | + * @method :post | ||
| 145 | + * @time :2023/6/14 15:44 | ||
| 146 | + */ | ||
| 147 | + public function inquiry($arr,$domain,$project_id){ | ||
| 148 | + $inquiry_list = (new FormGlobalsoApi())->getInquiryList($domain,'',1,100000000); | ||
| 149 | + if($inquiry_list == false){ | ||
| 150 | + return false; | ||
| 151 | + } | ||
| 152 | + if($inquiry_list['status'] == self::STATUS_ERROR){ | ||
| 153 | + $arr['inquiry_num'] = 0; | ||
| 154 | + $countryArr = []; | ||
| 155 | + }else{ | ||
| 156 | + $arr['inquiry_num'] = $inquiry_list['data']['total']; | ||
| 157 | + //询盘国家统计 | ||
| 158 | + $countryData = $inquiry_list['data']['data']; | ||
| 159 | + $countryArr = []; | ||
| 160 | + foreach ($countryData as $v1){ | ||
| 161 | + if(isset($countryArr[$v1['country']])){ | ||
| 162 | + $countryArr[$v1['country']]++; | ||
| 163 | + }else{ | ||
| 164 | + $countryArr[$v1['country']] = 1; | ||
| 165 | + } | ||
| 166 | + } | ||
| 167 | + } | ||
| 168 | + //加上其他询盘 | ||
| 169 | + ProjectServer::useProject($project_id); | ||
| 170 | + $arr['inquiry_num'] += InquiryFormData::getCount(); | ||
| 171 | + $countryData = InquiryFormData::getCountryCount(); | ||
| 172 | + foreach ($countryData as $v1){ | ||
| 173 | + if(isset($countryArr[$v1['country']])){ | ||
| 174 | + $countryArr[$v1['country']] += $v1['count']; | ||
| 175 | + }else{ | ||
| 176 | + $countryArr[$v1['country']] = $v1['count']; | ||
| 177 | + } | ||
| 178 | + } | ||
| 179 | + arsort($countryArr); | ||
| 180 | + $top20 = array_slice($countryArr, 0, 20, true); | ||
| 181 | + $arr['country'] = json_encode($top20); | ||
| 182 | + return $arr; | ||
| 183 | + } | ||
| 123 | 184 | ||
| 124 | } | 185 | } |
| @@ -6,6 +6,7 @@ use App\Models\Inquiry\InquiryCount as InquiryCountModel; | @@ -6,6 +6,7 @@ use App\Models\Inquiry\InquiryCount as InquiryCountModel; | ||
| 6 | use App\Models\Inquiry\InquiryInfo; | 6 | use App\Models\Inquiry\InquiryInfo; |
| 7 | use Carbon\Carbon; | 7 | use Carbon\Carbon; |
| 8 | use Illuminate\Console\Command; | 8 | use Illuminate\Console\Command; |
| 9 | +use Illuminate\Support\Facades\Log; | ||
| 9 | 10 | ||
| 10 | /** | 11 | /** |
| 11 | * @remark : | 12 | * @remark : |
| @@ -62,20 +63,24 @@ class InquiryCount extends Command | @@ -62,20 +63,24 @@ class InquiryCount extends Command | ||
| 62 | //获取昨天的时间 | 63 | //获取昨天的时间 |
| 63 | $yesterday = Carbon::yesterday()->toDateString(); | 64 | $yesterday = Carbon::yesterday()->toDateString(); |
| 64 | $inquiryInfoModel = new InquiryInfo(); | 65 | $inquiryInfoModel = new InquiryInfo(); |
| 65 | - foreach ($this->status as $k=>$v){ | ||
| 66 | - $total = $inquiryInfoModel->formatQuery(['created_at'=>['between',[$yesterday.' 00:00:00',$yesterday.' 23:59:59']]])->count(); | ||
| 67 | - $untreated = $inquiryInfoModel->formatQuery(['created_at'=>['between',[$yesterday.' 00:00:00',$yesterday.' 23:59:59']],'status'=>1])->count(); | ||
| 68 | - $invalid = $inquiryInfoModel->formatQuery(['created_at'=>['between',[$yesterday.' 00:00:00',$yesterday.' 23:59:59']],'status'=>0])->count(); | ||
| 69 | - $data[] = [ | ||
| 70 | - 'type'=>$k, | ||
| 71 | - 'day'=>$yesterday, | ||
| 72 | - 'total'=>$total ?? 0, | ||
| 73 | - 'untreated'=>$untreated ?? 0, | ||
| 74 | - 'invalid'=>$invalid ?? 0 | ||
| 75 | - ]; | 66 | + try { |
| 67 | + foreach ($this->status as $k=>$v){ | ||
| 68 | + $total = $inquiryInfoModel->formatQuery(['created_at'=>['between',[$yesterday.' 00:00:00',$yesterday.' 23:59:59']]])->count(); | ||
| 69 | + $untreated = $inquiryInfoModel->formatQuery(['created_at'=>['between',[$yesterday.' 00:00:00',$yesterday.' 23:59:59']],'status'=>1])->count(); | ||
| 70 | + $invalid = $inquiryInfoModel->formatQuery(['created_at'=>['between',[$yesterday.' 00:00:00',$yesterday.' 23:59:59']],'status'=>0])->count(); | ||
| 71 | + $data[] = [ | ||
| 72 | + 'type'=>$k, | ||
| 73 | + 'day'=>$yesterday, | ||
| 74 | + 'total'=>$total ?? 0, | ||
| 75 | + 'untreated'=>$untreated ?? 0, | ||
| 76 | + 'invalid'=>$invalid ?? 0 | ||
| 77 | + ]; | ||
| 78 | + } | ||
| 79 | + $inquiryCount = new InquiryCountModel(); | ||
| 80 | + $inquiryCount->insert($data); | ||
| 81 | + }catch (\Exception $e){ | ||
| 82 | + Log::error('inquiry_count : error'); | ||
| 76 | } | 83 | } |
| 77 | - $inquiryCount = new InquiryCountModel(); | ||
| 78 | - $inquiryCount->insert($data); | ||
| 79 | return true; | 84 | return true; |
| 80 | } | 85 | } |
| 81 | } | 86 | } |
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * @remark : | ||
| 4 | + * @name :DeleteProductCategory.php | ||
| 5 | + * @author :lyh | ||
| 6 | + * @method :post | ||
| 7 | + * @time :2024/5/16 14:59 | ||
| 8 | + */ | ||
| 9 | + | ||
| 10 | +namespace App\Console\Commands\DeleteCategory; | ||
| 11 | + | ||
| 12 | +use App\Helper\Arr; | ||
| 13 | +use App\Models\Blog\Blog; | ||
| 14 | +use App\Models\Blog\BlogCategory; | ||
| 15 | +use App\Models\Com\NoticeLog; | ||
| 16 | +use App\Models\Project\Project; | ||
| 17 | +use App\Services\ProjectServer; | ||
| 18 | +use Illuminate\Console\Command; | ||
| 19 | +use Illuminate\Support\Facades\DB; | ||
| 20 | + | ||
| 21 | +/** | ||
| 22 | + * @remark :删除分类 | ||
| 23 | + * @name :DeleteProductCategory | ||
| 24 | + * @author :lyh | ||
| 25 | + * @method :post | ||
| 26 | + * @time :2024/5/16 15:00 | ||
| 27 | + */ | ||
| 28 | +class DeleteBlogCategory extends Command | ||
| 29 | +{ | ||
| 30 | + /** | ||
| 31 | + * The name and signature of the console command. | ||
| 32 | + * | ||
| 33 | + * @var string | ||
| 34 | + */ | ||
| 35 | + protected $signature = 'delete_blog_category'; | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * The console command description. | ||
| 39 | + * | ||
| 40 | + * @var string | ||
| 41 | + */ | ||
| 42 | + protected $description = '删除博客分类'; | ||
| 43 | + | ||
| 44 | + /** | ||
| 45 | + * Create a new command instance. | ||
| 46 | + * | ||
| 47 | + * @return void | ||
| 48 | + */ | ||
| 49 | + public function __construct() | ||
| 50 | + { | ||
| 51 | + parent::__construct(); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + /** | ||
| 55 | + * @remark :批量处理 | ||
| 56 | + * @name :handle | ||
| 57 | + * @author :lyh | ||
| 58 | + * @method :post | ||
| 59 | + * @time :2024/5/16 15:02 | ||
| 60 | + */ | ||
| 61 | + public function handle(){ | ||
| 62 | + while (true){ | ||
| 63 | + $noticeLogModel = new NoticeLog(); | ||
| 64 | + $list = $noticeLogModel->list(['status'=>NoticeLog::STATUS_PENDING,'type'=>NoticeLog::DELETE_BLOG_CATEGORY],'id',['*'],'asc',100); | ||
| 65 | + if(empty($list)){ | ||
| 66 | + sleep(10); | ||
| 67 | + continue; | ||
| 68 | + } | ||
| 69 | + foreach ($list as $item){ | ||
| 70 | + echo 'start:' . $item['id'] . PHP_EOL; | ||
| 71 | + try { | ||
| 72 | + $projectModel = new Project(); | ||
| 73 | + $projectInfo = $projectModel->read(['id'=>$item['data']['project_id']]); | ||
| 74 | + if($projectInfo === false){ | ||
| 75 | + continue; | ||
| 76 | + } | ||
| 77 | + ProjectServer::useProject($projectInfo['id']); | ||
| 78 | + $this->updateCategory(); | ||
| 79 | + DB::disconnect('custom_mysql'); | ||
| 80 | + $noticeLogModel->edit(['status'=>NoticeLog::STATUS_SUCCESS],['id'=>$item['id']]); | ||
| 81 | + echo 'success:' . $item['id'] . PHP_EOL; | ||
| 82 | + }catch (\Exception $e){ | ||
| 83 | + echo 'error:' . $item['id'] . $e->getMessage() . PHP_EOL; | ||
| 84 | + errorLog('delete_blog_category删除失败', $item, $e); | ||
| 85 | + } | ||
| 86 | + } | ||
| 87 | + return true; | ||
| 88 | + } | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + /** | ||
| 92 | + * @remark :更新分类 | ||
| 93 | + * @name :updateProductCategory | ||
| 94 | + * @author :lyh | ||
| 95 | + * @method :post | ||
| 96 | + * @time :2024/5/16 15:38 | ||
| 97 | + */ | ||
| 98 | + public function updateCategory(){ | ||
| 99 | + $page = 1; | ||
| 100 | + $blogModel = new Blog(); | ||
| 101 | + while (true){ | ||
| 102 | + $blogList = $blogModel->lists(['status'=>1],$page,1000,'id',['id','category_id']); | ||
| 103 | + if(empty($blogList) || empty($blogList['list'])){ | ||
| 104 | + return false; | ||
| 105 | + } | ||
| 106 | + foreach ($blogList['list'] as $v){ | ||
| 107 | + $category_id_arr = Arr::setToArr(trim($v['category_id'],',')); | ||
| 108 | + if(empty($category_id_arr)){ | ||
| 109 | + continue; | ||
| 110 | + } | ||
| 111 | + $categoryModel = new BlogCategory(); | ||
| 112 | + foreach ($category_id_arr as $k=>$cate_id){ | ||
| 113 | + $cateInfo = $categoryModel->read(['id'=>$cate_id],['id']); | ||
| 114 | + if($cateInfo == false){ | ||
| 115 | + //删除关联表 | ||
| 116 | + unset($category_id_arr[$k]); | ||
| 117 | + } | ||
| 118 | + } | ||
| 119 | + $str = !empty($category_id_arr) ? ','.Arr::arrToSet($category_id_arr).',' : ''; | ||
| 120 | + $blogModel->edit(['category_id'=>$str],['id'=>$v['id']]); | ||
| 121 | + } | ||
| 122 | + $page++; | ||
| 123 | + } | ||
| 124 | + return true; | ||
| 125 | + } | ||
| 126 | +} |
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * @remark : | ||
| 4 | + * @name :DeleteProductCategory.php | ||
| 5 | + * @author :lyh | ||
| 6 | + * @method :post | ||
| 7 | + * @time :2024/5/16 14:59 | ||
| 8 | + */ | ||
| 9 | + | ||
| 10 | +namespace App\Console\Commands\DeleteCategory; | ||
| 11 | + | ||
| 12 | +use App\Helper\Arr; | ||
| 13 | +use App\Models\Com\NoticeLog; | ||
| 14 | +use App\Models\CustomModule\CustomModuleCategory; | ||
| 15 | +use App\Models\CustomModule\CustomModuleContent; | ||
| 16 | +use App\Models\Project\Project; | ||
| 17 | +use App\Services\ProjectServer; | ||
| 18 | +use Illuminate\Console\Command; | ||
| 19 | +use Illuminate\Support\Facades\DB; | ||
| 20 | + | ||
| 21 | +/** | ||
| 22 | + * @remark :删除分类 | ||
| 23 | + * @name :DeleteProductCategory | ||
| 24 | + * @author :lyh | ||
| 25 | + * @method :post | ||
| 26 | + * @time :2024/5/16 15:00 | ||
| 27 | + */ | ||
| 28 | +class DeleteCustomCategory extends Command | ||
| 29 | +{ | ||
| 30 | + /** | ||
| 31 | + * The name and signature of the console command. | ||
| 32 | + * | ||
| 33 | + * @var string | ||
| 34 | + */ | ||
| 35 | + protected $signature = 'delete_custom_category'; | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * The console command description. | ||
| 39 | + * | ||
| 40 | + * @var string | ||
| 41 | + */ | ||
| 42 | + protected $description = '删除扩展模块分类'; | ||
| 43 | + | ||
| 44 | + /** | ||
| 45 | + * Create a new command instance. | ||
| 46 | + * | ||
| 47 | + * @return void | ||
| 48 | + */ | ||
| 49 | + public function __construct() | ||
| 50 | + { | ||
| 51 | + parent::__construct(); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + /** | ||
| 55 | + * @remark :批量处理 | ||
| 56 | + * @name :handle | ||
| 57 | + * @author :lyh | ||
| 58 | + * @method :post | ||
| 59 | + * @time :2024/5/16 15:02 | ||
| 60 | + */ | ||
| 61 | + public function handle(){ | ||
| 62 | + while (true){ | ||
| 63 | + $noticeLogModel = new NoticeLog(); | ||
| 64 | + $list = $noticeLogModel->list(['status'=>NoticeLog::STATUS_PENDING,'type'=>NoticeLog::DELETE_CUSTOM_CATEGORY],'id',['*'],'asc',100); | ||
| 65 | + if(empty($list)){ | ||
| 66 | + sleep(10); | ||
| 67 | + continue; | ||
| 68 | + } | ||
| 69 | + foreach ($list as $item){ | ||
| 70 | + echo 'start:' . $item['id'] . PHP_EOL; | ||
| 71 | + try { | ||
| 72 | + $projectModel = new Project(); | ||
| 73 | + $projectInfo = $projectModel->read(['id'=>$item['data']['project_id']]); | ||
| 74 | + if($projectInfo === false){ | ||
| 75 | + continue; | ||
| 76 | + } | ||
| 77 | + ProjectServer::useProject($projectInfo['id']); | ||
| 78 | + $this->updateCategory(); | ||
| 79 | + DB::disconnect('custom_mysql'); | ||
| 80 | + $noticeLogModel->edit(['status'=>NoticeLog::STATUS_SUCCESS],['id'=>$item['id']]); | ||
| 81 | + echo 'success:' . $item['id'] . PHP_EOL; | ||
| 82 | + }catch (\Exception $e){ | ||
| 83 | + echo 'error:' . $item['id'] . $e->getMessage() . PHP_EOL; | ||
| 84 | + errorLog('delete_custom_category删除失败', $item, $e); | ||
| 85 | + } | ||
| 86 | + } | ||
| 87 | + return true; | ||
| 88 | + } | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + /** | ||
| 92 | + * @remark :更新分类 | ||
| 93 | + * @name :updateProductCategory | ||
| 94 | + * @author :lyh | ||
| 95 | + * @method :post | ||
| 96 | + * @time :2024/5/16 15:38 | ||
| 97 | + */ | ||
| 98 | + public function updateCategory(){ | ||
| 99 | + $page = 1; | ||
| 100 | + $customModel = new CustomModuleContent(); | ||
| 101 | + while (true){ | ||
| 102 | + $customList = $customModel->lists(['status'=>0],$page,1000,'id',['id','category_id']); | ||
| 103 | + if(empty($customList) || empty($customList['list'])){ | ||
| 104 | + return false; | ||
| 105 | + } | ||
| 106 | + foreach ($customList['list'] as $v){ | ||
| 107 | + $category_id_arr = $v['category_id']; | ||
| 108 | + if(empty($category_id_arr)){ | ||
| 109 | + continue; | ||
| 110 | + } | ||
| 111 | + $categoryModel = new CustomModuleCategory(); | ||
| 112 | + foreach ($category_id_arr as $k=>$cate_id){ | ||
| 113 | + $cateInfo = $categoryModel->read(['id'=>$cate_id],['id']); | ||
| 114 | + if($cateInfo == false){ | ||
| 115 | + //删除关联表 | ||
| 116 | + unset($category_id_arr[$k]); | ||
| 117 | + } | ||
| 118 | + } | ||
| 119 | + $str = !empty($category_id_arr) ? ','.Arr::arrToSet($category_id_arr).',' : ''; | ||
| 120 | + $customModel->edit(['category_id'=>$str],['id'=>$v['id']]); | ||
| 121 | + } | ||
| 122 | + $page++; | ||
| 123 | + } | ||
| 124 | + return true; | ||
| 125 | + } | ||
| 126 | +} |
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * @remark : | ||
| 4 | + * @name :DeleteProductCategory.php | ||
| 5 | + * @author :lyh | ||
| 6 | + * @method :post | ||
| 7 | + * @time :2024/5/16 14:59 | ||
| 8 | + */ | ||
| 9 | + | ||
| 10 | +namespace App\Console\Commands\DeleteCategory; | ||
| 11 | + | ||
| 12 | +use App\Helper\Arr; | ||
| 13 | +use App\Models\Com\NoticeLog; | ||
| 14 | +use App\Models\News\News; | ||
| 15 | +use App\Models\News\NewsCategory; | ||
| 16 | +use App\Models\Project\Project; | ||
| 17 | +use App\Services\ProjectServer; | ||
| 18 | +use Illuminate\Console\Command; | ||
| 19 | +use Illuminate\Support\Facades\DB; | ||
| 20 | + | ||
| 21 | +/** | ||
| 22 | + * @remark :删除分类 | ||
| 23 | + * @name :DeleteProductCategory | ||
| 24 | + * @author :lyh | ||
| 25 | + * @method :post | ||
| 26 | + * @time :2024/5/16 15:00 | ||
| 27 | + */ | ||
| 28 | +class DeleteNewsCategory extends Command | ||
| 29 | +{ | ||
| 30 | + /** | ||
| 31 | + * The name and signature of the console command. | ||
| 32 | + * | ||
| 33 | + * @var string | ||
| 34 | + */ | ||
| 35 | + protected $signature = 'delete_news_category'; | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * The console command description. | ||
| 39 | + * | ||
| 40 | + * @var string | ||
| 41 | + */ | ||
| 42 | + protected $description = '删除新闻分类'; | ||
| 43 | + | ||
| 44 | + /** | ||
| 45 | + * Create a new command instance. | ||
| 46 | + * | ||
| 47 | + * @return void | ||
| 48 | + */ | ||
| 49 | + public function __construct() | ||
| 50 | + { | ||
| 51 | + parent::__construct(); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + /** | ||
| 55 | + * @remark :批量处理 | ||
| 56 | + * @name :handle | ||
| 57 | + * @author :lyh | ||
| 58 | + * @method :post | ||
| 59 | + * @time :2024/5/16 15:02 | ||
| 60 | + */ | ||
| 61 | + public function handle(){ | ||
| 62 | + while (true){ | ||
| 63 | + $noticeLogModel = new NoticeLog(); | ||
| 64 | + $list = $noticeLogModel->list(['status'=>NoticeLog::STATUS_PENDING,'type'=>NoticeLog::DELETE_NEWS_CATEGORY],'id',['*'],'asc',100); | ||
| 65 | + if(empty($list)){ | ||
| 66 | + sleep(10); | ||
| 67 | + continue; | ||
| 68 | + } | ||
| 69 | + foreach ($list as $item){ | ||
| 70 | + echo 'start:' . $item['id'] . PHP_EOL; | ||
| 71 | + try { | ||
| 72 | + $projectModel = new Project(); | ||
| 73 | + $projectInfo = $projectModel->read(['id'=>$item['data']['project_id']]); | ||
| 74 | + if($projectInfo === false){ | ||
| 75 | + continue; | ||
| 76 | + } | ||
| 77 | + ProjectServer::useProject($projectInfo['id']); | ||
| 78 | + $this->updateCategory(); | ||
| 79 | + DB::disconnect('custom_mysql'); | ||
| 80 | + $noticeLogModel->edit(['status'=>NoticeLog::STATUS_SUCCESS],['id'=>$item['id']]); | ||
| 81 | + echo 'success:' . $item['id'] . PHP_EOL; | ||
| 82 | + }catch (\Exception $e){ | ||
| 83 | + echo 'error:' . $item['id'] . $e->getMessage() . PHP_EOL; | ||
| 84 | + errorLog('delete_news_category删除失败', $item, $e); | ||
| 85 | + } | ||
| 86 | + } | ||
| 87 | + return true; | ||
| 88 | + } | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + /** | ||
| 92 | + * @remark :更新分类 | ||
| 93 | + * @name :updateProductCategory | ||
| 94 | + * @author :lyh | ||
| 95 | + * @method :post | ||
| 96 | + * @time :2024/5/16 15:38 | ||
| 97 | + */ | ||
| 98 | + public function updateCategory(){ | ||
| 99 | + $page = 1; | ||
| 100 | + $newsModel = new News(); | ||
| 101 | + while (true){ | ||
| 102 | + $newsList = $newsModel->lists(['status'=>1],$page,1000,'id',['id','category_id']); | ||
| 103 | + if(empty($newsList) || empty($newsList['list'])){ | ||
| 104 | + return false; | ||
| 105 | + } | ||
| 106 | + foreach ($newsList['list'] as $v){ | ||
| 107 | + $category_id_arr = Arr::setToArr(trim($v['category_id'],',')); | ||
| 108 | + if(empty($category_id_arr)){ | ||
| 109 | + continue; | ||
| 110 | + } | ||
| 111 | + $categoryModel = new NewsCategory(); | ||
| 112 | + foreach ($category_id_arr as $k=>$cate_id){ | ||
| 113 | + $cateInfo = $categoryModel->read(['id'=>$cate_id],['id']); | ||
| 114 | + if($cateInfo === false){ | ||
| 115 | + //删除关联表 | ||
| 116 | + unset($category_id_arr[$k]); | ||
| 117 | + } | ||
| 118 | + } | ||
| 119 | + $str = !empty($category_id_arr) ? ','.Arr::arrToSet($category_id_arr).',' : ''; | ||
| 120 | + $newsModel->edit(['category_id'=>$str],['id'=>$v['id']]); | ||
| 121 | + } | ||
| 122 | + $page++; | ||
| 123 | + } | ||
| 124 | + return true; | ||
| 125 | + } | ||
| 126 | +} |
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * @remark : | ||
| 4 | + * @name :DeleteProductCategory.php | ||
| 5 | + * @author :lyh | ||
| 6 | + * @method :post | ||
| 7 | + * @time :2024/5/16 14:59 | ||
| 8 | + */ | ||
| 9 | + | ||
| 10 | +namespace App\Console\Commands\DeleteCategory; | ||
| 11 | + | ||
| 12 | +use App\Helper\Arr; | ||
| 13 | +use App\Models\Com\NoticeLog; | ||
| 14 | +use App\Models\Product\Category; | ||
| 15 | +use App\Models\Product\CategoryRelated; | ||
| 16 | +use App\Models\Product\Product; | ||
| 17 | +use App\Models\Project\Project; | ||
| 18 | +use App\Services\ProjectServer; | ||
| 19 | +use Illuminate\Console\Command; | ||
| 20 | +use Illuminate\Support\Facades\DB; | ||
| 21 | + | ||
| 22 | +/** | ||
| 23 | + * @remark :删除分类 | ||
| 24 | + * @name :DeleteProductCategory | ||
| 25 | + * @author :lyh | ||
| 26 | + * @method :post | ||
| 27 | + * @time :2024/5/16 15:00 | ||
| 28 | + */ | ||
| 29 | +class DeleteProductCategory extends Command | ||
| 30 | +{ | ||
| 31 | + /** | ||
| 32 | + * The name and signature of the console command. | ||
| 33 | + * | ||
| 34 | + * @var string | ||
| 35 | + */ | ||
| 36 | + protected $signature = 'delete_product_category'; | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * The console command description. | ||
| 40 | + * | ||
| 41 | + * @var string | ||
| 42 | + */ | ||
| 43 | + protected $description = '删除产品分类'; | ||
| 44 | + | ||
| 45 | + /** | ||
| 46 | + * Create a new command instance. | ||
| 47 | + * | ||
| 48 | + * @return void | ||
| 49 | + */ | ||
| 50 | + public function __construct() | ||
| 51 | + { | ||
| 52 | + parent::__construct(); | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + /** | ||
| 56 | + * @remark :批量处理 | ||
| 57 | + * @name :handle | ||
| 58 | + * @author :lyh | ||
| 59 | + * @method :post | ||
| 60 | + * @time :2024/5/16 15:02 | ||
| 61 | + */ | ||
| 62 | + public function handle(){ | ||
| 63 | + while (true){ | ||
| 64 | + $noticeLogModel = new NoticeLog(); | ||
| 65 | + $list = $noticeLogModel->list(['status'=>NoticeLog::STATUS_PENDING,'type'=>NoticeLog::DELETE_PRODUCT_CATEGORY],'id',['*'],'asc',100); | ||
| 66 | + if(empty($list)){ | ||
| 67 | + sleep(10); | ||
| 68 | + continue; | ||
| 69 | + } | ||
| 70 | + foreach ($list as $item){ | ||
| 71 | + echo 'start:' . $item['id'] . PHP_EOL; | ||
| 72 | + try { | ||
| 73 | + $projectModel = new Project(); | ||
| 74 | + $projectInfo = $projectModel->read(['id'=>$item['data']['project_id']]); | ||
| 75 | + if($projectInfo === false){ | ||
| 76 | + continue; | ||
| 77 | + } | ||
| 78 | + ProjectServer::useProject($projectInfo['id']); | ||
| 79 | + $this->updateCategory(); | ||
| 80 | + DB::disconnect('custom_mysql'); | ||
| 81 | + $noticeLogModel->edit(['status'=>NoticeLog::STATUS_SUCCESS],['id'=>$item['id']]); | ||
| 82 | + echo 'success:' . $item['id'] . PHP_EOL; | ||
| 83 | + }catch (\Exception $e){ | ||
| 84 | + echo 'error:' . $item['id'] . $e->getMessage() . PHP_EOL; | ||
| 85 | + errorLog('delete_product_category删除失败', $item, $e); | ||
| 86 | + } | ||
| 87 | + } | ||
| 88 | + return true; | ||
| 89 | + } | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + /** | ||
| 93 | + * @remark :更新分类 | ||
| 94 | + * @name :updateProductCategory | ||
| 95 | + * @author :lyh | ||
| 96 | + * @method :post | ||
| 97 | + * @time :2024/5/16 15:38 | ||
| 98 | + */ | ||
| 99 | + public function updateCategory(){ | ||
| 100 | + $page = 1; | ||
| 101 | + while (true){ | ||
| 102 | + $productModel = new Product(); | ||
| 103 | + $productList = $productModel->lists(['status'=>1],$page,1000,'id',['id','category_id']); | ||
| 104 | + if(empty($productList) || empty($productList['list'])){ | ||
| 105 | + return false; | ||
| 106 | + } | ||
| 107 | + foreach ($productList['list'] as $v){ | ||
| 108 | + $categoryRelatedModel = new CategoryRelated(); | ||
| 109 | + if(empty($v['category_id'])){ | ||
| 110 | + $categoryRelatedModel->del(['product_id'=>$v['id']]); | ||
| 111 | + continue; | ||
| 112 | + } | ||
| 113 | + $category_id_arr = $v['category_id']; | ||
| 114 | + $categoryModel = new Category(); | ||
| 115 | + foreach ($category_id_arr as $k=>$cate_id){ | ||
| 116 | + $cateInfo = $categoryModel->read(['id'=>$cate_id],['id']); | ||
| 117 | + if($cateInfo == false){ | ||
| 118 | + //删除关联表 | ||
| 119 | + $categoryRelatedModel->del(['cate_id'=>$cate_id]); | ||
| 120 | + unset($category_id_arr[$k]); | ||
| 121 | + } | ||
| 122 | + } | ||
| 123 | + $str = !empty($category_id_arr) ? ','.Arr::arrToSet($category_id_arr).',' : ''; | ||
| 124 | + $productModel->edit(['category_id'=>$str],['id'=>$v['id']]); | ||
| 125 | + } | ||
| 126 | + $page++; | ||
| 127 | + } | ||
| 128 | + return true; | ||
| 129 | + } | ||
| 130 | +} |
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * @remark : | ||
| 4 | + * @name :TemplateLog.php | ||
| 5 | + * @author :lyh | ||
| 6 | + * @method :post | ||
| 7 | + * @time :2024/7/10 14:44 | ||
| 8 | + */ | ||
| 9 | + | ||
| 10 | +namespace App\Console\Commands\DeleteTemplate; | ||
| 11 | + | ||
| 12 | +use App\Models\Project\Project; | ||
| 13 | +use App\Models\Template\BTemplateLog; | ||
| 14 | +use App\Services\ProjectServer; | ||
| 15 | +use Illuminate\Console\Command; | ||
| 16 | +use Illuminate\Support\Facades\DB; | ||
| 17 | + | ||
| 18 | +class TemplateLog extends Command | ||
| 19 | +{ | ||
| 20 | + /** | ||
| 21 | + * The name and signature of the console command. | ||
| 22 | + * | ||
| 23 | + * @var string | ||
| 24 | + */ | ||
| 25 | + protected $signature = 'delete_template_log'; | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * The console command description. | ||
| 29 | + * | ||
| 30 | + * @var string | ||
| 31 | + */ | ||
| 32 | + protected $description = '定时清理日志'; | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * Create a new command instance. | ||
| 36 | + * | ||
| 37 | + * @return void | ||
| 38 | + */ | ||
| 39 | + public function __construct() | ||
| 40 | + { | ||
| 41 | + parent::__construct(); | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + public function handle(){ | ||
| 45 | + $projectModel = new Project(); | ||
| 46 | + $list = $projectModel->list(['delete_status'=>0]); | ||
| 47 | + foreach ($list as $v){ | ||
| 48 | + echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL; | ||
| 49 | + ProjectServer::useProject($v['id']); | ||
| 50 | + $this->deleteTemplate(); | ||
| 51 | + DB::disconnect('custom_mysql'); | ||
| 52 | + } | ||
| 53 | + echo date('Y-m-d H:i:s') . 'end' . PHP_EOL; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + /** | ||
| 57 | + * @remark :定时清理可视化日志 | ||
| 58 | + * @name :deleteTemplate | ||
| 59 | + * @author :lyh | ||
| 60 | + * @method :post | ||
| 61 | + * @time :2024/7/10 14:48 | ||
| 62 | + */ | ||
| 63 | + public function deleteTemplate(){ | ||
| 64 | + $startDate = date("Y-m-01 00:00:00"); | ||
| 65 | + $endDate = date("Y-m-t 23:59:59"); | ||
| 66 | + $templateLogModel = new BTemplateLog(); | ||
| 67 | + return $templateLogModel->del(['created_at'=>['not between'=>[$startDate,$endDate]]]); | ||
| 68 | + } | ||
| 69 | +} |
| @@ -9,7 +9,10 @@ | @@ -9,7 +9,10 @@ | ||
| 9 | 9 | ||
| 10 | namespace App\Console\Commands\Domain; | 10 | namespace App\Console\Commands\Domain; |
| 11 | 11 | ||
| 12 | +use App\Models\Devops\ServerConfig; | ||
| 13 | +use App\Models\Devops\ServersIp; | ||
| 12 | use App\Models\Project\CountryCustom; | 14 | use App\Models\Project\CountryCustom; |
| 15 | +use App\Models\Project\Project; | ||
| 13 | use Illuminate\Console\Command; | 16 | use Illuminate\Console\Command; |
| 14 | use App\Models\Domain\DomainInfo as DomainInfoModel; | 17 | use App\Models\Domain\DomainInfo as DomainInfoModel; |
| 15 | 18 | ||
| @@ -61,7 +64,7 @@ class DomainInfo extends Command | @@ -61,7 +64,7 @@ class DomainInfo extends Command | ||
| 61 | public function startUpdateDomain() | 64 | public function startUpdateDomain() |
| 62 | { | 65 | { |
| 63 | $domainModel = new DomainInfoModel(); | 66 | $domainModel = new DomainInfoModel(); |
| 64 | - $list = $domainModel->where('status', '!=', 2)->where(function ($query) { | 67 | + $list = $domainModel->where('status', '=', 1)->where(function ($query) { |
| 65 | $query->whereNull('domain_end_time')->orWhere('domain_end_time', '<', date('Y-m-d H:i:s')); | 68 | $query->whereNull('domain_end_time')->orWhere('domain_end_time', '<', date('Y-m-d H:i:s')); |
| 66 | })->get()->toArray(); | 69 | })->get()->toArray(); |
| 67 | foreach ($list as $v) { | 70 | foreach ($list as $v) { |
| @@ -70,7 +73,6 @@ class DomainInfo extends Command | @@ -70,7 +73,6 @@ class DomainInfo extends Command | ||
| 70 | 'domain_start_time' => $time['start'], | 73 | 'domain_start_time' => $time['start'], |
| 71 | 'domain_end_time' => $time['end'] | 74 | 'domain_end_time' => $time['end'] |
| 72 | ]; | 75 | ]; |
| 73 | - | ||
| 74 | $domainModel->edit($data, ['id' => $v['id']]); | 76 | $domainModel->edit($data, ['id' => $v['id']]); |
| 75 | } | 77 | } |
| 76 | } | 78 | } |
| @@ -83,8 +85,9 @@ class DomainInfo extends Command | @@ -83,8 +85,9 @@ class DomainInfo extends Command | ||
| 83 | public function startUpdateCert() | 85 | public function startUpdateCert() |
| 84 | { | 86 | { |
| 85 | $domainModel = new DomainInfoModel(); | 87 | $domainModel = new DomainInfoModel(); |
| 88 | + $projectModel = new Project(); | ||
| 86 | $end_day = date('Y-m-d H:i:s', time() + 3 * 24 * 3600);//3天后到期 | 89 | $end_day = date('Y-m-d H:i:s', time() + 3 * 24 * 3600);//3天后到期 |
| 87 | - $list = $domainModel->where('status', '!=', 2)->where(function ($query) use ($end_day) { | 90 | + $list = $domainModel->where('status', '=', 1)->where(function ($query) use ($end_day) { |
| 88 | $query->whereNull('certificate_end_time')->orWhere('certificate_end_time', '<', $end_day); | 91 | $query->whereNull('certificate_end_time')->orWhere('certificate_end_time', '<', $end_day); |
| 89 | })->get()->toArray(); | 92 | })->get()->toArray(); |
| 90 | foreach ($list as $v) { | 93 | foreach ($list as $v) { |
| @@ -95,13 +98,19 @@ class DomainInfo extends Command | @@ -95,13 +98,19 @@ class DomainInfo extends Command | ||
| 95 | $ssl['from'] && $data['certificate_start_time'] = $ssl['from']; | 98 | $ssl['from'] && $data['certificate_start_time'] = $ssl['from']; |
| 96 | $ssl['to'] && $data['certificate_end_time'] = $ssl['to']; | 99 | $ssl['to'] && $data['certificate_end_time'] = $ssl['to']; |
| 97 | 100 | ||
| 98 | - if ($v['type'] == 1 && $ssl['to'] < $end_day) { | ||
| 99 | - //申请免费证书 | ||
| 100 | - $this->updatePrivate($v); | 101 | + $project_info = $projectModel->read(['id' => $v['project_id']], ['serve_id']); |
| 102 | + if ($v['type'] == 1 && $ssl['to'] < $end_day && $project_info) { | ||
| 103 | + $serverIpModel = new ServersIp(); | ||
| 104 | + $servers_ip_info = $serverIpModel->read(['id' => $project_info['serve_id']], ['servers_id']); | ||
| 105 | + if ($servers_ip_info && $servers_ip_info['servers_id'] != ServerConfig::SELF_SITE_ID) { | ||
| 106 | + //非自建站项目,申请免费证书 | ||
| 107 | + $this->updatePrivate($v); | ||
| 108 | + | ||
| 109 | + $ssl_new = $this->updateDomainSsl($v['domain']); | ||
| 110 | + $ssl_new['from'] && $data['certificate_start_time'] = $ssl_new['from']; | ||
| 111 | + $ssl_new['to'] && $data['certificate_end_time'] = $ssl_new['to']; | ||
| 112 | + } | ||
| 101 | 113 | ||
| 102 | - $ssl_new = $this->updateDomainSsl($v['domain']); | ||
| 103 | - $ssl_new['from'] && $data['certificate_start_time'] = $ssl_new['from']; | ||
| 104 | - $ssl_new['to'] && $data['certificate_end_time'] = $ssl_new['to']; | ||
| 105 | } | 114 | } |
| 106 | 115 | ||
| 107 | $domainModel->edit($data, ['id' => $v['id']]); | 116 | $domainModel->edit($data, ['id' => $v['id']]); |
| @@ -116,8 +125,9 @@ class DomainInfo extends Command | @@ -116,8 +125,9 @@ class DomainInfo extends Command | ||
| 116 | public function startUpdateAmpCert() | 125 | public function startUpdateAmpCert() |
| 117 | { | 126 | { |
| 118 | $domainModel = new DomainInfoModel(); | 127 | $domainModel = new DomainInfoModel(); |
| 128 | + $projectModel = new Project(); | ||
| 119 | $end_day = date('Y-m-d H:i:s', time() + 3 * 24 * 3600);//3天后到期 | 129 | $end_day = date('Y-m-d H:i:s', time() + 3 * 24 * 3600);//3天后到期 |
| 120 | - $list = $domainModel->where('status', '!=', 2)->where('amp_status', 1)->where(function ($query) use ($end_day) { | 130 | + $list = $domainModel->where('status', '=', 1)->where('amp_status', 1)->where(function ($query) use ($end_day) { |
| 121 | $query->whereNull('amp_certificate_end_time')->orWhere('amp_certificate_end_time', '<', $end_day); | 131 | $query->whereNull('amp_certificate_end_time')->orWhere('amp_certificate_end_time', '<', $end_day); |
| 122 | })->get()->toArray(); | 132 | })->get()->toArray(); |
| 123 | foreach ($list as $v) { | 133 | foreach ($list as $v) { |
| @@ -137,13 +147,18 @@ class DomainInfo extends Command | @@ -137,13 +147,18 @@ class DomainInfo extends Command | ||
| 137 | $ssl['from'] && $data['amp_certificate_start_time'] = $ssl['from']; | 147 | $ssl['from'] && $data['amp_certificate_start_time'] = $ssl['from']; |
| 138 | $ssl['to'] && $data['amp_certificate_end_time'] = $ssl['to']; | 148 | $ssl['to'] && $data['amp_certificate_end_time'] = $ssl['to']; |
| 139 | 149 | ||
| 140 | - if ($v['amp_type'] == 1 && $ssl['to'] < $end_day) { | ||
| 141 | - //申请免费证书 | ||
| 142 | - $this->updateAmpPrivate($v['domain']); | ||
| 143 | - | ||
| 144 | - $ssl_new = $this->updateDomainSsl($v['domain']); | ||
| 145 | - $ssl_new['from'] && $data['certificate_start_time'] = $ssl_new['from']; | ||
| 146 | - $ssl_new['to'] && $data['certificate_end_time'] = $ssl_new['to']; | 150 | + $project_info = $projectModel->read(['id' => $v['project_id']], ['serve_id']); |
| 151 | + if ($v['amp_type'] == 1 && $ssl['to'] < $end_day && $project_info) { | ||
| 152 | + $serverIpModel = new ServersIp(); | ||
| 153 | + $servers_ip_info = $serverIpModel->read(['id' => $project_info['serve_id']], ['servers_id']); | ||
| 154 | + if ($servers_ip_info && $servers_ip_info['servers_id'] != ServerConfig::SELF_SITE_ID) { | ||
| 155 | + //非自建站项目,申请免费证书 | ||
| 156 | + $this->updateAmpPrivate($v); | ||
| 157 | + | ||
| 158 | + $ssl_new = $this->updateDomainSsl($v['domain']); | ||
| 159 | + $ssl_new['from'] && $data['certificate_start_time'] = $ssl_new['from']; | ||
| 160 | + $ssl_new['to'] && $data['certificate_end_time'] = $ssl_new['to']; | ||
| 161 | + } | ||
| 147 | } | 162 | } |
| 148 | 163 | ||
| 149 | $domainModel->edit($data, ['id' => $v['id']]); | 164 | $domainModel->edit($data, ['id' => $v['id']]); |
| @@ -197,24 +212,28 @@ class DomainInfo extends Command | @@ -197,24 +212,28 @@ class DomainInfo extends Command | ||
| 197 | "rewrite" => $param['extend_config'], | 212 | "rewrite" => $param['extend_config'], |
| 198 | 'other_domain' => $param['other_domain'], | 213 | 'other_domain' => $param['other_domain'], |
| 199 | 'is_https' => $param['is_https'], | 214 | 'is_https' => $param['is_https'], |
| 215 | + 'not_allow_country' => $param['not_allow_country'], | ||
| 216 | + 'not_allow_ip' => $param['not_allow_ip'], | ||
| 217 | + 'is_redirect' => $param['is_redirect'] | ||
| 200 | ]; | 218 | ]; |
| 201 | return $this->curlRequest($url, $param); | 219 | return $this->curlRequest($url, $param); |
| 202 | } | 220 | } |
| 203 | 221 | ||
| 204 | /** | 222 | /** |
| 205 | * 更新amp站证书 | 223 | * 更新amp站证书 |
| 206 | - * @param $domain | 224 | + * @param $param |
| 207 | * @return array | 225 | * @return array |
| 208 | * @author Akun | 226 | * @author Akun |
| 209 | * @date 2024/02/26 10:25 | 227 | * @date 2024/02/26 10:25 |
| 210 | */ | 228 | */ |
| 211 | - public function updateAmpPrivate($domain) | 229 | + public function updateAmpPrivate($param) |
| 212 | { | 230 | { |
| 213 | - $url = 'https://' . $domain . '/api/createSiteAmp/'; | 231 | + $url = 'https://' . $param['domain'] . '/api/createSiteAmp/'; |
| 214 | $param = [ | 232 | $param = [ |
| 215 | - "domain" => $domain, | ||
| 216 | - 'private_key' => '', | ||
| 217 | - 'cert' => '' | 233 | + "domain" => $param['domain'], |
| 234 | + 'not_allow_country' => $param['not_allow_country'], | ||
| 235 | + 'not_allow_ip' => $param['not_allow_ip'], | ||
| 236 | + 'is_redirect' => $param['is_redirect'] | ||
| 218 | ]; | 237 | ]; |
| 219 | return $this->curlRequest($url, $param); | 238 | return $this->curlRequest($url, $param); |
| 220 | } | 239 | } |
| @@ -283,9 +302,9 @@ class DomainInfo extends Command | @@ -283,9 +302,9 @@ class DomainInfo extends Command | ||
| 283 | ], | 302 | ], |
| 284 | ]); | 303 | ]); |
| 285 | $stream = stream_socket_client('ssl://' . $domain . ':443', $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context); | 304 | $stream = stream_socket_client('ssl://' . $domain . ':443', $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context); |
| 286 | - if($stream){ | 305 | + if ($stream) { |
| 287 | $remote_cert = stream_context_get_params($stream)['options']['ssl']['peer_certificate']; | 306 | $remote_cert = stream_context_get_params($stream)['options']['ssl']['peer_certificate']; |
| 288 | - if($remote_cert){ | 307 | + if ($remote_cert) { |
| 289 | $valid_from = date('Y-m-d H:i:s', openssl_x509_parse($remote_cert)['validFrom_time_t']); | 308 | $valid_from = date('Y-m-d H:i:s', openssl_x509_parse($remote_cert)['validFrom_time_t']); |
| 290 | $valid_to = date('Y-m-d H:i:s', openssl_x509_parse($remote_cert)['validTo_time_t']); | 309 | $valid_to = date('Y-m-d H:i:s', openssl_x509_parse($remote_cert)['validTo_time_t']); |
| 291 | } | 310 | } |
| @@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
| 2 | 2 | ||
| 3 | namespace App\Console\Commands\Domain; | 3 | namespace App\Console\Commands\Domain; |
| 4 | 4 | ||
| 5 | +use App\Models\Project\DeployOptimize; | ||
| 5 | use App\Models\Project\OnlineCheck; | 6 | use App\Models\Project\OnlineCheck; |
| 6 | use App\Models\Project\Project; | 7 | use App\Models\Project\Project; |
| 7 | use Illuminate\Console\Command; | 8 | use Illuminate\Console\Command; |
| @@ -22,6 +23,9 @@ class RemainDay extends Command | @@ -22,6 +23,9 @@ class RemainDay extends Command | ||
| 22 | */ | 23 | */ |
| 23 | protected $signature = 'remain_day'; | 24 | protected $signature = 'remain_day'; |
| 24 | 25 | ||
| 26 | + protected $projectId = [ | ||
| 27 | + 1434 | ||
| 28 | + ];//需要单独处理的项目 | ||
| 25 | /** | 29 | /** |
| 26 | * The console command description. | 30 | * The console command description. |
| 27 | * | 31 | * |
| @@ -44,22 +48,29 @@ class RemainDay extends Command | @@ -44,22 +48,29 @@ class RemainDay extends Command | ||
| 44 | */ | 48 | */ |
| 45 | public function handle() | 49 | public function handle() |
| 46 | { | 50 | { |
| 47 | - $list = Project::whereIn('type', [2,3,4])->get(); | 51 | + $list = Project::whereIn('type', [Project::TYPE_TWO,Project::TYPE_THREE,Project::TYPE_FOUR])->get(); |
| 48 | foreach ($list as $item){ | 52 | foreach ($list as $item){ |
| 49 | - if($item['type'] == Project::TYPE_TWO){ | ||
| 50 | - //排名达标天数 | ||
| 51 | -// $compliance_day = GoogleRankModel::where(['project_id' => $item['id'], 'lang' => ''])->value('compliance_day') ?: 0; | ||
| 52 | - //获取当前项目的达标天数 | ||
| 53 | - $compliance_day = Project::where(['id' => $item['id']])->value('finish_remain_day') ?: 0; | ||
| 54 | - $remain_day = $item['deploy_build']['service_duration'] - $compliance_day; | 53 | + if(in_array($item->id,$this->projectId)){//已开始优化的时间结算 |
| 54 | + $optimizeModel = new DeployOptimize(); | ||
| 55 | + $opInfo = $optimizeModel->read(['project_id'=>$item->id],['start_date']); | ||
| 56 | + if($opInfo === false){ | ||
| 57 | + continue; | ||
| 58 | + } | ||
| 59 | + $diff = time() - strtotime($opInfo['start_date'] ?? $item->uptime); | ||
| 60 | + $remain_day = $item['deploy_build']['service_duration'] - floor($diff / (60 * 60 * 24)); | ||
| 55 | }else{ | 61 | }else{ |
| 56 | - //审核上线后开始 | ||
| 57 | - $check_time = OnlineCheck::where('project_id', $item['id'])->where('status', 1)->value('created_at') ?: ''; | ||
| 58 | - if(!$check_time){ | ||
| 59 | - $remain_day = $item['deploy_build']['service_duration']; | 62 | + if($item['type'] == Project::TYPE_TWO){ |
| 63 | + //获取当前项目的达标天数 | ||
| 64 | + $compliance_day = $item->finish_remain_day ?? 0; | ||
| 65 | + $remain_day = $item['deploy_build']['service_duration'] - $compliance_day; | ||
| 60 | }else{ | 66 | }else{ |
| 61 | - $diff = time() - strtotime($check_time); | ||
| 62 | - $remain_day = floor($diff / (60 * 60 * 24)); | 67 | + if($item->uptime){ |
| 68 | + $diff = time() - strtotime($item->uptime); | ||
| 69 | + $item->finish_remain_day = floor($diff / (60 * 60 * 24)); | ||
| 70 | + $remain_day = $item['deploy_build']['service_duration'] - floor($diff / (60 * 60 * 24)); | ||
| 71 | + }else{ | ||
| 72 | + $remain_day = $item['deploy_build']['service_duration']; | ||
| 73 | + } | ||
| 63 | } | 74 | } |
| 64 | } | 75 | } |
| 65 | $item->remain_day = $remain_day > 0 ? $remain_day : 0; | 76 | $item->remain_day = $remain_day > 0 ? $remain_day : 0; |
| @@ -42,16 +42,16 @@ class ImportChannel extends Command | @@ -42,16 +42,16 @@ class ImportChannel extends Command | ||
| 42 | 'channel'=>['like','%"user_id": "0"%'], | 42 | 'channel'=>['like','%"user_id": "0"%'], |
| 43 | ]; | 43 | ]; |
| 44 | $lists = $projectModel->list($map); | 44 | $lists = $projectModel->list($map); |
| 45 | -// var_dump($lists); | ||
| 46 | -// die(); | ||
| 47 | - foreach ($lists as $k => $v){ | ||
| 48 | - $order_id = $v['notice_order_id']; | ||
| 49 | - $api = new OaGlobalsoApi(); | ||
| 50 | - $data = $api->order_info($order_id); | ||
| 51 | - $data = $data['data']; | ||
| 52 | - $channel = Channel::getProjectChannel($data['company_id'], $data['username_sales']); | ||
| 53 | - $projectModel->edit(['channel'=>$channel],['id'=>$v['id']]); | 45 | + if(!empty($lists)){ |
| 46 | + foreach ($lists as $k => $v){ | ||
| 47 | + $order_id = $v['notice_order_id']; | ||
| 48 | + $api = new OaGlobalsoApi(); | ||
| 49 | + $data = $api->order_info($order_id); | ||
| 50 | + $data = $data['data']; | ||
| 51 | + $channel = Channel::getProjectChannel($data['company_id'], $data['username_sales']); | ||
| 52 | + $projectModel->edit(['channel'=>$channel],['id'=>$v['id']]); | ||
| 53 | + } | ||
| 54 | } | 54 | } |
| 55 | - return 1; | 55 | + return true; |
| 56 | } | 56 | } |
| 57 | } | 57 | } |
| @@ -30,7 +30,7 @@ class ImportManager extends Command | @@ -30,7 +30,7 @@ class ImportManager extends Command | ||
| 30 | * | 30 | * |
| 31 | * @var string | 31 | * @var string |
| 32 | */ | 32 | */ |
| 33 | - protected $description = '导入数据'; | 33 | + protected $description = '导入数据(同步5.0人事信息)'; |
| 34 | /** | 34 | /** |
| 35 | * @remark :导入5.0管理员数据 | 35 | * @remark :导入5.0管理员数据 |
| 36 | * @name :handle | 36 | * @name :handle |
| @@ -57,13 +57,10 @@ class LastInquiry extends Command | @@ -57,13 +57,10 @@ class LastInquiry extends Command | ||
| 57 | //其他询盘的最新时间 | 57 | //其他询盘的最新时间 |
| 58 | ProjectServer::useProject($item['id']); | 58 | ProjectServer::useProject($item['id']); |
| 59 | $other_last_time = InquiryFormData::orderBy('id', 'desc')->value('submit_at'); | 59 | $other_last_time = InquiryFormData::orderBy('id', 'desc')->value('submit_at'); |
| 60 | - | ||
| 61 | $last_inquiry_time = $last_time > $other_last_time ? $last_time : $other_last_time; | 60 | $last_inquiry_time = $last_time > $other_last_time ? $last_time : $other_last_time; |
| 62 | - | ||
| 63 | if(!$last_inquiry_time){ | 61 | if(!$last_inquiry_time){ |
| 64 | continue; | 62 | continue; |
| 65 | } | 63 | } |
| 66 | - | ||
| 67 | $item->last_inquiry_time = $last_inquiry_time; | 64 | $item->last_inquiry_time = $last_inquiry_time; |
| 68 | $item->save(); | 65 | $item->save(); |
| 69 | } | 66 | } |
| @@ -16,8 +16,12 @@ use App\Models\Product\Keyword; | @@ -16,8 +16,12 @@ use App\Models\Product\Keyword; | ||
| 16 | use App\Models\Product\Product; | 16 | use App\Models\Product\Product; |
| 17 | use App\Services\ProjectServer; | 17 | use App\Services\ProjectServer; |
| 18 | use Illuminate\Console\Command; | 18 | use Illuminate\Console\Command; |
| 19 | +use Illuminate\Support\Carbon; | ||
| 20 | +use Illuminate\Support\Facades\Cache; | ||
| 21 | +use Illuminate\Support\Facades\DB; | ||
| 19 | use Illuminate\Support\Facades\Http; | 22 | use Illuminate\Support\Facades\Http; |
| 20 | use Illuminate\Support\Facades\Log; | 23 | use Illuminate\Support\Facades\Log; |
| 24 | +use Illuminate\Support\Facades\Redis; | ||
| 21 | 25 | ||
| 22 | class VideoTask extends Command | 26 | class VideoTask extends Command |
| 23 | { | 27 | { |
| @@ -49,15 +53,19 @@ class VideoTask extends Command | @@ -49,15 +53,19 @@ class VideoTask extends Command | ||
| 49 | * @var int 最大子任务 | 53 | * @var int 最大子任务 |
| 50 | */ | 54 | */ |
| 51 | public $max_sub_task = 200; | 55 | public $max_sub_task = 200; |
| 52 | - | 56 | + public $max_num = 49000; |
| 53 | /** | 57 | /** |
| 54 | * @return bool | 58 | * @return bool |
| 55 | */ | 59 | */ |
| 56 | public function handle() | 60 | public function handle() |
| 57 | { | 61 | { |
| 58 | - echo '开始:'.PHP_EOL; | ||
| 59 | Log::info('开始视频推广任务'); | 62 | Log::info('开始视频推广任务'); |
| 60 | - $this->createSubTask(); | 63 | + $number = KeywordVideoTaskLog::getMonthVideoNum(); |
| 64 | + if($number >= $this->max_num){ | ||
| 65 | + Log::info('当月以达到最大视频生成数,任务执行数:' . $number); | ||
| 66 | + return true; | ||
| 67 | + } | ||
| 68 | + $this->createSubTask($number); | ||
| 61 | $this->sendSubTask(); | 69 | $this->sendSubTask(); |
| 62 | Log::info('结束视频推广任务'); | 70 | Log::info('结束视频推广任务'); |
| 63 | return true; | 71 | return true; |
| @@ -68,17 +76,21 @@ class VideoTask extends Command | @@ -68,17 +76,21 @@ class VideoTask extends Command | ||
| 68 | * TODO 获取需要生成子任务的项目,获取项目中未生成视频的关键词,通过关键词生成初始化子任务 | 76 | * TODO 获取需要生成子任务的项目,获取项目中未生成视频的关键词,通过关键词生成初始化子任务 |
| 69 | * @return bool | 77 | * @return bool |
| 70 | */ | 78 | */ |
| 71 | - public function createSubTask() | 79 | + public function createSubTask($number) |
| 72 | { | 80 | { |
| 73 | $sub_task_num = $this->max_sub_task; | 81 | $sub_task_num = $this->max_sub_task; |
| 74 | while (true) { | 82 | while (true) { |
| 75 | if ($sub_task_num <= 0){ | 83 | if ($sub_task_num <= 0){ |
| 76 | break; | 84 | break; |
| 77 | } | 85 | } |
| 86 | + if($number >= $this->max_num){ | ||
| 87 | + break; | ||
| 88 | + } | ||
| 78 | $task_project = KeywordVideoTask::where(['status' => KeywordVideoTask::STATUS_OPEN])->orderBy('sort', 'desc')->orderBy('id', 'desc')->first(); | 89 | $task_project = KeywordVideoTask::where(['status' => KeywordVideoTask::STATUS_OPEN])->orderBy('sort', 'desc')->orderBy('id', 'desc')->first(); |
| 79 | if (empty($task_project)){ | 90 | if (empty($task_project)){ |
| 80 | break; | 91 | break; |
| 81 | } | 92 | } |
| 93 | + echo '开始,项目id:'.$task_project->project_id.PHP_EOL; | ||
| 82 | $domainModel = new DomainInfo(); | 94 | $domainModel = new DomainInfo(); |
| 83 | $domainInfo = $domainModel->read(['project_id'=>$task_project->project_id]); | 95 | $domainInfo = $domainModel->read(['project_id'=>$task_project->project_id]); |
| 84 | if($domainInfo === false){ | 96 | if($domainInfo === false){ |
| @@ -87,7 +99,10 @@ class VideoTask extends Command | @@ -87,7 +99,10 @@ class VideoTask extends Command | ||
| 87 | continue; | 99 | continue; |
| 88 | } | 100 | } |
| 89 | ProjectServer::useProject($task_project->project_id); | 101 | ProjectServer::useProject($task_project->project_id); |
| 90 | - $keyword = $this->getProjectKeyword($task_project->number); | 102 | + if(!empty($task_project->keywords)){ |
| 103 | + $keywords = explode(',',trim(',',$task_project->keywords)); | ||
| 104 | + } | ||
| 105 | + $keyword = $this->getProjectKeyword($task_project->number,$keywords ?? []); | ||
| 91 | // 已经没有需要生成视频的关键词 | 106 | // 已经没有需要生成视频的关键词 |
| 92 | if (!$keyword) { | 107 | if (!$keyword) { |
| 93 | $task_project->status = KeywordVideoTask::STATUS_CLOSE; | 108 | $task_project->status = KeywordVideoTask::STATUS_CLOSE; |
| @@ -96,7 +111,7 @@ class VideoTask extends Command | @@ -96,7 +111,7 @@ class VideoTask extends Command | ||
| 96 | } | 111 | } |
| 97 | $logo_bg = $this->getImage($domainInfo); | 112 | $logo_bg = $this->getImage($domainInfo); |
| 98 | foreach ($keyword as $val) { | 113 | foreach ($keyword as $val) { |
| 99 | - $log = KeywordVideoTaskLog::where(['project_id' => $task_project->project_id, 'keyword_id' => $val->id])->first(); | 114 | + $log = KeywordVideoTaskLog::where(['project_id' => $task_project->project_id, 'keyword_id' => $val->id , 'result_status'=>'200'])->first(); |
| 100 | if ($log){ | 115 | if ($log){ |
| 101 | continue; | 116 | continue; |
| 102 | } | 117 | } |
| @@ -113,10 +128,13 @@ class VideoTask extends Command | @@ -113,10 +128,13 @@ class VideoTask extends Command | ||
| 113 | 'updated_at' => date('Y-m-d H:i:s'), | 128 | 'updated_at' => date('Y-m-d H:i:s'), |
| 114 | 'created_at' => date('Y-m-d H:i:s'), | 129 | 'created_at' => date('Y-m-d H:i:s'), |
| 115 | ]; | 130 | ]; |
| 116 | - KeywordVideoTaskLog::insert($array); | ||
| 117 | - $sub_task_num--; | 131 | + $rs = KeywordVideoTaskLog::insert($array); |
| 132 | + if($rs && ($sub_task_num > 0)){ | ||
| 133 | + $sub_task_num--; | ||
| 134 | + } | ||
| 118 | } | 135 | } |
| 119 | } | 136 | } |
| 137 | + Cache::put('video_keyword_number_month',$number + count($keyword),3600); | ||
| 120 | $task_project->status = KeywordVideoTask::STATUS_CLOSE; | 138 | $task_project->status = KeywordVideoTask::STATUS_CLOSE; |
| 121 | $task_project->save(); | 139 | $task_project->save(); |
| 122 | } | 140 | } |
| @@ -168,11 +186,18 @@ class VideoTask extends Command | @@ -168,11 +186,18 @@ class VideoTask extends Command | ||
| 168 | * @param $number | 186 | * @param $number |
| 169 | * @return mixed | 187 | * @return mixed |
| 170 | */ | 188 | */ |
| 171 | - public function getProjectKeyword($number) | 189 | + public function getProjectKeyword($number,$keywords = []) |
| 172 | { | 190 | { |
| 173 | - $keyword_arr_id = Keyword::where('video', null)->where('route', 'not like', '%-tag')->whereNotNull('keyword_content')->pluck('id')->toArray(); | ||
| 174 | - $keyword_id = array_rand($keyword_arr_id, $number); | ||
| 175 | - $keyword = Keyword::whereIn("id", $keyword_id)->get(); | 191 | + |
| 192 | + $keyword_id = Keyword::where('video', null)->whereIn("title", $keywords) | ||
| 193 | + ->where('route', 'not like', '%-tag')->whereNotNull('keyword_content')->limit($number)->pluck('id')->toArray(); | ||
| 194 | + $need = $number - count($keyword_id); | ||
| 195 | + if ($need > 0) { | ||
| 196 | + $keyword_arr_id = Keyword::where('video', null)->where('route', 'not like', '%-tag') | ||
| 197 | + ->whereNotNull('keyword_content')->whereNotIn('id', $keyword_id)->orderBy('id','asc')->limit($need)->pluck('id')->toArray(); | ||
| 198 | + } | ||
| 199 | + $keyword_arr_id = array_merge($keyword_id, $keyword_arr_id); | ||
| 200 | + $keyword = Keyword::whereIn("id", $keyword_arr_id)->get(); | ||
| 176 | return $keyword; | 201 | return $keyword; |
| 177 | } | 202 | } |
| 178 | 203 | ||
| @@ -213,7 +238,7 @@ class VideoTask extends Command | @@ -213,7 +238,7 @@ class VideoTask extends Command | ||
| 213 | } | 238 | } |
| 214 | } | 239 | } |
| 215 | //TODO::所有产品 | 240 | //TODO::所有产品 |
| 216 | - $thumb = $this->getRecommendAndHotProducts($keywordInfo['route'],$project_id); | 241 | + $thumb = $this->getRecommendAndHotProducts($keyword_id); |
| 217 | $keyword_arr = Keyword::where("project_id",$project_id)->where("status",1)->inRandomOrder()->take(10)->pluck('title')->toArray(); | 242 | $keyword_arr = Keyword::where("project_id",$project_id)->where("status",1)->inRandomOrder()->take(10)->pluck('title')->toArray(); |
| 218 | $data = [ | 243 | $data = [ |
| 219 | 'url'=> 'https://' . $domain.'/'.$keywordInfo['route'], | 244 | 'url'=> 'https://' . $domain.'/'.$keywordInfo['route'], |
| @@ -229,38 +254,24 @@ class VideoTask extends Command | @@ -229,38 +254,24 @@ class VideoTask extends Command | ||
| 229 | /** | 254 | /** |
| 230 | * 关键词聚合页-推荐&热门产品 | 255 | * 关键词聚合页-推荐&热门产品 |
| 231 | */ | 256 | */ |
| 232 | - public function getRecommendAndHotProducts($route,$project_id): ?array | 257 | + public function getRecommendAndHotProducts($keyword_id): ?array |
| 233 | { | 258 | { |
| 234 | $productIds = []; | 259 | $productIds = []; |
| 235 | - $productKeyword = Keyword::where("project_id",$project_id)->where("route",$route)->first(); | ||
| 236 | - if (!empty($productKeyword)){ | ||
| 237 | - $productsQuery = Product::where("project_id", $project_id)->where("status",1)->where("keyword_id","like","%,".$productKeyword->id.",%")->limit(7)->get(); | ||
| 238 | - if (!empty($productsQuery)){ | ||
| 239 | - foreach ($productsQuery as $item){ | ||
| 240 | - $productIds[] = $item->id; | ||
| 241 | - } | ||
| 242 | - if (count($productIds)<7){ | ||
| 243 | - $product_all_id = Product::where("project_id", $project_id)->where('thumb','!=',null)->whereNotIn('id', $productIds)->where("status",Product::STATUS_ON)->pluck('id')->toArray(); | ||
| 244 | - $number = 40; | ||
| 245 | - $array_count = count($product_all_id); | ||
| 246 | - if ($array_count > 0) { | ||
| 247 | - $product_id = array_rand($product_all_id, min($array_count, $number - count($productIds))); | ||
| 248 | - $randomData = Product::where("project_id", $project_id)->whereIn("id", $product_id)->get(); | ||
| 249 | - $products = $productsQuery->merge($randomData); | ||
| 250 | - } | ||
| 251 | - }else{ | ||
| 252 | - $products = $productsQuery; | ||
| 253 | - } | 260 | + $productsQuery = Product::where("status",1)->where("keyword_id","like","%,".$keyword_id.",%")->limit(13)->get(); |
| 261 | + if (count($productsQuery) > 0){ | ||
| 262 | + foreach ($productsQuery as $item){ | ||
| 263 | + $productIds[] = $item->id; | ||
| 264 | + } | ||
| 265 | + if (count($productIds) < 13){ | ||
| 266 | + $product_all_id = Product::where('thumb','!=',null)->whereNotIn('id', $productIds)->where("status",Product::STATUS_ON)->inRandomOrder()->take(20 - count($productIds))->pluck('id')->toArray(); | ||
| 267 | + $randomData = Product::whereIn("id", $product_all_id)->orderByRaw(DB::raw("FIELD(id, " . implode(',', $product_all_id) . ")"))->get(); | ||
| 268 | + $products = $productsQuery->merge($randomData); | ||
| 254 | }else{ | 269 | }else{ |
| 255 | - $product_all_id = Product::where("project_id", $project_id)->where('thumb','!=',null)->where("status",Product::STATUS_ON)->pluck('id')->toArray(); | ||
| 256 | - $number = 40; | ||
| 257 | - $array_count = count($product_all_id); | ||
| 258 | - if ($array_count > 0) | ||
| 259 | - { | ||
| 260 | - $product_id = array_rand($product_all_id, min($array_count, $number-count($productIds))); | ||
| 261 | - $products = Product::where("project_id", $project_id)->whereIn("id", $product_id)->get(); | ||
| 262 | - } | 270 | + $products = $productsQuery; |
| 263 | } | 271 | } |
| 272 | + }else{ | ||
| 273 | + $product_all_id = Product::where('thumb','!=',null)->where("status",Product::STATUS_ON)->inRandomOrder()->take(20)->pluck('id')->toArray(); | ||
| 274 | + $products = Product::whereIn("id", $product_all_id)->orderByRaw(DB::raw("FIELD(id, " . implode(',', $product_all_id) . ")"))->get(); | ||
| 264 | } | 275 | } |
| 265 | $data = []; | 276 | $data = []; |
| 266 | if (!empty($products)){ | 277 | if (!empty($products)){ |
| @@ -271,12 +282,13 @@ class VideoTask extends Command | @@ -271,12 +282,13 @@ class VideoTask extends Command | ||
| 271 | if(count($data) > 13){ | 282 | if(count($data) > 13){ |
| 272 | break; | 283 | break; |
| 273 | } | 284 | } |
| 274 | - $keyword_id = implode(',',$item->keyword_id); | ||
| 275 | - if (strpos(','.$keyword_id.',', ','.$productKeyword->id.',') === false) { | 285 | + $keyword_ids = implode(',',$item->keyword_id); |
| 286 | + if (strpos(','.$keyword_ids.',', ','.$keyword_id.',') === false) { | ||
| 276 | //不包含 | 287 | //不包含 |
| 277 | $productModel = new Product(); | 288 | $productModel = new Product(); |
| 278 | - $keyword_id = ','.$keyword_id.',' . $productKeyword->id.','; | ||
| 279 | - $productModel->edit(['keyword_id'=>$keyword_id],['id'=>$item->id]); | 289 | + $keyword_ids = !empty($keyword_ids) ? ','.$keyword_ids.',' : ',' ; |
| 290 | + $keyword_id_str = $keyword_ids . $keyword_id.','; | ||
| 291 | + $productModel->edit(['keyword_id'=>$keyword_id_str],['id'=>$item->id]); | ||
| 280 | } | 292 | } |
| 281 | $data[] = ['url'=>getImageUrl($item->thumb['url']),'title'=>$item->title]; | 293 | $data[] = ['url'=>getImageUrl($item->thumb['url']),'title'=>$item->title]; |
| 282 | } | 294 | } |
| 1 | -<?php | ||
| 2 | - | ||
| 3 | -namespace App\Console\Commands\MonthlyCount; | ||
| 4 | - | ||
| 5 | -use App\Helper\FormGlobalsoApi; | ||
| 6 | -use App\Models\Domain\DomainInfo; | ||
| 7 | -use App\Models\Inquiry\InquiryFormData; | ||
| 8 | -use App\Models\Project\Project; | ||
| 9 | -use App\Services\ProjectServer; | ||
| 10 | -use Carbon\Carbon; | ||
| 11 | -use Illuminate\Console\Command; | ||
| 12 | -use Illuminate\Support\Facades\DB; | ||
| 13 | - | ||
| 14 | -class InquiryMonthlyCount extends Command | ||
| 15 | -{ | ||
| 16 | - const STATUS_ERROR = 400; | ||
| 17 | - public $error = 0; | ||
| 18 | - /** | ||
| 19 | - * The name and signature of the console command. | ||
| 20 | - * | ||
| 21 | - * @var string | ||
| 22 | - */ | ||
| 23 | - protected $signature = 'month_count'; | ||
| 24 | - | ||
| 25 | - /** | ||
| 26 | - * The console command description. | ||
| 27 | - * | ||
| 28 | - * @var string | ||
| 29 | - */ | ||
| 30 | - protected $description = '询盘月报告统计'; | ||
| 31 | - | ||
| 32 | - /** | ||
| 33 | - * @remark :询盘月报告 | ||
| 34 | - * @name :handle | ||
| 35 | - * @author :lyh | ||
| 36 | - * @method :post | ||
| 37 | - * @time :2023/6/30 9:32 | ||
| 38 | - */ | ||
| 39 | - public function handle(){ | ||
| 40 | - $list = DB::table('gl_project')->where('gl_project.extend_type','=',0) | ||
| 41 | - ->where('gl_project.type','!=',0) | ||
| 42 | - ->leftJoin('gl_project_deploy_build', 'gl_project.id', '=', 'gl_project_deploy_build.project_id') | ||
| 43 | - ->leftJoin('gl_project_deploy_optimize', 'gl_project.id', '=', 'gl_project_deploy_optimize.project_id') | ||
| 44 | - ->select($this->selectParam())->get()->toArray(); | ||
| 45 | - // 获取上个月的开始时间 | ||
| 46 | - $startTime = Carbon::now()->subMonth()->startOfMonth()->toDateString(); | ||
| 47 | - // 获取上个月的结束时间 | ||
| 48 | - $endTime = Carbon::now()->subMonth()->endOfMonth()->toDateString(); | ||
| 49 | - $domainInfo = new DomainInfo(); | ||
| 50 | - foreach ($list as $value){ | ||
| 51 | - $value = (array)$value; | ||
| 52 | - if($value['type'] == Project::TYPE_ZERO){ | ||
| 53 | - continue; | ||
| 54 | - } | ||
| 55 | - if(!empty($value['domain'])){ | ||
| 56 | - $info = $domainInfo->read(['id'=>$value['domain']]); | ||
| 57 | - if($info !== false){ | ||
| 58 | - $value['test_domain'] = $info['domain']; | ||
| 59 | - } | ||
| 60 | - } | ||
| 61 | - $arr = []; | ||
| 62 | - //按月统计询盘记录 | ||
| 63 | - $arr = $this->inquiryCount($arr,$startTime,$endTime,$value['test_domain'],$value['project_id']); | ||
| 64 | - $arr = $this->flowCount($arr,$startTime,$endTime,$value['project_id']); | ||
| 65 | - ProjectServer::useProject($value['project_id']); | ||
| 66 | - $arr = $this->sourceCount($arr,$value['test_domain'],$startTime,$endTime); | ||
| 67 | - DB::disconnect('custom_mysql'); | ||
| 68 | - $arr['created_at'] = date('Y-m-d H:i:s'); | ||
| 69 | - $arr['updated_at'] = date('Y-m-d H:i:s'); | ||
| 70 | - $arr['project_id'] = $value['project_id']; | ||
| 71 | - // 获取当前日期时间 | ||
| 72 | - $arr['month'] = Carbon::now()->subMonth()->format('Y-m'); | ||
| 73 | - DB::table('gl_month_count')->insert($arr); | ||
| 74 | - } | ||
| 75 | - return true; | ||
| 76 | - } | ||
| 77 | - | ||
| 78 | - /** | ||
| 79 | - * @param $domain | ||
| 80 | - * @param $project_id | ||
| 81 | - * @remark :询盘按月统计 | ||
| 82 | - * @name :inquiryCount | ||
| 83 | - * @author :lyh | ||
| 84 | - * @method :post | ||
| 85 | - * @time :2023/6/30 14:29 | ||
| 86 | - */ | ||
| 87 | - public function inquiryCount(&$arr,&$startTime,&$endTime,$domain,$project_id){ | ||
| 88 | - $inquiry_list = (new FormGlobalsoApi())->getInquiryList($domain,'',1,100000000); | ||
| 89 | - //总数 | ||
| 90 | - $arr['total'] = $inquiry_list['data']['total'] ?? 0; | ||
| 91 | - //数据详情 | ||
| 92 | - $data = $inquiry_list['data']['data'] ?? 0; | ||
| 93 | - $arr['month_total'] = 0; | ||
| 94 | - $countryArr = []; | ||
| 95 | - $arr['country'] = ""; | ||
| 96 | - if(!empty($data)){ | ||
| 97 | - foreach ($data as $v){ | ||
| 98 | - if(($startTime.' 00:00:00' <= $v['submit_time']) && $v['submit_time'] <= $endTime.' 23:59:59'){ | ||
| 99 | - $arr['month_total']++; | ||
| 100 | - if(isset($countryArr[$v['country']])){ | ||
| 101 | - $countryArr[$v['country']]++; | ||
| 102 | - }else{ | ||
| 103 | - $countryArr[$v['country']] = 1; | ||
| 104 | - } | ||
| 105 | - } | ||
| 106 | - } | ||
| 107 | - } | ||
| 108 | - //加上其他询盘 | ||
| 109 | - ProjectServer::useProject($project_id); | ||
| 110 | - $arr['total'] += InquiryFormData::count(); | ||
| 111 | - $arr['month_total'] += InquiryFormData::getCount([$startTime, $endTime]); | ||
| 112 | - $countryData = InquiryFormData::getCountryCount([$startTime, $endTime]); | ||
| 113 | - foreach ($countryData as $v1){ | ||
| 114 | - if(isset($countryArr[$v1['country']])){ | ||
| 115 | - $countryArr[$v1['country']] += $v1['count']; | ||
| 116 | - }else{ | ||
| 117 | - $countryArr[$v1['country']] = $v1['count']; | ||
| 118 | - } | ||
| 119 | - } | ||
| 120 | - | ||
| 121 | - arsort($countryArr); | ||
| 122 | - $top20 = array_slice($countryArr, 0, 15, true); | ||
| 123 | - $arr['country'] = json_encode($top20); | ||
| 124 | - return $arr; | ||
| 125 | - } | ||
| 126 | - | ||
| 127 | - /** | ||
| 128 | - * @remark :流量统计 | ||
| 129 | - * @name :flowCount | ||
| 130 | - * @author :lyh | ||
| 131 | - * @method :post | ||
| 132 | - * @time :2023/6/30 14:31 | ||
| 133 | - */ | ||
| 134 | - public function flowCount(&$arr,&$startTime,&$endTime,$project_id){ | ||
| 135 | - $pv_ip = DB::table('gl_count') | ||
| 136 | - ->where(['project_id'=>$project_id]) | ||
| 137 | - ->where('date','>=',$startTime.' 00:00:00') | ||
| 138 | - ->where('date','<=',$endTime.' 23:59:59') | ||
| 139 | - ->select(DB::raw('SUM(pv_num) as pv_num'), DB::raw('SUM(ip_num) as ip_num')) | ||
| 140 | - ->first(); | ||
| 141 | - $arr['pv'] = $pv_ip->pv_num; | ||
| 142 | - $arr['ip'] = $pv_ip->ip_num; | ||
| 143 | - if($arr['ip'] != 0){ | ||
| 144 | - $arr['rate'] = round(($arr['month_total'] / $arr['ip']) * 10,2); | ||
| 145 | - } | ||
| 146 | - return $arr; | ||
| 147 | - } | ||
| 148 | - | ||
| 149 | - /** | ||
| 150 | - * @remark :来源访问前8 | ||
| 151 | - * @name :sourceCount | ||
| 152 | - * @author :lyh | ||
| 153 | - * @method :post | ||
| 154 | - * @time :2023/6/30 16:14 | ||
| 155 | - */ | ||
| 156 | - public function sourceCount(&$arr,$domain,$startTime,$endTime){ | ||
| 157 | - //访问来源前10 | ||
| 158 | - $source = DB::connection('custom_mysql')->table('gl_customer_visit') | ||
| 159 | - ->select('referrer_url', DB::raw('COUNT(*) as count')) | ||
| 160 | - ->groupBy('referrer_url') | ||
| 161 | - ->whereBetween('updated_date', [$startTime,$endTime]) | ||
| 162 | - ->orderByDesc('count')->limit(10)->get()->toArray(); | ||
| 163 | - $arr['source'] = json_encode($source); | ||
| 164 | - //访问国家前15 | ||
| 165 | - $source_country = DB::connection('custom_mysql')->table('gl_customer_visit') | ||
| 166 | - ->select('country',DB::raw('COUNT(*) as ip'),DB::raw('SUM(depth) as pv')) | ||
| 167 | - ->groupBy('country') | ||
| 168 | - ->whereBetween('updated_date', [$startTime,$endTime]) | ||
| 169 | - ->orderBy('ip','desc')->limit(15)->get()->toArray(); | ||
| 170 | - $arr['source_country'] = json_encode($source_country); | ||
| 171 | - //受访界面前15 | ||
| 172 | - $referrer_url = DB::connection('custom_mysql')->table('gl_customer_visit') | ||
| 173 | - ->select('url',DB::raw('COUNT(*) as num')) | ||
| 174 | - ->orderBy('num','desc') | ||
| 175 | - ->whereBetween('updated_date', [$startTime,$endTime]) | ||
| 176 | - ->groupBy('url') | ||
| 177 | - ->limit(15)->get()->toArray(); | ||
| 178 | - $arr['referrer_url'] = json_encode($referrer_url); | ||
| 179 | - //访问端口 | ||
| 180 | - $referrer_port = DB::connection('custom_mysql')->table('gl_customer_visit') | ||
| 181 | - ->select('device_port',DB::raw('COUNT(*) as num')) | ||
| 182 | - ->orderBy('num','desc') | ||
| 183 | - ->whereBetween('updated_date', [$startTime,$endTime]) | ||
| 184 | - ->groupBy('device_port') | ||
| 185 | - ->limit(15)->get()->toArray(); | ||
| 186 | - $arr['referrer_port'] = json_encode($referrer_port); | ||
| 187 | - return $arr; | ||
| 188 | - } | ||
| 189 | - | ||
| 190 | - /** | ||
| 191 | - * @name :(查询参数设置)selectParam | ||
| 192 | - * @author :lyh | ||
| 193 | - * @method :post | ||
| 194 | - * @time :2023/6/14 15:00 | ||
| 195 | - */ | ||
| 196 | - public function selectParam(){ | ||
| 197 | - $select = [ | ||
| 198 | - 'gl_project.id AS id', | ||
| 199 | - 'gl_project.type AS type', | ||
| 200 | - 'gl_project.extend_type AS extend_type', | ||
| 201 | - 'gl_project_deploy_build.test_domain AS test_domain', | ||
| 202 | - 'gl_project_deploy_optimize.domain AS domain', | ||
| 203 | - 'gl_project_deploy_build.project_id AS project_id', | ||
| 204 | - 'gl_project.cooperate_date AS cooperate_date', | ||
| 205 | - 'gl_project_deploy_build.service_duration AS service_duration', | ||
| 206 | - ]; | ||
| 207 | - return $select; | ||
| 208 | - } | ||
| 209 | -} |
| 1 | <?php | 1 | <?php |
| 2 | /** | 2 | /** |
| 3 | * @remark : | 3 | * @remark : |
| 4 | - * @name :UpgradeProjectCount.php | 4 | + * @name :CountProject.php |
| 5 | * @author :lyh | 5 | * @author :lyh |
| 6 | * @method :post | 6 | * @method :post |
| 7 | * @time :2024/1/8 9:03 | 7 | * @time :2024/1/8 9:03 |
| @@ -13,6 +13,7 @@ use App\Helper\FormGlobalsoApi; | @@ -13,6 +13,7 @@ use App\Helper\FormGlobalsoApi; | ||
| 13 | use App\Models\Com\UpdateOldInfo; | 13 | use App\Models\Com\UpdateOldInfo; |
| 14 | use App\Models\Domain\DomainInfo; | 14 | use App\Models\Domain\DomainInfo; |
| 15 | use App\Models\HomeCount\MonthCount; | 15 | use App\Models\HomeCount\MonthCount; |
| 16 | +use App\Models\Inquiry\InquiryFormData; | ||
| 16 | use App\Models\Project\Project; | 17 | use App\Models\Project\Project; |
| 17 | use App\Models\Visit\Visit; | 18 | use App\Models\Visit\Visit; |
| 18 | use App\Services\ProjectServer; | 19 | use App\Services\ProjectServer; |
| @@ -20,14 +21,14 @@ use Illuminate\Console\Command; | @@ -20,14 +21,14 @@ use Illuminate\Console\Command; | ||
| 20 | use Illuminate\Support\Facades\DB; | 21 | use Illuminate\Support\Facades\DB; |
| 21 | use App\Models\HomeCount\Count; | 22 | use App\Models\HomeCount\Count; |
| 22 | 23 | ||
| 23 | -class UpgradeCount extends Command | 24 | +class MonthAllCount extends Command |
| 24 | { | 25 | { |
| 25 | /** | 26 | /** |
| 26 | * The name and signature of the console command. | 27 | * The name and signature of the console command. |
| 27 | * | 28 | * |
| 28 | * @var string | 29 | * @var string |
| 29 | */ | 30 | */ |
| 30 | - protected $signature = 'upgrade_month_counts'; | 31 | + protected $signature = 'month_all'; |
| 31 | 32 | ||
| 32 | /** | 33 | /** |
| 33 | * The console command description. | 34 | * The console command description. |
| @@ -38,14 +39,23 @@ class UpgradeCount extends Command | @@ -38,14 +39,23 @@ class UpgradeCount extends Command | ||
| 38 | 39 | ||
| 39 | public function handle(){ | 40 | public function handle(){ |
| 40 | $projectModel = new Project(); | 41 | $projectModel = new Project(); |
| 41 | - $list = $projectModel->list(['is_upgrade'=>1,'delete_status'=>0]); | 42 | + $list = $projectModel->list(['delete_status'=>0,'type'=>['in',[1,2,3,4,6]]]); |
| 42 | foreach ($list as $v) { | 43 | foreach ($list as $v) { |
| 43 | - $oldModel = new UpdateOldInfo(); | ||
| 44 | - $info = $oldModel->read(['project_id' => $v['id']]); | ||
| 45 | - if ($info !== false) { | ||
| 46 | - $url = $info['old_domain_online']; | 44 | + if($v['is_upgrade'] == 1){ |
| 45 | + $oldModel = new UpdateOldInfo(); | ||
| 46 | + $info = $oldModel->read(['project_id' => $v['id']]); | ||
| 47 | + if ($info !== false) { | ||
| 48 | + $url = $info['old_domain_online']; | ||
| 49 | + }else{ | ||
| 50 | + continue; | ||
| 51 | + } | ||
| 47 | }else{ | 52 | }else{ |
| 48 | - continue; | 53 | + $domainModel = new DomainInfo(); |
| 54 | + $info = $domainModel->read(['project_id'=>$v['id']]); | ||
| 55 | + if($info === false){ | ||
| 56 | + continue; | ||
| 57 | + } | ||
| 58 | + $url = $info['domain']; | ||
| 49 | } | 59 | } |
| 50 | ProjectServer::useProject($v['id']); | 60 | ProjectServer::useProject($v['id']); |
| 51 | echo date('Y-m-d H:i:s') . '项目id:'.$v['id'] . PHP_EOL; | 61 | echo date('Y-m-d H:i:s') . '项目id:'.$v['id'] . PHP_EOL; |
| @@ -67,9 +77,7 @@ class UpgradeCount extends Command | @@ -67,9 +77,7 @@ class UpgradeCount extends Command | ||
| 67 | ->groupBy('month')->get()->toArray(); | 77 | ->groupBy('month')->get()->toArray(); |
| 68 | foreach ($list as $k=>$v){ | 78 | foreach ($list as $k=>$v){ |
| 69 | $v = (array)$v; | 79 | $v = (array)$v; |
| 70 | - if($v['month'] == date('Y-m')){ | ||
| 71 | - continue; | ||
| 72 | - } | 80 | + $arr = []; |
| 73 | $monthCountModel = new MonthCount(); | 81 | $monthCountModel = new MonthCount(); |
| 74 | $info = $monthCountModel->read(['month'=>$v['month'],'project_id'=>$project_id]); | 82 | $info = $monthCountModel->read(['month'=>$v['month'],'project_id'=>$project_id]); |
| 75 | // 获取当月开始时间 | 83 | // 获取当月开始时间 |
| @@ -78,7 +86,7 @@ class UpgradeCount extends Command | @@ -78,7 +86,7 @@ class UpgradeCount extends Command | ||
| 78 | $end = date('Y-m-t', strtotime($v['month'])); | 86 | $end = date('Y-m-t', strtotime($v['month'])); |
| 79 | $arr['project_id'] = $project_id; | 87 | $arr['project_id'] = $project_id; |
| 80 | $res = $this->inquiry($url,$v['month']); | 88 | $res = $this->inquiry($url,$v['month']); |
| 81 | -// $arr['month_total'] = 0; | 89 | + $arr['total'] = $arr['month_total'] = 0; |
| 82 | if(isset($res['data']['count'])){ | 90 | if(isset($res['data']['count'])){ |
| 83 | echo date('Y-m-d H:i:s') . '数据:'.$res['data']['count'] . PHP_EOL; | 91 | echo date('Y-m-d H:i:s') . '数据:'.$res['data']['count'] . PHP_EOL; |
| 84 | $arr['month_total'] = $res['data']['count']; | 92 | $arr['month_total'] = $res['data']['count']; |
| @@ -91,9 +99,21 @@ class UpgradeCount extends Command | @@ -91,9 +99,21 @@ class UpgradeCount extends Command | ||
| 91 | $arr['total'] = $res['data']['count'] + ($previousInfo['total'] ?? 0); | 99 | $arr['total'] = $res['data']['count'] + ($previousInfo['total'] ?? 0); |
| 92 | } | 100 | } |
| 93 | } | 101 | } |
| 102 | + //获取当月的其他询盘 | ||
| 103 | + $arr['total'] += InquiryFormData::getCount([$start.' 00:00:00',$end.' 00:00:00']); | ||
| 104 | + $country = []; | ||
| 94 | if(isset($res['data']['data'])){ | 105 | if(isset($res['data']['data'])){ |
| 95 | - $arr['country'] = json_encode($res['data']['data']); | 106 | + $country = $res['data']['data']; |
| 107 | + } | ||
| 108 | + $countryData = InquiryFormData::getCountryCount([$start.' 00:00:00',$end.' 00:00:00']); | ||
| 109 | + foreach ($countryData as $v1){ | ||
| 110 | + if(isset($country[$v1['country']])){ | ||
| 111 | + $country[$v1['country']] += $v1['count']; | ||
| 112 | + }else{ | ||
| 113 | + $country[$v1['country']] = $v1['count']; | ||
| 114 | + } | ||
| 96 | } | 115 | } |
| 116 | + $arr['country'] = json_encode($country); | ||
| 97 | $arr['month'] = $v['month']; | 117 | $arr['month'] = $v['month']; |
| 98 | $arr = $this->pv_ip($arr,$start,$end,$project_id); | 118 | $arr = $this->pv_ip($arr,$start,$end,$project_id); |
| 99 | $arr = $this->sourceCount($arr,$start,$end); | 119 | $arr = $this->sourceCount($arr,$start,$end); |
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * @remark : | ||
| 4 | + * @name :CountProject.php | ||
| 5 | + * @author :lyh | ||
| 6 | + * @method :post | ||
| 7 | + * @time :2024/1/8 9:03 | ||
| 8 | + */ | ||
| 9 | + | ||
| 10 | +namespace App\Console\Commands\MonthlyCount; | ||
| 11 | + | ||
| 12 | +use App\Models\Com\UpdateOldInfo; | ||
| 13 | +use App\Models\Domain\DomainInfo; | ||
| 14 | +use App\Models\Inquiry\InquiryFormData; | ||
| 15 | +use App\Models\Project\Project; | ||
| 16 | +use App\Services\ProjectServer; | ||
| 17 | +use Illuminate\Console\Command; | ||
| 18 | +use Illuminate\Support\Facades\DB; | ||
| 19 | +use App\Models\HomeCount\MonthCount AS MonthCountModel; | ||
| 20 | + | ||
| 21 | +class MonthCount extends Command | ||
| 22 | +{ | ||
| 23 | + /** | ||
| 24 | + * The name and signature of the console command. | ||
| 25 | + * | ||
| 26 | + * @var string | ||
| 27 | + */ | ||
| 28 | + protected $signature = 'month_counts'; | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * The console command description. | ||
| 32 | + * | ||
| 33 | + * @var string | ||
| 34 | + */ | ||
| 35 | + protected $description = '每天生成月统计记录'; | ||
| 36 | + | ||
| 37 | + public function handle(){ | ||
| 38 | + $list = DB::table('gl_project')->where('gl_project.extend_type','=',0) | ||
| 39 | + ->whereIn('gl_project.type',[1,2,3,4,6]) | ||
| 40 | + ->leftJoin('gl_project_deploy_build', 'gl_project.id', '=', 'gl_project_deploy_build.project_id') | ||
| 41 | + ->leftJoin('gl_project_deploy_optimize', 'gl_project.id', '=', 'gl_project_deploy_optimize.project_id') | ||
| 42 | + ->select($this->selectParam())->get()->toArray(); | ||
| 43 | + foreach ($list as $v) { | ||
| 44 | + $v = (array)$v; | ||
| 45 | + if($v['type'] == Project::TYPE_ZERO){ | ||
| 46 | + continue; | ||
| 47 | + } | ||
| 48 | + if($v['is_upgrade'] == 1){ | ||
| 49 | + $oldModel = new UpdateOldInfo(); | ||
| 50 | + $info = $oldModel->read(['project_id' => $v['id']]); | ||
| 51 | + if ($info !== false) { | ||
| 52 | + $url = $info['old_domain_online']; | ||
| 53 | + }else{ | ||
| 54 | + continue; | ||
| 55 | + } | ||
| 56 | + }else{ | ||
| 57 | + $domainInfo = new DomainInfo(); | ||
| 58 | + if(!empty($v['domain'])){ | ||
| 59 | + $info = $domainInfo->read(['id'=>$v['domain']]); | ||
| 60 | + if($info !== false){ | ||
| 61 | + $url = $info['domain']; | ||
| 62 | + } | ||
| 63 | + }else{ | ||
| 64 | + $url = $v['test_domain']; | ||
| 65 | + } | ||
| 66 | + } | ||
| 67 | + ProjectServer::useProject($v['id']); | ||
| 68 | + echo date('Y-m-d H:i:s') . '项目id:'.$v['id'] . PHP_EOL; | ||
| 69 | + $this->count($v['id'], $url); | ||
| 70 | + DB::disconnect('custom_mysql'); | ||
| 71 | + } | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + /** | ||
| 75 | + * @name :(查询参数设置)selectParam | ||
| 76 | + * @author :lyh | ||
| 77 | + * @method :post | ||
| 78 | + * @time :2023/6/14 15:00 | ||
| 79 | + */ | ||
| 80 | + public function selectParam(){ | ||
| 81 | + $select = [ | ||
| 82 | + 'gl_project.id AS id', | ||
| 83 | + 'gl_project.type AS type', | ||
| 84 | + 'gl_project.extend_type AS extend_type', | ||
| 85 | + 'gl_project_deploy_build.test_domain AS test_domain', | ||
| 86 | + 'gl_project.is_upgrade AS is_upgrade', | ||
| 87 | + 'gl_project_deploy_optimize.domain AS domain', | ||
| 88 | + 'gl_project_deploy_build.project_id AS project_id', | ||
| 89 | + 'gl_project.cooperate_date AS cooperate_date', | ||
| 90 | + 'gl_project_deploy_build.service_duration AS service_duration', | ||
| 91 | + ]; | ||
| 92 | + return $select; | ||
| 93 | + } | ||
| 94 | + /** | ||
| 95 | + * @remark :日统计记录 | ||
| 96 | + * @name :count | ||
| 97 | + * @author :lyh | ||
| 98 | + * @method :post | ||
| 99 | + * @time :2024/1/8 9:05 | ||
| 100 | + */ | ||
| 101 | + public function count($project_id,$url){ | ||
| 102 | + $arr = []; | ||
| 103 | + $v = ['month'=>date('Y-m')]; | ||
| 104 | + $monthCountModel = new MonthCountModel(); | ||
| 105 | + $info = $monthCountModel->read(['month'=>$v['month'],'project_id'=>$project_id]); | ||
| 106 | + // 获取当月开始时间 | ||
| 107 | + $start = date('Y-m-01', strtotime($v['month'])); | ||
| 108 | + // 获取当月结束时间 | ||
| 109 | + $end = date('Y-m-t', strtotime($v['month'])); | ||
| 110 | + $arr['project_id'] = $project_id; | ||
| 111 | + $res = $this->inquiry($url,$v['month']); | ||
| 112 | + $arr['total'] = $arr['month_total'] = 0; | ||
| 113 | + if(isset($res['data']['count'])){ | ||
| 114 | + echo date('Y-m-d H:i:s') . '数据:'.$res['data']['count'] . PHP_EOL; | ||
| 115 | + $arr['month_total'] = $res['data']['count']; | ||
| 116 | + //获取上一个的count | ||
| 117 | + $previousMonth = date('Y-m', strtotime($v['month'] . ' -1 month')); | ||
| 118 | + $previousInfo = $monthCountModel->read(['month'=>$previousMonth,'project_id'=>$project_id]); | ||
| 119 | + if($previousInfo === false){ | ||
| 120 | + $arr['total'] = $arr['month_total']; | ||
| 121 | + }else{ | ||
| 122 | + $arr['total'] = $res['data']['count'] + ($previousInfo['total'] ?? 0); | ||
| 123 | + } | ||
| 124 | + } | ||
| 125 | + //获取当月的其他询盘 | ||
| 126 | + $arr['total'] += InquiryFormData::getCount([$start.' 00:00:00',$end.' 00:00:00']); | ||
| 127 | + $country = []; | ||
| 128 | + if(isset($res['data']['data'])){ | ||
| 129 | + $country = $res['data']['data']; | ||
| 130 | + } | ||
| 131 | + $countryData = InquiryFormData::getCountryCount([$start.' 00:00:00',$end.' 00:00:00']); | ||
| 132 | + foreach ($countryData as $v1){ | ||
| 133 | + if(isset($country[$v1['country']])){ | ||
| 134 | + $country[$v1['country']] += $v1['count']; | ||
| 135 | + }else{ | ||
| 136 | + $country[$v1['country']] = $v1['count']; | ||
| 137 | + } | ||
| 138 | + } | ||
| 139 | + $arr['country'] = json_encode($country); | ||
| 140 | + $arr['month'] = $v['month']; | ||
| 141 | + $arr = $this->pv_ip($arr,$start,$end,$project_id); | ||
| 142 | + $arr = $this->sourceCount($arr,$start,$end); | ||
| 143 | + if($info === false){ | ||
| 144 | + $selectedDate = $start; | ||
| 145 | + $firstDayOfNextMonth = date('Y-m-01 01:00:00', strtotime("$selectedDate +1 month")); | ||
| 146 | + $arr['created_at'] = $firstDayOfNextMonth; | ||
| 147 | + $arr['updated_at'] = $firstDayOfNextMonth; | ||
| 148 | +// echo date('Y-m-d H:i:s') . '数据:'.json_encode($arr) . PHP_EOL; | ||
| 149 | + $monthCountModel->insert($arr); | ||
| 150 | + }else{ | ||
| 151 | + $monthCountModel->edit($arr,['id'=>$info['id']]); | ||
| 152 | + } | ||
| 153 | + echo date('Y-m-d H:i:s') . 'end' . PHP_EOL; | ||
| 154 | + } | ||
| 155 | + | ||
| 156 | + /** | ||
| 157 | + * @remark :本月询盘总量 | ||
| 158 | + * @name :month_total | ||
| 159 | + * @author :lyh | ||
| 160 | + * @method :post | ||
| 161 | + * @time :2024/1/8 11:02 | ||
| 162 | + */ | ||
| 163 | + public function pv_ip(&$arr,$start,$end,$project_id){ | ||
| 164 | + $pv_ip = DB::table('gl_count') | ||
| 165 | + ->where(['project_id'=>$project_id]) | ||
| 166 | + ->where('date','>=',$start.' 00:00:00') | ||
| 167 | + ->where('date','<=',$end.' 23:59:59') | ||
| 168 | + ->select(DB::raw('SUM(pv_num) as pv_num'), DB::raw('SUM(ip_num) as ip_num'),DB::raw('SUM(inquiry_num) as inquiry_num')) | ||
| 169 | + ->first(); | ||
| 170 | + $arr['pv'] = $pv_ip->pv_num; | ||
| 171 | + $arr['ip'] = $pv_ip->ip_num; | ||
| 172 | + if($arr['ip'] != 0){ | ||
| 173 | + $arr['rate'] = round((($arr['month_total'] ?? 0) / $arr['ip']) * 10,2); | ||
| 174 | + } | ||
| 175 | + return $arr; | ||
| 176 | + } | ||
| 177 | + /** | ||
| 178 | + * @remark :来源访问前8 | ||
| 179 | + * @name :sourceCount | ||
| 180 | + * @author :lyh | ||
| 181 | + * @method :post | ||
| 182 | + * @time :2023/6/30 16:14 | ||
| 183 | + */ | ||
| 184 | + public function sourceCount(&$arr,$startTime,$endTime){ | ||
| 185 | + //访问来源前10 | ||
| 186 | + $source = DB::connection('custom_mysql')->table('gl_customer_visit') | ||
| 187 | + ->select('referrer_url', DB::raw('COUNT(*) as count')) | ||
| 188 | + ->groupBy('referrer_url') | ||
| 189 | + ->whereBetween('updated_date', [$startTime,$endTime]) | ||
| 190 | + ->orderByDesc('count')->limit(10)->get()->toArray(); | ||
| 191 | + $arr['source'] = json_encode($source); | ||
| 192 | + //访问国家前15 | ||
| 193 | + $source_country = DB::connection('custom_mysql')->table('gl_customer_visit') | ||
| 194 | + ->select('country',DB::raw('COUNT(*) as ip'),DB::raw('SUM(depth) as pv')) | ||
| 195 | + ->groupBy('country') | ||
| 196 | + ->whereBetween('updated_date', [$startTime,$endTime]) | ||
| 197 | + ->orderBy('ip','desc')->limit(15)->get()->toArray(); | ||
| 198 | + $arr['source_country'] = json_encode($source_country); | ||
| 199 | + //受访界面前15 | ||
| 200 | + $referrer_url = DB::connection('custom_mysql')->table('gl_customer_visit') | ||
| 201 | + ->select('url',DB::raw('COUNT(*) as num')) | ||
| 202 | + ->orderBy('num','desc') | ||
| 203 | + ->whereBetween('updated_date', [$startTime,$endTime]) | ||
| 204 | + ->groupBy('url') | ||
| 205 | + ->limit(15)->get()->toArray(); | ||
| 206 | + $arr['referrer_url'] = json_encode($referrer_url); | ||
| 207 | + //访问端口 | ||
| 208 | + $referrer_port = DB::connection('custom_mysql')->table('gl_customer_visit') | ||
| 209 | + ->select('device_port',DB::raw('COUNT(*) as num')) | ||
| 210 | + ->orderBy('num','desc') | ||
| 211 | + ->whereBetween('updated_date', [$startTime,$endTime]) | ||
| 212 | + ->groupBy('device_port') | ||
| 213 | + ->limit(15)->get()->toArray(); | ||
| 214 | + $arr['referrer_port'] = json_encode($referrer_port); | ||
| 215 | + return $arr; | ||
| 216 | + } | ||
| 217 | + | ||
| 218 | + public function inquiry($url,$month){ | ||
| 219 | + $url = 'https://'.$url.'/'; | ||
| 220 | + $token = md5($url.date("Y-m-d")); | ||
| 221 | + $url = 'https://form.globalso.com/api/external-interface/country_con/15243d63ed5a5738?domain='.$url.'&token='.$token.'&source=1,2,3,4&model=month&sta_date='.$month; | ||
| 222 | + $res = http_get($url,['charset=utf-8']); | ||
| 223 | + echo date('Y-m-d H:i:s') . '数据:'.json_encode($res) . PHP_EOL; | ||
| 224 | + return $res; | ||
| 225 | + } | ||
| 226 | + | ||
| 227 | +} |
| 1 | <?php | 1 | <?php |
| 2 | /** | 2 | /** |
| 3 | * @remark : | 3 | * @remark : |
| 4 | - * @name :UpgradeProjectCount.php | 4 | + * @name :CountProject.php |
| 5 | * @author :lyh | 5 | * @author :lyh |
| 6 | * @method :post | 6 | * @method :post |
| 7 | * @time :2024/1/8 9:03 | 7 | * @time :2024/1/8 9:03 |
| @@ -13,6 +13,7 @@ use App\Helper\FormGlobalsoApi; | @@ -13,6 +13,7 @@ use App\Helper\FormGlobalsoApi; | ||
| 13 | use App\Models\Com\UpdateOldInfo; | 13 | use App\Models\Com\UpdateOldInfo; |
| 14 | use App\Models\Domain\DomainInfo; | 14 | use App\Models\Domain\DomainInfo; |
| 15 | use App\Models\HomeCount\MonthCount; | 15 | use App\Models\HomeCount\MonthCount; |
| 16 | +use App\Models\Inquiry\InquiryFormData; | ||
| 16 | use App\Models\Project\Project; | 17 | use App\Models\Project\Project; |
| 17 | use App\Models\Visit\Visit; | 18 | use App\Models\Visit\Visit; |
| 18 | use App\Services\ProjectServer; | 19 | use App\Services\ProjectServer; |
| @@ -20,14 +21,14 @@ use Illuminate\Console\Command; | @@ -20,14 +21,14 @@ use Illuminate\Console\Command; | ||
| 20 | use Illuminate\Support\Facades\DB; | 21 | use Illuminate\Support\Facades\DB; |
| 21 | use App\Models\HomeCount\Count; | 22 | use App\Models\HomeCount\Count; |
| 22 | 23 | ||
| 23 | -class UpgradeProjectCount extends Command | 24 | +class MonthProjectCount extends Command |
| 24 | { | 25 | { |
| 25 | /** | 26 | /** |
| 26 | * The name and signature of the console command. | 27 | * The name and signature of the console command. |
| 27 | * | 28 | * |
| 28 | * @var string | 29 | * @var string |
| 29 | */ | 30 | */ |
| 30 | - protected $signature = 'upgrade_month_count {project_id}'; | 31 | + protected $signature = 'month_project {project_id}'; |
| 31 | 32 | ||
| 32 | /** | 33 | /** |
| 33 | * The console command description. | 34 | * The console command description. |
| @@ -64,10 +65,8 @@ class UpgradeProjectCount extends Command | @@ -64,10 +65,8 @@ class UpgradeProjectCount extends Command | ||
| 64 | ->select(DB::raw('DATE_FORMAT(updated_date, "%Y-%m") as month')) | 65 | ->select(DB::raw('DATE_FORMAT(updated_date, "%Y-%m") as month')) |
| 65 | ->groupBy('month')->get()->toArray(); | 66 | ->groupBy('month')->get()->toArray(); |
| 66 | foreach ($list as $k=>$v){ | 67 | foreach ($list as $k=>$v){ |
| 68 | + $arr = []; | ||
| 67 | $v = (array)$v; | 69 | $v = (array)$v; |
| 68 | - if($v['month'] == date('Y-m')){ | ||
| 69 | - continue; | ||
| 70 | - } | ||
| 71 | $monthCountModel = new MonthCount(); | 70 | $monthCountModel = new MonthCount(); |
| 72 | $info = $monthCountModel->read(['month'=>$v['month'],'project_id'=>$project_id]); | 71 | $info = $monthCountModel->read(['month'=>$v['month'],'project_id'=>$project_id]); |
| 73 | // 获取当月开始时间 | 72 | // 获取当月开始时间 |
| @@ -76,7 +75,7 @@ class UpgradeProjectCount extends Command | @@ -76,7 +75,7 @@ class UpgradeProjectCount extends Command | ||
| 76 | $end = date('Y-m-t', strtotime($v['month'])); | 75 | $end = date('Y-m-t', strtotime($v['month'])); |
| 77 | $arr['project_id'] = $project_id; | 76 | $arr['project_id'] = $project_id; |
| 78 | $res = $this->inquiry($url,$v['month']); | 77 | $res = $this->inquiry($url,$v['month']); |
| 79 | -// $arr['month_total'] = 0; | 78 | + $arr['total'] = $arr['month_total'] = 0; |
| 80 | if(isset($res['data']['count'])){ | 79 | if(isset($res['data']['count'])){ |
| 81 | echo date('Y-m-d H:i:s') . '数据:'.$res['data']['count'] . PHP_EOL; | 80 | echo date('Y-m-d H:i:s') . '数据:'.$res['data']['count'] . PHP_EOL; |
| 82 | $arr['month_total'] = $res['data']['count']; | 81 | $arr['month_total'] = $res['data']['count']; |
| @@ -89,9 +88,21 @@ class UpgradeProjectCount extends Command | @@ -89,9 +88,21 @@ class UpgradeProjectCount extends Command | ||
| 89 | $arr['total'] = $res['data']['count'] + ($previousInfo['total'] ?? 0); | 88 | $arr['total'] = $res['data']['count'] + ($previousInfo['total'] ?? 0); |
| 90 | } | 89 | } |
| 91 | } | 90 | } |
| 91 | + //获取当月的其他询盘 | ||
| 92 | + $arr['total'] += InquiryFormData::getCount([$start.' 00:00:00',$end.' 00:00:00']); | ||
| 93 | + $country = []; | ||
| 92 | if(isset($res['data']['data'])){ | 94 | if(isset($res['data']['data'])){ |
| 93 | - $arr['country'] = json_encode($res['data']['data']); | 95 | + $country = $res['data']['data']; |
| 96 | + } | ||
| 97 | + $countryData = InquiryFormData::getCountryCount([$start.' 00:00:00',$end.' 00:00:00']); | ||
| 98 | + foreach ($countryData as $v1){ | ||
| 99 | + if(isset($country[$v1['country']])){ | ||
| 100 | + $country[$v1['country']] += $v1['count']; | ||
| 101 | + }else{ | ||
| 102 | + $country[$v1['country']] = $v1['count']; | ||
| 103 | + } | ||
| 94 | } | 104 | } |
| 105 | + $arr['country'] = json_encode($country); | ||
| 95 | $arr['month'] = $v['month']; | 106 | $arr['month'] = $v['month']; |
| 96 | $arr = $this->pv_ip($arr,$start,$end,$project_id); | 107 | $arr = $this->pv_ip($arr,$start,$end,$project_id); |
| 97 | $arr = $this->sourceCount($arr,$start,$end); | 108 | $arr = $this->sourceCount($arr,$start,$end); |
| @@ -13,6 +13,7 @@ use App\Models\Com\KeywordVideoTaskLog; | @@ -13,6 +13,7 @@ use App\Models\Com\KeywordVideoTaskLog; | ||
| 13 | use App\Models\Domain\DomainInfo; | 13 | use App\Models\Domain\DomainInfo; |
| 14 | use Illuminate\Console\Command; | 14 | use Illuminate\Console\Command; |
| 15 | use Illuminate\Support\Facades\DB; | 15 | use Illuminate\Support\Facades\DB; |
| 16 | +use Illuminate\Support\Facades\Log; | ||
| 16 | 17 | ||
| 17 | /** | 18 | /** |
| 18 | * @remark :通知C端生成界面 | 19 | * @remark :通知C端生成界面 |
| @@ -65,6 +66,7 @@ class Notice extends Command | @@ -65,6 +66,7 @@ class Notice extends Command | ||
| 65 | } | 66 | } |
| 66 | foreach ($domainList as $v1){ | 67 | foreach ($domainList as $v1){ |
| 67 | //TODO::通知C端 | 68 | //TODO::通知C端 |
| 69 | + @file_put_contents(storage_path('logs/notice_c'.'.log'), var_export($v1['domain'], true) . PHP_EOL, FILE_APPEND); | ||
| 68 | $this->curlDelRoute($v1['domain'],$v1['project_id']); | 70 | $this->curlDelRoute($v1['domain'],$v1['project_id']); |
| 69 | } | 71 | } |
| 70 | return true; | 72 | return true; |
| @@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
| 2 | 2 | ||
| 3 | namespace App\Console\Commands\Project; | 3 | namespace App\Console\Commands\Project; |
| 4 | 4 | ||
| 5 | +use App\Helper\Translate; | ||
| 5 | use App\Models\Com\NoticeLog; | 6 | use App\Models\Com\NoticeLog; |
| 6 | use App\Models\Product\Keyword; | 7 | use App\Models\Product\Keyword; |
| 7 | use App\Models\RouteMap\RouteMap; | 8 | use App\Models\RouteMap\RouteMap; |
| @@ -80,7 +81,12 @@ class InitKeyword extends Command | @@ -80,7 +81,12 @@ class InitKeyword extends Command | ||
| 80 | foreach ($keyword as $val) { | 81 | foreach ($keyword as $val) { |
| 81 | $this->output(' keywordID: ' . $val->id . ', title: ' . $val->title); | 82 | $this->output(' keywordID: ' . $val->id . ', title: ' . $val->title); |
| 82 | try { | 83 | try { |
| 83 | - $route = RouteMap::setRoute($val['title'],RouteMap::SOURCE_PRODUCT_KEYWORD, $val->id, $notice['data']['project_id']); | 84 | + if(contains_russian($val['title'])){ |
| 85 | + $title = Translate::tran($val['title'], 'en'); | ||
| 86 | + }else{ | ||
| 87 | + $title = $val['title']; | ||
| 88 | + } | ||
| 89 | + $route = RouteMap::setRoute($title,RouteMap::SOURCE_PRODUCT_KEYWORD, $val->id, $notice['data']['project_id']); | ||
| 84 | $val->route = $route; | 90 | $val->route = $route; |
| 85 | $val->save(); | 91 | $val->save(); |
| 86 | } catch (\Exception $e) { | 92 | } catch (\Exception $e) { |
| @@ -61,10 +61,6 @@ class InitProject extends Command | @@ -61,10 +61,6 @@ class InitProject extends Command | ||
| 61 | $project_logic->createUser($project['mobile'],$project['id'],$project['lead_name']); | 61 | $project_logic->createUser($project['mobile'],$project['id'],$project['lead_name']); |
| 62 | } | 62 | } |
| 63 | $project_logic->createdRole($project['id']); | 63 | $project_logic->createdRole($project['id']); |
| 64 | - //更改服务器状态 | ||
| 65 | - if(!empty($project['serve_id'])){ | ||
| 66 | - $project_logic->updateServe($project['serve_id']); | ||
| 67 | - } | ||
| 68 | $item->status = NoticeLog::STATUS_SUCCESS; | 64 | $item->status = NoticeLog::STATUS_SUCCESS; |
| 69 | $item->save(); | 65 | $item->save(); |
| 70 | echo 'success:' . $item['id'] . PHP_EOL; | 66 | echo 'success:' . $item['id'] . PHP_EOL; |
| @@ -446,6 +446,8 @@ class SyncProject extends Command | @@ -446,6 +446,8 @@ class SyncProject extends Command | ||
| 446 | ProjectServer::createDatabase($project); | 446 | ProjectServer::createDatabase($project); |
| 447 | //创建表 | 447 | //创建表 |
| 448 | ProjectServer::initTable(); | 448 | ProjectServer::initTable(); |
| 449 | + //初始数据 | ||
| 450 | + ProjectServer::saveInitParam($project_id); | ||
| 449 | } | 451 | } |
| 450 | 452 | ||
| 451 | /** | 453 | /** |
| @@ -65,7 +65,7 @@ class RankData extends BaseCommands | @@ -65,7 +65,7 @@ class RankData extends BaseCommands | ||
| 65 | $error = 0; | 65 | $error = 0; |
| 66 | $api = new QuanqiusouApi(); | 66 | $api = new QuanqiusouApi(); |
| 67 | //有排名api编号的项目 | 67 | //有排名api编号的项目 |
| 68 | - $list = DeployOptimize::where('api_no', '>', 0)->select('api_no', 'minor_languages', 'project_id')->orderBy('project_id', 'asc')->get(); | 68 | + $list = DeployOptimize::where('api_no', '>', 0)->select('api_no', 'project_id')->orderBy('project_id', 'asc')->get(); |
| 69 | Log::channel('rank_data')->info('开始-排名数据-' . count($list)); | 69 | Log::channel('rank_data')->info('开始-排名数据-' . count($list)); |
| 70 | //当日所有站点谷歌收录数据 | 70 | //当日所有站点谷歌收录数据 |
| 71 | $site_res = $api->getSiteRes(); | 71 | $site_res = $api->getSiteRes(); |
| @@ -62,23 +62,24 @@ class ReplaceHtml extends Command | @@ -62,23 +62,24 @@ class ReplaceHtml extends Command | ||
| 62 | while (true){ | 62 | while (true){ |
| 63 | $replaceHtmlModel = new TemplateReplaceHtml(); | 63 | $replaceHtmlModel = new TemplateReplaceHtml(); |
| 64 | $replaceHtmlList = $replaceHtmlModel->list(['status'=>$replaceHtmlModel::STATUS]); | 64 | $replaceHtmlList = $replaceHtmlModel->list(['status'=>$replaceHtmlModel::STATUS]); |
| 65 | - if(!empty($replaceHtmlList)){ | ||
| 66 | - foreach ($replaceHtmlList as $v){ | ||
| 67 | - ProjectServer::useProject($v['project_id']); | ||
| 68 | - echo '开始,任务id:'.$v['id'].PHP_EOL; | ||
| 69 | - if($v['source'] == 9){//单页面 | ||
| 70 | - $count = $this->createReplacePageHtmlLog($v); | ||
| 71 | - }else{ | ||
| 72 | - $count = $this->createReplaceHtmlLog($v); | ||
| 73 | - } | ||
| 74 | - //修改当前主任务状态为待执行 | ||
| 75 | - $replaceHtmlModel->edit(['status'=>$replaceHtmlModel::STATUS_START,'total_num'=>$count],['id'=>$v['id']]); | ||
| 76 | - echo '结束'.PHP_EOL; | ||
| 77 | - DB::disconnect('custom_mysql'); | 65 | + if(empty($replaceHtmlList)){ |
| 66 | + sleep(20); | ||
| 67 | + continue; | ||
| 68 | + } | ||
| 69 | + foreach ($replaceHtmlList as $v){ | ||
| 70 | + ProjectServer::useProject($v['project_id']); | ||
| 71 | + echo '开始,任务id:'.$v['id'].PHP_EOL; | ||
| 72 | + if($v['source'] == 9){//单页面 | ||
| 73 | + $count = $this->createReplacePageHtmlLog($v); | ||
| 74 | + }else{ | ||
| 75 | + $count = $this->createReplaceHtmlLog($v); | ||
| 78 | } | 76 | } |
| 77 | + //修改当前主任务状态为待执行 | ||
| 78 | + $replaceHtmlModel->edit(['status'=>$replaceHtmlModel::STATUS_START,'total_num'=>$count],['id'=>$v['id']]); | ||
| 79 | + echo '结束'.PHP_EOL; | ||
| 80 | + DB::disconnect('custom_mysql'); | ||
| 79 | } | 81 | } |
| 80 | - sleep(5); | ||
| 81 | - return true; | 82 | + sleep(10); |
| 82 | } | 83 | } |
| 83 | } | 84 | } |
| 84 | 85 | ||
| @@ -104,7 +105,7 @@ class ReplaceHtml extends Command | @@ -104,7 +105,7 @@ class ReplaceHtml extends Command | ||
| 104 | 'source_id'=>$v['id'], | 105 | 'source_id'=>$v['id'], |
| 105 | 'is_rollback'=>$info['is_rollback'], | 106 | 'is_rollback'=>$info['is_rollback'], |
| 106 | 'template_id'=>$info['template_id'], | 107 | 'template_id'=>$info['template_id'], |
| 107 | - 'name'=>$v['name'], | 108 | + 'source_name'=>$v['name'], |
| 108 | 'created_at'=>date('Y-m-d H:i:s'), | 109 | 'created_at'=>date('Y-m-d H:i:s'), |
| 109 | 'updated_at'=>date('Y-m-d H:i:s') | 110 | 'updated_at'=>date('Y-m-d H:i:s') |
| 110 | ]; | 111 | ]; |
| @@ -124,22 +125,40 @@ class ReplaceHtml extends Command | @@ -124,22 +125,40 @@ class ReplaceHtml extends Command | ||
| 124 | * @time :2024/5/10 17:26 | 125 | * @time :2024/5/10 17:26 |
| 125 | */ | 126 | */ |
| 126 | public function createReplaceHtmlLog($info){ | 127 | public function createReplaceHtmlLog($info){ |
| 127 | - $bTemplateModel = new BTemplate(); | ||
| 128 | - $condition = ['is_custom'=>$info['is_custom'], 'is_list'=>$info['is_list'], 'template_id'=>$info['template_id']]; | ||
| 129 | - if($info['source'] != 0){ | ||
| 130 | - $condition['source'] = $info['source']; | ||
| 131 | - } | ||
| 132 | - if($info['template_id'] != 0){ | ||
| 133 | - $condition['main_html'] = ['like','%'.trim($info['old_html']).'%']; | 128 | + if($info['is_rollback'] != 0){ |
| 129 | + $saveData = []; | ||
| 130 | + $templateHtmlLogModel = new TemplateReplaceHtmlLog(); | ||
| 131 | + $list = $templateHtmlLogModel->list(['replace_id'=>$info['rollback_id']]); | ||
| 132 | + foreach ($list as $value){ | ||
| 133 | + unset($value['id']); | ||
| 134 | + $value['replace_id'] = $info['id']; | ||
| 135 | + $value['is_rollback'] = $info['is_rollback']; | ||
| 136 | + $value['old_html'] = $info['old_html']; | ||
| 137 | + $value['html'] = $info['html']; | ||
| 138 | + $value['created_at'] = date('Y-m-d H:i:s'); | ||
| 139 | + $value['updated_at'] = date('Y-m-d H:i:s'); | ||
| 140 | + $saveData[] = $value; | ||
| 141 | + } | ||
| 134 | }else{ | 142 | }else{ |
| 135 | - $condition['html'] = ['like','%'.trim($info['old_html']).'%']; | ||
| 136 | - } | ||
| 137 | - $bTemplateList = $bTemplateModel->list($condition); | ||
| 138 | - $saveData = []; | ||
| 139 | - foreach ($bTemplateList as $v){ | ||
| 140 | - $source_id = $v['source'] == 1 ? 0 : $v['source_id']; | ||
| 141 | - $name = $this->getSourceName($v['source'],$source_id,$v['is_list'],$v['is_custom']); | ||
| 142 | - $saveData[] = $this->saveData($info,$v,$source_id,$name); | 143 | + $bTemplateModel = new BTemplate(); |
| 144 | + $condition = ['is_custom'=>$info['is_custom'], 'is_list'=>$info['is_list'], 'template_id'=>$info['template_id']]; | ||
| 145 | + if($info['source'] != 0){ | ||
| 146 | + $condition['source'] = $info['source']; | ||
| 147 | + } | ||
| 148 | + if($info['template_id'] != 0){ | ||
| 149 | + $condition['main_html'] = ['like','%'.trim($info['old_html']).'%']; | ||
| 150 | + }else{ | ||
| 151 | + $condition['html'] = ['like','%'.trim($info['old_html']).'%']; | ||
| 152 | + } | ||
| 153 | + $bTemplateList = $bTemplateModel->list($condition); | ||
| 154 | + $saveData = []; | ||
| 155 | + foreach ($bTemplateList as $v){ | ||
| 156 | + $source_id = $v['source'] == 1 ? 0 : $v['source_id']; | ||
| 157 | + $name_route = $this->getSourceName($v['source'],$source_id,$v['is_list'],$v['is_custom']); | ||
| 158 | + if($name_route !== false){ | ||
| 159 | + $saveData[] = $this->saveData($info,$v,$source_id,$name_route); | ||
| 160 | + } | ||
| 161 | + } | ||
| 143 | } | 162 | } |
| 144 | if(!empty($saveData)){ | 163 | if(!empty($saveData)){ |
| 145 | $templateHtmlLogModel = new TemplateReplaceHtmlLog(); | 164 | $templateHtmlLogModel = new TemplateReplaceHtmlLog(); |
| @@ -155,7 +174,7 @@ class ReplaceHtml extends Command | @@ -155,7 +174,7 @@ class ReplaceHtml extends Command | ||
| 155 | * @method :post | 174 | * @method :post |
| 156 | * @time :2024/5/13 11:29 | 175 | * @time :2024/5/13 11:29 |
| 157 | */ | 176 | */ |
| 158 | - public function saveData($info,$v,$source_id,$name){ | 177 | + public function saveData($info,$v,$source_id,$name_route){ |
| 159 | return [ | 178 | return [ |
| 160 | 'replace_id'=>$info['id'], | 179 | 'replace_id'=>$info['id'], |
| 161 | 'project_id'=>$info['project_id'], | 180 | 'project_id'=>$info['project_id'], |
| @@ -168,7 +187,8 @@ class ReplaceHtml extends Command | @@ -168,7 +187,8 @@ class ReplaceHtml extends Command | ||
| 168 | 'is_list'=>$v['is_list'], | 187 | 'is_list'=>$v['is_list'], |
| 169 | 'is_rollback'=>$info['is_rollback'], | 188 | 'is_rollback'=>$info['is_rollback'], |
| 170 | 'template_id'=>$info['template_id'], | 189 | 'template_id'=>$info['template_id'], |
| 171 | - 'source_name'=>$name, | 190 | + 'source_name'=>$name_route['name'], |
| 191 | + 'route'=>$name_route['route'], | ||
| 172 | 'created_at'=>date('Y-m-d H:i:s'), | 192 | 'created_at'=>date('Y-m-d H:i:s'), |
| 173 | 'updated_at'=>date('Y-m-d H:i:s') | 193 | 'updated_at'=>date('Y-m-d H:i:s') |
| 174 | ]; | 194 | ]; |
| @@ -186,7 +206,7 @@ class ReplaceHtml extends Command | @@ -186,7 +206,7 @@ class ReplaceHtml extends Command | ||
| 186 | return $this->getCustomName($source,$source_id,$is_list); | 206 | return $this->getCustomName($source,$source_id,$is_list); |
| 187 | } | 207 | } |
| 188 | if($source == BTemplate::SOURCE_HOME){ | 208 | if($source == BTemplate::SOURCE_HOME){ |
| 189 | - return ''; | 209 | + return ['name'=>'','route'=>'']; |
| 190 | }elseif ($source == BTemplate::SOURCE_PRODUCT){ | 210 | }elseif ($source == BTemplate::SOURCE_PRODUCT){ |
| 191 | return $this->getProductName($source_id,$is_list); | 211 | return $this->getProductName($source_id,$is_list); |
| 192 | }elseif ($source == BTemplate::SOURCE_BLOG){ | 212 | }elseif ($source == BTemplate::SOURCE_BLOG){ |
| @@ -230,6 +250,7 @@ class ReplaceHtml extends Command | @@ -230,6 +250,7 @@ class ReplaceHtml extends Command | ||
| 230 | return false; | 250 | return false; |
| 231 | } | 251 | } |
| 232 | $name = $cateInfo['name']; | 252 | $name = $cateInfo['name']; |
| 253 | + $route = $cateInfo['alias']; | ||
| 233 | }else{ | 254 | }else{ |
| 234 | $newsModel = new News(); | 255 | $newsModel = new News(); |
| 235 | $newsInfo = $newsModel->read(['id'=>$source_id]); | 256 | $newsInfo = $newsModel->read(['id'=>$source_id]); |
| @@ -237,8 +258,9 @@ class ReplaceHtml extends Command | @@ -237,8 +258,9 @@ class ReplaceHtml extends Command | ||
| 237 | return false; | 258 | return false; |
| 238 | } | 259 | } |
| 239 | $name = $newsInfo['name']; | 260 | $name = $newsInfo['name']; |
| 261 | + $route = $newsInfo['url']; | ||
| 240 | } | 262 | } |
| 241 | - return $name; | 263 | + return ['name'=>$name,'route'=>$route]; |
| 242 | } | 264 | } |
| 243 | 265 | ||
| 244 | /** | 266 | /** |
| @@ -256,6 +278,7 @@ class ReplaceHtml extends Command | @@ -256,6 +278,7 @@ class ReplaceHtml extends Command | ||
| 256 | return false; | 278 | return false; |
| 257 | } | 279 | } |
| 258 | $name = $cateInfo['name']; | 280 | $name = $cateInfo['name']; |
| 281 | + $route = $cateInfo['alias']; | ||
| 259 | }else{ | 282 | }else{ |
| 260 | $blogModel = new Blog(); | 283 | $blogModel = new Blog(); |
| 261 | $productInfo = $blogModel->read(['id'=>$source_id]); | 284 | $productInfo = $blogModel->read(['id'=>$source_id]); |
| @@ -263,8 +286,9 @@ class ReplaceHtml extends Command | @@ -263,8 +286,9 @@ class ReplaceHtml extends Command | ||
| 263 | return false; | 286 | return false; |
| 264 | } | 287 | } |
| 265 | $name = $productInfo['name']; | 288 | $name = $productInfo['name']; |
| 289 | + $route = $productInfo['url']; | ||
| 266 | } | 290 | } |
| 267 | - return $name; | 291 | + return ['name'=>$name,'route'=>$route]; |
| 268 | } | 292 | } |
| 269 | 293 | ||
| 270 | /** | 294 | /** |
| @@ -282,6 +306,7 @@ class ReplaceHtml extends Command | @@ -282,6 +306,7 @@ class ReplaceHtml extends Command | ||
| 282 | return false; | 306 | return false; |
| 283 | } | 307 | } |
| 284 | $name = $cateInfo['title']; | 308 | $name = $cateInfo['title']; |
| 309 | + $route = $cateInfo['route']; | ||
| 285 | }else{ | 310 | }else{ |
| 286 | $productModel = new Product(); | 311 | $productModel = new Product(); |
| 287 | $productInfo = $productModel->read(['id'=>$source_id]); | 312 | $productInfo = $productModel->read(['id'=>$source_id]); |
| @@ -289,8 +314,9 @@ class ReplaceHtml extends Command | @@ -289,8 +314,9 @@ class ReplaceHtml extends Command | ||
| 289 | return false; | 314 | return false; |
| 290 | } | 315 | } |
| 291 | $name = $productInfo['title']; | 316 | $name = $productInfo['title']; |
| 317 | + $route = $productInfo['route']; | ||
| 292 | } | 318 | } |
| 293 | - return $name; | 319 | + return ['name'=>$name,'route'=>$route]; |
| 294 | } | 320 | } |
| 295 | 321 | ||
| 296 | /** | 322 | /** |
| @@ -313,6 +339,7 @@ class ReplaceHtml extends Command | @@ -313,6 +339,7 @@ class ReplaceHtml extends Command | ||
| 313 | return false; | 339 | return false; |
| 314 | } | 340 | } |
| 315 | $name = $cateInfo['name']; | 341 | $name = $cateInfo['name']; |
| 342 | + $route = $cateInfo['route']; | ||
| 316 | }else{ | 343 | }else{ |
| 317 | $contentModel = new CustomModuleContent(); | 344 | $contentModel = new CustomModuleContent(); |
| 318 | $contentInfo = $contentModel->read(['id'=>$source_id],['id','name']); | 345 | $contentInfo = $contentModel->read(['id'=>$source_id],['id','name']); |
| @@ -320,7 +347,8 @@ class ReplaceHtml extends Command | @@ -320,7 +347,8 @@ class ReplaceHtml extends Command | ||
| 320 | return false; | 347 | return false; |
| 321 | } | 348 | } |
| 322 | $name = $contentInfo['name']; | 349 | $name = $contentInfo['name']; |
| 350 | + $route = $contentInfo['route']; | ||
| 323 | } | 351 | } |
| 324 | - return $name; | 352 | + return ['name'=>$name,'route'=>$route]; |
| 325 | } | 353 | } |
| 326 | } | 354 | } |
| @@ -66,7 +66,7 @@ class ReplaceHtmlLog extends Command | @@ -66,7 +66,7 @@ class ReplaceHtmlLog extends Command | ||
| 66 | echo '结束'.PHP_EOL; | 66 | echo '结束'.PHP_EOL; |
| 67 | } | 67 | } |
| 68 | } | 68 | } |
| 69 | - sleep(5); | 69 | + sleep(20); |
| 70 | return true; | 70 | return true; |
| 71 | } | 71 | } |
| 72 | 72 | ||
| @@ -80,7 +80,7 @@ class ReplaceHtmlLog extends Command | @@ -80,7 +80,7 @@ class ReplaceHtmlLog extends Command | ||
| 80 | public function replaceHtml($info){ | 80 | public function replaceHtml($info){ |
| 81 | $source_id = $info['source'] == 1 ? 0 : $info['source_id']; | 81 | $source_id = $info['source'] == 1 ? 0 : $info['source_id']; |
| 82 | $bTemplateModel = new BTemplate(); | 82 | $bTemplateModel = new BTemplate(); |
| 83 | - $condition = ['source'=>$info['source'],'source_id'=>$info['source_id'], | 83 | + $condition = ['source'=>$info['source'],'source_id'=>$source_id, |
| 84 | 'template_id'=>$info['template_id'],'is_custom'=>$info['is_custom'],'is_list'=>$info['is_list']]; | 84 | 'template_id'=>$info['template_id'],'is_custom'=>$info['is_custom'],'is_list'=>$info['is_list']]; |
| 85 | $old_html = $info['old_html']; | 85 | $old_html = $info['old_html']; |
| 86 | $html = $info['html']; | 86 | $html = $info['html']; |
| @@ -9,14 +9,13 @@ | @@ -9,14 +9,13 @@ | ||
| 9 | 9 | ||
| 10 | namespace App\Console\Commands\Suppliers; | 10 | namespace App\Console\Commands\Suppliers; |
| 11 | 11 | ||
| 12 | -use App\Models\Com\Purchaser; | ||
| 13 | use App\Models\Product\Keyword; | 12 | use App\Models\Product\Keyword; |
| 14 | use App\Models\Project\DeployBuild; | 13 | use App\Models\Project\DeployBuild; |
| 15 | -use App\Models\Project\Project; | 14 | +use App\Models\Purchaser\Purchaser; |
| 15 | +use App\Models\Purchaser\PurchaserInfo; | ||
| 16 | use App\Services\ProjectServer; | 16 | use App\Services\ProjectServer; |
| 17 | use Illuminate\Console\Command; | 17 | use Illuminate\Console\Command; |
| 18 | use Illuminate\Support\Facades\DB; | 18 | use Illuminate\Support\Facades\DB; |
| 19 | -use Illuminate\Support\Facades\Log; | ||
| 20 | 19 | ||
| 21 | class RecommendedSuppliers extends Command | 20 | class RecommendedSuppliers extends Command |
| 22 | { | 21 | { |
| @@ -52,27 +51,20 @@ class RecommendedSuppliers extends Command | @@ -52,27 +51,20 @@ class RecommendedSuppliers extends Command | ||
| 52 | { | 51 | { |
| 53 | $projectModel = new DeployBuild(); | 52 | $projectModel = new DeployBuild(); |
| 54 | $project_list = $projectModel->list(['is_supplier'=>1]);//TODO::已开启推荐供应商 | 53 | $project_list = $projectModel->list(['is_supplier'=>1]);//TODO::已开启推荐供应商 |
| 55 | - foreach ($project_list as $k => $v){ | 54 | + foreach ($project_list as $v){ |
| 56 | echo date('Y-m-d H:i:s') . 'project_id:'.$v['project_id'] . PHP_EOL; | 55 | echo date('Y-m-d H:i:s') . 'project_id:'.$v['project_id'] . PHP_EOL; |
| 57 | - ProjectServer::useProject($v['id']); | ||
| 58 | - $info = Keyword::inRandomOrder()->first(); | ||
| 59 | - if(empty($info)){ | ||
| 60 | - continue; | ||
| 61 | - } | ||
| 62 | - $keywordInfo = $this->getPurchaser($info['title']); | ||
| 63 | - if($keywordInfo !== false){ | ||
| 64 | - continue; | ||
| 65 | - } | 56 | + ProjectServer::useProject($v['project_id']); |
| 57 | + $title = $this->getKeywords($v['project_id']); | ||
| 66 | echo date('Y-m-d H:i:s') . '开始:'.$v['project_id'] . PHP_EOL; | 58 | echo date('Y-m-d H:i:s') . '开始:'.$v['project_id'] . PHP_EOL; |
| 67 | - $this->savePurchaser($v['id'],$info['title']); | 59 | + $this->savePurchaser($v['project_id'],$title); |
| 68 | DB::disconnect('custom_mysql'); | 60 | DB::disconnect('custom_mysql'); |
| 69 | } | 61 | } |
| 70 | return true; | 62 | return true; |
| 71 | } | 63 | } |
| 72 | 64 | ||
| 73 | - public function getPurchaser($keyword){ | 65 | + public function getPurchaser($keyword,$project_id){ |
| 74 | $purchaserModel = new Purchaser(); | 66 | $purchaserModel = new Purchaser(); |
| 75 | - return $purchaserModel->read(['keyword'=>$keyword]); | 67 | + return $purchaserModel->read(['keyword'=>$keyword,'project_id'=>$project_id]); |
| 76 | } | 68 | } |
| 77 | 69 | ||
| 78 | /** | 70 | /** |
| @@ -83,7 +75,7 @@ class RecommendedSuppliers extends Command | @@ -83,7 +75,7 @@ class RecommendedSuppliers extends Command | ||
| 83 | * @time :2024/3/5 11:38 | 75 | * @time :2024/3/5 11:38 |
| 84 | */ | 76 | */ |
| 85 | public function savePurchaser($project_id,$keyword,$row = 10){ | 77 | public function savePurchaser($project_id,$keyword,$row = 10){ |
| 86 | - $url = 'https://admin.hagro.cn/api/company_list'; | 78 | + $url = 'https://fob.ai.cc/api/company_list'; |
| 87 | $data = [ | 79 | $data = [ |
| 88 | 'prod_desc'=>$keyword, | 80 | 'prod_desc'=>$keyword, |
| 89 | 'total'=>$row ?? 10, | 81 | 'total'=>$row ?? 10, |
| @@ -97,7 +89,9 @@ class RecommendedSuppliers extends Command | @@ -97,7 +89,9 @@ class RecommendedSuppliers extends Command | ||
| 97 | 'total'=>$this->param['row'] ?? 10, | 89 | 'total'=>$this->param['row'] ?? 10, |
| 98 | ]; | 90 | ]; |
| 99 | $res = http_post($url,json_encode($param)); | 91 | $res = http_post($url,json_encode($param)); |
| 100 | - if(!empty($res) && $res['code'] == 200){ | 92 | + echo date('Y-m-d H:i:s') . json_encode($res) . PHP_EOL; |
| 93 | + if(!empty($res) && $res['code'] == 200 && !empty($res['data'])){ | ||
| 94 | + //保存多条数据 | ||
| 101 | $saveData = [ | 95 | $saveData = [ |
| 102 | 'project_id'=>$project_id, | 96 | 'project_id'=>$project_id, |
| 103 | 'keyword'=>$keyword, | 97 | 'keyword'=>$keyword, |
| @@ -105,6 +99,54 @@ class RecommendedSuppliers extends Command | @@ -105,6 +99,54 @@ class RecommendedSuppliers extends Command | ||
| 105 | ]; | 99 | ]; |
| 106 | $purchaserModel = new Purchaser(); | 100 | $purchaserModel = new Purchaser(); |
| 107 | $purchaserModel->add($saveData); | 101 | $purchaserModel->add($saveData); |
| 102 | + $this->savePurchaserInfo($project_id,$keyword,$res['data']); | ||
| 103 | + }else{ | ||
| 104 | + $title = $this->getKeywords($project_id); | ||
| 105 | + $this->savePurchaser($project_id,$title); | ||
| 106 | + } | ||
| 107 | + return true; | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + /** | ||
| 111 | + * @remark :取关键词 | ||
| 112 | + * @name :getKeywords | ||
| 113 | + * @author :lyh | ||
| 114 | + * @method :post | ||
| 115 | + * @time :2024/7/1 18:07 | ||
| 116 | + */ | ||
| 117 | + public function getKeywords($project_id){ | ||
| 118 | + $keywordModel = new Keyword(); | ||
| 119 | + $keywordModel-> | ||
| 120 | + $info = Keyword::inRandomOrder()->first(); | ||
| 121 | + $keywordInfo = $this->getPurchaser($info->title,$project_id); | ||
| 122 | + if($keywordInfo !== false){ | ||
| 123 | + $this->getKeywords($project_id); | ||
| 124 | + } | ||
| 125 | + return $info->title; | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + /** | ||
| 129 | + * @remark :保存供应商详情 | ||
| 130 | + * @name :savePurchaserInfo | ||
| 131 | + * @author :lyh | ||
| 132 | + * @method :post | ||
| 133 | + * @time :2024/5/29 16:38 | ||
| 134 | + */ | ||
| 135 | + public function savePurchaserInfo($project_id,$keyword,$data){ | ||
| 136 | + $purchaserInfoModel = new PurchaserInfo(); | ||
| 137 | + foreach ($data as $k =>$v){ | ||
| 138 | + $v['project_id'] = $project_id; | ||
| 139 | + $v['keyword'] = $keyword; | ||
| 140 | + $v['email'] = json_encode($v['email'],JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); | ||
| 141 | + $v['mobile'] = json_encode($v['mobile'],JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); | ||
| 142 | + $v['social_media'] = json_encode($v['social_media'],JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); | ||
| 143 | +// $v['created_at'] = date('Y-m-d H:i:s'); | ||
| 144 | +// $v['updated_at'] = $v['created_at']; | ||
| 145 | + $param = $v; | ||
| 146 | + $info = $purchaserInfoModel->read(['keyword'=>$keyword,'buyer'=>$v['buyer'],'project_id'=>$project_id],['id']); | ||
| 147 | + if($info === false){ | ||
| 148 | + $purchaserInfoModel->add($param); | ||
| 149 | + } | ||
| 108 | } | 150 | } |
| 109 | return true; | 151 | return true; |
| 110 | } | 152 | } |
| @@ -33,11 +33,16 @@ class SyncFile extends Command | @@ -33,11 +33,16 @@ class SyncFile extends Command | ||
| 33 | $errorFileModel = new ErrorFile(); | 33 | $errorFileModel = new ErrorFile(); |
| 34 | $lists = $errorFileModel->list(['status'=>0]);//未同步成功的图片及文件 | 34 | $lists = $errorFileModel->list(['status'=>0]);//未同步成功的图片及文件 |
| 35 | foreach ($lists as $k => $v){ | 35 | foreach ($lists as $k => $v){ |
| 36 | - $code = $this->synchronizationFile($v['path']); | 36 | + if(strpos($v['path'], '/181/') !== false ){ |
| 37 | + $code = $this->synchronizationFiles($v['path']); | ||
| 38 | + }else{ | ||
| 39 | + $code = $this->synchronizationFile($v['path']); | ||
| 40 | + } | ||
| 37 | if((int)$code == 200){ | 41 | if((int)$code == 200){ |
| 38 | echo date('Y-m-d H:i:s') . '编辑的path为:'. $v['path'] .',主键id:'. $v['id'] . PHP_EOL; | 42 | echo date('Y-m-d H:i:s') . '编辑的path为:'. $v['path'] .',主键id:'. $v['id'] . PHP_EOL; |
| 39 | $errorFileModel->edit(['status'=>1],['id'=>$v['id']]); | 43 | $errorFileModel->edit(['status'=>1],['id'=>$v['id']]); |
| 40 | } | 44 | } |
| 45 | + | ||
| 41 | } | 46 | } |
| 42 | echo date('Y-m-d H:i:s') . '编辑的end为:' . PHP_EOL; | 47 | echo date('Y-m-d H:i:s') . '编辑的end为:' . PHP_EOL; |
| 43 | return true; | 48 | return true; |
| @@ -57,4 +62,13 @@ class SyncFile extends Command | @@ -57,4 +62,13 @@ class SyncFile extends Command | ||
| 57 | $cmd = 'curl -F "file_path='.$file_path.'" -F "save_path=/www/wwwroot/cos'.$directoryPath.'" https://v6-file.globalso.com/upload.php'; | 62 | $cmd = 'curl -F "file_path='.$file_path.'" -F "save_path=/www/wwwroot/cos'.$directoryPath.'" https://v6-file.globalso.com/upload.php'; |
| 58 | return shell_exec($cmd); | 63 | return shell_exec($cmd); |
| 59 | } | 64 | } |
| 65 | + | ||
| 66 | + | ||
| 67 | + public function synchronizationFiles($path_name){ | ||
| 68 | + //同步到大文件 | ||
| 69 | + $file_path = config('filesystems.disks.s3')['cdn'].$path_name; | ||
| 70 | + $directoryPath = pathinfo($path_name, PATHINFO_DIRNAME); | ||
| 71 | + $cmd = 'curl -F "file_path='.$file_path.'" -F "save_path=/www/wwwroot/cos'.$directoryPath.'" https://v6-file.globalso.com/upload.php'; | ||
| 72 | + return shell_exec($cmd); | ||
| 73 | + } | ||
| 60 | } | 74 | } |
| @@ -28,30 +28,29 @@ class SyncSubmitTask extends Command | @@ -28,30 +28,29 @@ class SyncSubmitTask extends Command | ||
| 28 | 28 | ||
| 29 | public function handle() | 29 | public function handle() |
| 30 | { | 30 | { |
| 31 | - $backup = false; | ||
| 32 | while (true) { | 31 | while (true) { |
| 33 | - $task_id = $this->getTaskId(); | ||
| 34 | - if ($task_id > 2000000) { | ||
| 35 | - $backup = true; | ||
| 36 | - } | ||
| 37 | - if (empty($task_id)) { | ||
| 38 | - if ($backup) { | ||
| 39 | - $this->backup(); | ||
| 40 | - $backup = false; | ||
| 41 | - } | ||
| 42 | - sleep(5); | 32 | + $task_id = Redis::rpop('sync_submit_task'); |
| 33 | + if(!$task_id){ | ||
| 43 | continue; | 34 | continue; |
| 44 | } | 35 | } |
| 36 | + | ||
| 45 | $this->output('任务' . $task_id . '开始'); | 37 | $this->output('任务' . $task_id . '开始'); |
| 38 | + | ||
| 39 | + $time = time(); | ||
| 40 | + | ||
| 41 | + | ||
| 42 | + DB::enableQueryLog(); //启用查询日志 | ||
| 43 | + //清除之前的查询日志 | ||
| 44 | + DB::flushQueryLog(); | ||
| 45 | + | ||
| 46 | $task_info = SyncSubmitTaskModel::find($task_id); | 46 | $task_info = SyncSubmitTaskModel::find($task_id); |
| 47 | - if (empty($task_info) || $task_info->status) { | 47 | + if (empty($task_info) || $task_info->status !=3) { |
| 48 | $this->output('任务不存在或者已执行'); | 48 | $this->output('任务不存在或者已执行'); |
| 49 | continue; | 49 | continue; |
| 50 | } | 50 | } |
| 51 | try { | 51 | try { |
| 52 | $project = Project::getProjectByDomain($task_info['data']['domain'] ?? ''); | 52 | $project = Project::getProjectByDomain($task_info['data']['domain'] ?? ''); |
| 53 | $task_info->project_id = $project->id; | 53 | $task_info->project_id = $project->id; |
| 54 | - | ||
| 55 | SyncSubmitTaskService::handler($task_info); | 54 | SyncSubmitTaskService::handler($task_info); |
| 56 | $task_info->status = 1; | 55 | $task_info->status = 1; |
| 57 | $task_info->save(); | 56 | $task_info->save(); |
| @@ -76,20 +75,15 @@ class SyncSubmitTask extends Command | @@ -76,20 +75,15 @@ class SyncSubmitTask extends Command | ||
| 76 | 75 | ||
| 77 | $this->output('任务失败:' . $e->getMessage()); | 76 | $this->output('任务失败:' . $e->getMessage()); |
| 78 | } | 77 | } |
| 79 | - } | ||
| 80 | - } | ||
| 81 | 78 | ||
| 82 | - public function getTaskId() | ||
| 83 | - { | ||
| 84 | - $task_id = Redis::rpop('sync_submit_task'); | ||
| 85 | - if (empty($task_id)) { | ||
| 86 | - $ids = SyncSubmitTaskModel::where('status', 0)->limit(100)->pluck('id'); | ||
| 87 | - foreach ($ids as $id) { | ||
| 88 | - Redis::lpush('sync_submit_task', $id); | 79 | + $use_time = time() - $time; |
| 80 | + if($use_time > 1){ | ||
| 81 | + //数据库查询 | ||
| 82 | + $this->output('任务用时:' .$use_time . ' | ' . json_encode(DB::getQueryLog(),JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); | ||
| 89 | } | 83 | } |
| 90 | - $task_id = Redis::rpop('sync_submit_task'); | 84 | + //清除之前的查询日志 |
| 85 | + DB::flushQueryLog(); | ||
| 91 | } | 86 | } |
| 92 | - return $task_id; | ||
| 93 | } | 87 | } |
| 94 | 88 | ||
| 95 | /** | 89 | /** |
| @@ -100,31 +94,4 @@ class SyncSubmitTask extends Command | @@ -100,31 +94,4 @@ class SyncSubmitTask extends Command | ||
| 100 | echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL; | 94 | echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL; |
| 101 | return true; | 95 | return true; |
| 102 | } | 96 | } |
| 103 | - | ||
| 104 | - /** | ||
| 105 | - * 备份数据 | ||
| 106 | - * @author zbj | ||
| 107 | - * @date 2024/1/23 | ||
| 108 | - */ | ||
| 109 | - public function backup() | ||
| 110 | - { | ||
| 111 | - DB::beginTransaction(); | ||
| 112 | - try { | ||
| 113 | - $table = (new SyncSubmitTaskModel())->getTable(); | ||
| 114 | - $new_table = $table . '_backup_' . date('Ymd'); | ||
| 115 | - | ||
| 116 | - //重命名当前表 | ||
| 117 | - Schema::rename($table, $new_table); | ||
| 118 | - //克隆表数据 | ||
| 119 | - DB::statement('CREATE TABLE ' . $table . ' LIKE ' . $new_table); | ||
| 120 | - | ||
| 121 | - DB::commit(); | ||
| 122 | - | ||
| 123 | - $this->output('数据备份成功'); | ||
| 124 | - } catch (\Exception $e) { | ||
| 125 | - $this->output('数据备份失败' . $e->getMessage()); | ||
| 126 | - DB::rollBack(); | ||
| 127 | - } | ||
| 128 | - return true; | ||
| 129 | - } | ||
| 130 | } | 97 | } |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Console\Commands\Sync; | ||
| 4 | + | ||
| 5 | + | ||
| 6 | +use App\Exceptions\InquiryFilterException; | ||
| 7 | +use App\Models\Project\Project; | ||
| 8 | +use App\Models\SyncSubmitTask\SyncSubmitTask as SyncSubmitTaskModel; | ||
| 9 | +use App\Services\SyncSubmitTaskService; | ||
| 10 | +use Illuminate\Console\Command; | ||
| 11 | +use Illuminate\Support\Facades\Cache; | ||
| 12 | +use Illuminate\Support\Facades\DB; | ||
| 13 | +use Illuminate\Support\Facades\Redis; | ||
| 14 | +use Illuminate\Support\Facades\Schema; | ||
| 15 | +use Illuminate\Support\Str; | ||
| 16 | + | ||
| 17 | +/** | ||
| 18 | + * | ||
| 19 | + * Class SyncSubmitTask | ||
| 20 | + * @package App\Console\Commands | ||
| 21 | + * @author zbj | ||
| 22 | + * @date 2023/11/28 | ||
| 23 | + */ | ||
| 24 | +class SyncSubmitTaskDistribution extends Command | ||
| 25 | +{ | ||
| 26 | + | ||
| 27 | + protected $signature = 'sync_submit_task_distribution'; | ||
| 28 | + protected $description = '询盘、访问异步任务分发'; | ||
| 29 | + | ||
| 30 | + public function handle() | ||
| 31 | + { | ||
| 32 | + while (true) { | ||
| 33 | + $len = Redis::llen('sync_submit_task'); | ||
| 34 | + if (!$len) { | ||
| 35 | + $max_id = SyncSubmitTaskModel::orderBy('id', 'desc')->value('id'); | ||
| 36 | + if ($max_id > 2000000) { | ||
| 37 | + $this->backup(); | ||
| 38 | + } else { | ||
| 39 | + $tasks = SyncSubmitTaskModel::where('status', 0)->limit(100)->get(); | ||
| 40 | + foreach ($tasks as $task) { | ||
| 41 | + $task->status = 3; | ||
| 42 | + $task->save(); | ||
| 43 | + Redis::lpush('sync_submit_task', $task->id); | ||
| 44 | + } | ||
| 45 | + } | ||
| 46 | + } | ||
| 47 | + } | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + /** | ||
| 51 | + * 输出处理日志 | ||
| 52 | + */ | ||
| 53 | + public function output($message): bool | ||
| 54 | + { | ||
| 55 | + echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL; | ||
| 56 | + return true; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + /** | ||
| 60 | + * 备份数据 | ||
| 61 | + * @author zbj | ||
| 62 | + * @date 2024/1/23 | ||
| 63 | + */ | ||
| 64 | + public function backup() | ||
| 65 | + { | ||
| 66 | + DB::beginTransaction(); | ||
| 67 | + try { | ||
| 68 | + $table = (new SyncSubmitTaskModel())->getTable(); | ||
| 69 | + $new_table = $table . '_backup_' . date('Ymd'); | ||
| 70 | + | ||
| 71 | + //重命名当前表 | ||
| 72 | + Schema::rename($table, $new_table); | ||
| 73 | + //克隆表数据 | ||
| 74 | + DB::statement('CREATE TABLE ' . $table . ' LIKE ' . $new_table); | ||
| 75 | + | ||
| 76 | + //未入队的写到新表 | ||
| 77 | + $list = DB::table($new_table)->where('status', 0)->get(); | ||
| 78 | + $data = []; | ||
| 79 | + foreach ($list as $task) { | ||
| 80 | + $data[] = [ | ||
| 81 | + 'type' => $task->type, | ||
| 82 | + 'data' => json_encode($task->data), | ||
| 83 | + 'created_at' => $task['created_at'], | ||
| 84 | + 'updated_at' => $task['updated_at'], | ||
| 85 | + ]; | ||
| 86 | + } | ||
| 87 | + $data && SyncSubmitTaskModel::insert($data); | ||
| 88 | + | ||
| 89 | + DB::commit(); | ||
| 90 | + | ||
| 91 | + $this->output('数据备份成功'); | ||
| 92 | + } catch (\Exception $e) { | ||
| 93 | + $this->output('数据备份失败' . $e->getMessage()); | ||
| 94 | + DB::rollBack(); | ||
| 95 | + } | ||
| 96 | + return $new_table ?? ''; | ||
| 97 | + } | ||
| 98 | +} |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Console\Commands\Sync; | ||
| 4 | + | ||
| 5 | + | ||
| 6 | +use App\Exceptions\InquiryFilterException; | ||
| 7 | +use App\Models\Project\Project; | ||
| 8 | +use App\Models\SyncSubmitTask\SyncSubmitTaskZbj as SyncSubmitTaskModel; | ||
| 9 | +use App\Services\SyncSubmitTaskService; | ||
| 10 | +use Illuminate\Console\Command; | ||
| 11 | +use Illuminate\Support\Facades\DB; | ||
| 12 | +use Illuminate\Support\Facades\Redis; | ||
| 13 | +use Illuminate\Support\Facades\Schema; | ||
| 14 | +use Illuminate\Support\Str; | ||
| 15 | + | ||
| 16 | +/** | ||
| 17 | + * | ||
| 18 | + * Class SyncSubmitTask | ||
| 19 | + * @package App\Console\Commands | ||
| 20 | + * @author zbj | ||
| 21 | + * @date 2023/11/28 | ||
| 22 | + */ | ||
| 23 | +class SyncSubmitTaskZbj extends Command | ||
| 24 | +{ | ||
| 25 | + | ||
| 26 | + protected $signature = 'sync_submit_task_zbj'; | ||
| 27 | + protected $description = '询盘、访问异步任务'; | ||
| 28 | + | ||
| 29 | + public function handle() | ||
| 30 | + { | ||
| 31 | + $backup = false; | ||
| 32 | + while (true) { | ||
| 33 | + $task_id = $this->getTaskId(); | ||
| 34 | + if ($task_id > 2000000) { | ||
| 35 | + $backup = true; | ||
| 36 | + } | ||
| 37 | + if (empty($task_id)) { | ||
| 38 | + if ($backup) { | ||
| 39 | + $this->backup(); | ||
| 40 | + $backup = false; | ||
| 41 | + } | ||
| 42 | + sleep(5); | ||
| 43 | + continue; | ||
| 44 | + } | ||
| 45 | + $this->output('任务' . $task_id . '开始'); | ||
| 46 | + $task_info = SyncSubmitTaskModel::find($task_id); | ||
| 47 | + if (empty($task_info) || $task_info->status != 3) { | ||
| 48 | + $this->output('任务不存在或者已执行'); | ||
| 49 | + continue; | ||
| 50 | + } | ||
| 51 | + try { | ||
| 52 | + $project = Project::getProjectByDomain($task_info['data']['domain'] ?? ''); | ||
| 53 | + $task_info->project_id = $project->id; | ||
| 54 | + | ||
| 55 | + SyncSubmitTaskService::handler($task_info, $task_info->created_at); | ||
| 56 | + $task_info->status = 1; | ||
| 57 | + $task_info->save(); | ||
| 58 | + | ||
| 59 | + $this->output('任务完成'); | ||
| 60 | + } catch (InquiryFilterException $e) { | ||
| 61 | + $task_info->status = 1; | ||
| 62 | + $task_info->is_filtered = 1; | ||
| 63 | + $task_info->remark = $e->getMessage(); | ||
| 64 | + $task_info->save(); | ||
| 65 | + | ||
| 66 | + $this->output('任务完成'); | ||
| 67 | + } catch (\Exception $e) { | ||
| 68 | + $task_info->retry = $task_info->retry + 1; | ||
| 69 | + if ($task_info->retry >= 3) { | ||
| 70 | + $task_info->status = 2; | ||
| 71 | + $task_info->remark = Str::substr($e->getMessage(), 0, 200); | ||
| 72 | + } else { | ||
| 73 | + Redis::lpush('sync_submit_task_zbj', $task_id); | ||
| 74 | + } | ||
| 75 | + $task_info->save(); | ||
| 76 | + | ||
| 77 | + $this->output('任务失败:' . $e->getMessage()); | ||
| 78 | + } | ||
| 79 | + } | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + public function getTaskId() | ||
| 83 | + { | ||
| 84 | + $task_id = Redis::rpop('sync_submit_task_zbj'); | ||
| 85 | + if (empty($task_id)) { | ||
| 86 | + $ids = SyncSubmitTaskModel::where('status', 3)->limit(100)->pluck('id'); | ||
| 87 | + foreach ($ids as $id) { | ||
| 88 | + Redis::lpush('sync_submit_task_zbj', $id); | ||
| 89 | + } | ||
| 90 | + $task_id = Redis::rpop('sync_submit_task_zbj'); | ||
| 91 | + } | ||
| 92 | + return $task_id; | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + /** | ||
| 96 | + * 输出处理日志 | ||
| 97 | + */ | ||
| 98 | + public function output($message): bool | ||
| 99 | + { | ||
| 100 | + echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL; | ||
| 101 | + return true; | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + /** | ||
| 105 | + * 备份数据 | ||
| 106 | + * @author zbj | ||
| 107 | + * @date 2024/1/23 | ||
| 108 | + */ | ||
| 109 | + public function backup() | ||
| 110 | + { | ||
| 111 | + DB::beginTransaction(); | ||
| 112 | + try { | ||
| 113 | + $table = (new SyncSubmitTaskModel())->getTable(); | ||
| 114 | + $new_table = $table . '_backup_' . date('Ymd'); | ||
| 115 | + | ||
| 116 | + //重命名当前表 | ||
| 117 | + Schema::rename($table, $new_table); | ||
| 118 | + //克隆表数据 | ||
| 119 | + DB::statement('CREATE TABLE ' . $table . ' LIKE ' . $new_table); | ||
| 120 | + | ||
| 121 | + DB::commit(); | ||
| 122 | + | ||
| 123 | + $this->output('数据备份成功'); | ||
| 124 | + } catch (\Exception $e) { | ||
| 125 | + $this->output('数据备份失败' . $e->getMessage()); | ||
| 126 | + DB::rollBack(); | ||
| 127 | + } | ||
| 128 | + return true; | ||
| 129 | + } | ||
| 130 | +} |
| @@ -10,6 +10,7 @@ use App\Models\Domain\DomainInfo; | @@ -10,6 +10,7 @@ use App\Models\Domain\DomainInfo; | ||
| 10 | use App\Models\Mail\Mail; | 10 | use App\Models\Mail\Mail; |
| 11 | use App\Models\Project\DeployBuild; | 11 | use App\Models\Project\DeployBuild; |
| 12 | use App\Models\Project\DeployOptimize; | 12 | use App\Models\Project\DeployOptimize; |
| 13 | +use App\Models\Project\ProjectKeyword; | ||
| 13 | use App\Models\Project\ProjectUpdateTdk; | 14 | use App\Models\Project\ProjectUpdateTdk; |
| 14 | use App\Models\User\User; | 15 | use App\Models\User\User; |
| 15 | use App\Models\WebSetting\WebLanguage; | 16 | use App\Models\WebSetting\WebLanguage; |
| @@ -199,7 +200,7 @@ class UpdateSeoTdk extends Command | @@ -199,7 +200,7 @@ class UpdateSeoTdk extends Command | ||
| 199 | if($table == 'gl_product'){ | 200 | if($table == 'gl_product'){ |
| 200 | foreach ($map as $field){ | 201 | foreach ($map as $field){ |
| 201 | $field_arr = explode('.', $field); | 202 | $field_arr = explode('.', $field); |
| 202 | - $query->orWhereRaw('JSON_EXTRACT('.$field_arr[0].', "$.'.$field_arr[1].'") IS NULL OR JSON_EXTRACT('.$field_arr[0].', "$.'.$field_arr[1].'") = ""'); | 203 | + $query->orWhereRaw('JSON_CONTAINS('.$field_arr[0].', "null", "$.'.$field_arr[1].'") OR JSON_EXTRACT('.$field_arr[0].', "$.'.$field_arr[1].'") = ""'); |
| 203 | } | 204 | } |
| 204 | }else{ | 205 | }else{ |
| 205 | foreach ($map as $field){ | 206 | foreach ($map as $field){ |
| @@ -375,7 +376,13 @@ class UpdateSeoTdk extends Command | @@ -375,7 +376,13 @@ class UpdateSeoTdk extends Command | ||
| 375 | $info = Cache::get($cache_key); | 376 | $info = Cache::get($cache_key); |
| 376 | if(!$info){ | 377 | if(!$info){ |
| 377 | $projectOptimizeModel = new DeployOptimize(); | 378 | $projectOptimizeModel = new DeployOptimize(); |
| 378 | - $info = $projectOptimizeModel->read(['project_id' => $project_id], ['id', 'company_en_name', 'company_en_description', 'main_keywords']); | 379 | + $info = $projectOptimizeModel->read(['project_id' => $project_id], ['id', 'company_en_name', 'company_en_description']); |
| 380 | + $projectKeywordModel = new ProjectKeyword(); | ||
| 381 | + $keywordInfo = $projectKeywordModel->read(['project_id'=>$project_id]); | ||
| 382 | + $info['main_keyword'] = ''; | ||
| 383 | + if($keywordInfo === false){ | ||
| 384 | + $info['main_keyword'] = $keywordInfo['main_keyword']; | ||
| 385 | + } | ||
| 379 | Cache::put($cache_key, $info, 600); | 386 | Cache::put($cache_key, $info, 600); |
| 380 | } | 387 | } |
| 381 | return $info; | 388 | return $info; |
| @@ -412,12 +419,12 @@ class UpdateSeoTdk extends Command | @@ -412,12 +419,12 @@ class UpdateSeoTdk extends Command | ||
| 412 | { | 419 | { |
| 413 | $str = ''; | 420 | $str = ''; |
| 414 | $info = $this->getDeployOptimize($project_id); | 421 | $info = $this->getDeployOptimize($project_id); |
| 415 | - if (!empty($info['main_keywords'])) { | ||
| 416 | - $main_keywords = explode("\r\n", $info['main_keywords']); | 422 | + if (!empty($info['main_keyword'])) { |
| 423 | + $main_keyword = explode("\r\n", $info['main_keyword']); | ||
| 417 | //随机取 | 424 | //随机取 |
| 418 | - shuffle($main_keywords); | ||
| 419 | - $main_keywords = array_slice($main_keywords, 0, $num); | ||
| 420 | - $str = implode(", ", $main_keywords); | 425 | + shuffle($main_keyword); |
| 426 | + $main_keyword = array_slice($main_keyword, 0, $num); | ||
| 427 | + $str = implode(", ", $main_keyword); | ||
| 421 | } | 428 | } |
| 422 | return $str; | 429 | return $str; |
| 423 | } | 430 | } |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Console\Commands\Tdk; | ||
| 4 | + | ||
| 5 | +use App\Helper\Arr; | ||
| 6 | +use App\Helper\Common; | ||
| 7 | +use App\Helper\Gpt; | ||
| 8 | +use App\Models\Ai\AiCommand; | ||
| 9 | +use App\Models\Domain\DomainInfo; | ||
| 10 | +use App\Models\Mail\Mail; | ||
| 11 | +use App\Models\Project\DeployBuild; | ||
| 12 | +use App\Models\Project\DeployOptimize; | ||
| 13 | +use App\Models\Project\ProjectKeyword; | ||
| 14 | +use App\Models\Project\ProjectUpdateTdk; | ||
| 15 | +use App\Models\User\User; | ||
| 16 | +use App\Models\WebSetting\WebLanguage; | ||
| 17 | +use App\Services\ProjectServer; | ||
| 18 | +use Illuminate\Console\Command; | ||
| 19 | +use Illuminate\Support\Facades\Cache; | ||
| 20 | +use Illuminate\Support\Facades\DB; | ||
| 21 | +use Illuminate\Support\Facades\Redis; | ||
| 22 | +use Illuminate\Support\Str; | ||
| 23 | + | ||
| 24 | +/** | ||
| 25 | + * 指定跑某个项目 | ||
| 26 | + * Class InitProject | ||
| 27 | + * @package App\Console\Commands | ||
| 28 | + * @author zbj | ||
| 29 | + * @date 2023/10/8 | ||
| 30 | + */ | ||
| 31 | +class UpdateSeoTdkByTaskId extends Command | ||
| 32 | +{ | ||
| 33 | + /** | ||
| 34 | + * The name and signature of the console command. | ||
| 35 | + * | ||
| 36 | + * @var string | ||
| 37 | + */ | ||
| 38 | + protected $signature = 'update_seo_tdk_by {task_id}'; | ||
| 39 | + | ||
| 40 | + /** | ||
| 41 | + * The console command description. | ||
| 42 | + * | ||
| 43 | + * @var string | ||
| 44 | + */ | ||
| 45 | + protected $description = '一键生成tdk'; | ||
| 46 | + | ||
| 47 | + protected $project; | ||
| 48 | + | ||
| 49 | + /** | ||
| 50 | + * Create a new command instance. | ||
| 51 | + * | ||
| 52 | + * @return void | ||
| 53 | + */ | ||
| 54 | + public function __construct() | ||
| 55 | + { | ||
| 56 | + parent::__construct(); | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + /** | ||
| 60 | + * '表' => [ | ||
| 61 | + * '指令key' => '表字段' | ||
| 62 | + * ] | ||
| 63 | + * @return array | ||
| 64 | + * @author zbj | ||
| 65 | + * @date 2023/11/3 | ||
| 66 | + */ | ||
| 67 | + protected $maps = [ | ||
| 68 | + 'gl_web_custom_template' => [ | ||
| 69 | + 'page_title' => 'title', | ||
| 70 | + 'page_meta_keywords' => 'keywords', | ||
| 71 | + 'page_meta_description' => 'description', | ||
| 72 | + ], | ||
| 73 | + 'gl_product' => [ | ||
| 74 | + 'product_title' => 'seo_mate.title', | ||
| 75 | + 'product_meta_keywords' => 'seo_mate.keyword', | ||
| 76 | + 'product_meta_description' => 'seo_mate.description', | ||
| 77 | + ], | ||
| 78 | + 'gl_product_category' => [ | ||
| 79 | + 'product_cat_title' => 'seo_title', | ||
| 80 | + 'product_cat_meta_keywords' => 'seo_keywords', | ||
| 81 | + 'product_cat_meta_description' => 'seo_des', | ||
| 82 | + ], | ||
| 83 | + 'gl_blog' => [ | ||
| 84 | + 'blog_title' => 'seo_title', | ||
| 85 | + 'blog_meta_keywords' => 'seo_keywords', | ||
| 86 | + 'blog_meta_description' => 'seo_description', | ||
| 87 | + ], | ||
| 88 | + 'gl_blog_category' => [ | ||
| 89 | + 'blog_cat_title' => 'seo_title', | ||
| 90 | + 'blog_cat_meta_keywords' => 'seo_keywords', | ||
| 91 | + 'blog_cat_meta_description' => 'seo_des', | ||
| 92 | + ], | ||
| 93 | + 'gl_news' => [ | ||
| 94 | + 'news_title' => 'seo_title', | ||
| 95 | + 'news_meta_keywords' => 'seo_keywords', | ||
| 96 | + 'news_meta_description' => 'seo_description', | ||
| 97 | + ], | ||
| 98 | + 'gl_news_category' => [ | ||
| 99 | + 'news_cat_title' => 'seo_title', | ||
| 100 | + 'news_cat_meta_keywords' => 'seo_keywords', | ||
| 101 | + 'news_cat_meta_description' => 'seo_des', | ||
| 102 | + ], | ||
| 103 | + 'gl_product_keyword' => [ | ||
| 104 | + 'tags_title' => 'seo_title', | ||
| 105 | + 'tags_meta_keywords' => 'seo_keywords', | ||
| 106 | + 'tags_meta_description' => 'seo_description', | ||
| 107 | + 'tags_content_title' => 'keyword_title', | ||
| 108 | + 'tags_content_description' => 'keyword_content', | ||
| 109 | + ] | ||
| 110 | + ]; | ||
| 111 | + | ||
| 112 | + /** | ||
| 113 | + * topic-对相应字段 | ||
| 114 | + * @var array | ||
| 115 | + */ | ||
| 116 | + protected $topic_fields = [ | ||
| 117 | + 'gl_web_custom_template' => 'name', | ||
| 118 | + 'gl_product' => 'title', | ||
| 119 | + 'gl_product_category' => 'title', | ||
| 120 | + 'gl_blog' => 'name', | ||
| 121 | + 'gl_blog_category' => 'name', | ||
| 122 | + 'gl_news' => 'name', | ||
| 123 | + 'gl_news_category' => 'name', | ||
| 124 | + 'gl_product_keyword' => 'title' | ||
| 125 | + ]; | ||
| 126 | + | ||
| 127 | + /** | ||
| 128 | + * 使用核心关键词的key 数量 | ||
| 129 | + * @var array | ||
| 130 | + */ | ||
| 131 | + protected $core_keyword_keys = [ | ||
| 132 | + 'page_meta_keywords' => 1, | ||
| 133 | + 'blog_cat_meta_keywords' => 8, | ||
| 134 | + 'news_cat_meta_keywords' => 8, | ||
| 135 | + ]; | ||
| 136 | + | ||
| 137 | + /** | ||
| 138 | + * @return bool | ||
| 139 | + */ | ||
| 140 | + public function handle() | ||
| 141 | + { | ||
| 142 | + $task_id = $this->argument('task_id'); | ||
| 143 | + $task = ProjectUpdateTdk::where('status', ProjectUpdateTdk::STATUS_PENDING)->where('id', $task_id)->first(); | ||
| 144 | + if (!$task) { | ||
| 145 | + echo date('Y-m-d H:i:s') . ' 任务不存在: ' . $task_id . PHP_EOL; | ||
| 146 | + } | ||
| 147 | + $project_id = $task->project_id; | ||
| 148 | + | ||
| 149 | + echo date('Y-m-d H:i:s') . ' start project_id: ' . $project_id . PHP_EOL; | ||
| 150 | + try { | ||
| 151 | + $this->project = ProjectServer::useProject($project_id); | ||
| 152 | + $this->seo_tdk($project_id, $task->id); | ||
| 153 | + DB::disconnect('custom_mysql'); | ||
| 154 | + }catch (\Exception $e){ | ||
| 155 | + echo date('Y-m-d H:i:s') . 'line: '. $e->getLine() .' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL; | ||
| 156 | + ProjectUpdateTdk::retry($task->id, $e->getMessage()); | ||
| 157 | + } | ||
| 158 | + Cache::forget('project_deploy_optimize_info_' . $project_id); | ||
| 159 | + echo date('Y-m-d H:i:s') . ' end project_id: ' . $project_id . PHP_EOL; | ||
| 160 | + } | ||
| 161 | + public function sendNotify($project_id, $route) | ||
| 162 | + { | ||
| 163 | + //获取当前项目的域名 | ||
| 164 | + $domainModel = new DomainInfo(); | ||
| 165 | + $domainInfo = $domainModel->read(['project_id'=>$project_id]); | ||
| 166 | + if($domainInfo === false){ | ||
| 167 | + //获取测试域名 | ||
| 168 | + $deployBuildModel = new DeployBuild(); | ||
| 169 | + $buildInfo = $deployBuildModel->read(['project_id'=>$project_id]); | ||
| 170 | + $this->param['domain'] = $buildInfo['test_domain']; | ||
| 171 | + }else{ | ||
| 172 | + $this->param['domain'] = 'https://'.$domainInfo['domain'].'/'; | ||
| 173 | + } | ||
| 174 | + $url = $this->param['domain'].'api/update_page/'; | ||
| 175 | + $param = [ | ||
| 176 | + 'project_id' => $project_id, | ||
| 177 | + 'type' => 1, | ||
| 178 | + 'route' => $route, | ||
| 179 | + 'url' => [], | ||
| 180 | + 'language'=> [], | ||
| 181 | + ]; | ||
| 182 | + http_post($url, json_encode($param)); | ||
| 183 | + echo '更新中请稍后, 更新完成将会发送站内信通知更新结果!'. PHP_EOL; | ||
| 184 | + } | ||
| 185 | + public function seo_tdk($project_id, $task_id) | ||
| 186 | + { | ||
| 187 | + $notify_master = $notify_keyword = false; | ||
| 188 | + //更新统计 | ||
| 189 | + $update = []; | ||
| 190 | + $ai_commands = AiCommand::where('is_batch', 1)->select('key', 'scene', 'ai')->get()->toArray(); | ||
| 191 | + $ai_commands = Arr::setValueToKey($ai_commands, 'key'); | ||
| 192 | + foreach ($this->maps as $table => $map) { | ||
| 193 | + $total_page = DB::connection('custom_mysql')->table($table)->count(); | ||
| 194 | + $update[$table] = ['total_page'=>$total_page, 'title'=>0, 'keyword'=>0, 'des'=>0,'keyword_title'=>0,'keyword_content'=>0]; | ||
| 195 | + echo date('Y-m-d H:i:s') . '更新--' . $table . ': 项目id' . $project_id . PHP_EOL; | ||
| 196 | + $list = DB::connection('custom_mysql')->table($table) | ||
| 197 | + ->where(function ($query) use ($table, $map){ | ||
| 198 | + if($table == 'gl_product'){ | ||
| 199 | + foreach ($map as $field){ | ||
| 200 | + $field_arr = explode('.', $field); | ||
| 201 | + $query->orWhereRaw('JSON_CONTAINS('.$field_arr[0].', "null", "$.'.$field_arr[1].'") OR JSON_EXTRACT('.$field_arr[0].', "$.'.$field_arr[1].'") = ""'); | ||
| 202 | + } | ||
| 203 | + }else{ | ||
| 204 | + foreach ($map as $field){ | ||
| 205 | + $query->orWhereRaw($field . " IS NULL OR ".$field." = ''"); | ||
| 206 | + } | ||
| 207 | + } | ||
| 208 | + })->select('id')->get(); | ||
| 209 | + if (!empty($list)) { | ||
| 210 | + $list = $list->toArray(); | ||
| 211 | + foreach ($list as $v) { | ||
| 212 | + $v = (array)$v; | ||
| 213 | + | ||
| 214 | + //缓存 在处理的项目数据 id | ||
| 215 | + $cache_key = "seo_tdk_{$project_id}_{$table}_{$v['id']}"; | ||
| 216 | + if(!Redis::setnx($cache_key, 1)){ | ||
| 217 | + continue; | ||
| 218 | + } | ||
| 219 | + Redis::expire($cache_key, 120); | ||
| 220 | + | ||
| 221 | + echo date('Y-m-d H:i:s') . '更新--' . $table . ': 项目id' . $project_id . ':id' . $v['id'] . PHP_EOL; | ||
| 222 | + $v = DB::connection('custom_mysql')->table($table)->where('id', $v['id'])->first(); | ||
| 223 | + $v = (array)$v; | ||
| 224 | + $data = []; | ||
| 225 | + $json_field = ''; | ||
| 226 | + foreach ($map as $ai_key => $field) { | ||
| 227 | + $field_arr = explode('.', $field); | ||
| 228 | + if (count($field_arr) > 1) { | ||
| 229 | + $json_field = $field_arr[0]; | ||
| 230 | + $value = json_decode($v[$field_arr[0]], true)[$field_arr[1]] ?? ''; | ||
| 231 | + } else { | ||
| 232 | + $value = $v[$field] ?? ''; | ||
| 233 | + } | ||
| 234 | + //已有值的 跳过 | ||
| 235 | + if ($value) { | ||
| 236 | + echo $field.'已有值 跳过' . PHP_EOL; | ||
| 237 | + continue; | ||
| 238 | + } | ||
| 239 | + | ||
| 240 | + //AI生成 | ||
| 241 | + if (!empty($ai_commands[$ai_key]['ai'])) { | ||
| 242 | + $prompt = $this->getPrompt($project_id, $ai_commands[$ai_key]['ai'], $table, $v); | ||
| 243 | + if(!$prompt){ | ||
| 244 | + continue; | ||
| 245 | + } | ||
| 246 | + if (count($field_arr) > 1) { | ||
| 247 | + if($field_arr[1] == 'title'){ | ||
| 248 | + $update[$table]['title']++; | ||
| 249 | + }elseif ($field_arr[1] == 'keyword'){ | ||
| 250 | + $update[$table]['keyword']++; | ||
| 251 | + }elseif ($field_arr[1] == 'description'){ | ||
| 252 | + $update[$table]['des']++; | ||
| 253 | + } | ||
| 254 | + $data[$field_arr[0]][$field_arr[1]] = $this->ai_send($prompt); | ||
| 255 | + }else{ | ||
| 256 | + if($field == 'title' || $field == 'seo_title'){ | ||
| 257 | + $update[$table]['title']++; | ||
| 258 | + } | ||
| 259 | + if($field == 'keywords' || $field == 'seo_keywords'){ | ||
| 260 | + $update[$table]['keyword']++; | ||
| 261 | + } | ||
| 262 | + if($field == 'seo_description' || $field == 'description' || $field == 'seo_des'){ | ||
| 263 | + $update[$table]['des']++; | ||
| 264 | + } | ||
| 265 | + if($field == 'keyword_title'){ | ||
| 266 | + $update[$table]['keyword_title']++; | ||
| 267 | + } | ||
| 268 | + if($field == 'keyword_content'){ | ||
| 269 | + $update[$table]['keyword_content']++; | ||
| 270 | + } | ||
| 271 | + $data[$field] = $this->ai_send($prompt); | ||
| 272 | + } | ||
| 273 | + } else { | ||
| 274 | + //直接使用topic | ||
| 275 | + if (count($field_arr) > 1) { | ||
| 276 | + $data[$field_arr[0]][$field_arr[1]] = $v[$this->topic_fields[$table]] ?? ''; | ||
| 277 | + //使用核心关键词 | ||
| 278 | + if(in_array($ai_key, array_keys($this->core_keyword_keys))){ | ||
| 279 | + $data[$field_arr[0]][$field_arr[1]] = $this->mainKeywords($project_id, $this->core_keyword_keys[$ai_key]); | ||
| 280 | + if(!empty($data[$field_arr[0]][$field_arr[1]])){ | ||
| 281 | + if($field_arr[1] == 'title'){ | ||
| 282 | + $data[$table]['title']++; | ||
| 283 | + }elseif ($field_arr[1] == 'keyword'){ | ||
| 284 | + $data[$table]['keyword']++; | ||
| 285 | + }elseif ($field_arr[1] == 'description'){ | ||
| 286 | + $data[$table]['des']++; | ||
| 287 | + } | ||
| 288 | + } | ||
| 289 | + } | ||
| 290 | + }else{ | ||
| 291 | + $data[$field] = $v[$this->topic_fields[$table]] ?? ''; | ||
| 292 | + //使用核心关键词 | ||
| 293 | + if(in_array($ai_key, array_keys($this->core_keyword_keys))){ | ||
| 294 | + $data[$field] = $this->mainKeywords($project_id, $this->core_keyword_keys[$ai_key]); | ||
| 295 | + if(!empty($data[$field])){ | ||
| 296 | + if($field == 'title' || $field == 'seo_title'){ | ||
| 297 | + $update[$table]['title']++; | ||
| 298 | + } | ||
| 299 | + if($field == 'keywords' || $field == 'seo_keywords'){ | ||
| 300 | + $update[$table]['keyword']++; | ||
| 301 | + } | ||
| 302 | + if($field == 'seo_description' || $field == 'description' || $field == 'seo_des'){ | ||
| 303 | + $update[$table]['des']++; | ||
| 304 | + } | ||
| 305 | + if($field == 'keyword_title'){ | ||
| 306 | + $update[$table]['keyword_title']++; | ||
| 307 | + } | ||
| 308 | + if($field == 'keyword_content'){ | ||
| 309 | + $update[$table]['keyword_content']++; | ||
| 310 | + } | ||
| 311 | + } | ||
| 312 | + } | ||
| 313 | + } | ||
| 314 | + } | ||
| 315 | + } | ||
| 316 | + if(!$data){ | ||
| 317 | + continue; | ||
| 318 | + } | ||
| 319 | + if($json_field){ | ||
| 320 | + $old_data = json_decode($v[$field_arr[0]], true); | ||
| 321 | + foreach ($old_data ?: [] as $kk=>$vv){ | ||
| 322 | + empty($data[$json_field][$kk]) && $data[$json_field][$kk] = $vv; | ||
| 323 | + } | ||
| 324 | + $data[$json_field] = json_encode($data[$json_field]); | ||
| 325 | + } | ||
| 326 | + DB::connection('custom_mysql')->table($table)->where(['id' => $v['id']])->update($data); | ||
| 327 | + if($table == 'gl_product_keyword'){ | ||
| 328 | + $notify_keyword = true; | ||
| 329 | + }else{ | ||
| 330 | + $notify_master = true; | ||
| 331 | + } | ||
| 332 | + } | ||
| 333 | + } | ||
| 334 | + } | ||
| 335 | + ProjectUpdateTdk::finish($task_id, $update); | ||
| 336 | + | ||
| 337 | + //通知C端更新界面 | ||
| 338 | + $notify_master && $this->sendNotify($project_id, 1); //通知主站更新 | ||
| 339 | + $notify_keyword && $this->sendNotify($project_id, 4); //通知聚合页更新 | ||
| 340 | + } | ||
| 341 | + | ||
| 342 | + public function getPrompt($project_id, $prompt, $table, $data){ | ||
| 343 | + if(strpos($prompt, '{topic}') !== false){ | ||
| 344 | + $topic = $data[$this->topic_fields[$table]] ?? ''; | ||
| 345 | + if(!$topic){ | ||
| 346 | + echo 'topic为空 跳过' . PHP_EOL; | ||
| 347 | + return false; | ||
| 348 | + } | ||
| 349 | + $prompt = str_replace('{topic}', $topic, $prompt); | ||
| 350 | + } | ||
| 351 | + if(strpos($prompt, '{keyword}') !== false) { | ||
| 352 | + $keyword = $this->mainKeywords($project_id, 1); | ||
| 353 | + if(!$keyword){ | ||
| 354 | + echo '核心关键词为空 跳过' . PHP_EOL; | ||
| 355 | + return false; | ||
| 356 | + } | ||
| 357 | + $prompt = str_replace('{keyword}', $keyword, $prompt); | ||
| 358 | + } | ||
| 359 | + if(strpos($prompt, '{company name}') !== false) { | ||
| 360 | + $company_name = $this->companyName($project_id); | ||
| 361 | + if(!$company_name){ | ||
| 362 | + echo '公司英文全称为空 跳过' . PHP_EOL; | ||
| 363 | + return false; | ||
| 364 | + } | ||
| 365 | + $prompt = str_replace('{company name}', $company_name, $prompt); | ||
| 366 | + } | ||
| 367 | + $prompt .= '.Please answer in ' . $this->getLang(); | ||
| 368 | + return $prompt; | ||
| 369 | + } | ||
| 370 | + | ||
| 371 | + | ||
| 372 | + public function getDeployOptimize($project_id){ | ||
| 373 | + $cache_key = 'project_deploy_optimize_info_' . $project_id; | ||
| 374 | + $info = Cache::get($cache_key); | ||
| 375 | + if(!$info){ | ||
| 376 | + $projectOptimizeModel = new DeployOptimize(); | ||
| 377 | + $info = $projectOptimizeModel->read(['project_id' => $project_id], ['id', 'company_en_name', 'company_en_description']); | ||
| 378 | + $projectKeywordModel = new ProjectKeyword(); | ||
| 379 | + $keywordInfo = $projectKeywordModel->read(['project_id'=>$project_id]); | ||
| 380 | + $info['main_keyword'] = ''; | ||
| 381 | + if($keywordInfo === false){ | ||
| 382 | + $info['main_keyword'] = $keywordInfo['main_keyword']; | ||
| 383 | + } | ||
| 384 | + Cache::put($cache_key, $info, 600); | ||
| 385 | + } | ||
| 386 | + return $info; | ||
| 387 | + } | ||
| 388 | + | ||
| 389 | + /** | ||
| 390 | + * @remark :获取公司英文名称 | ||
| 391 | + * @name :companyName | ||
| 392 | + * @author :lyh | ||
| 393 | + * @method :post | ||
| 394 | + * @time :2023/10/30 11:22 | ||
| 395 | + */ | ||
| 396 | + public function companyName($project_id, $key = '') | ||
| 397 | + { | ||
| 398 | + $data = [ | ||
| 399 | + 'product_long_description', | ||
| 400 | + ]; | ||
| 401 | + $info = $this->getDeployOptimize($project_id); | ||
| 402 | + if (in_array($key, $data)) { | ||
| 403 | + return $info['company_en_description']; | ||
| 404 | + } else { | ||
| 405 | + return $info['company_en_name']; | ||
| 406 | + } | ||
| 407 | + } | ||
| 408 | + | ||
| 409 | + /** | ||
| 410 | + * @remark :获取公司核心关键词 | ||
| 411 | + * @name :mainKeywords | ||
| 412 | + * @author :lyh | ||
| 413 | + * @method :post | ||
| 414 | + * @time :2023/10/30 11:22 | ||
| 415 | + */ | ||
| 416 | + public function mainKeywords($project_id, $num) | ||
| 417 | + { | ||
| 418 | + $str = ''; | ||
| 419 | + $info = $this->getDeployOptimize($project_id); | ||
| 420 | + if (!empty($info['main_keyword'])) { | ||
| 421 | + $main_keyword = explode("\r\n", $info['main_keyword']); | ||
| 422 | + //随机取 | ||
| 423 | + shuffle($main_keyword); | ||
| 424 | + $main_keyword = array_slice($main_keyword, 0, $num); | ||
| 425 | + $str = implode(", ", $main_keyword); | ||
| 426 | + } | ||
| 427 | + return $str; | ||
| 428 | + } | ||
| 429 | + | ||
| 430 | + public function getLang(){ | ||
| 431 | + $lang = WebLanguage::getLangById($this->project['main_lang_id']??1); | ||
| 432 | + return $lang['english'] ?? 'English'; | ||
| 433 | + } | ||
| 434 | + | ||
| 435 | + /** | ||
| 436 | + * @remark :AI发送 | ||
| 437 | + * @name :ai_send | ||
| 438 | + * @author :lyh | ||
| 439 | + * @method :post | ||
| 440 | + * @time :2023/8/19 10:40 | ||
| 441 | + */ | ||
| 442 | + public function ai_send($prompt) | ||
| 443 | + { | ||
| 444 | + $text = Gpt::instance()->openai_chat_qqs($prompt); | ||
| 445 | + $text = Common::deal_keywords($text); | ||
| 446 | + $text = Common::deal_str($text); | ||
| 447 | + | ||
| 448 | + //包含这写字 重新生成 | ||
| 449 | + if(Str::contains(Str::lower($text), ['[your brand]', '[brand name]'])){ | ||
| 450 | + return $this->ai_send($prompt); | ||
| 451 | + } | ||
| 452 | + | ||
| 453 | + return $text; | ||
| 454 | + } | ||
| 455 | + | ||
| 456 | + /** | ||
| 457 | + * @remark :发送站内信 | ||
| 458 | + * @name :send_message | ||
| 459 | + * @author :lyh | ||
| 460 | + * @method :post | ||
| 461 | + * @time :2023/11/4 10:22 | ||
| 462 | + */ | ||
| 463 | + public function send_message($project_id){ | ||
| 464 | + $user = new User(); | ||
| 465 | + $userInfo = $user->read(['project_id'=>$project_id,'role_id'=>0]); | ||
| 466 | + $data["title"] = "seo更新通知---完成"; | ||
| 467 | + $data["user_list"] = $userInfo['id']; | ||
| 468 | + $data["content"] = "seo更新成功,更新完成时间".date('Y-m-d H:i:s'); | ||
| 469 | + $mail = new Mail(); | ||
| 470 | + return $mail->add($data); | ||
| 471 | + } | ||
| 472 | +} |
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * @remark : | ||
| 4 | + * @name :PopularTemplateLabel.php | ||
| 5 | + * @author :lyh | ||
| 6 | + * @method :post | ||
| 7 | + * @time :2024/6/3 17:00 | ||
| 8 | + */ | ||
| 9 | + | ||
| 10 | +namespace App\Console\Commands\TemplateLabel; | ||
| 11 | + | ||
| 12 | +use App\Models\Template\Template; | ||
| 13 | +use App\Models\Template\TemplateLabel as TemplateLabelModel; | ||
| 14 | +use App\Models\Template\TemplateModule; | ||
| 15 | +use Illuminate\Console\Command; | ||
| 16 | + | ||
| 17 | +class PopularTemplateLabel extends Command | ||
| 18 | +{ | ||
| 19 | + /** | ||
| 20 | + * The name and signature of the console command. | ||
| 21 | + * | ||
| 22 | + * @var string | ||
| 23 | + */ | ||
| 24 | + protected $signature = 'popular_template_label'; | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * The console command description. | ||
| 28 | + * | ||
| 29 | + * @var string | ||
| 30 | + */ | ||
| 31 | + protected $description = '设置热门label'; | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * @remark :执行脚本 | ||
| 35 | + * @name :handle | ||
| 36 | + * @author :lyh | ||
| 37 | + * @method :post | ||
| 38 | + * @time :2024/6/3 17:01 | ||
| 39 | + */ | ||
| 40 | + public function handle(){ | ||
| 41 | + $this->setTemplate(); | ||
| 42 | + $this->setTemplateModule(); | ||
| 43 | + return true; | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + /** | ||
| 47 | + * @remark :公共模块热门模块 | ||
| 48 | + * @name :setTemplate | ||
| 49 | + * @author :lyh | ||
| 50 | + * @method :post | ||
| 51 | + * @time :2024/6/3 15:56 | ||
| 52 | + */ | ||
| 53 | + public function setTemplate(){ | ||
| 54 | + $templateModel = new Template(); | ||
| 55 | + $info = $templateModel->list(['test_model'=>0,'number'=>['<>',0]],'number',['id'],'desc',50); | ||
| 56 | + if(empty($info)){ | ||
| 57 | + return true; | ||
| 58 | + }else{ | ||
| 59 | + //清除当前所有最新标签 | ||
| 60 | + $labelModel = new TemplateLabelModel(); | ||
| 61 | + $labelModel->del(['name'=>'热门','type'=>1]); | ||
| 62 | + $data = []; | ||
| 63 | + foreach ($info as $v){ | ||
| 64 | + $data[] = [ | ||
| 65 | + 'name'=>'热门', | ||
| 66 | + 'type'=>1, | ||
| 67 | + 'template_id'=>$v['id'], | ||
| 68 | + 'manager_id'=>0, | ||
| 69 | + 'created_at'=>date('Y-m-d H:i:s'), | ||
| 70 | + 'updated_at'=>date('Y-m-d H:i:s') | ||
| 71 | + ]; | ||
| 72 | + } | ||
| 73 | + //设置为最新 | ||
| 74 | + $labelModel->insert($data); | ||
| 75 | + } | ||
| 76 | + return true; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + /** | ||
| 80 | + * @remark :左侧模块 | ||
| 81 | + * @name :templateModule | ||
| 82 | + * @author :lyh | ||
| 83 | + * @method :post | ||
| 84 | + * @time :2024/6/3 15:54 | ||
| 85 | + */ | ||
| 86 | + public function setTemplateModule(){ | ||
| 87 | + $templateModuleModel = new TemplateModule(); | ||
| 88 | + $moduleInfo = $templateModuleModel->list(['test_model'=>0,'number'=>['<>',0]],'id',['id']); | ||
| 89 | + if(empty($moduleInfo)){ | ||
| 90 | + return true; | ||
| 91 | + }else{ | ||
| 92 | + //清除当前所有最新标签 | ||
| 93 | + $labelModel = new TemplateLabelModel(); | ||
| 94 | + $labelModel->del(['name'=>'热门','type'=>2]); | ||
| 95 | + $moduleData = []; | ||
| 96 | + foreach ($moduleInfo as $k => $v){ | ||
| 97 | + $moduleData[] = [ | ||
| 98 | + 'name'=>'热门', | ||
| 99 | + 'type'=>2, | ||
| 100 | + 'template_id'=>$v['id'], | ||
| 101 | + 'manager_id'=>0, | ||
| 102 | + 'created_at'=>date('Y-m-d H:i:s'), | ||
| 103 | + 'updated_at'=>date('Y-m-d H:i:s') | ||
| 104 | + ]; | ||
| 105 | + } | ||
| 106 | + //设置为最新 | ||
| 107 | + $labelModel->insert($moduleData); | ||
| 108 | + } | ||
| 109 | + return true; | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | +} |
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * @remark : | ||
| 4 | + * @name :TemplateLabel.php | ||
| 5 | + * @author :lyh | ||
| 6 | + * @method :post | ||
| 7 | + * @time :2024/6/3 11:33 | ||
| 8 | + */ | ||
| 9 | + | ||
| 10 | +namespace App\Console\Commands\TemplateLabel; | ||
| 11 | + | ||
| 12 | +use App\Models\Template\Template; | ||
| 13 | +use App\Models\Template\TemplateModule; | ||
| 14 | +use Illuminate\Console\Command; | ||
| 15 | +use App\Models\Template\TemplateLabel as TemplateLabelModel; | ||
| 16 | + | ||
| 17 | +class TemplateLabel extends Command | ||
| 18 | +{ | ||
| 19 | + /** | ||
| 20 | + * The name and signature of the console command. | ||
| 21 | + * | ||
| 22 | + * @var string | ||
| 23 | + */ | ||
| 24 | + protected $signature = 'template_label'; | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * The console command description. | ||
| 28 | + * | ||
| 29 | + * @var string | ||
| 30 | + */ | ||
| 31 | + protected $description = '设置label'; | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * @remark :执行脚本 | ||
| 35 | + * @name :handle | ||
| 36 | + * @author :lyh | ||
| 37 | + * @method :post | ||
| 38 | + * @time :2024/6/3 11:35 | ||
| 39 | + */ | ||
| 40 | + public function handle(){ | ||
| 41 | + //获取最近7天模版的记录 | ||
| 42 | + $start_time = now()->subDays(90)->startOfDay()->toDateString(); | ||
| 43 | + $end_time = now()->startOfDay()->toDateString(); | ||
| 44 | + $this->setTemplateModule($start_time,$end_time); | ||
| 45 | + $this->setTemplate($start_time,$end_time); | ||
| 46 | + return true; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + /** | ||
| 50 | + * @remark :公共模块 | ||
| 51 | + * @name :setTemplate | ||
| 52 | + * @author :lyh | ||
| 53 | + * @method :post | ||
| 54 | + * @time :2024/6/3 15:56 | ||
| 55 | + */ | ||
| 56 | + public function setTemplate($start_time,$end_time){ | ||
| 57 | + $templateModel = new Template(); | ||
| 58 | + $info = $templateModel->list(['created_at'=>['between',[$start_time,$end_time]],'test_model'=>0],'id',['id']); | ||
| 59 | + if(empty($info)){ | ||
| 60 | + return true; | ||
| 61 | + }else{ | ||
| 62 | + //清除当前所有最新标签 | ||
| 63 | + $labelModel = new TemplateLabelModel(); | ||
| 64 | + $labelModel->del(['name'=>'最新','type'=>1]); | ||
| 65 | + $data = []; | ||
| 66 | + foreach ($info as $k => $v){ | ||
| 67 | + $data[] = [ | ||
| 68 | + 'name'=>'最新', | ||
| 69 | + 'type'=>1, | ||
| 70 | + 'template_id'=>$v['id'], | ||
| 71 | + 'manager_id'=>0, | ||
| 72 | + 'created_at'=>date('Y-m-d H:i:s'), | ||
| 73 | + 'updated_at'=>date('Y-m-d H:i:s') | ||
| 74 | + ]; | ||
| 75 | + } | ||
| 76 | + //设置为最新 | ||
| 77 | + $labelModel->insert($data); | ||
| 78 | + } | ||
| 79 | + return true; | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + /** | ||
| 83 | + * @remark :左侧模块 | ||
| 84 | + * @name :templateModule | ||
| 85 | + * @author :lyh | ||
| 86 | + * @method :post | ||
| 87 | + * @time :2024/6/3 15:54 | ||
| 88 | + */ | ||
| 89 | + public function setTemplateModule($start_time,$end_time){ | ||
| 90 | + $templateModuleModel = new TemplateModule(); | ||
| 91 | + $moduleInfo = $templateModuleModel->list(['created_at'=>['between',[$start_time,$end_time]],'test_model'=>0],'id',['id']); | ||
| 92 | + if(empty($moduleInfo)){ | ||
| 93 | + return true; | ||
| 94 | + }else{ | ||
| 95 | + //清除当前所有最新标签 | ||
| 96 | + $labelModel = new TemplateLabelModel(); | ||
| 97 | + $labelModel->del(['name'=>'最新','type'=>2]); | ||
| 98 | + $moduleData = []; | ||
| 99 | + foreach ($moduleInfo as $k => $v){ | ||
| 100 | + $moduleData[] = [ | ||
| 101 | + 'name'=>'最新', | ||
| 102 | + 'type'=>2, | ||
| 103 | + 'template_id'=>$v['id'], | ||
| 104 | + 'manager_id'=>0, | ||
| 105 | + 'created_at'=>date('Y-m-d H:i:s'), | ||
| 106 | + 'updated_at'=>date('Y-m-d H:i:s') | ||
| 107 | + ]; | ||
| 108 | + } | ||
| 109 | + //设置为最新 | ||
| 110 | + $labelModel->insert($moduleData); | ||
| 111 | + } | ||
| 112 | + return true; | ||
| 113 | + } | ||
| 114 | +} |
| @@ -7,39 +7,29 @@ | @@ -7,39 +7,29 @@ | ||
| 7 | */ | 7 | */ |
| 8 | namespace App\Console\Commands\Test; | 8 | namespace App\Console\Commands\Test; |
| 9 | 9 | ||
| 10 | -use App\Helper\Common; | ||
| 11 | -use App\Models\Blog\Blog; | 10 | + |
| 11 | +use App\Models\Com\KeywordVideoTask; | ||
| 12 | +use App\Models\Com\KeywordVideoTaskLog; | ||
| 12 | use App\Models\Devops\ServerConfig; | 13 | use App\Models\Devops\ServerConfig; |
| 13 | -use App\Models\Domain\DomainInfo; | 14 | +use App\Models\Devops\Servers; |
| 15 | +use App\Models\Devops\ServersIp; | ||
| 14 | use App\Models\File\File; | 16 | use App\Models\File\File; |
| 15 | use App\Models\File\File as FileModel; | 17 | use App\Models\File\File as FileModel; |
| 16 | use App\Models\File\Image; | 18 | use App\Models\File\Image; |
| 17 | use App\Models\File\Image as ImageModel; | 19 | use App\Models\File\Image as ImageModel; |
| 18 | -use App\Models\Manage\BelongingGroup; | ||
| 19 | -use App\Models\Manage\Dept; | ||
| 20 | -use App\Models\Manage\EntryPosition; | ||
| 21 | -use App\Models\Manage\ManageHr; | ||
| 22 | -use App\Models\Nav\BNav; | ||
| 23 | -use App\Models\Nav\BNavGroup; | ||
| 24 | use App\Models\Product\Keyword; | 20 | use App\Models\Product\Keyword; |
| 25 | use App\Models\Product\Product; | 21 | use App\Models\Product\Product; |
| 26 | use App\Models\Project\DeployOptimize; | 22 | use App\Models\Project\DeployOptimize; |
| 27 | use App\Models\Project\MinorLanguages; | 23 | use App\Models\Project\MinorLanguages; |
| 28 | use App\Models\Project\Project; | 24 | use App\Models\Project\Project; |
| 29 | -use App\Models\RouteMap\RouteMap; | ||
| 30 | -use App\Models\Template\BCustomTemplate; | ||
| 31 | -use App\Models\Template\BTemplate; | ||
| 32 | -use App\Models\Template\BTemplateCom; | ||
| 33 | -use App\Models\Template\BTemplateCommon; | ||
| 34 | -use App\Models\Template\Setting; | ||
| 35 | -use App\Models\WebSetting\WebSettingService; | 25 | +use App\Models\Purchaser\PurchaserInfo; |
| 36 | use App\Services\AmazonS3Service; | 26 | use App\Services\AmazonS3Service; |
| 37 | use App\Services\ProjectServer; | 27 | use App\Services\ProjectServer; |
| 38 | -use App\Services\SyncService; | ||
| 39 | -use GuzzleHttp\Client; | 28 | +use App\Utils\EncryptUtils; |
| 40 | use Illuminate\Console\Command; | 29 | use Illuminate\Console\Command; |
| 41 | use Illuminate\Support\Facades\DB; | 30 | use Illuminate\Support\Facades\DB; |
| 42 | -use Illuminate\Support\Facades\Log; | 31 | +use Illuminate\Support\Facades\Schema; |
| 32 | + | ||
| 43 | 33 | ||
| 44 | class Demo extends Command | 34 | class Demo extends Command |
| 45 | { | 35 | { |
| @@ -56,84 +46,16 @@ class Demo extends Command | @@ -56,84 +46,16 @@ class Demo extends Command | ||
| 56 | * @var string | 46 | * @var string |
| 57 | */ | 47 | */ |
| 58 | protected $description = 'demo'; | 48 | protected $description = 'demo'; |
| 59 | - /** | ||
| 60 | - * Execute the job. | ||
| 61 | - * | ||
| 62 | - * @return void | ||
| 63 | - */ | ||
| 64 | - public function handle() | ||
| 65 | - { | ||
| 66 | - $projectModel = new Project(); | ||
| 67 | - $list = $projectModel->list(['delete_status'=>0,'type'=>['!=',0]]); | ||
| 68 | - $data = []; | ||
| 69 | - foreach ($list as $v){ | ||
| 70 | - echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL; | ||
| 71 | - ProjectServer::useProject($v['id']); | ||
| 72 | - DB::table('gl_web_template_com')->truncate(); | ||
| 73 | - $templateComModel = new BTemplateCom(); | ||
| 74 | - $templateComModel->truncate(); | ||
| 75 | - $this->saveTemplateCom($v['id']); | ||
| 76 | - DB::disconnect('custom_mysql'); | ||
| 77 | - } | ||
| 78 | - echo date('Y-m-d H:i:s') . 'end' . PHP_EOL; | 49 | + |
| 50 | + public function handle(){ | ||
| 51 | + $this->synchronizationFile('/upload/m/file/2024-07/tongli-haiyuan-keywords.pdf'); | ||
| 79 | } | 52 | } |
| 80 | 53 | ||
| 81 | - public function saveTemplateCom($project_id){ | ||
| 82 | - //获取当前项目选择的模版 | ||
| 83 | - $settingModel = new Setting(); | ||
| 84 | - $settingInfo = $settingModel->read(['project_id'=>$project_id]); | ||
| 85 | - echo date('Y-m-d H:i:s') . '设置的模版:'.json_encode($settingInfo) . PHP_EOL; | ||
| 86 | - if($settingInfo !== false){ | ||
| 87 | - $templateCommonModel = new BTemplateCommon(); | ||
| 88 | - $commonList = $templateCommonModel->list(['template_id'=>['in',[$settingInfo['template_id'],0]]]); | ||
| 89 | - if(!empty($commonList)){ | ||
| 90 | - foreach ($commonList as $v){ | ||
| 91 | - $typeArr = [1, 2, 3]; | ||
| 92 | - foreach ($typeArr as $type){ | ||
| 93 | - if($type == 1){ | ||
| 94 | - $headData = [ | ||
| 95 | - 'project_id'=>$v['project_id'], | ||
| 96 | - 'source'=>$v['type'] == 1 ? 99 : $v['type'], | ||
| 97 | - 'common_type'=>1, | ||
| 98 | - 'template_id'=>$v['template_id'], | ||
| 99 | - 'html'=>$v['head_html'], | ||
| 100 | - 'html_style'=>$v['head_css'], | ||
| 101 | - 'is_custom'=>$v['is_custom'], | ||
| 102 | - 'is_list'=>$v['is_list'] | ||
| 103 | - ]; | ||
| 104 | - $templateComModel = new BTemplateCom(); | ||
| 105 | - $templateComModel->add($headData); | ||
| 106 | - }elseif ($type == 2){ | ||
| 107 | - $footerData = [ | ||
| 108 | - 'project_id'=>$v['project_id'], | ||
| 109 | - 'source'=>$v['type'] == 1 ? 99 : $v['type'], | ||
| 110 | - 'common_type'=>2, | ||
| 111 | - 'template_id'=>$v['template_id'], | ||
| 112 | - 'html'=>$v['footer_html'], | ||
| 113 | - 'html_style'=>$v['footer_css'], | ||
| 114 | - 'is_custom'=>$v['is_custom'], | ||
| 115 | - 'is_list'=>$v['is_list'] | ||
| 116 | - ]; | ||
| 117 | - $templateComModel = new BTemplateCom(); | ||
| 118 | - $templateComModel->add($footerData); | ||
| 119 | - }elseif ($type == 3){ | ||
| 120 | - $otherData = [ | ||
| 121 | - 'project_id'=>$v['project_id'], | ||
| 122 | - 'source'=>$v['type'] == 1 ? 99 : $v['type'], | ||
| 123 | - 'common_type'=>3, | ||
| 124 | - 'template_id'=>$v['template_id'], | ||
| 125 | - 'html'=>$v['other'], | ||
| 126 | - 'html_style'=>null, | ||
| 127 | - 'is_custom'=>$v['is_custom'], | ||
| 128 | - 'is_list'=>$v['is_list'] | ||
| 129 | - ]; | ||
| 130 | - $templateComModel = new BTemplateCom(); | ||
| 131 | - $templateComModel->add($otherData); | ||
| 132 | - } | ||
| 133 | - } | ||
| 134 | - } | ||
| 135 | - } | ||
| 136 | - } | ||
| 137 | - return true; | 54 | + public function synchronizationFile($path_name){ |
| 55 | + //同步到大文件 | ||
| 56 | + $file_path = config('filesystems.disks.cos')['cdn1'].$path_name; | ||
| 57 | + $directoryPath = pathinfo($path_name, PATHINFO_DIRNAME); | ||
| 58 | + $cmd = 'curl -F "file_path='.$file_path.'" -F "save_path=/www/wwwroot/cos'.$directoryPath.'" https://v6-file.globalso.com/upload.php'; | ||
| 59 | + return shell_exec($cmd); | ||
| 138 | } | 60 | } |
| 139 | } | 61 | } |
app/Console/Commands/Test/HeaderFooter.php
0 → 100644
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * @remark : | ||
| 4 | + * @name :HeaderFooter.php | ||
| 5 | + * @author :lyh | ||
| 6 | + * @method :post | ||
| 7 | + * @time :2024/5/21 9:42 | ||
| 8 | + */ | ||
| 9 | + | ||
| 10 | +namespace App\Console\Commands\Test; | ||
| 11 | + | ||
| 12 | +use App\Models\Template\BTemplateCom; | ||
| 13 | +use App\Models\Template\BTemplateCommon; | ||
| 14 | +use App\Models\Template\Setting; | ||
| 15 | +use Illuminate\Console\Command; | ||
| 16 | + | ||
| 17 | +/** | ||
| 18 | + * @remark :头部底部分开 脚本数据 | ||
| 19 | + * @name :HeaderFooter | ||
| 20 | + * @author :lyh | ||
| 21 | + * @method :post | ||
| 22 | + * @time :2024/5/21 9:42 | ||
| 23 | + */ | ||
| 24 | +class HeaderFooter extends Command | ||
| 25 | +{ | ||
| 26 | + /** | ||
| 27 | + * The name and signature of the console command. | ||
| 28 | + * | ||
| 29 | + * @var string | ||
| 30 | + */ | ||
| 31 | + protected $signature = 'common_header'; | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * The console command description. | ||
| 35 | + * | ||
| 36 | + * @var string | ||
| 37 | + */ | ||
| 38 | + protected $description = 'common_header'; | ||
| 39 | + /** | ||
| 40 | + * Execute the job. | ||
| 41 | + * | ||
| 42 | + * @return void | ||
| 43 | + */ | ||
| 44 | + public function handle() | ||
| 45 | + { | ||
| 46 | + $projectModel = new Project(); | ||
| 47 | + $list = $projectModel->list(['delete_status'=>0,'type'=>['!=',0]]); | ||
| 48 | + $data = []; | ||
| 49 | + foreach ($list as $v){ | ||
| 50 | + echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL; | ||
| 51 | + ProjectServer::useProject($v['id']); | ||
| 52 | + DB::table('gl_web_template_com')->truncate(); | ||
| 53 | + $this->saveTemplateCom($v['id']); | ||
| 54 | + DB::disconnect('custom_mysql'); | ||
| 55 | + } | ||
| 56 | + echo date('Y-m-d H:i:s') . 'end' . PHP_EOL; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + /** | ||
| 60 | + * @remark :头部底部分开脚本 | ||
| 61 | + * @name :saveTemplateCom | ||
| 62 | + * @author :lyh | ||
| 63 | + * @method :post | ||
| 64 | + * @time :2024/6/17 14:46 | ||
| 65 | + */ | ||
| 66 | + public function saveTemplateCom($project_id){ | ||
| 67 | + //获取当前项目选择的模版 | ||
| 68 | + $settingModel = new Setting(); | ||
| 69 | + $settingInfo = $settingModel->read(['project_id'=>$project_id]); | ||
| 70 | + echo date('Y-m-d H:i:s') . '设置的模版:'.json_encode($settingInfo) . PHP_EOL; | ||
| 71 | + if($settingInfo !== false){ | ||
| 72 | + $templateCommonModel = new BTemplateCommon(); | ||
| 73 | + $commonList = $templateCommonModel->list(['template_id'=>['in',[$settingInfo['template_id'],0]]]); | ||
| 74 | + if(!empty($commonList)){ | ||
| 75 | + foreach ($commonList as $v){ | ||
| 76 | + $typeArr = [1, 2, 3]; | ||
| 77 | + foreach ($typeArr as $type){ | ||
| 78 | + if($type == 1){ | ||
| 79 | + $headData = [ | ||
| 80 | + 'project_id'=>$v['project_id'], | ||
| 81 | + 'source'=>$v['type'] == 1 ? 99 : $v['type'], | ||
| 82 | + 'common_type'=>1, | ||
| 83 | + 'template_id'=>$v['template_id'], | ||
| 84 | + 'html'=>$v['head_html'], | ||
| 85 | + 'html_style'=>$v['head_css'], | ||
| 86 | + 'is_custom'=>$v['is_custom'], | ||
| 87 | + 'is_list'=>$v['is_list'] | ||
| 88 | + ]; | ||
| 89 | + $templateComModel = new BTemplateCom(); | ||
| 90 | + $templateComModel->add($headData); | ||
| 91 | + }elseif ($type == 2){ | ||
| 92 | + $footerData = [ | ||
| 93 | + 'project_id'=>$v['project_id'], | ||
| 94 | + 'source'=>$v['type'] == 1 ? 99 : $v['type'], | ||
| 95 | + 'common_type'=>2, | ||
| 96 | + 'template_id'=>$v['template_id'], | ||
| 97 | + 'html'=>$v['footer_html'], | ||
| 98 | + 'html_style'=>$v['footer_css'], | ||
| 99 | + 'is_custom'=>$v['is_custom'], | ||
| 100 | + 'is_list'=>$v['is_list'] | ||
| 101 | + ]; | ||
| 102 | + $templateComModel = new BTemplateCom(); | ||
| 103 | + $templateComModel->add($footerData); | ||
| 104 | + }elseif ($type == 3){ | ||
| 105 | + $otherData = [ | ||
| 106 | + 'project_id'=>$v['project_id'], | ||
| 107 | + 'source'=>$v['type'] == 1 ? 99 : $v['type'], | ||
| 108 | + 'common_type'=>3, | ||
| 109 | + 'template_id'=>$v['template_id'], | ||
| 110 | + 'html'=>$v['other'], | ||
| 111 | + 'html_style'=>null, | ||
| 112 | + 'is_custom'=>$v['is_custom'], | ||
| 113 | + 'is_list'=>$v['is_list'] | ||
| 114 | + ]; | ||
| 115 | + $templateComModel = new BTemplateCom(); | ||
| 116 | + $templateComModel->add($otherData); | ||
| 117 | + } | ||
| 118 | + } | ||
| 119 | + } | ||
| 120 | + } | ||
| 121 | + } | ||
| 122 | + return true; | ||
| 123 | + } | ||
| 124 | +} |
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * @remark : | ||
| 4 | + * @name :ProductFileUpload.php | ||
| 5 | + * @author :lyh | ||
| 6 | + * @method :post | ||
| 7 | + * @time :2024/6/18 15:43 | ||
| 8 | + */ | ||
| 9 | + | ||
| 10 | +namespace App\Console\Commands\Test; | ||
| 11 | + | ||
| 12 | +use App\Models\File\File; | ||
| 13 | +use App\Models\Product\Product; | ||
| 14 | +use App\Services\ProjectServer; | ||
| 15 | +use Illuminate\Console\Command; | ||
| 16 | +use Illuminate\Support\Facades\DB; | ||
| 17 | + | ||
| 18 | +class ProductFileUpload extends Command | ||
| 19 | +{ | ||
| 20 | + /** | ||
| 21 | + * The name and signature of the console command. | ||
| 22 | + * | ||
| 23 | + * @var string | ||
| 24 | + */ | ||
| 25 | + protected $signature = 'files_upload {project_id}'; | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * The console command description. | ||
| 29 | + * | ||
| 30 | + * @var string | ||
| 31 | + */ | ||
| 32 | + protected $description = '重新上传文件获取文件后缀'; | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * @remark : | ||
| 36 | + * @name :handle | ||
| 37 | + * @author :lyh | ||
| 38 | + * @method :post | ||
| 39 | + * @time :2024/6/18 15:46 | ||
| 40 | + */ | ||
| 41 | + public function handle(){ | ||
| 42 | + $project_id = $this->argument('project_id'); | ||
| 43 | + ProjectServer::useProject($project_id); | ||
| 44 | + $productModel = new Product(); | ||
| 45 | + $lists = $productModel->list(['status'=>1,'id'=>['<=',106]]); | ||
| 46 | + foreach ($lists as $k => $v){ | ||
| 47 | + if(!empty($v['files']) && !empty($v['files']['url'])){ | ||
| 48 | + $url = str_replace_url($v['files']['url']); | ||
| 49 | + //获取当前图片的原名称 | ||
| 50 | + $files = new File(); | ||
| 51 | + $fileInfo = $files->read(['path'=>$url,'project_id'=>$project_id]); | ||
| 52 | + if($fileInfo === false){ | ||
| 53 | + continue; | ||
| 54 | + } | ||
| 55 | + $newName = $fileInfo['name']; | ||
| 56 | + $code = $this->synchronizationFile($url,$newName); | ||
| 57 | + if((int)$code == 200){ | ||
| 58 | + echo date('Y-m-d H:i:s') . '编辑的path为:'. $url .',主键id:'. $v['id'] . PHP_EOL; | ||
| 59 | + $v['files']['url'] = preg_replace('#/[^/]*$#', '/', $url).$newName; | ||
| 60 | + $productModel->edit(['files'=>json_encode($v['files'])],['id'=>$v['id']]); | ||
| 61 | + } | ||
| 62 | + } | ||
| 63 | + } | ||
| 64 | + DB::disconnect('custom_mysql'); | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + /** | ||
| 68 | + * @remark :指定同步文件到獨立177服務器 | ||
| 69 | + * @name :synchronizationFile | ||
| 70 | + * @author :lyh | ||
| 71 | + * @method :post | ||
| 72 | + * @time :2024/4/8 11:10 | ||
| 73 | + */ | ||
| 74 | + public function synchronizationFile($path_name,$newName){ | ||
| 75 | + //同步到大文件 | ||
| 76 | + $file_path = config('filesystems.disks.cos')['cdn1'].$path_name; | ||
| 77 | + echo date('Y-m-d H:i:s') . '编辑的path为:'. $file_path. PHP_EOL; | ||
| 78 | + $directoryPath = pathinfo($path_name, PATHINFO_DIRNAME); | ||
| 79 | + $cmd = 'curl -F "file_path='.$file_path.'" -F "save_path=/www/wwwroot/cos'.$directoryPath.'" -F "file_name='.$newName.'" https://v6-file.globalso.com/fileUploads.php'; | ||
| 80 | + return shell_exec($cmd); | ||
| 81 | + } | ||
| 82 | +} |
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * @remark : | ||
| 4 | + * @name :SyncProjectFile.php | ||
| 5 | + * @author :lyh | ||
| 6 | + * @method :post | ||
| 7 | + * @time :2024/6/18 14:53 | ||
| 8 | + */ | ||
| 9 | + | ||
| 10 | +namespace App\Console\Commands\Test; | ||
| 11 | + | ||
| 12 | +use App\Models\File\ErrorFile; | ||
| 13 | +use App\Models\File\File; | ||
| 14 | +use Illuminate\Console\Command; | ||
| 15 | + | ||
| 16 | +class SyncProjectFile extends Command | ||
| 17 | +{ | ||
| 18 | + /** | ||
| 19 | + * The name and signature of the console command. | ||
| 20 | + * | ||
| 21 | + * @var string | ||
| 22 | + */ | ||
| 23 | + protected $signature = 'sync_project_file {project_id}'; | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * The console command description. | ||
| 27 | + * | ||
| 28 | + * @var string | ||
| 29 | + */ | ||
| 30 | + protected $description = '同步图片与文件'; | ||
| 31 | + | ||
| 32 | + | ||
| 33 | + public function handle(){ | ||
| 34 | + $project_id = $this->argument('project_id'); | ||
| 35 | + $fileModel = new File(); | ||
| 36 | + $lists = $fileModel->list(['project_id'=>$project_id]);//未同步成功的图片及文件 | ||
| 37 | + foreach ($lists as $k => $v){ | ||
| 38 | + if(strpos($v['path'], '/181/') !== false ){ | ||
| 39 | + $code = $this->synchronizationFiles($v['path']); | ||
| 40 | + }else{ | ||
| 41 | + $code = $this->synchronizationFile($v['path']); | ||
| 42 | + } | ||
| 43 | + if((int)$code == 200){ | ||
| 44 | + echo date('Y-m-d H:i:s') . '编辑的path为:'. $v['path'] .',主键id:'. $v['id'] . PHP_EOL; | ||
| 45 | + } | ||
| 46 | + } | ||
| 47 | + echo date('Y-m-d H:i:s') . '编辑的end为:' . PHP_EOL; | ||
| 48 | + return true; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + /** | ||
| 52 | + * @remark :指定同步文件到獨立177服務器 | ||
| 53 | + * @name :synchronizationFile | ||
| 54 | + * @author :lyh | ||
| 55 | + * @method :post | ||
| 56 | + * @time :2024/4/8 11:10 | ||
| 57 | + */ | ||
| 58 | + public function synchronizationFile($path_name){ | ||
| 59 | + //同步到大文件 | ||
| 60 | + $file_path = config('filesystems.disks.cos')['cdn1'].$path_name; | ||
| 61 | + $directoryPath = pathinfo($path_name, PATHINFO_DIRNAME); | ||
| 62 | + $cmd = 'curl -F "file_path='.$file_path.'" -F "save_path=/www/wwwroot/cos'.$directoryPath.'" https://v6-file.globalso.com/upload.php'; | ||
| 63 | + return shell_exec($cmd); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + | ||
| 67 | + public function synchronizationFiles($path_name){ | ||
| 68 | + //同步到大文件 | ||
| 69 | + $file_path = config('filesystems.disks.s3')['cdn'].$path_name; | ||
| 70 | + $directoryPath = pathinfo($path_name, PATHINFO_DIRNAME); | ||
| 71 | + $cmd = 'curl -F "file_path='.$file_path.'" -F "save_path=/www/wwwroot/cos'.$directoryPath.'" https://v6-file.globalso.com/upload.php'; | ||
| 72 | + return shell_exec($cmd); | ||
| 73 | + } | ||
| 74 | +} |
| @@ -34,108 +34,24 @@ class Temp extends Command | @@ -34,108 +34,24 @@ class Temp extends Command | ||
| 34 | */ | 34 | */ |
| 35 | protected $description = '临时脚本'; | 35 | protected $description = '临时脚本'; |
| 36 | 36 | ||
| 37 | - public function handle() | ||
| 38 | - { | ||
| 39 | - $domain_model = new DomainInfo(); | ||
| 40 | - $notify_model = new Notify(); | ||
| 41 | - $project_model = new Project(); | 37 | + public function handle(){ |
| 38 | + ProjectServer::useProject(1515); | ||
| 42 | 39 | ||
| 43 | - $domain_list = $domain_model->list(['amp_status' => 1]); | ||
| 44 | - foreach ($domain_list as $info) { | ||
| 45 | - if ($info['project_id'] > 0) { | ||
| 46 | - $notify_info = $notify_model->read(['project_id' => $info['project_id'], 'type' => 3]); | ||
| 47 | - if (!$notify_info) { | 40 | + $products = Product::select(['id','content'])->get(); |
| 48 | 41 | ||
| 49 | - $domain_array = parse_url($info['domain']); | ||
| 50 | - $host = $domain_array['host'] ?? $domain_array['path']; | ||
| 51 | - $host_array = explode('.', $host); | ||
| 52 | - if (count($host_array) <= 2) { | ||
| 53 | - array_unshift($host_array, 'm'); | ||
| 54 | - } else { | ||
| 55 | - $host_array[0] = 'm'; | ||
| 56 | - } | ||
| 57 | - $amp_domain = implode('.', $host_array); | 42 | + foreach ($products as $product){ |
| 43 | + $content = $product->content; | ||
| 44 | + $content = str_replace('<h1','<h2', $content); | ||
| 45 | + $content = str_replace('</h1','</h2', $content); | ||
| 58 | 46 | ||
| 59 | - $project_info = $project_model->read(['id' => $info['project_id']]); | 47 | + $product->content = $content; |
| 48 | + $product->save(); | ||
| 60 | 49 | ||
| 61 | - $notify_model->add([ | ||
| 62 | - 'project_id' => $info['project_id'], | ||
| 63 | - 'type' => 3, | ||
| 64 | - 'data' => json_encode(['domain' => $amp_domain, 'url' => [], 'language' => []]), | ||
| 65 | - 'server_id' => $project_info['serve_id'], | ||
| 66 | - ]); | ||
| 67 | - } | ||
| 68 | - } | 50 | + $this->output('productID:'.$product->id.',success'); |
| 69 | } | 51 | } |
| 70 | - } | ||
| 71 | 52 | ||
| 72 | -// public function handle() | ||
| 73 | -// { | ||
| 74 | -// $domain_model = new DomainInfo(); | ||
| 75 | -// $server_model = new ServerConfig(); | ||
| 76 | -// $project_model = new Project(); | ||
| 77 | -// | ||
| 78 | -// $domain_list = $domain_model->list(['domain' => ['like', 'www.%']], 'id', ['id', 'domain', 'project_id'], 'asc'); | ||
| 79 | -// foreach ($domain_list as $info) { | ||
| 80 | -// $this->output('domain:' . $info['domain'] . ',开始'); | ||
| 81 | -// | ||
| 82 | -// $project_info = $project_model->read(['id' => $info['project_id']], 'serve_id'); | ||
| 83 | -// if ($project_info === false) { | ||
| 84 | -// $this->output('获取项目数据失败'); | ||
| 85 | -// continue; | ||
| 86 | -// } | ||
| 87 | -// | ||
| 88 | -// $server_info = $server_model->read(['id' => $project_info['serve_id']], ['init_domain', 'host']); | ||
| 89 | -// if ($server_info === false) { | ||
| 90 | -// $this->output('获取服务器数据失败'); | ||
| 91 | -// continue; | ||
| 92 | -// } | ||
| 93 | -// | ||
| 94 | -// $domain_array = parse_url($info['domain']); | ||
| 95 | -// $host = $domain_array['host'] ?? $domain_array['path']; | ||
| 96 | -// $host_array = explode('.', $host); | ||
| 97 | -// if (count($host_array) <= 2) { | ||
| 98 | -// array_unshift($host_array, 'm'); | ||
| 99 | -// } else { | ||
| 100 | -// $host_array[0] = 'm'; | ||
| 101 | -// } | ||
| 102 | -// $amp_domain = implode('.', $host_array); | ||
| 103 | -// if (!$this->check_cname($amp_domain, $server_info)) { | ||
| 104 | -// $this->output('AMP站点域名' . $amp_domain . '未解析至目标服务器'); | ||
| 105 | -// continue; | ||
| 106 | -// } | ||
| 107 | -// | ||
| 108 | -// $api_url = 'http://' . $server_info['init_domain'] . '/api/createSiteAmp'; | ||
| 109 | -// $api_param = [ | ||
| 110 | -// 'domain' => $info['domain'], | ||
| 111 | -// 'private_key' => '', | ||
| 112 | -// 'cert' => '' | ||
| 113 | -// ]; | ||
| 114 | -// | ||
| 115 | -// try { | ||
| 116 | -// $rs = HttpUtils::get($api_url, $api_param); | ||
| 117 | -// $rs = json_decode($rs, true); | ||
| 118 | -// if (isset($rs['status']) && $rs['status'] == 200) { | ||
| 119 | -// $this->output('创建AMP站点成功'); | ||
| 120 | -// } else { | ||
| 121 | -// $this->output($rs['message'] ?? ''); | ||
| 122 | -// continue; | ||
| 123 | -// } | ||
| 124 | -// } catch (\Exception | GuzzleException $e) { | ||
| 125 | -// errorLog('创建AMP站点', $api_param, $e); | ||
| 126 | -// $this->output('创建AMP站点失败'); | ||
| 127 | -// continue; | ||
| 128 | -// } | ||
| 129 | -// | ||
| 130 | -// $data = [ | ||
| 131 | -// 'amp_status' => 1, | ||
| 132 | -// 'amp_type' => 1, | ||
| 133 | -// ]; | ||
| 134 | -// $domain_model->edit($data, ['id' => $info['id']]); | ||
| 135 | -// } | ||
| 136 | -// | ||
| 137 | -// echo '成功' . PHP_EOL; | ||
| 138 | -// } | 53 | + $this->output('end'); |
| 54 | + } | ||
| 139 | 55 | ||
| 140 | public function check_cname($domain, $server_info) | 56 | public function check_cname($domain, $server_info) |
| 141 | { | 57 | { |
| @@ -147,7 +63,7 @@ class Temp extends Command | @@ -147,7 +63,7 @@ class Temp extends Command | ||
| 147 | $output = explode(PHP_EOL, $process->getOutput()); | 63 | $output = explode(PHP_EOL, $process->getOutput()); |
| 148 | foreach ($output as $line) { | 64 | foreach ($output as $line) { |
| 149 | if ($line) { | 65 | if ($line) { |
| 150 | - $checkA = strpos($line, $server_info['host']) !== false; | 66 | + $checkA = strpos($line, $server_info['ip']) !== false; |
| 151 | if ($checkA) { | 67 | if ($checkA) { |
| 152 | return $domain; | 68 | return $domain; |
| 153 | } | 69 | } |
| @@ -160,7 +76,7 @@ class Temp extends Command | @@ -160,7 +76,7 @@ class Temp extends Command | ||
| 160 | $output = explode(PHP_EOL, $process->getOutput()); | 76 | $output = explode(PHP_EOL, $process->getOutput()); |
| 161 | foreach ($output as $line) { | 77 | foreach ($output as $line) { |
| 162 | if ($line) { | 78 | if ($line) { |
| 163 | - $checkCname = (strpos($line, $server_info['init_domain']) !== false); | 79 | + $checkCname = (strpos($line, $server_info['domain']) !== false); |
| 164 | if ($checkCname) { | 80 | if ($checkCname) { |
| 165 | return $domain; | 81 | return $domain; |
| 166 | } | 82 | } |
| @@ -10,11 +10,16 @@ use App\Models\HomeCount\Count; | @@ -10,11 +10,16 @@ use App\Models\HomeCount\Count; | ||
| 10 | use App\Models\Inquiry\InquiryFormData; | 10 | use App\Models\Inquiry\InquiryFormData; |
| 11 | use App\Models\Nav\BNav; | 11 | use App\Models\Nav\BNav; |
| 12 | use App\Models\Nav\BNavGroup; | 12 | use App\Models\Nav\BNavGroup; |
| 13 | +use App\Models\Project\OnlineCheck; | ||
| 13 | use App\Models\Project\Project; | 14 | use App\Models\Project\Project; |
| 14 | use App\Models\SyncSubmitTask\SyncSubmitTask as SyncSubmitTaskModel; | 15 | use App\Models\SyncSubmitTask\SyncSubmitTask as SyncSubmitTaskModel; |
| 15 | use App\Models\WebSetting\Translate as TranslateModel; | 16 | use App\Models\WebSetting\Translate as TranslateModel; |
| 17 | +use App\Models\WebSetting\WebLanguage; | ||
| 16 | use App\Services\ProjectServer; | 18 | use App\Services\ProjectServer; |
| 19 | +use Carbon\Carbon; | ||
| 17 | use Illuminate\Console\Command; | 20 | use Illuminate\Console\Command; |
| 21 | +use Illuminate\Support\Facades\DB; | ||
| 22 | +use Illuminate\Support\Facades\Redis; | ||
| 18 | 23 | ||
| 19 | /** | 24 | /** |
| 20 | * Class Test | 25 | * Class Test |
| @@ -53,6 +58,19 @@ class Test extends Command | @@ -53,6 +58,19 @@ class Test extends Command | ||
| 53 | */ | 58 | */ |
| 54 | public function handle() | 59 | public function handle() |
| 55 | { | 60 | { |
| 61 | + $date = '2024-05-16'; | ||
| 62 | + $list = $this->getProjectList(); | ||
| 63 | + foreach ($list as $item){ | ||
| 64 | + ProjectServer::useProject($item['project_id']); | ||
| 65 | + //pv统计 | ||
| 66 | + $pv_num = $this->pv_num($date); | ||
| 67 | + //ip统计 | ||
| 68 | + $ip_num = $this->ip_num($date); | ||
| 69 | + | ||
| 70 | + echo $item['project_id'] . ',pv:' . $pv_num . ',ip:' . $ip_num . PHP_EOL; | ||
| 71 | + } | ||
| 72 | + exit; | ||
| 73 | + | ||
| 56 | 74 | ||
| 57 | $i=0; | 75 | $i=0; |
| 58 | while (true){ | 76 | while (true){ |
| @@ -167,4 +185,78 @@ class Test extends Command | @@ -167,4 +185,78 @@ class Test extends Command | ||
| 167 | $arr['country'] = json_encode($top20); | 185 | $arr['country'] = json_encode($top20); |
| 168 | return $arr; | 186 | return $arr; |
| 169 | } | 187 | } |
| 188 | + | ||
| 189 | + protected function getProjectList($type = 1){ | ||
| 190 | + $ru_lang_id = WebLanguage::getIdByLang('ru'); | ||
| 191 | + | ||
| 192 | + //推广项目 | ||
| 193 | + $list = Project::with('domainInfo') | ||
| 194 | + ->leftJoin('gl_project_deploy_optimize as pdo', 'pdo.project_id', '=', 'gl_project.id') | ||
| 195 | + ->leftJoin('gl_project_online_check as poc', 'poc.project_id', '=', 'gl_project.id') | ||
| 196 | + ->where('pdo.domain', '>', 0) | ||
| 197 | + ->where('poc.qa_status', OnlineCheck::STATUS_ONLINE_TRUE) | ||
| 198 | + ->whereIn('gl_project.type', [Project::TYPE_TWO, Project::TYPE_FOUR]) | ||
| 199 | + ->where('gl_project.is_upgrade', 0) //非升级项目 | ||
| 200 | + ->where('gl_project.main_lang_id', '<>', $ru_lang_id) //非俄语站 | ||
| 201 | + ->where(function ($query) use ($type) { | ||
| 202 | + if($type == 1){ | ||
| 203 | + //1-3个月项目 | ||
| 204 | + $startTime = Carbon::now()->addMonths(-4)->toDateString(); | ||
| 205 | + $endTime = Carbon::now()->addMonths(-1)->toDateString(); | ||
| 206 | + $query->whereBetween('pdo.start_date', [$startTime,$endTime]); | ||
| 207 | + }elseif($type == 2){ | ||
| 208 | + //4-8个月项目 | ||
| 209 | + $startTime = Carbon::now()->addMonths(-9)->startOfDay()->toDateTimeString(); | ||
| 210 | + $endTime = Carbon::now()->addMonths(-4)->endOfDay()->toDateTimeString(); | ||
| 211 | + $query->whereBetween('pdo.start_date', [$startTime,$endTime]); | ||
| 212 | + }else{ | ||
| 213 | + //大于9个月项目 | ||
| 214 | + $startTime = Carbon::now()->addMonths(-9)->startOfDay()->toDateTimeString(); | ||
| 215 | + $query->where('pdo.start_date', '<', $startTime); | ||
| 216 | + } | ||
| 217 | + })->select(['pdo.project_id','gl_project.main_lang_id','gl_project.id']) | ||
| 218 | + ->orderBy('project_id') | ||
| 219 | + ->get(); | ||
| 220 | + //其他地方在引流的域名 | ||
| 221 | + $other = DB::connection('projects_mysql')->table('projects')->where('switch', 1)->pluck('domain')->toArray(); | ||
| 222 | + $data = []; | ||
| 223 | + foreach ($list as $project) { | ||
| 224 | + $lang = WebLanguage::getLangById($project['main_lang_id']??1)['short']; | ||
| 225 | + if(empty($project->domainInfo['domain'])){ | ||
| 226 | + continue; | ||
| 227 | + } | ||
| 228 | + //其他地方在引流就不再引流了 | ||
| 229 | + if(in_array($project->domainInfo['domain'], $other)){ | ||
| 230 | + continue; | ||
| 231 | + } | ||
| 232 | + $data[] = [ | ||
| 233 | + 'project_id' => $project['project_id'], | ||
| 234 | + 'domain' => 'https://' . $project->domainInfo['domain'] . '/', | ||
| 235 | + 'lang' => $lang | ||
| 236 | + ]; | ||
| 237 | + } | ||
| 238 | + return $data; | ||
| 239 | + } | ||
| 240 | + /** | ||
| 241 | + * @name :(统计pv)pv_num | ||
| 242 | + * @author :lyh | ||
| 243 | + * @method :post | ||
| 244 | + * @time :2023/6/14 15:40 | ||
| 245 | + */ | ||
| 246 | + public function pv_num($yesterday){ | ||
| 247 | + $pv = DB::connection('custom_mysql')->table('gl_customer_visit_item')->where('updated_date', $yesterday)->count(); | ||
| 248 | + return $pv; | ||
| 249 | + } | ||
| 250 | + | ||
| 251 | + /** | ||
| 252 | + * @name :(统计ip)ip_num | ||
| 253 | + * @author :lyh | ||
| 254 | + * @method :post | ||
| 255 | + * @time :2023/6/14 15:40 | ||
| 256 | + */ | ||
| 257 | + public function ip_num($yesterday) | ||
| 258 | + { | ||
| 259 | + $ip = DB::connection('custom_mysql')->table('gl_customer_visit')->where('updated_date', $yesterday)->count(); | ||
| 260 | + return $ip; | ||
| 261 | + } | ||
| 170 | } | 262 | } |
app/Console/Commands/Test/Translate.php
0 → 100644
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * @remark : | ||
| 4 | + * @name :Translate.php | ||
| 5 | + * @author :lyh | ||
| 6 | + * @method :post | ||
| 7 | + * @time :2024/5/21 9:32 | ||
| 8 | + */ | ||
| 9 | + | ||
| 10 | +namespace App\Console\Commands\Test; | ||
| 11 | + | ||
| 12 | +use App\Models\Project\Project; | ||
| 13 | +use App\Models\RouteMap\RouteMap; | ||
| 14 | +use App\Models\Template\BTemplateCom; | ||
| 15 | +use App\Models\Template\BTemplateCommon; | ||
| 16 | +use App\Models\Template\Setting; | ||
| 17 | +use App\Services\ProjectServer; | ||
| 18 | +use Illuminate\Console\Command; | ||
| 19 | +use Illuminate\Support\Facades\DB; | ||
| 20 | + | ||
| 21 | +class Translate extends Command | ||
| 22 | +{ | ||
| 23 | + /** | ||
| 24 | + * The name and signature of the console command. | ||
| 25 | + * | ||
| 26 | + * @var string | ||
| 27 | + */ | ||
| 28 | + protected $signature = 'translate'; | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * The console command description. | ||
| 32 | + * | ||
| 33 | + * @var string | ||
| 34 | + */ | ||
| 35 | + protected $description = 'translate'; | ||
| 36 | + public function handle(){ | ||
| 37 | + $projectModel = new Project(); | ||
| 38 | + $list = $projectModel->list(['id'=>452]); | ||
| 39 | + foreach ($list as $v){ | ||
| 40 | + echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL; | ||
| 41 | + ProjectServer::useProject($v['id']); | ||
| 42 | + $translateModel = new \App\Models\WebSetting\Translate(); | ||
| 43 | + $translateList = $translateModel->list(['id'=>['between',[150000,200000]]],'id',['id','url']); | ||
| 44 | + if(!empty($translateList)){ | ||
| 45 | + foreach ($translateList as $value){ | ||
| 46 | + echo date('Y-m-d H:i:s') . '数据路由:'.$value['url'] . PHP_EOL; | ||
| 47 | + $data = $this->getRouteSource($value['url']); | ||
| 48 | + if($data === false){ | ||
| 49 | + continue; | ||
| 50 | + } | ||
| 51 | + $rs = $translateModel->edit($data,['id'=>$value['id']]); | ||
| 52 | + gc_collect_cycles(); | ||
| 53 | + } | ||
| 54 | + } | ||
| 55 | + DB::disconnect('custom_mysql'); | ||
| 56 | + } | ||
| 57 | + DB::disconnect('custom_mysql'); | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + /** | ||
| 61 | + * @remark :根据路由获取source+source_id | ||
| 62 | + * @name :getRouteSource | ||
| 63 | + * @author :lyh | ||
| 64 | + * @method :post | ||
| 65 | + * @time :2024/5/17 15:11 | ||
| 66 | + */ | ||
| 67 | + public function getRouteSource($route){ | ||
| 68 | + $data = ['source'=>0,'source_id'=>0,'is_list'=>0,'is_custom'=>0]; | ||
| 69 | + if(strtolower($route) == 'all'){ | ||
| 70 | + return $data; | ||
| 71 | + } | ||
| 72 | + if($route == '/'){ | ||
| 73 | + $data['source'] = 1; | ||
| 74 | + return $data; | ||
| 75 | + } | ||
| 76 | + $route = $this->handleRoute($route); | ||
| 77 | + $routeModel = new RouteMap(); | ||
| 78 | + $routeInfo = $routeModel->read(['route'=>$route]); | ||
| 79 | + if($routeInfo === false){ | ||
| 80 | + return false; | ||
| 81 | + } | ||
| 82 | + return $this->resultData($routeInfo,$data); | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + /** | ||
| 86 | + * @remark :处理路由 | ||
| 87 | + * @name :handleRoute | ||
| 88 | + * @author :lyh | ||
| 89 | + * @method :post | ||
| 90 | + * @time :2024/1/18 17:25 | ||
| 91 | + */ | ||
| 92 | + public function handleRoute($url){ | ||
| 93 | + $str = trim($url,'/'); | ||
| 94 | + $route = 'index'; | ||
| 95 | + if(!empty($str)){ | ||
| 96 | + $arr = explode('/',$str); | ||
| 97 | + $num = count($arr); | ||
| 98 | + if($num == 1){ | ||
| 99 | + $route = $arr[0]; | ||
| 100 | + }elseif ($num == 2){ | ||
| 101 | + if(ctype_digit($arr[1])){//是数字的情况 | ||
| 102 | + $route = $arr[0]; | ||
| 103 | + }else{ | ||
| 104 | + $route = $arr[1]; | ||
| 105 | + } | ||
| 106 | + }elseif($num == 3){ | ||
| 107 | + if(ctype_digit($arr[2])){//是数字的情况 | ||
| 108 | + $route = $arr[0]; | ||
| 109 | + }else{ | ||
| 110 | + if($arr[2] == 'page'){ | ||
| 111 | + $route = $arr[1]; | ||
| 112 | + }else{ | ||
| 113 | + $route = $arr[0]; | ||
| 114 | + } | ||
| 115 | + } | ||
| 116 | + }elseif ($num == 4){ | ||
| 117 | + if(ctype_digit($arr[3])){//是数字的情况 | ||
| 118 | + $route = $arr[1]; | ||
| 119 | + } | ||
| 120 | + } | ||
| 121 | + } | ||
| 122 | + return $route; | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + /** | ||
| 126 | + * @remark :返回数据 | ||
| 127 | + * @name :resultData | ||
| 128 | + * @author :lyh | ||
| 129 | + * @method :post | ||
| 130 | + * @time :2024/5/20 11:54 | ||
| 131 | + */ | ||
| 132 | + public function resultData($routeInfo,$data){ | ||
| 133 | + if($routeInfo['source'] == RouteMap::SOURCE_PAGE){ | ||
| 134 | + if($routeInfo['source_id']){ | ||
| 135 | + $data = ['source'=>9,'source_id'=>$routeInfo['source_id'],'is_list'=>0,'is_custom'=>0]; | ||
| 136 | + } | ||
| 137 | + } | ||
| 138 | + if($routeInfo['source'] == RouteMap::SOURCE_PRODUCT){ | ||
| 139 | + if($routeInfo['source_id']){ | ||
| 140 | + $data = ['source'=>2,'source_id'=>$routeInfo['source_id'],'is_list'=>0,'is_custom'=>0]; | ||
| 141 | + } | ||
| 142 | + } | ||
| 143 | + if($routeInfo['source'] == RouteMap::SOURCE_PRODUCT_CATE){ | ||
| 144 | + if($routeInfo['source_id']){ | ||
| 145 | + $data = ['source'=>2,'source_id'=>$routeInfo['source_id'],'is_list'=>1,'is_custom'=>0]; | ||
| 146 | + } | ||
| 147 | + } | ||
| 148 | + if($routeInfo['source'] == RouteMap::SOURCE_BLOG){ | ||
| 149 | + if($routeInfo['source_id']){ | ||
| 150 | + $data = ['source'=>3,'source_id'=>$routeInfo['source_id'],'is_list'=>0,'is_custom'=>0]; | ||
| 151 | + } | ||
| 152 | + } | ||
| 153 | + if($routeInfo['source'] == RouteMap::SOURCE_BLOG_CATE){ | ||
| 154 | + if($routeInfo['source_id']){ | ||
| 155 | + $data = ['source'=>3,'source_id'=>$routeInfo['source_id'],'is_list'=>1,'is_custom'=>0]; | ||
| 156 | + } | ||
| 157 | + } | ||
| 158 | + if($routeInfo['source'] == RouteMap::SOURCE_NEWS){ | ||
| 159 | + if($routeInfo['source_id']){ | ||
| 160 | + $data = ['source'=>4,'source_id'=>$routeInfo['source_id'],'is_list'=>0,'is_custom'=>0]; | ||
| 161 | + } | ||
| 162 | + } | ||
| 163 | + if($routeInfo['source'] == RouteMap::SOURCE_NEWS_CATE){ | ||
| 164 | + if($routeInfo['source_id']){ | ||
| 165 | + $data = ['source'=>4,'source_id'=>$routeInfo['source_id'],'is_list'=>1,'is_custom'=>0]; | ||
| 166 | + } | ||
| 167 | + } | ||
| 168 | + if($routeInfo['source'] == RouteMap::SOURCE_MODULE){ | ||
| 169 | + if($routeInfo['source_id']){ | ||
| 170 | + $data = ['source'=>7,'source_id'=>$routeInfo['source_id'],'is_list'=>0,'is_custom'=>1]; | ||
| 171 | + } | ||
| 172 | + } | ||
| 173 | + if($routeInfo['source'] == RouteMap::SOURCE_MODULE_CATE){ | ||
| 174 | + if($routeInfo['source_id']){ | ||
| 175 | + $data = ['source'=>7,'source_id'=>$routeInfo['source_id'],'is_list'=>1,'is_custom'=>1]; | ||
| 176 | + } | ||
| 177 | + } | ||
| 178 | + return $data; | ||
| 179 | + } | ||
| 180 | + | ||
| 181 | +} |
| @@ -50,12 +50,14 @@ class UpdateProductCategory extends Command | @@ -50,12 +50,14 @@ class UpdateProductCategory extends Command | ||
| 50 | public function handle(){ | 50 | public function handle(){ |
| 51 | //获取所有项目 | 51 | //获取所有项目 |
| 52 | $projectModel = new Project(); | 52 | $projectModel = new Project(); |
| 53 | - $list = $projectModel->list(['id'=>['in',[621]]],'id',['id']); | 53 | + $list = $projectModel->list(['id'=>978],'id',['id']); |
| 54 | echo date('Y-m-d H:i:s') . ' start: ' . json_encode($list) . PHP_EOL; | 54 | echo date('Y-m-d H:i:s') . ' start: ' . json_encode($list) . PHP_EOL; |
| 55 | try { | 55 | try { |
| 56 | foreach ($list as $v) { | 56 | foreach ($list as $v) { |
| 57 | echo date('Y-m-d H:i:s') . ' start: ' . $v['id'] . PHP_EOL; | 57 | echo date('Y-m-d H:i:s') . ' start: ' . $v['id'] . PHP_EOL; |
| 58 | ProjectServer::useProject($v['id']); | 58 | ProjectServer::useProject($v['id']); |
| 59 | + $cateRelatedModel = new CategoryRelated(); | ||
| 60 | + $cateRelatedModel->truncate(); | ||
| 59 | $this->getUpdateProductCategory(); | 61 | $this->getUpdateProductCategory(); |
| 60 | DB::disconnect('custom_mysql'); | 62 | DB::disconnect('custom_mysql'); |
| 61 | } | 63 | } |
| @@ -74,7 +76,7 @@ class UpdateProductCategory extends Command | @@ -74,7 +76,7 @@ class UpdateProductCategory extends Command | ||
| 74 | */ | 76 | */ |
| 75 | public function getUpdateProductCategory(){ | 77 | public function getUpdateProductCategory(){ |
| 76 | $productModel = new Product(); | 78 | $productModel = new Product(); |
| 77 | - $lists = $productModel->list(['status'=>1],'id',['id','category_id']); | 79 | + $lists = $productModel->list(['deleted_at'=>null],'id',['id','category_id']); |
| 78 | foreach ($lists as $k => $v){ | 80 | foreach ($lists as $k => $v){ |
| 79 | if(!empty($v['category_id'])){ | 81 | if(!empty($v['category_id'])){ |
| 80 | $this->handleCategory($v['id'],$v['category_id']); | 82 | $this->handleCategory($v['id'],$v['category_id']); |
| @@ -96,14 +98,15 @@ class UpdateProductCategory extends Command | @@ -96,14 +98,15 @@ class UpdateProductCategory extends Command | ||
| 96 | $categoryModel = new Category(); | 98 | $categoryModel = new Category(); |
| 97 | $info = $categoryModel->read(['id'=>$v],['id']); | 99 | $info = $categoryModel->read(['id'=>$v],['id']); |
| 98 | if($info === false){ | 100 | if($info === false){ |
| 99 | - continue; | ||
| 100 | - }else{ | ||
| 101 | - //更新关联表 | ||
| 102 | $cateRelatedModel = new CategoryRelated(); | 101 | $cateRelatedModel = new CategoryRelated(); |
| 103 | - $relateInfo = $cateRelatedModel->read(['product_id'=>$id,'cate_id'=>$v]); | ||
| 104 | - if($relateInfo === false){ | ||
| 105 | - $cateRelatedModel->add(['product_id'=>$id, 'cate_id'=>$v]); | ||
| 106 | - } | 102 | + $cateRelatedModel->del(['cate_id'=>$v]); |
| 103 | + continue; | ||
| 104 | + } | ||
| 105 | + //更新关联表 | ||
| 106 | + $cateRelatedModel = new CategoryRelated(); | ||
| 107 | + $relateInfo = $cateRelatedModel->read(['product_id'=>$id,'cate_id'=>$v]); | ||
| 108 | + if($relateInfo === false){ | ||
| 109 | + $cateRelatedModel->add(['product_id'=>$id, 'cate_id'=>$v]); | ||
| 107 | } | 110 | } |
| 108 | } | 111 | } |
| 109 | } | 112 | } |
| @@ -20,6 +20,7 @@ use App\Models\RouteMap\RouteMap; | @@ -20,6 +20,7 @@ use App\Models\RouteMap\RouteMap; | ||
| 20 | use App\Services\ProjectServer; | 20 | use App\Services\ProjectServer; |
| 21 | use Illuminate\Console\Command; | 21 | use Illuminate\Console\Command; |
| 22 | use Illuminate\Support\Facades\DB; | 22 | use Illuminate\Support\Facades\DB; |
| 23 | +use Illuminate\Support\Facades\Schema; | ||
| 23 | 24 | ||
| 24 | /** | 25 | /** |
| 25 | * @remark :更新所有项目的路由 | 26 | * @remark :更新所有项目的路由 |
| @@ -53,11 +54,12 @@ class UpdateRoute extends Command | @@ -53,11 +54,12 @@ class UpdateRoute extends Command | ||
| 53 | */ | 54 | */ |
| 54 | public function handle(){ | 55 | public function handle(){ |
| 55 | $projectModel = new Project(); | 56 | $projectModel = new Project(); |
| 56 | - $list = $projectModel->list(['id'=>688]); | 57 | + $list = $projectModel->list(['id'=>['in',[664]]]); |
| 57 | $data = []; | 58 | $data = []; |
| 58 | foreach ($list as $v){ | 59 | foreach ($list as $v){ |
| 59 | echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL; | 60 | echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL; |
| 60 | ProjectServer::useProject($v['id']); | 61 | ProjectServer::useProject($v['id']); |
| 62 | +// $this->getProduct(); | ||
| 61 | $this->setProductKeyword(); | 63 | $this->setProductKeyword(); |
| 62 | DB::disconnect('custom_mysql'); | 64 | DB::disconnect('custom_mysql'); |
| 63 | } | 65 | } |
| @@ -105,31 +107,85 @@ class UpdateRoute extends Command | @@ -105,31 +107,85 @@ class UpdateRoute extends Command | ||
| 105 | if(!empty($lists)){ | 107 | if(!empty($lists)){ |
| 106 | foreach ($lists as $v){ | 108 | foreach ($lists as $v){ |
| 107 | if(!empty($v['route'])){ | 109 | if(!empty($v['route'])){ |
| 108 | -// $tag = "-tag"; | ||
| 109 | -// if ((substr($v['route'], -strlen($tag)) === $tag)) { | ||
| 110 | -// echo date('Y-m-d H:i:s') . '拼接 :'.$v['id'] . PHP_EOL; | ||
| 111 | -// $route = Translate::tran($v['route'], 'en').$tag; | ||
| 112 | -// // 如果不是以 '-tag' 结尾,则拼接上 '-tag' | ||
| 113 | -// $route = trim($v['route'],'-tag'); | ||
| 114 | -// $route = RouteMap::setRoute($route, RouteMap::SOURCE_PRODUCT_KEYWORD, $v['id'], $v['project_id']); | ||
| 115 | -// $keywordModel->edit(['route'=>$route],['id'=>$v['id']]); | ||
| 116 | -// }else{ | ||
| 117 | -// $route = Translate::tran($v['title'], 'en').$tag; | ||
| 118 | -// $route = RouteMap::setRoute($route, RouteMap::SOURCE_PRODUCT_KEYWORD, $v['id'], $v['project_id']); | ||
| 119 | -// $keywordModel->edit(['route'=>$route],['id'=>$v['id']]); | ||
| 120 | -// } | 110 | + echo date('Y-m-d H:i:s') . 'route :'.$v['id'] . PHP_EOL; |
| 111 | + continue; | ||
| 121 | }else{ | 112 | }else{ |
| 113 | + echo date('Y-m-d H:i:s') . 'route :'.$v['id'] . PHP_EOL; | ||
| 122 | $route = Translate::tran($v['title'], 'en'); | 114 | $route = Translate::tran($v['title'], 'en'); |
| 123 | - echo date('Y-m-d H:i:s') . 'route :'.$route . PHP_EOL; | ||
| 124 | - $route = RouteMap::setRoute($route, RouteMap::SOURCE_PRODUCT_KEYWORD, $v['id'], $v['project_id']); | ||
| 125 | - $keywordModel->edit(['route'=>$route],['id'=>$v['id']]); | 115 | + if(!empty($route)){ |
| 116 | + echo date('Y-m-d H:i:s') . $route . PHP_EOL; | ||
| 117 | + $route = $this->setRoute($route, RouteMap::SOURCE_PRODUCT_KEYWORD, $v['id'], $v['project_id']); | ||
| 118 | + $keywordModel->edit(['route'=>$route],['id'=>$v['id']]); | ||
| 119 | + } | ||
| 126 | } | 120 | } |
| 127 | -// echo date('Y-m-d H:i:s') . 'end :' . PHP_EOL; | ||
| 128 | } | 121 | } |
| 129 | } | 122 | } |
| 130 | } | 123 | } |
| 131 | 124 | ||
| 132 | /** | 125 | /** |
| 126 | + * @param $title | ||
| 127 | + * @param $source | ||
| 128 | + * @param $source_id | ||
| 129 | + * @param int $project_id | ||
| 130 | + * @return bool | ||
| 131 | + * @throws \Exception | ||
| 132 | + * @author zbj | ||
| 133 | + * @date 2023/4/17 | ||
| 134 | + */ | ||
| 135 | + public static function setRoute($title, $source, $source_id, $project_id = 0){ | ||
| 136 | + $route = self::generateRoute($title, $source, $source_id, $project_id); | ||
| 137 | + if(!$route){ | ||
| 138 | + throw new \Exception('路由生成失败'); | ||
| 139 | + } | ||
| 140 | + try { | ||
| 141 | + $route_map = RouteMap::where('project_id', $project_id)->where('source_id', $source_id)->where('source', $source)->first(); | ||
| 142 | + if(!$route_map){ | ||
| 143 | + $route_map = new RouteMap(); | ||
| 144 | + $route_map->source = $source; | ||
| 145 | + $route_map->source_id = $source_id; | ||
| 146 | + $route_map->project_id = $project_id; | ||
| 147 | + } | ||
| 148 | + $route_map->route = $route; | ||
| 149 | + $route_map->save(); | ||
| 150 | + }catch (\Exception $e){ | ||
| 151 | + throw new \Exception('路由映射失败'); | ||
| 152 | + } | ||
| 153 | + return $route; | ||
| 154 | + } | ||
| 155 | + | ||
| 156 | + /** | ||
| 157 | + * 生成路由标识 | ||
| 158 | + * @param $title | ||
| 159 | + * @param $source | ||
| 160 | + * @param $source_id | ||
| 161 | + * @param $project_id | ||
| 162 | + * @return string | ||
| 163 | + * @author zbj | ||
| 164 | + * @date 2023/4/17 | ||
| 165 | + */ | ||
| 166 | + public static function generateRoute($title, $source, $source_id, $project_id){ | ||
| 167 | + $i=1; | ||
| 168 | + $sign = generateRoute($title); | ||
| 169 | + $length = strlen($sign); | ||
| 170 | + if($length > 100){ | ||
| 171 | + $sign = trim(mb_substr($sign, 0, 100, 'UTF-8'),'-'); | ||
| 172 | + } | ||
| 173 | + $info = RouteMap::where(['project_id' => $project_id, 'source' => $source, 'source_id'=>$source_id])->first(); | ||
| 174 | + $suffix = ''; | ||
| 175 | + if(empty($info)){ | ||
| 176 | + if($source == 'product'){ | ||
| 177 | + $suffix = '-product'; | ||
| 178 | + } | ||
| 179 | + } | ||
| 180 | + $route = $sign.$suffix; | ||
| 181 | + while(RouteMap::isExist($route, $source_id, $project_id)){ | ||
| 182 | + $route = $sign .'-'.$i.$suffix; | ||
| 183 | + $i++; | ||
| 184 | + } | ||
| 185 | + return $route; | ||
| 186 | + } | ||
| 187 | + | ||
| 188 | + /** | ||
| 133 | * @remark :产品关键字 | 189 | * @remark :产品关键字 |
| 134 | * @name :getProductKeyword | 190 | * @name :getProductKeyword |
| 135 | * @author :lyh | 191 | * @author :lyh |
| @@ -157,7 +213,7 @@ class UpdateRoute extends Command | @@ -157,7 +213,7 @@ class UpdateRoute extends Command | ||
| 157 | 213 | ||
| 158 | public function getProduct(){ | 214 | public function getProduct(){ |
| 159 | $productModel = new Product(); | 215 | $productModel = new Product(); |
| 160 | - $lists = $productModel->list(['status'=>1]); | 216 | + $lists = $productModel->list(['status'=>1,'id'=>['<=',501]]); |
| 161 | if(!empty($lists)){ | 217 | if(!empty($lists)){ |
| 162 | foreach ($lists as $v){ | 218 | foreach ($lists as $v){ |
| 163 | if(!empty($v['route'])){ | 219 | if(!empty($v['route'])){ |
| @@ -173,9 +229,10 @@ class UpdateRoute extends Command | @@ -173,9 +229,10 @@ class UpdateRoute extends Command | ||
| 173 | // $route = RouteMap::setRoute($v['title'], RouteMap::SOURCE_PRODUCT, $v['id'], $v['project_id']); | 229 | // $route = RouteMap::setRoute($v['title'], RouteMap::SOURCE_PRODUCT, $v['id'], $v['project_id']); |
| 174 | // $productModel->edit(['route'=>$route],['id'=>$v['id']]); | 230 | // $productModel->edit(['route'=>$route],['id'=>$v['id']]); |
| 175 | } | 231 | } |
| 232 | + continue; | ||
| 176 | }else{ | 233 | }else{ |
| 177 | echo date('Y-m-d H:i:s') . 'id :'.$v['id'] . PHP_EOL; | 234 | echo date('Y-m-d H:i:s') . 'id :'.$v['id'] . PHP_EOL; |
| 178 | -// $v['title'] = Translate::tran($v['title'], 'en'); | 235 | + $v['title'] = Translate::tran($v['title'], 'en'); |
| 179 | $route = RouteMap::setRoute($v['title'], RouteMap::SOURCE_PRODUCT, $v['id'], $v['project_id']); | 236 | $route = RouteMap::setRoute($v['title'], RouteMap::SOURCE_PRODUCT, $v['id'], $v['project_id']); |
| 180 | $productModel->edit(['route'=>$route],['id'=>$v['id']]); | 237 | $productModel->edit(['route'=>$route],['id'=>$v['id']]); |
| 181 | } | 238 | } |
| @@ -278,4 +335,55 @@ class UpdateRoute extends Command | @@ -278,4 +335,55 @@ class UpdateRoute extends Command | ||
| 278 | RouteMap::setRoute($v['route'],'product_keyword',$v['id'],569); | 335 | RouteMap::setRoute($v['route'],'product_keyword',$v['id'],569); |
| 279 | } | 336 | } |
| 280 | } | 337 | } |
| 338 | + | ||
| 339 | + public function copyTable() | ||
| 340 | + { | ||
| 341 | + $sourceTable = 'gl_route_map'; | ||
| 342 | + $destinationTable = 'gl_route_map_copy'; | ||
| 343 | + | ||
| 344 | + if (!Schema::connection('custom_mysql')->hasTable($sourceTable)) { | ||
| 345 | + $this->error("Source table {$sourceTable} does not exist."); | ||
| 346 | + return false; | ||
| 347 | + } | ||
| 348 | + if (Schema::connection('custom_mysql')->hasTable($destinationTable)) { | ||
| 349 | + Schema::connection('custom_mysql')->dropIfExists($destinationTable); | ||
| 350 | + } | ||
| 351 | + $columns = DB::connection('custom_mysql')->select(DB::raw("SHOW COLUMNS FROM {$sourceTable}")); | ||
| 352 | + $columnsDefinition = collect($columns)->map(function($column) { | ||
| 353 | + $columnDefinition = $column->Field . ' ' . $column->Type . | ||
| 354 | + ($column->Null === 'NO' ? ' NOT NULL' : '') . | ||
| 355 | + ($column->Default !== null ? " DEFAULT '" . $column->Default . "'" : '') . | ||
| 356 | + ($column->Extra ? ' ' . $column->Extra : ''); | ||
| 357 | + return $columnDefinition; | ||
| 358 | + })->implode(', '); | ||
| 359 | + // Add PRIMARY KEY to the id column | ||
| 360 | + $primaryKey = collect($columns)->firstWhere('Field', 'id') ? 'PRIMARY KEY (id)' : ''; | ||
| 361 | + $columnsDefinition = $columnsDefinition . ($primaryKey ? ', ' . $primaryKey : ''); | ||
| 362 | + DB::connection('custom_mysql')->statement("CREATE TABLE {$destinationTable} ({$columnsDefinition})"); | ||
| 363 | + DB::connection('custom_mysql')->statement("INSERT INTO {$destinationTable} SELECT * FROM {$sourceTable}"); | ||
| 364 | + $this->info("Table {$sourceTable} has been copied to {$destinationTable} successfully."); | ||
| 365 | + } | ||
| 366 | + | ||
| 367 | + | ||
| 368 | + /** | ||
| 369 | + * @remark :routeMap去重 | ||
| 370 | + * @name :routeMapDeduplication | ||
| 371 | + * @author :lyh | ||
| 372 | + * @method :post | ||
| 373 | + * @time :2024/5/28 11:31 | ||
| 374 | + */ | ||
| 375 | + public function routeMapDeduplication(){ | ||
| 376 | + $routeMapModel = new RouteMap(); | ||
| 377 | + $lists = $routeMapModel->list(['source'=>'product_keyword'],'id',['id'],'asc'); | ||
| 378 | + foreach ($lists as $v){ | ||
| 379 | + echo date('Y-m-d H:i:s') . '关键字id:'.$v['id'] . PHP_EOL; | ||
| 380 | + //查询当前数据详情 | ||
| 381 | + $info = $routeMapModel->read(['id'=>$v['id']],['id','source_id']); | ||
| 382 | + if($info !== false){ | ||
| 383 | + //删除其他一样的数据 | ||
| 384 | + $routeMapModel->del(['id'=>['!=',$info['id']],'source'=>'product_keyword','source_id'=>$info['source_id']]); | ||
| 385 | + } | ||
| 386 | + } | ||
| 387 | + return true; | ||
| 388 | + } | ||
| 281 | } | 389 | } |
| @@ -47,7 +47,7 @@ class HtmlCollect extends Command | @@ -47,7 +47,7 @@ class HtmlCollect extends Command | ||
| 47 | 47 | ||
| 48 | public function handle() | 48 | public function handle() |
| 49 | { | 49 | { |
| 50 | - ini_set('memory_limit', '512M'); | 50 | + ini_set('memory_limit', '1024M'); |
| 51 | while (true) { | 51 | while (true) { |
| 52 | $this->start_collect(); | 52 | $this->start_collect(); |
| 53 | } | 53 | } |
| @@ -92,8 +92,6 @@ class HtmlCollect extends Command | @@ -92,8 +92,6 @@ class HtmlCollect extends Command | ||
| 92 | try { | 92 | try { |
| 93 | $html = curl_c('https://' . $collect_info->domain . $collect_info->route, false); | 93 | $html = curl_c('https://' . $collect_info->domain . $collect_info->route, false); |
| 94 | if (strlen($html) < 4) { | 94 | if (strlen($html) < 4) { |
| 95 | - $collect_info->status = CollectTask::STATUS_FAIL; | ||
| 96 | - $collect_info->save(); | ||
| 97 | 95 | ||
| 98 | if ($html == 404) { | 96 | if ($html == 404) { |
| 99 | //原数据页面404,需要将6.0数据存入草稿箱 | 97 | //原数据页面404,需要将6.0数据存入草稿箱 |
| @@ -123,7 +121,9 @@ class HtmlCollect extends Command | @@ -123,7 +121,9 @@ class HtmlCollect extends Command | ||
| 123 | $model = new BCustomTemplate(); | 121 | $model = new BCustomTemplate(); |
| 124 | $status_draft = BCustomTemplate::STATUS_DRAFT; | 122 | $status_draft = BCustomTemplate::STATUS_DRAFT; |
| 125 | } | 123 | } |
| 126 | - $model->edit(['status' => $status_draft], ['project_id' => $project_id, 'id' => $collect_info->source_id]); | 124 | + $model->edit(['status' => $status_draft], ['project_id' => $project_id, 'id' => $collect_info->source_id, 'six_read' => 1]); |
| 125 | + | ||
| 126 | + CollectTask::where('source', $collect_info->source)->where('source_id', $collect_info->source_id)->delete(); | ||
| 127 | } | 127 | } |
| 128 | 128 | ||
| 129 | echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', collect_id: ' . $collect_id . ', error: ' . $html . PHP_EOL; | 129 | echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', collect_id: ' . $collect_id . ', error: ' . $html . PHP_EOL; |
| @@ -347,6 +347,14 @@ class HtmlCollect extends Command | @@ -347,6 +347,14 @@ class HtmlCollect extends Command | ||
| 347 | $source[] = $check_vv2; | 347 | $source[] = $check_vv2; |
| 348 | } | 348 | } |
| 349 | } | 349 | } |
| 350 | + preg_match_all('/<iframe\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $html, $result_video_3); | ||
| 351 | + $video_3 = $result_video_3[2] ?? []; | ||
| 352 | + foreach ($video_3 as $vv3) { | ||
| 353 | + $check_vv3 = $this->url_check($vv3, $project_id, $domain, $web_url_domain, $home_url); | ||
| 354 | + if ($check_vv3 && (!in_array($check_vv3, $source))) { | ||
| 355 | + $source[] = $check_vv3; | ||
| 356 | + } | ||
| 357 | + } | ||
| 350 | 358 | ||
| 351 | //css | 359 | //css |
| 352 | preg_match_all('/<link\s+[^>]*?href\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $html, $result_css); | 360 | preg_match_all('/<link\s+[^>]*?href\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $html, $result_css); |
| @@ -434,7 +442,12 @@ class HtmlCollect extends Command | @@ -434,7 +442,12 @@ class HtmlCollect extends Command | ||
| 434 | foreach ($source as $vs) { | 442 | foreach ($source as $vs) { |
| 435 | 443 | ||
| 436 | if ($vs['download']) { | 444 | if ($vs['download']) { |
| 437 | - $new_source = CosService::uploadRemote($project_id, 'source', $vs['url_complete']); | 445 | + if ($project_id == 1355 && in_array(substr($vs['url_complete'], -3), ['pdf', 'zip', 'rar', '.gz'])) { |
| 446 | + //项目id为1355的项目,可下载类资源要保持原名称,做特殊处理 | ||
| 447 | + $new_source = CosService::uploadRemote($project_id, 'source', $vs['url_complete'], '', '', 1); | ||
| 448 | + } else { | ||
| 449 | + $new_source = CosService::uploadRemote($project_id, 'source', $vs['url_complete']); | ||
| 450 | + } | ||
| 438 | if ($new_source) { | 451 | if ($new_source) { |
| 439 | CollectSource::insert([ | 452 | CollectSource::insert([ |
| 440 | 'project_id' => $project_id, | 453 | 'project_id' => $project_id, |
| @@ -308,6 +308,13 @@ class ProjectUpdate extends Command | @@ -308,6 +308,13 @@ class ProjectUpdate extends Command | ||
| 308 | $keyword_id = ',' . implode(',', array_column($keyword_arr, 'id')) . ','; | 308 | $keyword_id = ',' . implode(',', array_column($keyword_arr, 'id')) . ','; |
| 309 | } | 309 | } |
| 310 | } | 310 | } |
| 311 | + //产品参数 | ||
| 312 | + $attrs = []; | ||
| 313 | + if ($item['attr'] ?? []) { | ||
| 314 | + foreach ($item['attr'] as $k_attr => $attr) { | ||
| 315 | + $attrs[] = ['key' => $k_attr, 'value' => $attr]; | ||
| 316 | + } | ||
| 317 | + } | ||
| 311 | //名称去掉特殊符号 | 318 | //名称去掉特殊符号 |
| 312 | $item['ttile'] = $this->special2str($item['ttile'] ?? ''); | 319 | $item['ttile'] = $this->special2str($item['ttile'] ?? ''); |
| 313 | 320 | ||
| @@ -323,6 +330,7 @@ class ProjectUpdate extends Command | @@ -323,6 +330,7 @@ class ProjectUpdate extends Command | ||
| 323 | 'keyword_id' => $keyword_id, | 330 | 'keyword_id' => $keyword_id, |
| 324 | 'thumb' => isset($gallery[0]) ? Arr::a2s($gallery[0]) : '', | 331 | 'thumb' => isset($gallery[0]) ? Arr::a2s($gallery[0]) : '', |
| 325 | 'gallery' => Arr::a2s($gallery), | 332 | 'gallery' => Arr::a2s($gallery), |
| 333 | + 'attrs' => Arr::a2s($attrs), | ||
| 326 | 'seo_mate' => Arr::a2s([ | 334 | 'seo_mate' => Arr::a2s([ |
| 327 | 'title' => $item['ttile'], | 335 | 'title' => $item['ttile'], |
| 328 | 'keyword' => $item['keywords'] ?? '', | 336 | 'keyword' => $item['keywords'] ?? '', |
| @@ -353,6 +361,7 @@ class ProjectUpdate extends Command | @@ -353,6 +361,7 @@ class ProjectUpdate extends Command | ||
| 353 | 'keyword_id' => $keyword_id, | 361 | 'keyword_id' => $keyword_id, |
| 354 | 'thumb' => isset($gallery[0]) ? Arr::a2s($gallery[0]) : '', | 362 | 'thumb' => isset($gallery[0]) ? Arr::a2s($gallery[0]) : '', |
| 355 | 'gallery' => Arr::a2s($gallery), | 363 | 'gallery' => Arr::a2s($gallery), |
| 364 | + 'attrs' => Arr::a2s($attrs), | ||
| 356 | 'seo_mate' => Arr::a2s([ | 365 | 'seo_mate' => Arr::a2s([ |
| 357 | 'title' => $item['ttile'], | 366 | 'title' => $item['ttile'], |
| 358 | 'keyword' => $item['keywords'] ?? '', | 367 | 'keyword' => $item['keywords'] ?? '', |
| @@ -361,15 +370,20 @@ class ProjectUpdate extends Command | @@ -361,15 +370,20 @@ class ProjectUpdate extends Command | ||
| 361 | 'send_time' => $item['post_date'] ?? date('Y-m-d H:i:s'), | 370 | 'send_time' => $item['post_date'] ?? date('Y-m-d H:i:s'), |
| 362 | 'sort' => $item['sort'] ?? 0, | 371 | 'sort' => $item['sort'] ?? 0, |
| 363 | ], ['id' => $id]); | 372 | ], ['id' => $id]); |
| 373 | + } else { | ||
| 374 | + //按6.0展示只更新分类 | ||
| 375 | + $model->edit([ | ||
| 376 | + 'category_id' => $category_id | ||
| 377 | + ], ['id' => $id]); | ||
| 364 | } | 378 | } |
| 365 | } | 379 | } |
| 366 | 380 | ||
| 367 | - if ($six_read) { | ||
| 368 | - //关联分类 | ||
| 369 | - if ($category_arr) { | ||
| 370 | - CategoryRelated::saveRelated($id, array_column($category_arr, 'id')); | ||
| 371 | - } | 381 | + //关联分类 |
| 382 | + if ($category_arr) { | ||
| 383 | + CategoryRelated::saveRelated($id, array_column($category_arr, 'id')); | ||
| 384 | + } | ||
| 372 | 385 | ||
| 386 | + if ($six_read) { | ||
| 373 | //扩展字段 | 387 | //扩展字段 |
| 374 | if ($item['extend'] ?? []) { | 388 | if ($item['extend'] ?? []) { |
| 375 | foreach (array_reverse($item['extend']) as $ke => $ve) { | 389 | foreach (array_reverse($item['extend']) as $ke => $ve) { |
| @@ -649,9 +663,17 @@ class ProjectUpdate extends Command | @@ -649,9 +663,17 @@ class ProjectUpdate extends Command | ||
| 649 | $new_img = $this->source_download($image, $project_id, $domain_arr['host'], $web_url_domain, $home_url); | 663 | $new_img = $this->source_download($image, $project_id, $domain_arr['host'], $web_url_domain, $home_url); |
| 650 | //名称去掉特殊符号 | 664 | //名称去掉特殊符号 |
| 651 | $item['title'] = $this->special2str($item['title'] ?? ''); | 665 | $item['title'] = $this->special2str($item['title'] ?? ''); |
| 666 | + //排序 | ||
| 667 | + $sort = 0; | ||
| 668 | + if (isset($item['listorder'])) { | ||
| 669 | + $sort = $item['listorder']; | ||
| 670 | + } | ||
| 671 | + if (isset($item['sort'])) { | ||
| 672 | + $sort = $item['sort']; | ||
| 673 | + } | ||
| 652 | 674 | ||
| 653 | try { | 675 | try { |
| 654 | - $custom_content = $model->read(['route' => $route], ['id','six_read']); | 676 | + $custom_content = $model->read(['route' => $route], ['id', 'six_read']); |
| 655 | if (!$custom_content) { | 677 | if (!$custom_content) { |
| 656 | $id = $model->insertGetId([ | 678 | $id = $model->insertGetId([ |
| 657 | 'project_id' => $project_id, | 679 | 'project_id' => $project_id, |
| @@ -659,7 +681,7 @@ class ProjectUpdate extends Command | @@ -659,7 +681,7 @@ class ProjectUpdate extends Command | ||
| 659 | 'module_id' => $custom_info['id'], | 681 | 'module_id' => $custom_info['id'], |
| 660 | 'category_id' => $category_id, | 682 | 'category_id' => $category_id, |
| 661 | 'content' => $item['content'] ?? '', | 683 | 'content' => $item['content'] ?? '', |
| 662 | - 'sort' => $item['sort'] ?? 0, | 684 | + 'sort' => $sort, |
| 663 | 'image' => $new_img, | 685 | 'image' => $new_img, |
| 664 | 'created_at' => $item['post_time'] ?? date('Y-m-d H:i:s'), | 686 | 'created_at' => $item['post_time'] ?? date('Y-m-d H:i:s'), |
| 665 | 'updated_at' => $item['post_time'] ?? date('Y-m-d H:i:s'), | 687 | 'updated_at' => $item['post_time'] ?? date('Y-m-d H:i:s'), |
| @@ -675,12 +697,12 @@ class ProjectUpdate extends Command | @@ -675,12 +697,12 @@ class ProjectUpdate extends Command | ||
| 675 | } else { | 697 | } else { |
| 676 | $id = $custom_content['id']; | 698 | $id = $custom_content['id']; |
| 677 | $six_read = $custom_content['six_read']; | 699 | $six_read = $custom_content['six_read']; |
| 678 | - if($six_read){ | 700 | + if ($six_read) { |
| 679 | $model->edit([ | 701 | $model->edit([ |
| 680 | 'name' => $item['title'], | 702 | 'name' => $item['title'], |
| 681 | 'category_id' => $category_id, | 703 | 'category_id' => $category_id, |
| 682 | 'content' => $item['content'] ?? '', | 704 | 'content' => $item['content'] ?? '', |
| 683 | - 'sort' => $item['sort'] ?? 0, | 705 | + 'sort' => $sort, |
| 684 | 'release_at' => $item['post_time'] ?? date('Y-m-d H:i:s'), | 706 | 'release_at' => $item['post_time'] ?? date('Y-m-d H:i:s'), |
| 685 | 'image' => $new_img | 707 | 'image' => $new_img |
| 686 | ], ['id' => $id]); | 708 | ], ['id' => $id]); |
| @@ -688,7 +710,7 @@ class ProjectUpdate extends Command | @@ -688,7 +710,7 @@ class ProjectUpdate extends Command | ||
| 688 | } | 710 | } |
| 689 | 711 | ||
| 690 | //扩展字段 | 712 | //扩展字段 |
| 691 | - if($six_read){ | 713 | + if ($six_read) { |
| 692 | if ($item['extend'] ?? []) { | 714 | if ($item['extend'] ?? []) { |
| 693 | foreach ($item['extend'] as $ke => $ve) { | 715 | foreach ($item['extend'] as $ke => $ve) { |
| 694 | $extend = $extend_model->read(['title' => $ke]); | 716 | $extend = $extend_model->read(['title' => $ke]); |
| @@ -776,11 +798,7 @@ class ProjectUpdate extends Command | @@ -776,11 +798,7 @@ class ProjectUpdate extends Command | ||
| 776 | //获取地址路由 | 798 | //获取地址路由 |
| 777 | protected function get_url_route($url) | 799 | protected function get_url_route($url) |
| 778 | { | 800 | { |
| 779 | - if (strpos($url, '%ec') !== false) { | ||
| 780 | - $url = str_replace('%ec', 'v6SpecialStr', $url); | ||
| 781 | - $url = urldecode($url); | ||
| 782 | - $url = str_replace('v6SpecialStr', '%ec', $url); | ||
| 783 | - } else { | 801 | + if (strpos($url, '%3A') !== false || strpos($url, '%2F') !== false) { |
| 784 | $url = urldecode($url); | 802 | $url = urldecode($url); |
| 785 | } | 803 | } |
| 786 | $arr = parse_url($url); | 804 | $arr = parse_url($url); |
-
请 注册 或 登录 后发表评论