<?php
namespace store\Admin;

use Dever;

class Stat extends Core
{
	# 列表
    public function getList()
    {
    	$where = array();
    	$where['store_id'] = $this->id;
    	$status = Dever::input('store_status');
    	if ($status) {
    		$where['store_status'] = $status;
    	}
    	$start = Dever::input('start');
    	if ($start) {
    		$where['start'] = $start;
    	}
    	$end = Dever::input('end');
    	if ($end) {
    		$where['end'] = $end;
    	}
        $data = Dever::db('cash/store')->getAll($where);

        $html = '';
        if ($data) {
        	$config = Dever::db('cash/store')->config;
        	foreach ($data as $k => $v) {

        		$view = Dever::url('stat_view?id=' . $v['id'] . '&type=store&show=2', 'store');

        		$url = Dever::url('lib/set.audit_other&id='.$v['id'].'&type=store', 'cash');
        		$button = '<a href="'.$view.'"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 layui-btn layui-btn-xs">查看详情</button></a>';

        		if ($v['store_status'] == 1) {
        			$button .= '&nbsp;&nbsp;<a href="javascript:;" onclick="load(\''.$url.'\', \''.Dever::load('cash/lib/set')->statYes($v, 'store').'\', \'请确认\')"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 layui-btn layui-btn-xs">确认对账数量</button></a>';
        		}


        		$html .= '<tr><td>'.Dever::load("cash/lib/set.statDate", $v['type'], $v['day']).'</td><td>'.Dever::load("cash/lib/set.statTime", $v['start'], $v['end']).'</td><td>'.$v['num'].'</td><td>'.$config['config_status'][$v['store_status']].'</td><td>'.$button.'</td></tr>';
        	}
        }
        return $html;
    }

    # 获取列表页搜索信息
    public function getSearch()
    {
    	$config = array
        (
        	array('value' => '0', 'name' => '全部'),
            array('value' => 1, 'name' => '未对账'),
            array('value' => 2, 'name' => '已对账'),
        );

        $status = Dever::input('store_status');

        $html = '';
        foreach ($config as $k => $v) {
        	$selected = '';
    		if ((!$status && $k == 0) || $status == $v['value']) {
    			$selected = 'selected=""';
    		} 

    		$html .= '<option value="'.$v['value'].'" '.$selected.'>'.$v['name'].'</option>';
    	}

        return $html;
    }

    # 获取基本信息
    public function getConfig()
    {
    	$data['search'] = Dever::url('stat', 'store');

    	return $data;
    }

    # 打印订单单
    public function print_api()
    {
        return Dever::load('cash/lib/set')->printer($this->user);
    }
}