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

namespace App\Http\Controllers\Admin;use App\Models\CreditOrganization;use App\Models\Dictionary;use Illuminate\Http\Request;use App\Http\Controllers\Controller;use Illuminate\Support\Facades\DB;class CreditOrgController extends Controller{public function index(Request $request){$organizations=CreditOrganization::select()->orderBy('sort','desc')->get();$model=Dictionary::where(['slug'=>'credit_organization'])->first();return view('admin.dictionary.organization',compact('organizations','model'));}public function store(Request $request){$news=$request->input('new');$old=$request->input('old');$O28AC0=array();$arr=$O28AC0;if($news)goto O28Bodyx2;goto O28Nextx2;O28Bodyx2:$arr_new=array_pluck($news,'name');$arr=array_merge($arr,$arr_new);goto O28x1;O28Nextx2:O28x1:if($old)goto O28Bodyx4;goto O28Nextx4;O28Bodyx4:$arr_old=array_pluck($old,'name');$arr=array_merge($arr,$arr_old);goto O28x3;O28Nextx4:O28x3:$arr_unique=array_unique($arr);$A_____AA="count";$O28AC0=$A_____AA($arr_unique);$A____A__="count";$O28AC1=$A____A__($arr);$O280=$O28AC0!=$O28AC1;if($O280)goto O28Bodyx6;goto O28Nextx6;O28Bodyx6:return response()->json(['code'=>1,'msg'=>'存在重复的卡组织名称,请仔细检查']);goto O28x5;O28Nextx6:O28x5:$model=Dictionary::where(['slug'=>'credit_organization'])->first();$A____A_A="count";$O28AC0=$A____A_A($arr);$O280=$O28AC0>$model->max_num;if($O280)goto O28Bodyx8;goto O28Nextx8;O28Bodyx8:return response()->json(['code'=>1,'msg'=>'最多添加'.$model->max_num.'个卡组织']);goto O28x7;O28Nextx8:O28x7:$old_ids=$request->input('ids',[]);DB::beginTransaction();try{CreditOrganization::whereNotIn('id',$old_ids)->delete();if($old)goto O28Bodyxb;goto O28Nextxb;O28Bodyxb:foreach($old as $item){$id=$item['id'];unset($item['id']);CreditOrganization::where(['id'=>$id])->update($item);}goto O28xa;O28Nextxb:O28xa:if($news)goto O28Bodyxd;goto O28Nextxd;O28Bodyxd:foreach($news as $value){CreditOrganization::create($value);}goto O28xc;O28Nextxd:O28xc:$query=CreditOrganization::select()->orderBy('sort','desc');Dictionary::where(['slug'=>'credit_organization'])->update(['content'=>implode('、',$query->pluck('name')->all()),'model_ids'=>$query->pluck('id')->toJson()]);DB::commit();return response()->json(['code'=>0,'msg'=>'保存成功']);}catch(\Exception $exception){DB::rollBack();return response()->json(['code'=>1,'msg'=>'保存失败'.$exception->getMessage()]);}}}
?>