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

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