Commit 2dbe4fb9ebe21ce4526d3d47eff0696051923f7f

Authored by chenyueqi
1 parent 3dbe0d5d

充值礼包自选部分逻辑

src/actions/StoreAction.lua
@@ -7,12 +7,13 @@ function _M.rechargeRpc(agent , data) @@ -7,12 +7,13 @@ function _M.rechargeRpc(agent , data)
7 local role = agent.role 7 local role = agent.role
8 local msg = MsgPack.unpack(data) 8 local msg = MsgPack.unpack(data)
9 local id = msg.id 9 local id = msg.id
  10 + local choose = msg.choose or ""
10 local dataSet = csvdb["shop_rechargeCsv"][id] 11 local dataSet = csvdb["shop_rechargeCsv"][id]
11 if not dataSet then return end 12 if not dataSet then return end
12 local roleId = role:getProperty("id") 13 local roleId = role:getProperty("id")
13 14
14 --创建订单号 15 --创建订单号
15 - local partnerOrderId = role:getPurchaseOrder(id) 16 + local partnerOrderId = role:getPurchaseOrder(id,nil,choose)
16 if partnerOrderId == "" then 17 if partnerOrderId == "" then
17 return 1 18 return 1
18 end 19 end
@@ -58,13 +59,14 @@ function _M.googleRechargeRpc(agent, data) @@ -58,13 +59,14 @@ function _M.googleRechargeRpc(agent, data)
58 local role = agent.role 59 local role = agent.role
59 local msg = MsgPack.unpack(data) 60 local msg = MsgPack.unpack(data)
60 local id = msg.id 61 local id = msg.id
  62 + local choose = msg.choose or ""
61 local dataSet = csvdb["shop_rechargeCsv"][id] 63 local dataSet = csvdb["shop_rechargeCsv"][id]
62 if not dataSet then return end 64 if not dataSet then return end
63 local roleId = role:getProperty("id") 65 local roleId = role:getProperty("id")
64 66
65 role.ignoreHeartbeat = true 67 role.ignoreHeartbeat = true
66 --创建订单号 68 --创建订单号
67 - local partnerOrderId = role:getPurchaseOrder(id) 69 + local partnerOrderId = role:getPurchaseOrder(id,nil,choose)
68 -- 签名 70 -- 签名
69 local secret_key = "b7657fa7ccd44c16a35e3f454ac7a075" 71 local secret_key = "b7657fa7ccd44c16a35e3f454ac7a075"
70 local need = { 72 local need = {
@@ -85,13 +87,14 @@ function _M.myCardRechargeRpc(agent, data) @@ -85,13 +87,14 @@ function _M.myCardRechargeRpc(agent, data)
85 local role = agent.role 87 local role = agent.role
86 local msg = MsgPack.unpack(data) 88 local msg = MsgPack.unpack(data)
87 local id = msg.id 89 local id = msg.id
  90 + local choose = msg.choose or ""
88 local dataSet = csvdb["shop_rechargeCsv"][id] 91 local dataSet = csvdb["shop_rechargeCsv"][id]
89 if not dataSet then return end 92 if not dataSet then return end
90 local roleId = role:getProperty("id") 93 local roleId = role:getProperty("id")
91 94
92 role.ignoreHeartbeat = true 95 role.ignoreHeartbeat = true
93 --创建订单号 96 --创建订单号
94 - local partnerOrderId = role:getPurchaseOrder(id) 97 + local partnerOrderId = role:getPurchaseOrder(id,nil,choose)
95 -- 签名 98 -- 签名
96 local secret_key = "48759e07540f46d9af17ec82669b4272" 99 local secret_key = "48759e07540f46d9af17ec82669b4272"
97 local need = { 100 local need = {
@@ -111,13 +114,14 @@ function _M.iosRechargeRpc(agent, data) @@ -111,13 +114,14 @@ function _M.iosRechargeRpc(agent, data)
111 local role = agent.role 114 local role = agent.role
112 local msg = MsgPack.unpack(data) 115 local msg = MsgPack.unpack(data)
113 local id = msg.id 116 local id = msg.id
  117 + local choose = msg.choose or ""
114 local dataSet = csvdb["shop_rechargeCsv"][id] 118 local dataSet = csvdb["shop_rechargeCsv"][id]
115 if not dataSet then return end 119 if not dataSet then return end
116 local roleId = role:getProperty("id") 120 local roleId = role:getProperty("id")
117 121
118 role.ignoreHeartbeat = true 122 role.ignoreHeartbeat = true
119 --创建订单号 123 --创建订单号
120 - local partnerOrderId = role:getPurchaseOrder(id) 124 + local partnerOrderId = role:getPurchaseOrder(id,nil,choose)
121 -- 签名 125 -- 签名
122 local secret_key = "9647d2efe1074c73b9ac19af4337a70e" 126 local secret_key = "9647d2efe1074c73b9ac19af4337a70e"
123 local need = { 127 local need = {
src/models/Order.lua
@@ -12,6 +12,7 @@ Order.schema = { @@ -12,6 +12,7 @@ Order.schema = {
12 createTime = {"number", skynet.timex()}, -- 订单创建时间 12 createTime = {"number", skynet.timex()}, -- 订单创建时间
13 finishTime = {"number", 0}, -- 服务端验证完成时间 13 finishTime = {"number", 0}, -- 服务端验证完成时间
14 status = {"string", "create"}, 14 status = {"string", "create"},
  15 + choose = {"string", ""}, -- 自选奖励
15 } 16 }
16 17
17 Order.fields = { 18 Order.fields = {
@@ -21,6 +22,7 @@ Order.fields = { @@ -21,6 +22,7 @@ Order.fields = {
21 createTime = true, 22 createTime = true,
22 finishTime = true, 23 finishTime = true,
23 status = true, 24 status = true,
  25 + choose = true,
24 } 26 }
25 27
26 return Order 28 return Order
27 \ No newline at end of file 29 \ No newline at end of file
src/models/RolePlugin.lua
@@ -2013,7 +2013,7 @@ function RolePlugin.bind(Role) @@ -2013,7 +2013,7 @@ function RolePlugin.bind(Role)
2013 return "error money" 2013 return "error money"
2014 end 2014 end
2015 -- 发现需要的id 2015 -- 发现需要的id
2016 - local partnerOrderId = self:getPurchaseOrder(k, params.transactionId) 2016 + local partnerOrderId = self:getPurchaseOrder(k, params.transactionId, params.choose)
2017 if partnerOrderId == "" then 2017 if partnerOrderId == "" then
2018 return "no product" 2018 return "no product"
2019 end 2019 end
@@ -2023,7 +2023,7 @@ function RolePlugin.bind(Role) @@ -2023,7 +2023,7 @@ function RolePlugin.bind(Role)
2023 end 2023 end
2024 2024
2025 -- 获取充值订单号 2025 -- 获取充值订单号
2026 - function Role:getPurchaseOrder(rechargeId, transactionId) 2026 + function Role:getPurchaseOrder(rechargeId, transactionId, choose)
2027 local roleId = self:getProperty("id") 2027 local roleId = self:getProperty("id")
2028 local rechargeData = csvdb["shop_rechargeCsv"][rechargeId] 2028 local rechargeData = csvdb["shop_rechargeCsv"][rechargeId]
2029 if not rechargeData then 2029 if not rechargeData then
@@ -2035,6 +2035,25 @@ function RolePlugin.bind(Role) @@ -2035,6 +2035,25 @@ function RolePlugin.bind(Role)
2035 if limit ~= 0 and limit <= (rechargeRecord[rechargeId] or 0) then 2035 if limit ~= 0 and limit <= (rechargeRecord[rechargeId] or 0) then
2036 return "" 2036 return ""
2037 end 2037 end
  2038 +
  2039 + -- 检查礼包自选奖励合法
  2040 + if choose and choose ~= "" then
  2041 + if rechargeData.itemgift == "" then return "" end
  2042 + local slot = rechargeData.itemdirect or 0
  2043 + local set = choose:toTableArray(true)
  2044 + if slot ~= #set then return "" end
  2045 + local pass = {}
  2046 + local groups = rechargeData.itemdirect:toTableArray(true)
  2047 + for _, item in ipairs(set) do
  2048 + for _, group in ipairs(groups) do
  2049 + if group[2] == item[1] and group[3] == item[2] then
  2050 + pass[group[1]] = 1
  2051 + break
  2052 + end
  2053 + end
  2054 + end
  2055 + if #pass ~= slot then return "" end
  2056 + end
2038 2057
2039 --判断是否是活动商品 2058 --判断是否是活动商品
2040 if rechargeData.activity_id ~= 0 then 2059 if rechargeData.activity_id ~= 0 then
@@ -2061,6 +2080,7 @@ function RolePlugin.bind(Role) @@ -2061,6 +2080,7 @@ function RolePlugin.bind(Role)
2061 rechargeId = rechargeId, 2080 rechargeId = rechargeId,
2062 createTime = skynet.timex(), 2081 createTime = skynet.timex(),
2063 transactionId = transactionId, 2082 transactionId = transactionId,
  2083 + choose = choose or "",
2064 }) 2084 })
2065 order:create() 2085 order:create()
2066 -- 正在进行中的订单 缓存 2086 -- 正在进行中的订单 缓存
@@ -2128,7 +2148,7 @@ function RolePlugin.bind(Role) @@ -2128,7 +2148,7 @@ function RolePlugin.bind(Role)
2128 }) 2148 })
2129 end 2149 end
2130 2150
2131 - return true, rechargeId 2151 + return true, rechargeId, orderObject:getProperty("choose")
2132 end 2152 end
2133 2153
2134 -- 充值 -- 2154 -- 充值 --
@@ -2146,7 +2166,7 @@ function RolePlugin.bind(Role) @@ -2146,7 +2166,7 @@ function RolePlugin.bind(Role)
2146 local roleId = self:getProperty("id") 2166 local roleId = self:getProperty("id")
2147 local partnerOrderStr = params.order 2167 local partnerOrderStr = params.order
2148 2168
2149 - local status, back = self:updatePurchaseOrder(partnerOrderStr, params.transactionId, "finsh") 2169 + local status, back, choose = self:updatePurchaseOrder(partnerOrderStr, params.transactionId, "finsh")
2150 if not status then 2170 if not status then
2151 if back == "finsh" then 2171 if back == "finsh" then
2152 -- 订单已经处理 2172 -- 订单已经处理
@@ -2168,6 +2188,7 @@ function RolePlugin.bind(Role) @@ -2168,6 +2188,7 @@ function RolePlugin.bind(Role)
2168 transactionId = params.transactionId, 2188 transactionId = params.transactionId,
2169 pay_time = params.pay_time, 2189 pay_time = params.pay_time,
2170 order = partnerOrderStr, 2190 order = partnerOrderStr,
  2191 + choose = choose,
2171 }) 2192 })
2172 2193
2173 if not status then 2194 if not status then
@@ -2215,6 +2236,17 @@ function RolePlugin.bind(Role) @@ -2215,6 +2236,17 @@ function RolePlugin.bind(Role)
2215 return 3 2236 return 3
2216 end 2237 end
2217 2238
  2239 + -- 自选奖励部分
  2240 + if params.choose and params.choose ~= "" then
  2241 + local tReward, tChange = self:award(params.choose, {log = {desc = "recharge", int1 = id}})
  2242 + for itemId, value in pairs(tReward) do
  2243 + reward[itemId] = (reward[itemId] or 0) + value
  2244 + end
  2245 + for itemId, value in pairs(tChange) do
  2246 + reward[itemId] = (reward[itemId] or 0) + value
  2247 + end
  2248 + end
  2249 +
2218 if diamondCount > 0 then 2250 if diamondCount > 0 then
2219 reward[ItemId.Diamond] = (reward[ItemId.Diamond] or 0) + diamondCount 2251 reward[ItemId.Diamond] = (reward[ItemId.Diamond] or 0) + diamondCount
2220 end 2252 end