def user_add_order(): # 验证用户是否已登录 token = request.args.get('token', None) if token is None: return jsonify({ 'code': 202, 'msg': 'token查询参数必须提供或者登录后获取token' }) if cache.check_token(token): user_id = cache.get_token_user_id(token) order_info = request.get_json() # 验证订单参数(和t_order表字段对应或order_detail) # 下订单的业务处理 # 生成订单号(2019070200001, 2019070200002) dao = OrderDao() next_order_num = dao.next_order_num() order_info['order_num'] = next_order_num order_info['user_id'] = user_id tasks.add_order.delay(**order_info) return jsonify({ 'code': 201, 'msg': '正在抢单', 'oder_num': next_order_num })
def add_order(**order_info): # 被Worker工作进程执行 # 确定order_info 包含order_num(订单号)信息 dao = OrderDao() if dao.save('t_order', **order_info): cache.add_qbuy_order(order_info['order_num'], order_info['user_id']) return {'msg': '下单成功!', 'user_id': order_info['user_id']}
def post(self): json = request.get_json() dao = OrderDao() peo_count = json.get("peo_count") child_count = json.get("child_count") scenicid = json.get("scenicid") date = request.form.get("date") price = request.form.get("price") order_time = datetime.now() username = json.get("username") phone_num = json.get("phone_num") email = json.get("email") token = json.get("token") p_num = r.get(token) user_dao = UserDao() user_id = user_dao.user_id_list(p_num) todao = TeOrderDao() order_code = todao.next_order_num() try: dao.save("travel_infor", **{ "code":order_code, "order_status":0, "start_time":date, "order_time":order_time, "price":price, "scenic_id":scenicid, "user_id": user_id }) dao.save("contact_infor",**{ "name":username, "phone_num":phone_num, "email":email, "user_id":user_id }) order_id = dao.order_list(order_code) dao.save("order_detail", **{ "adult_num": peo_count, "child_num": child_count, "flight_id": 1, "insurance": 1, "order_id":order_id }) return jsonify({ "code": 703, "msg": "成功!" }) except: return jsonify({ "code": 704, "msg": "保存失败!" })
def order_detail(): try: token = request.args.get("token") if not token: return jsonify({"code": 400, "msg": "您还未登录,请先登录!"}) user_id = get_token_user_id(token) # 通过token获取id order_id = request.args.get("order_id") dao = OrderDao() data = dao.order_details(order_id, user_id) # 执行添加购物车函数 return jsonify({"code": 200, "msg": "获取订单详情成功", "data": data}) except: return jsonify({"code": 400, "msg": "获取订单详情失败"})
def pay_order(): try: token = request.args.get("token") if not token: return jsonify({"code": 400, "msg": "您还未登录,请先登录!"}) order_id = request.form.get("order_id") user_id = get_token_user_id(token) pay_pwd = request.form.get("pay_str") # 支付密码 dao = OrderDao() msg = dao.pay_order(user_id, order_id, pay_pwd) return jsonify({"code": 200, "msg": msg}) except: return jsonify({"code": 400, "msg": "支付失败"})
def order_list(): try: token = request.args.get("token") if not token: return jsonify({"code": 400, "msg": "您还未登录,请先登录!"}) user_id = get_token_user_id(token) # 通过token获取id dao = OrderDao() data = dao.order_list(user_id) return jsonify({"code": 200, "msg": "添加购物车成功", "data": data}) except: return jsonify({"code": 400, "msg": "获取订单列表成功"})
def get(self): dao = OrderDao() data = dao.tn_list("travel_infor") if data: return jsonify({ "code":701, "msg":"成功!", "data":data }) else: return jsonify({ "code": 702, "msg": "没有数据!" })
def create_order(): try: token = request.args.get("token") if not token: return jsonify({"code": 400, "msg": "您还未登录,请先登录!"}) user_id = get_token_user_id(token) # 通过token获取id dao = OrderDao() dao.create_order(user_id) data = dao.order_data(user_id) dao.delete_cart(user_id) return jsonify({"code": 200, "msg": "下单成功", "data": data}) except: return jsonify({"code": 400, "msg": "下单失败"})
def cancel_order(): token = request.args.get("token", None) order_num = request.args.get("trade_number") if token is None: return jsonify({"code": 201, "msg": "token查询参数必须提供"}) u_id = cache_.get_token_user_id(token) if u_id: order_cancel = OrderDao() delete_order = order_cancel.delete_order(u_id, order_num) if delete_order: return jsonify({"code": 200, "msg": "已关闭!"}) else: return jsonify({"code": 200, "msg": "取消订单失败!"}) return jsonify({"code": 201, "msg": "用户还未登录或注册"})
def post(self): json = request.get_json() scenicid = json.get("scenicid") dao = OrderDao() data = dao.price_list("scenic_date_price",scenicid) if data: return jsonify({ "code":8101, "msg":"查询成功!", "data":data }) else: return jsonify({ "code":8102, "msg":"没有该景点!" })
def order_detail(): token = request.args.get("token", None) order_num = request.args.get("trade_number") if token is None: return jsonify({"code": 201, "msg": "token查询参数必须提供"}) u_id = cache_.get_token_user_id(token) if u_id: order_detail_obj = OrderDao() order_detail = order_detail_obj.get_order_detail(u_id, order_num) return jsonify({ "code": 200, 'msg': "ok", "order_detail": order_detail }) return jsonify({"code": 201, "msg": "用户还未登录或注册"})
def get_order_received(): # 验证用户是否已登录 token = request.get_json().get('token', None) if cache.check_token(token): user_id_id = cache.get_token_user_id(token) dao = OrderDao() order_list_rec = dao.get_order_list(user_id_id ,1) return jsonify({ 'code': 200, 'msg': '已支付订单查询成功', 'order_list': order_list_rec }) else: return jsonify({ 'code': 400, 'msg': 'token查询参数必须提供或者登录后获取token' })
def get_order_arrearage(): # 验证用户是否已登录 token = request.get_json().get('token', None) if cache.check_token(token): user_id_id = cache.get_token_user_id(token) dao = OrderDao() order_list_ara = dao.get_order_sts(user_id_id ,0) return jsonify({ 'code': 200, 'msg': '待支付订单查询成功', 'order_list': order_list_ara }) return jsonify({ 'code': 400, 'msg': 'token查询参数必须提供或者登录后获取token' })
def get_order_evaluated(): # 验证用户是否已登录 token = request.get_json().get('token', None) if cache.check_token(token): user_id_id = cache.get_token_user_id(token) dao = OrderDao() order_list_eva = dao.get_order_sts(user_id_id ,2) return jsonify({ 'code': 200, 'msg': '待评价订单查询成功', 'order_list': order_list_eva }) else: return jsonify({ 'code': 400, 'msg': 'token查询参数必须提供或者登录后获取token' })
def pay_go(): args = eval(request.get_data()) user_id = args.get("user_id") shop_id = args.get("shop_id") sql = "select * from carts left join goods on carts.cart_goods_id = goods.id where cart_good_select = 1 and cart_user_id = %s and cart_shop_id = %s" data = OrderDao().query(sql, user_id, shop_id) if not data: return jsonify({ "code": 207, "msg": "当前购物车为空" }) sum = 0 order_num = datetime.now().strftime("%Y%m%d%H%M%S") + uuid.uuid4().hex[-10:] for good in data: dic = { "order_num": order_num, "cart_card": good.get("cart_card"), "order_goods_id": good.get("cart_goods_id"), "order_goods_num": good.get("cart_good_num"), "order_shop_id": good.get("cart_shop_id"), "order_user_id": good.get("cart_user_id"), "order_time": datetime.now().strftime("%Y-%m-%d %H:%M:%S") } sum += float(good.get("goods_min_price")) * int(good.get("cart_good_num")) dao.save(**dic) r.setex(order_num, sum, 900) r2.delete(str(user_id) + "-" + str(shop_id)) sql = "delete from carts where (cart_user_id, cart_shop_id) = (%s, %s)" cartdao.query(sql, user_id, shop_id) return jsonify({ "code": 200, "msg": "ok", "data": { "u_tel": UserDao().get_profile(user_id).get("u_tel"), "addr": "北京", "data": data } })
def post(self): json = request.get_json() name = json.get("name") phone_num = json.get("phone_num") email = json.get("email") document_type = json.get("document_type") id_number = json.get("id_number") token = json.get("token") p_num = r.get(token) user_dao = UserDao() user_id = user_dao.user_id_list(p_num) dao = OrderDao() try: dao.save("travel_infor",**{ "name":name, "phone_num":phone_num, "email":email, "document_type":document_type, "id_number":id_number, "user_id":user_id }) return jsonify({ "code":705, "msg":"成功!", "data":{ "name":name, "phone_num":phone_num, "email":email, "document_type":document_type, "id_number":id_number } }) except: return jsonify({ "code":706, "msg":"保存失败!" })
def my_order(): token = request.headers.get("token") if token is None: return jsonify({{"code": 201, "msg": "token查询参数必须提供"}}) u_id = cache_.get_token_user_id(token) if u_id: # 如果用户登录,返回订单的信息 order = OrderDao() order_all_info = order.get_order_info(u_id) # 订单的全部信息 order_pay = order.get_order_pay_state(u_id).get("pay") # 已支付的订单信息 order_no_pay = order.get_order_pay_state(u_id).get( "no_pay") # 未支付的订单信息 if any((order_all_info, order_pay, order_no_pay)): return jsonify({ "code": 200, 'msg': "ok", 'data': { "order_all_info": order_all_info, "order_pay": order_pay, "order_no_pay": order_no_pay } }) else: return jsonify({"code": 200, "msg": "用户暂未相关订单"}) return jsonify({"code": 201, "msg": "用户还未登录或注册"})
from flask import Blueprint, jsonify, request from dao.order_dao import OrderDao from libs import cache dao = OrderDao() blue_order = Blueprint('order_api', __name__) @blue_order.route('/add_order/', methods=('POST', )) #添加订单 def add_order(): req_data = None if request.headers['Content-Type'].startswith('application/json'): req_data = request.get_json() if req_data is None: return jsonify({'code': 9000, 'msg': '请上传json数据,且参数必须按api接口标准给定'}) token = req_data.get('token', None) if token is None: return jsonify({'code': 202, 'msg': '没有登录,请先登录'}) if bool(cache.check_token(token)): print() user_id = cache.get_token_user_id(token) kfCion_totel = req_data['kfCoin'] users = dao.check_user(user_id) print(users) if int(users['userKfCoin']) < kfCion_totel: return jsonify({'code': 202, 'msg': '空粉币不足不能下单'}) else: req_data['totalfuZuan'] = 0 req_data['totalkfCoin'] = kfCion_totel req_data['pay'] = 0
def payorder(): token = request.get_json().get('token', None) if cache.check_token(token): user_id_id = cache.get_token_user_id(token) order_list = request.get_json().get("order_list") total = request.get_json().get("total") paypassword = request.get_json().get("paypassword") dao2 = OrderDao() if all((order_list, total)): order_rd_list = rd.lindex(order_list[0], 0) if not order_rd_list: #删除订单 for i in range(len(order_list)): dao2.UpdateOrder(user_id_id, 5, order_list[i]) return jsonify({'code': 404, 'msg': '订单已过期'}) order_rd_list = order_rd_list.decode()[1:-1] order_rd_list = order_rd_list.split("'") for i in range(len(order_list)): print(order_list[i], order_rd_list[i * 2 + 1]) if order_list[i] != order_rd_list[i * 2 + 1]: return jsonify({'code': 400, 'msg': '支付请求出错'}) dao = UserDao() user_info = dao.get_profile(user_id_id)[0] asset = user_info['asset'] pay_pwd = user_info['pay_pwd'] # paypassword = make_password(paypassword) if pay_pwd != paypassword: return jsonify({'code': 400, 'msg': '支付密码错误,请重新输入'}) if asset < total: return jsonify({'code': 400, 'msg': '余额不足,请先充值'}) asset -= total dao.update_asset(user_id_id, asset) for i in range(len(order_list)): dao2.UpdateOrder(user_id_id, 1, order_list[i]) return jsonify({'code': 200, 'msg': '支付成功'}) else: o_num = request.get_json().get("orderid") dao3 = UserDao() dao4 = OrderDao() order_info = dao4.get_oreder_info(o_num) if not order_info: return jsonify({"code": 401, "msg": "订单不存在"}) order_info = order_info[0] total1 = order_info['o_relpay'] user_info = dao3.get_profile(user_id_id) asset = user_info['asset'] pay_pwd = user_info['pay_pwd'] if pay_pwd != paypassword: return jsonify({'code': 400, 'msg': '支付密码错误,请重新输入'}) if asset < total1: return jsonify({'code': 400, 'msg': '余额不足,请先充值'}) asset -= total1 dao3.update_asset(user_id_id, asset) dao4.UpdateOrder(user_id_id, 1, o_num) return jsonify({'code': 200, 'msg': '支付成功'}) else: return jsonify({'code': 400, 'msg': '您还未登陆,请先登录'})
def post(self): json = request.get_json() dao = OrderDao() peo_count = json.get("peo_count") child_count = json.get("child_count") if child_count is None: child_count = 0 date = json.get("date") price = json.get("price") scenicid = json.get("scenicid") scenic_name = dao.scenic_list("scenics",scenicid)[0]["name"] cityname = json.get("cityname") price_z = price*peo_count + price*child_count*0.8 lals = getcode(scenic_name) dao.scenic_insert(lals,scenicid) lal = getcode(cityname) # 经纬度 dis = dao.travel_type(lal[1],lal[0],scenicid) sc_items = dao.scenic_list("scenics", scenicid) cityid = sc_items[0]["city_id"] city_dao = CityDao() sc_city_name = city_dao.city_name(cityid)[0]["name"] if float(dis[0]["dis"]) > 800: f_dict = { "出发地":cityname, "目的地":sc_city_name, "出发日期":date, "出发时间":"07:05", "到达时间":"09:25", "类型":"惠选经济舱", "航班号":"国航HU7137", "飞行时间":"2小时20分钟" } else: f_dict = { "出发时间":"07:00:00", "返回": "国贸", "备注": "距离远的游客请自行前往集合点" } ins_items = dao.tn_list("insurances") return jsonify({ "code":8103, "msg":"返回数据!", "data":{ "scenic_name":scenic_name, "pro_code":"210107045", "peo_count":peo_count, "child_count":child_count, "date":date, "f_dict":f_dict, "insurances":ins_items, "price_z":price_z } })
def add_order(): token = request.get_json().get("token") if token is None: return jsonify({"code": 201, "msg": "token查询参数必须提供"}) resp = request.get_json() total = resp.get("total") type1 = resp.get("type") c_id = resp.get("course") # 获取的c_id是字符串 <class 'str'> u_id = cache_.get_token_user_id(token) print(c_id) if u_id: if type1 == "fromcart": # 如果是从购物车提交订单 cart_dao = CartDao() course_info = cart_dao.will_pay_course(c_id, u_id).get("course_list") total_price = cart_dao.will_pay_course(c_id, u_id).get("total_price") # print("aaaaaaaaaa", course_info,type(course_info)) if len(c_id) > 1: if total_price == total: # 提交订单传递的总价是否和后台计算的总价相等 order_obj = OrderDao() # user_course = UserCourseDao() order_num = order_obj.next_order_num() # 生成订单编号 for course in course_info: # 创建订单记录 order_success = order_obj.save( "orders", **{ "order_num": order_num, "user_id": u_id, "course_id": course.get("id"), "price": course.get("price") }) if order_success: # 如果创建订单,购买的课程存入用户课程表中成功,则删除购物车记录 cart_delete = cart_dao.delete_user_cart_course( course.get("id"), u_id) if cart_delete: continue # 返回订单信息 return jsonify({ "code": 200, "order_num": order_num, "data": course_info }) return jsonify({"code": 201, "msg": "价格不正确"}) elif len(c_id) == 1: if total_price == total: order_obj = OrderDao() order_num = order_obj.next_order_num() order_success = order_obj.save( "orders", **{ "order_num": order_num, "user_id": u_id, "course_id": course_info.get("id"), "price": course_info.get("price") }) if order_success: # 如果创建订单记录成功,返回订单信息 cart_delete = cart_dao.delete_user_cart_course( course_info.get("id"), u_id) if cart_delete: return jsonify({ "code": 200, "order_num": order_num, "data": course_info }) return jsonify({"code": 201, "msg": "价格不正确"}) elif type1 == "fromcombat": # 如果是立即购买提交订单 pay_dao = PayDao() cid = pay_dao.get_course_id(c_id) course_info = pay_dao.get_pay_course(cid).get("pay_course") total_price = pay_dao.get_pay_course(cid).get("total_price") if total_price == total: # 总价相等,创建一条订单记录 order_obj = OrderDao() order_num = order_obj.next_order_num() order_success = order_obj.save( "orders", **{ "order_num": order_num, "user_id": u_id, "course_id": course_info[0].get("id"), "price": course_info[0].get("price") }) if order_success: # 如果创建订单记录成功,返回订单信息 return jsonify({ "code": 200, "order_num": order_num, "data": course_info }) return jsonify({"code": 201, "msg": "价格不正确"}) return jsonify({"code": 201, "msg": "用户未登录或注册"})
def __init__(self): self.order_dao = OrderDao()