|
|
|
@ -347,6 +347,45 @@ class Goods extends Controller |
|
|
|
|
|
|
|
|
|
//return $this->renderSuccess(compact('list')); |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* 多个商品批量加价 |
|
|
|
|
* [addPrice description] |
|
|
|
|
* @param array $categoryIds [description] |
|
|
|
|
* @param int $rate [description] |
|
|
|
|
*/ |
|
|
|
|
public function batchAddPrice(array $goodsIds, int $rate){ |
|
|
|
|
// ini_set('memory_limit', '1024M'); |
|
|
|
|
// set_time_limit(0); |
|
|
|
|
$platform = $this->getUserPlatform(); |
|
|
|
|
$channels = $platform ? array_column($platform->toArray(), "code") : []; |
|
|
|
|
$goodsList = GoodsModel::alias('g') |
|
|
|
|
->where('g.store_id',0) |
|
|
|
|
->where('g.is_delete',0) |
|
|
|
|
->whereIn('g.goods_id',$goodsIds) |
|
|
|
|
->whereIn('g.channel', $channels) |
|
|
|
|
->field(['g.goods_id','g.cost_price_min']) |
|
|
|
|
->group('g.goods_id') |
|
|
|
|
->order("g.goods_id asc") |
|
|
|
|
->select() |
|
|
|
|
->toArray(); |
|
|
|
|
if (!$goodsList) { |
|
|
|
|
return $this->renderSuccess('没有需要加价的商品'); |
|
|
|
|
} |
|
|
|
|
// 分批每次导入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, |
|
|
|
|
]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $this->renderSuccess('加价成功'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 加价 |
|
|
|
|