lqmac 8 months ago
parent 0688df2ff7
commit 4fb08b28d2
  1. 39
      app/admin/controller/Goods.php
  2. 17
      app/store/model/Order.php

@ -347,6 +347,45 @@ class Goods extends Controller
//return $this->renderSuccess(compact('list')); //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('加价成功');
}
/** /**
* 加价 * 加价

@ -48,6 +48,23 @@ class Order extends OrderModel
'trade', 'trade',
]); ]);
$order->merchant_remark = $order->merchant_remark ? htmlspecialchars_decode($order->merchant_remark) : ""; $order->merchant_remark = $order->merchant_remark ? htmlspecialchars_decode($order->merchant_remark) : "";
$goods = $order->goods ? $order->goods->toArray() : [];
if ($goods) {
$goods = array_column($goods, null, 'goods_id');
if ($order->delivery) {
$delivery = $order->delivery->toArray();
foreach ($order->delivery as &$val) {
foreach ($val->goods as &$value) {
$value->goods_name = $goods[$value->goods_id]['goods_name'] ?? "";
$value->goods_image = $goods[$value->goods_id]['goods_image'] ?? "";
}
}
$order->delivery = $delivery;
}
}
// 附加数据 // 附加数据
static::related($order, ['user', 'address', 'express', 'extract']); static::related($order, ['user', 'address', 'express', 'extract']);
return $order; return $order;

Loading…
Cancel
Save