public function persist()
 {
     $filename = $this->moveToLocalStorage($this->file('doctor-information'));
     \Excel::load(storage_path('app/doctor-information/' . $filename), function (LaravelExcelReader $reader) {
         $result = $reader->get();
         foreach ($result as $row) {
             $param = ['name' => $row['姓名'], 'type' => substr(trim($row['等级']), 0, 1), 'level' => 5, 'hospital' => $row['所属医院'], 'hospital_level' => $row['医院级别'], 'department' => $row['科室'], 'phone' => strval(intval($row['注册电话'])), 'referred_name' => $row['推荐代表'], 'referred_phone' => strval(intval($row['代表电话'])), 'region' => $row['区域9大区'], 'region_level' => $row['销售大区级别'], 'responsible' => $row['销售地区级别']];
             if ($customer = Customer::where('phone', strval(intval($row['注册电话'])))->first()) {
                 $param['customer_id'] = $customer->id;
             }
             if ($customer_info = CustomerInformation::where('phone', strval(intval($row['注册电话'])))->first()) {
                 $customer_info->update($param);
                 return;
             }
             CustomerInformation::create($param);
         }
     });
 }
 public function store(Request $request)
 {
     $customerInformation = CustomerInformation::create(['name' => $request->input('name'), 'hospital' => $request->input('hospital'), 'province' => $request->input('province'), 'city' => $request->input('city'), 'district' => $request->input('district'), 'department' => $request->input('department'), 'remark' => $request->input('remark'), 'type' => $request->input('type'), 'referred_name' => $request->input('referred_name'), 'referred_phone' => $request->input('referred_phone'), 'region' => $request->input('region'), 'region_level' => $request->input('region_level'), 'responsible' => $request->input('responsible'), 'hospital_level' => $request->input('hospital_level'), 'phone' => $request->input('phone')]);
     $inputPhone = $request->input('phone');
     if ($inputPhone) {
         $customer = Customer::where('phone', $inputPhone)->first();
         if ($customer) {
             $customerInformation->update(['customer_id' => $customer->id]);
         } else {
             $customerInformation->update(['customer_id' => null]);
         }
     }
     if ($request->has('beans_total') && $customer) {
         $customer->update(['beans_total' => $request->input('beans_total')]);
     }
     if ($request->has('type_id') && $customer) {
         $customer->update(['type_id' => $request->input('type_id')]);
     }
     if ($customer) {
         return response()->json(['success' => true, 'data' => ['customer' => $customer->with('information')]]);
     } else {
         return response()->json(['success' => true, 'data' => ['customer' => null]]);
     }
 }