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.
242 lines
7.6 KiB
242 lines
7.6 KiB
package pc
|
|
|
|
import (
|
|
"hudongzhuanjia/controllers"
|
|
"hudongzhuanjia/models"
|
|
"hudongzhuanjia/services/pay"
|
|
"hudongzhuanjia/utils"
|
|
"hudongzhuanjia/utils/code"
|
|
"hudongzhuanjia/utils/define"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/ouxuanserver/osmanthuswine/src/core"
|
|
)
|
|
|
|
type BullyScreenCtl struct {
|
|
controllers.AuthorCtl
|
|
}
|
|
|
|
type BullyScreenBaseResult struct {
|
|
models.BullyScreenHistory `xorm:"extends"`
|
|
User *models.User `json:"user" xorm:"extends"`
|
|
}
|
|
|
|
//获取待审核列表
|
|
func (t *BullyScreenCtl) WaitReview() {
|
|
activityId := t.MustGetInt64("activity_id")
|
|
|
|
activity := new(models.Activity)
|
|
exist, err := models.GetById(activity, activityId)
|
|
t.CheckErr(err)
|
|
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
|
|
|
|
//获取霸屏服务得id
|
|
bullyScreenServer := new(models.BullyScreenServer)
|
|
exist, err = bullyScreenServer.GetByActivityId(activityId)
|
|
t.CheckErr(err)
|
|
t.Assert(exist, code.MSG_BULLY_SCREEN_SERVER_NOT_EXIST, "霸屏不存在")
|
|
|
|
t.CheckErr(pay_service.BatchQueryByActivityId(activityId))
|
|
t.CheckErr(pay_service.BatchQueryRefundByActivityId(activityId))
|
|
|
|
//根据霸屏服务得id获取待审核得霸屏列表
|
|
result := make([]*BullyScreenBaseResult, 0)
|
|
err = core.GetXormAuto().Table(new(models.BullyScreenHistory)).Alias("h").
|
|
Join("LEFT", "ox_user as u", "h.user_id=u.id and u.is_delete=0").
|
|
Where("h.bully_screen_server_id=? and h.is_delete=0 and h.status=0 and h.rehearsal_id=?",
|
|
bullyScreenServer.Id, activity.RehearsalId).Desc("h.created_at").Find(&result)
|
|
t.CheckErr(err)
|
|
|
|
t.JSON(map[string]interface{}{
|
|
"total": len(result),
|
|
"list": result,
|
|
})
|
|
}
|
|
|
|
//审核操作
|
|
func (t *BullyScreenCtl) Review() {
|
|
idList := t.MustGet("ids")
|
|
status := t.MustGetBool("status")
|
|
ids := strings.Split(idList, "|")
|
|
//rehearsalId := t.MustGetInt64("rehearsal_id")
|
|
|
|
//将金额退回给用户
|
|
result := make([]*models.BullyScreenHistory, 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 { // true 失败 、、 false 成功
|
|
_, err := v.UpdateStatus(v.Id, 1)
|
|
t.CheckErr(err)
|
|
|
|
//if rehearsalId != 0 { // 彩排
|
|
// continue
|
|
//}
|
|
|
|
//todo: 回退金额给用户 ==> 直接微信退款
|
|
// 1. 提请微信退款
|
|
// 2. 查询退款是否成功
|
|
// 3. 退款成功设置状态
|
|
// 4. 写入金额流水记录
|
|
order := new(models.UserOrder)
|
|
exist, err := models.GetById(order, v.UserOrderId)
|
|
t.CheckErr(err)
|
|
t.Assert(exist, code.MSG_USER_ORDER_NOT_EXIST, "用户支付订单不存在")
|
|
|
|
_, err = pay_service.Refund("欧轩互动-霸屏拉黑", order.OutTradeNo, order.OpenId, order.GoodType, order.TotalFee, order.TotalFee, order.UserId, order.ActivityId)
|
|
t.CheckErr(err)
|
|
|
|
} else {
|
|
_, err := v.UpdateStatus(v.Id, 2)
|
|
t.CheckErr(err)
|
|
// todo: 审核成功
|
|
// 1. 金额打入主账号的打赏钱包里面
|
|
// 2. 记录金额流水
|
|
|
|
//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.BullyScreenWallet)
|
|
_, err = wallet.IncrBalance(customer.Id, v.Amount)
|
|
t.CheckErr(err)
|
|
|
|
_, err = core.GetXormAuto().InsertOne(&models.BullyScreenWalletHistory{
|
|
CustomerId: customer.Id,
|
|
UserId: v.UserId,
|
|
Money: v.Amount,
|
|
Type: "霸屏",
|
|
Status: "交易成功",
|
|
Mark: "霸屏金额",
|
|
CreatedAt: time.Now(),
|
|
UpdatedAt: time.Now(),
|
|
})
|
|
t.CheckErr(err)
|
|
}
|
|
}
|
|
t.SUCCESS("审核成功")
|
|
}
|
|
|
|
//获取黑名单列表
|
|
func (t *BullyScreenCtl) Blacklist() {
|
|
activityId := t.MustGetInt64("activity_id")
|
|
|
|
activity := new(models.Activity)
|
|
exist, err := models.GetById(activity, activityId)
|
|
t.CheckErr(err)
|
|
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
|
|
|
|
//获取霸屏服务得id
|
|
bullyScreenServer := new(models.BullyScreenServer)
|
|
exist, err = bullyScreenServer.GetByActivityId(activityId)
|
|
t.CheckErr(err)
|
|
t.Assert(exist, code.MSG_BULLY_SCREEN_SERVER_NOT_EXIST, "霸屏活动不存在")
|
|
|
|
//根据霸屏服务得id获取待审核得霸屏列表
|
|
result := make([]*BullyScreenBaseResult, 0)
|
|
err = core.GetXormAuto().Table(new(models.BullyScreenHistory)).Alias("h").
|
|
Join("LEFT", new(models.User).Alias("u"), "u.id=h.user_id and u.is_delete=0").
|
|
Where("h.is_delete=0 and h.bully_screen_server_id=? and h.status=1 and h.rehearsal_id=?",
|
|
bullyScreenServer.Id, activity.RehearsalId).Desc("review_time").Find(&result)
|
|
t.CheckErr(err)
|
|
|
|
t.DisplayByData(map[string]interface{}{
|
|
"total": len(result),
|
|
"list": result,
|
|
})
|
|
}
|
|
|
|
//获取目前霸屏得总金额
|
|
func (t *BullyScreenCtl) Amount() {
|
|
activityId := t.MustGetInt64("activity_id")
|
|
rehearsalId := t.MustGetInt64("rehearsal_id")
|
|
|
|
//获取霸屏服务得id
|
|
bullyScreenServer := new(models.BullyScreenServer)
|
|
exist, err := bullyScreenServer.GetByActivityId(activityId)
|
|
t.CheckErr(err)
|
|
t.Assert(exist, code.MSG_BULLY_SCREEN_SERVER_NOT_EXIST, "霸屏不存在")
|
|
|
|
totalSecond, err := core.GetXormAuto().Where("bully_screen_server_id=? and status=3 and "+
|
|
" is_delete=false and rehearsal_id=?", bullyScreenServer.Id, rehearsalId).
|
|
Sum(new(models.BullyScreenHistory), "second")
|
|
t.CheckErr(err)
|
|
|
|
t.JSON(map[string]interface{}{
|
|
"amount": utils.Float64CusDecimal(totalSecond*bullyScreenServer.Price, 2),
|
|
})
|
|
}
|
|
|
|
type ModuleService struct {
|
|
models.ActivityModuleService `xorm:"extends"`
|
|
History models.ModuleServiceHistory `xorm:"extends"`
|
|
}
|
|
|
|
//获取最新得霸屏记录
|
|
func (t *BullyScreenCtl) Latest() {
|
|
activityId := t.MustGetInt64("activity_id")
|
|
|
|
activity := new(models.Activity)
|
|
exist, err := models.GetById(activity, activityId)
|
|
t.CheckErr(err)
|
|
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
|
|
|
|
//获取霸屏服务得id
|
|
bullyScreenServer := new(models.BullyScreenServer)
|
|
exist, err = bullyScreenServer.GetByActivityId(activityId)
|
|
t.CheckErr(err)
|
|
t.Assert(exist, code.MSG_BULLY_SCREEN_SERVER_NOT_EXIST, "霸屏不存在")
|
|
|
|
result := new(BullyScreenBaseResult)
|
|
exist, err = core.GetXormAuto().Table(new(models.BullyScreenHistory)).Alias("h").
|
|
Join("LEFT", new(models.User).Alias("u"), "u.id=h.user_id and u.is_delete=0").
|
|
Where("h.bully_screen_server_id=? and h.status=2 and h.rehearsal_id=? and h.is_delete=0",
|
|
bullyScreenServer.Id, activity.RehearsalId).Desc("review_time").Get(result)
|
|
t.CheckErr(err)
|
|
if !exist {
|
|
t.RAW(result)
|
|
}
|
|
|
|
//根据主活动得id获取所有得模块列表
|
|
module := new(ModuleService)
|
|
exist, err = core.GetXormAuto().Table(new(models.ActivityModuleService)).Alias("s").
|
|
Join("LEFT", new(models.ModuleServiceHistory).Alias("h"),
|
|
"s.service_module_history_id=h.id and h.is_delete=0 and h.name=?", define.MODULE_BULLYS).
|
|
Where("s.activity_id=? and s.is_delete=0", bullyScreenServer.ActivityId).
|
|
Get(module)
|
|
t.CheckErr(err)
|
|
if !exist {
|
|
t.ERROR("该服务模块尚未开通", code.MSG_ERR_Param)
|
|
}
|
|
|
|
//更改推送状态
|
|
result.BullyScreenHistory.Status = 3
|
|
result.BullyScreenHistory.UpdatedAt = time.Now()
|
|
t.CheckErr(models.Save(map[string]interface{}{
|
|
"id =": result.BullyScreenHistory.Id,
|
|
}, &result.BullyScreenHistory, "status", "updated_at"))
|
|
t.RAW(result)
|
|
}
|
|
|
|
// 霸屏服务器开关
|
|
func (t *BullyScreenCtl) Details() {
|
|
activityId := t.MustGetInt64("activity_id")
|
|
server := new(models.BullyScreenServer)
|
|
exist, err := server.GetByActivityId(activityId)
|
|
t.CheckErr(err)
|
|
t.Assert(exist, code.MSG_BULLY_SCREEN_SERVER_NOT_EXIST, "霸屏不存在")
|
|
t.JSON(map[string]interface{}{
|
|
"server": server,
|
|
})
|
|
}
|