<?php

/* ========================================================================
 * $Id: index.php 3049 2020-06-12 10:24:27Z onez $
 * 
 * Email: www@onez.cn
 * QQ: 6200103
 * HomePage: http://www.onez.cn
 * ========================================================================
 * Copyright 2016-2017 佳蓝科技.
 * 
 * ======================================================================== */

!defined('IN_ONEZ') && exit('Access Denied');
# index
#请求数据
if($MODE=='$post'){
  $action=onez()->gp('action');
  if($action=='data'){
    $id=(int)$_GET['id'];
    $T=$G['this']->data()->open('pay.temps')->one("id='$id'");
    $ac=onez()->gp('ac');
    if($ac=='check'){
      $A['status']=$T['key1'].'';
      return;
    }
    $A['pagedata']['header']['title']='支付方式';
    $navs=array();
    $A['pagedata']['navs']=$navs;
    if($T['key1']=='end'){
      $record[]=array(
        'type'=>'message',
        'status'=>'success',
        'text'=>'支付完成',
      );
      $A['pagedata']['waiting']=false;
      $A['pagedata']['record']=$record;
      return;
    }
    $req=$T['req'];
    $record=array();
    $record[]=array(
      'type'=>'space',
    );
    $record[]=array(
      'type'=>'pictext2',
      'subject'=>$req['subject'],
      'summary'=>'支付总额: ￥'.$req['price'].'元',
    );
    $record[]=array(
      'type'=>'space',
    );
    if($req['carts']){
      foreach($req['carts'] as $k=>$v){
        $record[]=array(
          'type'=>'pictext2',
          'nobr'=>'1',
          'icon'=>$v['image'],
          'subject'=>$v['title'],
          'summary'=>'单价:'.$v['price'].', 数量:'.$v['num'],
          'rt'=>'x'.$v['num'],
        );
      }
      $record[]=array(
        'type'=>'space',
      );
    }
    if(onez('bs')->is_weixin()){
      $u=$G['this']->userdb()->open('member')->one("id='$T[userid]'");
      
      $record[]=array(
        'type'=>'button',
        'skin'=>'success',
        'name'=>'微信支付',
        'event'=>array(
          'token'=>'api',
          'action'=>'bs.weixin:wxpay',
          'option'=>array(
            'price'=>$req['price'],
            'subject'=>$req['subject'],
            'openid'=>$u['openid'],
            'goto'=>onez()->cururl(),
            'siteId'=>$G['this']->site['id'],
            'sitetoken'=>$G['this']->token,
            'bstoken'=>$G['bs']?$G['bs']->token:'',
            'plugintoken'=>'bs.pay',
            'productId'=>$id,
          ),
        ),
      );
    }else{
      $hash=md5($req['price']."\t".$req['subject']."\t".onez('alipay')->hashkey);
      $url=onez('alipay')->view('getorder&jump=1&price='.urlencode($req['price']).'&subject='.urlencode($req['subject']).'&goto='.onez()->cururl().'&siteId='.$G['this']->site['id'].'&service=wap&sitetoken='.$G['this']->token.'&bstoken='.($G['bs']?$G['bs']->token:'').'&plugintoken=bs.pay&productId='.$id.'&hash='.$hash);
      $record[]=array(
        'type'=>'button',
        'skin'=>'info',
        'name'=>'支付宝支付',
        'event'=>array(
          'token'=>'location',
          'action'=>$url,
        ),
      );
    }
    $A['pagedata']['record']=$record;
    $u=$G['this']->userdb()->open('member')->one("id='$T[userid]'");
    $A['pagedata']['userid']=$u['id'];
    $A['pagedata']['openid']=$u['openid']?$u['openid']:false;
    $A['pagedata']['waiting']=true;
    $A['pagedata']['id']=$id;
  }
  return;
}
?>
<onez-m-page :data="$pagedata" />