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

namespace App\Http\Controllers\Admin;use App\Models\Dictionary;use App\Models\ProductRangePeriod;use Illuminate\Http\Request;use App\Http\Controllers\Controller;use Illuminate\Support\Facades\DB;class ProductRepayController extends Controller{public function index(){$repays=ProductRangePeriod::select()->orderBy('sort','desc')->get();$model=Dictionary::where(['slug'=>'product_repay'])->first();return view('admin.dictionary.repay',compact('repays','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,'type');$arr=array_merge($arr,$arr_new);goto P2gx1;P2gNextx2:P2gx1:if($old)goto P2gBodyx4;goto P2gNextx4;P2gBodyx4:$arr_old=array_pluck($old,'type');$arr=array_merge($arr,$arr_old);goto P2gx3;P2gNextx4:P2gx3:$old_ids=$request->input('ids',[]);DB::beginTransaction();try{ProductRangePeriod::whereNotIn('id',$old_ids)->delete();if($old)goto P2gBodyx7;goto P2gNextx7;P2gBodyx7:foreach($old as $item){$id=$item['id'];unset($item['id']);if(isset($item['per_value']))goto P2gBodyx9;goto P2gNextx9;P2gBodyx9:$P2g0=$item['per_value'];goto P2gx8;P2gNextx9:$P2g0=0;P2gx8:$item['per_value']=$P2g0;if(isset($item['min']))goto P2gBodyxb;goto P2gNextxb;P2gBodyxb:$P2g0=$item['min'];goto P2gxa;P2gNextxb:$P2g0=0;P2gxa:$item['min']=$P2g0;if(isset($item['max']))goto P2gBodyxd;goto P2gNextxd;P2gBodyxd:$P2g0=$item['max'];goto P2gxc;P2gNextxd:$P2g0=0;P2gxc:$item['max']=$P2g0;ProductRangePeriod::where(['id'=>$id])->update($item);}goto P2gx6;P2gNextx7:P2gx6:if($news)goto P2gBodyxf;goto P2gNextxf;P2gBodyxf:foreach($news as $value){ProductRangePeriod::create($value);}goto P2gxe;P2gNextxf:P2gxe:$P2gAC0=array();$names=$P2gAC0;$query=ProductRangePeriod::select()->orderBy('sort','desc');$repays=$query->get();if($repays->count())goto P2gBodyxh;goto P2gNextxh;P2gBodyxh:foreach($repays as $repay){$range='';$P2g0=$repay->type==2;if($P2g0)goto P2gBodyxj;goto P2gNextxj;P2gBodyxj:$P2g0=$repay->min . '~';$P2g1=$P2g0 . $repay->max;$name=$P2g1;goto P2gxi;P2gNextxj:$name=$repay->per_value;$P2g0=$repay->type==1;if($P2g0)goto P2gBodyxl;goto P2gNextxl;P2gBodyxl:$range='以内';goto P2gxk;P2gNextxl:$range='以上';P2gxk:P2gxi:$P2g0=$repay->unit=='week';if($P2g0)goto P2gBodyxn;goto P2gNextxn;P2gBodyxn:$P2g0='周' . $range;$name=$name.$P2g0;goto P2gxm;P2gNextxn:$P2g0=$repay->unit=='month';if($P2g0)goto P2gBodyxo;goto P2gNextxo;P2gBodyxo:$P2g0='个月' . $range;$name=$name.$P2g0;goto P2gxm;P2gNextxo:$P2g0=$repay->unit=='year';if($P2g0)goto P2gBodyxp;goto P2gNextxp;P2gBodyxp:$P2g0='年' . $range;$name=$name.$P2g0;goto P2gxm;P2gNextxp:$P2g0='天' . $range;$name=$name.$P2g0;P2gxm:$names[]=$name;$P2g0=$name;}goto P2gxg;P2gNextxh:P2gxg:Dictionary::where(['slug'=>'product_repay'])->update(['content'=>implode('、',$names),'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()]);}}}
?>