<?php
defined('IN_IA') or exit('Access Denied');
global $_GPC, $_W;
$sql ="SELECT * FROM".tablename("evzg_express_member")."WHERE openid='{$_W['openid']}' AND 	uniacid='{$_W['uniacid']}'";
$member = pdo_fetch($sql);
$op = !empty($_GPC['op']) ? $_GPC['op']:'display';
if(empty($member['mobile'])){
    message("请先绑定手机号",$this->createMobileUrl('member',array('op'=>'addmobile')),"error");
}
if($op=='display'){
    $condition      = ' WHERE uniacid = :aid AND mobile = :mobile';
    $params[':aid'] = $_W['uniacid'];
    $params[':mobile'] = $member['mobile'];
    $lists  = pdo_fetchall('SELECT * FROM ' . tablename('evzg_express_expres') . $condition . ' ORDER BY displayorder DESC ', $params);
    foreach ($lists as &$v){
        $yy= pdo_fetch("SELECT * FROM".tablename("evzg_express_order")."WHERE eid='{$v['id']}'");
        $v['yystatus'] = $yy['status'];
        unset($v);
    }
    //var_dump($lists);die();
    include $this->template('express');
}
if($op=='yy'){
    $id=$_GPC['id'];
    $condition      = ' WHERE uniacid = :aid AND mobile = :mobile AND status = :status' ;
    $params[':aid'] = $_W['uniacid'];
    $params[':mobile'] = $member['mobile'];
    $params[':status'] =0;
    $date = date("Y-m-d",time());
    //var_dump($date);die();
    $lists  = pdo_fetchall('SELECT * FROM ' . tablename('evzg_express_expres') . $condition . ' ORDER BY displayorder DESC ', $params);
    include $this->template('yy');
}
if($op=='addyy'){
    $data['eid'] = intval($_GPC['exid']);
    if(empty($_GPC['address'])){
        message("预约地址不能为空",$this->createMobileUrl('express',array('op'=>'yy','id'=>$_GPC['eid'])),"error");
    }
    if(empty($_GPC['timeslot'])){
        message("预约时间不能为空",$this->createMobileUrl('express',array('op'=>'yy','id'=>$_GPC['eid'])),"error");
    }
    $data['address'] = trim($_GPC['address']);
    $data['timeslot'] = trim($_GPC['timeslot']);
    $data['createtime'] = time();
    $data['openid'] = $_W['openid'];
    $data['uniacid'] = $_W['uniacid'];
    $expresorder = pdo_fetch("SELECT * FROM".tablename("evzg_express_expres")."WHERE id='{$_GPC['exid']}'");
    $data['usercontent'] = json_encode($expresorder);
    $data['sid'] = $expresorder['sid'];
    $result= pdo_insert("evzg_express_order",$data);
    if($result){
        message("保存成功",$this->createMobileUrl('index',array('op'=>'member')),"success");
    }else{
        message("保存失败",$this->createMobileUrl('index',array('op'=>'member')),"error");
    }
}