瀏覽代碼

Merge branch 'master' of http://git.choozmo.com:3000/choozmo/HHH_Home_Decoration_2 into master

jeter20131220 3 年之前
父節點
當前提交
f78b985fad
共有 1 個文件被更改,包括 32 次插入9 次删除
  1. 32 9
      api/main.py

+ 32 - 9
api/main.py

@@ -72,15 +72,38 @@ async def create_req(req:deco_request):
 
 
 @app.post("/deco_request_detail")
 @app.post("/deco_request_detail")
 async def create_req_detail(req:deco_request_detail):
 async def create_req_detail(req:deco_request_detail):
-    request_table = db['deco_request']
-    time_stamp = datetime.fromtimestamp(time.time())
-    time_stamp = time_stamp.strftime("%Y-%m-%d %H:%M:%S")
-    req.time_stamp = time_stamp
-    pk = request_table.insert({'name':req.name,'email':req.email,'phone':req.phone,'loc':req.loc
-    ,'h_class':req.h_class,'type':req.type,'budget':req.budget,'size':req.size,'bed_num':req.bed_num
-    ,'liv_num':req.liv_num,'bath_num':req.bath_num,'style':req.style,'prefer_date':req.prefer_date,'time_stamp':req.time_stamp,'gender':req.gender})
-    req.id = pk
-    return req
+    
+    statement = 'SELECT * FROM deco_request WHERE email="'+req.email+'"'
+    email_cnt = 0
+    for row in db.query(statement):
+        email_cnt = email_cnt + 1
+    
+    statement = 'SELECT * FROM deco_request WHERE phone="'+req.phone+'"'
+    phone_cnt = 0
+    for row in db.query(statement):
+        phone_cnt = phone_cnt + 1
+    
+    return_code = 0
+    #return code 0=good, 1=email duplication, 2=phone duplication, 3= both duplicate
+    if email_cnt>0 and phone_cnt==0:
+        return_code = 1
+    if email_cnt==0 and phone_cnt>0:
+        return_code = 2
+    if email_cnt>0 and phone_cnt>0:
+        return_code = 3
+    
+    if return_code ==0 :
+        request_table = db['deco_request']
+        time_stamp = datetime.fromtimestamp(time.time())
+        time_stamp = time_stamp.strftime("%Y-%m-%d %H:%M:%S")
+        req.time_stamp = time_stamp
+        pk = request_table.insert({'name':req.name,'email':req.email,'phone':req.phone,'loc':req.loc
+        ,'h_class':req.h_class,'type':req.type,'budget':req.budget,'size':req.size,'bed_num':req.bed_num
+        ,'liv_num':req.liv_num,'bath_num':req.bath_num,'style':req.style,'prefer_date':req.prefer_date,'time_stamp':req.time_stamp,'gender':req.gender})
+        req.id = pk
+        return return_code
+    else :
+        return return_code