<?php
namespace app\pay\controller;

class Query extends \think\Controller
{
	public function index()
	{
	    if(isset($_GET['account']) && isset($_GET['serverid']) && isset($_GET['guid']) && isset($_GET['productId'])){
	        $account = $_GET['account'];
	        $serverid = $_GET['serverid'];
	        $guid = $_GET['guid'];
	        $productId = $_GET['productId'];
	        
	        $data = \think\Db::name("payconfig")->field(true)->where("id", $productId)->find();
			if ($data) {
			    if ($data["limitType"] == 0) {  // 不限购
			        return json(["ret" => 0, "msg" => "!"]);
			    }
			    
			    if ($data["limitType"] == 1) {  // 每日限购
			        $count = \think\Db::name("gamebuy_log")->where(["account" => $account, "server" => $serverid, "guid" => $guid, "productId" => $productId, "status" => 1])->whereTime("time", "today")->count();
			        if($count >= $data["limitNumber"]){
			            return json(["ret" => -1, "msg" => "超过当日购买限制"]);
			        }
			        return json(["ret" => 0, "msg" => "!"]);
			    }
			    
			    if ($data["limitType"] == 2) {  // 永久限购
			        $count = \think\Db::name("gamebuy_log")->where(["account" => $account, "server" => $serverid, "guid" => $guid, "productId" => $productId, "status" => 1])->count();
			        if($count >= $data["limitNumber"]){
			            return json(["ret" => -1, "msg" => "超过永久购买限制"]);
			        }
			        return json(["ret" => 0, "msg" => "!"]);
			    }
			} else {
				return json(["ret" => -1, "msg" => "购买物品不存在"]);
			}
	    }else{
	        return json(["ret" => -1, "msg" => "非法访问"]);
	    }
	}
}