<?php

namespace app\agent\controller;

use fastphp\base\Controller;
use app\agent\model\AgentUser;
use app\agent\model\User as UserModel;
use app\agent\model\AgentScore as AgentScoreModel;

class Score extends Controller
{
    //账号列表
    public function getList ()
    {
        $agent_id = $this->userinfo['OperaterID'];
        $page = 0;
        if (isset($_GET['PageIndex'])) {
            $page = ($_GET['PageIndex'] - 1) * 50;
        }
        $where = [];
        $where_str = '';
        $where['agent_id'] = $agent_id;

        if (!empty($_GET['Btime'])){
            $date1 = date('Y-m-d', strtotime($_GET['Btime']));
            $date2 = date('Y-m-d', strtotime($_GET['Etime']));
            $where_str .= " UpdateTime>='" . $date1 . "' and UpdateTime<='" . $date2 . "' ";
        }


        
        $score_model = new AgentScoreModel;
        $list = $score_model->getAgentListPage($where,$where_str, '*', 'id desc', "$page,50");


        $data = [
            'Code' => 10000,
            'Data' => $list,
            'Message' => '',
            'TotalCount' => (int)$score_model->getCount($where)['count'],
        ];
        echo json_encode($data);
    }

     //账号列表
     public function getScoreList ()
     {
         
        $get_data = $_GET;
         $page = 0;
         if (isset($_GET['PageIndex'])) {
             $page = ($_GET['PageIndex'] - 1) * 50;
         }
         $where = [];
         $where_str = '';

         if(!empty($get_data['keyWord'])){
            $agent_user_model = new AgentUser;
            $id = $agent_user_model->getOne(['username'=>$get_data['keyWord']])['id'];
            $where['agent_id'] = $id;
         }

         if(!empty($get_data['id'])){
            $where['agent_id'] = $get_data['id'];
         }
 
         if (!empty($_GET['Btime'])){
             $date1 = date('Y-m-d', strtotime($_GET['Btime']));
             $date2 = date('Y-m-d', strtotime($_GET['Etime']));
             $where_str .= " UpdateTime>='" . $date1 . "' and UpdateTime<='" . $date2 . "' ";
         }
 
 
         
         $score_model = new AgentScoreModel;
         $list = $score_model->getAgentListPage($where,$where_str, '*', 'id desc', "$page,50");
 
 
         $data = [
             'Code' => 10000,
             'Data' => $list,
             'Message' => '',
             'TotalCount' => (int)$score_model->getCount($where)['count'],
         ];
         echo json_encode($data);
     }

}