<?php
defined('IN_IA') or exit('Access Denied');
global $_GPC, $_W;
$op =$_GPC['op'];
$sql ="SELECT * FROM".tablename("evzg_express_member")."WHERE openid='{$_W['openid']}' AND 	uniacid='{$_W['uniacid']}'";
$member = pdo_fetch($sql);
if($op=='addmobile'){
   include $this->template('mobile');
}
if($op=='post'){
   $code = $_GPC['code'];
   $mobile = $_GPC['mobile'];
   if($code!=$member['code']){
      message("验证码错误",$this->createMobileUrl('member',array('op'=>'addmobile')),"error");
   }
   //$memberinfo = mc_fansinfo($_W['openid']);
   $data['openid'] =$_W['fans']['openid'];
   $data['nickname'] =$_W['fans']['nickname'];
   $data['avatar'] =$_W['fans']['tag']['avatar'];
   $data['address'] =$_W['fans']['city'];
   $data['createtime'] = time();
   $data['mobile'] = $mobile;
   $result = pdo_update("evzg_express_member",$data,array('openid'=>$_W['openid']));
   if($result){
       message("手机号绑定成功",$this->createMobileUrl('index',array('op'=>'member')),"success");
   }
}
if($op=='address'){
    $condition      = ' uniacid = :aid ';
    $params[':aid'] = $_W['uniacid'];
    $community  = pdo_fetchall('SELECT * FROM ' . tablename('evzg_express_community') . ' WHERE ' . $condition . ' ORDER BY displayorder DESC,id ASC  ', $params, 'id');
    include $this->template('address');
}
if($op=='postaddress'){
    $data['community'] = intval($_GPC['community']);
    $data['address'] = trim($_GPC['address']);
    $result= pdo_update("evzg_express_member",$data,array('openid'=>$_W['openid']));
    if($result){
        message("保存成功",$this->createMobileUrl('index',array('op'=>'member')),"success");
    }else{
        message("保存失败",$this->createMobileUrl('index',array('op'=>'member')),"error");
    }
}
if($op=='postmember'){
    load()->classs('weixin.account');
    $account_api = WeAccount::create();
    $account_api->clearAccessToken();
    $access_token = $account_api->getAccessToken();
    if(!empty($_GPC['serverId'])){
      $avatar = getmedia($access_token,$_GPC['serverId'],"serverId");
      $avatar = toimage($avatar);
    }else{
      $avatar =  $_GPC['avatar'];
    }
    $data['avatar'] = $avatar;
    $data['shop'] = intval($_GPC['shop']);
    $data['community'] = intval($_GPC['community']);
    $data['address'] = trim($_GPC['address']);
    $result = pdo_update("evzg_express_member",$data,array('openid'=>$_W['openid']));
    if($result){
        message("保存成功",$this->createMobileUrl('index',array('op'=>'member')),"success");
    }else{
        message("保存失败",$this->createMobileUrl('index',array('op'=>'member')),"error");
    }
}