<?php

namespace  App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class GloryController extends Controller{


    //获取奖励金明细列表
    public function all(Request $request){
        $dt=[];
        $users = DB::table('glory')->join('user','user.id','=','glory.uid')
            ->where('glory.season',$request->season)
            ->select('user.nickname','user.phone','glory.bonus','user.level_name','glory.glory','glory.rank','glory.integral')->paginate(15);
        $dt=[];
        $total=0;
        if ($users->items()){
            foreach ($users->items() as $k=>$v){
                $dt[$k]['nickname'] = $v->nickname;
                $dt[$k]['phone'] = $v->phone;
                $dt[$k]['rank'] = $v->rank;
                $dt[$k]['type'] = $v->glory;
                $dt[$k]['score'] = $v->integral;
                $dt[$k]['level_name'] =$v->level_name;
                $dt[$k]['bonus'] = $v->bonus;
            }
            $total=$users->total();
        }

        return $this->success_list($dt,'',$users->total());
    }
    //搜索奖励金明细列表
    public function search(Request $request){
        $phone = $request->phone;
        $dt=[];
        $users = DB::table('user')->select('id','nickname','phone','level_name')->where('phone','=',$phone)->first();
        if ($users){
            $glory = DB::table('glory')->select('rank','glory','bonus','integral')->where('uid','=',$users->id)->where('season',$request->season)->get();
            if ($glory){
                foreach ($glory as $k=>$v){
                    $dt[$k]['nickname'] = $users->nickname;
                    $dt[$k]['phone'] = $users->phone;
                    $dt[$k]['rank'] = $v->rank;
                    $dt[$k]['score'] = $v->integral;
                    $dt[$k]['type'] = $v->glory;
                    $dt[$k]['level_name'] =$users->level_name;
                    $dt[$k]['bonus'] = $v->bonus;
                }
            }
        }

        return $this->success_list($dt,'',1);


    }
}