<?php
defined('IN_IA') or exit('Access Denied');
global $_GPC, $_W;
$settings = $this->module['config'];
mload()->model('sms');
$op = ! empty($_GPC['op']) ? $_GPC['op'] : 'list';

if ($op == 'list') {
    $ids = $_GPC['id'];
    $id = intval($ids);
    $status = intval($_GPC['status']);
    if (!is_array($ids)) {
        $ids = array(
            $ids
        );
    }
    foreach ($ids as $id) {
        if($status==5){
            $result= pdo_delete('evzg_express_sms_order', array(
                'uniacid' => $_W['uniacid'],
                'id' => $id
            ));
        }else{
            if ($id <= 0)
                continue;
            if($status==2){
                $status=0;
            }
            $result= pdo_update('evzg_express_sms_order', array(
                'status' => $status
            ), array(
                'uniacid' => $_W['uniacid'],
                'id' => $id
            ));
        }
    }
    if($result){
        message('操作成功！', referer(), 'success');
    }
    $sid = $member['id'];
    $condition = ' WHERE t.uniacid = :aid AND t.sid = m.id';
    $params[':aid'] = $_W['uniacid'];
    $pindex = max(1, intval($_GPC['page']));
    $psize = 20;
    $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('evzg_express_sms_order') . " WHERE uniacid = '{$_W['uniacid']}' ORDER BY id  DESC");
    $list = pdo_fetchall('SELECT t.*,m.name as name FROM ' . tablename('evzg_express_sms_order').'as t,'.tablename("evzg_express_shop").'as m' . $condition . ' ORDER BY id DESC ', $params);
    $pager = pagination($total, $pindex, $psize);
    include $this->template('paysms');
}
if($op == 'pay'){
    $id = $_GPC['id'];
    $smsOrder = pdo_get("evzg_express_sms_order",array('id'=>$_GPC['id']));
    if(empty($smsOrder)){
        message("支付不存在",referer(),'error');
    }
    pdo_update("evzg_express_sms_order",array('status'=>1,'paytime'=>time()),array('id'=>$_GPC['id']));
    $result =  sms_order_paystaus($id);
    message("支付成功",referer(),'success');
}
if($op == 'del'){
    $smsOrder = pdo_get("evzg_express_sms_order",array('id'=>$_GPC['id']));
    if(empty($smsOrder)){
        message("支付不存在",referer(),'error');
    }
    pdo_delete("evzg_express_sms_order",array('id'=>$_GPC['id']));
    message("删除支付成功",referer(),'success');
}
if($op == 'close'){

    $smsOrder = pdo_get("evzg_express_sms_order",array('id'=>$_GPC['id']));
    if(empty($smsOrder)){
        message("支付不存在",referer(),'error');
    }
    pdo_update("evzg_express_sms_order",array('status'=>'-1'),array('id'=>$_GPC['id']));
    message("取消支付成功",referer(),'success');
}

