shop.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. package model
  2. import (
  3. "errors"
  4. "leafstalk/otherutils/deepcopy"
  5. "strconv"
  6. "xorm.io/xorm"
  7. )
  8. type StoreDailyDetail struct {
  9. RefreshTs int64 `json:"refreshTs"` // 上次自动刷新时间
  10. RefreshFreeNum int64 `json:"refreshFreeNum"` // 免费刷新次数
  11. RefreshGoldNum int64 `json:"refreshGoldNum"` // 金币刷新次数
  12. RefreshAdNum int64 `json:"refreshAdNum"` // 广告刷新次数
  13. AdGoodsByNum map[int64]int64 `json:"adGoodsByNum"` // 广告位商品购买次数
  14. Goods map[int64]*DailyGood `json:"goods"` // 商品列表 {槽位id:{}}
  15. }
  16. type DailyGood struct {
  17. AdId int64 `json:"adId"` // 广告点id。为0表示不是广告点需要用DailyGoodsId
  18. DailyGoodsId int64 `json:"dailyGoodsId"` // 商品id。与AdId不能同时存在
  19. BuyNum int64 `json:"buyNum"` // 购买次数
  20. }
  21. type StoreGeneralDetail struct {
  22. RefreshTs int64 `json:"refreshTs"` // 上次自动刷新时间
  23. BuyGoods map[int64]int64 `json:"goods"` // 购买过的商品列表 {商品id:购买次数}
  24. }
  25. type PlayerStore struct {
  26. Id int64
  27. PlayerId int64 `xorm:"BIGINT 'playerid'"`
  28. StoreDiscount *StoreGeneralDetail `xorm:"TEXT json 'storeDiscount'"` // 特惠商店商品购买信息 {礼包id:购买次数}
  29. StoreDaily *StoreDailyDetail `xorm:"TEXT json 'storeDaily'"` // 每日商店信息 {槽位id}
  30. StoreGold *StoreGeneralDetail `xorm:"TEXT json 'storeGold'"`
  31. StoreDiamond *StoreGeneralDetail `xorm:"TEXT json 'storeDiamond'"`
  32. StoreExchange *StoreGeneralDetail `xorm:"TEXT json 'storeExchange'"`
  33. PlayerLevel int64 `xorm:"BIGINT 'level'"`
  34. }
  35. func (m PlayerStore) TableName() string {
  36. return "player_store"
  37. }
  38. // 需要保存的数据需确保在这里能复制到new1 中
  39. //
  40. // func (m *PlayerStore) DeepCopy() interface{} {
  41. // new1 := new(PlayerStore)
  42. // *new1 = *m
  43. //
  44. // return new1
  45. // }
  46. func (m *PlayerStore) QueryExist(eng *xorm.Engine) (bool, error) {
  47. player := new(PlayerStore)
  48. player.PlayerId = m.PlayerId
  49. return eng.Exist(player)
  50. }
  51. func (m *PlayerStore) UpdateDB(eng *xorm.Engine) (int64, error) {
  52. return eng.Where("playerid=?", m.PlayerId).AllCols().Update(m)
  53. }
  54. func (m *PlayerStore) GetUniqueKey() string {
  55. return strconv.FormatInt(m.PlayerId, 10)
  56. }
  57. func CopyPlayerStore(old *PlayerStore) *PlayerStore {
  58. nu := deepcopy.MustCopy(old).(*PlayerStore)
  59. return nu
  60. }
  61. const (
  62. PayTypeMoney = 1 //现金支付
  63. PayTypeAd = 2 //广告获得
  64. PayTypeItem = 3 //道具兑换
  65. PayTypeFree = 4 //免费
  66. )
  67. // 玩家商城购买记录
  68. //type PlayerShop struct {
  69. // Id int64
  70. // PlayerId int64 `xorm:"BIGINT 'playerid'"`
  71. // Levels map[int64]struct{} `xorm:"VARCHAR(1000) 'levels'"`
  72. //}
  73. // 购买信息
  74. //type WxPayPlayer struct {
  75. // Id int64
  76. // PlayerID int64 `xorm:"BIGINT 'playerid'"`
  77. // Buys map[int64]*PeriodBuys `xorm:"BIGINT 'buys'"`
  78. // Refreshs map[int64]*RefreshGoods `xorm:"varchar(255) json 'refresh'"`
  79. //
  80. // // LevelGoods map[int64]struct{} `xorm:"TEXT 'lvGoods'"`
  81. // // DailyGoods *RefreshBuys `xorm:"TEXT json'dailys'"`
  82. // // CoinGoods *PeriodBuys `xorm:"TEXT json 'coins'"`
  83. // // DiamondGoods map[int64]int `xorm:"TEXT json 'diamonds'"`
  84. //
  85. // // BuyStatis map[int64]uint `xorm:"TEXT 'buyStatis'"`
  86. // // NewerBox map[int64]int `xorm:"TEXT json 'orderBox'"`
  87. // // VipGoods []*LastBuyItem `xorm:"TEXT 'vipGoods'"`
  88. // // DailyDiscount *TickBuys `xorm:"TEXT json 'dailyDiscount'"`
  89. // // RoleGift *RoleGiftBuys `xorm:"TEXT json 'roleGift'"`
  90. // // Invite *InviteGift `xorm:"TEXT json 'invite'"`
  91. // // AccPay *AccPayGift `xorm:"TEXT json 'accPay'"`
  92. // // Balance int `xorm:"int 'balance'"`
  93. // // LuckDraw *PlayerLuckDraw `xorm:"TEXT json 'luckDraw'"`
  94. // // Growth *GrowthGift `xorm:"TEXT json 'growth'"`
  95. // // BoxKeyGift *TickBuys2 `xorm:"TEXT json 'boxKeyGift'"` // 装备钥匙礼包
  96. // // NewYearGift *TickBuys2 `xorm:"TEXT json 'newYearGift'"`
  97. // // Fifteen *TickBuys2 `xorm:"TEXT json 'fifteen'"` // NewFifteen *TickBuys2 `xorm:"TEXT json 'newFifteen'"`
  98. // // TombSweep *TickBuys2 `xorm:"TEXT json 'tombSweep'"`
  99. // // Lady38 *TickBuys2 `xorm:"TEXT json 'lady38'"`
  100. // // SpecialGift *SpecialGift `xorm:"TEXT json 'specialGift'"`
  101. // // RichManGift *TickBuys2 `xorm:"TEXT json 'richMan'"` // 51劳动节
  102. // // DragonBoat *TickBuys2 `xorm:"TEXT json 'dragonBoat'"` // 端午节
  103. // // WeekendGift *TickBuys `xorm:"TEXT json 'weekendGift'"` // 周末礼包
  104. // // QiXiGift *TickBuys2 `xorm:"TEXT json 'qiXiGift'"` // 七夕礼包
  105. // // MoonFestivalGift *TickBuys2 `xorm:"TEXT json 'moonFestivalGift'"` // 中秋礼包
  106. // // YuanDanGift *TickBuys2 `xorm:"TEXT json 'yuanDanGift'"` // 元旦礼包
  107. // // ReturneGift *ReturneTickBuys `xorm:"TEXT json 'returneGift'"` // 回归礼包
  108. // // EndLessPass *EndLessPassGift `xorm:"TEXT json 'endLessPassGift'"` // 无尽通行证
  109. // // PuzzlePass *PuzzlePassGift `xorm:"TEXT json 'puzzlePassGift'"` // 拼图通行证
  110. // // WinterJonesPass *PuzzlePassGift `xorm:"TEXT json 'winterjonesPassGift'"` // 冬日夺宝通行证
  111. // // AccCostDiamond *AccCostDiamond `xorm:"TEXT json 'accCostDiamond'"` // 累计花费钻石
  112. // // NewServerAct *NewServerActTickBuys `xorm:"TEXT json 'newServerAct'"` // 新服活动
  113. // // NewerBox2 *NewerBox2 `xorm:"TEXT json 'orderBox2'"` //
  114. // // ChanceBoxGift *GiftInfo `xorm:"TEXT json 'chanceBoxGift'"` // 机缘宝盒
  115. // // NationalGift *TickBuys2 `xorm:"TEXT json 'nationalGift'"` // 国庆礼包
  116. // // Holiday12Gift *TickBuys2 `xorm:"TEXT json 'holiday12Gift'"` // 双11礼包
  117. // // MonarchGift *MonarchGift `xorm:"TEXT json 'monarchGift'"` // 魔君赠送
  118. // // MasterPass *MasterPassGift `xorm:"TEXT json 'masterPassGift'"` // 最强王者通行证
  119. // // RichManPass *RichManPassGift `xorm:"TEXT json 'richManPassGift'"` // 51通行证
  120. // OpenId string `xorm:"-"`
  121. // // GdtVid string `xorm:"-"`
  122. // // Friends []int64 `xorm:"-"`
  123. // // GateId int `xorm:"-"`
  124. // // RecentPayedOrders []string `xorm:"-"` //最近支付订单 不用保存太多,最多50笔
  125. //}
  126. //type PeriodBuys struct {
  127. // // Id int64 `json:"id"`
  128. // Ts int64 `json:"ts"` //最后购买时间
  129. // Count int64 `json:"count"` //周期
  130. // Total int64 `json:"total"` //总
  131. //}
  132. //type RefreshGoods struct {
  133. // Ts int64 `json:"ts"` //刷新时间
  134. // Count int64 `json:"count"` //刷新次数
  135. // Goods []int64 `json:"goods"` //商品ID列表
  136. //}
  137. //type PeriodBuysItem struct {
  138. // Num int `json:"num"`
  139. // Ts int64 `json:"ts"` //当前商品购买时间,计算CD用
  140. //}
  141. // TickBuysTick
  142. // 统计周期内购买商品及数量
  143. //type PeriodBuys2 struct {
  144. // Ts int64 `json:"ts"` //周期开始时间
  145. // Buys map[int64]*PeriodBuysItem `json:"buys"`
  146. //}
  147. //type RefreshBuys struct {
  148. // Ts int64 `json:"ts"` //周期开始时间
  149. // RefreshCount int64 `json:"refresh"` //刷新次数
  150. // Goods []int64 `json:"goods"` //商品ID列表
  151. // Buys map[int64]int `json:"buys"` //购买次数
  152. //}
  153. // StoreGoods
  154. // 商店表-Store exported from 商店表.xlsx
  155. //type StoreGoods struct {
  156. // Id int64 `json:"Uid"` // ID
  157. // GoodsType int64 `json:"GoodsType"` // 商店类型 1--等级商店 2--每日商店 3--金币商店 4--钻石商店
  158. // UnlockLv int64 `json:"UnlockLv"` // 解锁要求 0--不限 1--等级 2--关卡
  159. // Name string `json:"Name"` // 礼包名称
  160. // Content [][]int64 `json:"Content"` // 商品内容
  161. // RandomGroup int64 `json:"RandomGroup"` // 随机组
  162. // Weight int64 `json:"Weight"` // 刷新权重 -1--必出 0--不出
  163. // Quota []int64 `json:"Quota"` // 限购次数 0--不限 1--每日 2--每周 3--总限 4--日刷新
  164. // Discount float64 `json:"Discount"` // 折扣比例 显示用
  165. // Price []int64 `json:"Price"` // 价格 [支付方式,道具ID,数量] 1-现金 2-广告 3-道具 4-免费
  166. // CdrpId int64 `json:"CdrpId"` // 计费点
  167. // Video int64 `json:"Video"` // 广告点ID
  168. //}
  169. //
  170. //func (sg *StoreGoods) GetWeight() int64 {
  171. // return sg.Weight
  172. //}
  173. //func (sg *StoreGoods) GetId() int64 {
  174. // return sg.Id
  175. //}
  176. //
  177. //func (sg *StoreGoods) GetCost() (payType int64, cost []int64, err error) {
  178. // num := len(sg.Price)
  179. // if num == 0 {
  180. // err = errors.New("no price")
  181. // return
  182. // }
  183. // payType = sg.Price[0]
  184. //
  185. // switch payType {
  186. // case PayTypeMoney:
  187. // return
  188. // case PayTypeAd:
  189. // return
  190. // case PayTypeItem:
  191. // if num != 3 {
  192. // err = errors.New("price error")
  193. // return
  194. // }
  195. // cost = sg.Price[1:]
  196. //
  197. // case PayTypeFree:
  198. // return
  199. // }
  200. // return
  201. //}
  202. // 商店刷新-StoreRefresh exported from 商店表.xlsx
  203. type StoreRefresh struct {
  204. Uid int64 `json:"Uid"` // ID
  205. RandomGroup int64 `json:"RandomGroup"` // 随机组
  206. RefreshTime int64 `json:"RefreshTime"` // 刷新次数 0--表示无
  207. RefreshNum int64 `json:"RefreshNum"` // 刷新数量
  208. Price [][]int64 `json:"Price"` // 每次刷新消耗 [方式,具ID,数量] 3-道具 4-免费
  209. }
  210. // 广告点配置-AdList exported from 广告点.xlsx
  211. type AdList struct {
  212. Uid int64 `json:"Uid"` // 广告点唯一编号 其它地方统一调用此编号
  213. Name string `json:"Name"` // 广告点名字
  214. CD int64 `json:"CD"` // 冷却时间 /秒
  215. AdReward [][]int64 `json:"AdReward"` // 有广告时奖励 【【道具类型,道具ID,道具数量】】 【0】:无奖励/功能类广告
  216. NormalReward [][]int64 `json:"NormalReward"` // 无广告时奖励 【】:不填则入口消失 【【道具类型,道具ID,道具数量】】 【0】:无奖励/功能类广告
  217. } // package model
  218. // 渠道组-AdChannel exported from 广告点.xlsx
  219. type AdChannel struct {
  220. Uid int64 `json:"Uid"` // 唯一编号
  221. Name string `json:"Name"` // 渠道名称
  222. Ad int64 `json:"Ad"` // 是否观看广告 0-无 1-有
  223. }
  224. // 计费点-CDRP exported from 计费点.xlsx
  225. type CDRP struct {
  226. Uid int64 `json:"Uid"` // 编号
  227. Name string `json:"Name"` // 名称
  228. UseType int64 `json:"UseType"` // 服务器需要统计不同功能的限购次数,查找不同的功能点 功能类型 1:特惠商店-StoreDiscount 2:钻石商店-StoreDiamond 3:兑换商店-StoreExchange 4:7日礼包-Ac7DayGiftPack 5:每日特惠-AcDailyDeal 6:每日特惠价格-AcDailyDealPrice 7:首充-AcFirstCharge 8:幸运礼包-AcLuckGift 9:活动列表-ActivityList 10:月卡-MonthlyCard 11:特权卡-PrivilegeCard 12:战令配置-WarOrderValue
  229. PlatformPrice1 int64 `json:"PlatformPrice1"` // 微信平台 现价
  230. PlatformPrice2 int64 `json:"PlatformPrice2"` // 抖音平台 现价
  231. Include int64 `json:"Include"` // 是否计入(每日充值,循环充值)金额 0-不计入 1-计入
  232. }
  233. const (
  234. PlatNameWX = "wx"
  235. PlatNameTT = "tt"
  236. PlatNameH5 = "h5"
  237. )
  238. func (c *CDRP) GetPrice(plat string) int64 {
  239. switch plat {
  240. case "wx":
  241. return c.PlatformPrice1
  242. case "tt":
  243. return c.PlatformPrice2
  244. default:
  245. return c.PlatformPrice1
  246. }
  247. }
  248. //type VirtualPayOrder struct {
  249. // Id int64
  250. // PlayerID int64 `xorm:"BIGINT index 'playerid'"`
  251. // OrderId string `xorm:"varchar(255) index 'orderId'"`
  252. // Price int64 `xorm:"BIGINT 'price'"`
  253. // State int `xorm:"int 'state'"`
  254. // GoodsId int64 `xorm:"BIGINT 'goodsId'"` // 购买物品
  255. // Platform int `xorm:"BIGINT 'platform'"` //平台 1:微信 2:抖音
  256. // PayMethod int `xorm:"int 'payMethod'"` //支付方式 //0:苹果游戏外微信支付 1:安卓游戏内支付 2:安卓游戏外微信支付 3:苹果游戏内支付
  257. // Balance int `xorm:"int 'balance'"` //游戏币个数(包含赠送)
  258. // GenBalance int `xorm:"int 'genBalance'"` //赠送游戏币数量(赠送游戏币数量
  259. // SaveSum int `xorm:"int 'saveSum'"` //历史总游戏币金额
  260. // SaveAmt int `xorm:"int 'saveAmt'"` //累计充值金额的游戏币数量
  261. // CostSum int `xorm:"int 'costSum'"` //历史总消费游戏币金额
  262. // PresentSum int `xorm:"int 'presentSum'"` //历史累计收到赠送金额
  263. // Operation string `xorm:"varchar(255) 'operation'"`
  264. // BillNo string `xorm:"varchar(255) 'billNo'"`
  265. // PayedBalance int `xorm:"int 'payedBalance'"` //预扣后的余额
  266. // UsedGenAmt int `xorm:"int 'usedGenAmt'"` //本次扣的赠送币的金额
  267. // CreateTime time.Time `xorm:"created"`
  268. //}
  269. //
  270. //func (m VirtualPayOrder) TableName() string {
  271. // return "virtualpayorder"
  272. //}
  273. //
  274. //func (m *VirtualPayOrder) QueryExist(eng *xorm.Engine) (bool, error) {
  275. // q := new(VirtualPayOrder)
  276. // //q.PlayerID = m.PlayerID
  277. // q.BillNo = m.BillNo
  278. // return eng.Exist(q)
  279. //}
  280. //
  281. //// 不许修改
  282. //func (m *VirtualPayOrder) UpdateDB(eng *xorm.Engine) (int64, error) {
  283. // //return eng.Where("playerid=?", m.PlayerID).Update(m)
  284. // return 0, nil
  285. //}
  286. //
  287. //func (m *VirtualPayOrder) GetUniqueKey() string {
  288. // return m.BillNo
  289. //}
  290. //
  291. //func CopyVirtualPayOrder(old *VirtualPayOrder) *VirtualPayOrder {
  292. // new1, err := deepcopy.Copy(old) //.(*VirtualPayOrder) //new(VirtualPayOrder)
  293. // if err != nil {
  294. // return nil
  295. // }
  296. // // *new1 = *old
  297. // return new1.(*VirtualPayOrder)
  298. //}
  299. // 商品价格表-StoreItem exported from 商店表.xlsx
  300. type StoreItem struct {
  301. ItemId int64 `json:"ItemId"` // 道具ID
  302. Price []int64 `json:"Price"` // 购买价格 【道具ID,价格】
  303. }
  304. // 特惠商店-StoreDiscount exported from 商店表.xlsx
  305. type StoreDiscount struct {
  306. Uid int64 `json:"Uid"` // ID
  307. UnlockLv []int64 `json:"UnlockLv"` // 解锁要求 0--不限 1--等级 2--关卡
  308. Name string `json:"Name"` // 礼包名称
  309. Content [][]int64 `json:"Content"` // 商品内容 【【道具ID,道具数量】】
  310. Quota int64 `json:"Quota"` // 总限购次数
  311. Discount float64 `json:"Discount"` // 折扣比例 显示用
  312. Price []int64 `json:"Price"` // 价格 [支付方式,道具ID,数量] 1-现金 2-广告 3-道具 4-免费
  313. CdrpId int64 `json:"CdrpId"` // 计费点
  314. Video int64 `json:"Video"` // 广告点ID
  315. } // package model
  316. // 每日商店基础-StoreDailyBase exported from 商店表.xlsx
  317. type StoreDailyBase struct {
  318. ResetTime int64 `json:"ResetTime"` // 每日商店 刷新倒计时 /秒
  319. FreeNum int64 `json:"FreeNum"` // 每日免费 刷新次数
  320. GoldNum []int64 `json:"GoldNum"` // 金币刷新 【消耗数量,次数】
  321. ADNum int64 `json:"ADNum"` // 广告刷新 次数
  322. Video int64 `json:"Video"` // 广告点ID
  323. } // package model
  324. // 每日商店-StoreDaily exported from 商店表.xlsx
  325. type StoreDaily struct {
  326. Uid int64 `json:"Uid"` // ID
  327. Slot int64 `json:"Slot"` // 槽位ID
  328. Video int64 `json:"Video"` // 广告点ID
  329. VideoNum int64 `json:"VideoNum"` // 广告点次数
  330. } // package model
  331. // 每日商店随机商品-StoreDailyGoods exported from 商店表.xlsx
  332. type StoreDailyGoods struct {
  333. Uid int64 `json:"Uid"` // 唯一编号
  334. UnlockLv []int64 `json:"UnlockLv"` // 等级范围
  335. Content []int64 `json:"Content"` // 商品内容 【道具ID,道具数量】
  336. Quota int64 `json:"Quota"` // 限购次数
  337. Price []int64 `json:"Price"` // 价格 [支付方式,道具ID,数量] 1-现金 2-广告 3-道具 4-免费
  338. Discount float64 `json:"Discount"` // 折扣比例 显示用
  339. Weight int64 `json:"Weight"` // 出现权重
  340. } // package model
  341. func (t *StoreDailyGoods) GetWeight() int64 {
  342. return t.Weight
  343. }
  344. // 金币商店-StoreGold exported from 商店表.xlsx
  345. type StoreGold struct {
  346. Uid int64 `json:"Uid"` // ID
  347. Name string `json:"Name"` // 礼包名称
  348. Content []int64 `json:"Content"` // 商品内容 【道具ID,道具数量】
  349. Quota int64 `json:"Quota"` // 每日限购次数
  350. Price []int64 `json:"Price"` // 价格 [支付方式,道具ID,数量] 1-现金 2-广告 3-道具 4-免费
  351. CdrpId int64 `json:"CdrpId"` // 计费点
  352. Video int64 `json:"Video"` // 广告点ID
  353. } // package model
  354. // 钻石商店-StoreDiamond exported from 商店表.xlsx
  355. type StoreDiamond struct {
  356. Uid int64 `json:"Uid"` // ID
  357. Name string `json:"Name"` // 礼包名称
  358. Content []int64 `json:"Content"` // 商品内容 【道具ID,道具数量】
  359. ExtraReward []int64 `json:"ExtraReward"` // 首次额外奖励 [道具类型,道具ID,道具数量]
  360. Quota int64 `json:"Quota"` // 每日限购次数
  361. Price []int64 `json:"Price"` // 价格 [支付方式,道具ID,数量] 1-现金 2-广告 3-道具 4-免费
  362. CdrpId int64 `json:"CdrpId"` // 计费点
  363. Video int64 `json:"Video"` // 广告点ID
  364. } // package model
  365. // 兑换商店-StoreExchange exported from 商店表.xlsx
  366. type StoreExchange struct {
  367. Uid int64 `json:"Uid"` // ID
  368. Name string `json:"Name"` // 礼包名称
  369. Content []int64 `json:"Content"` // 商品内容 【道具ID,道具数量】
  370. Quota int64 `json:"Quota"` // 终身限购 每个账号可购买次数
  371. Price []int64 `json:"Price"` // 价格 [支付方式,道具ID,数量] 1-现金 2-广告 3-道具 4-免费
  372. CdrpId int64 `json:"CdrpId"` // 计费点
  373. Video int64 `json:"Video"` // 广告点ID
  374. } // package model
  375. func GetCost(price []int64) (payType int64, cost []int64, err error) {
  376. num := len(price)
  377. if num == 0 {
  378. err = errors.New("no price")
  379. return
  380. }
  381. payType = price[0]
  382. switch payType {
  383. case PayTypeMoney:
  384. return
  385. case PayTypeAd:
  386. return
  387. case PayTypeItem:
  388. if num != 3 {
  389. err = errors.New("price error")
  390. return
  391. }
  392. cost = price[1:]
  393. case PayTypeFree:
  394. return
  395. }
  396. return
  397. }