wesley 6 роки тому
батько
коміт
684447e00e

+ 4 - 60
app/Http/Controllers/Admin/Company/InfoController.php

xqd
@@ -127,66 +127,10 @@ class InfoController extends Controller
      */
     public function create(Request $request)
     {
-        $tmp_file = $_FILES['company_info']['name'];
-        $file_types = explode(".", $tmp_file);
-        $file_type = $file_types [count($file_types) - 1];
-        if (strtolower($file_type) == "xls" || strtolower($file_type) == "xlsx") {
-            $file = $request->file('company_info');
-            $path = 'upload/excel';
-            $filename = $tmp_file;
-            $file->move($path, $filename);
-            $filePath = $path . '/' . $filename;
-
-            Excel::import(new CompanyInfoImport, ''.$filePath.'','public_file');
-//            Excel::load($filePath, function ($reader) {
-//                $data = $reader->toArray();
-//                $a = [];
-//                if (empty($data)) {
-//                    die('<script>alert("信息填写不完整,请检查后导入数据");history.back();</script>');
-//                } else {
-//                    foreach ($data as $k1 => $v1) {
-//
-//                        foreach ($v1 as $k2 => $v2) {
-//                            $a[$k1]['year'] = isset($v2['年度'])?$v2['年度']:'';
-//                            $a[$k1]['class'] = isset($v2['科类'])?$v2['科类']:'';
-//                            $a[$k1]['batch'] = isset($v2['批次'])?$v2['批次']:'';
-//                            $a[$k1]['level'] = isset($v2['层次'])?$v2['层次']:'';
-//                            $a[$k1]['type'] = isset($v2['类别'])?$v2['类别']:'';
-//                            $a[$k1]['college'] = isset($v2['院校'])?$v2['院校']:'';
-//                            $a[$k1]['province'] = isset($v2['所在省份'])?$v2['所在省份']:'
-//                                ';
-//                            $a[$k1]['city'] = isset($v2['所在地市'])?$v2['所在地市']:'';
-//                            $a[$k1]['major'] = isset($v2['专业'])?$v2['专业']:'';
-//                            $a[$k1]['comment'] = isset($v2['专业备注'])?$v2['专业备注']:'';
-//                            $a[$k1]['min_grade'] = isset($v2['最低分'])?$v2['最低分']:'';
-//                            $a[$k1]['avg_grade'] = isset($v2['平均分'])?$v2['平均分']:'';
-//                            $a[$k1]['max_grade'] = isset($v2['最高分'])?$v2['最高分']:'';
-//                            $a[$k1]['batch_grade'] = isset($v2['批次线'])?$v2['批次线']:'';
-//                            $a[$k1]['miss_grade'] = isset($v2['线差'])?$v2['线差']:'';
-//                            $a[$k1]['min_rank'] = isset($v2['最低位次'])?$v2['最低位次']:'';
-//                            $a[$k1]['max_rank'] = isset($v2['最高位次'])?$v2['最高位次']:'';
-//                            $a[$k1]['avg_rank'] = isset($v2['平均位次'])?$v2['平均位次']:'';
-//                            $a[$k1]['major_grade'] = $a[$k1]['batch_grade'] + $a[$k1]['miss_grade'];
-//
-//                            $a[$k1]['created_at'] = date('Y-m-d H:i:s', time());
-//                            $a[$k1]['updated_at'] = date('Y-m-d H:i:s', time());
-//
-//                            $res = $this->repository->create($a[$k1]);
-//                        }
-//
-//                    }
-//                }
-//
-//                if (!$res) {
-//                    die('<script>alert("导入专业信息失败");history.back();</script>');
-//                }
-//            });
-//                读取.xls文件后删除文件
-            unlink($filePath);
-            return back()->with('success', '导入专业信息成功');
-        } else {
-            return back()->with('error', '不是Excel .xls或者.xlsx文件,请重新上传');
-        }
+        $res = Excel::import(new CompanyInfoImport, request()->file('company_info'));
+
+        $url[] = array('url' => U('Company/Info/index'), 'title' => '返回列表');
+        $this->showMessage('导入成功', $url);
     }
 
     /**

+ 22 - 2
app/Imports/CompanyInfoImport.php

xqd xqd
@@ -2,6 +2,8 @@
 
 namespace App\Imports;
 
+use App\Models\CompanyContactsModel;
+use App\Models\CompanyInfoModel;
 use Illuminate\Support\Collection;
 use Maatwebsite\Excel\Concerns\ToCollection;
 
@@ -13,8 +15,26 @@ class CompanyInfoImport implements ToCollection
     public function collection(Collection $collection)
     {
         foreach ($collection as $key => $row){
-            if ($key ==0) continue;
-            dd($row[0]);
+            if ($key ==0 ) continue;
+            $isExisted = CompanyInfoModel::where('companyName',$row[1])->first();
+            if($isExisted){
+                $company_id = $isExisted->id;
+            }else{
+                $data['companyName'] = $row[1];
+                $data['legalPerson'] = $row[8];
+                $data['startDate'] = $row[9];
+                $data['regCapital'] = (int)$row[10];
+                $data['regAddr'] = $row[11];
+                $res = CompanyInfoModel::create($data);
+                $company_id = $res->id;
+            }
+            CompanyContactsModel::create([
+                'company_id'=> $company_id,
+                'linkman'=> $row[2],
+                'phone'=> $row[3]?$row[3]:$row[4],
+                'email'=> $row[5],
+                'qq'=> $row[6]
+            ]);
         }
     }
 }

+ 1 - 1
app/Repositories/Company/InfoRepository.php

xqd
@@ -17,7 +17,7 @@ class InfoRepository extends Repository {
         return \App\Models\CompanyInfoModel::class;
     }
 
-    public function searchCompany(array $search,array $orderby=['id'=>'desc'],$pagesize=3)
+    public function searchCompany(array $search,array $orderby=['id'=>'desc'],$pagesize=10)
     {
         $currentQuery = $this->model;
         /*企业名称*/

+ 112 - 0
config/excel.php

xqd
@@ -0,0 +1,112 @@
+<?php
+
+use Maatwebsite\Excel\Excel;
+
+return [
+    'exports' => [
+
+        /*
+        |--------------------------------------------------------------------------
+        | Chunk size
+        |--------------------------------------------------------------------------
+        |
+        | When using FromQuery, the query is automatically chunked.
+        | Here you can specify how big the chunk should be.
+        |
+        */
+        'chunk_size'             => 1000,
+
+        /*
+        |--------------------------------------------------------------------------
+        | Temporary path
+        |--------------------------------------------------------------------------
+        |
+        | When exporting files, we use a temporary file, before storing
+        | or downloading. Here you can customize that path.
+        |
+        */
+        'temp_path'              => sys_get_temp_dir(),
+
+        /*
+       |--------------------------------------------------------------------------
+       | Pre-calculate formulas during export
+       |--------------------------------------------------------------------------
+       */
+        'pre_calculate_formulas' => false,
+
+        /*
+        |--------------------------------------------------------------------------
+        | CSV Settings
+        |--------------------------------------------------------------------------
+        |
+        | Configure e.g. delimiter, enclosure and line ending for CSV exports.
+        |
+        */
+        'csv'                    => [
+            'delimiter'              => ',',
+            'enclosure'              => '"',
+            'line_ending'            => PHP_EOL,
+            'use_bom'                => false,
+            'include_separator_line' => false,
+            'excel_compatibility'    => false,
+        ],
+    ],
+
+    'imports'            => [
+
+        'read_only' => true,
+
+        'heading_row' => [
+
+            /*
+            |--------------------------------------------------------------------------
+            | Heading Row Formatter
+            |--------------------------------------------------------------------------
+            |
+            | Configure the heading row formatter.
+            | Available options: none|slug|custom
+            |
+            */
+            'formatter' => 'slug',
+        ],
+    ],
+
+    /*
+    |--------------------------------------------------------------------------
+    | Extension detector
+    |--------------------------------------------------------------------------
+    |
+    | Configure here which writer type should be used when
+    | the package needs to guess the correct type
+    | based on the extension alone.
+    |
+    */
+    'extension_detector' => [
+        'xlsx'     => Excel::XLSX,
+        'xlsm'     => Excel::XLSX,
+        'xltx'     => Excel::XLSX,
+        'xltm'     => Excel::XLSX,
+        'xls'      => Excel::XLS,
+        'xlt'      => Excel::XLS,
+        'ods'      => Excel::ODS,
+        'ots'      => Excel::ODS,
+        'slk'      => Excel::SLK,
+        'xml'      => Excel::XML,
+        'gnumeric' => Excel::GNUMERIC,
+        'htm'      => Excel::HTML,
+        'html'     => Excel::HTML,
+        'csv'      => Excel::CSV,
+        'tsv'      => Excel::TSV,
+
+        /*
+        |--------------------------------------------------------------------------
+        | PDF Extension
+        |--------------------------------------------------------------------------
+        |
+        | Configure here which Pdf driver should be used by default.
+        | Available options: Excel::MPDF | Excel::TCPDF | Excel::DOMPDF
+        |
+        */
+        'pdf'      => Excel::DOMPDF,
+    ],
+];

+ 0 - 49
resources/views/admin/company/info/data.blade.php

xqd
@@ -1,52 +1,3 @@
-{{--<table class="table table-striped table-bordered table-hover dataTables-example dataTable">--}}
-    {{--<thead>--}}
-    {{--<tr>--}}
-
-        {{--<th class="sorting" data-sort="id"> ID</th>--}}
-        {{--<th class="sorting" data-sort="companyName"> 企业名称</th>--}}
-        {{--<th class="sorting" data-sort="orgNo"> 组织机构代码</th>--}}
-        {{--<th class="sorting" data-sort="legalPerson"> 法人</th>--}}
-        {{--<th class="sorting" data-sort="openStatus"> 经营状态</th>--}}
-        {{--<th class="sorting" data-sort="startDate"> 成立日期</th>--}}
-        {{--<th class="sorting" data-sort="regCapital"> 注册资本(万元)</th>--}}
-        {{--<th width="22%">相关操作</th>--}}
-    {{--</tr>--}}
-    {{--</thead>--}}
-    {{--<tbody>--}}
-
-
-    {{--@if(isset($list))--}}
-        {{--@foreach($list as $key => $item)--}}
-            {{--<tr>--}}
-
-                {{--<td>{{ $item->id }}</td>--}}
-                {{--<td>{{ $item->companyName }}</td>--}}
-                {{--<td>{{ $item->orgNo }}</td>--}}
-                {{--<td>{{ $item->legalPerson }}</td>--}}
-                {{--<td>{{ $item->openStatus }}</td>--}}
-                {{--<td>{{ $item->startDate }}</td>--}}
-                {{--<td>{{ $item->regCapital }}</td>--}}
-                {{--<td>--}}
-                    {{--@if(role('Company/Info/update') && !$item->isThread())--}}
-                    {{--<button class="btn btn-sm btn-success"--}}
-                    {{--onclick="window.location.href='{{ U('User/Threads/create',['company_id'=>$item->id])}}' ">--}}
-                    {{--领取线索--}}
-                    {{--</button>--}}
-                    {{--@endif--}}
-
-                    {{--@if(role('Company/Info/view'))--}}
-                        {{--<a href="{{ U('Company/Info/view',['id'=>$item->id])}}"--}}
-                           {{--class="btn btn-sm btn-primary "> 查看</a>--}}
-                    {{--@endif--}}
-                {{--</td>--}}
-            {{--</tr>--}}
-        {{--@endforeach--}}
-    {{--@endif--}}
-
-    {{--</tbody>--}}
-{{--</table>--}}
-
-
 @if(isset($list))
     @foreach($list as $key => $item)
         <div class="col-sm-7" style="margin: auto">

+ 12 - 3
resources/views/admin/company/info/index.blade.php

xqd xqd
@@ -52,15 +52,15 @@
 
                             @if(role('Company/Info/collection'))
                                 <div class="col-sm-8 pull-right">
-                                    <span class="btn btn-warning pull-right" onclick="save_collection()">保存为我的公海
+                                    <span class="btn btn-sm btn-warning pull-right" onclick="save_collection()">保存为我的公海
                                     </span>
 
                                     <form class="form-horizontal" role="form" method="post" enctype="multipart/form-data" action="{{ U('Company/Info/create')}}">
                                         {{csrf_field()}}
-                                        <input id="input-b2" name="company_info" type="file"  data-show-preview="false" data-language="zh">
-                                        <button class="btn btn-sm btn-primary pull-right" style="margin-right: 5px" type="submit">
+                                        <button class="btn btn-sm btn-primary pull-right company-import" style="margin-right: 5px;display: none" type="submit">
                                             Excel导入
                                         </button>
+                                        <input id="company-import" name="company_info" type="file"  class="pull-right" data-show-preview="false" data-language="zh">
                                     </form>
 
                                 </div>
@@ -202,5 +202,14 @@
 
         });
 
+        $('body').on('change','#company-import',function (e) {
+            file = $('#company-import').val()
+            if(file){
+                $('.company-import').show()
+            }else {
+                $('.company-import').hide()
+            }
+        })
+
     </script>
 @endsection

+ 1 - 1
resources/views/admin/company/info/view.blade.php

xqd
@@ -126,7 +126,7 @@
                                                         <div class="form-group row">
                                                             <div class="col-sm-6">
                                                                 <label for="col-sm-3">法定代表人:</label>
-                                                                <span>{{ $data->orgNo }}</span>
+                                                                <span>{{ $data->legalPerson }}</span>
                                                             </div>
                                                             <div class="col-sm-6">
                                                                 <label for="col-sm-3">经营状态:</label>