ticket.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package model
  2. import (
  3. item "go-common/app/service/openplatform/ticket-item/api/grpc/v1"
  4. "strconv"
  5. )
  6. // TicketInfo 票价综合字段
  7. type TicketInfo struct {
  8. TicketPrice
  9. BuyNumLimit map[string]*TicketPriceExtra
  10. }
  11. // FormatTicketBuyLimit 格式化票价购票限制
  12. func (t *TicketInfo) FormatTicketBuyLimit(limit *item.TicketBuyNumLimit) {
  13. limit.Normal = make(map[int32]int64)
  14. limit.Vip = make(map[int32]int64)
  15. limit.AnnualVip = make(map[int32]int64)
  16. if ext, ok := t.BuyNumLimit[TkBuyNumLimitNormal]; ok {
  17. limit.Normal = ext.ParseBuyLimit()
  18. }
  19. if ext, ok := t.BuyNumLimit[TkBuyNumLimitVip]; ok {
  20. limit.Vip = ext.ParseBuyLimit()
  21. }
  22. if ext, ok := t.BuyNumLimit[TkBuyNumLimitAnnualVip]; ok {
  23. limit.AnnualVip = ext.ParseBuyLimit()
  24. }
  25. }
  26. // ParseBuyLimit parse 购票限制成map
  27. func (ext *TicketPriceExtra) ParseBuyLimit() (m map[int32]int64) {
  28. var (
  29. i int32
  30. max int32
  31. l int32
  32. )
  33. l = 2
  34. max = 6
  35. r := []rune(ext.Value)
  36. m = make(map[int32]int64)
  37. for i = 0; i < max+1; i++ {
  38. m[i] = ext.SliceBuyLimit(r, i*l, (i+1)*l)
  39. }
  40. return m
  41. }
  42. // SliceBuyLimit 分割等级购票限制
  43. func (ext *TicketPriceExtra) SliceBuyLimit(r []rune, start int32, end int32) int64 {
  44. slice := string(r[start:end])
  45. if i, err := strconv.ParseInt(slice, 10, 64); err == nil {
  46. return i
  47. } else if slice == "**" {
  48. return -1
  49. } else {
  50. return 0
  51. }
  52. }