Anonymous avatar Anonymous committed 5025265

fix search mall part

Comments (0)

Files changed (1)

         return json.dumps(temp)
 
 class searchMall(object):
-    def POST(self):
+    def GET(self):
         i = web.input(keyword=None, city=None, state=None, latitude=None, longitude=None, distance=None, page=1, pageSize=20)
         try:
             page = int(i.page)
             pageSize = int(i.pageSize)
         except:
             pageSize = 20
-        web.header('Content-Type', 'application/json')
+        #web.header('Content-Type', 'application/json')
         temp = []
         sql = 'SELECT m.id AS mallId, m.name AS mallName ' \
             'FROM malls m ' \
             'WHERE '
         if i.keyword:
             sql = sql + 'LOWER(m.name) LIKE "%%%%%s%%%%" ' % i.keyword
-        if i.state:
+        if i.state and not i.keyword:
+            sql = sql + 'm.stateId = %s ' % i.state
+        elif i.state and i.keyword:
             sql = sql + 'AND m.stateId = %s ' % i.state
-        if i.city:
+        if i.city and not i.keyword and not i.state:
+            sql = sql + 'm.cityId = %s ' % i.city
+        elif i.city and (i.keyword or i.state):
             sql = sql + 'AND m.cityId = %s ' % i.city
-        if i.latitude and i.longitude and i.distace:
+        if i.latitude and i.longitude and i.distance and not i.keyword and not i.state and not i.city:
+            sql = sql + '(POW((%s - m.latitude), 2) + POW((%s - m.longitude), 2)) <= POW(%s, 2) ' % (i.latitude, i.longitude, i.distance)
+        elif i.latitude and i.longtitude and i.distance and (i.keyword or i.state or i.city):
             sql = sql + 'AND (POW((%s - m.latitude), 2) + POW((%s - m.longitude), 2)) <= POW(%s, 2) ' % (i.latitude, i.longitude, i.distance)
+        if not i.keyword and not i.state and not i.state and not i.city and not i.latitude and not i.longitude and not i.distance:
+            return json.dumps([])
         sql = sql + 'GROUP BY m.id ORDER BY m.name ASC LIMIT %d, %d' % ((page-1)*pageSize, pageSize)
         if i.keyword or i.state or i.city or i.latitude or i.longitude or i.distance:
             malls = list(db.query(sql))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.