|
...
|
...
|
@@ -5,6 +5,7 @@ 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\CollectSource;
|
|
|
|
use App\Models\Collect\CollectTask;
|
|
|
|
use App\Models\Com\UpdateLog;
|
|
|
|
use App\Models\News\News;
|
|
...
|
...
|
@@ -14,6 +15,7 @@ use App\Models\Product\Product; |
|
|
|
use App\Models\RouteMap\RouteMap;
|
|
|
|
use App\Models\Template\BCustomTemplate;
|
|
|
|
use App\Models\WebSetting\WebSettingReceiving;
|
|
|
|
use App\Services\CosService;
|
|
|
|
use App\Services\ProjectServer;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
...
|
...
|
@@ -79,10 +81,22 @@ class ProjectUpdate extends Command |
|
|
|
$domain_arr = parse_url($api_url);
|
|
|
|
//获取网站配置
|
|
|
|
$link_type = 0;
|
|
|
|
$web_url_domain = $domain_arr['host'];
|
|
|
|
$home_url = $domain_arr['host'];
|
|
|
|
$url_web_config = 'https://' . $domain_arr['host'] . '/wp-content/cache/user_config.text';
|
|
|
|
$data_config = curl_c($url_web_config);
|
|
|
|
if ($data_config) {
|
|
|
|
$link_type = $data_config['link_type'];
|
|
|
|
$link_type = $data_config['link_type'] ?? 0;
|
|
|
|
|
|
|
|
$web_url_arr = parse_url($data_config['web_url_domain'] ?? '');
|
|
|
|
if (isset($web_url_arr['host'])) {
|
|
|
|
$web_url_domain = $web_url_arr['host'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$home_url_arr = parse_url($data_config['home_url'] ?? '');
|
|
|
|
if (isset($home_url_arr['host'])) {
|
|
|
|
$home_url = $home_url_arr['host'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//获取所有语种
|
|
|
|
$language_list = [];
|
|
...
|
...
|
@@ -140,11 +154,10 @@ class ProjectUpdate extends Command |
|
|
|
'seo_title' => $item['seo_title'] ?? '',
|
|
|
|
'seo_keywords' => $item['seo_keywords'] ?? '',
|
|
|
|
'seo_description' => $item['seo_description'] ?? '',
|
|
|
|
'is_upgrade' => 1,
|
|
|
|
'route' => $route
|
|
|
|
]);
|
|
|
|
$this->set_map($route, RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $project_id);
|
|
|
|
|
|
|
|
CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $link_type, $language_list, $page_list);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
|
|
|
|
continue;
|
|
...
|
...
|
@@ -224,6 +237,8 @@ class ProjectUpdate extends Command |
|
|
|
$items = $data_page['data']['data'] ?? [];
|
|
|
|
|
|
|
|
$model = new Product();
|
|
|
|
$category_model = new Category();
|
|
|
|
$logic = new CategoryLogic();
|
|
|
|
|
|
|
|
foreach ($items as $item) {
|
|
|
|
$route = $this->get_url_route($item['url'] ?? '');
|
|
...
|
...
|
@@ -234,31 +249,39 @@ class ProjectUpdate extends Command |
|
|
|
$gallery = [];
|
|
|
|
if ($item['images'] ?? []) {
|
|
|
|
foreach ($item['images'] as $k_img => $img) {
|
|
|
|
$gallery[] = ['alt' => '这是一张产品图', 'url' => $img];
|
|
|
|
$gallery[] = ['alt' => '这是一张产品图', 'url' => $this->source_download($img, $project_id, $domain_arr['host'], $web_url_domain, $home_url)];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//分类
|
|
|
|
$category_id = '';
|
|
|
|
//产品类型,2Featured Products,3Hot Products
|
|
|
|
$product_type = '';
|
|
|
|
|
|
|
|
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[] = $this->special2str($return['name'] ?? '');
|
|
|
|
$pid = $return['id'];
|
|
|
|
$type_arr = [];
|
|
|
|
$new_category = [];
|
|
|
|
foreach ($item['category'] as $cate) {
|
|
|
|
if ($cate['parent'] == 0 && $cate['name'] == 'Featured Products') {
|
|
|
|
$type_arr[] = 2;
|
|
|
|
} elseif ($cate['parent'] == 0 && $cate['name'] == 'Hot Products') {
|
|
|
|
$type_arr[] = 3;
|
|
|
|
} else {
|
|
|
|
$new_category[] = $cate['id'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($category_arr) {
|
|
|
|
$categoryLogic = new CategoryLogic();
|
|
|
|
$category_id = $categoryLogic->importProductCategory($project_id, implode('/', $category_arr));
|
|
|
|
if ($type_arr) {
|
|
|
|
$product_type = ',' . implode(',', $type_arr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($new_category) {
|
|
|
|
$category_arr = $category_model->list(['original_id' => ['in', $new_category]]);
|
|
|
|
$category_id = $logic->getLastCategory(array_column($category_arr, 'id'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
$item['ttile'] = $this->special2str($item['ttile'] ?? '');
|
|
|
|
$id = $model->addReturnId([
|
|
|
|
$id = $model->insertGetId([
|
|
|
|
'project_id' => $project_id,
|
|
|
|
'title' => $item['ttile'],
|
|
|
|
'intro' => $item['description'] ?? '',
|
|
...
|
...
|
@@ -266,13 +289,18 @@ class ProjectUpdate extends Command |
|
|
|
'category_id' => $category_id,
|
|
|
|
'thumb' => isset($gallery[0]) ? Arr::a2s($gallery[0]) : '',
|
|
|
|
'gallery' => Arr::a2s($gallery),
|
|
|
|
'product_type' => $product_type,
|
|
|
|
'seo_mate' => Arr::a2s([
|
|
|
|
'title' => $item['ttile'],
|
|
|
|
'keyword' => $item['keywords'] ?? '',
|
|
|
|
'description' => $item['description'] ?? ''
|
|
|
|
]),
|
|
|
|
'status' => Product::STATUS_ON,
|
|
|
|
'created_at' => $item['post_date'] ?? date('Y-m-d H:i:s'),
|
|
|
|
'updated_at' => $item['post_date'] ?? date('Y-m-d H:i:s'),
|
|
|
|
'sort' => $item['sort'] ?? 0,
|
|
|
|
'is_upgrade' => 1,
|
|
|
|
'six_read' => 1,
|
|
|
|
'route' => $route
|
|
|
|
]);
|
|
|
|
$this->set_map($route, RouteMap::SOURCE_PRODUCT, $id, $project_id);
|
|
...
|
...
|
@@ -323,19 +351,21 @@ class ProjectUpdate extends Command |
|
|
|
} else {
|
|
|
|
$image = $item['images'] ?? '';
|
|
|
|
}
|
|
|
|
if (strpos($image, '//') === 0) {
|
|
|
|
$image = 'https:' . $image;
|
|
|
|
}
|
|
|
|
$id = $model->addReturnId([
|
|
|
|
|
|
|
|
$id = $model->insertGetId([
|
|
|
|
'project_id' => $project_id,
|
|
|
|
'name' => $item['ttile'],
|
|
|
|
'seo_title' => $item['ttile'],
|
|
|
|
'seo_keywords' => $item['keywords'] ?? '',
|
|
|
|
'seo_description' => $item['description'] ?? '',
|
|
|
|
'text' => $item['content'] ?? '',
|
|
|
|
'image' => $image,
|
|
|
|
'image' => $this->source_download($image, $project_id, $domain_arr['host'], $web_url_domain, $home_url),
|
|
|
|
'status' => $api_type == 'news' ? News::STATUS_ONE : Blog::STATUS_ONE,
|
|
|
|
'created_at' => $item['post_date'] ?? date('Y-m-d H:i:s'),
|
|
|
|
'updated_at' => $item['post_date'] ?? date('Y-m-d H:i:s'),
|
|
|
|
'sort' => $item['sort'] ?? 0,
|
|
|
|
'is_upgrade' => 1,
|
|
|
|
'six_read' => 1,
|
|
|
|
'url' => $route
|
|
|
|
]);
|
|
|
|
$this->set_map($route, $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id, $project_id);
|
|
...
|
...
|
@@ -376,7 +406,7 @@ class ProjectUpdate extends Command |
|
|
|
if (!$custom) {
|
|
|
|
try {
|
|
|
|
$item['ttile'] = $this->special2str($item['ttile'] ?? '');
|
|
|
|
$id = $model->addReturnId([
|
|
|
|
$id = $model->insertGetId([
|
|
|
|
'project_id' => $project_id,
|
|
|
|
'name' => $item['ttile'],
|
|
|
|
'title' => $item['ttile'],
|
|
...
|
...
|
@@ -384,7 +414,10 @@ class ProjectUpdate extends Command |
|
|
|
'description' => $item['description'] ?? '',
|
|
|
|
'html' => $item['content'] ?? '',
|
|
|
|
'status' => 1,
|
|
|
|
'created_at' => $item['post_date'] ?? date('Y-m-d H:i:s'),
|
|
|
|
'updated_at' => $item['post_date'] ?? date('Y-m-d H:i:s'),
|
|
|
|
'is_upgrade' => 1,
|
|
|
|
'six_read' => 1,
|
|
|
|
'url' => $route
|
|
|
|
]);
|
|
|
|
$this->set_map($route, RouteMap::SOURCE_PAGE, $id, $project_id);
|
|
...
|
...
|
@@ -424,7 +457,7 @@ class ProjectUpdate extends Command |
|
|
|
return $task_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
$task_list = UpdateLog::where('status', UpdateLog::STATUS_UN)->orderBy('project_id', 'asc')->orderBy('sort', 'asc')->limit(7)->get();
|
|
|
|
$task_list = UpdateLog::where('project_id', 543)->where('status', UpdateLog::STATUS_UN)->orderBy('project_id', 'asc')->orderBy('sort', 'asc')->limit(7)->get();
|
|
|
|
if ($task_list->count() == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
...
|
...
|
@@ -472,6 +505,7 @@ class ProjectUpdate extends Command |
|
|
|
'pid' => $pid,
|
|
|
|
'keywords' => $item['keywords'] ?? '',
|
|
|
|
'describe' => $item['description'] ?? '',
|
|
|
|
'original_id' => $item['id'],
|
|
|
|
'route' => $route
|
|
|
|
]);
|
|
|
|
$this->set_map($route, RouteMap::SOURCE_PRODUCT_CATE, $parent_id, $project_id);
|
|
...
|
...
|
@@ -490,18 +524,6 @@ class ProjectUpdate extends Command |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//获取分类名称数组
|
|
|
|
protected function get_category_name_arr($category, $pid = 0)
|
|
|
|
{
|
|
|
|
foreach ($category as $k => $v) {
|
|
|
|
if ($v['parent'] == $pid) {
|
|
|
|
return $v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
//特殊字符转换
|
|
|
|
protected function special2str($str)
|
|
|
|
{
|
|
...
|
...
|
@@ -547,4 +569,45 @@ class ProjectUpdate extends Command |
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//资源下载
|
|
|
|
protected function source_download($url, $project_id, $domain, $web_url_domain, $home_url)
|
|
|
|
{
|
|
|
|
if (!$url) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$arr = parse_url($url);
|
|
|
|
$scheme = $arr['scheme'] ?? '';
|
|
|
|
$host = $arr['host'] ?? '';
|
|
|
|
$path = $arr['path'] ?? '';
|
|
|
|
|
|
|
|
$url_complete = ($scheme ?: 'https') . '://' . ($host ?: $domain) . $path;
|
|
|
|
|
|
|
|
if ((empty($host) || $host == $web_url_domain || $host == $home_url) && $path) {
|
|
|
|
|
|
|
|
$source = CollectSource::where('project_id', $project_id)->where('origin', $url)->first();
|
|
|
|
if (!$source) {
|
|
|
|
$new_url = CosService::uploadRemote($project_id, 'image_product', $url_complete);
|
|
|
|
|
|
|
|
if ($new_url) {
|
|
|
|
CollectSource::insert([
|
|
|
|
'project_id' => $project_id,
|
|
|
|
'origin' => $url,
|
|
|
|
'target' => $new_url,
|
|
|
|
'created_at' => date('Y-m-d H:i:s'),
|
|
|
|
'updated_at' => date('Y-m-d H:i:s'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
return getImageUrl($new_url);
|
|
|
|
} else {
|
|
|
|
return $url_complete;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return getImageUrl($source['target']);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return $url_complete;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|