<?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\ProductOrder as ProductOrderModel;

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

        if(!empty($get_data['ProductIds'])){
            $where['ProductId'] = $get_data['ProductIds'];
        }
        if(!empty($get_data['PackageNames'])){
            $where['PackageName'] = $get_data['PackageNames'];
        }
        if(!empty($get_data['OrderTypes'])){
            $where['OrderType'] = $get_data['OrderTypes'];
        }
        if (!empty($_GET['Btime'])){
            $date1 = date('Y-m-d', strtotime($_GET['Btime']));
            $date2 = date('Y-m-d', strtotime($_GET['Etime']));
            $where_str .= " AND UpdateTime>='" . $date1 . "' and UpdateTime<='" . $date2 . "' ";
        }
        if (!empty($get_data['keyWord'])){
            $where['UserName'] = ['like','%'.$get_data['keyWord'].'%'];
        }


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


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

}