-------------------------------------------------
-- 充值
-------------------------------------------------

local BuyExcel = require("excel.buy")
local Msg = require("core.Msg")
local ObjHuman = require("core.ObjHuman")
local BuyLogic = require("topup.BuyLogic")
local SceneHandler = require("scene.Handler")
local YunYingLogic = require("yunying.YunYingLogic")
local LeichongHaoli = require("present.LeichongHaoli")
local LeijiChongzhi = require("present.LeijiChongzhi")
local DailyLeichong = require("present.DailyLeichong")
local LoginSignLogic = require("loginSign.LoginSignLogic")
local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
local RoleSystemDefine = require("roleSystem.RoleSystemDefine")

-- 专属客服充值额度
EXCLUSIVE_SERVER_9937 = 1000

TOPUP_LIBAO_ID1 = 1   --盲盒礼包
TOPUP_LIBAO_ID2 = 2   --铂金周卡
TOPUP_LIBAO_ID3 = 3   --365王卡

--封装直购基本信息
local function wrapTopupItem(net, config, human)
	net.id = config.id	
	BuyLogic.fontBuyItem(human, net.buyItem, config.buyID)
end

-- 充值列表
function query(human)
	if SceneHandler.canCharge(human) ~= true then
		return
	end
	local msgRet = Msg.gc.GC_TOPUP_QUERY
	msgRet.list[0] = #BuyExcel.topup
	for i, config in ipairs(BuyExcel.topup) do
		local net = msgRet.list[i]
		wrapTopupItem(net, config, human)
	end
	Msg.send(msgRet,human.fd)
end

-- 直购回调
function clacTopupAcount(human, price, buyID)
    if price < 0 then return end

    ObjHuman.updateDaily(human)

	human.db.topupAcountDaily = (human.db.topupAcountDaily or 0) + price
	human.db.topupAccountMonth = (human.db.topupAccountMonth or 0) + price
    human.db.topupAcount = (human.db.topupAcount or 0) + price

    checkKf(human)

	YunYingLogic.onCharge(human, price, buyID)
	DailyLeichong.charge(human, price)
	LeichongHaoli.onAddMoney(human, price)
	LeijiChongzhi.onAddMoney(human, price)
	LoginSignLogic.chargeAfter(human)
end

function checkKf(human)
	-- 激活专属客服
    if human.db.topupAcount ~= nil and human.db.topupAcount >= EXCLUSIVE_SERVER_9937 then
        Msg.send(Msg.gc.GC_EXCLUSIVE_SERVER,human.fd)
    end
end