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