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

209 lines
5.5 KiB

package pc
import (
"fmt"
"hudongzhuanjia/controllers"
"hudongzhuanjia/libs/im"
"hudongzhuanjia/models"
bully_reward_service "hudongzhuanjia/services/bully_reward"
im_service "hudongzhuanjia/services/im"
"hudongzhuanjia/services/pay"
"hudongzhuanjia/utils"
"hudongzhuanjia/utils/code"
"strings"
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
)
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.RAW(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.RAW(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() {
// todo: false 代表通过, true 代表不通过
idList := t.MustGet("ids")
status := t.MustGetBool("status")
ids := strings.Split(idList, "|")
rehearsalId := t.MustGetInt64("rehearsal_id")
result := make([]*models.RewardHistory, 0)
err := core.GetXormAuto().Where("is_delete=0").In("id", ids).Find(&result)
t.CheckErr(err)
// 审核
for _, v := range result {
if v.Status != 0 {
t.ERROR("该打赏已处理", code.MSG_USER_DATA_ERROR)
}
if status { // false 通过 , true 不通过
// 回退金额给用户
// 应该微信退款
_, err = v.UpdateStatus(v.Id, 1)
t.CheckErr(err)
if rehearsalId != 0 { // 彩排不需要金额
continue
}
_, err = pay_service.Refund("欧轩互动-打赏拉黑", v.OutTradeNo)
t.CheckErr(err)
} else {
var exist bool
//增加客户的金额
_, err = v.UpdateStatus(v.Id, 2)
t.CheckErr(err)
user := new(models.User)
exist, err = models.GetById(user, v.UserId)
t.CheckErr(err)
t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
go im_service.SendGroupCustomMessage(fmt.Sprint(user.Id), v.ActivityId, im.NoticeReward,
map[string]interface{}{
"amount": v.Amount,
"content": v.Content,
})
if rehearsalId != 0 { // 彩排不需要金额
continue
}
uid := t.MustGetUID()
customer := new(models.Customer)
exist, err = models.GetById(customer, uid)
t.CheckErr(err)
t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
wallet := new(models.RewardWallet)
_, err = wallet.IncrBalance(uid, v.Amount)
t.CheckErr(err)
_, err = core.GetXormAuto().InsertOne(&models.RewardWalletHistory{
CustomerId: uid,
Money: v.Amount,
Type: "打赏",
UserId: v.UserId,
RewardHistoryId: v.Id,
RewardAccount: v.RewardAmount,
Status: "交易成功",
Mark: "打赏金额",
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
})
t.CheckErr(err)
}
}
// 发送审核的信息
t.RAW("审核成功")
}
//获取打赏得总金额
func (t *RewardCtl) Amount() {
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, "打赏不存在")
totalAmount, err := core.GetXormAuto().Where("reward_server_id=? and status=3 and is_delete=0 "+
" and rehearsal_id=?", server.Id, rehearsalId).Sum(new(models.RewardHistory), "amount")
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,
})
}