<?php

/* ========================================================================
 * $Id: pay.php 3921 2020-07-08 16:49:28Z onez $
 * 
 * Email: www@onez.cn
 * QQ: 6200103
 * HomePage: http://www.onez.cn
 * ========================================================================
 * Copyright 2016-2017 佳蓝科技.
 * 
 * ======================================================================== */

!defined('IN_ONEZ') && exit('Access Denied');
define('IS_ONEZ_DEBUG',1);
# pay
#请求数据
if($MODE=='$pay'){//在线支付
  $nickname=$G['nickname'];
  $sitetoken=$order['sitetoken'];
  $that=$sitetoken?onez($sitetoken):$G['this'];
  $that->payback($order);
  return;
}elseif($MODE=='$post'){
  $action=onez()->gp('action');
  if($action=='data'){
    $orderno=onez()->gp('orderno');
    $order=$G['this']->data()->open('temp.orders')->one("token='$orderno'");
    $data=$order['data'];
    $data['orderno']=$orderno;
    $A['pagedata']=$data;
    $ac=onez()->gp('ac');
    if($ac=='pay'){
      $data['$file']=__FILE__;
      $data['userid']=$G['userid'];
      $data['qq']=onez()->gp('qq');
      $data['email']=onez()->gp('email');
      $data['paytype']=onez()->gp('paytype');
      $G['this']->data()->open('temp.orders')->update(array('data'=>$data),"id='$order[id]'");
      $A['data']=$data;
      $A['orderno']=$orderno;
      $pay=onez('bs.pay')->pay($data);
      $pay && $A=array_merge($A,$pay);
      return;
    }
    
    $paytypes=array();
    $T2=$G['this']->data()->open('bs.pay.setting')->record("index1=1 order by step desc,id");
    foreach($T2 as $r){
      #余额支付必须登录
      if($r['token']=='system.amt'){
        if(!$G['userid']){
          continue;
        }
      }
      list($Token,$_token)=explode('.',$r['token']);
      $conFile=onez('bs.pay')->path.'/paytypes/'.$Token.'/'.$_token.'/config.php';
      $con=include($conFile);
      $paytypes[]=array(
        'name'=>$r['name'],
        'image'=>$con['logo'],
        'token'=>$r['token'],
      );
    }
    #商品列表
    if($data['proId']){
      $T=$G['this']->data()->open('products')->one("id='$data[proId]'");
      $A['pagedata']['products'][]=array(
        'name'=>$T['name'],
        'image'=>$T['image'],
      );
    }
    if($data['carts']){
      foreach($data['carts'] as $v){
        $A['pagedata']['products'][]=array(
          'name'=>$v['title'],
          'image'=>$v['image'],
        );
      }
    }
    $A['pagedata']['paytypes']=$paytypes;
    $A['pagedata']['myuserid']=(int)$G['userid'];
    $A['pagedata']['money']=onez('bs.money')->getMoney($G['userid'])*1;
    
    
  }
  return;
}
?>
<template v-if="$pagedata && $pagedata.paytypes">
<div class="item btns" v-if="pagedata.paytypes.length>0">
  <button type="button" :class="{active:item.token==payType}" v-for="item in pagedata.paytypes" @click="selPayType(item)">
  <van-icon :name="item.image" />
  {{item.name}}</button>
</div>
<div class="item item-info">
  <onez-pictext :icon="item.image" :name="item.name" v-if="payType!='user' && pagedata.products" v-for="item in pagedata.products" />
  <van-cell title="商品名称" :value="pagedata.subject" />
  <template v-for="item in pagedata.paytypes">
    <van-cell title="支付方式" v-if="item.token==payType" :value="item.name">
      <template #right-icon>
        <van-icon :name="item.image" />
      </template>
    </van-cell>
  </template>
  <van-cell title="订单编号" :value="pagedata.orderno" />
  <van-cell title="订单金额" :value="pagedata.price" />
  <van-cell title="账户余额" v-if="pagedata.myuserid>0 && payType=='system.amt'" :value="pagedata.money" />
</div>
<template v-if="pagedata.myuserid==0">
    <div class="item item-form">
      <div class="iconBox">
        <span class="icon iconfont icon-QQ"></span>
      </div>
      <input type="text" ref="qq" placeholder="请输入您的QQ信息"/>
    </div>
    <div class="item item-form">
      <div class="iconBox">
        <span class="layui-icon layui-icon-email"></span>
      </div>
      <input type="text" ref="email" placeholder="请输入您的电子邮箱"/>
    </div>
</template>
<div class="mainBtns">
<van-button type="info" v-if="payType=='user'" @click="pay">提交订单</van-button>
<van-button type="info" v-else @click="pay">确认付款</van-button>
</div>
</template>