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

namespace App\Http\Controllers\Api\V1;use App\Http\Controllers\BaseController;use App\Models\Cart;use App\Models\Member;use App\Models\Product;use App\Models\ProductHasType;use App\Models\ProductType;use Illuminate\Http\Request;use Illuminate\Support\Facades\DB;use Illuminate\Support\Facades\Validator;class CartController extends BaseController{public function index(Request $request){$validate=Validator::make($request->all(),['type_id'=>'required',]);$O280=!$validate->fails();if($O280)goto O28Bodyx2;goto O28Nextx2;O28Bodyx2:$exist=ProductHasType::where(['type_id'=>$request->type_id])->get(['product_id']);if($exist)goto O28Bodyx4;goto O28Nextx4;O28Bodyx4:$ids=$exist->pluck('product_id')->toArray();$list=Cart::with(['product'=>function($query){$query->with(['label','corner'=>function($query){$query->select(['id','name','url']);},'website','type','collect','video','trade','resource'])->select(['id','name','logo','quota_min','quota_max','slogan','corner_id','market_element','fast_lend_sort']);}])->where(['type'=>$request->type_id,'mid'=>$request->uid])->whereIn('product_id',$ids)->paginate($this->page_sizes);$A___AA__A="count";$O28AC0=$A___AA__A($list);if($O28AC0)goto O28Bodyx6;goto O28Nextx6;O28Bodyx6:$this->set('data',$list);goto O28x5;O28Nextx6:$this->set('type',$this->noContent);$this->set('info','暂无内容');O28x5:goto O28x3;O28Nextx4:$this->set('type',$this->noContent);$this->set('info','暂无内容');O28x3:goto O28x1;O28Nextx2:$this->set('type',$this->badRequest);$this->set('info','参数错误');O28x1:return $this->jsonResponse();}public function store(Request $request){$validate=Validator::make($request->all(),['id'=>'required',]);$O280=!$validate->fails();if($O280)goto O28Bodyx8;goto O28Nextx8;O28Bodyx8:$product=Product::with('pro_type')->where('status',1)->find($request->id);if($product)goto O28Bodyxa;goto O28Nextxa;O28Bodyxa:DB::beginTransaction();try{$type=$product->pro_type['type_id'];$cart=Cart::where(['mid'=>$request->uid,'type'=>$type,'product_id'=>$request->id])->first();$O280=!$cart;if($O280)goto O28Bodyxd;goto O28Nextxd;O28Bodyxd:Cart::create(['mid'=>$request->uid,'type'=>$type,'number'=>1,'status'=>1,'product_id'=>$request->id]);goto O28xc;O28Nextxd:O28xc:DB::commit();}catch(\Exception $e){DB::rollBack();$this->set('type',$this->serviceError);}goto O28x9;O28Nextxa:$this->set('type',$this->noContent);$this->set('info','暂无内容');O28x9:goto O28x7;O28Nextx8:$this->set('type',$this->badRequest);$this->set('info','参数错误');O28x7:return $this->jsonResponse();}public function modify(Request $request,$id){$validate=Validator::make($request->all(),['id'=>'required','action'=>'required']);$O280=!$validate->fails();$O281=(bool)$O280;if($O281)goto O28Bodyxg;goto O28Nextxg;O28Bodyxg:$O281=(bool)in_array($request->action,['add','reduce','delete']);goto O28xf;O28Nextxg:O28xf:if($O281)goto O28Bodyxh;goto O28Nextxh;O28Bodyxh:$product=Cart::find($id);if($product)goto O28Bodyxj;goto O28Nextxj;O28Bodyxj:$O280=$request->action=='add';if($O280)goto O28Bodyxl;goto O28Nextxl;O28Bodyxl:$product->number=$product->number++;$product->save();goto O28xk;O28Nextxl:$O280=$request->action=='reduce';if($O280)goto O28Bodyxm;goto O28Nextxm;O28Bodyxm:$O280=$product->number==1;if($O280)goto O28Bodyxo;goto O28Nextxo;O28Bodyxo:$product->delete();goto O28xn;O28Nextxo:$product->number=$product->number--;$product->save();O28xn:goto O28xk;O28Nextxm:$product->delete();O28xk:goto O28xi;O28Nextxj:$this->set('type',$this->noContent);$this->set('info','暂无内容');O28xi:goto O28xe;O28Nextxh:$this->set('type',$this->badRequest);$this->set('info','参数错误');O28xe:return $this->jsonResponse();}}
?>