作者 lyh

gx

<?php
/**
* @remark :
* @name :UpdateProductCategory.php
* @author :lyh
* @method :post
* @time :2023/12/6 16:07
*/
namespace App\Console\Commands;
use App\Models\Product\Category;
use App\Models\Product\CategoryRelated;
use App\Models\Product\Product;
use App\Models\Project\Project;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
/**
* @remark :更新分类
* @name :UpdateProductCategory
* @author :lyh
* @method :post
* @time :2023/12/6 16:07
*/
class UpdateProductCategory extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'update_product_cate';
/**
* The console command description.
*
* @var string
*/
protected $description = '更新产品分类';
/**
* @remark :执行方法
* @name :handle
* @author :lyh
* @method :post
* @time :2023/12/6 16:09
*/
public function handle(){
//获取所有项目
$projectModel = new Project();
$list = $projectModel->list(['type'=>['in',[1,2,3,4],'project_id'=>1]]);
try {
foreach ($list as $v) {
echo date('Y-m-d H:i:s') . ' start: ' . $v['id'] . PHP_EOL;
ProjectServer::useProject($v['id']);
$this->getUpdateProductCategory($v['id']);
DB::disconnect('custom_mysql');
}
}catch (\Exception $e){
echo date('Y-m-d H:i:s') . ' error: ->' . $e->getMessage() . PHP_EOL;
}
echo date('Y-m-d H:i:s') . ' end: ' . PHP_EOL;
}
/**
* @remark :更新
* @name :getUpdateProductCategory
* @author :lyh
* @method :post
* @time :2023/12/6 16:12
*/
public function getUpdateProductCategory(){
$productModel = new Product();
$lists = $productModel->list(['status'=>1],'id',['id','category_id']);
foreach ($lists as $k => $v){
if(!empty($v['category_id'])){
$this->handleCategory($v['id'],$v['category_id']);
}
}
return true;
}
/**
* @remark :处理分类
* @name :handleCategory
* @author :lyh
* @method :post
* @time :2023/12/6 16:20
*/
public function handleCategory($id,$category){
$category = trim($category,',');
$cate_arr = explode(',',$category);
if(!empty($cate_arr) && is_array($cate_arr)){
foreach ($cate_arr as $v){
$categoryModel = new Category();
$info = $categoryModel->read(['pid'=>$v],['id']);
if($info === false){
//有下级时,跳过
continue;
}else{
//更新关联表
$cateRelatedModel = new CategoryRelated();
$relateInfo = $cateRelatedModel->read(['product_id'=>$id,'cate_id'=>$v]);
if($relateInfo === false){
$cateRelatedModel->add(['product_id'=>$id, 'cate_id'=>$v]);
}
}
}
}
}
}
... ...
... ... @@ -138,6 +138,14 @@ class OnlineController extends BaseController
$query->where('gl_project.title', 'like', '%' . $this->map['search'] . '%');
}
}
if(isset($this->map['qa_status']) && !empty($this->map['qa_status'])){
// 搜索状态
$query->where('gl_project_online_check.qa_status',$this->map['qa_status']);
}
if(isset($this->map['optimist_status']) && !empty($this->map['optimist_status'])){
// 搜索状态
$query->where('gl_project_online_check.optimist_status',$this->map['optimist_status']);
}
$query = $query->where('gl_project.status',1);//TODO::已提交审核
return $query;
}
... ...
... ... @@ -391,7 +391,6 @@ class BTemplateLogic extends BaseLogic
*/
public function templateSaveParam($param){
$param['project_id'] = $this->user['project_id'];
$param['html'] = $param['main_html'];
unset($param['head_html'],$param['head_css'],$param['footer_html'],$param['footer_css']);
return $this->success($param);
}
... ...