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.
188 lines
4.9 KiB
188 lines
4.9 KiB
package pc
|
|
|
|
import (
|
|
"fmt"
|
|
"hudongzhuanjia/controllers"
|
|
"hudongzhuanjia/models"
|
|
bully_reward_service "hudongzhuanjia/services/bully_reward"
|
|
im_service "hudongzhuanjia/services/im"
|
|
"hudongzhuanjia/services/pay"
|
|
"hudongzhuanjia/utils"
|
|
"hudongzhuanjia/utils/code"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
type RewardCtl struct {
|
|
controllers.AuthorCtl
|
|
}
|
|
|
|
//获取最新的打赏记录
|
|
func (t *RewardCtl) Latest() {
|
|
activityId := t.MustGetInt64("activity_id")
|
|
rehearsalId := t.MustGetInt64("rehearsal_id")
|
|
|
|
//获取打赏服务得id
|
|
server := new(models.RewardServer)
|
|
exist, err := server.GetByActivityId(activityId)
|
|
t.CheckErr(err)
|
|
t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
|
|
|
|
result, err := bully_reward_service.GetRewardLatest(server.Id, rehearsalId)
|
|
t.CheckErr(err)
|
|
if result == nil || result.Id == 0 {
|
|
t.JSON(result)
|
|
}
|
|
|
|
result.User.Openid = ""
|
|
result.User.Unionid = ""
|
|
result.RewardHistory.RewardAmount = fmt.Sprintf("%.2f", result.RewardHistory.Amount)
|
|
t.CheckErr(models.Save(map[string]interface{}{
|
|
"id=": result.RewardHistory.Id,
|
|
}, &models.RewardHistory{
|
|
Status: 3,
|
|
UpdatedAt: time.Now(),
|
|
}, "status", "update_at"))
|
|
t.JSON(result)
|
|
}
|
|
|
|
//获取待审核列表
|
|
func (t *RewardCtl) WaitReview() {
|
|
activityId := t.MustGetInt64("activity_id")
|
|
rehearsalId := t.MustGetInt64("rehearsal_id")
|
|
|
|
//获取打赏服务得id
|
|
server := new(models.RewardServer)
|
|
exist, err := server.GetByActivityId(activityId)
|
|
t.CheckErr(err)
|
|
t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
|
|
|
|
//// todo: 检查订单
|
|
//t.CheckErr(bully_reward_service.CheckRewardStatus(server.Id))
|
|
|
|
result, err := bully_reward_service.GetRewardReview(server.Id, rehearsalId)
|
|
t.CheckErr(err)
|
|
//根据打赏服务得id获取待审核得打赏列表
|
|
|
|
t.JSON(map[string]interface{}{
|
|
"total": len(result),
|
|
"list": result,
|
|
})
|
|
}
|
|
|
|
//审核
|
|
func (t *RewardCtl) Review() {
|
|
status := t.MustGetBool("status")
|
|
ids := strings.Split(t.MustGet("ids"), "|")
|
|
uid := t.MustGetUID()
|
|
|
|
result, err := models.GetRewardHistoryByIds(ids)
|
|
t.CheckErr(err)
|
|
|
|
// 审核
|
|
for _, v := range result {
|
|
if status { // false 通过 , true 不通过
|
|
v.Status = 1
|
|
_, err = models.Update(v.Id, v, "status")
|
|
t.CheckErr(err)
|
|
|
|
if v.RehearsalId != 0 && v.Type == 0 { // 彩排不需要金额
|
|
continue
|
|
}
|
|
|
|
_, err = pay_service.Refund("欧轩互动-打赏敏感关键字拉黑", v.OutTradeNo)
|
|
t.CheckErr(err)
|
|
|
|
} else {
|
|
//增加客户的金额
|
|
v.Status = 2
|
|
_, err = models.Update(v.Id, v, "status")
|
|
t.CheckErr(err)
|
|
|
|
if v.RehearsalId != 0 && v.Type == 0 { // 线下h5彩排不需要金额
|
|
continue
|
|
}
|
|
|
|
go im_service.SendGroupCustomMessage(v.UserId, v.ActivityId, im_service.NoticeReward,
|
|
map[string]interface{}{
|
|
"amount": v.Amount,
|
|
"content": v.Content,
|
|
})
|
|
|
|
wallet := new(models.RewardWallet)
|
|
_, err = wallet.IncrBalance(uid, v.Amount)
|
|
t.CheckErr(err)
|
|
history := models.RewardWalletHistory{
|
|
CustomerId: uid,
|
|
Money: v.Amount,
|
|
Type: "打赏",
|
|
UserId: v.UserId,
|
|
RewardHistoryId: v.Id,
|
|
RewardAccount: v.RewardAmount,
|
|
Status: "交易成功",
|
|
Mark: "打赏金额",
|
|
}
|
|
_, err = models.Add(history)
|
|
t.CheckErr(err)
|
|
}
|
|
}
|
|
// 发送审核的信息
|
|
t.JSON("审核成功")
|
|
}
|
|
|
|
//获取打赏得总金额
|
|
func (t *RewardCtl) Amount() {
|
|
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, "互动不存在")
|
|
//获取打赏服务得id
|
|
server := new(models.RewardServer)
|
|
exist, err = server.GetByActivityId(activityId)
|
|
t.CheckErr(err)
|
|
t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
|
|
|
|
totalAmount, err := new(models.RewardHistory).SumMoney(server.Id, activity.RehearsalId)
|
|
t.CheckErr(err)
|
|
|
|
t.DisplayByData(map[string]interface{}{
|
|
"amount": utils.Float64CusDecimal(totalAmount, 2),
|
|
})
|
|
}
|
|
|
|
// 黑名单
|
|
func (t *RewardCtl) Blacklist() {
|
|
activityId := t.MustGetInt64("activity_id")
|
|
rehearsalId := t.MustGetInt64("rehearsal_id")
|
|
// 获取打赏的服务id
|
|
server := new(models.RewardServer)
|
|
exist, err := server.GetByActivityId(activityId)
|
|
t.CheckErr(err)
|
|
t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
|
|
|
|
// 根据打赏服务id获取待审核的名单
|
|
// status=true 代表审核不通过还是通过
|
|
// 目前表示不通过,bully_screen也一样
|
|
result, err := bully_reward_service.GetRewardBlacklist(server.Id, rehearsalId)
|
|
t.CheckErr(err)
|
|
|
|
t.JSON(map[string]interface{}{
|
|
"total": len(result),
|
|
"list": result,
|
|
})
|
|
}
|
|
|
|
// 开启打赏
|
|
func (t *RewardCtl) Details() {
|
|
activityId := t.MustGetInt64("activity_id")
|
|
server := new(models.RewardServer)
|
|
exist, err := server.GetByActivityId(activityId)
|
|
t.CheckErr(err)
|
|
t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
|
|
|
|
t.JSON(map[string]interface{}{
|
|
"server": server,
|
|
})
|
|
}
|