vip.go 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. package http
  2. import (
  3. "strings"
  4. "go-common/app/interface/main/account/model"
  5. col "go-common/app/service/main/coupon/model"
  6. vipmol "go-common/app/service/main/vip/model"
  7. "go-common/library/ecode"
  8. "go-common/library/log"
  9. bm "go-common/library/net/http/blademaster"
  10. "go-common/library/net/metadata"
  11. )
  12. const (
  13. _headerBuvid = "Buvid"
  14. )
  15. func codeVerify(c *bm.Context) {
  16. c.JSON(vipSvc.CodeVerify(c))
  17. }
  18. func codeOpen(c *bm.Context) {
  19. mid, exists := c.Get("mid")
  20. if !exists {
  21. c.JSON(nil, ecode.NoLogin)
  22. return
  23. }
  24. arg := new(struct {
  25. Token string `form:"token" validate:"required"`
  26. Code string `form:"code" validate:"required"`
  27. Verify string `form:"verify" validate:"required"`
  28. })
  29. if err := c.Bind(arg); err != nil {
  30. return
  31. }
  32. arg.Code = strings.Trim(arg.Code, " ")
  33. c.JSON(vipSvc.CodeOpen(c, mid.(int64), arg.Code, arg.Token, arg.Verify))
  34. }
  35. // tips info.
  36. func tips(c *bm.Context) {
  37. var (
  38. res *vipmol.TipsResp
  39. arg = new(model.TipsReq)
  40. err error
  41. )
  42. if err = c.Bind(arg); err != nil {
  43. log.Error("c.Bind err(%+v)", err)
  44. return
  45. }
  46. if res, err = vipSvc.Tips(c, arg); err != nil {
  47. log.Error("vipSvc.Tips(%+v) err(%v)", arg, err)
  48. c.JSON(nil, err)
  49. return
  50. }
  51. c.JSON(res, nil)
  52. }
  53. // tips info.
  54. func tipsv2(c *bm.Context) {
  55. var (
  56. res []*vipmol.TipsResp
  57. arg = new(model.TipsReq)
  58. err error
  59. )
  60. if err = c.Bind(arg); err != nil {
  61. log.Error("c.Bind err(%+v)", err)
  62. return
  63. }
  64. if res, err = vipSvc.TipsV2(c, arg); err != nil {
  65. log.Error("vipSvc.Tips(%+v) err(%v)", arg, err)
  66. c.JSON(nil, err)
  67. return
  68. }
  69. c.JSON(res, nil)
  70. }
  71. func vipPanel(c *bm.Context) {
  72. var (
  73. err error
  74. res *vipmol.VipPirceResp5
  75. )
  76. mid, exists := c.Get("mid")
  77. if !exists {
  78. c.JSON(nil, ecode.NoLogin)
  79. return
  80. }
  81. arg := new(model.VipPanelRes)
  82. if err = c.Bind(arg); err != nil {
  83. return
  84. }
  85. if res, err = vipSvc.VipPanel5(c, mid.(int64), arg); err != nil {
  86. log.Error("vipSvc.VipPanel(%+v) err(%v)", arg, err)
  87. c.JSON(nil, err)
  88. return
  89. }
  90. c.JSON(res, nil)
  91. }
  92. func couponUsable(c *bm.Context) {
  93. var (
  94. err error
  95. res *col.CouponAllowancePanelInfo
  96. )
  97. mid, exists := c.Get("mid")
  98. if !exists {
  99. c.JSON(nil, ecode.NoLogin)
  100. return
  101. }
  102. arg := new(model.ArgVipCoupon)
  103. if err = c.Bind(arg); err != nil {
  104. return
  105. }
  106. if res, err = vipSvc.CouponBySuitID(c, mid.(int64), arg.ID); err != nil {
  107. c.JSON(nil, err)
  108. return
  109. }
  110. c.JSON(res, nil)
  111. }
  112. func couponList(c *bm.Context) {
  113. var (
  114. err error
  115. res *col.CouponAllowancePanelResp
  116. )
  117. mid, exists := c.Get("mid")
  118. if !exists {
  119. c.JSON(nil, ecode.NoLogin)
  120. return
  121. }
  122. arg := new(model.ArgVipCoupon)
  123. if err = c.Bind(arg); err != nil {
  124. return
  125. }
  126. if res, err = vipSvc.CouponsForPanelV2(c, mid.(int64), arg.ID); err != nil {
  127. log.Error("vipSvc.CouponsForPanelV2(%+v) err(%v)", arg, err)
  128. c.JSON(nil, err)
  129. return
  130. }
  131. c.JSON(res, nil)
  132. }
  133. func couponUnlock(c *bm.Context) {
  134. var err error
  135. mid, exists := c.Get("mid")
  136. if !exists {
  137. c.JSON(nil, ecode.NoLogin)
  138. return
  139. }
  140. arg := new(model.ArgVipCancelPay)
  141. if err = c.Bind(arg); err != nil {
  142. return
  143. }
  144. if err = vipSvc.CancelUseCoupon(c, &vipmol.ArgCancelUseCoupon{
  145. Mid: mid.(int64),
  146. CouponToken: arg.CouponToken,
  147. }); err != nil {
  148. log.Error("vipSvc.CancelUseCoupon(%+v) err(%v)", arg, err)
  149. c.JSON(nil, err)
  150. return
  151. }
  152. c.JSON(model.CouponCancelExplain, nil)
  153. }
  154. func vipPanelV2(c *bm.Context) {
  155. var err error
  156. arg := new(model.ArgVipPanel)
  157. if err = c.Bind(arg); err != nil {
  158. return
  159. }
  160. mid, exists := c.Get("mid")
  161. if exists {
  162. arg.Mid = mid.(int64)
  163. }
  164. arg.IP = metadata.String(c, metadata.RemoteIP)
  165. c.JSON(vipSvc.VipPanelV2(c, arg))
  166. }
  167. func vipPanelV8(c *bm.Context) {
  168. var err error
  169. arg := new(model.ArgVipPanel)
  170. if err = c.Bind(arg); err != nil {
  171. return
  172. }
  173. mid, exists := c.Get("mid")
  174. if exists {
  175. arg.Mid = mid.(int64)
  176. }
  177. arg.IP = metadata.String(c, metadata.RemoteIP)
  178. c.JSON(vipSvc.VipPanelV8(c, arg))
  179. }
  180. func privilegeBySid(c *bm.Context) {
  181. var err error
  182. arg := new(vipmol.ArgPrivilegeBySid)
  183. if err = c.Bind(arg); err != nil {
  184. return
  185. }
  186. c.JSON(vipSvc.PrivilegebySid(c, arg))
  187. }
  188. func privilegeByType(c *bm.Context) {
  189. var err error
  190. arg := new(vipmol.ArgPrivilegeDetail)
  191. if err = c.Bind(arg); err != nil {
  192. return
  193. }
  194. c.JSON(vipSvc.PrivilegebyType(c, arg))
  195. }
  196. func vipManagerInfo(c *bm.Context) {
  197. c.JSON(vipSvc.ManagerInfo(c))
  198. }
  199. func codeOpeneds(c *bm.Context) {
  200. var (
  201. err error
  202. )
  203. arg := new(model.CodeInfoReq)
  204. if err = c.Bind(arg); err != nil {
  205. return
  206. }
  207. c.JSON(vipSvc.CodeOpeneds(c, arg, metadata.String(c, metadata.RemoteIP)))
  208. }
  209. func unfrozen(c *bm.Context) {
  210. mid, exists := c.Get("mid")
  211. if !exists {
  212. c.JSON(nil, ecode.AccountNotLogin)
  213. return
  214. }
  215. c.JSON(nil, vipSvc.Unfrozen(c, mid.(int64)))
  216. }
  217. func frozenTime(c *bm.Context) {
  218. mid, exists := c.Get("mid")
  219. if !exists {
  220. c.JSON(nil, ecode.AccountNotLogin)
  221. return
  222. }
  223. c.JSON(vipSvc.FrozenTime(c, mid.(int64)))
  224. }
  225. func publicPriceList(c *bm.Context) {
  226. var (
  227. err error
  228. res *vipmol.VipPirceResp
  229. mid int64
  230. )
  231. midStr, exists := c.Get("mid")
  232. if exists {
  233. mid = midStr.(int64)
  234. }
  235. arg := new(model.VipPanelRes)
  236. if err = c.Bind(arg); err != nil {
  237. return
  238. }
  239. if res, err = vipSvc.VipPanel(c, mid, arg); err != nil {
  240. log.Error("vipSvc.VipPanel(%+v) err(%v)", arg, err)
  241. c.JSON(nil, err)
  242. return
  243. }
  244. c.JSON(res, nil)
  245. }
  246. func useBatch(c *bm.Context) {
  247. var err error
  248. arg := new(vipmol.ArgUseBatch)
  249. if err = c.Bind(arg); err != nil {
  250. log.Error("use batch bind err(%+v) arg(%+v)", err, arg)
  251. return
  252. }
  253. c.JSON(nil, vipSvc.UseBatch(c, arg))
  254. }
  255. func orderStatus(c *bm.Context) {
  256. var (
  257. err error
  258. )
  259. midI, ok := c.Get("mid")
  260. if !ok {
  261. c.JSON(nil, ecode.NoLogin)
  262. return
  263. }
  264. arg := new(vipmol.ArgDialog)
  265. if err = c.Bind(arg); err != nil {
  266. return
  267. }
  268. arg.Mid = midI.(int64)
  269. c.JSON(vipSvc.OrderStatus(c, arg))
  270. }
  271. func resourceBanner(c *bm.Context) {
  272. var (
  273. err error
  274. )
  275. midI, ok := c.Get("mid")
  276. if !ok {
  277. c.JSON(nil, ecode.NoLogin)
  278. return
  279. }
  280. arg := new(model.ArgResource)
  281. if err = c.Bind(arg); err != nil {
  282. return
  283. }
  284. arg.MID = midI.(int64)
  285. arg.Buvid = c.Request.Header.Get(_headerBuvid)
  286. arg.Plat = model.Plat(arg.MobiApp, arg.Device)
  287. c.JSON(vipSvc.ResourceBanner(c, arg))
  288. }
  289. func resourceBuy(c *bm.Context) {
  290. var (
  291. err error
  292. )
  293. midI, ok := c.Get("mid")
  294. if !ok {
  295. c.JSON(nil, ecode.NoLogin)
  296. return
  297. }
  298. arg := new(model.ArgResource)
  299. if err = c.Bind(arg); err != nil {
  300. return
  301. }
  302. arg.MID = midI.(int64)
  303. arg.Buvid = c.Request.Header.Get(_headerBuvid)
  304. arg.Plat = model.Plat(arg.MobiApp, arg.Device)
  305. c.JSON(vipSvc.ResourceBuy(c, arg))
  306. }
  307. func couponBySuitIDV2(c *bm.Context) {
  308. var err error
  309. arg := new(model.ArgCouponBySuitID)
  310. if err = c.Bind(arg); err != nil {
  311. return
  312. }
  313. mid, exists := c.Get("mid")
  314. if exists {
  315. arg.Mid = mid.(int64)
  316. }
  317. c.JSON(vipSvc.CouponBySuitIDV2(c, arg))
  318. }
  319. func vipPanelV9(c *bm.Context) {
  320. var err error
  321. arg := new(model.ArgVipPanel)
  322. if err = c.Bind(arg); err != nil {
  323. return
  324. }
  325. mid, exists := c.Get("mid")
  326. if exists {
  327. arg.Mid = mid.(int64)
  328. }
  329. arg.IP = metadata.String(c, metadata.RemoteIP)
  330. c.JSON(vipSvc.VipPanelV9(c, arg))
  331. }