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

106 lines
2.9 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. 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. // todo: 支付接口
  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. }
  26. //检查内容是否包含敏感
  27. //if models.IsSensitive(content) {
  28. // t.ERROR("内容包含敏感字", code.MSG_ERR)
  29. //}
  30. content = filter.Replace(content)
  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. ip := strings.Split(t.Request.OriginRequest.RemoteAddr, ":")
  47. res, err := pay_service.Order("欧轩互动-打赏支付", ip[0], user.Openid, int(amount*100), 2, user.Id, activityId)
  48. t.CheckErr(err)
  49. _, err = core.GetXormAuto().InsertOne(&models.RewardHistory{
  50. UserOrderId: res["user_order_id"].(int64),
  51. RewardServerId: rewardServer.Id,
  52. CustomerId: t.MustGetCustomerId(),
  53. UserId: user.Id,
  54. Amount: amount,
  55. Content: content,
  56. RehearsalId: activity.RehearsalId,
  57. Status: -1,
  58. ReviewTime: 0,
  59. IsDelete: false,
  60. CreatedAt: time.Now(),
  61. UpdatedAt: time.Now(),
  62. })
  63. t.CheckErr(err)
  64. delete(res, "user_order_id")
  65. delete(res, "out_trade_no")
  66. t.JSON(res)
  67. }
  68. type RWListResult struct {
  69. Id int64 `json:"id"`
  70. Content string `json:"content"`
  71. Amount float64 `json:"amount"`
  72. Status int `json:"status"`
  73. }
  74. func (t *RewardCtl) List() {
  75. uid := t.MustGetUID()
  76. activityId := t.MustGetActivityId()
  77. rs := new(models.RewardServer)
  78. exist, err := rs.GetByActivityId(activityId)
  79. t.CheckErr(err)
  80. t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
  81. t.CheckErr(pay_service.BatchQueryByUserId(uid))
  82. t.CheckErr(pay_service.BatchQueryRefundByUserId(uid))
  83. list := make([]*RWListResult, 0)
  84. err = core.GetXormAuto().Table(new(models.RewardHistory)).Select("id, content, amount, status").
  85. Where("is_delete=0 and user_id=? and reward_server_id=? and status <> -1", uid, rs.Id).
  86. Desc("created_at").Find(&list)
  87. t.CheckErr(err)
  88. t.JSON(map[string]interface{}{
  89. "total": len(list),
  90. "list": list,
  91. })
  92. }