<?php
defined('IN_IA') or exit('Access Denied');
global $_GPC, $_W;
$settings = $this->module['config'];
$sql = "SELECT * FROM" . tablename("evzg_express_shop") . "WHERE openid='{$_W['openid']}' AND 	uniacid='{$_W['uniacid']}'";
$shop = pdo_fetch($sql);
$op = ! empty($_GPC['op']) ? $_GPC['op'] : 'display';
$shop_set = shop_get_set();
if (empty($shop)) {
    message("你不是门店管理者,请先注册", $this->createMobileUrl('login', array(
        'op' => 'reg'
    )), "error");
}
if(empty($shop['enabled'])){
    message("亲的店铺已被封停，请联系管理员开启",$this->createMobileUrl('shop'), "error");
}

if ($op == 'add') {
    $num = intval($_GPC['num']);
    if($num<=0){
        message("充值短信数量不能小于等于0",$this->createMobileUrl('paysms'),"error");
    }
    $data = array();
    $data['uniacid'] = $_W['uniacid'];
    $data['sid'] = $shop['id'];
    $data['title'] = "充值短信";
    $data['ordersn'] = order_no();
    $data['openid'] = $_W['openid'];
    $data['num'] = $num;
    $data['price'] = $num*floatval($shop_set['smsprice']);
    $data['createtime'] = time();
    $result = pdo_insert("evzg_express_sms_order",$data);
    $sms_order_id = pdo_insertid();
    if(!$result){
        message("短信充值出错",$this->createMobileUrl('paysms'),'error');
    }
    $params = array(
        'tid' => "sms".$sms_order_id,      //充值模块中的订单号，此号码用于业务模块中区分订单，交易的识别码
        'ordersn' => $data['ordersn'],  //收银台中显示的订单号
        'title' => '充值短信',          //收银台中显示的标题
        'fee' => $data['price'],      //收银台中显示需要支付的金额,只能大于 0
        'user' => $_W['member']['uid'],     //付款用户, 付款的用户名(选填项)
    );
    //调用pay方法
    $this->pay($params);
    exit();
}
$default='default/shop/';
include $this->template($default.'paysms');