互动
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
2.9 KiB

5 years ago
  1. package client
  2. import (
  3. "hudongzhuanjia/controllers"
  4. "hudongzhuanjia/models"
  5. bully_screen_service "hudongzhuanjia/services/bully_screen"
  6. "hudongzhuanjia/services/pay"
  7. "hudongzhuanjia/utils/code"
  8. "strings"
  9. "time"
  10. "github.com/ouxuanserver/osmanthuswine/src/core"
  11. )
  12. //霸屏
  13. type BullyScreenCtl struct {
  14. controllers.AuthorCtl
  15. }
  16. //用户霸屏
  17. // todo: 支付接口
  18. func (t *BullyScreenCtl) PaScreen() {
  19. activityId := t.MustGetActivityId()
  20. uid := t.MustGetUID()
  21. content := t.MustGet("content")
  22. second := t.MustGetDouble("second")
  23. style := t.MustGetInt("style")
  24. activity := new(models.Activity)
  25. exist, err := models.GetById(activity, activityId)
  26. t.CheckErr(err)
  27. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  28. t.CheckRunning(activity.Status)
  29. //检查内容是否包含敏感
  30. if models.IsSensitive(content) {
  31. t.ERROR("内容包含敏感字", code.MSG_ERR)
  32. }
  33. //查询该活动的的霸屏服务id
  34. bullyScreenServer := new(models.BullyScreenServer)
  35. exist, err = bullyScreenServer.GetByActivityId(activityId)
  36. t.CheckErr(err)
  37. t.Assert(exist, code.MSG_BULLY_SCREEN_SERVER_NOT_EXIST, "霸屏不存在")
  38. //查询用户信息
  39. user := new(models.User)
  40. exist, err = models.GetById(user, uid)
  41. t.CheckErr(err)
  42. t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
  43. //扣除用户的金额
  44. // todo:微信直接付款
  45. // 调用微信统一下单接口
  46. amount := bullyScreenServer.Price * second
  47. ip := strings.Split(t.Request.OriginRequest.RemoteAddr, ":")
  48. res, err := pay_service.Order("欧轩互动-霸屏支付", ip[0], user.Openid, int(amount*100), 1, user.Id, activityId)
  49. t.CheckErr(err)
  50. history := &models.BullyScreenHistory{
  51. UserOrderId: res["user_order_id"].(int64),
  52. BullyScreenServerId: bullyScreenServer.Id,
  53. ActivityId: activityId,
  54. UserId: user.Id,
  55. Nickname: user.Nickname,
  56. CustomerId: t.MustGetCustomerId(),
  57. RehearsalId: activity.RehearsalId,
  58. Second: int(second),
  59. Amount: amount,
  60. Style: style,
  61. ReviewTime: 0,
  62. Status: -1,
  63. Content: content,
  64. IsDelete: false,
  65. CreatedAt: time.Now(),
  66. UpdatedAt: time.Now(),
  67. }
  68. _, err = core.GetXormAuto().InsertOne(history)
  69. t.CheckErr(err)
  70. delete(res, "out_trade_no")
  71. delete(res, "user_order_id")
  72. t.JSON(res)
  73. }
  74. // 审核列表 [未审核,未通过,已通过]
  75. func (t *BullyScreenCtl) List() {
  76. uid := t.MustGetUID()
  77. activityId := t.MustGetActivityId()
  78. bss := new(models.BullyScreenServer)
  79. exist, err := bss.GetByActivityId(activityId)
  80. t.CheckErr(err)
  81. t.Assert(exist, code.MSG_BULLY_SCREEN_SERVER_NOT_EXIST, "霸屏不存在")
  82. // 查询是否已经付款
  83. t.CheckErr(pay_service.BatchQueryByUserId(uid))
  84. t.CheckErr(pay_service.BatchQueryRefundByUserId(uid))
  85. list, err := bully_screen_service.GetReviewList(uid, bss.Id)
  86. t.CheckErr(err)
  87. t.JSON(map[string]interface{}{
  88. "total": len(list),
  89. "list": list,
  90. })
  91. }