|
|
package client
import ( "hudongzhuanjia/controllers" "hudongzhuanjia/libs/filter" "hudongzhuanjia/models" bully_reward_service "hudongzhuanjia/services/bully_reward" pay_service "hudongzhuanjia/services/pay" "hudongzhuanjia/utils" "hudongzhuanjia/utils/code" "time" )
//打赏
type RewardCtl struct { controllers.AuthorCtl }
func (t *RewardCtl) Reward() { activityId := t.MustGetInt64("activity_id") content := t.MustGet("content") amount := t.MustGetDouble("amount") uid := t.MustGetUID() _type := t.DefaultInt("type", 0)
if amount <= 0 { t.ERROR("打赏金额不能小于0", code.MSG_ERR_Param) return }
//检查内容是否包含敏感
if ok, _ := filter.Validate(content); !ok { t.ERROR("内容包含敏感字", code.MSG_ERR) return }
activity := new(models.Activity) exist, err := models.Get(activity, activityId) t.CheckErr(err) t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
//查询该活动的的打赏服务id
rewardServer := new(models.RewardServer) exist, err = rewardServer.GetByActivityId(activityId) t.CheckErr(err) t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
amount = utils.Float64CusDecimal(amount, 2)
//查询用户信息
user := new(models.User) exist, err = models.Get(user, uid) t.CheckErr(err) t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
var res = make(map[string]interface{}, 0) var expireAt = time.Now().Add(24 * time.Hour).Unix() res["out_trade_no"] = "" if activity.RehearsalId == 0 || _type == 1 { // 直播不用彩排
res, err = pay_service.UnifiedOrder("欧轩互动-打赏支付", user.Openid, int64(amount*100), 2, user.Id, activityId, expireAt) t.CheckErr(err) }
history := models.RewardHistory{ OutTradeNo: res["out_trade_no"].(string), ActivityId: activityId, RewardServerId: rewardServer.Id, CustomerId: activity.CustomerId, UserId: user.Id, Amount: amount, Content: content, RehearsalId: activity.RehearsalId, Status: -1, ReviewTime: 0, ExpireTime: expireAt, Type: _type, }
if activity.RehearsalId != 0 && _type == 0 { // 线下h5彩排不需要支付
history.Status = 0 }
_, err = models.Add(&history) t.CheckErr(err)
res["rehearsal_id"] = activity.RehearsalId t.JSON(res) }
func (t *RewardCtl) List() { uid := t.MustGetUID() activityId := t.MustGetInt64("activity_id")
activity := new(models.Activity) exist, err := models.Get(activity, activityId) t.CheckErr(err) t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
rs := new(models.RewardServer) exist, err = rs.GetByActivityId(activityId) t.CheckErr(err) t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
list, err := bully_reward_service.GetRewardList(uid, activity.RehearsalId, rs.Id) t.CheckErr(err) t.JSON(map[string]interface{}{ "total": len(list), "list": list, }) }
|