From 85252096dcf522696fb536a376838a8769e5efe8 Mon Sep 17 00:00:00 2001 From: shenjiachi Date: Wed, 20 Nov 2024 19:28:30 +0800 Subject: [PATCH] add home page --- src/dao/egg_energy_price_dao.go | 1 + src/dao/egg_sign_in_dao.go | 4 +++ src/dao/user_dao.go | 1 + src/implement/egg_energy_price_implement.go | 9 ++++++ src/implement/egg_sign_in_implement.go | 35 +++++++++++++++++++++ src/implement/user_implement.go | 8 +++++ src/model/egg_sign_in.go | 13 +++++--- 7 files changed, 66 insertions(+), 5 deletions(-) diff --git a/src/dao/egg_energy_price_dao.go b/src/dao/egg_energy_price_dao.go index 544d920..4bd4114 100644 --- a/src/dao/egg_energy_price_dao.go +++ b/src/dao/egg_energy_price_dao.go @@ -7,4 +7,5 @@ type EggEnergyPriceDao interface { EggEnergyPriceGetLastOne() (*model.EggEnergyPrice, bool, error) EggEnergyPriceInsert(eggEnergyPrice *model.EggEnergyPrice) (int64, error) EggEnergyPriceUpdate(eggEnergyPrice *model.EggEnergyPrice) (int64, error) + EggEnergyPriceGetOneByParams(Date string, Hour int) (*model.EggEnergyPrice, error) } diff --git a/src/dao/egg_sign_in_dao.go b/src/dao/egg_sign_in_dao.go index 380b2f4..4b59cf9 100644 --- a/src/dao/egg_sign_in_dao.go +++ b/src/dao/egg_sign_in_dao.go @@ -1,5 +1,9 @@ package dao +import "code.fnuoos.com/EggPlanet/egg_models.git/src/model" + type EggSignInDao interface { //TODO:: You can add specific method definitions here + EggSignInGetOne(startAt, endAt string, uid int64) (bool, *model.EggSignIn, error) + EggSignInFindByParams(params map[string]interface{}) ([]*model.EggSignIn, error) } diff --git a/src/dao/user_dao.go b/src/dao/user_dao.go index 900db74..5a91632 100644 --- a/src/dao/user_dao.go +++ b/src/dao/user_dao.go @@ -17,4 +17,5 @@ type UserDao interface { UserInsert(m *model.User) (int64, error) UpdateUser(m *model.User, columns ...string) (int64, error) GetUser(id int64) (m *model.User, err error) + UserCount() (int64, error) } diff --git a/src/implement/egg_energy_price_implement.go b/src/implement/egg_energy_price_implement.go index 0bdad42..83bf33d 100644 --- a/src/implement/egg_energy_price_implement.go +++ b/src/implement/egg_energy_price_implement.go @@ -53,3 +53,12 @@ func (e EggEnergyPriceDb) EggEnergyPriceUpdate(eggEnergyPrice *model.EggEnergyPr } return affected, nil } + +func (e EggEnergyPriceDb) EggEnergyPriceGetOneByParams(Date string, Hour int) (*model.EggEnergyPrice, error) { + var m model.EggEnergyPrice + _, err := e.Db.Where("date = ?", Date).And("hour = ?", Hour).Get(&m) + if err != nil { + return nil, zhios_order_relate_logx.Error(err.Error()) + } + return &m, nil +} diff --git a/src/implement/egg_sign_in_implement.go b/src/implement/egg_sign_in_implement.go index 04c7c11..1454667 100644 --- a/src/implement/egg_sign_in_implement.go +++ b/src/implement/egg_sign_in_implement.go @@ -2,6 +2,11 @@ import ( "code.fnuoos.com/EggPlanet/egg_models.git/src/dao" + "code.fnuoos.com/EggPlanet/egg_models.git/src/model" + zhios_order_relate_utils "code.fnuoos.com/EggPlanet/egg_models.git/utils" + zhios_order_relate_logx "code.fnuoos.com/EggPlanet/egg_models.git/utils/logx" + "fmt" + "reflect" "xorm.io/xorm" ) @@ -12,3 +17,33 @@ func NewEggSignInDb(engine *xorm.Engine) dao.EggSignInDao { type EggSignInDb struct { Db *xorm.Engine } + +func (e EggSignInDb) EggSignInGetOne(startAt, endAt string, uid int64) (bool, *model.EggSignIn, error) { + var eggSignIn model.EggSignIn + has, err := e.Db.Where("start_time > ?", startAt). + And("end_time < ?", endAt). + And("uid = ?", uid). + And("is_completed = 0"). + Get(&eggSignIn) + if err != nil { + return false, nil, err + } + return has, &eggSignIn, nil +} + +func (e EggSignInDb) EggSignInFindByParams(params map[string]interface{}) ([]*model.EggSignIn, error) { + var m []*model.EggSignIn + if reflect.TypeOf(params["value"]).Kind() == reflect.Slice { + //指定In查询 + if err := e.Db.In(zhios_order_relate_utils.AnyToString(params["key"]), params["value"]).Find(m); err != nil { + return nil, zhios_order_relate_logx.Warn(err) + } + } else { + var query = fmt.Sprintf("%s =?", params["key"]) + err := e.Db.Where(query, params["value"]).Find(m) + if err != nil { + return nil, zhios_order_relate_logx.Error(err) + } + } + return m, nil +} diff --git a/src/implement/user_implement.go b/src/implement/user_implement.go index 94da786..6117051 100644 --- a/src/implement/user_implement.go +++ b/src/implement/user_implement.go @@ -149,3 +149,11 @@ func (u UserDb) UserFindAndCount(uid int64, phone string, nickname string, level } return &m, total, nil } + +func (u UserDb) UserCount() (int64, error) { + count, err := u.Db.Count(&model.User{}) + if err != nil { + return 0, zhios_order_relate_logx.Error(err) + } + return count, nil +} diff --git a/src/model/egg_sign_in.go b/src/model/egg_sign_in.go index e899d8c..4131b98 100644 --- a/src/model/egg_sign_in.go +++ b/src/model/egg_sign_in.go @@ -1,9 +1,12 @@ package model type EggSignIn struct { - Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"` - Uid int64 `json:"uid" xorm:"not null default 0 comment('用户id') INT(11)"` - StartTime string `json:"start_time" xorm:"not null default 'CURRENT_TIMESTAMP' comment('签到开始时间') DATETIME"` - EndTime string `json:"end_time" xorm:"not null default 'CURRENT_TIMESTAMP' comment('签到结束时间') DATETIME"` - IsCompleted int `json:"is_completed" xorm:"not null default 0 comment('是否完成(0:未完成 1:已完成)') TINYINT(1)"` + Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"` + Uid int64 `json:"uid" xorm:"not null default 0 comment('用户id') BIGINT(20)"` + StartTime string `json:"start_time" xorm:"not null default 'CURRENT_TIMESTAMP' comment('签到开始时间') DATETIME"` + EndTime string `json:"end_time" xorm:"not null default 'CURRENT_TIMESTAMP' comment('签到结束时间') DATETIME"` + TotalPersonEggPoints string `json:"total_person_egg_points" xorm:"not null comment('个人蛋蛋积分值') DECIMAL(28,8)"` + TotalTeamEggPoints string `json:"total_team_egg_points" xorm:"not null comment('团队蛋蛋积分值') DECIMAL(28,8)"` + EstimatePerSecondEggEnergyValue string `json:"estimate_per_second_egg_energy_value" xorm:"not null comment('预估每秒奖励蛋蛋能量值') DECIMAL(28,8)"` + IsCompleted int `json:"is_completed" xorm:"not null default 0 comment('是否完成(0:未完成 1:已完成)') TINYINT(1)"` }