ソースを参照

add access total method

master
shenjiachi 6日前
コミット
8f7f975c04
2個のファイルの変更31行の追加0行の削除
  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 ファイルの表示

@@ -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 ファイルの表示

@@ -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
}

読み込み中…
キャンセル
保存