coupon.go 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. package model
  2. import (
  3. "fmt"
  4. "strings"
  5. "go-common/library/time"
  6. )
  7. // coupon_batch_info表 product_limit_renewal字段.
  8. const (
  9. ProdLimRenewalAll int8 = iota
  10. ProdLimRenewalAuto
  11. ProdLimRenewalNotAuto
  12. )
  13. // coupon_batch_info表 product_limit_renewal字段.
  14. const (
  15. None int8 = 0
  16. ProdLimMonth1 = 1
  17. ProdLimMonth3 = 3
  18. ProdLimMonth12 = 12
  19. )
  20. const (
  21. // CardSalt .
  22. CardSalt = "7RbjA6mpSz9DYQ0n"
  23. )
  24. // CardType table:coupon_user_card field:card_type
  25. const (
  26. CardType1 int8 = iota
  27. CardType3
  28. CardType12
  29. )
  30. // CardState table:coupon_user_card field:state
  31. const (
  32. CardStateNotOpen int8 = iota
  33. CardStateOpened
  34. CardStateUsed
  35. )
  36. // product limit map .
  37. var (
  38. ProdLimMonthMap = map[int8]string{None: "", ProdLimMonth1: "月度", ProdLimMonth3: "季度", ProdLimMonth12: "年度"}
  39. ProdLimRenewalMap = map[int8]string{ProdLimRenewalAll: "", ProdLimRenewalAuto: "自动续期", ProdLimRenewalNotAuto: "非自动续期"}
  40. )
  41. // MapFullAmount .
  42. var MapFullAmount = map[int8]float64{
  43. CardType1: 25,
  44. CardType3: 68,
  45. CardType12: 233,
  46. }
  47. // CouponChangeLog coupon change log.
  48. type CouponChangeLog struct {
  49. ID int64 `json:"-"`
  50. CouponToken string `json:"coupon_token"`
  51. Mid int64 `json:"mid"`
  52. State int8 `json:"state"`
  53. Ctime time.Time `json:"ctime"`
  54. Mtime time.Time `json:"mtime"`
  55. }
  56. // CouponPageResp coupon page.
  57. type CouponPageResp struct {
  58. ID int64 `json:"id"`
  59. Title string `json:"title"`
  60. Time int64 `json:"time"`
  61. RefID int64 `json:"ref_id"`
  62. Tips string `json:"tips"`
  63. Count int64 `json:"count"`
  64. }
  65. // CouponOrder coupon order info.
  66. type CouponOrder struct {
  67. ID int64 `json:"id"`
  68. OrderNo string `json:"order_no"`
  69. Mid int64 `json:"mid"`
  70. Count int64 `json:"count"`
  71. State int8 `json:"state"`
  72. CouponType int8 `json:"coupon_type"`
  73. ThirdTradeNo string `json:"third_trade_no"`
  74. Remark string `json:"remark"`
  75. Tips string `json:"tips"`
  76. UseVer int64 `json:"use_ver"`
  77. Ver int64 `json:"ver"`
  78. Ctime time.Time `json:"ctime"`
  79. Mtime time.Time `json:"mtime"`
  80. }
  81. // CouponOrderLog coupon order log.
  82. type CouponOrderLog struct {
  83. ID int64 `json:"id"`
  84. OrderNo string `json:"order_no"`
  85. Mid int64 `json:"mid"`
  86. State int8 `json:"state"`
  87. Ctime time.Time `json:"ctime"`
  88. Mtime time.Time `json:"mtime"`
  89. }
  90. // CouponBalanceChangeLog coupon balance change log.
  91. type CouponBalanceChangeLog struct {
  92. ID int64 `json:"id"`
  93. OrderNo string `json:"order_no"`
  94. Mid int64 `json:"mid"`
  95. BatchToken string `json:"batch_token"`
  96. Balance int64 `json:"balance"`
  97. ChangeBalance int64 `json:"change_balance"`
  98. ChangeType int8 `json:"change_type"`
  99. Ctime time.Time `json:"ctime"`
  100. Mtime time.Time `json:"mtime"`
  101. }
  102. // CouponCartoonPageResp coupon cartoon page.
  103. type CouponCartoonPageResp struct {
  104. Count int64 `json:"count"`
  105. CouponCount int64 `json:"coupon_count"`
  106. List []*CouponPageResp `json:"list"`
  107. }
  108. // CouponBatchInfo coupon batch info.
  109. type CouponBatchInfo struct {
  110. ID int64 `json:"id"`
  111. AppID int64 `json:"app_id"`
  112. Name string `json:"name"`
  113. BatchToken string `json:"batch_token"`
  114. MaxCount int64 `json:"max_count"`
  115. CurrentCount int64 `json:"current_count"`
  116. LimitCount int64 `json:"limit_count"`
  117. StartTime int64 `json:"start_time"`
  118. ExpireTime int64 `json:"expire_time"`
  119. ExpireDay int64 `json:"expire_day"`
  120. Ver int64 `json:"ver"`
  121. Ctime time.Time `json:"ctime"`
  122. Mtime time.Time `json:"mtime"`
  123. FullAmount float64 `json:"full_amount"`
  124. Amount float64 `json:"amount"`
  125. State int8 `json:"state"`
  126. CouponType int8 `json:"coupon_type"`
  127. PlatformLimit string `json:"platform_limit"`
  128. ProdLimMonth int8 `json:"product_limit_month"`
  129. ProdLimRenewal int8 `json:"product_limit_Renewal"`
  130. }
  131. // CouponAllowancePanelInfo allowance coupon panel info.
  132. type CouponAllowancePanelInfo struct {
  133. CouponToken string `json:"coupon_token"`
  134. Amount float64 `json:"coupon_amount"`
  135. State int32 `json:"state"`
  136. FullLimitExplain string `json:"full_limit_explain"`
  137. ScopeExplain string `json:"scope_explain"`
  138. FullAmount float64 `json:"full_amount"`
  139. CouponDiscountPrice float64 `json:"coupon_discount_price"`
  140. StartTime int64 `json:"start_time"`
  141. ExpireTime int64 `json:"expire_time"`
  142. Selected int8 `json:"selected"`
  143. DisablesExplains string `json:"disables_explains"`
  144. OrderNO string `json:"order_no"`
  145. Name string `json:"name"`
  146. Usable int8 `json:"usable"`
  147. }
  148. // CouponTipInfo coupon tip info.
  149. type CouponTipInfo struct {
  150. CouponTip string `json:"coupon_tip"`
  151. CouponInfo *CouponAllowancePanelInfo `json:"coupon_info"`
  152. }
  153. // CouponAllowanceChangeLog coupon allowance change log.
  154. type CouponAllowanceChangeLog struct {
  155. ID int64 `json:"-"`
  156. CouponToken string `json:"coupon_token"`
  157. OrderNO string `json:"order_no"`
  158. Mid int64 `json:"mid"`
  159. State int8 `json:"state"`
  160. ChangeType int8 `json:"change_type"`
  161. Ctime time.Time `json:"ctime"`
  162. Mtime time.Time `json:"mtime"`
  163. }
  164. //CouponReceiveLog receive log.
  165. type CouponReceiveLog struct {
  166. ID int64 `json:"id"`
  167. Appkey string `json:"appkey"`
  168. OrderNo string `json:"order_no"`
  169. Mid int64 `json:"mid"`
  170. CouponToken string `json:"coupon_token"`
  171. CouponType int8 `json:"coupon_type"`
  172. }
  173. //CouponAllowancePanelResp def.
  174. type CouponAllowancePanelResp struct {
  175. Usables []*CouponAllowancePanelInfo `json:"usables"`
  176. Disables []*CouponAllowancePanelInfo `json:"disables"`
  177. Using []*CouponAllowancePanelInfo `json:"using"`
  178. }
  179. // SalaryCouponForThirdResp resp.
  180. type SalaryCouponForThirdResp struct {
  181. Amount float64 `json:"amount"`
  182. FullAmount float64 `json:"full_amount"`
  183. Description string `json:"description"`
  184. }
  185. // ScopeExplainFmt get scope explain fmt.
  186. func (c *CouponAllowancePanelInfo) ScopeExplainFmt(pstr string, prodLimMonth, prodLimRenewal int8, platMap map[string]string) {
  187. var (
  188. ps []string
  189. plats, scope, scopePlat, limr, limm string
  190. )
  191. if len(pstr) == 0 && prodLimMonth == 0 && prodLimRenewal == 0 {
  192. c.ScopeExplain = ScopeNoLimit
  193. return
  194. }
  195. if len(pstr) > 0 {
  196. ps = strings.Split(pstr, ",")
  197. for _, v := range ps {
  198. plats += platMap[v] + ","
  199. }
  200. }
  201. if len(plats) > 0 {
  202. plats = plats[:len(plats)-1]
  203. scopePlat = fmt.Sprintf(ScopePlatFmt, plats)
  204. }
  205. limr = ProdLimRenewalMap[prodLimRenewal]
  206. limm = ProdLimMonthMap[prodLimMonth]
  207. scope = scopePlat + fmt.Sprintf(ScopeProductFmt, limr, limm)
  208. c.ScopeExplain = scope
  209. }
  210. // PlatfromLimitExplain platform limit explain.
  211. func PlatfromLimitExplain(pstr string, platMap map[string]string) string {
  212. var (
  213. ps []string
  214. plats string
  215. )
  216. if len(pstr) == 0 {
  217. return ""
  218. }
  219. if len(pstr) > 0 {
  220. ps = strings.Split(pstr, ",")
  221. for _, v := range ps {
  222. plats += platMap[v] + ","
  223. }
  224. }
  225. if len(plats) > 0 {
  226. plats = plats[:len(plats)-1]
  227. }
  228. return plats
  229. }
  230. // PrizeCards struct .
  231. type PrizeCards struct {
  232. List []*PrizeCardRep `json:"list"`
  233. }
  234. // PrizeCardRep struct .
  235. type PrizeCardRep struct {
  236. CardType int8 `json:"card_type"`
  237. State int8 `json:"state"`
  238. OriginalPrice int64 `json:"original_price,omitempty"`
  239. CouponAmount int64 `json:"coupon_amount,omitempty"`
  240. DiscountRate string `json:"discount_rate,omitempty"`
  241. }
  242. // CouponUserCard struct .
  243. type CouponUserCard struct {
  244. MID int64 `json:"mid"`
  245. CardType int8 `json:"card_type"`
  246. State int8 `json:"state"`
  247. BatchToken string `json:"batch_token"`
  248. CouponToken string `json:"coupon_token"`
  249. ActID int64 `json:"act_id"`
  250. }