You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
411 lines
18 KiB
411 lines
18 KiB
<?php
|
|
|
|
declare (strict_types=1);
|
|
|
|
namespace app\command;
|
|
|
|
use think\console\Command;
|
|
use think\console\Output;
|
|
use think\console\Input;
|
|
use think\facade\Db;
|
|
use app\common\model\MaintenanceCategory;
|
|
use app\common\model\Maintenance;
|
|
use app\common\model\article\Category;
|
|
use app\common\model\Article;
|
|
use app\common\model\Store;
|
|
use app\common\model\Agreement;
|
|
use app\common\model\UploadFile;
|
|
use app\store\model\server\RecoveryCategory;
|
|
use app\store\model\server\ServerRecovery;
|
|
use app\store\model\server\Server;
|
|
use app\store\model\ServerCategory;
|
|
|
|
// /www/server/php/74/bin/php /server/wwwroot/yanzong/think test
|
|
class SyncStoreBasicData extends Command
|
|
{
|
|
const DEFAULT_STORE_ID = 10048;
|
|
|
|
protected function configure()
|
|
{
|
|
// 指令配置
|
|
$this->setName('SyncStoreBasicData')->setDescription('同步商城基础数据');
|
|
$this->addArgument("store_id");
|
|
$this->addArgument("isSyncMaintenanceData");
|
|
$this->addArgument("isSyncHelpData");
|
|
$this->addArgument("isSyncRichTextData");
|
|
$this->addArgument("isSyncRecoveryData");
|
|
$this->addArgument("isSyncServerData");
|
|
}
|
|
|
|
protected function execute(Input $input, Output $output)
|
|
{
|
|
$store_id = $input->getArgument("store_id");
|
|
$isSyncMaintenanceData = $input->getArgument("isSyncMaintenanceData");
|
|
$isSyncHelpData = $input->getArgument("isSyncHelpData");
|
|
$isSyncRichTextData = $input->getArgument("isSyncRichTextData");
|
|
|
|
$where[] = ['is_sync','=', 0];
|
|
$where[] = ['is_delete','=', 0];
|
|
$where[] = ['is_recycle','=', 0];
|
|
$where[] = ['status','=', 1];
|
|
|
|
if ($store_id) {
|
|
$where[] = ['store_id','=', $store_id];
|
|
} else {
|
|
$where[] = ['store_id', '<>', self::DEFAULT_STORE_ID];
|
|
}
|
|
$stores = Store::where($where)->field('store_id,is_sync,is_recycle,status,is_delete')->select()->toArray();
|
|
// echo "<pre>";
|
|
// print_r($stores);
|
|
// exit();
|
|
if (!$stores) {
|
|
echo "没有要同步的商城了";
|
|
return;
|
|
}
|
|
foreach ($stores as $store) {
|
|
if ($isSyncMaintenanceData) {
|
|
$this->syncMaintenanceData($store);
|
|
}
|
|
if ($isSyncHelpData) {
|
|
$this->syncHelpData($store);
|
|
}
|
|
if ($isSyncRichTextData) {
|
|
$this->syncRichTextData($store);
|
|
}
|
|
Store::where('store_id', $store['store_id'])->update(['is_sync' => 1]);
|
|
}
|
|
|
|
|
|
}
|
|
/**
|
|
* 同步富文本数据
|
|
* [syncHelpData description]
|
|
* @param [type] $store [description]
|
|
* @return [type] [description]
|
|
*/
|
|
private function syncRichTextData($store){
|
|
//维修分类数据同步
|
|
$agreementList = Agreement::where('store_id',self::DEFAULT_STORE_ID)->select()->toArray();
|
|
if ($agreementList) {
|
|
foreach ($agreementList as &$agreement) {
|
|
$info = Agreement::where('store_id', $store['store_id'])->where('original_id', $agreement['id'])->find();
|
|
if ($info) {
|
|
echo $agreement['id']."富文本已存在".PHP_EOL;
|
|
continue;
|
|
}
|
|
$agreement['create_time'] = time();
|
|
$agreement['update_time'] = time();
|
|
$agreement['original_id'] = $agreement['id'];
|
|
$agreement['store_id'] = $store['store_id'];
|
|
unset($agreement['id']);
|
|
$ret = Agreement::create($agreement);
|
|
var_dump($ret->id);
|
|
}
|
|
unset($agreement);
|
|
}
|
|
}
|
|
/**
|
|
* 同步帮助中心数据
|
|
* [syncHelpData description]
|
|
* @param [type] $store [description]
|
|
* @return [type] [description]
|
|
*/
|
|
private function syncHelpData($store){
|
|
//维修分类数据同步
|
|
$articleCategoryList = Category::where('store_id',self::DEFAULT_STORE_ID)->where('status', 1)->select()->toArray();
|
|
if ($articleCategoryList) {
|
|
foreach ($articleCategoryList as &$articleCategory) {
|
|
$info = Category::where('store_id', $store['store_id'])->where('original_id', $articleCategory['category_id'])->find();
|
|
if ($info) {
|
|
echo $articleCategory['category_id']."帮助分类已存在".PHP_EOL;
|
|
continue;
|
|
}
|
|
$articleCategory['create_time'] = time();
|
|
$articleCategory['update_time'] = time();
|
|
$articleCategory['original_id'] = $articleCategory['category_id'];
|
|
$articleCategory['store_id'] = $store['store_id'];
|
|
unset($articleCategory['category_id']);
|
|
|
|
//复制图片
|
|
$upload_file = Db::name('upload_file')->where('file_id', $articleCategory['img_id'])->find();
|
|
if ($upload_file) {
|
|
$upload_file['store_id'] = $store['store_id'];
|
|
$upload_file['create_time'] = time();
|
|
unset($upload_file['file_id']);
|
|
$image_id = Db::name('upload_file')->insertGetId($upload_file);
|
|
}
|
|
//写入维修数据
|
|
$articleCategory['img_id'] = $image_id ?? 0;
|
|
$ret = Category::create($articleCategory);
|
|
var_dump($ret->id);
|
|
}
|
|
unset($articleCategory);
|
|
}
|
|
|
|
//维修数据同步
|
|
$articleList = Article::where('store_id',self::DEFAULT_STORE_ID)->where('is_delete', 0)->where('status', 1)->select()->toArray();
|
|
if ($articleList) {
|
|
foreach ($articleList as &$article) {
|
|
$info = Article::where('store_id', $store['store_id'])->where('original_id', $article['article_id'])->find();
|
|
if ($info) {
|
|
echo $article['article_id']."帮助已存在".PHP_EOL;
|
|
continue;
|
|
}
|
|
//查询分类id
|
|
$articleCategory = Category::where('original_id', $article['category_id'])->where('store_id', $store['store_id'])->find();
|
|
if (!$articleCategory) {
|
|
continue;
|
|
}
|
|
$article['create_time'] = time();
|
|
$article['update_time'] = time();
|
|
$article['original_id'] = $article['article_id'];
|
|
$article['category_id'] = $articleCategory['category_id'];
|
|
$article['store_id'] = $store['store_id'];
|
|
unset($article['article_id']);
|
|
//复制图片
|
|
$upload_file = Db::name('upload_file')->where('file_id', $article['image_id'])->find();
|
|
if ($upload_file) {
|
|
$upload_file['store_id'] = $store['store_id'];
|
|
$upload_file['create_time'] = time();
|
|
unset($upload_file['file_id']);
|
|
$image_id = Db::name('upload_file')->insertGetId($upload_file);
|
|
}
|
|
//写入维修数据
|
|
$article['image_id'] = $image_id;
|
|
$ret = Article::create($article);
|
|
//写入图片id
|
|
var_dump($ret->id);
|
|
}
|
|
unset($article);
|
|
}
|
|
}
|
|
/**
|
|
* 同步维修数据
|
|
* [syncMaintenanceData description]
|
|
* @param [type] $store [description]
|
|
* @return [type] [description]
|
|
*/
|
|
private function syncMaintenanceData($store){
|
|
//维修分类数据同步
|
|
$maintenanceCategoryList = MaintenanceCategory::where('store_id',self::DEFAULT_STORE_ID)->where('status', 1)->select()->toArray();
|
|
|
|
if ($maintenanceCategoryList) {
|
|
foreach ($maintenanceCategoryList as &$maintenanceCategory) {
|
|
$info = MaintenanceCategory::where('store_id', $store['store_id'])->where('original_id', $maintenanceCategory['id'])->find();
|
|
if ($info) {
|
|
echo $maintenanceCategory['id']."维修分类已存在".PHP_EOL;
|
|
continue;
|
|
}
|
|
$maintenanceCategory['create_time'] = time();
|
|
$maintenanceCategory['update_time'] = time();
|
|
$maintenanceCategory['original_id'] = $maintenanceCategory['id'];
|
|
$maintenanceCategory['store_id'] = $store['store_id'];
|
|
unset($maintenanceCategory['id']);
|
|
// echo "<pre>";
|
|
// print_r($maintenanceCategory);
|
|
// exit();
|
|
$ret = MaintenanceCategory::create($maintenanceCategory);
|
|
var_dump($ret->id);
|
|
}
|
|
unset($maintenanceCategory);
|
|
}
|
|
|
|
//维修数据同步
|
|
$maintenanceList = Maintenance::where('store_id',self::DEFAULT_STORE_ID)->where('is_delete', 0)->select()->toArray();
|
|
|
|
if ($maintenanceList) {
|
|
foreach ($maintenanceList as &$maintenance) {
|
|
$info = Maintenance::where('store_id', $store['store_id'])->where('original_id', $maintenance['id'])->find();
|
|
if ($info) {
|
|
echo $maintenance['id']."维修已存在".PHP_EOL;
|
|
continue;
|
|
}
|
|
// echo "<pre>";
|
|
// print_r($info);
|
|
// exit();
|
|
//查询分类id
|
|
$maintenanceCategory = MaintenanceCategory::where('original_id', $maintenance['category_id'])->where('store_id', $store['store_id'])->find();
|
|
if (!$maintenanceCategory) {
|
|
continue;
|
|
}
|
|
$maintenance['create_time'] = time();
|
|
$maintenance['update_time'] = time();
|
|
$maintenance['original_id'] = $maintenance['id'];
|
|
$maintenance['category_id'] = $maintenanceCategory['id'];
|
|
$maintenance['store_id'] = $store['store_id'];
|
|
unset($maintenance['id']);
|
|
//复制图片
|
|
$upload_file = Db::name('upload_file')->where('file_id', $maintenance['img_id'])->find();
|
|
if ($upload_file) {
|
|
$upload_file['store_id'] = $store['store_id'];
|
|
$upload_file['create_time'] = time();
|
|
unset($upload_file['file_id']);
|
|
// echo "<pre>";
|
|
// print_r($upload_file);
|
|
// exit();
|
|
$image_id = Db::name('upload_file')->insertGetId($upload_file);
|
|
}
|
|
|
|
//写入维修数据
|
|
$maintenance['img_id'] = $image_id ?? 0;
|
|
$ret = Maintenance::create($maintenance);
|
|
//写入图片id
|
|
var_dump($ret->id);
|
|
}
|
|
unset($maintenance);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 同步回收数据
|
|
* [syncHelpData description]
|
|
* @param [type] $store [description]
|
|
* @return [type] [description]
|
|
*/
|
|
private function syncRecoveryData($store){
|
|
//维修分类数据同步
|
|
$articleCategoryList = RecoveryCategory::where('store_id',self::DEFAULT_STORE_ID)->where('status', 1)->select()->toArray();
|
|
if ($articleCategoryList) {
|
|
foreach ($articleCategoryList as &$articleCategory) {
|
|
$info = RecoveryCategory::where('store_id', $store['store_id'])->where('original_id', $articleCategory['category_id'])->find();
|
|
if ($info) {
|
|
echo $articleCategory['category_id']."回收已存在".PHP_EOL;
|
|
continue;
|
|
}
|
|
$articleCategory['create_time'] = time();
|
|
$articleCategory['update_time'] = time();
|
|
$articleCategory['original_id'] = $articleCategory['category_id'];
|
|
$articleCategory['store_id'] = $store['store_id'];
|
|
unset($articleCategory['category_id']);
|
|
|
|
//复制图片
|
|
$upload_file = Db::name('upload_file')->where('file_id', $articleCategory['image_id'])->find();
|
|
if ($upload_file) {
|
|
$upload_file['store_id'] = $store['store_id'];
|
|
$upload_file['create_time'] = time();
|
|
unset($upload_file['file_id']);
|
|
$image_id = Db::name('upload_file')->insertGetId($upload_file);
|
|
}
|
|
//写入维修数据
|
|
$articleCategory['image_id'] = $image_id ?? 0;
|
|
$ret = RecoveryCategory::create($articleCategory);
|
|
var_dump($ret->id);
|
|
}
|
|
unset($articleCategory);
|
|
}
|
|
|
|
//维修数据同步
|
|
$articleList = ServerRecovery::where('store_id',self::DEFAULT_STORE_ID)->where('is_delete', 0)->where('status', 1)->select()->toArray();
|
|
if ($articleList) {
|
|
foreach ($articleList as &$article) {
|
|
$info = ServerRecovery::where('store_id', $store['store_id'])->where('original_id', $article['recovery_id'])->find();
|
|
if ($info) {
|
|
echo $article['recovery_id']."回收已存在".PHP_EOL;
|
|
continue;
|
|
}
|
|
//查询分类id
|
|
$articleCategory = RecoveryCategory::where('original_id', $article['category_id'])->where('store_id', $store['store_id'])->find();
|
|
if (!$articleCategory) {
|
|
continue;
|
|
}
|
|
$article['create_time'] = time();
|
|
$article['update_time'] = time();
|
|
$article['original_id'] = $article['recovery_id'];
|
|
$article['category_id'] = $articleCategory['category_id'];
|
|
$article['store_id'] = $store['store_id'];
|
|
unset($article['recovery_id']);
|
|
//复制图片
|
|
$upload_file = Db::name('upload_file')->where('file_id', $article['image_id'])->find();
|
|
if ($upload_file) {
|
|
$upload_file['store_id'] = $store['store_id'];
|
|
$upload_file['create_time'] = time();
|
|
unset($upload_file['file_id']);
|
|
$image_id = Db::name('upload_file')->insertGetId($upload_file);
|
|
}
|
|
//写入维修数据
|
|
$article['image_id'] = $image_id;
|
|
$ret = ServerRecovery::create($article);
|
|
//写入图片id
|
|
var_dump($ret->id);
|
|
}
|
|
unset($article);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 同步服务数据
|
|
* [syncHelpData description]
|
|
* @param [type] $store [description]
|
|
* @return [type] [description]
|
|
*/
|
|
private function syncServerData($store){
|
|
//维修分类数据同步
|
|
$articleCategoryList = ServerCategory::where('store_id',self::DEFAULT_STORE_ID)->where('status', 1)->select()->toArray();
|
|
if ($articleCategoryList) {
|
|
foreach ($articleCategoryList as &$articleCategory) {
|
|
$info = ServerCategory::where('store_id', $store['store_id'])->where('original_id', $articleCategory['category_id'])->find();
|
|
if ($info) {
|
|
echo $articleCategory['category_id']."服务分类已存在".PHP_EOL;
|
|
continue;
|
|
}
|
|
$articleCategory['create_time'] = time();
|
|
$articleCategory['update_time'] = time();
|
|
$articleCategory['original_id'] = $articleCategory['category_id'];
|
|
$articleCategory['store_id'] = $store['store_id'];
|
|
unset($articleCategory['category_id']);
|
|
|
|
//复制图片
|
|
$upload_file = Db::name('upload_file')->where('file_id', $articleCategory['image_id'])->find();
|
|
if ($upload_file) {
|
|
$upload_file['store_id'] = $store['store_id'];
|
|
$upload_file['create_time'] = time();
|
|
unset($upload_file['file_id']);
|
|
$image_id = Db::name('upload_file')->insertGetId($upload_file);
|
|
}
|
|
//写入维修数据
|
|
$articleCategory['image_id'] = $image_id ?? 0;
|
|
$ret = ServerCategory::create($articleCategory);
|
|
var_dump($ret->id);
|
|
}
|
|
unset($articleCategory);
|
|
}
|
|
|
|
//维修数据同步
|
|
$articleList = Server::where('store_id',self::DEFAULT_STORE_ID)->where('is_delete', 0)->where('status', 1)->select()->toArray();
|
|
if ($articleList) {
|
|
foreach ($articleList as &$article) {
|
|
$info = Server::where('store_id', $store['store_id'])->where('original_id', $article['server_id'])->find();
|
|
if ($info) {
|
|
echo $article['server_id']."服务已存在".PHP_EOL;
|
|
continue;
|
|
}
|
|
//查询分类id
|
|
$articleCategory = ServerCategory::where('original_id', $article['category_id'])->where('store_id', $store['store_id'])->find();
|
|
if (!$articleCategory) {
|
|
continue;
|
|
}
|
|
$article['create_time'] = time();
|
|
$article['update_time'] = time();
|
|
$article['original_id'] = $article['server_id'];
|
|
$article['category_id'] = $articleCategory['category_id'];
|
|
$article['store_id'] = $store['store_id'];
|
|
unset($article['server_id']);
|
|
//复制图片
|
|
$upload_file = Db::name('upload_file')->where('file_id', $article['image_id'])->find();
|
|
if ($upload_file) {
|
|
$upload_file['store_id'] = $store['store_id'];
|
|
$upload_file['create_time'] = time();
|
|
unset($upload_file['file_id']);
|
|
$image_id = Db::name('upload_file')->insertGetId($upload_file);
|
|
}
|
|
//写入维修数据
|
|
$article['image_id'] = $image_id;
|
|
$ret = Server::create($article);
|
|
//写入图片id
|
|
var_dump($ret->id);
|
|
}
|
|
unset($article);
|
|
}
|
|
}
|
|
|
|
}
|
|
|