|
|
package pc
import ( "hudongzhuanjia/controllers" "hudongzhuanjia/models" bully_reward_service "hudongzhuanjia/services/bully_reward" "hudongzhuanjia/services/pay" "hudongzhuanjia/utils" "hudongzhuanjia/utils/code" "hudongzhuanjia/utils/define" "strings" "time"
"github.com/ouxuanserver/osmanthuswine/src/core" )
type BullyScreenCtl struct { controllers.AuthorCtl }
//获取待审核列表
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, "霸屏不存在")
//根据霸屏服务得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() 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. 写入金额流水记录
_, err = pay_service.Refund("欧轩互动-霸屏拉黑", v.OutTradeNo) t.CheckErr(err)
} else { _, err = v.UpdateStatus(v.Id, 2) t.CheckErr(err) // todo: 审核成功
// 1. 金额打入主账号的打赏钱包里面
// 2. 记录金额流水
if rehearsalId != 0 { continue }
wallet := new(models.BullyScreenWallet) _, err = wallet.IncrBalance(customerId, v.Amount) t.CheckErr(err)
_, err = core.GetXormAuto().InsertOne(&models.BullyScreenWalletHistory{ CustomerId: customerId, 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, 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") 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, err := bully_reward_service.GetBullyScreenLatest(bullyScreenServer.Id, activity.RehearsalId) t.CheckErr(err) if result == nil || result.Id == 0 { 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, }) }
|