<?php
/**
 * @author min晓天 QQ416883181
 * @url http://bbs.we7.cc/
 */
defined('IN_IA') or exit('Access Denied');
global $_GPC, $_W;
$settings = $this->module['config'];
load()->func('tpl');
$operation = ! empty($_GPC['op']) ? $_GPC['op'] : 'display';
$sid = $_GPC['sid'];
if ($operation == 'display') {
        mload()->model('sms');
        $status = intval($_GPC['status']);
        if(!empty($status)){
            $ids = $_GPC['id'];
            $id = intval($ids);

            if (!is_array($ids)) {
                $ids = array(
                    $id
                );
            }
            foreach ($ids as $id) {
               if ($_GPC['status'] == '-1') {
                 $result =   pdo_delete('evzg_express_log', array('id' => $id));
               }
            }
            if($result){
                message('更新状态成功', referer(), 'success');
            }else{
                message('更新状态失败', referer(), 'error');
            }
    }

    $condition = ' WHERE uniacid = :aid ';
    $params[':aid'] = $_W['uniacid'];
    $type = $_GPC['type'];
    if(!empty($type)&&$type>0){
       $condition.= ' AND type = :type ';
       $params[':type'] = $type;
    }
    $uername = $_GPC['username'];
    if(!empty($uername)){
        $condition.= ' AND operator = :operator ';
        $params[':operator'] = $uername;
    }
    $starttime = strtotime($_GPC['starttime']);
	$endtime = strtotime($_GPC['endtime']);
	if($starttime != '' && $endtime != ''){
		$condition .= ' and addtime >= ' . $starttime . ' and addtime <= ' . $endtime;
		$starttime_a = date("Y-m-d  H:i:s", $starttime);
		$endtime_a = date("Y-m-d  H:i:s", $endtime);
	}
    $pindex = max(1, intval($_GPC['page']));
    $psize = 20;
    $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('evzg_express_log') . $condition, $params);
    $list = pdo_fetchall('SELECT * FROM ' . tablename('evzg_express_log') . $condition . ' ORDER BY id DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize, $params);
    foreach ($list as &$item) {
        $member = pdo_get('evzg_express_member',array('openid'=>$item['openid']));
        $item['nickname'] = $member['nickname'];
        sms_check_sendcode($item['id'],$settings);
        unset($item);
    }
    // 分页
    $pager = pagination($total, $pindex, $psize);
    include $this->template('log');
}
if($operation=='delete'){
    $id = intval($_GPC['id']);
    $expres = pdo_fetch("SELECT id FROM " . tablename('evzg_express_log') . " WHERE id = '$id'");
    if (empty($expres)) {
        message('抱歉，记录不存在或是已经被删除！', $this->createWebUrl('log', array(
            'op' => 'display'
        )), 'error');
    }
    pdo_delete('evzg_express_log', array(
        'id' => $id
    ));
    message('记录删除成功！', $this->createWebUrl('log', array(
        'op' => 'display'
    )), 'success');
}