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.
104 lines
2.7 KiB
104 lines
2.7 KiB
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"
|
|
|
|
"github.com/ouxuanserver/osmanthuswine/src/core"
|
|
)
|
|
|
|
//打赏
|
|
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.GetById(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.GetById(user, uid)
|
|
t.CheckErr(err)
|
|
t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
|
|
|
|
var res = make(map[string]interface{}, 0)
|
|
res["out_trade_no"] = ""
|
|
if activity.RehearsalId == 0 || _type == 1 { // 直播不用彩排
|
|
res, err = pay_service.UnifiedOrder("欧轩互动-打赏支付", user.Openid, int64(amount*100), 2, user.Id, activityId)
|
|
t.CheckErr(err)
|
|
}
|
|
|
|
_, err = core.GetXormAuto().InsertOne(&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,
|
|
IsDelete: false,
|
|
CreatedAt: time.Now(),
|
|
UpdatedAt: time.Now(),
|
|
})
|
|
t.CheckErr(err)
|
|
|
|
res["rehearsal_id"] = activity.RehearsalId
|
|
t.JSON(res)
|
|
}
|
|
|
|
func (t *RewardCtl) List() {
|
|
uid := t.MustGetUID()
|
|
activityId := t.MustGetInt64("activity_id")
|
|
|
|
rs := new(models.RewardServer)
|
|
exist, err := rs.GetByActivityId(activityId)
|
|
t.CheckErr(err)
|
|
t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
|
|
|
|
// todo: 检查订单
|
|
t.CheckErr(bully_reward_service.CheckRewardStatus(rs.Id))
|
|
|
|
list, err := bully_reward_service.GetRewardList(uid, rs.Id)
|
|
t.CheckErr(err)
|
|
t.JSON(map[string]interface{}{
|
|
"total": len(list),
|
|
"list": list,
|
|
})
|
|
}
|