商城 源码-商城小程序源码|开源小程序商城完整源码附视频搭建教程

商城小程序是建立在微信、抖音、头条等第三方平台上的社区电商购物系统。 本篇文章我们将探讨小程序商城源码的架构思路和基本方法。

源代码和演示:xcxyms.top

商城小程序源码要提供的功能

1、用户可以下订单、购买产品。

2. 用户将能够添加到购物车。

3.用户友好的支付系统。

4. 用户可以查看订单状态和历史记录。

设计思路:

首先,菜单将显示给顾客。 选择后,将显示所有产品及其价格。 然后客户将选择产品并选择数量(产品的数量)。 这个过程一直持续到购物完成。 每当顾客完成购物数量和单价时,就会显示最终支付的总额。

下面是上述函数的实现:

// C++ program to implement the program
// that illustrates Online shopping
#include 
#include 
#include 
#include 
using namespace std;
char c1, confirm_quantity;
float quantity;
int selectedNum;
double total_amount = 0;
int flag = 0;
// Stores items with their corresponding
// price
map items = {
{ "Samsung", 15000 },
{ "Redmi", 12000 },
{ "Apple", 100000 },
{ "Macbook", 250000 },
{ "HP", 40000 },
{ "Lenovo", 35000 },
{ "C", 1000 },
{ "C++", 3000 },
{ "Java", 4000 },
{ "Python", 3500 }
};
// Stores the selected items with
// their quantity
map selected_items;
// Function to print the bill after shopping
// is completed prints the items, quantity,
// their cost along with total amount
void printBill(map items,
map selected_items,
float total_amount)
{
cout << "Item	 "
<< "Quantity	 "
<< "Costn";
for (auto j = selected_items.begin();
j != selected_items.end(); j++) {
cout <first << "	 ";
cout <second << "		 ";
cout <first])
* (items[j->first])
<< endl;
}
cout << "-----------------------"
<< "-------------n";
cout << "Total amount:			 "
<< total_amount << endl;
cout << "-----------------------"
<< "-------------n";
cout << "*****THANK YOU && HAPPY"
<< " ONLINE SHOPPING*****";
}
// Function to ask the basic details of
// any customer
void customerDetails()
{
cout << "Enter your name: ";
string customer_name;
getline(cin, customer_name);
cout << "WELCOME ";
for (int i = 0;
i < customer_name.length();
i++) {
cout << char(toupper(
customer_name[i]));
}
cout << "n";
}
// showMenu() is to print the
// menu to the user
void showMenu()
{
cout << "Menun";
cout << "= = = = = = = = "
<< " = = = = = n";
cout << "1.Mobilen2.laptopn3"
<< ".Computer coursesn";
cout << "= = = = = = = = "
<< " = = = = = n";
}
// Function to display the mobile products
void showMobileMenu()
{
cout << "- - - - - - - - - - -"
<< " - -nItem	 Costn";
cout << "1.Samsung Rs.15, 000/-n";
cout << "2.Redmi Rs.12, 000/-n";
cout << "3.Apple Rs.1, 00, 000/-n";
cout << "- - - - - - - - - - - - -n";
}
// Function to display Laptop products
void showLaptopMenu()
{
cout << "- - - - - - - - - - -"
<< " - -nItem	 Costn";
cout << "1.Macbook Rs.2, 00, 000/-n";
cout << "2.HP	 Rs.40, 000/-n";
cout << "3.Lenovo Rs.35, 000/-n";
cout << "- - - - - - - - - - - - -n";
}
// if the user selects computer courses,
// then courses list will be displayed
void showComputerCourseMenu()
{
cout << "- - - - - - - - - - "
<< " - -nItem	 Costn";
cout << "1.C	 Rs.1, 000/-n";
cout << "2.C++	 Rs.3, 000/-n";
cout << "3.Java	 Rs.4, 000/-n";
cout << "4.Python Rs.3, 500/-n";
cout << "- - - - - - - - - - - - -n";
}
// Function to display the mobile category
void selectedMobile()
{
cout << "Do you wish to conti"
<< "nue?(for yes" + "press (Y/y ), "
<> c1;
if (c1 == 'Y' || c1 == 'y') {
cout <> selectedNum;
if (selectedNum == 1
|| selectedNum == 2
|| selectedNum == 3) {
// Selected Samsung
if (selectedNum == 1) {
cout << "selected Samsungn";
do {
cout <> quantity;
cout << "You have selected Samsung - "
<< quantity << endl;
cout << "Are you sure?"
<< "(for yes press (Y/y ), "
<> confirm_quantity;
} while ((confirm_quantity != 'y'
&& confirm_quantity != 'Y')
|| (quantity < 0)
|| (ceil(quantity) != floor(quantity)));
if (confirm_quantity == 'y'
|| confirm_quantity == 'Y') {
total_amount += quantity
* items["Samsung"];
selected_items["Samsung"] = quantity;
cout << "amount = "
<< total_amount << endl;
}
}
// Selected Redmi
if (selectedNum == 2) {
cout << "selected Redmin";
do {
cout <> quantity;
cout << "You have selec"
<< "ted Redmi - "
<< quantity << endl;
cout << "Are you sure?(f"
<< "or yes press (Y/y ), "
<> confirm_quantity;
} while ((confirm_quantity != 'y'
&& confirm_quantity != 'Y')
|| (quantity < 0)
|| (ceil(quantity)
!= floor(quantity)));
if (confirm_quantity == 'y'
|| confirm_quantity == 'Y') {
total_amount += quantity
* items["Redmi"];
selected_items["Redmi"] = quantity;
cout << "amount = "
<< total_amount << endl;
}
}
// Selected Apple
if (selectedNum == 3) {
cout << "You have selected Applen";
do {
cout <> quantity;
cout << "You have selected"
<< " Apple - "
<< quantity
<< endl;
cout << "Are you sure?"
<< "(for yes press (Y/y )"
<> confirm_quantity;
} while ((confirm_quantity != 'y'
&& confirm_quantity != 'Y')
|| (quantity < 0)
|| (ceil(quantity)
!= floor(quantity)));
if (confirm_quantity == 'y'
|| confirm_quantity == 'Y') {
total_amount += quantity
* items["Apple"];
selected_items["Apple"] = quantity;
cout << "amount = "
<< total_amount
<< endl;
}
}
}
else {
flag = 1;
}
}
else {
flag = 1;
}
}
// If Laptop category is selected
void selectedLaptop()
{
cout << "Do you wish to continue?"
<< "(for yes press (Y/y ), "
<> c1;
if (c1 == 'Y' || c1 == 'y') {
cout <> selectedNum;
if (selectedNum == 1
|| selectedNum == 2
|| selectedNum == 3) {
// selected Macbook
if (selectedNum == 1) {
cout << "selected Macbookn";
do {
cout <> quantity;
cout << "You have selected"
<< " Macbook - "
<< quantity << endl;
cout << "Are you sure?"
<< "(for yes press (Y/y ), "
<> confirm_quantity;
} while ((confirm_quantity != 'y'
&& confirm_quantity != 'Y')
|| (quantity < 0)
|| (ceil(quantity)
!= floor(quantity)));
if (confirm_quantity == 'y'
|| confirm_quantity == 'Y') {
total_amount += quantity
* items["Macbook"];
selected_items["Macbook"] = quantity;
cout << "amount = "
<< total_amount
<< endl;
}
}
// selected HP
if (selectedNum == 2) {
cout << "selected HPn";
do {
cout <> quantity;
cout << "You have selected"
<< " HP - "
<< quantity << endl;
cout << "Are you sure?"
<< "(for yes press (Y/y ), "
<> confirm_quantity;
} while ((confirm_quantity
!= 'y'
&& confirm_quantity != 'Y')
|| (quantity < 0)
|| (ceil(quantity)
!= floor(quantity)));
if (confirm_quantity == 'y'
|| confirm_quantity == 'Y') {
total_amount += quantity
* items["HP"];
selected_items["HP"] = quantity;
cout << "amount = "
<< total_amount
<< endl;
}
}
// selected Lenovo
if (selectedNum == 3) {
cout << "selected Lenovon";
do {
cout <> quantity;
cout << "You have selected"
" Lenovo - "
<< quantity << endl;
cout << "Are you sure?"
<< "(for yes press (Y/y ), "
<> confirm_quantity;
} while ((confirm_quantity != 'y'
&& confirm_quantity != 'Y')
|| (quantity < 0)
|| (ceil(quantity)
!= floor(quantity)));
if (confirm_quantity == 'y'
|| confirm_quantity == 'Y') {
total_amount += quantity
* items["Lenovo"];
selected_items["Lenovo"] = quantity;
cout << "amount = "
<< total_amount
<< endl;
}
}
}
else {
flag = 1;
}
}
else {
flag = 1;
}
}
// If computer course
// category is selected
void selectedCourses()
{
cout << "Do you wish to continue?"
<< "(for yes press (Y/y ), "
<> c1;
if (c1 == 'Y' || c1 == 'y') {
cout <> selectedNum;
if (selectedNum == 1
|| selectedNum == 2
|| selectedNum == 3
|| selectedNum == 4) {
// selected C
if (selectedNum == 1) {
cout << "selected C Language"
<< " coursen";
total_amount += items["C"];
selected_items["C"]++;
cout << "amount = "
<< total_amount
<< endl;
}
// selected C++
if (selectedNum == 2) {
cout << "selected C++ Language coursen";
total_amount += items["C++"];
selected_items["C++"]++;
cout << "amount = " << total_amount << endl;
}
// selected Java
if (selectedNum == 3) {
cout << "selected Java Language coursen";
total_amount += items["Java"];
selected_items["Java"]++;
cout << "amount = " << total_amount << endl;
}
// selected python
if (selectedNum == 4) {
cout << "selected Python"
<< " Language coursen";
total_amount += items["Python"];
selected_items["Python"]++;
cout << "amount = "
<< total_amount
<< endl;
}
}
else {
flag = 1;
}
}
else {
flag = 1;
}
}
// Driver code
int main()
{
// function call
customerDetails();
do {
showMenu();
cout << "Do you wish to continue?"
<< "(for yes press (Y/y ), "
<> c;
if (c == 'Y' || c == 'y') {
cout <> num;
if (num == 1 || num == 2
|| num == 3) {
switch (num) {
case 1:
// For Mobile
showMobileMenu();
selectedMobile();
break;
case 2:
// For Laptop
showLaptopMenu();
selectedLaptop();
break;
case 3:
// For computer course
showComputerCourseMenu();
selectedCourses();
break;
}
}
else {
flag = 1;
}
}
else {
flag = 1;
}
} while (flag == 0);
// print bill
printBill(items, selected_items,
total_amount);
}

输出:

假设有人需要购买 2 部红米手机、1 台惠普笔记本电脑和一门 Java 课程。

演示:

步骤1:首先,构建一个地图(例如地图项),其中存储产品及其成本。 构建另一个地图(例如 mapselected_items ),用于按数量推送所选项目。 然后将total_amount(存储的总金额)初始化为0。使用flags并初始化为0。如果客户出错商城 源码,flag变为1并直接退出商城 源码打印商品及其价格,然后打印总金额。

源码商城搭建_小程序源码商城_商城 源码

第二步:询问详细信息,例如客户的姓名。 在我们的指南中,customerDetails() 函数就是为此目的而构建的。 toupper() 用于将字符串中的所有字符转换为大写。

步骤3:向用户显示菜单。 showMenu() 函数就是为此目的而创建的。

第 4 步:询问用户是否愿意继续。 这里使用了do while循环,这个循环会一直持续到flag变为1。每当flag变为1时,就直接打印账单。

如果是,他需要输入 yes/yes,然后要求用户从菜单中输入相应的数字。 如果输入了错误的数字,则标志变为 1。

如果输入有效,则显示所选类型的产品。 要求用户输入相应的号码。 如果无效,标志将更改为1。