Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复niu包部分问题 #68

Merged
merged 5 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions niu/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,20 @@ func GetRankingInfo(gid int64, t bool) (BaseInfos, error) {
list users
err error
)

niuOfGroup, err := db.getAllNiuNiuOfGroup(gid)
if err != nil {
return nil, err
}

list = niuOfGroup.filter(t)
list.sort(t)
if len(list) == 0 {
if t {
return nil, ErrNoBoys
}
return nil, ErrNoGirls
}
list = niuOfGroup.filter(t)
f := make(BaseInfos, len(list))
for i, info := range list {
f[i] = BaseInfo{
Expand All @@ -140,10 +146,10 @@ func GetGroupUserRank(gid, uid int64) (int, error) {
}

// View 查看牛牛
func View(gid, uid int64, name string) (*strings.Builder, error) {
func View(gid, uid int64, name string) (string, error) {
i, err := db.getWordNiuNiu(gid, uid)
if err != nil {
return nil, ErrNoNiuNiu
return "", ErrNoNiuNiu
}
niuniu := i.Length
var result strings.Builder
Expand All @@ -155,12 +161,12 @@ func View(gid, uid int64, name string) (*strings.Builder, error) {
}
niuniuList, err := db.getAllNiuNiuOfGroup(gid)
if err != nil {
return nil, err
return "", err
}
result.WriteString(fmt.Sprintf("\n📛%s<%s>的牛牛信息\n⭕性别:%s\n⭕%s度:%.2fcm\n⭕排行:%d\n⭕%s ",
name, strconv.FormatInt(uid, 10),
sex, sexLong, niuniu, niuniuList.ranking(niuniu, uid), generateRandomString(niuniu)))
return &result, nil
return result.String(), nil
}

// HitGlue 打胶
Expand Down Expand Up @@ -310,15 +316,25 @@ func Sell(gid, uid int64) (string, error) {
if !t {
return "", errors.New(message)
}

if err := db.deleteWordNiuNiu(gid, uid); err != nil {
return "", err
}

err = wallet.InsertWalletOf(uid, money)
if err != nil {
return message, err
}

infos, _ := db.getAllNiuNiuAuction(gid)

u := AuctionInfo{
ID: len(infos),
UserID: niu.UID,
Length: niu.Length,
Money: money * 2,
}

err = db.setNiuNiuAuction(gid, &u)
return message, err
}
Expand All @@ -331,12 +347,11 @@ func ShowAuction(gid int64) ([]AuctionInfo, error) {
}

// Auction 购买牛牛
func Auction(gid, uid int64, i int) (string, error) {
func Auction(gid, uid int64, index int) (string, error) {
infos, err := db.getAllNiuNiuAuction(gid)
if err != nil {
return "", ErrNoNiuNiuINAuction
}
index := i - 1
if err := wallet.InsertWalletOf(uid, -infos[index].Money); err != nil {
return "", ErrNoMoney
}
Expand Down
14 changes: 6 additions & 8 deletions niu/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ type userInfo struct {

// AuctionInfo 拍卖信息
type AuctionInfo struct {
ID uint
UserID int64
Length float64
Money int
ID int `db:"id"`
UserID int64 `db:"user_id"`
Length float64 `db:"length"`
Money int `db:"money"`
}

// BaseInfo ...
Expand Down Expand Up @@ -388,16 +388,14 @@ func (db *model) getAllNiuNiuOfGroup(gid int64) (users, error) {
func (db *model) setNiuNiuAuction(gid int64, u *AuctionInfo) error {
db.Lock()
defer db.Unlock()
num, err := db.sql.Count(fmt.Sprintf("auction_%d", gid))
err := db.sql.Insert(fmt.Sprintf("auction_%d", gid), u)
if err != nil {
err = db.sql.Create(fmt.Sprintf("auction_%d", gid), &AuctionInfo{})
if err != nil {
return err
}
num = -1
err = db.sql.Insert(fmt.Sprintf("auction_%d", gid), u)
}
u.ID = uint(num + 1)
err = db.sql.Insert(fmt.Sprintf("auction_%d", gid), u)
return err
}

Expand Down
Loading