123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace App\Imports\User;
- use App\Models\User;
- use Maatwebsite\Excel\Concerns\ToModel;
- use Illuminate\Support\Collection;
- use Maatwebsite\Excel\Concerns\ToCollection;
- class UserSheet implements ToCollection
- {
- /**
- * @param Collection $collection
- */
- public function collection(Collection $collection)
- {
- $user_info = [];
- foreach ($collection as $row) {
- if ($row[0]=="userId")
- {
- continue;
- }
- //用户名
- if ($row[1] == null)
- {
- $user_info['user_name'] = '';
- }else{
- $user_info['user_name'] = $row[1];
- }
- //昵称
- if ($row[2] == null)
- {
- $user_info['nickname'] = '';
- }else{
- $user_info['nickname'] = $row[2];
- }
- //电话
- if ($row[3] == null)
- {
- $user_info['phone'] = '';
- }else{
- $user_info['phone'] = $row[3];
- }
- if ($row[4] == null)
- {
- $user_info['created_at'] =self::excelTime(0);
- }else{
- $user_info['created_at'] = self::excelTime($row[4]);
- }
- if ($row[5] == null)
- {
- $user_info['balance'] = '';
- }else{
- $user_info['balance'] = $row[5];
- }
- User::insert($user_info);
- }
- }
- public static function excelTime($date, $time = false) {
- $date=$date>25568?$date+1:25569;
- $ofs=(70 * 365 + 17+2) * 86400;
- $d1 = date("Y-m-d H:i:s",($date * 86400) - $ofs);
- $d1 = strtotime("-8hours",strtotime($d1));
- $d1 = date('Y-m-d H:i:s',$d1);
- $date = $d1;
- return $date;
- }
- }
|