From 8950e808afa5ec1149b3d3e08217319052138cc7 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Tue, 10 Dec 2024 18:22:30 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=AF=81=E4=B9=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/dao/user_certificate_dao.go | 9 ++++ src/implement/user_certificate_implement.go | 55 +++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 src/dao/user_certificate_dao.go create mode 100644 src/implement/user_certificate_implement.go diff --git a/src/dao/user_certificate_dao.go b/src/dao/user_certificate_dao.go new file mode 100644 index 0000000..f083f99 --- /dev/null +++ b/src/dao/user_certificate_dao.go @@ -0,0 +1,9 @@ +package dao + +import "code.fnuoos.com/EggPlanet/egg_models.git/src/model" + +type UserCertificateDao interface { + FindUserCertificate(page, limit, uid string) (*[]model.UserCertificate, error) + GetUserCertificateByNo(no string) (*model.UserCertificate, error) + GetUserCertificateById(id string) (*model.UserCertificate, error) +} diff --git a/src/implement/user_certificate_implement.go b/src/implement/user_certificate_implement.go new file mode 100644 index 0000000..f82549b --- /dev/null +++ b/src/implement/user_certificate_implement.go @@ -0,0 +1,55 @@ +package implement + +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" + "strings" + "xorm.io/xorm" +) + +func NewUserCertificateDb(engine *xorm.Engine) dao.UserCertificateDao { + return &UserCertificateDb{Db: engine} +} + +type UserCertificateDb struct { + Db *xorm.Engine +} + +func (u UserCertificateDb) FindUserCertificate(page, limit, uid string) (*[]model.UserCertificate, error) { + var m []model.UserCertificate + sess := u.Db.Where("1=1") + if uid != "" { + sess.In("uid", strings.Split(uid, ",")) + } + start := (zhios_order_relate_utils.StrToInt(page) - 1) * zhios_order_relate_utils.StrToInt(limit) + err := sess.Limit(zhios_order_relate_utils.StrToInt(limit), start).OrderBy("id desc").Find(&m) + if err != nil { + return nil, zhios_order_relate_logx.Error(err) + } + return &m, nil +} + +func (u UserCertificateDb) GetUserCertificateByNo(no string) (m *model.UserCertificate, err error) { + m = new(model.UserCertificate) + has, err := u.Db.Where("no =?", no).Get(m) + if err != nil { + return nil, zhios_order_relate_logx.Error(err) + } + if has == false { + return nil, nil + } + return m, nil +} +func (u UserCertificateDb) GetUserCertificateById(id string) (m *model.UserCertificate, err error) { + m = new(model.UserCertificate) + has, err := u.Db.Where("id =?", id).Get(m) + if err != nil { + return nil, zhios_order_relate_logx.Error(err) + } + if has == false { + return nil, nil + } + return m, nil +}