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
106 lines
2.9 KiB
package client
|
|
|
|
import (
|
|
"hudongzhuanjia/controllers"
|
|
"hudongzhuanjia/libs/filter"
|
|
"hudongzhuanjia/models"
|
|
pay_service "hudongzhuanjia/services/pay"
|
|
"hudongzhuanjia/utils"
|
|
"hudongzhuanjia/utils/code"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/ouxuanserver/osmanthuswine/src/core"
|
|
)
|
|
|
|
//打赏
|
|
type RewardCtl struct {
|
|
controllers.AuthorCtl
|
|
}
|
|
|
|
// todo: 支付接口
|
|
func (t *RewardCtl) Reward() {
|
|
activityId := t.MustGetInt64("activity_id")
|
|
content := t.MustGet("content")
|
|
amount := t.MustGetDouble("amount")
|
|
uid := t.MustGetUID()
|
|
if amount <= 0 {
|
|
t.ERROR("打赏金额不能小于0", code.MSG_ERR_Param)
|
|
}
|
|
//检查内容是否包含敏感
|
|
//if models.IsSensitive(content) {
|
|
// t.ERROR("内容包含敏感字", code.MSG_ERR)
|
|
//}
|
|
content = filter.Replace(content)
|
|
|
|
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, "用户不存在")
|
|
|
|
ip := strings.Split(t.Request.OriginRequest.RemoteAddr, ":")
|
|
res, err := pay_service.Order("欧轩互动-打赏支付", ip[0], user.Openid, int(amount*100), 2, user.Id, activityId)
|
|
t.CheckErr(err)
|
|
|
|
_, err = core.GetXormAuto().InsertOne(&models.RewardHistory{
|
|
UserOrderId: res["user_order_id"].(int64),
|
|
RewardServerId: rewardServer.Id,
|
|
CustomerId: t.MustGetCustomerId(),
|
|
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)
|
|
delete(res, "user_order_id")
|
|
delete(res, "out_trade_no")
|
|
t.JSON(res)
|
|
}
|
|
|
|
type RWListResult struct {
|
|
Id int64 `json:"id"`
|
|
Content string `json:"content"`
|
|
Amount float64 `json:"amount"`
|
|
Status int `json:"status"`
|
|
}
|
|
|
|
func (t *RewardCtl) List() {
|
|
uid := t.MustGetUID()
|
|
activityId := t.MustGetActivityId()
|
|
|
|
rs := new(models.RewardServer)
|
|
exist, err := rs.GetByActivityId(activityId)
|
|
t.CheckErr(err)
|
|
t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
|
|
|
|
t.CheckErr(pay_service.BatchQueryByUserId(uid))
|
|
t.CheckErr(pay_service.BatchQueryRefundByUserId(uid))
|
|
|
|
list := make([]*RWListResult, 0)
|
|
err = core.GetXormAuto().Table(new(models.RewardHistory)).Select("id, content, amount, status").
|
|
Where("is_delete=0 and user_id=? and reward_server_id=? and status <> -1", uid, rs.Id).
|
|
Desc("created_at").Find(&list)
|
|
t.CheckErr(err)
|
|
t.JSON(map[string]interface{}{
|
|
"total": len(list),
|
|
"list": list,
|
|
})
|
|
}
|