|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- package db
-
- import (
- "applet/app/db/model"
- "applet/app/utils/logx"
- "reflect"
- "xorm.io/xorm"
- )
-
- type SchemeWithGoodsDb struct {
- Db *xorm.Engine `json:"db"`
- }
-
- func (schemeWithGoodsDb *SchemeWithGoodsDb) Set() { // set方法
- schemeWithGoodsDb.Db = Db
- }
-
- func (schemeWithGoodsDb *SchemeWithGoodsDb) FindSchemeWithGoods(schemeId int) (*[]model.SchemeWithGoods, error) {
- var m []model.SchemeWithGoods
- if err := schemeWithGoodsDb.Db.Where("scheme_id =?", schemeId).Desc("id").Find(&m); err != nil {
- return nil, logx.Error(err)
- }
- return &m, nil
- }
-
- func (schemeWithGoodsDb *SchemeWithGoodsDb) GetSchemeWithGoods(schemeId int, goodsId int64) (m *model.SchemeWithGoods, err error) {
- m = new(model.SchemeWithGoods)
- has, err := schemeWithGoodsDb.Db.Where("scheme_id =?", schemeId).And("goods_id =?", goodsId).Get(m)
- if err != nil {
- return nil, logx.Error(err)
- }
- if has == false {
- return nil, nil
- }
- return m, nil
- }
-
- func (schemeWithGoodsDb *SchemeWithGoodsDb) SchemeDeleteBySession(session *xorm.Session, id interface{}) (int64, error) {
- if reflect.TypeOf(id).Kind() == reflect.Slice {
- return session.In("id", id).Delete(model.SchemeWithGoods{})
- } else {
- return session.Where("id = ?", id).Delete(model.SchemeWithGoods{})
- }
- }
-
- func (schemeWithGoodsDb *SchemeWithGoodsDb) SchemeWithGoodsInsert(m *model.SchemeWithGoods) (int, error) {
- _, err := schemeWithGoodsDb.Db.InsertOne(m)
- if err != nil {
- return 0, err
- }
- return m.Id, nil
- }
|