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

namespace App\Http\Controllers\Admin;use App\Models\Dictionary;use App\Models\ProductVideo;use Illuminate\Http\Request;use App\Http\Controllers\Controller;use Illuminate\Support\Facades\DB;class ProductVideoController extends Controller{public function index(Request $request){$banks=ProductVideo::select()->orderBy('sort','desc')->get();$model=Dictionary::where(['slug'=>'product_video'])->first();return view('admin.dictionary.video',compact('banks','model'));}public function store(Request $request){$news=$request->input('new');$old=$request->input('old');$P2gAC0=array();$arr=$P2gAC0;if($news)goto P2gBodyx2;goto P2gNextx2;P2gBodyx2:$arr_new=array_pluck($news,'name');$arr=array_merge($arr,$arr_new);goto P2gx1;P2gNextx2:P2gx1:if($old)goto P2gBodyx4;goto P2gNextx4;P2gBodyx4:$arr_old=array_pluck($old,'name');$arr=array_merge($arr,$arr_old);goto P2gx3;P2gNextx4:P2gx3:$arr_unique=array_unique($arr);$A__A_A_A="count";$P2gAC0=$A__A_A_A($arr_unique);$A__A_AA_="count";$P2gAC1=$A__A_AA_($arr);$P2g0=$P2gAC0!=$P2gAC1;if($P2g0)goto P2gBodyx6;goto P2gNextx6;P2gBodyx6:return response()->json(['code'=>1,'msg'=>'存在重复的资质名称,请仔细检查']);goto P2gx5;P2gNextx6:P2gx5:$model=Dictionary::where(['slug'=>'product_video'])->first();$A__A_AAA="count";$P2gAC0=$A__A_AAA($arr);$P2g0=$P2gAC0>$model->max_num;if($P2g0)goto P2gBodyx8;goto P2gNextx8;P2gBodyx8:return response()->json(['code'=>1,'msg'=>'最多添加'.$model->max_num.'条个人资质']);goto P2gx7;P2gNextx8:P2gx7:$old_ids=$request->input('ids',[]);DB::beginTransaction();try{ProductVideo::whereNotIn('id',$old_ids)->delete();if($old)goto P2gBodyxb;goto P2gNextxb;P2gBodyxb:foreach($old as $item){$id=$item['id'];unset($item['id']);ProductVideo::where(['id'=>$id])->update($item);}goto P2gxa;P2gNextxb:P2gxa:if($news)goto P2gBodyxd;goto P2gNextxd;P2gBodyxd:foreach($news as $value){ProductVideo::create($value);}goto P2gxc;P2gNextxd:P2gxc:$query=ProductVideo::select()->orderBy('sort','desc');Dictionary::where(['slug'=>'product_video'])->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()]);}}}
?>