|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Console\Commands\Update;
|
|
|
|
|
|
|
|
use App\Helper\Arr;
|
|
|
|
use App\Http\Logic\Bside\Product\CategoryLogic;
|
|
|
|
use App\Models\Blog\Blog;
|
|
|
|
use App\Models\Collect\CollectTask;
|
|
|
|
use App\Models\Com\UpdateLog;
|
|
|
|
use App\Models\News\News;
|
|
|
|
use App\Models\Product\Category;
|
|
|
|
use App\Models\Product\Keyword;
|
|
|
|
use App\Models\Product\Product;
|
|
|
|
use App\Models\RouteMap\RouteMap;
|
|
|
|
use App\Models\Template\BCustomTemplate;
|
|
|
|
use App\Models\WebSetting\WebSettingReceiving;
|
|
|
|
use App\Services\ProjectServer;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use Illuminate\Support\Facades\Redis;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 4.0,5.0升级到6.0,内容同步
|
|
|
|
* Class ProjectImport
|
|
|
|
* @package App\Console\Commands
|
|
|
|
* @author Akun
|
|
|
|
* @date 2023/10/9 15:04
|
|
|
|
*/
|
|
|
|
class Temp2 extends Command
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $signature = 'project_update_temp2';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = '执行项目升级任务';
|
|
|
|
|
|
|
|
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
$this->start_update();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function start_update()
|
|
|
|
{
|
|
|
|
|
|
|
|
// $data = UpdateLog::where('project_id','<=',530)->where('api_type','category')->get();
|
|
|
|
$data = UpdateLog::where('project_id', '=', 298)->where('api_type', 'post')->get();
|
|
|
|
foreach ($data as $task) {
|
|
|
|
$project_id = $task->project_id;
|
|
|
|
$api_type = $task->api_type;
|
|
|
|
$api_url_arr = explode('?', $task->api_url);
|
|
|
|
$api_url = $api_url_arr[0];
|
|
|
|
|
|
|
|
$page_size = 20;
|
|
|
|
|
|
|
|
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', task_type: ' . $api_type . ', update start' . PHP_EOL;
|
|
|
|
|
|
|
|
//设置数据库
|
|
|
|
$project = ProjectServer::useProject($project_id);
|
|
|
|
if ($project) {
|
|
|
|
//产品
|
|
|
|
$url = $api_url . '?' . http_build_query(['w' => 'post', 'page' => 1, 'pagesize' => 0]);
|
|
|
|
$data = curl_c($url);
|
|
|
|
if (isset($data['code']) && $data['code'] == 200) {
|
|
|
|
$count = $data['data']['count'] ?? 0;
|
|
|
|
|
|
|
|
$total_page = ceil($count / $page_size);
|
|
|
|
for ($page = 1; $page <= $total_page; $page++) {
|
|
|
|
$url_page = $api_url . '?' . http_build_query(['w' => 'post', 'page' => $page, 'pagesize' => $page_size]);
|
|
|
|
$data_page = curl_c($url_page);
|
|
|
|
if (isset($data_page['code']) && $data_page['code'] == 200) {
|
|
|
|
$items = $data_page['data']['data'] ?? [];
|
|
|
|
|
|
|
|
$model = new Product();
|
|
|
|
|
|
|
|
foreach ($items as $item) {
|
|
|
|
if ($item['ttile'] ?? '') {
|
|
|
|
$product = $model->read(['title' => $item['ttile']], 'id');
|
|
|
|
if ($product) {
|
|
|
|
//分类
|
|
|
|
$category_id = '';
|
|
|
|
if ($item['category'] ?? []) {
|
|
|
|
$category_arr = [];
|
|
|
|
|
|
|
|
$pid = 0;
|
|
|
|
for ($i = 0; $i < count($item['category']); $i++) {
|
|
|
|
$return = $this->get_category_name_arr($item['category'], $pid);
|
|
|
|
if ($return) {
|
|
|
|
$category_arr[] = $return['name'];
|
|
|
|
$pid = $return['id'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($category_arr) {
|
|
|
|
$categoryLogic = new CategoryLogic();
|
|
|
|
$category_id = $categoryLogic->importProductCategory($project_id, implode('/', $category_arr));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
$model->edit(['category_id' => $category_id], ['id' => $product['id']]);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//关闭数据库
|
|
|
|
DB::disconnect('custom_mysql');
|
|
|
|
|
|
|
|
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', task_type: ' . $api_type . ', update end ' . PHP_EOL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//获取分类名称数组
|
|
|
|
protected function get_category_name_arr($category, $pid = 0)
|
|
|
|
{
|
|
|
|
foreach ($category as $k => $v) {
|
|
|
|
if ($v['parent'] == $pid) {
|
|
|
|
return $v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|