diff --git a/app/admin/controller/Goods.php b/app/admin/controller/Goods.php index a4da2e11..4206f05c 100644 --- a/app/admin/controller/Goods.php +++ b/app/admin/controller/Goods.php @@ -363,46 +363,12 @@ class Goods extends Controller if (!$goods) { return $this->renderSuccess('没有需要加价的商品'); } - //更新总后台当前商品的价格 - GoodsModel::whereIn('goods_id', array_column($goods, "goods_id"))->update(['markup_rate' => $rate, 'update_time' => time()]); - foreach ($goods as $key => $value) { - //更新origin_goods_id为当前商品id的价格 - $goods_list = GoodsModel::where('origin_goods_id', $value['goods_id']) - ->where('is_delete', 0) - ->field(['goods_id','cost_price_min','goods_price_min','markup_rate']) - ->select() - ->toArray(); - - if (!$goods_list) { - continue; - } - $item = $goods_list[0]; - if ($item['markup_rate'] > 0) { - $item['cost_price_min'] = round($item['cost_price_min'] * (1 - ($rate / 100)), 0); - } - $cost_price = round($item['cost_price_min'] / (1 - ($rate / 100)), 0); - $profit = (float)$item['goods_price_min'] - (float)$cost_price; - $profit_rate = (float)$item['goods_price_min'] > 0 ? bcmul((string)($profit / (float)$item['goods_price_min']) , (string)100, 2) : 0.00; - $goodsData = [ - 'cost_price_min' => $cost_price, - 'profit_rate' => $profit_rate, - 'profit' => $profit, - 'markup_rate' => $rate, - 'update_time' => time() - ]; - GoodsModel::whereIn('goods_id', array_column($goods_list, "goods_id"))->update($goodsData); - $goodsSkuData = [ - 'cost_price' => $cost_price, - 'update_time' => time() - ]; - GoodsSku::whereIn('goods_id', array_column($goods_list, "goods_id"))->update($goodsSkuData); - - } - // GoodsAddPriceJob::dispatch([ - // 'categoryIds' => $categoryIds, - // 'rate' => $rate, - // 'channels' => $channels, - // ]); + + GoodsAddPriceJob::dispatch([ + 'categoryIds' => $categoryIds, + 'rate' => $rate, + 'channels' => $channels, + ]); return $this->renderSuccess('加价成功'); } diff --git a/app/common/model/Goods.php b/app/common/model/Goods.php index 1068c6ac..38ba52ea 100644 --- a/app/common/model/Goods.php +++ b/app/common/model/Goods.php @@ -353,6 +353,7 @@ class Goods extends BaseModel ->field($field) ->where('is_delete', '=', 0) ->where($str) + ->group("goods.goods_id") ->order($sort) ->paginate($listRows); } else { @@ -361,6 +362,7 @@ class Goods extends BaseModel ->alias($this->name) ->field($field) ->where('is_delete', '=', 0) + ->group("goods.goods_id") ->order($sort) ->paginate($listRows); } diff --git a/app/job/service/goods/GoodsAddPrice.php b/app/job/service/goods/GoodsAddPrice.php index 20460fdf..3fce33af 100644 --- a/app/job/service/goods/GoodsAddPrice.php +++ b/app/job/service/goods/GoodsAddPrice.php @@ -41,8 +41,8 @@ class GoodsAddPrice extends BaseService */ public function batch(array $categoryIds, int $rate, array $channels): bool { - ini_set('memory_limit', '1024M'); - set_time_limit(0); + // 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) diff --git a/config/queue.php b/config/queue.php index 52900d43..1833e678 100644 --- a/config/queue.php +++ b/config/queue.php @@ -30,7 +30,7 @@ return [ 'select' => 1,//env('redis.select', '0'), 'timeout' => 0, 'persistent' => false, - 'retry_after' => 60, // 队列任务无响应时(例如die exit)重试的间隔时间, 默认60秒 + 'retry_after' => 300, // 队列任务无响应时(例如die exit)重试的间隔时间, 默认60秒 ], ], 'failed' => [