pendant.go 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/service/main/usersuit/model"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/xstr"
  9. )
  10. const (
  11. _paySuccess = "1"
  12. )
  13. // groupInfo get group info
  14. func groupInfo(c *bm.Context) {
  15. c.JSON(usersuitSvc.GroupInfo(c))
  16. }
  17. // groupInfoByID get group info
  18. func groupInfoByID(c *bm.Context) {
  19. var (
  20. err error
  21. gid int64
  22. params = c.Request.Form
  23. gidstr = params.Get("gid")
  24. )
  25. if gidstr == "" {
  26. c.JSON(nil, ecode.RequestErr)
  27. return
  28. }
  29. if gid, err = strconv.ParseInt(gidstr, 10, 64); err != nil || gid < 0 {
  30. c.JSON(nil, ecode.RequestErr)
  31. return
  32. }
  33. c.JSON(usersuitSvc.GroupInfoByID(c, gid))
  34. }
  35. // vipGroup return vip group info
  36. func vipGroup(c *bm.Context) {
  37. c.JSON(usersuitSvc.GroupInfoByID(c, 31))
  38. }
  39. // entryGroup return vip group info
  40. func entryGroup(c *bm.Context) {
  41. c.JSON(usersuitSvc.GroupInfoByID(c, 30))
  42. }
  43. // pointRecommend get pendant which has point pay type
  44. func pointRecommend(c *bm.Context) {
  45. var (
  46. err error
  47. mid int64
  48. params = c.Request.Form
  49. midstr = params.Get("mid")
  50. )
  51. if midstr == "" {
  52. c.JSON(nil, ecode.RequestErr)
  53. return
  54. }
  55. if mid, err = strconv.ParseInt(midstr, 10, 64); err != nil || mid <= 0 {
  56. c.JSON(nil, ecode.RequestErr)
  57. return
  58. }
  59. c.JSON(usersuitSvc.PendantPoint(c, mid))
  60. }
  61. // pendantByID return pendant info
  62. func pendantByID(c *bm.Context) {
  63. var (
  64. err error
  65. pid int64
  66. params = c.Request.Form
  67. pidstr = params.Get("pid")
  68. )
  69. if pidstr == "" {
  70. c.JSON(nil, ecode.RequestErr)
  71. return
  72. }
  73. if pid, err = strconv.ParseInt(pidstr, 10, 64); err != nil || pid <= 0 {
  74. c.JSON(nil, ecode.RequestErr)
  75. return
  76. }
  77. c.JSON(usersuitSvc.PendantInfo(c, pid))
  78. }
  79. // orderHistory query order history
  80. func orderHistory(c *bm.Context) {
  81. var (
  82. err error
  83. t int64
  84. history *model.ArgOrderHistory
  85. data []*model.PendantOrderInfo
  86. count map[string]int64
  87. req = c.Request
  88. params = req.Form
  89. midStr = params.Get("mid")
  90. pidStr = params.Get("pid")
  91. orderID = params.Get("orderID")
  92. payID = params.Get("payID")
  93. payType = params.Get("payType")
  94. status = params.Get("status")
  95. startTime = params.Get("start_time")
  96. endTime = params.Get("end_time")
  97. page = params.Get("page")
  98. )
  99. if midStr == "" {
  100. c.JSON(nil, ecode.RequestErr)
  101. return
  102. }
  103. history = new(model.ArgOrderHistory)
  104. if history.Mid, err = strconv.ParseInt(midStr, 10, 64); err != nil || history.Mid <= 0 {
  105. c.JSON(nil, ecode.RequestErr)
  106. return
  107. }
  108. if pidStr != "" {
  109. if t, err = strconv.ParseInt(pidStr, 10, 64); err != nil {
  110. c.JSON(nil, ecode.RequestErr)
  111. return
  112. }
  113. history.Pid = t
  114. }
  115. if orderID != "" {
  116. history.OrderID = orderID
  117. }
  118. if payID != "" {
  119. history.PayID = payID
  120. }
  121. if payType != "" {
  122. if t, err = strconv.ParseInt(payType, 10, 64); err != nil {
  123. c.JSON(nil, ecode.RequestErr)
  124. return
  125. }
  126. history.PayType = int32(t)
  127. }
  128. if status != "" {
  129. if t, err = strconv.ParseInt(status, 10, 64); err != nil {
  130. c.JSON(nil, ecode.RequestErr)
  131. return
  132. }
  133. history.Status = int32(t)
  134. }
  135. if startTime != "" {
  136. if t, err = strconv.ParseInt(startTime, 10, 64); err != nil {
  137. c.JSON(nil, ecode.RequestErr)
  138. return
  139. }
  140. history.StartTime = t
  141. }
  142. if endTime != "" {
  143. if t, err = strconv.ParseInt(endTime, 10, 64); err != nil {
  144. c.JSON(nil, ecode.RequestErr)
  145. return
  146. }
  147. history.EndTime = t
  148. }
  149. if page != "" {
  150. if t, err = strconv.ParseInt(page, 10, 64); err != nil {
  151. history.Page = 1
  152. }
  153. history.Page = t
  154. } else {
  155. history.Page = 1
  156. }
  157. if data, count, err = usersuitSvc.OrderHistory(c, history); err != nil {
  158. log.Error("usersuitSvc.History error(%v)", err)
  159. c.JSON(nil, err)
  160. return
  161. }
  162. c.JSONMap(map[string]interface{}{
  163. "data": data,
  164. "count": count,
  165. }, nil)
  166. }
  167. // packageInfo get user package
  168. func packageInfo(c *bm.Context) {
  169. var (
  170. err error
  171. mid int64
  172. req = c.Request
  173. midStr = req.Form.Get("mid")
  174. )
  175. if midStr == "" {
  176. c.JSON(nil, ecode.RequestErr)
  177. return
  178. }
  179. if mid, err = strconv.ParseInt(midStr, 10, 64); err != nil || mid <= 0 {
  180. c.JSON(nil, ecode.RequestErr)
  181. return
  182. }
  183. c.JSON(usersuitSvc.PackageInfo(c, mid))
  184. }
  185. // equipment get current equipped pendant
  186. func equipment(c *bm.Context) {
  187. var (
  188. err error
  189. mid int64
  190. req = c.Request
  191. params = req.Form
  192. midStr = params.Get("mid")
  193. )
  194. if midStr == "" {
  195. c.JSON(nil, ecode.RequestErr)
  196. return
  197. }
  198. if mid, err = strconv.ParseInt(midStr, 10, 64); err != nil || mid <= 0 {
  199. c.JSON(nil, ecode.RequestErr)
  200. return
  201. }
  202. c.JSON(usersuitSvc.Equipment(c, mid))
  203. }
  204. // order order pendant
  205. func order(c *bm.Context) {
  206. var (
  207. err error
  208. mid, pid, expires, tp int64
  209. orderData *model.PayInfo
  210. req = c.Request
  211. params = req.Form
  212. midStr = params.Get("mid")
  213. pidStr = params.Get("pid")
  214. expiresStr = params.Get("expires")
  215. typeStr = params.Get("moneytype")
  216. )
  217. if midStr == "" || pidStr == "" || expiresStr == "" || typeStr == "" {
  218. c.JSON(nil, ecode.RequestErr)
  219. return
  220. }
  221. if mid, err = strconv.ParseInt(midStr, 10, 64); err != nil || mid <= 0 {
  222. c.JSON(nil, ecode.RequestErr)
  223. return
  224. }
  225. if pid, err = strconv.ParseInt(pidStr, 10, 64); err != nil || pid <= 0 {
  226. c.JSON(nil, ecode.RequestErr)
  227. return
  228. }
  229. if expires, err = strconv.ParseInt(expiresStr, 10, 64); err != nil || expires < 1 {
  230. c.JSON(nil, ecode.RequestErr)
  231. return
  232. }
  233. if tp, err = strconv.ParseInt(typeStr, 10, 64); err != nil || tp < 0 {
  234. c.JSON(nil, ecode.RequestErr)
  235. return
  236. }
  237. if orderData, err = usersuitSvc.OrderPendant(c, mid, pid, expires, tp); err != nil {
  238. c.JSON(nil, err)
  239. return
  240. }
  241. if orderData != nil && orderData.PayURL != "" {
  242. c.JSON(orderData, nil)
  243. }
  244. }
  245. // multiGrant batch grant pendant
  246. func multiGrantByMid(c *bm.Context) {
  247. var (
  248. err error
  249. pid, expire int64
  250. mids []int64
  251. req = c.Request
  252. params = req.Form
  253. midStr = params.Get("mids")
  254. pidStr = params.Get("pid")
  255. expireStr = params.Get("expire")
  256. )
  257. if midStr == "" || pidStr == "" || expireStr == "" {
  258. c.JSON(nil, ecode.RequestErr)
  259. return
  260. }
  261. if mids, err = xstr.SplitInts(midStr); err != nil || len(mids) == 0 {
  262. c.JSON(nil, ecode.RequestErr)
  263. return
  264. }
  265. if pid, err = strconv.ParseInt(pidStr, 10, 64); err != nil || pid <= 0 {
  266. c.JSON(nil, ecode.RequestErr)
  267. return
  268. }
  269. if expire, err = strconv.ParseInt(expireStr, 10, 64); err != nil || expire <= 0 || expire > 3650 {
  270. c.JSON(nil, ecode.RequestErr)
  271. return
  272. }
  273. c.JSON(nil, usersuitSvc.BatchGrantPendantByMid(c, pid, expire, mids))
  274. }
  275. // multiGrant batch grant pendant
  276. func multiGrantByPid(c *bm.Context) {
  277. var (
  278. err error
  279. mid int64
  280. pids, expires []int64
  281. req = c.Request
  282. params = req.Form
  283. midStr = params.Get("mid")
  284. pidStr = params.Get("pids")
  285. expireStr = params.Get("expires")
  286. )
  287. if midStr == "" || pidStr == "" || expireStr == "" {
  288. c.JSON(nil, ecode.RequestErr)
  289. return
  290. }
  291. if pids, err = xstr.SplitInts(pidStr); err != nil || len(pids) == 0 {
  292. c.JSON(nil, ecode.RequestErr)
  293. return
  294. }
  295. if mid, err = strconv.ParseInt(midStr, 10, 64); err != nil || mid <= 0 {
  296. c.JSON(nil, ecode.RequestErr)
  297. return
  298. }
  299. if expires, err = xstr.SplitInts(expireStr); err != nil {
  300. c.JSON(nil, ecode.RequestErr)
  301. return
  302. }
  303. c.JSON(nil, usersuitSvc.BatchGrantPendantByPid(c, mid, expires, pids))
  304. }
  305. // equip euqip pendant
  306. func equip(c *bm.Context) {
  307. var (
  308. err error
  309. mid, pid, status, source int64
  310. req = c.Request
  311. params = req.Form
  312. midStr = params.Get("mid")
  313. pidStr = params.Get("pid")
  314. statusStr = params.Get("status")
  315. sourceStr = params.Get("source") // 挂件来源(可选):默认0,0 未知,1背包,2大会员
  316. )
  317. if midStr == "" || pidStr == "" || statusStr == "" {
  318. c.JSON(nil, ecode.RequestErr)
  319. return
  320. }
  321. if mid, err = strconv.ParseInt(midStr, 10, 64); err != nil || mid <= 0 {
  322. c.JSON(nil, ecode.RequestErr)
  323. return
  324. }
  325. if pid, err = strconv.ParseInt(pidStr, 10, 64); err != nil || pid <= 0 {
  326. c.JSON(nil, ecode.RequestErr)
  327. return
  328. }
  329. if status, err = strconv.ParseInt(statusStr, 10, 64); err != nil || (status != 1 && status != 2) {
  330. c.JSON(nil, ecode.RequestErr)
  331. return
  332. }
  333. source = model.ParseSource(sourceStr)
  334. c.JSON(nil, usersuitSvc.EquipPendant(c, mid, pid, int8(status), source))
  335. }
  336. // pendantCallback pay callback func
  337. func pendantCallback(c *bm.Context) {
  338. var (
  339. err error
  340. sFlag int64
  341. arg *model.PendantOrderInfo
  342. req = c.Request
  343. params = req.Form
  344. success = params.Get("isSuccess") // NOTE : how to fixed 1
  345. orderID = params.Get("out_trade_no")
  346. payID = params.Get("trade_no")
  347. status = params.Get("trade_status")
  348. )
  349. if success == "" || orderID == "" || payID == "" || status == "" {
  350. c.JSON(nil, ecode.RequestErr)
  351. return
  352. }
  353. if status != _paySuccess {
  354. c.JSON(nil, nil)
  355. return
  356. }
  357. arg = &model.PendantOrderInfo{OrderID: orderID, PayID: payID}
  358. if sFlag, err = strconv.ParseInt(status, 10, 64); err != nil {
  359. c.JSON(nil, ecode.RequestErr)
  360. return
  361. }
  362. arg.Stauts = int32(sFlag)
  363. arg.IsCallback = 1
  364. c.JSON(nil, usersuitSvc.PendantCallback(c, arg))
  365. }