|
|
@@ -830,7 +830,10 @@ def Search(db, ctx):
|
|
|
res = {"result":"fail"}
|
|
|
cursor = db.cursor()
|
|
|
|
|
|
- fields = ["search_type", "search_string"]
|
|
|
+ fields = ["search_type", "search_string", "start", "count"]
|
|
|
+
|
|
|
+ start = "0"
|
|
|
+ count = "100"
|
|
|
|
|
|
val = {}
|
|
|
for f in fields:
|
|
|
@@ -838,6 +841,9 @@ def Search(db, ctx):
|
|
|
if ctx[f] and len(ctx[f]) > 0:
|
|
|
val[f] = ctx[f]
|
|
|
|
|
|
+ if "start" in val: start = val["start"]
|
|
|
+ if "count" in val: count = val["count"]
|
|
|
+
|
|
|
if val["search_type"] == "card":
|
|
|
|
|
|
t = val["search_string"]
|
|
|
@@ -848,11 +854,20 @@ def Search(db, ctx):
|
|
|
query += " or rfid_token like %s "
|
|
|
query += " or comment like %s "
|
|
|
query += " or issuetype like %s "
|
|
|
- cursor.execute(query, [p, p, p, p])
|
|
|
+ query += " and active = 1 "
|
|
|
+ query += " order by logical_card_id desc"
|
|
|
+ query += " limit %s,%s "
|
|
|
+
|
|
|
+ _v = [p,p, p, p, int(start), int(start) + int(count)]
|
|
|
+
|
|
|
+ #cursor.execute(query, [p, p, p, p])
|
|
|
+ cursor.execute(query, _v)
|
|
|
+
|
|
|
rows = cursor.fetchall()
|
|
|
res["data"] = []
|
|
|
for row in rows:
|
|
|
_d = {
|
|
|
+ "iscard": 1,
|
|
|
"logical_card_id": row[0],
|
|
|
"mag_token": row[1],
|
|
|
"rfid_token": row[2],
|
|
|
@@ -879,14 +894,22 @@ def Search(db, ctx):
|
|
|
query = "select userid, " + ", ".join(fields)
|
|
|
query += " from users "
|
|
|
query += " where " + " like %s or ".join(fields) + " like %s "
|
|
|
+ query += " and active = 1 "
|
|
|
+ query += " order by userid desc"
|
|
|
+ query += " limit %s,%s "
|
|
|
|
|
|
print("user query:", query)
|
|
|
|
|
|
- cursor.execute(query, [p]*len(fields))
|
|
|
+ _v = [p]*len(fields)
|
|
|
+ _v.append(int(start))
|
|
|
+ _v.append(int(start) + int(count))
|
|
|
+
|
|
|
+ #cursor.execute(query, [p]*len(fields))
|
|
|
+ cursor.execute(query, _v)
|
|
|
rows = cursor.fetchall()
|
|
|
res["data"] = []
|
|
|
for row in rows:
|
|
|
- _d = { "userid": row[0] }
|
|
|
+ _d = { "userid": row[0], "isuser": 1 }
|
|
|
for idx,f in enumerate(fields):
|
|
|
_d[f] = row[idx+1]
|
|
|
res["data"].append( _d )
|
|
|
@@ -894,6 +917,33 @@ def Search(db, ctx):
|
|
|
res["result"] = "success"
|
|
|
|
|
|
elif val["search_type"] == "admin":
|
|
|
+ t = val["search_string"]
|
|
|
+ p = '%' + t + '%'
|
|
|
+
|
|
|
+ fields = [ "username", "comment" ]
|
|
|
+
|
|
|
+ query = "select userid, group_id, " + ", ".join(fields)
|
|
|
+ query += " from admins "
|
|
|
+ query += " where " + " like %s or ".join(fields) + " like %s "
|
|
|
+ query += " and active = 1 "
|
|
|
+ query += " order by userid desc"
|
|
|
+ query += " limit %s,%s "
|
|
|
+
|
|
|
+ print("user query:", query)
|
|
|
+
|
|
|
+ _v = [p]*len(fields)
|
|
|
+ _v.append(int(start))
|
|
|
+ _v.append(int(start) + int(count))
|
|
|
+
|
|
|
+ cursor.execute(query, _v)
|
|
|
+ rows = cursor.fetchall()
|
|
|
+ res["data"] = []
|
|
|
+ for row in rows:
|
|
|
+ _d = { "userid": row[0], "group_id": row[1], "isadmin": 1 }
|
|
|
+ for idx,f in enumerate(fields):
|
|
|
+ _d[f] = row[idx+2]
|
|
|
+ res["data"].append( _d )
|
|
|
+
|
|
|
res["result"] = "success"
|
|
|
|
|
|
return res
|