--[[ Descripttion:支付 version: Author: Neo,Huang Date: 2022-03-14 20:21:10 LastEditors: Neo,Huang LastEditTime: 2022-03-14 20:21:10 --]] local timeUtil = require("utils.timeUtil") local shopAdapt = require("adapt.shopAdapt") local moduleData = require("data.module") local MODULE_NAME = "pay" local root = {} -- 支付金额:分 -- 新增支付 function root:user_add_pay(uid, gid, pennys) log.info("user_add_pay uid[%s] gid[%s] pennys[%s]", tostring(uid), tostring(gid), tostring(pennys)) if uid == nil or gid == nil then return end -- 总金额 pennys = pennys or shopAdapt:goods_get_rmb(gid) local totalAmount = moduleData:hget_int(uid, MODULE_NAME, "totalAmount") totalAmount = totalAmount + pennys moduleData:hset(uid, MODULE_NAME, "totalAmount", totalAmount) -- 购买商品列表 local currTime = timeUtil.now(uid) local goodsList = moduleData:hget_json(uid, MODULE_NAME, "goodsList") table.insert(goodsList, {gid = gid, amount = pennys, time = currTime}) moduleData:hset(uid, MODULE_NAME, "goodsList", goodsList) -- 当天信息 local dayInfo = self:get_day_info(uid) dayInfo.lastPayTime = currTime if dayInfo.goodsList == nil then dayInfo.goodsList = {} end table.insert(dayInfo.goodsList, {gid = gid, amount = pennys, time = currTime}) moduleData:hset(uid, MODULE_NAME, "dayInfo", dayInfo) return true end -- 累计支付金额 function root:user_get_total_pay_count(uid) if uid == nil then return end return moduleData:hget_int(uid, MODULE_NAME, "totalAmount") end -- 是否首次付费 function root:is_first_pay(uid) local goodsList = moduleData:hget_json(uid, MODULE_NAME, "goodsList") return is_empty(goodsList) end -- 是否商品首次付费 function root:is_goods_first_pay(uid, gid) local goodsList = moduleData:hget_json(uid, MODULE_NAME, "goodsList") for _, v in ipairs(goodsList) do if v.gid == gid then return false end end return true end -- 商品购买次数 function root:get_goods_pay_times(uid, gid) local times = 0 local goodsList = moduleData:hget_json(uid, MODULE_NAME, "goodsList") for _, v in ipairs(goodsList) do if v.gid == gid then times = times + 1 end end return times end ---------------------------------------- -- 当天 ---------------------------------------- -- 获取信息 function root:get_day_info(uid) local currTime = timeUtil.now(uid) local dayInfo = moduleData:hget_json(uid, MODULE_NAME, "dayInfo") if dayInfo.lastPayTime and not timeUtil.is_same_day(dayInfo.lastPayTime, currTime) then dayInfo = {} end return dayInfo end -- 支付金额 function root:get_day_total_amount(uid) local dayInfo = self:get_day_info(uid) local amount = 0 if not is_empty(dayInfo.goodsList) then for _, v in ipairs(dayInfo.goodsList) do amount = amount + v.amount end end return amount end ---------------------------------------- -- 商品定制 ---------------------------------------- -- 定制商品物品 function root:update_goods_pre_custom_items(uid, gid, items) if uid == nil or gid == nil or is_empty(items) then return false end local goodsPreCustomItems = moduleData:hget_json(uid, MODULE_NAME, "goodsPreCustomItems") local isMatch = false for k, v in ipairs(goodsPreCustomItems) do if v.gid == gid then isMatch = true v.items = items break end end if not isMatch then table.insert(goodsPreCustomItems, {gid = gid, items = items}) end moduleData:hset(uid, MODULE_NAME, "goodsPreCustomItems", goodsPreCustomItems) return true end -- 打包 - 商品定制信息 function root:pack_goods_pre_custom_info_list(uid) if uid == nil then return end local goodsPreCustomItems = moduleData:hget_json(uid, MODULE_NAME, "goodsPreCustomItems") if not is_empty(goodsPreCustomItems) then return goodsPreCustomItems end end -- 获取商品定制物品 function root:get_goods_pre_custom_items(uid, gid) if uid == nil or gid == nil then return end local goodsPreCustomItems = moduleData:hget_json(uid, MODULE_NAME, "goodsPreCustomItems") for k, v in ipairs(goodsPreCustomItems) do if v.gid == gid then return v.items end end end -- 删除商品定制物品 function root:del_goods_pre_custom_items(uid, gid) if uid == nil or gid == nil then return false end local goodsPreCustomItems = moduleData:hget_json(uid, MODULE_NAME, "goodsPreCustomItems") for k, v in ipairs(goodsPreCustomItems) do if v.gid == gid then table.remove(goodsPreCustomItems, k) moduleData:hset(uid, MODULE_NAME, "goodsPreCustomItems", goodsPreCustomItems) return true end end return false end -- 支付 - 更新商品定制物品 function root:update_goods_pay_custom_items(uid, gid, items) if uid == nil or gid == nil then return false end local goodsPayCustomItems = moduleData:hget_json(uid, MODULE_NAME, "goodsPayCustomItems") local isMatch = false for k, v in ipairs(goodsPayCustomItems) do if v.gid == gid then isMatch = true if is_empty(items) then table.remove(goodsPayCustomItems, k) else v.items = items end break end end if not isMatch then table.insert(goodsPayCustomItems, {gid = gid, items = items}) end moduleData:hset(uid, MODULE_NAME, "goodsPayCustomItems", goodsPayCustomItems) return true end -- 打包 - 商品定制信息 function root:pack_goods_pay_custom_info_list(uid) if uid == nil then return end local goodsPayCustomItems = moduleData:hget_json(uid, MODULE_NAME, "goodsPayCustomItems") if not is_empty(goodsPayCustomItems) then return goodsPayCustomItems end end return root