Merge pull request '添加导入商品价格比例' (#510) from dev into main
Reviewed-on: #510
This commit is contained in:
commit
c77e49f0ba
@ -160,6 +160,39 @@ class LocalController extends BaseAdminController
|
||||
return $this->success('数据已更新完成', $sql);
|
||||
}
|
||||
|
||||
public function updateProductPriceList()
|
||||
{
|
||||
$file = $this->request->file('file');
|
||||
$reader = IOFactory::createReader('Xlsx');
|
||||
$spreadsheet = $reader->load($file->getRealPath());
|
||||
$data = $spreadsheet->getActiveSheet()->toArray();
|
||||
$updateCount = 0;
|
||||
$insert = [];
|
||||
$time = time();
|
||||
foreach ($data as $k => $row) {
|
||||
if ($k < 1 || empty($row[0])) {
|
||||
continue;
|
||||
}
|
||||
$product = StoreProduct::where('id', $row[0])->value('id');
|
||||
if (empty($product)) {
|
||||
continue;
|
||||
}
|
||||
for ($i = 1; $i < 5; $i++) {
|
||||
if (empty($row[1 + $i])) {
|
||||
continue;
|
||||
}
|
||||
$insert[] = [
|
||||
'product_id' => $row[0],
|
||||
'price_type' => $i,
|
||||
'rate' => intval(rtrim($row[1 + $i], '%')) + 100,
|
||||
'create_time' => $time,
|
||||
];
|
||||
}
|
||||
}
|
||||
StoreProductPriceList::insertAll($insert);
|
||||
return $this->success('更新成功:' . $updateCount . '条');
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$file = $this->request->file('file');
|
||||
|
Loading…
x
Reference in New Issue
Block a user