<?php namespace Vip\Src;

use Dever;

# 未登录
class Api extends Base
{
    # 检测是否支付成功
    public function checkOrder()
    {
    	$buy_id = Dever::input('buy_id');
        $order_id = Dever::input('order_id');

    	$state = $this->check();
    	if ($state == 1) {
    		$url = $this->url('success', array('buy_id' => $buy_id, 'order_id' => $order_id), 'vip');
            Dever::location($url);
    	} else {
    		$url = $this->url('pay', array('buy_id' => $buy_id, 'order_id' => $order_id, 'open' => 2), 'vip');
        	Dever::location($url);
    	}
    }

    public function check()
    {
        $buy_id = Dever::input('buy_id');
        $order_id = Dever::input('order_id');

        if ($this->source_type) {
        	return 2;
        }
        if ($order_id) {
            $info = Dever::db('vip/order')->one($order_id);
            if ($info) {
                if ($info['status'] == 2) {
                    # 已支付
                    return 1;
                }
            }
        }
        # 未支付
        return 2;
    }
}