From 240b1dec27635113394839170b870857c6880c5c Mon Sep 17 00:00:00 2001 From: midoks Date: Tue, 16 May 2023 20:34:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E7=BD=91=E7=AB=99=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- class/core/db.py | 2 +- class/core/site_api.py | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/class/core/db.py b/class/core/db.py index 664bd93f6..91256ae7a 100755 --- a/class/core/db.py +++ b/class/core/db.py @@ -65,7 +65,7 @@ class Sql(): self.__DB_TABLE = table return self - def where(self, where, param): + def where(self, where, param=()): # WHERE条件 if where: self.__OPT_WHERE = " WHERE " + where diff --git a/class/core/site_api.py b/class/core/site_api.py index a9a132998..b2657b38a 100755 --- a/class/core/site_api.py +++ b/class/core/site_api.py @@ -101,19 +101,31 @@ class site_api: limit = request.form.get('limit', '10') p = request.form.get('p', '1') type_id = request.form.get('type_id', '0').strip() + search = request.form.get('search', '').strip() start = (int(p) - 1) * (int(limit)) siteM = mw.M('sites').field('id,name,path,status,ps,addtime,edate') - if type_id != '' and int(type_id) >= 0: - siteM.where('type_id=?', (type_id,)) + + sql_where = '' + if search != '': + sql_where = " name like '%" + search + "%' " + + if type_id != '' and int(type_id) >= 0 and search != '': + sql_where = sql_where + " and type_id=" + type_id + "" + elif type_id != '' and int(type_id) >= 0: + sql_where = " type_id=" + type_id + + if sql_where != '': + siteM.where(sql_where) _list = siteM.limit((str(start)) + ',' + limit).order('id desc').select() - for i in range(len(_list)): - _list[i]['backup_count'] = mw.M('backup').where( - "pid=? AND type=?", (_list[i]['id'], 0)).count() + if _list != None: + for i in range(len(_list)): + _list[i]['backup_count'] = mw.M('backup').where( + "pid=? AND type=?", (_list[i]['id'], 0)).count() _ret = {} _ret['data'] = _list