Exemplo n.º 1
0
def get_order(id):
    """
    提交我的订单
    """
    user_id = session['user_id']
    begin_date = datetime.datetime.strptime(request.form.get('start_date'),
                                            '%Y-%m-%d')
    end_date = datetime.datetime.strptime(request.form.get('end_date'),
                                          '%Y-%m-%d')
    times = end_date - begin_date
    days = times.days + 1
    house = House.query.get(id)
    price = house.price
    amount = days * price
    order = Order()
    order.user_id = user_id
    order.house_id = id
    order.begin_date = begin_date
    order.end_date = end_date
    order.days = days
    order.house_price = price
    order.amount = amount
    order.add_update()

    return jsonify(code=status_code.OK)
Exemplo n.º 2
0
def create_order():

    house_id = request.form.get('house_id')
    # 对前端传过来的时间值进行处理成可以做加法运算的
    begin_date = datetime.strptime(request.form.get('begin_date'), '%Y-%m-%d')
    end_date = datetime.strptime(request.form.get('end_date'), '%Y-%m-%d')
    user_id = session['user_id']

    # 验证是否有填写时间
    if not all([begin_date, end_date]):
        return jsonify(status_code.ORDER_BEGIN_END_DATA_NOT_NULL)
    # 验证初始时间是否大于结束时间
    if not begin_date < end_date:
        return jsonify(status_code.ORDER_BEGIN_DATA_GT_END_DATA_ERROE)
    # 获取房屋信息
    try:
        house = House.query.get(house_id)
    except:
        return jsonify(status_code.DATABASE_ERROR)
    # 创建订单对象
    order = Order()
    order.house_id = house_id
    order.end_date = end_date
    order.begin_date = begin_date
    order.user_id = user_id
    order.days = (end_date - begin_date).days + 1
    order.house_price = house.price
    order.amount = order.days * order.house_price

    order.add_update()

    return jsonify(status_code.SUCCESS)
Exemplo n.º 3
0
    def post(self):
        user_id = session['u_id']
        house_id = request.form.get('house_id')
        price = request.form.get('price')
        begin_date = datetime.strptime(request.form.get('begin_date'),
                                       '%Y-%m-%d')
        end_date = datetime.strptime(request.form.get('end_date'), '%Y-%m-%d')
        if not all([house_id, begin_date, end_date]):
            return jsonify(status_code.DATA_NOT_FULL)
        if begin_date > end_date:
            return jsonify(status_code.CREATE_ORDER_END_DATA_ERROR)
        order = Order()
        order.user_id = user_id
        order.house_id = house_id
        order.begin_date = begin_date
        order.end_date = end_date
        order.days = (end_date - begin_date).days + 1
        order.house_price = int(price)
        order.amount = order.days * order.house_price

        try:
            order.add_update()
        except Exception as e:
            return jsonify(status_code.DATABASE_ERROR)
        return jsonify(status_code.SUCCESS)
Exemplo n.º 4
0
def post_order():
    order_dict = request.form
    house_id = order_dict.get('house_id')
    start_time = datetime.strptime(order_dict.get('start_time'), '%Y-%m-%d')
    end_time = datetime.strptime(order_dict.get('end_time'), '%Y-%m-%d')

    if not all([house_id, start_time, end_time]):
        return jsonify(status_code.PARAMS_ERROR)

    if start_time > end_time:
        return jsonify(status_code.ORDER_START_TIME_GT_END_TIME)

    house = House.query.get(house_id)
    order = Order()
    order.user_id = session['user_id']
    order.house_id = house_id
    order.begin_date = start_time
    order.end_date = end_time
    order.house_price = house.price
    order.days = (end_time - start_time).days + 1
    order.amount = order.days * order.house_price
    try:
        order.add_update()
        return jsonify(code=status_code.OK)
    except Exception as e:
        return jsonify(status_code.DATABASE_ERROR)
Exemplo n.º 5
0
def create_order():

    begin_date = datetime.strptime(request.form.get('begin_date'), '%Y-%m-%d')
    end_date = datetime.strptime(request.form.get('end_date'), '%Y-%m-%d')
    house_id = request.form.get('house_id')
    user_id = session['user_id']

    if not all([begin_date, end_date]):
        return jsonify(status_code.ORDER_BEGIN_END_DATA_NOT_NULL)

    if begin_date > end_date:
        return jsonify(status_code.ORDER_BEGIN_DATA_GT_END_DATE_ERROR)

    house = House.query.get(house_id)

    order = Order()
    order.user_id = user_id
    order.house_id = house_id
    order.begin_date = begin_date
    order.end_date = end_date
    order.days = (end_date - begin_date).days + 1
    order.house_price = house.price
    order.amount = order.days * order.house_price

    order.add_update()

    return jsonify(status_code.SUCCESS)
Exemplo n.º 6
0
def get_order():
    house_id = request.form.get('house_id')
    begin_date = request.form.get('start_date')
    end_date = request.form.get('end_date')
    if not all([house_id, begin_date, end_date]):
        return jsonify(status_code.PARAMS_ERROR)
    x = (datetime.strptime(end_date, '%Y-%m-%d') - datetime.strptime(begin_date, '%Y-%m-%d')).days
    # 如果开始时间大于结束时间. 进行判断 返回参数错误
    if x < 0:
        return jsonify(status_code.END_TIME_IS_ERROR)

    days = x + 1
    house_price = House.query.filter_by(id=house_id).first().price
    amout = days * house_price
    # 创建订单
    order = Order()
    order.user_id = session['user_id']
    order.house_id = house_id
    order.begin_date = begin_date
    order.end_date = end_date
    order.days = days
    order.house_price = house_price
    order.amout = amout
    try:
        order.add_update()
        return jsonify(status_code.SUCCESS)
    except:
        return jsonify(status_code.DATABASE_ERROR)
Exemplo n.º 7
0
def order():
    # 接收参数
    dict = request.form
    house_id = int(dict.get('house_id'))
    start_date = datetime.strptime(dict.get('start_date'), '%Y-%m-%d')
    end_date = datetime.strptime(dict.get('end_date'), '%Y-%m-%d')
    # 验证有效性
    if not all([house_id, start_date, end_date]):
        return jsonify(status_code.PARAMS_ERROR)
    if start_date > end_date:
        return jsonify(status_code.ORDER_START_END_TIME_ERROR)
    # 查询房屋对象
    try:
        house = House.query.get(house_id)
    except:
        return jsonify(status_code.DATABASE_ERROR)
    # 创建订单对象
    order = Order()
    order.user_id = session['user_id']
    order.house_id = house_id
    order.begin_date = start_date
    order.end_date = end_date
    order.days = (end_date - start_date).days + 1
    order.house_price = house.price
    order.amount = order.days * order.house_price

    try:
        order.add_update()
    except:
        return jsonify(status_code.DATABASE_ERROR)

    # 返回信息
    return jsonify(code=status_code.OK)
Exemplo n.º 8
0
def create_order():
    if request.method == "POST":
        house_id = request.form.get('house_id')
        # 对前端传过来的时间值进行处理成可以做加法运算的
        print(request.form.get('begin_date'))
        begin_date = datetime.strptime(request.form.get('begin_date'),
                                       '%Y-%m-%d')
        end_date = datetime.strptime(request.form.get('end_date'), '%Y-%m-%d')
        print(begin_date, end_date)
        user_id = session['user_id']

        # 验证是否有填写时间
        if not all([begin_date, end_date]):
            return jsonify(status_code.ORDER_BEGIN_END_DATA_NOT_NULL)
        # 验证初始时间是否大于结束时间
        if begin_date > end_date:
            return jsonify(status_code.ORDER_BEGIN_DATA_GT_END_DATA_ERROE)
        # 获取房屋信息
        try:
            house = House.query.get(house_id)
        except:
            return jsonify(code=status_code.DATABASE_ERROR)
        # 创建订单对象
        order = Order()
        order.house_id = house_id
        order.end_date = end_date
        order.begin_date = begin_date
        order.user_id = user_id
        order.days = (end_date - begin_date).days + 1
        order.house_price = house.price
        order.amount = order.days * order.house_price

        order.add_update()
        data = {"order_id": order.id, "order_amount": order.amount}
        print(data)
        return jsonify(code=status_code.ok, data=data)
    else:
        id = request.args.get('id')
        amount = request.args.get('amount')
        print(id, amount)
        return render_template('order_success.html',
                               data={
                                   'id': id,
                                   'amount': amount
                               })
    def post(self):
        list_ = []
        parse = parser.parse_args()
        staff_id = parse.get('staff_id')
        number = parse.get('number')
        price = parse.get('price')
        address = parse.get('address')
        phone = parse.get('phone')
        consignee = parse.get('consignee')

        datetime_now = datetime.datetime.now()
        date_stamp = str(int(time.mktime(datetime_now.timetuple())))
        data_microsecond = str("%06d" % datetime_now.microsecond)
        date_stamp = date_stamp + data_microsecond

        order = Order()
        order.order_no = date_stamp
        order.price = price
        order.user_id = staff_id
        order.number = number
        order.address = address
        order.phone = phone
        order.consignee = consignee
        db.session.add(order)
        db.session.commit()

        point = Point.query.filter(Point.staff_id == staff_id).first()
        orders = Order.query.filter(Order.user_id == staff_id).all()
        if orders:
            for order in orders:
                list_.append(order.price)
            prices = sum(list_)
            print(prices)
            point.sumprice = prices
            print(point.sumprice)
            db.session.commit()
        else:
            pass

        return jsonify({'msg': '添加成功'})
Exemplo n.º 10
0
def bookings_post(id):
    start_date = request.form.get('start_date')
    end_date = request.form.get('end_date')
    live_time = datetime.strptime(end_date, '%Y-%m-%d') - datetime.strptime(
        start_date, '%Y-%m-%d')
    if live_time.days < 0:
        return jsonify(status_code.ORDER_DATE_IS_INVALID)
    house = House.query.filter_by(id=id).first()
    order = Order()
    order.user_id = session['user_id']
    order.house_id = id
    order.begin_date = start_date
    order.end_date = end_date
    order.days = live_time.days
    order.house_price = house.price
    order.amount = live_time.days * house.price

    try:
        order.add_update()
    except Exception as e:
        db.session.rollback()
        return jsonify(status_code.DATABASE_ERROR)
    return jsonify({'code': '200'})
Exemplo n.º 11
0
def shopping(request):
    if request.GET.get('pid'):
        product = Product.objects.get(pid=request.GET.get('pid'))
        if request.user.orders and product.order:
            if request.GET.get('deletepid'):
                order = product.order
                product = Product.objects.get(order_id=order.id)
                product.order_id = None
                product.save()
                order.delete()
                if request.user.orders.first():

                    object_list = [
                        Product.objects.filter(status=1,
                                               is_delete=0,
                                               type=0,
                                               inventory__gt=0),
                        Product.objects.filter(status=1,
                                               is_delete=0,
                                               type=1,
                                               inventory__gt=0),
                        Product.objects.filter(status=1,
                                               is_delete=0,
                                               type=2,
                                               inventory__gt=0),
                        [
                            i.products.first() for i in Order.objects.filter(
                                order_status=1, user_id=request.user.uid)
                        ],
                        [
                            int(
                                sum([
                                    i.products.first().price * i.productnum
                                    for i in Order.objects.filter(
                                        order_status=1,
                                        user_id=request.user.uid)
                                ])) - request.user.score / 10,
                            len([
                                i.products.first()
                                for i in Order.objects.filter(
                                    order_status=1, user_id=request.user.uid)
                            ]), request.user.score / 10
                        ]
                    ]

                    return render(request, 'shopping.html', locals())
                else:
                    return redirect(reverse('app:index'))
            order = product.order
            order.productnum += int(request.GET.get('num'))
            order.save()
            print([
                i.products.first().price * i.productnum
                for i in Order.objects.filter(order_status=1,
                                              user_id=request.user.uid)
            ])
            object_list = [
                Product.objects.filter(status=1,
                                       is_delete=0,
                                       type=0,
                                       inventory__gt=0),
                Product.objects.filter(status=1,
                                       is_delete=0,
                                       type=1,
                                       inventory__gt=0),
                Product.objects.filter(status=1,
                                       is_delete=0,
                                       type=2,
                                       inventory__gt=0),
                # Product.objects.filter(order=order.id)[0]
                [
                    i.products.first()
                    for i in Order.objects.filter(order_status=1,
                                                  user_id=request.user.uid)
                ],
                [
                    int(
                        sum([
                            i.products.first().price * i.productnum
                            for i in Order.objects.filter(
                                order_status=1, user_id=request.user.uid)
                        ])) - request.user.score / 10,
                    len([
                        i.products.first()
                        for i in Order.objects.filter(order_status=1,
                                                      user_id=request.user.uid)
                    ]), request.user.score / 10
                ]
            ]

            return render(request, 'shopping.html', locals())

        order = Order()
        order.user_id = request.user
        order.create_time = datetime.now()
        order.order_status = 1
        order.productnum = request.GET.get('num')
        order.total = int(product.price) * int(request.GET.get('num'))
        order.save()
        product.order = order
        product.save()

        object_list = [
            Product.objects.filter(status=1,
                                   is_delete=0,
                                   type=0,
                                   inventory__gt=0),
            Product.objects.filter(status=1,
                                   is_delete=0,
                                   type=1,
                                   inventory__gt=0),
            Product.objects.filter(status=1,
                                   is_delete=0,
                                   type=2,
                                   inventory__gt=0),
            # Product.objects.filter(order=order.id)[0]
            [
                i.products.first()
                for i in Order.objects.filter(order_status=1,
                                              user_id=request.user.uid)
            ],
            [
                int(
                    sum([
                        i.products.first().price * i.productnum
                        for i in Order.objects.filter(order_status=1,
                                                      user_id=request.user.uid)
                    ])) - request.user.score / 10,
                len([
                    i.products.first()
                    for i in Order.objects.filter(order_status=1,
                                                  user_id=request.user.uid)
                ]), request.user.score / 10
            ]
        ]

        return render(request, 'shopping.html', locals())
    else:
        print(1111111111111111111)
        object_list = [
            Product.objects.filter(status=1,
                                   is_delete=0,
                                   type=0,
                                   inventory__gt=0),
            Product.objects.filter(status=1,
                                   is_delete=0,
                                   type=1,
                                   inventory__gt=0),
            Product.objects.filter(status=1,
                                   is_delete=0,
                                   type=2,
                                   inventory__gt=0),
            # Product.objects.filter(order=order.id)[0]
            [
                i.products.first()
                for i in Order.objects.filter(order_status=1,
                                              user_id=request.user.uid)
            ],
            [
                int(
                    sum([
                        i.products.first().price * i.productnum
                        for i in Order.objects.filter(order_status=1,
                                                      user_id=request.user.uid)
                    ])) - request.user.score / 10,
                len([
                    i.products.first()
                    for i in Order.objects.filter(order_status=1,
                                                  user_id=request.user.uid)
                ]), request.user.score / 10
            ]
        ]

        return render(request, 'shopping.html', locals())