package pc import ( "hudongzhuanjia/controllers" "hudongzhuanjia/models" bully_reward_service "hudongzhuanjia/services/bully_reward" "hudongzhuanjia/services/pay" "hudongzhuanjia/utils" "hudongzhuanjia/utils/code" "strings" "time" ) type BullyScreenCtl struct { controllers.AuthorCtl } //获取待审核列表 func (t *BullyScreenCtl) WaitReview() { 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 bullyScreenServer := new(models.BullyScreenServer) exist, err = bullyScreenServer.GetByActivityId(activityId) t.CheckErr(err) t.Assert(exist, code.MSG_BULLY_SCREEN_SERVER_NOT_EXIST, "霸屏不存在") //根据霸屏服务得id获取待审核得霸屏列表 t.CheckErr(bully_reward_service.CheckBullyScreenStatus(bullyScreenServer.Id)) result, err := bully_reward_service.GetBullyScreenReview(bullyScreenServer.Id, activity.RehearsalId) t.CheckErr(err) t.JSON(map[string]interface{}{ "total": len(result), "list": result, }) } //审核操作 func (t *BullyScreenCtl) Review() { customerId := t.MustGetUID() status := t.MustGetBool("status") ids := strings.Split(t.MustGet("ids"), "|") activityId := t.MustGetInt64("activity_id") //rehearsalId := t.MustGetInt64("rehearsal_id") activity := new(models.Activity) exist, err := models.Get(activity, activityId) t.CheckErr(err) t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") //将金额退回给用户 result, err := models.GetBullyScreenHistoryByIds(ids) t.CheckErr(err) for _, v := range result { if status { // true 失败 、、 false 成功 v.Status = 1 _, err = models.Update(v.Id, v, "status") t.CheckErr(err) if activity.RehearsalId != 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 activity.RehearsalId != 0 { continue } // 订单宣告完成 _, err = new(models.UserOrder).UpdateStatusByOutTradeNo(v.OutTradeNo, 2) t.CheckErr(err) wallet := new(models.BullyScreenWallet) _, err = wallet.IncrBalance(customerId, v.Amount) t.CheckErr(err) history := models.BullyScreenWalletHistory{ CustomerId: customerId, UserId: v.UserId, Money: v.Amount, Type: "霸屏", Status: "交易成功", Mark: "霸屏金额", CreatedAt: time.Now(), UpdatedAt: time.Now(), } _, err = models.Add(history) t.CheckErr(err) } } t.SUCCESS("审核成功") } //获取黑名单列表 func (t *BullyScreenCtl) Blacklist() { 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 bullyScreenServer := new(models.BullyScreenServer) exist, err = bullyScreenServer.GetByActivityId(activityId) t.CheckErr(err) t.Assert(exist, code.MSG_BULLY_SCREEN_SERVER_NOT_EXIST, "霸屏活动不存在") //根据霸屏服务得id获取待审核得霸屏列表 result, err := bully_reward_service.GetBullyScreenBlacklist(bullyScreenServer.Id, activity.RehearsalId) t.CheckErr(err) t.DisplayByData(map[string]interface{}{ "total": len(result), "list": result, }) } //获取目前霸屏得总金额 func (t *BullyScreenCtl) 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 bullyScreenServer := new(models.BullyScreenServer) exist, err = bullyScreenServer.GetByActivityId(activityId) t.CheckErr(err) t.Assert(exist, code.MSG_BULLY_SCREEN_SERVER_NOT_EXIST, "霸屏不存在") totalSecond, err := new(models.BullyScreenHistory).SumSecond(bullyScreenServer.Id, activity.RehearsalId) t.CheckErr(err) t.JSON(map[string]interface{}{ "amount": utils.Float64CusDecimal(totalSecond*bullyScreenServer.Price, 2), }) } //获取最新得霸屏记录 func (t *BullyScreenCtl) Latest() { 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 bullyScreenServer := new(models.BullyScreenServer) exist, err = bullyScreenServer.GetByActivityId(activityId) t.CheckErr(err) t.Assert(exist, code.MSG_BULLY_SCREEN_SERVER_NOT_EXIST, "霸屏不存在") result, err := bully_reward_service.GetBullyScreenLatest(bullyScreenServer.Id, activity.RehearsalId) t.CheckErr(err) if result == nil || result.Id == 0 { t.JSON(result) } //更改推送状态 result.BullyScreenHistory.Status = 3 result.BullyScreenHistory.UpdatedAt = time.Now() _, err = models.Update(result.BullyScreenHistory.Id, &result.BullyScreenHistory, "status") t.CheckErr(err) t.JSON(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, }) }