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

namespace App\Http\Controllers\Admin;use App\Models\Apply;use App\Models\Channel;use App\Models\Member;use App\Models\MemberHasLevel;use App\Models\MemberLevel;use App\Models\MemberMoneyRecord;use App\Models\Product;use App\Models\ProductType;use App\Models\SettingLevelOption;use App\Models\SettingManager;use App\Models\SettingMemberLevel;use App\Models\User;use App\Models\UserModel;use Illuminate\Http\Request;use App\Http\Controllers\Controller;class UserAgentController extends Controller{public function setting(){return view('admin.member.agent.agent');}public function settingData(Request $request){$res=MemberLevel::paginate($request->get('limit',30))->toArray();$W33AC0=array();$W33AC0['code']=0;$W33AC0['msg']='正在请求中...';$W33AC0['count']=$res['total'];$W33AC0['data']=$res['data'];$data=$W33AC0;return response()->json($data);}public function data(Request $request,Member $member){$W330=$request->get('end_time')<$request->get('start_time');if($W330)goto W33Bodyx2;goto W33Nextx2;W33Bodyx2:$W33AC0=array();$W33AC0['code']=1;$W33AC0['msg']='结束时间不能小于开始时间';$W33AC0['count']='';$W33AC0['data']='';$data=$W33AC0;return response()->json($data);goto W33x1;W33Nextx2:W33x1:$res=$this->_query_box($request,$member);$W33AC0=array();$W33AC0['code']=0;$W33AC0['msg']='正在请求中...';$W33AC0['count']=$res['total'];$W33AC0['data']=$res['data'];$data=$W33AC0;return response()->json($data);}public function _query_box($request,$model,$type='index'){$user=User::find(auth()->user()->id);$phone=$request->phone;$model=$model->query();if($request->get('start_time'))goto W33Bodyx4;goto W33Nextx4;W33Bodyx4:$model=$model->where('created_at','>',$request->get('start_time'));goto W33x3;W33Nextx4:W33x3:if($request->get('end_time'))goto W33Bodyx6;goto W33Nextx6;W33Bodyx6:$model=$model->where('created_at','<=',$request->get('end_time'));goto W33x5;W33Nextx6:W33x5:if($request->get('phone'))goto W33Bodyx8;goto W33Nextx8;W33Bodyx8:$model=$model->where('phone','like',"%".$phone."%");goto W33x7;W33Nextx8:W33x7:if($request->level)goto W33Bodyxa;goto W33Nextxa;W33Bodyxa:$ids=MemberHasLevel::whereIn('level_id',$request->level)->distinct('member_id')->pluck('member_id')->all();goto W33x9;W33Nextxa:$all=MemberHasLevel::get()->toArray();$ids=array_column($all,'member_id');W33x9:$media_manager=SettingManager::where('type',1)->first();$model=$model->whereIn('id',$ids);$res=$model->orderBy('created_at','desc')->with(['page','info'])->paginate($request->get('limit',30))->toArray();foreach($res['data']as $k=>&$re){$re['products']=Product::where(['member_id'=>$re['id'],'created_from'=>'media'])->count();$re['applies']=Apply::where('mid',$re['id'])->where('status','>','1')->count();$re['media_manager']=$media_manager->name;$account=MemberMoneyRecord::where(['mid'=>$re['id']])->orderBy('id','desc')->first();if($account)goto W33Bodyxc;goto W33Nextxc;W33Bodyxc:$re['account']=$account->total_money;goto W33xb;W33Nextxc:W33xb:$W330=!$user->isRoot();if($W330)goto W33Bodyxe;goto W33Nextxe;W33Bodyxe:$A_AA_A="substr_replace";$W33AC0=$A_AA_A($re['phone'],'****',3,5);$res['data'][$k]['phone']=$W33AC0;goto W33xd;W33Nextxe:W33xd:}return $res;}public function index(){return view('admin.member.agent.index');}public function account(){return view('admin.member.agent.account');}public function chargeSetting(){$setting=SettingMemberLevel::first();$type=ProductType::where('status',1)->get();$setting->category=explode(',',$setting->category);return view('admin.member.agent.setting',compact('setting','type'));}public function settingUpdate(Request $request){$category=implode(',',$request->input('category'));$info=SettingMemberLevel::first();$info->type=$request->type;$info->category=$category;$info->save();SettingLevelOption::create(['uid'=>auth()->user()->id??0,'mark'=>'更改充值类型为：'.$request->type.'修改代理优惠类型为：'.$category,]);return redirect('/admin/agent/setting');}public function create(){return view('admin.member.agent.create');}public function edit($id){$info=MemberLevel::where('id',$id)->first();return view('admin.member.agent.edit',compact('info'));}public function update(Request $request){$data['name']=$request->name;$data['limit']=$request->limit;$data['status']=$request->status;$data['sale']=$request->sale;if(isset($request->id))goto W33Bodyxg;goto W33Nextxg;W33Bodyxg:$W330=$request->id;goto W33xf;W33Nextxg:$W330='';W33xf:$id=$W330;if($id)goto W33Bodyxi;goto W33Nextxi;W33Bodyxi:$W330='修改名称为：' . $data['name'];$W331=$W330 . ',限制为：';$W332=$W331 . $data['limit'];$W333=$W332 . '状态为：';$W334=$W333 . $data['status'];$W335=$W334 . '优惠比例为：';$W336=$W335 . $data['sale'];$mark=$W336;MemberLevel::where('id',$id)->update($data);goto W33xh;W33Nextxi:$W330='修改名称为：' . $data['name'];$W331=$W330 . ',限制为：';$W332=$W331 . $data['limit'];$W333=$W332 . '状态为：';$W334=$W333 . $data['status'];$W335=$W334 . '优惠比例为：';$W336=$W335 . $data['sale'];$mark=$W336;MemberLevel::create($data);W33xh:SettingLevelOption::create(['uid'=>auth()->user()->id,'mark'=>$mark,]);return redirect('/admin/agent/setting');}}
?>