|
|
@@ -1,6 +1,5 @@
|
|
|
|
|
|
local DB = require("common.DB")
|
|
|
-local Json = require("common.Json")
|
|
|
local CommonDB = require("common.CommonDB")
|
|
|
local CdkFixExcel = require("excel.cdkFix")
|
|
|
local LuaMongo = _G.lua_mongo
|
|
|
@@ -27,23 +26,20 @@ local function checkCDKParam(finishTime,cdkID)
|
|
|
if now > finishTime then
|
|
|
return
|
|
|
end
|
|
|
- if not CdkFixExcel[cdkID] then
|
|
|
- return
|
|
|
- end
|
|
|
return true
|
|
|
end
|
|
|
|
|
|
local function genCDKBatch(cnt,useCnt,cdkID)
|
|
|
local bat = assert(CommonDB.getCDKBatch(),"assert : cdk batch not found")
|
|
|
local db = {
|
|
|
- batch = bat,
|
|
|
+ batch = bat + 1,
|
|
|
cnt = cnt,
|
|
|
useCnt = useCnt,
|
|
|
info = cdkID,
|
|
|
useCDKList = {},
|
|
|
}
|
|
|
LuaMongo.insert(DB.db_cdk, db)
|
|
|
- CommonDB.setCDKBatch(bat + 1) -- 将下一次cdkBatch保存
|
|
|
+ CommonDB.setCDKBatch(bat + 1) -- 将最新的cdkBatch保存
|
|
|
return bat
|
|
|
end
|
|
|
|
|
|
@@ -65,8 +61,8 @@ local function genCDKCode(batch,index)
|
|
|
end
|
|
|
|
|
|
local function deCDKCode(cdk)
|
|
|
- local num = (CodeMap[cdk[3] ] - 1) * 100 + (CodeMap[cdk[4] ] - 1) * 10 + (CodeMap[cdk[5] ] - 1)
|
|
|
- local batch = (CodeMap[cdk[7] ] - 1) * 100 + (CodeMap[cdk[8] ] - 1) * 10 + (CodeMap[cdk[9] ] - 1)
|
|
|
+ local num = (CodeMap[string.sub(cdk,3,3) ] - 1) * 100 + (CodeMap[string.sub(cdk,4,4)] - 1) * 10 + (CodeMap[string.sub(cdk,5,5) ] - 1)
|
|
|
+ local batch = (CodeMap[string.sub(cdk,6,6) ] - 1) * 100 + (CodeMap[string.sub(cdk,7,7) ] - 1) * 10 + (CodeMap[string.sub(cdk,8,8) ] - 1)
|
|
|
return num,batch
|
|
|
end
|
|
|
|
|
|
@@ -81,25 +77,46 @@ function genCDK(cnt,useCnt,cdkId)
|
|
|
useCnt = useCnt or 1
|
|
|
cnt = cnt < 1000 and cnt or 999
|
|
|
local bat = genCDKBatch(cnt,useCnt,cdkId)
|
|
|
+ local fileName = "cdk"..bat
|
|
|
+ local f,err = io.open(fileName,"w")
|
|
|
+ if not f then
|
|
|
+ print("open file failed ",err)
|
|
|
+ return
|
|
|
+ end
|
|
|
local idx = 0
|
|
|
+ local data = "cdk : \n"
|
|
|
while true do
|
|
|
if idx > cnt then
|
|
|
break
|
|
|
end
|
|
|
local cdk = genCDKCode(bat,idx)
|
|
|
+ data = data .. cdk .. "\n"
|
|
|
idx = idx + 1
|
|
|
end
|
|
|
+ f:write(data)
|
|
|
end
|
|
|
|
|
|
-- 使用cdk
|
|
|
-function use(cdk)
|
|
|
+function useCDK(cdk)
|
|
|
|
|
|
end
|
|
|
|
|
|
-function test()
|
|
|
- local cdk = genCDKCode(55,125)
|
|
|
- print("cdk is ",cdk)
|
|
|
- local idx,bat = deCDKCode(cdk)
|
|
|
- print("batch is ",bat)
|
|
|
- print("index is ",idx)
|
|
|
+-- 检查CDK
|
|
|
+function checkCDK(cdk)
|
|
|
+ local num,batch = deCDKCode(cdk)
|
|
|
+ local curBatch = assert(CommonDB.getCDKBatch(),"assert : cdk batch not found")
|
|
|
+ if curBatch < batch then
|
|
|
+ return "batch error"
|
|
|
+ end
|
|
|
+ QueryCDK = { batch = { ["$eq"] = batch} }
|
|
|
+ LuaMongo.find(DB.db_cdk,QueryCDK)
|
|
|
+ local cdkBatchData = {}
|
|
|
+ LuaMongo.next(cdkBatchData)
|
|
|
+ if cdkBatchData.cnt < num then
|
|
|
+ return "invalid cdk"
|
|
|
+ end
|
|
|
+ if cdkBatchData.useCDKList[num] then
|
|
|
+ return "cdk used"
|
|
|
+ end
|
|
|
+ return nil, cdkBatchData
|
|
|
end
|