lszyh
parent
5d32f8d4ab
commit
474a0fffb7
@ -0,0 +1,52 @@ |
|||||||
|
<?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']; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,40 @@ |
|||||||
|
<?php |
||||||
|
declare (strict_types=1); |
||||||
|
|
||||||
|
namespace app\job\controller\goods; |
||||||
|
|
||||||
|
use app\job\service\goods\GoodsRealDelete as GoodsRealDeleteService; |
||||||
|
use cores\BaseJob; |
||||||
|
use cores\traits\QueueTrait; |
||||||
|
use cores\exception\BaseException; |
||||||
|
use think\db\exception\DataNotFoundException; |
||||||
|
use think\db\exception\DbException; |
||||||
|
use think\db\exception\ModelNotFoundException; |
||||||
|
|
||||||
|
/** |
||||||
|
* 队列任务:商品批量导入 |
||||||
|
* Class Import |
||||||
|
* @package app\job\controller |
||||||
|
*/ |
||||||
|
class GoodsRealDelete extends BaseJob |
||||||
|
{ |
||||||
|
use QueueTrait; |
||||||
|
|
||||||
|
/** |
||||||
|
* 消费队列任务:商品导入 |
||||||
|
* @param array $data 参数 [index队列顺序;totalCount商品总数量;list商品列表;storeId商城ID] |
||||||
|
* @return bool 返回结果 |
||||||
|
* @throws BaseException |
||||||
|
* @throws DataNotFoundException |
||||||
|
* @throws DbException |
||||||
|
* @throws ModelNotFoundException |
||||||
|
*/ |
||||||
|
public function handle(array $data): bool |
||||||
|
{ |
||||||
|
$time = date('H:i:s'); |
||||||
|
echo "\n ---- GoodsRealDelete ---- {$time} ---- \n"; |
||||||
|
|
||||||
|
$service = new GoodsRealDeleteService; |
||||||
|
return $service->batch($data['list']); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,41 @@ |
|||||||
|
<?php |
||||||
|
declare (strict_types=1); |
||||||
|
|
||||||
|
namespace app\job\service\goods; |
||||||
|
|
||||||
|
use app\common\library\helper; |
||||||
|
use app\common\service\BaseService; |
||||||
|
use app\common\model\Goods as GoodsModel; |
||||||
|
use app\common\model\GoodsSku; |
||||||
|
use app\store\model\GoodsCategoryRel; |
||||||
|
use cores\exception\BaseException; |
||||||
|
use think\facade\Log; |
||||||
|
use app\common\service\GoodsCateEs; |
||||||
|
|
||||||
|
/** |
||||||
|
* 批量同步到es |
||||||
|
* Class Import |
||||||
|
* @package app\job\service\goods |
||||||
|
*/ |
||||||
|
class GoodsRealDelete extends BaseService |
||||||
|
{ |
||||||
|
/** |
||||||
|
* 批量同步到es |
||||||
|
* @param array $list |
||||||
|
* @param int $recordId |
||||||
|
* @param int $storeId |
||||||
|
* @return bool |
||||||
|
* @throws BaseException |
||||||
|
* @throws \think\db\exception\DataNotFoundException |
||||||
|
* @throws \think\db\exception\DbException |
||||||
|
* @throws \think\db\exception\ModelNotFoundException |
||||||
|
*/ |
||||||
|
public function batch(array $goodsIds): bool |
||||||
|
{ |
||||||
|
$obj = new GoodsCateEs(); |
||||||
|
$obj->batchDelete($goodsIds); |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue