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

namespace App\Http\Controllers\Admin;use App\Http\Requests\ProductCategoryCreateRequest;use App\Http\Requests\ProductCategoryUpdateRequest;use App\Models\ProductCategory;use Illuminate\Http\Request;use App\Http\Controllers\Controller;use Illuminate\Support\Facades\DB;use Illuminate\Support\Facades\Storage;class ProductCategoryController extends Controller{public function index(){return view('admin.product_category.index');}public function data(Request $request){$pageSize=$request->input('limit',$this->pageSize);$field=$request->input('field','sort');$order=$request->input('order','desc');$res=ProductCategory::select();$res=$res->orderBy($field,$order)->paginate($pageSize)->toArray();if($res['data'])goto P2gBodyx2;goto P2gNextx2;P2gBodyx2:foreach($res['data']as $key=>$item){$P2g0=env('IMG_URL') . $item['icon'];$item['icon']=$P2g0;$P2g0=env('IMG_URL') . $item['banner'];$item['banner']=$P2g0;$res['data'][$key]=$item;}goto P2gx1;P2gNextx2:P2gx1:$P2gAC0=array();$P2gAC0['code']=0;$P2gAC0['msg']='正在请求中...';$P2gAC0['count']=$res['total'];$P2gAC0['data']=$res['data'];$data=$P2gAC0;return response()->json($data);}public function create(){$P2g0=new ProductCategory();$productCategory=$P2g0;return view('admin.product_category.create',compact('productCategory'));}public function store(ProductCategoryCreateRequest $request){$data=$request->except(['_method','_token']);if(ProductCategory::create($data))goto P2gBodyx4;goto P2gNextx4;P2gBodyx4:return response()->json(['code'=>0,'msg'=>'保存成功']);goto P2gx3;P2gNextx4:return response()->json(['code'=>1,'msg'=>'保存失败']);P2gx3:}public function show($id){}public function edit($id){$productCategory=ProductCategory::findOrFail($id);return view('admin.product_category.edit',compact('productCategory'));}public function update(ProductCategoryUpdateRequest $request,$id){$data=$request->except(['_method','_token','id','file']);$P2g0=!$data['redirect_type'];if($P2g0)goto P2gBodyx6;goto P2gNextx6;P2gBodyx6:$data['redirect_slug']=null;$data['redirect_id']=null;$data['banner_redirect']=null;goto P2gx5;P2gNextx6:$P2g0=$data['redirect_type']=='inside';if($P2g0)goto P2gBodyx8;goto P2gNextx8;P2gBodyx8:$data['banner_redirect']=null;$AAA_AAA="in_array";$P2gAC0=$AAA_AAA($data['redirect_slug'],['product','credit','article']);$P2g0=!$P2gAC0;if($P2g0)goto P2gBodyxa;goto P2gNextxa;P2gBodyxa:$data['redirect_id']=null;goto P2gx9;P2gNextxa:P2gx9:goto P2gx7;P2gNextx8:$data['redirect_slug']=null;$data['redirect_id']=null;P2gx7:P2gx5:if(ProductCategory::where(['id'=>$id])->update($data))goto P2gBodyxc;goto P2gNextxc;P2gBodyxc:return response()->json(['code'=>0,'msg'=>'保存成功']);goto P2gxb;P2gNextxc:return response()->json(['code'=>1,'msg'=>'保存失败']);P2gxb:}public function destroy(Request $request){$ids=$request->get('ids');$P2g0=!$ids;if($P2g0)goto P2gBodyxe;goto P2gNextxe;P2gBodyxe:return response()->json(['code'=>1,'msg'=>'请选择删除项']);goto P2gxd;P2gNextxe:P2gxd:DB::beginTransaction();try{$icons=ProductCategory::whereIn('id',$ids)->pluck('icon')->all();$banners=ProductCategory::whereIn('id',$ids)->pluck('banner')->all();if($icons)goto P2gBodyxh;goto P2gNextxh;P2gBodyxh:foreach($icons as $k=>$icon){$P2g0='public/' . $icon;$icons[$k]=$P2g0;}Storage::delete($icons);goto P2gxg;P2gNextxh:P2gxg:if($banners)goto P2gBodyxj;goto P2gNextxj;P2gBodyxj:foreach($banners as $k=>$banner){$P2g0='public/' . $banner;$banners[$k]=$P2g0;}Storage::delete($banners);goto P2gxi;P2gNextxj:P2gxi:ProductCategory::whereIn('id',$ids)->delete();DB::commit();return response()->json(['code'=>0,'msg'=>'删除成功']);}catch(\Exception $exception){return response()->json(['code'=>1,'msg'=>'删除失败'.$exception->getMessage()]);}}}
?>