package bully_reward_service import ( "hudongzhuanjia/models" "git.ouxuan.net/tommy/osmanthuswine/src/core" ) type BullyListResult struct { Id int `json:"id"` Content string `json:"content"` Status int `json:"status"` Second int `json:"second"` } func GetBullyList(userId, bullyId int) ([]*BullyListResult, error) { list := make([]*BullyListResult, 0) err := core.GetXormAuto().Table(new(models.BullyScreenHistory)).Select("id, content, status, second"). Where("is_delete=0 and user_id=? and bully_screen_server_id=? and status<> -1", userId, bullyId). OrderBy("created_at desc").Find(&list) return list, err } type RewardListResult struct { Id int `json:"id"` Content string `json:"content"` Amount float64 `json:"amount"` Status int `json:"status"` } func GetRewardList(userId, rehearsalId, rewardId int, archId interface{}) ([]*RewardListResult, error) { list := make([]*RewardListResult, 0) err := core.GetXormAuto().Table(new(models.RewardHistory)).Select("id, content, amount, status"). Where("is_delete=0 and user_id=? and reward_server_id=? and rehearsal_id=? and arch_id=? and status <> -1", userId, rewardId, rehearsalId, archId).Desc("created_at").Find(&list) return list, err } type RewardResult struct { models.RewardHistory `xorm:"extends"` User *models.User `json:"user" xorm:"extends"` } func GetRewardLatest(serverId, rehearsalId int, archId interface{}) (*RewardResult, error) { result := new(RewardResult) _, err := core.GetXormAuto().Table(new(models.RewardHistory)).Alias("h"). Join("LEFT", new(models.User).Alias("u"), "h.user_id=u.id and u.is_delete=0"). Where("h.is_delete=0 and h.status=2 and h.reward_server_id=? and h.rehearsal_id=? and h.arch_id=?", serverId, rehearsalId, archId).Desc("h.review_time").Get(result) return result, err } func GetRewardReview(serverId, rehearsalId int, archId interface{}) ([]*RewardResult, error) { result := make([]*RewardResult, 0) err := core.GetXormAuto().Table(new(models.RewardHistory)).Alias("h"). Join("LEFT", new(models.User).Alias("u"), "h.user_id=u.id and u.is_delete=0"). Where("h.is_delete=0 and h.status=0 and h.reward_server_id=? and h.rehearsal_id=? and h.arch_id=?", serverId, rehearsalId, archId).Desc("h.created_at").Find(&result) return result, err } func GetRewardBlacklist(serverId, rehearsalId int, archId interface{}) ([]*RewardResult, error) { result := make([]*RewardResult, 0) err := core.GetXormAuto().Table(new(models.RewardHistory)).Alias("h"). Join("LEFT", new(models.User).Alias("u"), "h.user_id=u.id and u.is_delete=0"). Where("h.is_delete=0 and h.status=1 and h.reward_server_id=? and h.rehearsal_id=? and arch_id=?", serverId, rehearsalId, archId).Desc("h.review_time").Find(&result) return result, err } type RewardStatus struct { History *models.RewardHistory `json:"history" xorm:"extends"` Order *models.UserOrder `json:"order" xorm:"extends"` } func CheckRewardStatus(serverId int, archId int) error { result := make([]*RewardStatus, 0) err := core.GetXormAuto().Table(new(models.RewardHistory)).Alias("h"). Join("LEFT", new(models.UserOrder).AliasName("u"), "h.out_trade_no=u.out_trade_no and u.is_delete=0"). Where("h.is_delete=0 and h.status=-1 and h.reward_server_id=? and h.arch_id=?", serverId, archId).Find(&result) if err != nil { return err } success := make([]int, 0) destroy := make([]int, 0) for _, v := range result { if v.Order.Status == 1 { success = append(success, v.History.Id) } else if v.Order.Status != 0 { destroy = append(destroy, v.History.Id) } } err = new(models.RewardHistory).UpdateStatusByIds(success, 0) if err != nil { return err } err = new(models.RewardHistory).UpdateStatusByIds(success, 4) if err != nil { return err } return nil } type BullyScreenResult struct { models.BullyScreenHistory `xorm:"extends"` User *models.User `json:"user" xorm:"extends"` } func GetBullyScreenReview(bullyScreenServerId, rehearsalId int, archId interface{}) ([]*BullyScreenResult, error) { result := make([]*BullyScreenResult, 0) err := core.GetXormAuto().Table(new(models.BullyScreenHistory)).Alias("h"). Join("LEFT", new(models.User).Alias("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=? and h.arch_id=?", bullyScreenServerId, rehearsalId, archId).Desc("h.created_at").Find(&result) return result, err } func GetBullyScreenBlacklist(bullyScreenServerId, rehearsalId int, archId interface{}) ([]*BullyScreenResult, error) { result := make([]*BullyScreenResult, 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=? and h.arch_id=?", bullyScreenServerId, rehearsalId, archId).Desc("review_time").Find(&result) return result, err } func GetBullyScreenLatest(bullyScreenServerId, rehearsalId int, archId interface{}) (*BullyScreenResult, error) { result := new(BullyScreenResult) _, 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.arch_id=? and h.is_delete=0", bullyScreenServerId, rehearsalId, archId).Desc("review_time").Get(result) return result, err } type BullyScreenStatus struct { History *models.BullyScreenHistory `json:"history" xorm:"extends"` Order *models.UserOrder `json:"order" xorm:"extends"` } func CheckBullyScreenStatus(serverId int) error { result := make([]*BullyScreenStatus, 0) err := core.GetXormAuto().Table(new(models.BullyScreenHistory)).Alias("h"). Join("LEFT", new(models.UserOrder).AliasName("u"), "u.out_trade_no=h.out_trade_no and u.is_delete=0"). Where("h.bully_screen_server_id=? and h.status=-1 and h.is_delete=0", serverId).Find(&result) if err != nil { return err } success := make([]int, 0) destroy := make([]int, 0) for _, v := range result { if v.Order.Status == 1 { success = append(success, v.History.Id) } else if v.Order.Status != 0 { destroy = append(destroy, v.History.Id) } } err = new(models.BullyScreenHistory).UpdateStatusByIds(success, 0) if err != nil { return err } err = new(models.BullyScreenHistory).UpdateStatusByIds(success, 4) if err != nil { return err } return nil }