|
|
@ -349,48 +349,60 @@ class Goods extends Controller |
|
|
|
public function addPrice(array $categoryIds, int $rate){ |
|
|
|
public function addPrice(array $categoryIds, int $rate){ |
|
|
|
// ini_set('memory_limit', '1024M'); |
|
|
|
// ini_set('memory_limit', '1024M'); |
|
|
|
// set_time_limit(0); |
|
|
|
// set_time_limit(0); |
|
|
|
$goods = GoodsCategoryRel::whereIn('category_id',$categoryIds)->where('store_id', 0)->select()->toArray(); |
|
|
|
$platform = $this->getUserPlatform(); |
|
|
|
|
|
|
|
$channels = $platform ? array_column($platform->toArray(), "code") : []; |
|
|
|
|
|
|
|
$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) |
|
|
|
|
|
|
|
->limit(100) |
|
|
|
|
|
|
|
->select() |
|
|
|
|
|
|
|
->toArray(); |
|
|
|
if (!$goods) { |
|
|
|
if (!$goods) { |
|
|
|
return $this->renderSuccess('没有需要加价的商品'); |
|
|
|
return $this->renderSuccess('没有需要加价的商品'); |
|
|
|
} |
|
|
|
} |
|
|
|
$goods = GoodsModel::whereIn('goods_id', array_column($goods, "goods_id"))->where('store_id', 0)->where('channel','sjdngys')->select()->toArray(); |
|
|
|
//更新总后台当前商品的价格 |
|
|
|
if (!$goods) { |
|
|
|
GoodsModel::whereIn('goods_id', array_column($goods, "goods_id"))->update(['markup_rate' => $rate, 'update_time' => time()]); |
|
|
|
return $this->renderSuccess('没有需要加价的商品'); |
|
|
|
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([ |
|
|
|
// GoodsAddPriceJob::dispatch([ |
|
|
|
'categoryIds' => $categoryIds, |
|
|
|
// 'categoryIds' => $categoryIds, |
|
|
|
'rate' => $rate, |
|
|
|
// 'rate' => $rate, |
|
|
|
]); |
|
|
|
// 'channels' => $channels, |
|
|
|
// foreach ($goods as $key => $value) { |
|
|
|
// ]); |
|
|
|
// //更新总后台当前商品的价格 |
|
|
|
|
|
|
|
// GoodsModel::where('goods_id', $value['goods_id'])->where('is_delete', 0)->where('store_id', 0)->update(['markup_rate' => $rate, 'update_time' => time()]); |
|
|
|
|
|
|
|
// //更新origin_goods_id为当前商品id的价格 |
|
|
|
|
|
|
|
// $goods_list = GoodsModel::where('origin_goods_id', $value['goods_id'])->where('is_delete', 0)->select(); |
|
|
|
|
|
|
|
// if (!$goods_list) { |
|
|
|
|
|
|
|
// continue; |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// foreach ($goods_list as $item) { |
|
|
|
|
|
|
|
// $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() |
|
|
|
|
|
|
|
// ]; |
|
|
|
|
|
|
|
// // var_dump($goodsData); |
|
|
|
|
|
|
|
// // exit(); |
|
|
|
|
|
|
|
// GoodsModel::where('goods_id', $item['goods_id'])->where('store_id', $item['store_id'])->update($goodsData); |
|
|
|
|
|
|
|
// $goodsSkuData = [ |
|
|
|
|
|
|
|
// 'cost_price' => $cost_price, |
|
|
|
|
|
|
|
// 'update_time' => time() |
|
|
|
|
|
|
|
// ]; |
|
|
|
|
|
|
|
// GoodsSku::where('goods_id', $item['goods_id'])->where('store_id', $item['store_id'])->update($goodsSkuData); |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
return $this->renderSuccess('加价成功'); |
|
|
|
return $this->renderSuccess('加价成功'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|