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

104 lines
2.7 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
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_reward_service "hudongzhuanjia/services/bully_reward"
  7. pay_service "hudongzhuanjia/services/pay"
  8. "hudongzhuanjia/utils"
  9. "hudongzhuanjia/utils/code"
  10. "time"
  11. "github.com/ouxuanserver/osmanthuswine/src/core"
  12. )
  13. //打赏
  14. type RewardCtl struct {
  15. controllers.AuthorCtl
  16. }
  17. func (t *RewardCtl) Reward() {
  18. activityId := t.MustGetInt64("activity_id")
  19. content := t.MustGet("content")
  20. amount := t.MustGetDouble("amount")
  21. uid := t.MustGetUID()
  22. _type := t.DefaultInt("type", 0)
  23. if amount <= 0 {
  24. t.ERROR("打赏金额不能小于0", code.MSG_ERR_Param)
  25. return
  26. }
  27. //检查内容是否包含敏感
  28. if ok, _ := filter.Validate(content); !ok {
  29. t.ERROR("内容包含敏感字", code.MSG_ERR)
  30. return
  31. }
  32. activity := new(models.Activity)
  33. exist, err := models.GetById(activity, activityId)
  34. t.CheckErr(err)
  35. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  36. //查询该活动的的打赏服务id
  37. rewardServer := new(models.RewardServer)
  38. exist, err = rewardServer.GetByActivityId(activityId)
  39. t.CheckErr(err)
  40. t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
  41. amount = utils.Float64CusDecimal(amount, 2)
  42. //查询用户信息
  43. user := new(models.User)
  44. exist, err = models.GetById(user, uid)
  45. t.CheckErr(err)
  46. t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
  47. var res = make(map[string]interface{}, 0)
  48. res["out_trade_no"] = ""
  49. if activity.RehearsalId == 0 || _type == 1 { // 直播不用彩排
  50. res, err = pay_service.UnifiedOrder("欧轩互动-打赏支付", user.Openid, int64(amount*100), 2, user.Id, activityId)
  51. t.CheckErr(err)
  52. }
  53. _, err = core.GetXormAuto().InsertOne(&models.RewardHistory{
  54. OutTradeNo: res["out_trade_no"].(string),
  55. ActivityId: activityId,
  56. RewardServerId: rewardServer.Id,
  57. CustomerId: activity.CustomerId,
  58. UserId: user.Id,
  59. Amount: amount,
  60. Content: content,
  61. RehearsalId: activity.RehearsalId,
  62. Status: -1,
  63. ReviewTime: 0,
  64. IsDelete: false,
  65. CreatedAt: time.Now(),
  66. UpdatedAt: time.Now(),
  67. })
  68. t.CheckErr(err)
  69. res["rehearsal_id"] = activity.RehearsalId
  70. t.JSON(res)
  71. }
  72. func (t *RewardCtl) List() {
  73. uid := t.MustGetUID()
  74. activityId := t.MustGetInt64("activity_id")
  75. rs := new(models.RewardServer)
  76. exist, err := rs.GetByActivityId(activityId)
  77. t.CheckErr(err)
  78. t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
  79. // todo: 检查订单
  80. t.CheckErr(bully_reward_service.CheckRewardStatus(rs.Id))
  81. list, err := bully_reward_service.GetRewardList(uid, rs.Id)
  82. t.CheckErr(err)
  83. t.JSON(map[string]interface{}{
  84. "total": len(list),
  85. "list": list,
  86. })
  87. }