panel.go 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. package model
  2. import (
  3. "fmt"
  4. "math"
  5. "strconv"
  6. colapi "go-common/app/service/main/coupon/api"
  7. col "go-common/app/service/main/coupon/model"
  8. "go-common/library/time"
  9. )
  10. // vip_price_config suit_type
  11. const (
  12. AllUser int8 = iota
  13. OldVIP
  14. NewVIP
  15. OldSubVIP
  16. NewSubVIP
  17. OldPackVIP
  18. NewPackVIP
  19. )
  20. // order type
  21. const (
  22. NoRenew int8 = iota
  23. OtherRenew
  24. IOSRenew
  25. )
  26. // order type by month for vip_user_discount_history table
  27. const (
  28. OneMonthSub int8 = iota + 1
  29. ThreeMonthSub
  30. OneYearSub
  31. )
  32. // const month
  33. const (
  34. OneMonth = int8(1)
  35. ThreeMonth = int8(3)
  36. OneYear = int8(12)
  37. )
  38. // const vip_price_config beforeSuitType
  39. const (
  40. All int8 = iota
  41. VIP
  42. Sub
  43. Pack
  44. )
  45. // const panel month sort
  46. const (
  47. PanelMonthDESC int8 = iota
  48. PanelMonthASC
  49. )
  50. // const PanelType
  51. const (
  52. PanelTypeNormal = "normal"
  53. PanelTypeFriend = "friend"
  54. PanelTypeCheck = "check"
  55. PanelTypeEle = "ele"
  56. )
  57. const (
  58. // PlatVipPriceConfigOther 其他平台
  59. PlatVipPriceConfigOther int64 = iota + 1
  60. // PlatVipPriceConfigIOS IOS平台
  61. PlatVipPriceConfigIOS
  62. // PlatVipPriceConfigIPADHD ipad hd平台
  63. PlatVipPriceConfigIPADHD
  64. // PlatVipPriceConfigFriendsGift 好友赠送
  65. PlatVipPriceConfigFriendsGift
  66. // PlatVipPriceConfigInternational 安卓国际版
  67. PlatVipPriceConfigInternational
  68. // PlatVipPriceConfigIphoneB iphone蓝版
  69. PlatVipPriceConfigIphoneB
  70. // PlatVipPriceConfigCheck 审核态价格
  71. PlatVipPriceConfigCheck = 20
  72. )
  73. // const select
  74. const (
  75. PanelNotSelected int32 = iota
  76. PanelSelected
  77. )
  78. // VipPriceConfig price config.
  79. type VipPriceConfig struct {
  80. ID int64 `json:"id"`
  81. Plat int64 `json:"platform"`
  82. PdName string `json:"product_name"`
  83. PdID string `json:"product_id"`
  84. SuitType int8 `json:"suit_type"`
  85. TopSuitType int8 `json:"-"`
  86. Month int16 `json:"month"`
  87. SubType int8 `json:"sub_type"`
  88. OPrice float64 `json:"original_price"`
  89. DPrice float64 `json:"discount_price"`
  90. Selected int32 `json:"selected"`
  91. Remark string `json:"remark"`
  92. Status int8 `json:"status"`
  93. Forever bool `json:"-"`
  94. Operator string `json:"operator"`
  95. OpID int64 `json:"oper_id"`
  96. Superscript string `json:"superscript"`
  97. StartBuild int64 `json:"start_build"`
  98. EndBuild int64 `json:"end_build"`
  99. PanelType string `json:"panel_type"`
  100. CTime time.Time `json:"ctime"`
  101. MTime time.Time `json:"mtime"`
  102. }
  103. // VipPirceResp vip pirce resp.
  104. type VipPirceResp struct {
  105. Vps []*VipPanelInfo `json:"price_list"`
  106. CouponInfo *col.CouponAllowancePanelInfo `json:"coupon_info"`
  107. CouponSwith int8 `json:"coupon_switch"`
  108. CodeSwitch int8 `json:"code_switch"`
  109. GiveSwitch int8 `json:"give_switch"`
  110. ExistCoupon int8 `json:"exist_coupon"`
  111. Privileges *PrivilegesResp `json:"privileges"`
  112. }
  113. // VipPirceResp5 vip pirce resp.
  114. type VipPirceResp5 struct {
  115. Vps []*VipPanelInfo `json:"price_list"`
  116. CouponInfo *col.CouponAllowancePanelInfo `json:"coupon_info"`
  117. CouponSwith int8 `json:"coupon_switch"`
  118. CodeSwitch int8 `json:"code_switch"`
  119. GiveSwitch int8 `json:"give_switch"`
  120. Privileges map[int8]*PrivilegesResp `json:"privileges"`
  121. }
  122. // VipPirceRespV9 vip pirce resp v9.
  123. type VipPirceRespV9 struct {
  124. Vps []*VipPanelInfo `json:"price_list"`
  125. Coupon *colapi.UsableAllowanceCouponV2Reply `json:"coupon"`
  126. CouponSwith int8 `json:"coupon_switch"`
  127. CodeSwitch int8 `json:"code_switch"`
  128. GiveSwitch int8 `json:"give_switch"`
  129. Privileges map[int8]*PrivilegesResp `json:"privileges"`
  130. }
  131. // VipDPriceConfig price discount config.
  132. type VipDPriceConfig struct {
  133. ID int64 `json:"id"`
  134. PdID string `json:"product_id"`
  135. DPrice float64 `json:"discount_price"`
  136. STime time.Time `json:"stime"`
  137. ETime time.Time `json:"etime"`
  138. Remark string `json:"remark"`
  139. Operator string `json:"operator"`
  140. OpID int64 `json:"oper_id"`
  141. CTime time.Time `json:"ctime"`
  142. MTime time.Time `json:"mtime"`
  143. FirstPrice float64 `json:"first_price"`
  144. }
  145. // DoTopSuitType .
  146. func (vpc *VipPriceConfig) DoTopSuitType() {
  147. switch vpc.SuitType {
  148. case OldPackVIP, NewPackVIP:
  149. vpc.TopSuitType = Pack
  150. case OldSubVIP, NewSubVIP:
  151. vpc.TopSuitType = Sub
  152. case OldVIP, NewVIP:
  153. vpc.TopSuitType = VIP
  154. case AllUser:
  155. vpc.TopSuitType = All
  156. }
  157. }
  158. // DoCheckRealPrice ,
  159. func (vpc *VipPriceConfig) DoCheckRealPrice(mvp map[int64]*VipDPriceConfig) {
  160. if vp, ok := mvp[vpc.ID]; ok {
  161. vpc.PdID = vp.PdID
  162. vpc.DPrice = vp.DPrice
  163. vpc.Remark = vp.Remark
  164. if vp.FirstPrice > 0 && vpc.SubType == AutoRenew {
  165. vpc.DPrice = vp.FirstPrice
  166. }
  167. }
  168. if vpc.DPrice == 0 {
  169. vpc.DPrice = vpc.OPrice
  170. }
  171. }
  172. // DoSubMonthKey .
  173. func (vpc *VipPriceConfig) DoSubMonthKey() string {
  174. return fmt.Sprintf("%d%d", vpc.Month, vpc.SubType)
  175. }
  176. // FormatRate .
  177. func (vpc *VipPriceConfig) FormatRate() string {
  178. if vpc.DPrice == 0 {
  179. return ""
  180. }
  181. if vpc.DPrice/vpc.OPrice == 1 {
  182. return ""
  183. }
  184. return strconv.FormatFloat(math.Floor((vpc.DPrice/vpc.OPrice)*100)/10, 'f', -1, 64) + "折"
  185. }
  186. // DoPayOrderTypeKey .
  187. func (po *PayOrder) DoPayOrderTypeKey() string {
  188. if po.OrderType == IOSRenew {
  189. po.OrderType = OtherRenew
  190. }
  191. return fmt.Sprintf("%d%d", po.BuyMonths, po.OrderType)
  192. }
  193. // IsSub .
  194. func (po *PayOrder) IsSub() bool {
  195. return po.OrderType == OtherRenew || po.OrderType == IOSRenew
  196. }
  197. // VipPirce vip pirce.
  198. type VipPirce struct {
  199. Panel *VipPanelInfo `json:"pirce_info"`
  200. Coupon *col.CouponAllowanceInfo `json:"coupon_info"`
  201. }
  202. // VipPanelExplain vip panel explain.
  203. type VipPanelExplain struct {
  204. BackgroundURL string `json:"background_url"`
  205. Explain string `json:"user_explain"`
  206. }
  207. // FilterBuild filter price build .
  208. func (vpc *VipPriceConfig) FilterBuild(build int64) bool {
  209. if (vpc.StartBuild != 0 && vpc.StartBuild > build) || (vpc.EndBuild != 0 && vpc.EndBuild < build) {
  210. return false
  211. }
  212. return true
  213. }
  214. // ArgProductLimit args product limit.
  215. type ArgProductLimit struct {
  216. Mid int64
  217. Months int32
  218. PanelType string
  219. }