docStatistics.go 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. package stdlib
  2. import (
  3. "log"
  4. "time"
  5. jyDocsRpcUtil "app.yhyue.com/moapp/jy_docs/services/util"
  6. )
  7. func DocStatistics(docId, appId string, dtype int) bool {
  8. sqlStr := ""
  9. state := false
  10. var count int64
  11. jyDocsRpcUtil.GetJyDocsDB().Table("doc_statistics").Where("docId = ? and appId = ?", docId, appId).Count(&count)
  12. if count < 1 {
  13. 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)
  14. }
  15. if dtype == 1 { //下载次数增加1
  16. sqlStr = "update doc_statistics set downTimes = downTimes + 1,updateDate = ? where docId = ? and appId = ?"
  17. } else if dtype == 2 { //浏览次数增加1
  18. sqlStr = "update doc_statistics set viewTimes = viewTimes + 1,updateDate = ? where docId = ? and appId = ?"
  19. }
  20. //mysql
  21. log.Println("sql ", sqlStr)
  22. updateDate := time.Now().Format("2006-01-02 15:04:05")
  23. err := jyDocsRpcUtil.GetJyDocsDB().Exec(sqlStr, updateDate, docId, appId).Error
  24. if err == nil {
  25. state = true
  26. }
  27. return state
  28. }