<?php
namespace app\common\game;
use \think\Db;
use \think\Cookie;
use \think\Session;
use \think\Cache;
use think\Controller;
//YY陪玩支付函数
class Yy_pei 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 = 'Paygate';
        }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/yypei/pay",http_build_query($post),''));

        if($pay_data->result == 1){
           $url = json_decode($pay_data->jsonMsg);
           $order_id = $url->orderId;//订单号
          
           if($order_id==''){
               $order_id = '';
               $wx_url = '';
               $message = 'YY陪玩渠道错误：'.$url->result;
               $order_mb = ''; 
           }else{
               $message = 'ok';//订单号;
           }
          
        }else{
           $order_id = '';
           $wx_url = '';
           $message = 'YY陪玩渠道错误：'.$pay_data->result;
           $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->payUrl;
                 $order_mb='h5';   
              }else{
                 $wx_url=$url->payUrl;
                 $order_mb='weixin_h5';    
              }
              
            }else{
             
              if($ck['yy_ms'] == '0'){
                
                 $wx_url= str_replace("https://payplf-gate.yy.com/qrcode/select.do","https://payplf-gate.yy.com/qrcode/zfb/wap.do",$url->payUrl);
                 
                 $order_mb='alipay_h5'; 
              }else{
                 $wx_url=urlencode($url->payUrl);
                 $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/yypei/order',http_build_query($post),'')); 
        
        $status = json_decode($query->jsonMsg);
       
        if($status->status =='1'){
            
          $syorder = $order;  
          return $syorder;
          
        }
       
    }
    
}