Python电影售票系统

     目   录

一、系统要求

二、用户信息

三、管理系统

1.管理系统

2.用户登录

3.管理登录

4.注册用户

5.找回密码


一、系统要求

电影售票系统程序,应具备以下几点功能:
1.用户认证
      系统用户分为用户、管理员两个角色,系统可根据不同用户角色权限进入不同界面,所有用户角色需要通过身份验证才能登录系统进行操作,角色操作完后可保存信息退出系统。

2.用户登录
      主要实现用户登录系统可查看本人会员信息、购买影票、查看订票、影票退订、修改信息等功能。

3.管理登录
       主要实现管理员登录系统可查看会员和管理信息、添加会员、注销会员、查看购票、影票出售、影票退订、查看影票余票和售票、增删管理、增删影片、修改信息等功能。


二、用户信息

如果需要电影售票管理系统用户信息数据请点击链接进行下载。


三、管理系统

1.管理系统

       主要实现简单电影售票管理系统应用,功能包括会员信息存储、修改、查看等,针对不同角色登录不同模块来完成对应操作。

import json,time,re
from managements import management_login
from users import users_login
from registered import registered
from back import back
read_movie = open('movie.json', 'r', encoding='utf-8')
movie = json.loads(read_movie.read())
read_user = open('user.json', 'r', encoding='utf-8')
user = json.loads(read_user.read())
read_management = open('management.json', 'r', encoding='utf-8')
management = json.loads(read_management.read())
read_ticket_record = open('ticket_record.json', 'r', encoding='utf-8')
ticket_record = json.loads(read_ticket_record.read())

def movie_tickets():
    while True:
        permissions = input('请您选择用户操作(1.用户登录 2.注册用户 3. 找回密码 4.退出系统):')
        if permissions == '1':
            while True:
                login = input('请您选择登录权限(1.个人登录 2.管理登录 3.退出登录):')
                if login == '1':
                    users_login(user, movie, ticket_record)
                elif login == '2':
                    management_login(management, user, movie, ticket_record)
                elif login == '3':
                    break

        elif permissions == '2':
            registered(user)
        elif permissions == '3':
            back(management, user)
        elif permissions == '4':
            break


movie_tickets()

save = open('movie.json', 'w', encoding='utf-8')
json.dump(movie, save, ensure_ascii=False, indent=4)
save = open('user.json', 'w', encoding='utf-8')
json.dump(user, save, ensure_ascii=False, indent=4)
save = open('management.json', 'w', encoding='utf-8')
json.dump(management, save, ensure_ascii=False, indent=4)
save = open('ticket_record.json', 'w', encoding='utf-8')
json.dump(ticket_record, save, ensure_ascii=False, indent=4)

2.用户登录

      主要实现用户登录系统可查看本人会员信息(会员卡号昵称、手机号码等信息)、购买影票(用户可以浏览当前上映的所有影片)、查看订票(用户可查看自己购买所有场次的购票信息)、影票退订(用户可以根据自身需求选择退订影票)、修改信息(可修改昵称、手机号码等信息)等功能。

import re, time

def users_login(x, y, z):
    account = input('请您输入账号:')
    password = input('请您输入密码:')
    if account in x:
        if x[account][0] == password:
            time.sleep(0.5)
            print('密码正确,登录成功!')
            while True:
                operation = input('请您选择操作(1.会员信息 2.购买影票 3.购票信息 4.影票退订 5.修改信息 6.退出系统):')

                if operation == '1':
                    time.sleep(0.5)
                    print('*' * 7 + '会员信息' + '*' * 7)
                    print('会员卡号:{}'.format(account))
                    print('会员昵称:{}'.format(x[account][1]))
                    print('会员性别:{}'.format(x[account][2]))
                    print('手机号码:{}'.format(x[account][3]))
                    print('*' * 21)

                elif operation == '2':
                    time.sleep(0.5)
                    print('*' * 3 + '电影放映表' + '*' * 3)
                    for a, b in list(enumerate(y, 1)):
                        print(a, b['name'])
                    print('*' * 13)

                    buy = int(input('请您选择电影场次:'))
                    time.sleep(0.5)
                    print('*' * 8 + '电影信息' + '*' * 8)
                    print('影名:{}'.format(y[buy - 1]['name']))
                    print('类别:{}'.format(y[buy - 1]['category']))
                    print('导演:{}'.format(y[buy - 1]['director']))
                    print('演员:{}'.format(y[buy - 1]['actor']))
                    print('*' * 23)

                    while True:
                        time.sleep(0.5)
                        print('*' * 13 + '影厅座位' + '*' * 13)
                        for i in y[buy - 1]['seat']:
                            print('  '.join(i))
                        print('*' * 32)
                        choose = input('是否继续购票(1.继续 2.退出):')
                        if choose == '2':
                            break
                        line_numbers = int(input('请您选择影厅行号:'))
                        seat_numbers = int(input('请您选择影厅座号:'))
                        if y[buy - 1]['seat'][line_numbers][seat_numbers] == '■':
                            print('不好意思,座位已选!')
                        else:
                            y[buy - 1]['seat'][line_numbers][seat_numbers] = '■'
                            time.sleep(0.5)
                            print('购票成功,电影名:{} 座位号:{}排{}号'.format(y[buy - 1]['name'], line_numbers, seat_numbers))
                            if account in z and y[buy - 1]['name'] in z[account]:
                                z[account][y[buy - 1]['name']].append(
                                    '{}排{}号'.format(line_numbers, seat_numbers))
                            elif account in z and y[buy - 1]['name'] not in z[account]:
                                z[account][y[buy - 1]['name']] = [
                                    '{}排{}号'.format(line_numbers, seat_numbers)]
                            else:
                                z[account] = {
                                    y[buy - 1]['name']: ['{}排{}号'.format(line_numbers, seat_numbers)]}

                elif operation == '3':
                    if account in z:
                        for i in z[account]:
                            time.sleep(0.5)
                            print('卡号:{} 昵称:{} 影名:{} 座位:{}'.format
                                  (account, x[account][1], i,' '.join(z[account][i])))
                    else:
                        print('未查询到购票信息')
                elif operation == '4':
                    if account in z:
                        for i in z[account]:
                            time.sleep(0.5)
                            print('卡号:{} 昵称:{} 影名:{} 座位:{}'.format(account, x[account][1], i,
                                                                   ' '.join(z[account][i])))
                    print('未查询到订票信息')

                    while True:
                        unsubscribe = input('是否需要退订影票(1.需要 2.退出):')
                        if unsubscribe == '2':
                            break
                        else:
                            name = dict(enumerate(z[account], 1))
                            for i in name:
                                print(i, name[i])
                            movie_number = int(input('请您选择需要退票电影序号:'))
                            number = dict(enumerate(z[account][name[movie_number]], 1))
                            for i in number:
                                print(i, number[i])
                            seat_number = int(input('请您选择需要退票电影座位:'))
                            message = re.findall(r'\d+', number[seat_number])
                            for i in y:
                                if name[movie_number] == i['name']:
                                    i['seat'][int(message[0])][int(message[1])] = '□'
                            z[account][name[movie_number]].remove(number[seat_number])
                            time.sleep(0.5)
                            print('退票成功!')
                            if not z[account][name[movie_number]]:
                                del z[account][name[movie_number]]

                elif operation == '5':
                    time.sleep(0.5)
                    print('*' * 7 + '会员信息' + '*' * 7)
                    print('会员卡号:{}'.format(account))
                    print('会员昵称:{}'.format(x[account][1]))
                    print('会员性别:{}'.format(x[account][2]))
                    print('手机号码:{}'.format(x[account][3]))
                    print('*' * 21)
                    while True:
                        modify = input('是否继续修改(1.继续 2.退出):')
                        if modify == '2':
                            break
                        choose = input('请您选择修改内容(1.会员昵称 2.会员性别 3.手机号码):')
                        if choose == '1':
                            x[account][1] = input('请输入会员昵称:')
                        elif choose == '2':
                            x[account][2] = input('请输入会员性别:')
                        elif choose == '3':
                            x[account][3] = input('请输入手机号码:')

                elif operation == '6':
                    print('系统退出成功,欢迎下次使用!')
                    break
        else:
            print('密码错误,登录失败!')
    else:
        print('账号错误,请您核对!')

3.管理登录

       该系统最高权限,主要实现管理员登录系统可查看会员和管理信息、添加会员、注销会员、查看购票、影票出售、影票退订、查看影票余票和售票、增删管理、增删影片、修改信息等功能。

import  time, re
operation = '''********欢迎使用漫漫影院系统*********
  1.查看信息  2.添加会员  3.注销会员 
  4.查看购票  5.影票出售  6.影票退订
  7.查看余票  8.增删管理  9.增删影片 
 10.销售记录 11.修改信息 12.退出系统
*********************************'''

def management_login(a, b, c, d):
    account = input('请您输入账号:')
    password = input('请您输入密码:')
    if account in a:
        if a[account][0] == password:
            time.sleep(0.5)
            print('密码正确,登录成功!')
            while True:
                print(operation)
                choose = input('请您选择操作选项:')

                if choose == '1':
                    while True:
                        query = input('请你选择查询选项(1.查询会员 2.查询管理 3.退出查询):')
                        if query == '1':
                            for i in b:
                                time.sleep(0.5)
                                print('会员卡号:{}、会员昵称:{}、会员性别:{}、手机号码:{}'.format
                                      (i, b[i][1], b[i][2], b[i][3]))
                        elif query =='2':
                            for i in a:
                                time.sleep(0.5)
                                print('管理账号:{}、管理昵称:{}、管理性别:{}、手机号码:{}'.format
                                      (i, a[i][1], a[i][2], a[i][3]))
                        elif query == '3':
                            break

                elif choose == '2':
                    while True:
                        add = input('是否需要添加会员(1.需要 2.退出):')
                        if add == '2':
                            break
                        else:
                            name = input('请您输入会员昵称:')
                            gender = input('请您输入会员性别:')
                            phone = input('请您输入手机号码:')
                            password = input('请您输入登录密码:')
                            account = []
                            for i in b:
                                account.append(int(i))
                            account.sort()
                            b[str(account[-1] + 1)] = [password, name, gender, phone]
                            time.sleep(0.5)
                            print('注册成功!')
                            time.sleep(0.5)
                            print('会员卡号:{}、登录密码:{}、会员昵称:{}、会员性别:{}、手机号码:{}'.format
                                  (str(account[-1] + 1), password,  name, gender,phone))

                elif choose == '3':
                    while True:
                        delete = input('是否需要注销会员(1.需要 2.取消):')
                        if delete == '2':
                            break
                        cancel = input('请您输入需要注销会员卡号:')
                        if cancel not in b:
                            print('卡号输入有误!')
                        else:
                            del b[cancel]
                            time.sleep(0.5)
                            print('会员注销成功!')

                elif choose == '4':
                    while True:
                        query = input('请您选择查询操作(1.查询个人 2.查询全部 3.退出查询):')
                        if query == '1':
                            query_personal = input('请您输入需要查询会员卡号:')
                            if query_personal in d:
                                for i in d[query_personal]:
                                    time.sleep(0.5)
                                    print('会员卡号:{}、会员昵称:{}、购票影片:{}、影厅座位:{}'.format
                                          (query_personal, b[query_personal][1], i, ' '.join(d[query_personal][i])))
                            else:
                                print('未查询到购票信息!')
                        elif query == '2':
                            for x in d:
                                for y in d[x]:
                                    if x in b:
                                        time.sleep(0.5)
                                        print('会员卡号:{}、会员昵称:{}、购票影片:{}、影厅座位:{}'.format
                                              (x, b[x][1], y, ' '.join(d[x][y])))
                                    else:
                                        time.sleep(0.5)
                                        print('会员卡号:{}、会员昵称:{}、购票影片:{}、影厅座位:{}'.format
                                              (x, a[x][1], y, ' '.join(d[x][y])))

                        elif query == '3':
                            break

                elif choose == '5':
                    card_number = ''
                    judge = input('是否有会员卡(1.有卡 2.无卡):')
                    if judge == '1':
                        card_number = input('请您输入会员卡号:')
                    elif judge == '2':
                        card_number = account
                    time.sleep(0.5)
                    print('*' * 3 + '电影放映表' + '*' * 3)
                    for x, y in list(enumerate(c, 1)):
                        print(x, y['name'])
                    print('*' * 13)

                    time.sleep(0.5)
                    buy = int(input('请您选择电影场次:'))
                    print('*' * 8 + '电影信息' + '*' * 8)
                    print('影名:{}'.format(c[buy - 1]['name']))
                    print('类别:{}'.format(c[buy - 1]['category']))
                    print('导演:{}'.format(c[buy - 1]['director']))
                    print('演员:{}'.format(c[buy - 1]['actor']))
                    print('*' * 23)

                    while True:
                        time.sleep(0.5)
                        print('*' * 13 + '影厅座位' + '*' * 13)
                        for i in c[buy - 1]['seat']:
                            print('  '.join(i))
                        print('*' * 32)
                        ticket = input('是否继续购票(1.继续 2.退出):')
                        if ticket == '2':
                            break

                        line_numbers = int(input('请您选择影厅行号:'))
                        seat_numbers = int(input('请您选择影厅座号:'))
                        if c[buy - 1]['seat'][line_numbers][seat_numbers] == '■':
                            print('不好意思,座位已选!')
                        else:
                            c[buy - 1]['seat'][line_numbers][seat_numbers] = '■'
                            time.sleep(0.5)
                            print('购票成功,电影名:{} 座位号:{}排{}号'.format
                                  (c[buy - 1]['name'], line_numbers, seat_numbers))

                            if card_number in d and c[buy - 1]['name'] in d[card_number]:
                                d[card_number][c[buy - 1]['name']].append(
                                    '{}排{}号'.format(line_numbers, seat_numbers))
                            elif card_number in d and c[buy - 1]['name'] not in d[card_number]:
                                d[card_number][c[buy - 1]['name']] = [
                                    '{}排{}号'.format(line_numbers, seat_numbers)]
                            else:
                                d[card_number] = {
                                    c[buy - 1]['name']: ['{}排{}号'.format(line_numbers, seat_numbers)]}

                elif choose == '6':
                    while True:
                        unsubscribe = input('是否需要退订影票(1.需要 2.退出):')
                        if unsubscribe == '2':
                            break
                        else:
                            card_number = input('请您输入会员卡号:')
                            for i in d[card_number]:
                                if card_number in b:
                                    time.sleep(0.5)
                                    print('卡号:{} 昵称:{} 影名:{} 座位:{}'.format
                                          (card_number, b[card_number][1], i, ' '.join(d[card_number][i])))
                                else:
                                    time.sleep(0.5)
                                    print('卡号:{} 昵称:{} 影名:{} 座位:{}'.format
                                          (card_number, a[card_number][1], i, ' '.join(d[card_number][i])))
                            name = dict(enumerate(d[card_number], 1))
                            for i in name:
                                print(i, name[i])
                            movie_number = int(input('请您选择需要退票电影序号:'))
                            number = dict(enumerate(d[card_number][name[movie_number]], 1))
                            for i in number:
                                print(i, number[i])
                            seat_number = int(input('请您选择需要退票电影座位:'))
                            message = re.findall(r'\d+', number[seat_number])
                            for i in c:
                                if name[movie_number] == i['name']:
                                    i['seat'][int(message[0])][int(message[1])] = '□'
                            d[card_number][name[movie_number]].remove(number[seat_number])
                            time.sleep(0.5)
                            print('退票成功!')
                            if not d[card_number][name[movie_number]]:
                                del d[card_number][name[movie_number]]

                elif choose == '7':
                    more_ticket = []
                    for x in range(len(c)):
                        number = 0
                        for y in c[x]['seat']:
                            number += y.count('□')
                        more_ticket.append(number)
                        time.sleep(0.5)
                        print('影名:{}-余票:{}张'.format(c[x]['name'], more_ticket[x]))

                elif choose == '8':
                    while True:
                        options = input('请您选择操作选项(1.添加管理 2.删除管理 3.退出系统):')
                        if options == '1':
                            name = input('请您输入管理昵称:')
                            gender = input('请您输入管理性别:')
                            phone = input('请您输入手机号码:')
                            password = input('请您输入登录密码:')
                            account = []
                            for i in a:
                                account.append(int(i))
                            account.sort()
                            a[str(account[-1] + 1)] = [password, name, gender, phone]
                            time.sleep(0.5)
                            print('注册成功!')
                            time.sleep(0.5)
                            print('管理账号:{}、登录密码:{}、管理昵称:{}、管理性别:{}、手机号码:{}'.format
                                  (str(account[-1] + 1), password, name, gender, phone))
                        elif options == '2':
                            while True:
                                delete = input('是否继续删除管理员(1.继续 2.退出):')
                                if delete == '2':
                                    break
                                else:
                                    card = input('请您输入删除管理员卡号:')
                                    del a[card]
                                    time.sleep(0.5)
                                    print('删除成功!')
                        elif options == '3':
                            break

                elif choose == '9':
                    while True:
                        options = input('请您选择操作选项(1.添加影片 2.删除影片 3.退出系统):')
                        if options == '1':
                            name = input('请您输入影名:')
                            category = input('请您输入类别:')
                            director = input('请您输入导演:')
                            actor = input('请您输入演员:')
                            seat = [[' ', '1', '2', '3', '4', '5', '6', '7', '8', '9', ' '],
                                    ['1', '□', '□', '□', '□', '□', '□', '□', '□', '□', '1'],
                                    ['2', '□', '□', '□', '□', '□', '□', '□', '□', '□', '2'],
                                    ['3', '□', '□', '□', '□', '□', '□', '□', '□', '□', '3'],
                                    ['4', '□', '□', '□', '□', '□', '□', '□', '□', '□', '4'],
                                    ['5', '□', '□', '□', '□', '□', '□', '□', '□', '□', '5'],
                                    ['6', '□', '□', '□', '□', '□', '□', '□', '□', '□', '6'],
                                    [' ', '1', '2', '3', '4', '5', '6', '7', '8', '9', ' ']]
                            c.append({'name': name, 'category': category, 'director': director, 'actor': actor,
                                      'seat': seat})
                            time.sleep(0.5)
                            print('添加影片成功!')
                        elif options == '2':
                            for x, y in list(enumerate(c, 1)):
                                print(x, y['name'])
                            delete = int(input('请您选择需要删除影片序号:'))
                            c.pop(delete - 1)
                            time.sleep(0.5)
                            print('影片删除成功!')
                        elif options == '3':
                            break

                elif choose == '10':
                    sales_ticket = []
                    for x in range(len(c)):
                        number = 0
                        for y in c[x]['seat']:
                            number += y.count('■')
                        sales_ticket.append(number)
                        time.sleep(0.5)
                        print('影名:{}-售出:{}张'.format(c[x]['name'], sales_ticket[x]))
                elif choose == '11':
                    print('管理卡号:{}、管理昵称:{}、管理性别:{}、手机号码:{}'.format
                          (account, a[account][1], a[account][2], a[account][3]))
                    while True:
                        continues = input('是否需要修改信息(1.需要 2.退出)')
                        if continues == '2':
                            break
                        else:
                            modify = input('请您选择修改选项(1.管理昵称 2.管理性别 3.手机号码):')
                            if modify == '1':
                                a[account][1] = input('请您输入管理昵称:')
                            elif modify == '2':
                                a[account][2] = input('请您输入管理性别:')
                            elif modify == '3':
                                a[account][3] = input('请您输入手机号码:')
                            time.sleep(0.5)
                            print('信息修改成功!')

                elif choose == '12':
                    break
        else:
            print('密码错误,登录失败!')
    else:
        print('账号错误,请您核对!')

4.注册用户

      主要能够实现售票管理系统新增会员的信息录入、查询等功能。

def registered(x):
    name = input('请您输入会员昵称:')
    gender = input('请您输入会员性别:')
    phone = input('请您输入手机号码:')
    password = input('请您输入登录密码:')
    account = []

    for i in x:
        account.append(int(i))
    account.sort()
    x[str(account[-1] + 1)] = [password, name, gender, phone]

    print('注册成功!')
    print('会员卡号:{}、登录密码:{}、会员昵称:{}、会员性别:{}、手机号码:{}'.format
          (str(account[-1] + 1), password, name, gender, phone))

5.找回密码

      主要实现管理系统根据用户登录系统或者预留手机号码方式修改密码和找回密码等操作。

def back(x, y):
    account = input('请您输入登录账号:')
    if account in x:
        while True:
            need = input('是否需要找回密码(1.需要 2.取消):')
            if need == '2':
                break
            phone = input('请您输入预留手机号码:')
            if phone == x[account][3]:
                x[account][0] = input('请您输入新密码:')
                print('号码正确,修改成功!')
            else:
                print('号码错误,请您核实!')

    elif account in y:
        while True:
            need = input('是否需要找回密码(1.需要 2.取消):')
            if need == '2':
                break
            phone = input('请您输入预留手机号码:')
            if phone == y[account][3]:
                y[account][0] = input('请您输入新密码:')
                print('号码正确,修改成功!')
            else:
                print('号码错误,请您核实!')
    else:
        print('账号错误,请您核对!')


  • 25
    点赞
  • 117
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 28
    评论
为了实现Python电影订票系统,我们需要完成以下几个步骤: 1. 安装Python和相关依赖,如MySQL客户端、Python-MySQL库和Redis服务器等。 2. 创建一个MySQL数据库,用于存储电影信息和用户订单信息等。 3. 编写Python脚本,实现电影选择和订票功能。可以使用Python的MySQL库连接到MySQL数据库,查询电影信息和用户订单信息,并根据用户输入进行相应的操作。 4. 将Python脚本部署到服务器上,并启动Redis服务器,以便在多个客户端之间共享电影信息和用户订单信息。 下面是一个简单的Python电影订票系统的示例代码: ```python import MySQLdb import redis # 连接MySQL数据库 db = MySQLdb.connect(host="localhost", user="root", passwd="password", db="movies") # 连接Redis服务器 r = redis.Redis(host='localhost', port=6379, db=0) # 查询电影信息 def get_movies(): cursor = db.cursor() cursor.execute("SELECT * FROM movies") movies = cursor.fetchall() return movies # 查询订单信息 def get_orders(): cursor = db.cursor() cursor.execute("SELECT * FROM orders") orders = cursor.fetchall() return orders # 显示电影列表 def show_movies(): movies = get_movies() for movie in movies: print(movie[0], movie[1], movie[2]) # 显示订单列表 def show_orders(): orders = get_orders() for order in orders: print(order[0], order[1], order[2], order[3]) # 选择电影 def select_movie(): while True: show_movies() choice = input("请选择电影序号或输入x退出:") if choice == 'x': break else: movie_id = int(choice) movie = get_movie(movie_id) if movie: print("您选择了电影:", movie[1]) select_seat(movie_id) else: print("无效的电影序号,请重新选择。") # 选择座位 def select_seat(movie_id): while True: seats = r.lrange("movie:%d:seats" % movie_id, 0, -1) print("可用座位:", seats) choice = input("请选择座位号或输入x返回:") if choice == 'x': break else: seat = choice if r.lrem("movie:%d:seats" % movie_id, 1, seat): print("您选择了座位:", seat) confirm_order(movie_id, seat) break else: print("无效的座位号,请重新选择。") # 确认订单 def confirm_order(movie_id, seat): cursor = db.cursor() cursor.execute("INSERT INTO orders (movie_id, seat) VALUES (%s, %s)", (movie_id, seat)) db.commit() print("订单已确认。") # 启动程序 if __name__ == '__main__': select_movie() ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 28
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

漫步桔田

编程界的一枚小学生!感谢支持!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值