互动
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.

107 lines
3.0 KiB

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