diff --git a/code/apps/models/AdminModel.py b/code/apps/models/AdminModel.py index 47c05ca..0509223 100644 --- a/code/apps/models/AdminModel.py +++ b/code/apps/models/AdminModel.py @@ -2,7 +2,7 @@ # @Author: smallevil # @Date: 2020-11-24 10:48:40 # @Last Modified by: smallevil -# @Last Modified time: 2020-11-27 02:26:56 +# @Last Modified time: 2020-11-27 19:00:27 import hashlib from .TBDB import TBDB @@ -30,6 +30,9 @@ def adminLogin(self, nick, passwd): def getUserInfoByID(self, userID): return self._db.getUserInfoByID(userID) + def getLinkInfoByID(self, linkID): + return self._db.getLinkInfoByID(linkID) + #添加短链接 def addLinkInfo(self, userID, url, domain, tag): urlmd5 = self.md5(url) @@ -104,4 +107,7 @@ def statBrowser(self, linkID, date): def statAddr(self, linkID, date): return self._db.statAddr(linkID, date) + def statViewHistory(self, linkID, date, start, limit): + return self._db.statViewHistory(linkID, date, start, limit) + diff --git a/code/apps/models/TBDB.py b/code/apps/models/TBDB.py index 32d13d3..16b52bb 100644 --- a/code/apps/models/TBDB.py +++ b/code/apps/models/TBDB.py @@ -2,7 +2,7 @@ # @Author: smallevil # @Date: 2020-11-24 10:48:40 # @Last Modified by: smallevil -# @Last Modified time: 2020-11-27 17:28:53 +# @Last Modified time: 2020-11-27 18:50:50 import records from hashids import Hashids @@ -66,6 +66,20 @@ def getLinkInfoByKey(self, key): else: return None + #根据key得到短链信息 + def getLinkInfoByID(self, linkID): + if not linkID: + return None + + params = {'id':linkID} + sql = "select * from link_info where link_id=:id" + rows = self._conn.query(sql, **params) + row = rows.first(as_dict=True) + if row: + return row + else: + return None + #根据urlmd5判断是否已添加 def getLinkInfoByMD5(self, userID, urlmd5): if not urlmd5 or not userID: @@ -267,6 +281,25 @@ def statAddr(self, linkID, date): rows = self._conn.query(sql, **params) return rows.all(as_dict=True) + def statViewHistory(self, linkID, date, start, limit): + limitDate = str(arrow.get(date, 'YYYYMMDD').format('YYYY-MM-DD')) + params = {'link_id':linkID, 'date':limitDate, 'start':start, 'limit':limit} + + if self._dbType: + sql = "select * from link_record where link_id=:link_id and record_date>=:date order by record_id desc limit :start, :limit" + else: + sql = "select * from link_record where link_id=:link_id and record_date>=:date order by record_id desc limit :limit offset :start" + + info = {} + rows = self._conn.query(sql, **params) + info['list'] = rows.all(as_dict=True) + + sql = "select count(*) as total from link_record where link_id=:link_id and record_date>=:date" + rows = self._conn.query(sql, **params) + row = rows.first(as_dict=True) + info['total'] = row['total'] + + return info diff --git a/code/apps/templates/admin/add.html b/code/apps/templates/admin/add.html index 50527e1..905d858 100644 --- a/code/apps/templates/admin/add.html +++ b/code/apps/templates/admin/add.html @@ -25,7 +25,7 @@
- + diff --git a/code/apps/templates/admin/stat_addr.html b/code/apps/templates/admin/stat_addr.html index eca720f..cb7e489 100644 --- a/code/apps/templates/admin/stat_addr.html +++ b/code/apps/templates/admin/stat_addr.html @@ -24,10 +24,18 @@