public function import()
{
set_time_limit(0);
$content = file_get_contents('./shop.csv');
$file_type = mb_detect_encoding($content,array('UTF-8','GBK','LATIN1','BIG5'));
\Excel::load('./shop.csv',function($reader){
$store_id = $this->storeId();
$data = $reader->all()->toArray();
if(count($data) > 0){
foreach ($data as $k => $v) {
$shop = new Shop;
$is_exist = Shop::where('shop_code', (string)(int)$v[1])->where('store_id', $store_id)->first();
if(empty($is_exist)) {
$shop->store_id = $store_id; //store_id
$shop->shop_code = (string)(int)$v[1]; //shop_code
$shop->name = $v[2]??''; //name
laravel - 导入csv文件到数据库
最新推荐文章于 2022-04-11 17:13:11 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)