<?php
defined('IN_IA') or exit('Access Denied');
$operation = ! empty($_GPC['op']) ? $_GPC['op'] : 'display';
if($operation=='display'){
    global $_GPC, $_W;
    $settings = $this->module['config'];
    $sql = "SELECT * FROM" . tablename("evzg_express_shop") . "WHERE uniacid='{$_W['uniacid']}'";
    $shoplist = pdo_fetchall($sql);
    $sql = "SELECT * FROM" . tablename("evzg_express_expressuser") . "WHERE uniacid='{$_W['uniacid']}'";
    $deliveryers = pdo_fetchall($sql);

    $sid = $_GPC['sid'];
    $order_type = empty($_GPC['order_type'])?1:intval($_GPC['order_type']);
    if (!empty($_GPC['createtime'])) {
        $starttime = strtotime($_GPC['createtime']['start']);
        $endtime   = strtotime($_GPC['createtime']['end']) + 86399;
    } else {
        $starttime = strtotime('-180 day');
        $endtime   = TIMESTAMP;
    }
    $condition = ' WHERE uniacid = :aid ';
    $params[':aid'] = $_W['uniacid'];
    if(!empty($sid)){
     $condition.=" AND sid = :sid";
     $params[':sid'] = $sid;
    }
    $condition .= " AND createtime > :start AND createtime < :end";
    $params[':start'] = $starttime;
    $params[':end']   = $endtime;
    $pindex = max(1, intval($_GPC['page']));
    $psize = 20;
    $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('evzg_express_expressorder') . $condition, $params);
    if($order_type==1){
      $lists = pdo_fetchall('SELECT * FROM ' . tablename('evzg_express_expressorder') . $condition . ' ORDER BY id DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize, $params);
       $pager = pagination($total, $pindex, $psize);
    }
    if($order_type==2){
        $lists = pdo_fetchall('SELECT * FROM ' . tablename('evzg_express_expressorder') . $condition . ' ORDER BY id DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize, $params);
        $pager = pagination($total, $pindex, $psize);
    }
    // var_dump($sid);die();
    include $this->template('order');
}
if ($operation == 'delete') {
    $id = intval($_GPC['id']);
    $expres = pdo_fetch("SELECT id FROM " . tablename('evzg_express_expres') . " WHERE id = '$id'");
    if (empty($expres)) {
        message('抱歉，快件不存在或是已经被删除！', $this->createWebUrl('order'), 'error');
    }
    pdo_delete('evzg_express_expres', array(
        'id' => $id
    ));
    message('快件删除成功！', $this->createWebUrl('order'), 'success');
}