lqmac 7 months ago
parent 6445a12864
commit 272ee7850a
  1. 46
      app/api/model/Goods.php

@ -669,28 +669,31 @@ class Goods extends GoodsModel
return false;
}
// 整理商品的价格
if ($detail['spec_type'] == GoodsSpecTypeEnum::MULTI) {
if(empty($data['sku_id'])) {
$this->error = "请输入sku_id";
return false;
}
//批量修改sku价格
$sku_ids = explode(',', $data['sku_id']);
foreach ($sku_ids as $sku_id) {
$skuData = GoodsSkuModel::get(['id' => $sku_id,'goods_id' => $data['id']]);
if ($skuData) {
$skuData->save(['goods_price' => $data['goods_price'], 'cost_price' => $data['cost_price']]);
}
}
// if ($detail['spec_type'] == GoodsSpecTypeEnum::MULTI) {
// if(empty($data['sku_id'])) {
// $this->error = "请输入sku_id";
// return false;
// }
// //批量修改sku价格
// $sku_ids = explode(',', $data['sku_id']);
// foreach ($sku_ids as $sku_id) {
// $skuData = GoodsSkuModel::get(['id' => $sku_id,'goods_id' => $data['id']]);
// if ($skuData) {
// $skuData->save(['goods_price' => $data['goods_price'], 'cost_price' => $data['cost_price']]);
// }
// }
$skuList = GoodsSkuModel::getSkuList((int)$data['id']);
[$data['goods_price_min'], $data['goods_price_max']] = GoodsSkuModel::getGoodsPrices($skuList->toArray());
// [$data['line_price_min'], $data['line_price_max']] = GoodsSkuModel::getLinePrices($skuList->toArray());
} elseif ($detail['spec_type'] == GoodsSpecTypeEnum::SINGLE) {
$data['goods_price_min'] = $data['goods_price_max'] = $data['goods_price'];
// $data['line_price_min'] = $data['line_price_max'] = $data['line_price'];
}
return $detail->save($data) !== false;
// $skuList = GoodsSkuModel::getSkuList((int)$data['id']);
// [$data['goods_price_min'], $data['goods_price_max']] = GoodsSkuModel::getGoodsPrices($skuList->toArray());
// } elseif ($detail['spec_type'] == GoodsSpecTypeEnum::SINGLE) {
//}
$data['goods_price_min'] = $data['goods_price_max'] = $data['line_price_min'] = $data['line_price_max'] = $data['goods_price'];
$data['cost_price_min'] = $data['cost_price'];
$detail->save($data);
//更新sku的价格
GoodsSkuModel::where('goods_id', $data['id'])->update(['cost_price'=>$data['cost_price'], 'goods_price' => $data['goods_price']]);
return true;
}
public function editGoodsSeckillPrice($data) {
@ -720,6 +723,7 @@ class Goods extends GoodsModel
'limit_times' => $data['limit_times'],
'sec_start_time' => $data['sec_start_time'],
'sec_end_time' => $data['sec_end_time'],
'sec_hour' => $data['sec_hour'],
];
$skuData->save($up_data);
}

Loading…
Cancel
Save