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.
52 lines
1.4 KiB
52 lines
1.4 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 think\facade\Db;
|
|
|
|
class SyncGoodsToPerMinute extends Command
|
|
{
|
|
|
|
protected function configure()
|
|
{
|
|
// 指令配置
|
|
$this->setName('SyncGoodsToPerMinute')->setDescription('同步商品数据到ES');
|
|
$this->addArgument("goods_id");
|
|
$this->addArgument("div");
|
|
$this->addArgument("mod");
|
|
$this->addArgument("minute");
|
|
}
|
|
|
|
|
|
protected function execute(Input $input, Output $output)
|
|
{
|
|
ini_set('memory_limit', '1024M');
|
|
$goods_id = $input->getArgument("goods_id");
|
|
$div = $input->getArgument("div");
|
|
$mod = $input->getArgument("mod");
|
|
$minute = $input->getArgument("minute");
|
|
|
|
$min_time = time() - $minute * 60;
|
|
$limit = 100;
|
|
while (TRUE) {
|
|
$sql = "SELECT * FROM `yoshop_goods` WHERE goods_id > " . $goods_id . " AND goods_id % ". $div . " = ". $mod ." AND update_time > ".$min_time." order by update_time asc LIMIT ".$limit;
|
|
$list = Db::query($sql);
|
|
if (!$list) {
|
|
return true;
|
|
}
|
|
$obj = new GoodsCateEs();
|
|
$res = $obj->addOrUpdateGoodsAndGoodsCate($list);
|
|
var_dump($res);
|
|
|
|
|
|
$goods_id = end($list)['goods_id'];
|
|
}
|
|
}
|
|
|
|
} |