func GiveAwards(user *models.Account, awards Awards, redis *models.RedisLogger) error { if awards.Level < 0 || awards.Score < 0 { panic("invalid level or score") } if _, err := sendCoin(user.Wallet.Addr, awards.Wealth); err != nil { return err } redis.SendCoins(user.Id, awards.Wealth) err := user.UpdateProps(models.Props{ Physical: awards.Physical, Literal: awards.Literal, Mental: awards.Mental, //Wealth: awards.Wealth, Score: awards.Score, //Level: awards.Level, }) if err != nil { return err } if lvl := models.Score2Level(user.Props.Score + awards.Score); lvl > user.Level() { // ws push event := &models.Event{ Type: models.EventNotice, Time: time.Now().Unix(), Data: models.EventData{ Type: models.EventLevelUP, To: user.Id, }, } event.Save() redis.PubMsg(event.Type, event.Data.To, event.Bytes()) } return nil }