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.
110 lines
3.8 KiB
110 lines
3.8 KiB
<?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\Goods as GoodsModel;
|
|
use app\common\model\Store;
|
|
use think\facade\Db;
|
|
|
|
class UpdateDataProviderGoods extends Command
|
|
{
|
|
|
|
const DEFAULT_STORE_ID = 0;
|
|
protected function configure()
|
|
{
|
|
// 指令配置
|
|
$this->setName('UpdateDataProviderGoods')->setDescription('处理历史服务商商品数据');
|
|
$this->addArgument("store_id");
|
|
$this->addArgument("is_update_image");
|
|
}
|
|
|
|
|
|
protected function execute(Input $input, Output $output)
|
|
{
|
|
$store_id = $input->getArgument("store_id");
|
|
$where[] = ['is_delete','=', 0];
|
|
$where[] = ['is_recycle','=', 0];
|
|
$where[] = ['status','=', 1];
|
|
$where[] = ['is_provider_data','=', 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')->order('store_id asc')->select()->toArray();
|
|
if (!$stores) {
|
|
echo "没有要同步的商城了";
|
|
return;
|
|
}
|
|
foreach ($stores as $store) {
|
|
$this->updateGoodsData($store['store_id']);
|
|
}
|
|
}
|
|
|
|
public function updateGoodsData(int $store_id){
|
|
|
|
$list = GoodsModel::where('store_id', $store_id)
|
|
->where('channel','zy')
|
|
->where('status', 10)
|
|
->where('is_pool', 1)
|
|
->where('is_delete', 0)
|
|
->field('goods_id,region,region_text,goods_source,delivery_time,is_check')
|
|
->select();
|
|
echo "<pre>";
|
|
print_r($list);
|
|
exit();
|
|
foreach ($list as $key => $value) {
|
|
echo $value['goods_id'].PHP_EOL;
|
|
$platformGoods = GoodsModel::where('origin_goods_id', $value['goods_id'])->field("goods_id,region,region_text,goods_source,delivery_time,is_check,origin_goods_id")->find();
|
|
if (!$platformGoods) {
|
|
echo $value['goods_id']."商品未同步到零售商城".PHP_EOL;
|
|
continue;
|
|
}
|
|
$up_data = [
|
|
'region_text' => $value['region_text'],
|
|
'region' => $value['region'],
|
|
'goods_source' => $value['goods_source'],
|
|
'delivery_time' => $value['delivery_time'],
|
|
'is_check' => $value['is_check'],
|
|
'update_time' => time(),
|
|
];
|
|
//更新零售商城总后台的商品
|
|
$ret = GoodsModel::where('origin_goods_id', $value['goods_id'])->update($up_data);
|
|
var_dump($ret);
|
|
//更新零售商城-商城端的商品
|
|
$ret = GoodsModel::where('origin_goods_id', $platformGoods['goods_id'])->update($up_data);
|
|
var_dump($ret);
|
|
//更新批发商城总后台的商品
|
|
$wholesalePlatformGoods = Db::connect("dataCenterMysql")->table('yoshop_goods')->where('origin_goods_id', $platformGoods['goods_id'])->find();
|
|
if (!$wholesalePlatformGoods) {
|
|
echo $platformGoods['goods_id']."商品未同步到批发商城".PHP_EOL;
|
|
return true;
|
|
}
|
|
$ret = Db::connect("dataCenterMysql")->table('yoshop_goods')->where('origin_goods_id', $platformGoods['goods_id'])->update($up_data);
|
|
var_dump($ret);
|
|
//上架批发商城-商城端的商品
|
|
$ret = Db::connect("dataCenterMysql")->table('yoshop_goods')->where('origin_goods_id', $wholesalePlatformGoods['goods_id'])->update($up_data);
|
|
var_dump($ret);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |