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

97 lines
2.5 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
  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. "strings"
  11. "time"
  12. "github.com/ouxuanserver/osmanthuswine/src/core"
  13. )
  14. //打赏
  15. type RewardCtl struct {
  16. controllers.AuthorCtl
  17. }
  18. func (t *RewardCtl) Reward() {
  19. activityId := t.MustGetInt64("activity_id")
  20. content := t.MustGet("content")
  21. amount := t.MustGetDouble("amount")
  22. uid := t.MustGetUID()
  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. ip := strings.Split(t.Request.OriginRequest.RemoteAddr, ":")
  48. res, err := pay_service.UnifiedOrder("欧轩互动-打赏支付", ip[0], user.Openid, int64(amount*100), 2, user.Id, activityId)
  49. t.CheckErr(err)
  50. _, err = core.GetXormAuto().InsertOne(&models.RewardHistory{
  51. OutTradeNo: res["out_trade_no"].(string),
  52. RewardServerId: rewardServer.Id,
  53. CustomerId: t.MustGetCustomerId(),
  54. UserId: user.Id,
  55. Amount: amount,
  56. Content: content,
  57. RehearsalId: activity.RehearsalId,
  58. Status: -1,
  59. ReviewTime: 0,
  60. IsDelete: false,
  61. CreatedAt: time.Now(),
  62. UpdatedAt: time.Now(),
  63. })
  64. t.CheckErr(err)
  65. t.JSON(res)
  66. }
  67. func (t *RewardCtl) List() {
  68. uid := t.MustGetUID()
  69. activityId := t.MustGetInt64("activity_id")
  70. rs := new(models.RewardServer)
  71. exist, err := rs.GetByActivityId(activityId)
  72. t.CheckErr(err)
  73. t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
  74. // todo: 检查订单
  75. t.CheckErr(bully_reward_service.CheckRewardStatus(rs.Id))
  76. list, err := bully_reward_service.GetRewardList(uid, rs.Id)
  77. t.CheckErr(err)
  78. t.JSON(map[string]interface{}{
  79. "total": len(list),
  80. "list": list,
  81. })
  82. }