基於Python實現電影售票系統

一、系統要求

電影售票系統程序,應具備以下幾點功能:

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  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('賬號錯誤,請您核對!')

3.用戶登錄

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('賬號錯誤,請您核對!')

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('賬號錯誤,請您核對!')

四、效果圖展示

以上就是基於Python實現電影售票系統的詳細內容,更多關於Python電影售票系統的資料請關註WalkonNet其它相關文章!

推薦閱讀: