wesley 6 years ago
parent
commit
4463bc00e4

+ 11 - 6
app/Http/Controllers/Admin/Company/CollectionController.php

xqd
@@ -31,14 +31,19 @@ class CollectionController extends Controller
      */
     public function create(Request $request)
     {
+        $user_id = \Auth::guard('admin')->user()->id;
         $filter_fields = $request->except('_token');
 
-        $data['user_id'] = \Auth::guard('admin')->user()->id;
-        $data['filter_fields'] = json_encode($filter_fields);
-        $data['name'] = '我的公海';
-
-        UserCompanyCollectionModel::create($data);
-
+        $isCreated = UserCompanyCollectionModel::where('user_id',$user_id)->first();
+        if($isCreated){
+            $isCreated->filter_fields = json_encode($filter_fields);
+            $isCreated->save();
+        }else{
+            $data['user_id'] = $user_id;
+            $data['filter_fields'] = json_encode($filter_fields);
+            $data['name'] = '我的公海';
+            UserCompanyCollectionModel::create($data);
+        }
         return 200;
     }
 

+ 11 - 5
app/Http/Controllers/Admin/Company/InfoController.php

xqd xqd xqd xqd
@@ -13,6 +13,7 @@ use App\Http\Controllers\Admin\Controller;
 use App\Imports\CompanyInfoImport;
 use App\Models\CompanyContactsModel;
 use App\Models\CompanyInfoModel;
+use App\Models\UserCompanyCollectionModel;
 use Illuminate\Http\Request;
 use App\Repositories\Company\InfoRepository;
 use Maatwebsite\Excel\Facades\Excel;
@@ -59,8 +60,10 @@ class InfoController extends Controller
 
         $fields = (new CompanyInfoModel())->filterFields;
 
+        $user_id = \Auth::guard('admin')->user()->id;
+        $hasCollection = UserCompanyCollectionModel::where('user_id', $user_id)->count();
 
-        return view('admin.company.info.index', compact('list', 'fields'));
+        return view('admin.company.info.index', compact('list', 'fields', 'hasCollection'));
     }
 
     /***
@@ -69,10 +72,8 @@ class InfoController extends Controller
      */
     public function import(Request $request)
     {
-        $res = Excel::import(new CompanyInfoImport, request()->file('company_info'));
-
-        $url[] = array('url' => U('Company/Info/index'), 'title' => '返回列表');
-        $this->showMessage('导入成功', $url);
+        Excel::import(new CompanyInfoImport, request()->file('company_info'));
+        $this->showMessage('操作成功');
     }
 
     /***
@@ -101,6 +102,11 @@ class InfoController extends Controller
         }
     }
 
+    /***
+     * 添加联系人备注
+     * @param Request $request
+     * @return int
+     */
     public function addremarks(Request $request)
     {
         $contact = CompanyContactsModel::find($request->get('id'));

+ 61 - 18
app/Imports/CompanyInfoImport.php

xqd
@@ -15,26 +15,69 @@ class CompanyInfoImport implements ToCollection
     public function collection(Collection $collection)
     {
         foreach ($collection as $key => $row){
-            if ($key ==0 ) continue;
-            $isExisted = CompanyInfoModel::where('companyName',$row[1])->first();
-            if($isExisted){
-                $company_id = $isExisted->id;
+            if ($key == 0 ) continue;
+            if(strpos($row[0],'国税局')){
+                \Log::info('start');
+                $isExisted = CompanyInfoModel::where('companyName',$row[3])->first();
+
+                if($isExisted){
+                    \Log::info('1');
+                    $company_id = $isExisted->id;
+                }else{
+                    \Log::info('2');
+                    $data['companyName'] = $row[3];
+                    $data['legalPerson'] = $row[5];
+                    $data['startDate'] = str_replace('/','-',$row[1]);
+                    $data['regAddr'] = $row[4];
+                    $data['scope'] = $row[7];
+                    $data['industry'] = $row[10];
+                    $data['regNo'] = $row[2];
+
+                    $res = CompanyInfoModel::create($data);
+                    $company_id = $res->id;
+                }
+
+                if($row[6]){
+                    CompanyContactsModel::create([
+                        'company_id'=> $company_id,
+                        'linkman'=> $row[5],
+                        'phone'=> $row[6],
+                    ]);
+                }
+                if($row[9]){
+                    CompanyContactsModel::create([
+                        'company_id'=> $company_id,
+                        'linkman'=> $row[8],
+                        'phone'=> $row[9],
+                    ]);
+                }
+
+
+
             }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;
+                $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]
+                ]);
             }
-            CompanyContactsModel::create([
-                'company_id'=> $company_id,
-                'linkman'=> $row[2],
-                'phone'=> $row[3]?$row[3]:$row[4],
-                'email'=> $row[5],
-                'qq'=> $row[6]
-            ]);
+
         }
     }
 }

+ 12 - 4
app/Repositories/Company/InfoRepository.php

xqd
@@ -29,28 +29,36 @@ class InfoRepository extends Repository {
         }
         /*所在地区*/
         if(isset($search['district']) && ! empty($search['district'])) {
-            $district = str_replace(',','|',$search['district']);
+            $district = $search['district'];
+            if (is_array($district)) $district = join('|',$district) ;
+
             $currentQuery = $currentQuery->where(function ($query) use ($district) {
                 $query->where('district','REGEXP', $district);
             });
         }
         /*企业类型*/
         if(isset($search['entType']) && ! empty($search['entType'])) {
-            $entType = str_replace(',','|',$search['entType']);
+            $entType = $search['entType'];
+            if (is_array($entType)) $entType = join('|',$entType) ;
+
             $currentQuery = $currentQuery->where(function ($query) use ($entType) {
                 $query->where('entType','REGEXP',$entType);
             });
         }
         /*经营状态*/
         if(isset($search['openStatus']) && ! empty($search['openStatus'])) {
-            $openStatus = str_replace(',','|',$search['openStatus']);
+            $openStatus = $search['openStatus'];
+            if (is_array($openStatus)) $openStatus = join('|',$openStatus) ;
+
             $currentQuery = $currentQuery->where(function ($query) use ($openStatus) {
                 $query->where('openStatus','REGEXP',$openStatus);
             });
         }
         /*所属行业*/
         if(isset($search['industry']) && ! empty($search['industry'])) {
-            $industry= str_replace(',','|',$search['industry']);
+            $industry = $search['industry'];
+            if (is_array($industry)) $industry = join('|',$industry) ;
+
             $currentQuery = $currentQuery->where(function ($query) use ($industry) {
                 $query->where('industry','REGEXP',$industry);
             });

+ 24 - 4
resources/views/admin/company/info/index.blade.php

xqd xqd xqd xqd
@@ -63,7 +63,7 @@
                                           action="{{ U('Company/Info/import')}}">
                                         {{csrf_field()}}
                                         <button class="btn btn-sm btn-primary pull-right company-import"
-                                                style="margin-right: 5px;display: none" type="submit">
+                                                style="margin-right: 5px;display: none" type="submit" onclick="layer.load(1)">
                                             Excel导入
                                         </button>
                                         <input id="company-import" name="company_info" type="file" class="pull-right"
@@ -93,11 +93,11 @@
                                         </select>
                                     </th>
                                     <th>
-                                        <select name="industry" class="form-control" onchange="filter_company()">
+                                        <select name="industry[]" data-placeholder="所属行业" class="form-control chosen-select" onchange="filter_company()" multiple="" tabindex="-1">
                                             <option value="">所属行业</option>
                                             @foreach($fields['industry'] as $industry)
                                                 <option value="{{$industry['value']}}"
-                                                        @if($industry['value'] == Request::get('industry')) selected @endif>{{$industry['name']}}</option>
+                                                        @if(Request::get('industry') &&  in_array($industry['value'],Request::get('industry')) ) selected @endif>{{$industry['name']}}</option>
                                             @endforeach
                                         </select>
                                     </th>
@@ -180,6 +180,21 @@
 
         /*保存公海*/
         function save_collection() {
+            hasCollection = "{{$hasCollection}}";
+            if (hasCollection) {
+                layer.confirm('你已经创建过公海,确定要替换吗?替换后不可撤销!', {
+                    btn: ['确定', '取消']//按钮
+                }, function (index) {
+                    layer.close(index);
+                    ajax_collection_save()
+                });
+            } else {
+                ajax_collection_save()
+            }
+
+        }
+
+        function ajax_collection_save() {
             data = $('#filter_company').serialize();
             $.ajax({
                 url: '{{ U('Company/Collection/create') }}',
@@ -187,7 +202,12 @@
                 data: data,
                 success: function (data) {
                     if (data == 200) {
-                        layer.msg('保存公海成功!', {icon: 1})
+                        layer.msg('保存公海成功!',
+                            {icon: 1},
+                            function () {
+                                window.location.href = '{{ U('Company/Collection/index') }}'
+                            }
+                        )
                     }
                 }
 

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

xqd xqd xqd
@@ -69,7 +69,7 @@
                                         <label class="font-normal">多选</label>
                                         <div>
                                             <select data-placeholder="全部" class="chosen-select" multiple=""
-                                                    style="width: 350px; display: none;" tabindex="-1" name="industry">
+                                                    style="width: 350px; display: none;" tabindex="-1" name="industry[]">
                                                 <option value="">全部</option>
                                                 @foreach($fields['industry'] as $industry)
                                                     <option value="{{$industry['value']}}"
@@ -92,7 +92,7 @@
                                             <div>
                                                 <select data-placeholder="全部" class="chosen-select" multiple=""
                                                         style="width: 350px; display: none;" tabindex="-1"
-                                                        name="entType">
+                                                        name="entType[]">
                                                     <option value="">全部</option>
                                                     @foreach($fields['entType'] as $entType)
                                                         <option value="{{$entType['value']}}"
@@ -116,7 +116,7 @@
                                             <div>
                                                 <select data-placeholder="全部" class="chosen-select" multiple=""
                                                         style="width: 350px; display: none;" tabindex="-1"
-                                                        name="district">
+                                                        name="district[]">
                                                     <option value="">全部</option>
                                                     @foreach($fields['district'] as $district)
                                                         <option value="{{$district['value']}}">{{$district['name']}}</option>