def getordersapi(): useremail = session.get('useremail') userid = session.get('id') getordersapimessage = "未付款" if useremail: getorderdata = request.get_json() for i in getorderdata: if (getorderdata[i] == None): return {"error": True, "message": "輸入有空白"}, 400 #訂單存進資料庫 tripordernumber = UseData.Ordersave(useremail, userid, getorderdata, getordersapimessage) #連線取訂單付款 tappaypaybyprime = usetappay.paybyprime(getorderdata) if tappaypaybyprime["status"] == 0: getordersapimessage = UseData.Orderupdate(getorderdata) getordersapi = { "data": { "number": tripordernumber, "payment": { "status": 0, "message": getordersapimessage } } } else: return {"error": True, "message": tripordernumber + "訂單錯誤"}, 400 return getordersapi else: return {"error": True, "message": "未登入"}, 403
def attractionId(attractionId): IdCount = UseData.CheakIdCount() attractionId = int(attractionId) if attractionId <= int(IdCount) and attractionId >= 1: data = UseData.LoadDataToId(attractionId) # print(data) return Response(json.dumps({"data": data}, sort_keys=False), mimetype='application/json') else: abort(400)
def usercheck(): # print("request.method:", request.method) 連線方式 useremail = session.get('useremail') username = session.get('username') userid = session.get('id') if useremail and username and userid: # 檢核登入狀態 if request.method == "GET": # print("登入中") return { "data": { "id": userid, "name": username, "email": useremail } } # 登出 if request.method == "DELETE": session.clear() getdata.clear() return {"ok": True} else: data = request.get_json() if data != None: useremail = data['email'] userpassword = data['password'] # 註冊 if (data.get('name') != None and request.method == "POST"): username = data['name'] # 檢查輸入是否為空白 if not useremail.strip() or not userpassword.strip( ) or not username.strip(): return {"error": True, "message": "檢查輸入是否為空白!"} else: state = UseData.Registered(username, useremail, userpassword) data = {} return state # 登入 if (data.get('name') == None and request.method == "PATCH"): # 檢查輸入是否為空白 if not useremail.strip() or not userpassword.strip(): return {"error": True, "message": "檢查輸入是否為空白!"} else: state, DBloaddata = UseData.Signin(useremail, userpassword) if (state.get('ok')): session['useremail'] = useremail session['username'] = DBloaddata[1] session['id'] = DBloaddata[0] # print("session", session) data = {} return state else: return {"data": None}
def apibooking(): useremail = session.get('useremail') username = session.get('username') userid = session.get('id') if useremail and username and userid: if request.method == "GET": return Response(json.dumps(getdata, sort_keys=False), mimetype='application/json') if request.method == "POST": orderdata = request.get_json() id = orderdata['attractionId'] apigetdata = UseData.LoadDataToId(id) # apigetdata = apianalysis.apiget(id) # print("apigetdata",apigetdata) getdata["data"] = {} getdata["data"]["attraction"] = apigetdata getdata["data"]["date"] = orderdata['date'] getdata["data"]["time"] = orderdata['time'] getdata["data"]["price"] = orderdata['price'] if (getdata == None or orderdata['date'] == None or orderdata['time'] == None or orderdata['price'] == None): return abort(400) if getdata != None: return {"ok": True} else: return abort(500) if request.method == "DELETE": getdata.clear() return {"ok": True} else: return {"error": True, "message": "未登入"}, 403
def attraction(id): IdCount = UseData.CheakIdCount() attractionId = int(id) if attractionId <= int(IdCount) and attractionId >= 1: return render_template("attraction.html") else: abort(400)
def getordataapi(ordernumber): useremail = session.get('useremail') if useremail: orderdataapi = UseData.getorderdata(ordernumber, useremail) return Response(json.dumps(orderdataapi, sort_keys=False), mimetype='application/json') else: return {"error": True, "message": "未登入"}, 403
def getbaseapi(): WebPage = request.args.get("page", 0) WebKeyword = request.args.get("keyword", None) data = UseData.LoadDataToDB(WebPage, WebKeyword) # data=data[12*int(WebPage):12*(int(WebPage)+1)] if (len(data) >= 12): return Response(json.dumps({ "nextpage": int(WebPage) + 1, "data": data }, sort_keys=False), mimetype='application/json') if (len(data) < 12) and (len(data) >= 1): return Response(json.dumps({ "nextpage": None, "data": data }, sort_keys=False), mimetype='application/json') else: abort(500)
def getordernumber(): useremail = session.get('useremail') getordernumberdata = UseData.getordername(useremail) return Response(json.dumps(getordernumberdata, sort_keys=False), mimetype='application/json')