互动
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
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. pay_service "hudongzhuanjia/services/pay"
  7. "hudongzhuanjia/utils"
  8. "hudongzhuanjia/utils/code"
  9. "strings"
  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. }
  25. //检查内容是否包含敏感
  26. if ok, _ := filter.Validate(content); !ok {
  27. t.ERROR("内容包含敏感字", code.MSG_ERR)
  28. }
  29. activity := new(models.Activity)
  30. exist, err := models.GetById(activity, activityId)
  31. t.CheckErr(err)
  32. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  33. //查询该活动的的打赏服务id
  34. rewardServer := new(models.RewardServer)
  35. exist, err = rewardServer.GetByActivityId(activityId)
  36. t.CheckErr(err)
  37. t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
  38. amount = utils.Float64CusDecimal(amount, 2)
  39. //查询用户信息
  40. user := new(models.User)
  41. exist, err = models.GetById(user, uid)
  42. t.CheckErr(err)
  43. t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
  44. ip := strings.Split(t.Request.OriginRequest.RemoteAddr, ":")
  45. res, err := pay_service.Order("欧轩互动-打赏支付", ip[0], user.Openid, int(amount*100), 2, user.Id, activityId)
  46. t.CheckErr(err)
  47. _, err = core.GetXormAuto().InsertOne(&models.RewardHistory{
  48. UserOrderId: res["user_order_id"].(int64),
  49. RewardServerId: rewardServer.Id,
  50. CustomerId: t.MustGetCustomerId(),
  51. UserId: user.Id,
  52. Amount: amount,
  53. Content: content,
  54. RehearsalId: activity.RehearsalId,
  55. Status: -1,
  56. ReviewTime: 0,
  57. IsDelete: false,
  58. CreatedAt: time.Now(),
  59. UpdatedAt: time.Now(),
  60. })
  61. t.CheckErr(err)
  62. delete(res, "user_order_id")
  63. delete(res, "out_trade_no")
  64. t.JSON(res)
  65. }
  66. type RWListResult struct {
  67. Id int64 `json:"id"`
  68. Content string `json:"content"`
  69. Amount float64 `json:"amount"`
  70. Status int `json:"status"`
  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. t.CheckErr(pay_service.BatchQueryByUserId(uid))
  80. t.CheckErr(pay_service.BatchQueryRefundByUserId(uid))
  81. list := make([]*RWListResult, 0)
  82. err = core.GetXormAuto().Table(new(models.RewardHistory)).Select("id, content, amount, status").
  83. Where("is_delete=0 and user_id=? and reward_server_id=? and status <> -1", uid, rs.Id).
  84. Desc("created_at").Find(&list)
  85. t.CheckErr(err)
  86. t.JSON(map[string]interface{}{
  87. "total": len(list),
  88. "list": list,
  89. })
  90. }