12345678910111213141516171819202122232425262728293031 |
- package stdlib
- import (
- "log"
- "time"
- jyDocsRpcUtil "app.yhyue.com/moapp/jy_docs/services/util"
- )
- func DocStatistics(docId, appId string, dtype int) bool {
- sqlStr := ""
- state := false
- var count int64
- jyDocsRpcUtil.GetJyDocsDB().Table("doc_statistics").Where("docId = ? and appId = ?", docId, appId).Count(&count)
- if count < 1 {
- jyDocsRpcUtil.GetJyDocsDB().Exec("insert into doc_statistics (docId,appId,updateDate,score,downTimes,viewTimes) values (?,?,?,?,?,?)", docId, appId, time.Now().Format("2006-01-02 15:04:05"), 0, 0, 0)
- }
- if dtype == 1 { //下载次数增加1
- sqlStr = "update doc_statistics set downTimes = downTimes + 1,updateDate = ? where docId = ? and appId = ?"
- } else if dtype == 2 { //浏览次数增加1
- sqlStr = "update doc_statistics set viewTimes = viewTimes + 1,updateDate = ? where docId = ? and appId = ?"
- }
- //mysql
- log.Println("sql ", sqlStr)
- updateDate := time.Now().Format("2006-01-02 15:04:05")
- err := jyDocsRpcUtil.GetJyDocsDB().Exec(sqlStr, updateDate, docId, appId).Error
- if err == nil {
- state = true
- }
- return state
- }
|