예제 #1
0
파일: tasks.py 프로젝트: 91money/apiserver1
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']}
예제 #2
0
 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":"保存失败!"
         })
예제 #3
0
    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": "保存失败!"
            })
예제 #4
0
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": "用户未登录或注册"})