<?php
namespace app\common\game;
use \think\Db;
use \think\Cookie;
use \think\Session;
use \think\Cache;
use think\Controller;
//YY陪玩支付函数
class Yy_pei_jb extends Controller {
    
     //YY陪玩支付发起
    static function pay($ck,$money,$land_id){
        
        $is_weixin = is_weixin();
        $uid = getSubstr($ck['yy_ck'], 'yyuid=', ';');
        
        if($ck['yy_type'] == '1'){
           $payChannel = 'alipay';
        }else{
           $payChannel = 'weixin';
        }
        
        $post = array('cook' => base64_encode($ck['yy_ck']), 'payChannel' => $payChannel, 'uid' => $uid, 'money' => $money);
        
        $pay_data = json_decode(curl("http://api.fssy.cc/pay/yypeijb/pay_alipay_h5",http_build_query($post),''));

        if($pay_data->status == 0 && $pay_data->msg == '处理成功！'){
           $url = $pay_data->data;
           
           $order_id = $url->orderId;//订单号
         
           if($order_id==''){
               $order_id = '';
               $wx_url = '';
               $message = 'YY陪玩金贝渠道错误：'.$pay_data->msg;
               $order_mb = ''; 
           }else{
               $message = 'ok';//订单号;
           }
          
        }else{
           $order_id = '';
           $wx_url = '';
           if($pay_data->msg!=''){
               $msg = $pay_data->msg;
           }else{
               $pay_data->message;
           }
           $message = 'YY陪玩金贝渠道错误：'.$msg;
           $order_mb = '';
           //api_log($message,'https://www.yy.com/show/qr/qrRecharge.action',$land_id,'YY',$money);  
        }
      
        
   
       if($message=='ok'){
          //if($is_weixin==1){
        
                
                //if($ck['yy_type'] == '0'){
                   //$wx_url=$url->payUrl;
                   //$order_mb='h5';   
               // }else{
                   //$wx_url=urlencode($url->payUrl);
                   //$order_mb='alipay_ewm'; 
               // }
                
         // }else{
              
                
                //if($ck['yy_type'] == '0'){
                 // $wx_url=$url->payUrl;
                 // $order_mb='weixin_h5';  
                //}else{
                  //$wx_url=urlencode($url->payUrl);
                  //$order_mb='alipay_ewm'; 
               // }
              
          //}
          
          if($ck['yy_type'] == '0'){
              
              if($ck['yy_ms'] == '0'){
                 $wx_url=$url->url;
                 $order_mb='h5';   
              }else{
                 $wx_url=$url->url;
                 $order_mb='weixin_h5';    
              }
              
            }else{
             
              if($ck['yy_ms'] == '0'){
                
                 $wx_url= $url->url;
                 
                 $order_mb='alipay_h5'; 
              }else{
                 $wx_url=urlencode($url->url);
                 $order_mb='alipay_ewm';   
              }
              
            }
        }  
    
        $order['order_id']=$order_id;
		$order['order_url']=$wx_url;
		$order['order_message']=$message;
		$order['alipay_url']='';
		$order['order_mb']=$order_mb;
		$order['hy_sign']='';
		$order['hy_time']='';
		return $order;
        
    
        
    }
    
    static function status($ck,$order,$money){
      
        $uid = getSubstr($ck['yy_ck'], 'yyuid=', ';');
        
        $post = array('cook' => base64_encode($ck['yy_ck']),'uid' => $uid,'order' => $order);
        
        $query = json_decode(curl('http://api.fssy.cc/pay/yypeijb/order',http_build_query($post),'')); 
        
        $status = $query->data;
       
        if($status->order_status =='C'){
            
          $syorder = $order;  
          return $syorder;
          
        }
       
    }
    
}