示例#1
0
def get_order_status(id):
    db, cursor = get_db()
    sql = "SELECT o.name, o.phone, o.order_num, o.id_number, o.status, os.status as round_status" \
          " FROM orders o INNER JOIN order_set os on o.round_id = os.id" \
          " WHERE o.id=%s"
    cursor.execute(sql, id)
    record = cursor.fetchone()
    if record is None:
        return make_response(msg="预约编号不存在", code=100)

    if record['round_status'] == 0:
        return make_response(msg="抽签未开始", code=200)
    record.pop('round_status')

    if record['status'] == 0:
        return make_response(msg="未中签", code=300)

    name_len = len(record['name'])
    if name_len < 3:
        record['name'] = record['name'][0] + '*'
    else:
        record['name'] = record['name'][0] + '*' * (name_len -
                                                    2) + record['name'][-1]
    try:
        record[
            'phone'] = record['phone'][0:3] + '*' * 4 + record['phone'][7:11]
        record['id_number'] = record['id_number'][0:5] + '*' * 9 + record[
            'id_number'][-4:]
    except IndexError:
        pass
    return make_response(data=record)
示例#2
0
def getPatients():
    cachedResults = redis.keys()
    if not cachedResults:
        all_Products = Product.query.all()
        result = patients_schema.dump(all_Products)
        for resu in result:
            hash = calHash(resu["name"])
            redis.set(hash, json.dumps(resu), 120)
        return make_response(jsonify(result), 200)
    else:
        return make_response(jsonify(redis.mget(cachedResults)), 202)
示例#3
0
def admin_login():
    username = request.form.get('username')
    password = request.form.get('password')
    if username is None or password is None:
        return make_response(msg="信息不完整", code=100)

    msg = check_admin(username, password)
    if msg:
        return make_response(msg=msg, code=200)
    session.clear()
    session['username'] = username
    return make_response(msg="登录成功")
示例#4
0
def order_success_list(id):
    db, cursor = get_db()
    cursor.execute("SELECT status FROM order_set WHERE id=%s", id)
    round = cursor.fetchone()
    if round is None:
        return make_response(msg="该预约场次不存在", code=100)
    if round['status'] == 0:
        return make_response(msg="该预约场次未开始抽签", code=200)

    cursor.execute("SELECT phone, name, id_number, order_num, id"
                   " FROM orders WHERE status=1 AND round_id=%s", id)
    data = cursor.fetchall()
    return make_response(data=data)
示例#5
0
def set_order():
    current_time = datetime.now()
    start_time = request.form.get('start_time')
    end_time = request.form.get('end_time')
    total = request.form.get('total', type=int)
    order_max = request.form.get('order_max', type=int)

    if start_time is None:
        return make_response(msg="未设置开始日期", code=100)
    if end_time is None:
        return make_response(msg="未设置结束日期", code=100)
    if total is None:
        return make_response(msg="未设置总量", code=100)
    if order_max is None:
        return make_response(msg="未设置预约数量", code=100)
    try:
        start_time = datetime.strptime(start_time, "%Y-%m-%d %H:%M:%S")
        end_time = datetime.strptime(end_time, "%Y-%m-%d %H:%M:%S")
    except ValueError:
        return make_response(msg="日期格式错误", code=200)
    if start_time < current_time or start_time > end_time or \
            order_max > total or total < 1 or order_max < 1:
        return make_response(msg="设置信息错误", code=201)

    db, cursor = get_db()
    cursor.execute("SELECT id FROM order_set WHERE status=0")
    if cursor.fetchone() is not None:
        return make_response(msg="存在未进行抽签的预约", code=300)

    cursor.execute("INSERT INTO order_set(start_time, end_time, total, order_max) "
                   "values (%s, %s, %s, %s)", (start_time, end_time, total, order_max))
    db.commit()
    return make_response(msg="设置成功")
示例#6
0
def order_list():
    db, cursor = get_db()
    cursor.execute("SELECT * FROM order_set ORDER BY status, id DESC")
    data = cursor.fetchall()
    for record in data:
        record['start_time'] = record['start_time'].strftime('%Y-%m-%d %H:%M:%S')
        record['end_time'] = record['end_time'].strftime('%Y-%m-%d %H:%M:%S')
    return make_response(data=data)
示例#7
0
def order_info():
    db, cursor = get_db()
    cursor.execute(
        "SELECT * FROM order_set ORDER BY id DESC LIMIT 1")  # 只返回最新的一条记录
    data = cursor.fetchone()
    data['start_time'] = data['start_time'].strftime('%Y-%m-%d %H:%M:%S')
    data['end_time'] = data['end_time'].strftime('%Y-%m-%d %H:%M:%S')
    return make_response(data=data)
示例#8
0
def new_order():
    name = request.form.get('name')
    if name is None:
        return make_response(msg="名字为空", code=111)
    phone = request.form.get('phone')
    if phone is None:
        return make_response(msg="电话号码为空", code=111)
    id_number = request.form.get('id_num')
    if id_number is None:
        return make_response(msg="电话号码为空", code=111)
    order_num = request.form.get('order_num')
    if order_num is None:
        return make_response(msg="订单数量为空", code=111)

    time_now = datetime.datetime.now()
    sql1 = """SELECT * FROM order_set WHERE status=0 """
    db, cursor = get_db()
    cursor.execute(sql1)
    result = cursor.fetchone()
    if result is None:
        return make_response(msg="预约不存在", code=111)
    round_id = result['id']
    start_time = result['start_time']
    end_time = result['end_time']
    if (time_now < start_time) | (time_now > end_time) | round_id is None:
        return make_response(msg="当前时间不可预订口罩", code=111)

    cursor.execute(
        "SELECT id FROM orders"
        " WHERE (phone=%s OR id_number=%s) AND round_id >= %s AND status=1",
        (phone, id_number, round_id - 3))
    if cursor.fetchone() is not None:
        return make_response(msg="该手机号或身份证号码近期已中签过口罩", code=111)

    cursor.execute(
        "SELECT id FROM orders"
        " WHERE (phone=%s OR id_number=%s) AND round_id =%s",
        (phone, id_number, round_id))
    if cursor.fetchone() is not None:
        return make_response(msg="该手机号或身份证号码已预约过口罩", code=111)

    sql3 = """INSERT INTO orders(round_id, phone, name, id_number,order_num)
         VALUES (%s, %s, %s, %s,%s)"""
    cursor.execute(sql3, (round_id, phone, name, id_number, order_num))
    db.commit()
    return make_response(msg="插入订单项成功")
示例#9
0
 def wrapped_view(**kwargs):
     username = session.get('username')
     if username is None:
         return make_response(code=300, msg="需要管理员登录")
     return view(**kwargs)
示例#10
0
def finish_order():
    msg = draw_mask()
    if msg:
        return make_response(msg=msg, code=100)
    return make_response()