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.
yanzong/app/command/SyncChannel.php

60 lines
1.7 KiB

2 months ago
<?php
namespace app\command;
use app\common\service\GoodsCateEs;
use app\common\service\GoodsEs;
use think\console\Command;
use think\console\Output;
use think\console\Input;
use app\store\model\Category as CategoryModel;
use app\common\model\Channel;
use think\facade\Db;
class SyncChannel extends Command
{
const DEFAULT_STORE_ID = 0;
protected function configure()
{
// 指令配置
$this->setName('SyncChannel')->setDescription('同步渠道');
}
protected function execute(Input $input, Output $output)
{
$where[] = ['is_delete','=', 0];
$where[] = ['status','=', 1];
$channels = Db::connect("shopMysql")->name('yoshop_channel')->where('status',1)->where('is_delete', 0)->order("id desc")->select();
if (!$channels) {
echo "没有要同步的渠道了";
return;
}
foreach ($channels as $key => $value) {
$channel = Channel::where('code', $value['code'])->find();
$upData = [
'name' => $value['name'],
'alias' => $value['alias'],
'shop_name' => $value['shop_name'],
'shop_label' => $value['shop_label'],
'remark' => $value['remark'],
'update_time' => time(),
];
if ($channel) {
// 更新渠道信息
$ret = Channel::where('id', $channel['id'])->update($upData);
} else {
$upData['code'] = $value['code'];
$upData['create_time'] = time();
$ret = Channel::create($upData);
}
var_dump($ret);
}
}
}