加价率处理

es
lqmac 10 months ago
parent 4e4be005a6
commit 1978607b17
  1. 24
      app/admin/controller/Goods.php
  2. 2
      app/job/controller/goods/GoodsAddPrice.php
  3. 20
      app/job/service/goods/GoodsAddPrice.php
  4. 2
      config/queue.php

@ -351,24 +351,34 @@ class Goods extends Controller
// set_time_limit(0);
$platform = $this->getUserPlatform();
$channels = $platform ? array_column($platform->toArray(), "code") : [];
$goods = GoodsModel::alias('g')
$goodsList = GoodsModel::alias('g')
->join('goods_category_rel c', 'g.goods_id = c.goods_id')
->where('c.store_id',0)
->where('g.is_delete',0)
->whereIn('c.category_id',$categoryIds)
->whereIn('g.channel', $channels)
->limit(100)
->field(['g.goods_id'])
->group('g.goods_id')
->order("g.goods_id asc")
// ->limit(100)
->select()
->toArray();
if (!$goods) {
if (!$goodsList) {
return $this->renderSuccess('没有需要加价的商品');
}
GoodsAddPriceJob::dispatch([
'categoryIds' => $categoryIds,
// 分批每次导入20条
$limit = 50;
// 根据商品总数量计算需要的队列任务数量
$jobCount = \count($goodsList) / $limit;
// 逐次发布队列任务
for ($i = 0; $i < $jobCount; $i++) {
$data = array_slice($goodsList, $i * $limit, $limit);
GoodsAddPriceJob::dispatch([
'list' => $data,
'rate' => $rate,
'channels' => $channels,
]);
}
return $this->renderSuccess('加价成功');
}

@ -44,6 +44,6 @@ class GoodsAddPrice extends BaseJob
echo "\n ---- GoodsAddPrice ---- {$time} ---- \n";
$service = new GoodsAddPriceService;
return $service->batch($data['categoryIds'], $data['rate'], $data['channels']);
return $service->batch($data['list'], $data['rate']);
}
}

@ -39,19 +39,19 @@ class GoodsAddPrice extends BaseService
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function batch(array $categoryIds, int $rate, array $channels): bool
public function batch(array $goods, int $rate): bool
{
// ini_set('memory_limit', '1024M');
// set_time_limit(0);
$goods = GoodsModel::alias('g')
->join('goods_category_rel c', 'g.goods_id = c.goods_id')
->where('c.store_id',0)
->where('g.is_delete',0)
->whereIn('c.category_id', $categoryIds)
->whereIn('g.channel',$channels)
->order("g.goods_id asc")
->select()
->toArray();
// $goods = GoodsModel::alias('g')
// ->join('goods_category_rel c', 'g.goods_id = c.goods_id')
// ->where('c.store_id',0)
// ->where('g.is_delete',0)
// ->whereIn('c.category_id', $categoryIds)
// ->whereIn('g.channel',$channels)
// ->order("g.goods_id asc")
// ->select()
// ->toArray();
if (!$goods) {
return true;
}

@ -30,7 +30,7 @@ return [
'select' => 1,//env('redis.select', '0'),
'timeout' => 0,
'persistent' => false,
'retry_after' => 300, // 队列任务无响应时(例如die exit)重试的间隔时间, 默认60秒
'retry_after' => 60, // 队列任务无响应时(例如die exit)重试的间隔时间, 默认60秒
],
],
'failed' => [

Loading…
Cancel
Save