<?php
/**
 *
 * @author min晓天
 * @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') {
    if(!empty($_GPC['status'])){
        $ids = $_GPC['id'];
        $id = intval($ids);
        $status = intval($_GPC['status']);
        if (!is_array($ids)) {
            $ids = array(
                $ids
            );
        }
        $status = intval($_GPC['status']);
        foreach ($ids as $id) {
            if($status==6){
                $result= pdo_delete('evzg_express_member', array(
                    'uniacid' => $_W['uniacid'],
                    'id' => $id
                ));
            }else{
                if ($id <= 0)
                    continue;
                $result= pdo_update('evzg_express_member', array(
                    'status' => $status
                ), array(
                    'uniacid' => $_W['uniacid'],
                    'id' => $id
                ));
            }
        }
        if($result){
            message('删除用户成功', referer(), 'success');
        }else{
            message('删除用户失败', referer(), 'error');
        }
    }
    $condition      = ' WHERE uniacid = :aid ';
    $params[':aid'] = $_W['uniacid'];
    $pindex           = max(1, intval($_GPC['page']));
    $psize            = 20;
    $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('evzg_express_member') . $condition, $params);
    $list  = pdo_fetchall('SELECT * FROM ' . tablename('evzg_express_member') . $condition . ' ORDER BY id DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize, $params);
    foreach ($list as &$v){
        $expres =pdo_fetchcolumn("SELECT COUNT(*) FROM".tablename("evzg_express_expres")."WHERE mobile='{$v['mobile']}'");
        $v['expresssn'] = $expres;
        unset($v);
    }
    //分页
    $pager = pagination($total, $pindex, $psize);
    include $this->template('member');
}  elseif ($operation == 'delete') {
    $id = intval($_GPC['id']);
    $expres = pdo_fetch("SELECT id FROM " . tablename('evzg_express_member') . " WHERE id = '$id'");
    if (empty($expres)) {
        message('抱歉，会员件不存在或是已经被删除！', $this->createWebUrl('member', array(
            'op' => 'display','sid'=>$sid
        )), 'error');
    }
    pdo_delete('evzg_express_member', array(
        'id' => $id,
    ));
    message('会员删除成功！', $this->createWebUrl('member', array(
        'op' => 'display','sid'=>$sid
    )), 'success');
} elseif ($operation == 'list') {
    $id = intval($_GPC['id']);
    $member = pdo_fetch("SELECT * FROM " . tablename('evzg_express_member') . " WHERE id = '$id'");
    $condition      = ' WHERE uniacid = :aid AND mobile =:mobile';
    $params[':aid'] = $_W['uniacid'];
    $params[':mobile'] = $member['mobile'];
    $pindex           = max(1, intval($_GPC['page']));
    $psize            = 20;
    $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('evzg_express_expres') . $condition, $params);
    $lists  = pdo_fetchall('SELECT * FROM ' . tablename('evzg_express_expres') . $condition . ' ORDER BY displayorder DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize, $params);
    //分页
    $pager = pagination($total, $pindex, $psize);
    include $this->template('member');
}
