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

178 lines
6.2 KiB

package bully_reward_service
import (
"github.com/ouxuanserver/osmanthuswine/src/core"
"hudongzhuanjia/models"
)
type BullyListResult struct {
Id int `json:"id"`
Content string `json:"content"`
Status int `json:"status"`
Second int `json:"second"`
}
func GetBullyList(userId, bullyId int64) ([]*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 int64 `json:"id"`
Content string `json:"content"`
Amount float64 `json:"amount"`
Status int `json:"status"`
}
func GetRewardList(userId, rehearsalId, rewardId int64) ([]*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 status <> -1", userId, rewardId, rehearsalId).
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 int64) (*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=?",
serverId, rehearsalId).Desc("h.review_time").Get(result)
return result, err
}
func GetRewardReview(serverId, rehearsalId int64) ([]*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=?",
serverId, rehearsalId).Desc("h.created_at").Find(&result)
return result, err
}
func GetRewardBlacklist(serverId, rehearsalId int64) ([]*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=?",
serverId, rehearsalId).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 int64) 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=?",
serverId).Find(&result)
if err != nil {
return err
}
success := make([]int64, 0)
destroy := make([]int64, 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 int64) ([]*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=?",
bullyScreenServerId, rehearsalId).Desc("h.created_at").Find(&result)
return result, err
}
func GetBullyScreenBlacklist(bullyScreenServerId, rehearsalId int64) ([]*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=?",
bullyScreenServerId, rehearsalId).Desc("review_time").Find(&result)
return result, err
}
func GetBullyScreenLatest(bullyScreenServerId, rehearsalId int64) (*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.is_delete=0",
bullyScreenServerId, rehearsalId).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(bullyScreenServerId int64) 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",
bullyScreenServerId).Find(&result)
if err != nil {
return err
}
success := make([]int64, 0)
destroy := make([]int64, 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
}