<?php

namespace app\admin\controller;

use app\admin\model\Admin;
use app\admin\model\User;
use app\common\controller\Backend;
use app\common\model\Attachment;
use fast\Date;
use think\Db;

/**
 * 控制台
 *
 * @icon   fa fa-dashboard
 * @remark 用于展示当前系统中的统计数据、统计报表及重要实时数据
 */
class Dashboard extends Backend
{

    /**
     * 查看
     */
    public function index()
    {
        //今日
        $starttime = strtotime(date('Y-m-d'));
        $endtime = $starttime + 86400 - 1;
        $map = [
            'paytime' => ['BETWEEN',[$starttime,$endtime]],
            'status'  => ['IN','1,2'],
        ];
        $today_order_amount = Db::name('order')->where($map)->sum('pay_fee');

        //七日
        $starttime = strtotime(date('Y-m-d')) - (86400*6);
        $endtime = $starttime + (86400*7) - 1;
        $map = [
            'paytime' => ['BETWEEN',[$starttime,$endtime]],
            'status'  => ['IN','1,2'],
        ];
        $serventoday_order_amount = Db::name('order')->where($map)->sum('pay_fee');

        //全部
        $map = [
            'status'  => ['IN','1,2'],
        ];
        $alltoday_order_amount = Db::name('order')->where($map)->sum('pay_fee');

        $this->view->assign([
            'today_order_amount'         => $today_order_amount,
            'serventoday_order_amount'        => $serventoday_order_amount,
            'alltoday_order_amount'        => $alltoday_order_amount,

        ]);

        return $this->view->fetch();
    }

}
