<?php

namespace app\common;

use extend\alipay\Alipay as AlipaySdk;
use app\ros\model\Order as OrderModel;


class Alipay {

     /**
     * @description: 获取支付宝是否支付成功
     * @param {*}
     * @return {*}
     */    
    public function alipayVerify() {

        $ali = new AlipaySdk();

        $flag = $ali->payVerify($_POST);
        
        if($flag){
            
            $status = $_POST['trade_status'];

            $flag = false;

            if ($status == 'TRADE_SUCCESS' && $_POST['auth_app_id'] == '2021002102631089' && $_POST['seller_id'] = '2088431603383955') {
                $flag = true;
            } 

            if ($flag) {

                $order_model = new OrderModel();
                $order_no=$_POST['out_trade_no'];
                $alipay_no = $_POST['trade_no'];

                

                //获取充值信息
                $order_info = $order_model->getOne(['order_no'=>$order_no]);

                if (!empty($order_info['ali_wx_no'])) {
                    die;
                }

                $update_data = [];
            
                //更新充值订单
                $update_data['ali_wx_no'] = $alipay_no;
                $update_data['status'] = 1;
                $order_model->updateOne(['order_no'=>$order_no],$update_data);
            }
        } 
        
        echo 'success';
    }
}