<?php
/*
 本代码由 口号帮 创建
 创建时间 2019-05-06 16:50:44
 技术支持 口号帮
 严禁反编译、逆向等任何形式的侵权行为，违者将追究法律责任
*/

namespace App\Http\Controllers\Admin;use App\Http\Requests\VirtualPhoneCreateRequest;use App\Models\VirtualPhone;use Illuminate\Http\Request;use App\Http\Controllers\Controller;use Illuminate\Support\Facades\DB;use Illuminate\Support\Facades\Storage;use Maatwebsite\Excel\Facades\Excel;class VirtualPhoneController extends Controller{protected $phones=[];protected $error=0;protected $msg='';protected $exist_phones=[];public function index(){return view('admin.virtual_phone.index');}public function data(Request $request){$pageSize=$request->input('limit',$this->pageSize);$res=VirtualPhone::orderBy('created_at','desc')->paginate($pageSize)->toArray();$O28AC0=array();$O28AC0['code']=0;$O28AC0['msg']='正在请求中...';$O28AC0['count']=$res['total'];$O28AC0['data']=$res['data'];$data=$O28AC0;return response()->json($data);}public function create(){return view('admin.virtual_phone.create');}public function store(VirtualPhoneCreateRequest $request){$O280=storage_path('app') . '/';$O281=$O280 . $request->input('path');$filename=$O281;Excel::load($filename,function($reader){$reader->each(function($sheet){if($sheet->count()){$heading=$sheet->getHeading();if($heading&&$heading[0]=='phone'){$sheet->each(function($row){$phone="".$row->phone;if(preg_match("/^1[3456789]\d{9}$/",$phone)){$this->phones[]=$phone;}else{$this->error++;$this->msg='手机号'.$phone.'格式不正确';}});}else{$this->error++;$this->msg='Excel格式有误';}}});});$O280=!$this->error;if($O280)goto O28Bodyx2;goto O28Nextx2;O28Bodyx2:$db_phones=VirtualPhone::pluck('phone')->all();$this->exist_phones=array_intersect($this->phones,$db_phones);$O280=$request->import_type=='append';$import_type=$O280;if($import_type)goto O28Bodyx4;goto O28Nextx4;O28Bodyx4:$dif_phones=array_diff($this->phones,$db_phones);goto O28x3;O28Nextx4:$dif_phones=$this->phones;O28x3:$O28AC0=array();$phones=$O28AC0;if($dif_phones)goto O28Bodyx6;goto O28Nextx6;O28Bodyx6:foreach($dif_phones as $dif_phone){$A___A__AA="in_array";$O28AC0=$A___A__AA($dif_phone,array_pluck($phones,'phone'));$O280=!$O28AC0;if($O280)goto O28Bodyx8;goto O28Nextx8;O28Bodyx8:$O28AC0=array();$O28AC0['phone']=$dif_phone;$A___A_A__="date";$O28AC1=$A___A_A__('Y-m-d H:i:s');$O28AC0['created_at']=$O28AC1;$A___A_A_A="date";$O28AC2=$A___A_A_A('Y-m-d H:i:s');$O28AC0['updated_at']=$O28AC2;$phones[]=$O28AC0;$O280=$O28AC0;goto O28x7;O28Nextx8:$this->exist_phones[]=$dif_phone;$O280=$dif_phone;O28x7:}goto O28x5;O28Nextx6:O28x5:if($phones)goto O28Bodyxa;goto O28Nextxa;O28Bodyxa:$O280=$import_type=='append';if($O280)goto O28Bodyxc;goto O28Nextxc;O28Bodyxc:if(DB::table('virtual_phones')->insert($phones))goto O28Bodyxe;goto O28Nextxe;O28Bodyxe:return response()->json(['code'=>0,'msg'=>"保存成功,成功导入".count($phones)."条,重复".count($this->exist_phones)."条未导入"]);goto O28xd;O28Nextxe:return response()->json(['code'=>1,'msg'=>'保存失败']);O28xd:goto O28xb;O28Nextxc:DB::beginTransaction();try{DB::table('virtual_phones')->truncate();DB::table('virtual_phones')->insert($phones);Storage::delete($request->input('path'));DB::commit();return response()->json(['code'=>0,'msg'=>"保存成功,成功导入".count($phones)."条"]);}catch(\Exception $exception){DB::rollBack();return response()->json(['code'=>1,'msg'=>'保存失败'.$exception->getMessage()]);}O28xb:goto O28x9;O28Nextxa:return response()->json(['code'=>1,'msg'=>'导入号码为空或全部已存在于号码池']);O28x9:goto O28x1;O28Nextx2:return response()->json(['code'=>1,'msg'=>$this->msg]);O28x1:}public function show($id){}public function edit($id){}public function update(Request $request,$id){}public function destroy(Request $request){$ids=$request->get('ids');if(VirtualPhone::whereIn('id',$ids)->delete())goto O28Bodyxh;goto O28Nextxh;O28Bodyxh:return response()->json(['code'=>0,'msg'=>'删除成功']);goto O28xg;O28Nextxh:return response()->json(['code'=>1,'msg'=>'删除失败']);O28xg:}public function destroyAll(Request $request){if(VirtualPhone::truncate())goto O28Bodyxj;goto O28Nextxj;O28Bodyxj:return response()->json(['code'=>0,'msg'=>'清空成功']);goto O28xi;O28Nextxj:return response()->json(['code'=>1,'msg'=>'清空失败']);O28xi:}}
?>