Browse Source

add access total method

master
shenjiachi 6 days ago
parent
commit
8f7f975c04
2 changed files with 31 additions and 0 deletions
  1. +1
    -0
      src/dao/egg_access_total_dao.go
  2. +30
    -0
      src/implement/egg_access_total_implement.go

+ 1
- 0
src/dao/egg_access_total_dao.go View File

@@ -5,4 +5,5 @@ import "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
type EggAccessTotalDao interface {
//TODO:: You can add specific method definitions here
EggAccessTotalGetByPage(year, week, page, limit int) ([]model.EggAccessTotal, error)
EggAccessTotalAddOrDefault(uid int64, year, week int) (int64, error)
}

+ 30
- 0
src/implement/egg_access_total_implement.go View File

@@ -23,3 +23,33 @@ func (e EggAccessTotalDb) EggAccessTotalGetByPage(year, week, page, limit int) (
}
return m, nil
}

func (e EggAccessTotalDb) EggAccessTotalAddOrDefault(uid int64, year, week int) (int64, error) {
session := e.Db.NewSession()
session.Begin()
var m model.EggAccessTotal
var affected int64
exist, err := session.Where("uid = ?", uid).And("year = ?", year).And("week = ?", week).Get(&m)
if err != nil {
return 0, zhios_order_relate_logx.Error(err.Error())
}
if !exist {
// 不存在则创建
m.Total = 1
m.Uid = uid
m.Year = year
m.Week = week
affected, err = session.Insert(m)
if err != nil {
return 0, zhios_order_relate_logx.Error(err.Error())
}
} else {
m.Total++
affected, err = session.Where("id = ?", m.Id).MustCols("total").Update(m)
if err != nil {
return 0, zhios_order_relate_logx.Error(err.Error())
}
}
session.Commit()
return affected, nil
}

Loading…
Cancel
Save