Home  >  Article  >  Backend Development  >  An example tutorial for writing a shopping mall

An example tutorial for writing a shopping mall

PHP中文网
PHP中文网Original
2017-06-20 16:19:202642browse

Assignment: Shopping mall

Product display, price

Buy, add to shopping cart

Payment, money is not enough

The flow chart is as follows:

The code has 4 files in total, as follows:

User file:

alex 666geng 888zhang 222lou 250zeng 333

Product file:

10001 小米3 2699 5010002 比亚迪宋 100001 9110003 格力变频空调 20000 410004 TCL电视 6000 9810005 联想001 5600 99210006 跑步鸡 250 66310007 大众 58000 9710008 马自达 68000 43

Shopping cart file:

10002 比亚迪宋 100001 1 geng10006 跑步鸡 250 1 geng10008 马自达 68000 1 geng10003 格力变频空调 20000 1 geng

Wallet file:

geng 115880zeng 126748

The code is as follows:

==, end=,)  line =+,shopping_name+,shopping_price+,shopping_stock+=,)  user_line == user = input( pwd == %== stock = input( (num) <= (shoppings[stock_list.index(stock)][],shoppings[stock_list.index(stock)][] = str((shoppings[stock_list.index(stock)][]) - (num) > (shoppings[stock_list.index(stock)][,)  shop_list =  + =,)  line = username ==(price)*=  cost +== input(=,)  line = username === str((bal) + ,)  user_wallet  .join(user_wallet) + ===,)  line = username == (purse) >= = str((purse) -  __name__ == == *******************************************************************************************[;1m欢迎来到小猪猪购物网站,祝你购物愉快!\*******************************************************************************************== input(== lists[= lists[= input( shopping_index == =,)  shopping_list =  .join(shopping_list) + ==,)  user_line  .join(user_line) + )
运行结果如下:

*******************************************************************************************

                       欢迎来到小猪猪购物网站,祝你购物愉快!

*******************************************************************************************
    
商品编号:   商品名称:   商品价格:   商品库存:
*************************************************************************************
10001       小米3       2699       50      
10002       比亚迪宋       100001       92      
10003       格力变频空调       20000       5      
10004       TCL电视       6000       98      
10005       联想001       5600       992      
10006       跑步鸡       250       664      
10007       大众       58000       97      
10008       马自达       68000       44      
请输入你的用户名:geng
请输入你的密码:888
您好,欢迎geng,购物愉快!
请输入你要购买商品的编号(输入quit退出购物):10002
请输入你要购买商品的数量:1
请输入你要购买商品的编号(输入quit退出购物):10006
请输入你要购买商品的数量:1
请输入你要购买商品的编号(输入quit退出购物):10008
请输入你要购买商品的数量:1
请输入你要购买商品的编号(输入quit退出购物):10003
请输入你要购买商品的数量:1
请输入你要购买商品的编号(输入quit退出购物):quit
对不起,你的余额不足,请充值
请输入你要充值的金额:100000
支付成功!

The running process of the above code is as follows:

(1) Display product information;

(2) User login verification;

 (3) The user enters the product and quantity they want to purchase, and enters quit to exit shopping;

  (4) Add to shopping cart file;

 (5) Settlement, go to the shopping cart to calculate the shopping cost;

 (6) Call the user wallet file to see if the balance is enough to pay;

 (7) The balance is greater than or equal to the same number of purchases, and the payment is successful; the balance is not enough, the user recharges;

 (8) Call the recharge module to recharge;

  (9) Recursion, it is judged that the balance after the user's recharge is greater than or equal to the cost of this shopping, the payment is successful;

  (10) End the program.

Master the knowledge:

(1) List traversal method, list modification is to first read into a list, and then according to the user Modify the input information;

 (2) Open and close files back and forth;

 (3) Apply recursion, that is, when When the user's balance is always small, recurse until the user's balance is greater than the shopping cost;

  (4) The beginning and end of the loop (break), the beginning and end of the program Termination (sys.exit), the start and termination of the function (return);

  (5) The association and indexing of lists, and the problem of the order in which files are read.

The above is the detailed content of An example tutorial for writing a shopping mall. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn