作者 lyh

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

<?php
namespace App\Console\Commands\Test;
use App\Models\Collect\CollectTask;
use App\Models\Com\UpdateLog;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class Temp extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'test_temp';
/**
* The console command description.
*
* @var string
*/
protected $description = '临时脚本';
public function handle()
{
$data = UpdateLog::where('sort', 0)->get();
foreach ($data as $item) {
$project_id = $item->project_id;
$project = ProjectServer::useProject($project_id);
if ($project) {
try {
DB::connection('custom_mysql')->statement("ALTER TABLE `gl_product_category` ADD COLUMN `original_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '来源id'");
} catch (\Exception $e) {
echo $project_id . '已存在';
continue;
}
}
//关闭数据库
DB::disconnect('custom_mysql');
echo $project_id.'成功';
}
}
}
... ...
... ... @@ -237,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'] ?? '');
... ... @@ -256,33 +258,26 @@ class ProjectUpdate extends Command
$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'];
}
}
if ($category_arr) {
$categoryLogic = new CategoryLogic();
$category_id = $categoryLogic->importProductCategory($project_id, implode('/', $category_arr));
}
$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 ($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'] ?? '');
... ... @@ -507,6 +502,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);
... ... @@ -525,18 +521,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)
{
... ...
... ... @@ -154,6 +154,9 @@ class ProductLogic extends BaseLogic
}else{
$this->param['thumb'] = Arr::a2s([]);
}
if(isset($this->param['route']) && !empty($this->param['route'])){
$this->param['route'] = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT, $this->param['id'], $this->user['project_id']);
}
$this->model->edit($this->param,['id'=>$this->param['id']]);
return $this->success();
}
... ...