<?php
// +----------------------------------------------------------------------
// | [ WE CAN DO IT MORE SIMPLE  ]
// +----------------------------------------------------------------------
// | Copyright (c) 2018-2020 rights reserved.
// +----------------------------------------------------------------------
// | Author: TABLE ME
// +----------------------------------------------------------------------
// | Date: 2020-11-08 12:56
// +----------------------------------------------------------------------

namespace app\system\controller\v1;


use app\BaseController;
use app\model\system\SiteTotal;
use app\Request;
use library\services\UtilService;

class Total extends BaseController {



    /**
     * 获取订单数据
     * @param Request $request
     */
    public function index(Request $request){
        $pageSize = 50;
        $post =  UtilService::getMore(
            [
                ['page',1],
                ['start_time',''],
                ['end_time','']
            ],$request
        );
        $func = function($val){ return empty($val) ? "0.00" : $val;};
        $where = $post;
        list($pageCount,$data) = (new \app\model\system\Site)->getList2($post['page'],$where,$pageSize);
        $result = UtilService::getParam([
            "sassid",
            "name",
            "user_count",
            "order_count",
            "sub_order_count",
            ["order_money","order_money",$func],
            ['recharge_money','recharge_money',$func],
            ['commission_money','commission_money',$func]
        ],$data);
        return app('json')->success([
            'list'      => $result,
            'pageCount' => $pageCount,
            'pageSize'  => $pageSize,
            'page'      => $post['page']
        ]);
    }

    /**
     * 业绩total
     * @param Request $request
     */
    public function siteTotal(Request $request) {
        $pageSize = 50;
        $post =  UtilService::getMore(
            [
                ['page',1],
                ['sassid','','empty','参数错误'],
                ['start_time',''],
                ['end_time','']
            ],$request
        );
        $where['st.sassid'] = $post['sassid'];
        if(!empty($post['start_time'])) {
            $where['st.time'] = [[strtotime($post['start_time']),strtotime($post['end_time'])],'whereBetween'];
        }
        list($pageCount,$data) = (new \app\model\system\SiteTotal())->getList($post['page'],$where,$pageSize,'*','time desc');
        $func = function($val){ return empty($val) ? "0.00" : $val;};
        $data = UtilService::getParam([
            "sassid",
            "name",
            ['time','time','date("Y-m-d",$1)'],
            "user_count",
            "order_count",
            "sub_order_count",
            ["order_money","order_money",$func],
            ['recharge_money','recharge_money',$func],
            ['commission_money','commission_money',$func]
        ],$data);
        return app('json')->success([
            'list'      => $data,
            'pageCount' => $pageCount,
            'pageSize'  => $pageSize,
            'page'      => $post['page']
        ]);
    }


}