翼度科技»论坛 编程开发 .net 查看内容

[回馈]ASP.NET Core MVC开发实战之商城系统(六)

3

主题

3

帖子

9

积分

新手上路

Rank: 1

积分
9
经过一段时间的准备,新的一期【ASP.NET Core MVC开发实战之商城系统】已经开始,在之前的文章中,讲解了商城系统的整体功能设计,页面布局设计,环境搭建,系统配置,及首页【商品类型,banner条,友情链接,降价促销,新品爆款】,商品列表页面,商品详情,购物车等功能的开发,今天继续讲解订单管理功能开发,仅供学习分享使用,如有不足之处,还请指正。

 
订单管理功能说明

 
在商城系统中,当用户需要购买商品时,就会进行下单。购买的入口有很多,比如:

  • 首页或商品列表页面,看到商品缩略图,可以点击【立即购买】按钮进行下单;
  • 在商品详情页面,查看商品的详细参数后,也可以点击【立即购买】按钮进行下单;
  • 在购物车页面,选择购物车中的商品,进行批量下单。
以上3个入口,下单方式大致相同,却又略有差异。具体如下所示:

  • 1,2两种方式是单个商品的购买。
  • 3是批量商品下单或单个商品下单,可以自由选择。
  • 1是默认商品参数进行下单,2是可以自由选择商品参数进行下单。
所以在不同是入口进行下单,要进行细微的调整。但是在跳转的下单页面,又可以进行统一。
同样立即购买功能,和添加购物车功能一样,需要用户的信息,需要登录才可以。
 
商品下单流程图

 
在易购商城系统中,商品下单流程图,如下所示:

 
订单管理功能开发

 
1. 数据表创建

 
订单表【EB_Purchase】,主要保存用户的订单信息,包括订单ID,商品ID,用户ID,物流ID,收货地址,商品备注等信息。具体如下所示:

订单表创建表语句如下所示:
  1. CREATE TABLE [dbo].[EB_Purchase](
  2.         [Id] [bigint] IDENTITY(1,1) NOT NULL,
  3.         [ProductId] [bigint] NULL,
  4.         [CustomerId] [bigint] NULL,
  5.         [BuyCount] [int] NULL,
  6.         [TotalPrice] [money] NULL,
  7.         [LogisticsId] [bigint] NULL,
  8.         [Status] [int] NULL,
  9.         [Remark] [varchar](200) NULL,
  10.         [RecvAddr] [varchar](300) NULL,
  11.         [CreateTime] [datetime] NOT NULL,
  12.         [CreateUser] [varchar](50) NULL,
  13.         [LastEditTime] [datetime] NULL,
  14.         [LastEditUser] [varchar](50) NULL
  15. ) ON [PRIMARY]
复制代码
 
2. 订单表实体模型创建

 
实体模型和数据库表字段保持一致,便于进行数据映射,具体如下所示:
  1. using SqlSugar;
  2. namespace EasyBuyShop.Models
  3. {
  4.     [SugarTable("EB_Purchase")]
  5.     public class Purchase : EntityModel
  6.     {
  7.         public long ProductId { get; set; }
  8.         public long CustomerId { get; set; }
  9.         public int BuyCount { get; set; }
  10.         public decimal TotalPrice { get; set; }
  11.         public long LogisticsId { get; set; }
  12.         /// <summary>
  13.         /// 收件地址ID
  14.         /// </summary>
  15.         public string RecvAddr { get; set; }
  16.         /// <summary>
  17.         /// 订单状态
  18.         /// </summary>
  19.         public int Status { get; set; }
  20.         public string Remark { get; set; }
  21.     }
  22. }
复制代码
 
3. 数据处理层DAL

 
数据处理层DAL,主要进行订单的查询,插入等操作。如下所示:
  1. using EasyBuyShop.Models;
  2. using EasyBuyShop.Utils;
  3. namespace EasyBuyShop.DAL
  4. {
  5.     public class PurchaseDal : BaseDal
  6.     {
  7.         /// <summary>
  8.         /// 获取当前用户的订单列表
  9.         /// </summary>
  10.         /// <param name="userId"></param>
  11.         /// <returns></returns>
  12.         public List<Purchase> GetPurchases(long userId)
  13.         {
  14.             try
  15.             {
  16.                 using (var db = this.GetDb(BaseDal.ConnStr))
  17.                 {
  18.                     return db.Queryable<Purchase>().Where(r => r.CustomerId == userId).ToList();
  19.                 }
  20.             }
  21.             catch (Exception ex)
  22.             {
  23.                 LogHelper.Fatal(ex.Message);
  24.                 return new List<Purchase>();
  25.             }
  26.         }
  27.     }
  28. }
复制代码
 
4. 控制器获取

 
控制器主要包括订单管理【如:查询,删除等操作】,下单购买功能,根据上述分析,不同的入口单独进行处理。如下所示:
  1. using EasyBuyShop.DAL;
  2. using EasyBuyShop.Models;
  3. using Microsoft.AspNetCore.Mvc;
  4. namespace EasyBuyShop.Controllers
  5. {
  6.     public class PurchaseController : Controller
  7.     {
  8.         public IActionResult Index()
  9.         {
  10.             var username = HttpContext.Session.GetString("username");
  11.             var realName = HttpContext.Session.GetString("realname");
  12.             var userId = HttpContext.Session.GetInt32("userid");
  13.             ViewData["Username"] = username;
  14.             ViewData["RealName"] = realName;
  15.             var purchaseDal = new PurchaseDal();
  16.             var purchases =  purchaseDal.GetPurchases(userId.Value);
  17.             var products=new List<Product>();
  18.             var shops = new List<Shop>();
  19.             if (purchases != null && purchases.Count() > 0)
  20.             {
  21.                 var productDal = new ProductDal();
  22.                 var pIds = purchases.Select(x => x.ProductId).ToList();
  23.                 products = productDal.GetProductListByIds(pIds);
  24.                 if (products != null && products.Count() > 0)
  25.                 {
  26.                     var shopDal = new ShopDal();
  27.                     shops = shopDal.GetShops(products.Select(r => r.ShopId).ToList());
  28.                 }
  29.             }
  30.             ViewData["Shops"] = shops;
  31.             ViewData["ProductList"] = products;
  32.             ViewData["Purchases"] = purchases;
  33.             return View();
  34.         }
  35.         /// <summary>
  36.         /// 首页或商品列表快捷下单
  37.         /// </summary>
  38.         /// <param name="productId"></param>
  39.         /// <returns></returns>
  40.         [HttpGet]
  41.         public IActionResult Buy(int productId)
  42.         {
  43.             Msg msg = new Msg();
  44.             var userId = HttpContext.Session.GetInt32("userid");
  45.             var userName = HttpContext.Session.GetString("username");
  46.             var realName = HttpContext.Session.GetString("realname");
  47.             ViewData["Username"] = userName;
  48.             ViewData["RealName"] = realName;
  49.             if (userId == null)
  50.             {
  51.                 msg.code = -1;
  52.                 msg.message = "尚未登录";
  53.                 return Redirect("/Auth/Login");
  54.             }
  55.             var shopDal = new ShopDal();
  56.             var productDal = new ProductDal();
  57.             var addrDal = new AddrDal();
  58.             var product = productDal.GetProduct(productId);
  59.             var shop = shopDal.GetShopById(product.ShopId);
  60.             var addrs = addrDal.GetAddrByUserId((long)userId);
  61.             List<Product> products = new List<Product>() { product };
  62.             List<Shop> shops = new List<Shop>() { shop };
  63.             Dictionary<string, string> productConfigs = new Dictionary<string, string>();
  64.             ViewData["Products"] = products;
  65.             ViewData["Shops"] = shops;
  66.             ViewData["Addrs"] = addrs;
  67.             ViewData["ProductConfigs"] = productConfigs;
  68.             return View();
  69.         }
  70.         /// <summary>
  71.         /// 确认下单
  72.         /// </summary>
  73.         /// <returns></returns>
  74.         [HttpPost]
  75.         public IActionResult Buy()
  76.         {
  77.             Msg msg = new Msg();
  78.             var userId = HttpContext.Session.GetInt32("userid");
  79.             var userName = HttpContext.Session.GetString("username");
  80.             if (userId == null)
  81.             {
  82.                 msg.code = -1;
  83.                 msg.message = "尚未登录";
  84.                 return Redirect("/Auth/Login");
  85.             }
  86.             var addr = Request.Form["addr"];
  87.             var productIds = Request.Form["productId"].ToList();
  88.             foreach (var productId in productIds)
  89.             {
  90.                 var remark = Request.Form[$"textarea_{productId}"];
  91.                 var quantity = Request.Form[$"quantity_{productId}"];
  92.                 var productDal = new ProductDal();
  93.                 var product = productDal.GetProduct(long.Parse(productId));
  94.                 if (product != null)
  95.                 {
  96.                     var pruchaseDal = new PurchaseDal();
  97.                     var purchase = new Purchase();
  98.                     purchase.ProductId = long.Parse(productId);
  99.                     purchase.CustomerId = userId.Value;
  100.                     purchase.BuyCount = int.Parse(quantity);
  101.                     purchase.TotalPrice = product.PreferentialPrice * int.Parse(quantity);
  102.                     purchase.LogisticsId = 0;//物流ID,下单时为空,商家发货后制定
  103.                     purchase.Remark = remark;
  104.                     purchase.Status = 0;
  105.                     purchase.RecvAddr = addr;
  106.                     purchase.CreateUser = userName;
  107.                     purchase.CreateTime = DateTime.Now;
  108.                     purchase.LastEditUser = userName;
  109.                     purchase.LastEditTime = DateTime.Now;
  110.                     int id = pruchaseDal.InsertT<Purchase>(purchase);
  111.                     if (id > 0)
  112.                     {
  113.                         msg.code = 0;
  114.                         msg.message = "成功";
  115.                     }
  116.                     else
  117.                     {
  118.                         msg.code = -1;
  119.                         msg.message = "购买失败";
  120.                         break;
  121.                     }
  122.                 }
  123.                 else
  124.                 {
  125.                     msg.code = -1;
  126.                     msg.message = "商品不存在";
  127.                     break;
  128.                 }
  129.             }
  130.             if (msg.code < 0)
  131.             {
  132.                 ViewData["Msg"] = msg;
  133.                 return View();
  134.             }
  135.             else
  136.             {
  137.                 return Redirect("/Purchase/Index");
  138.             }
  139.         }
  140.         /// <summary>
  141.         /// 从详情页面下单
  142.         /// </summary>
  143.         /// <returns></returns>
  144.         [HttpPost]
  145.         public IActionResult BuyWithForm()
  146.         {
  147.             Msg msg = new Msg();
  148.             var userId = HttpContext.Session.GetInt32("userid");
  149.             var userName = HttpContext.Session.GetString("username");
  150.             if (userId == null)
  151.             {
  152.                 msg.code = -1;
  153.                 msg.message = "尚未登录";
  154.                 return Json(msg);
  155.             }
  156.             var productId = long.Parse(Request.Form["productId"]);
  157.             var quantity = int.Parse(Request.Form["quantity"]);
  158.             var color = Request.Form["color"];
  159.             var size = Request.Form["size"];
  160.             var remark = $"颜色:{color},大小:{size}";
  161.             var productDal = new ProductDal();
  162.             var product = productDal.GetProduct(productId);
  163.             var shopDal = new ShopDal();
  164.             var addrDal = new AddrDal();
  165.             var shop = shopDal.GetShopById(product.ShopId);
  166.             var addrs = addrDal.GetAddrByUserId((long)userId);
  167.             List<Product> products = new List<Product>() { product };
  168.             List<Shop> shops = new List<Shop>() { shop };
  169.             Dictionary<string, string> productConfigs = new Dictionary<string, string>();
  170.             productConfigs.Add($"remark_{productId}", remark);
  171.             productConfigs.Add($"quantity_{productId}", quantity.ToString());
  172.             ViewData["Products"] = products;
  173.             ViewData["Shops"] = shops;
  174.             ViewData["Addrs"] = addrs;
  175.             ViewData["ProductConfigs"] = productConfigs;
  176.             return View("/Views/Purchase/Buy.cshtml");
  177.         }
  178.         /// <summary>
  179.         /// 从购物车下单
  180.         /// </summary>
  181.         /// <returns></returns>
  182.         [HttpPost]
  183.         public IActionResult BuyWithCart()
  184.         {
  185.             Msg msg = new Msg();
  186.             var userId = HttpContext.Session.GetInt32("userid");
  187.             var userName = HttpContext.Session.GetString("username");
  188.             if (userId == null)
  189.             {
  190.                 msg.code = -1;
  191.                 msg.message = "尚未登录";
  192.                 return Json(msg);
  193.             }
  194.             var cartIds = Request.Form["chkCart"];
  195.             if (string.IsNullOrEmpty(cartIds))
  196.             {
  197.                 msg.code = -1;
  198.                 msg.message = "没有选择任何商品";
  199.                 return Json(msg);
  200.             }
  201.             var cartIdArr = cartIds.ToString().Split(',');
  202.             if(cartIdArr!=null && cartIdArr.Length > 0)
  203.             {
  204.                 var cartDal = new CartDal();
  205.                 var productDal = new ProductDal();
  206.                 var shopDal = new ShopDal();
  207.                 var addrDal = new AddrDal();
  208.                 List<Product> products = new List<Product>();
  209.                 List<Shop> shops = new List<Shop>();
  210.                 Dictionary<string, string> productConfigs = new Dictionary<string, string>();
  211.                 foreach (var cartId in cartIdArr)
  212.                 {
  213.                     var cart = cartDal.GetCart(long.Parse( cartId));
  214.                     var product = productDal.GetProduct(cart.ProductId);
  215.                     if (product != null)
  216.                     {
  217.                         products.Add(product);
  218.                     }
  219.                     var shop = shopDal.GetShopById(product.ShopId);
  220.                     if (shop != null)
  221.                     {
  222.                         shops.Add(shop);
  223.                     }
  224.                     
  225.                     productConfigs.Add($"remark_{cart.ProductId}", cart.Remark);
  226.                     productConfigs.Add($"quantity_{cart.ProductId}", cart.Quantity.ToString());
  227.                 }
  228.                 var addrs = addrDal.GetAddrByUserId((long)userId);
  229.                 ViewData["Products"] = products;
  230.                 ViewData["Shops"] = shops;
  231.                 ViewData["Addrs"] = addrs;
  232.                 ViewData["ProductConfigs"] = productConfigs;
  233.                 return View("/Views/Purchase/Buy.cshtml");
  234.             }
  235.             else
  236.             {
  237.                 return View("/Views/Cart/Index");
  238.             }
  239.             
  240.         }
  241.     }
  242. }
复制代码
 
5. 视图层展示

 
订单相关功能主要有两个页面,一个下单页面,一个订单管理页面。
下单页面主要功能是展示商品列表,下单按钮,以及用户的选择,备注,价格等信息。如下所示:
  1.     <form method="post" action="/Purchase/Buy">
  2.         @{
  3.             var addrs = ViewData["Addrs"] as List<Address>;
  4.             addrs = addrs.OrderByDescending(r => r.IsDefault).ToList();
  5.             var defaultAddr = addrs.FirstOrDefault(r => r.IsDefault);
  6.             var productConfigs = ViewData["ProductConfigs"] as Dictionary<string, string>;
  7.             var total = 0M;
  8.         }
  9.         
  10.             
  11.                
  12.                     <h2 >
  13.                         确认收货地址
  14.                         <a  rel="noopener noreferrer" target="_blank" href="//member1.taobao.com/member/fresh/deliver_address.htm">管理收货地址</a>
  15.                     </h2>
  16.                
  17.                
  18.                 <input type="hidden" name="addr" id="addr" value="@($"{defaultAddr.ToString()} ({defaultAddr.Name} 收) {defaultAddr.Phone}")" />
  19.                
  20.                     @{
  21.                         for (int i = 0; i < addrs.Count; i++)
  22.                         {
  23.                             var addr = addrs[i];
  24.                             if (addr.IsDefault)
  25.                             {
  26.                                 
  27.                                     
  28.                                        
  29.                                             
  30.                                                 <i >♥</i>
  31.                                                 寄送至
  32.                                             
  33.                                             <label dir="ltr" aria-checked="true" >
  34.                                                 
  35.                                                    
  36.                                                     <input role="radio" tabindex="0" type="radio" aria-checked="true"  checked="">
  37.                                                 
  38.                                                 
  39.                                                     @addr.Province
  40.                                                     @addr.City
  41.                                                     @addr.District
  42.                                                     @addr.Street
  43.                                                     @addr.Detail
  44.                                                     (@(addr.Name) 收)
  45.                                                     @addr.Phone
  46.                                                     默认地址
  47.                                                 
  48.                                             </label>
  49.                                             <a  title="设置当前地址为默认">设置为默认收货地址</a>
  50.                                        
  51.                                         <a title="修改地址" >修改本地址</a>
  52.                                     
  53.                                     
  54.                                 
  55.                             }
  56.                             else
  57.                             {
  58.                                 
  59.                                     
  60.                                        
  61.                                             <label dir="ltr" aria-checked="false" >
  62.                                                 
  63.                                                    
  64.                                                     <input role="radio" tabindex="0" type="radio" aria-checked="false" >
  65.                                                 
  66.                                                 
  67.                                                     @addr.Province
  68.                                                     @addr.City
  69.                                                     @addr.District
  70.                                                     @addr.Street
  71.                                                     @addr.Detail
  72.                                                     (@(addr.Name) 收)
  73.                                                     @addr.Phone
  74.                                                     默认地址
  75.                                                 
  76.                                             </label>
  77.                                             <a  title="设置当前地址为默认">设置为默认收货地址</a>
  78.                                        
  79.                                     
  80.                                     
  81.                                 
  82.                             }
  83.                         }
  84.                     }
  85.                
  86.                
  87.                
  88.                     <a  >使用其它地址</a>
  89.                
  90.             
  91.         
  92.         
  93.             
  94.                
  95.                     <h2 >确认订单信息</h2>
  96.                
  97.                
  98.                     店铺宝贝
  99.                     商品属性
  100.                     单价
  101.                     数量
  102.                     优惠方式
  103.                     小计
  104.                
  105.             
  106.         
  107.         @{
  108.             var products = ViewData["Products"] as List<Product>;
  109.             var shops = ViewData["Shops"] as List<Shop>;
  110.             for (int i = 0; i < products.Count; i++)
  111.             {
  112.                 var product = products[i];
  113.                 var quantity_key = $"quantity_{product.Id}";
  114.                 var remark_key = $"remark_{product.Id}";
  115.                 var quantity = 1;
  116.                 var remark = "";
  117.                 if (productConfigs != null || productConfigs.Count > 0)
  118.                 {
  119.                     if (productConfigs.ContainsKey(quantity_key))
  120.                     {
  121.                         quantity = int.Parse(productConfigs[quantity_key]);
  122.                     }
  123.                     if (productConfigs.ContainsKey(remark_key))
  124.                     {
  125.                         remark = productConfigs[remark_key];
  126.                     }
  127.                 }
  128.                 var shop = shops.FirstOrDefault(r => r.Id == product.ShopId);
  129.                 total += (product.PreferentialPrice * quantity);
  130.                 <input type="hidden" name="productId" value="@(product.Id)" />
  131.                
  132.                     
  133.                         
  134.                             店铺: 
  135.                             <a href="https://www.cnblogs.com/Shop/Index?id=@(product.ShopId)" target="_blank" rel="noopener noreferrer" title="" >@(shop.Description)</a>
  136.                            
  137.                                 卖家: 
  138.                                 <a href="https://www.cnblogs.com/##" target="_blank" rel="noopener noreferrer" title="@(shop.Description)" >@(shop.Name)</a>
  139.                            
  140.                            
  141.                                 <a href="https://www.cnblogs.com/" target="_blank"  title=""></a>
  142.                            
  143.                         
  144.                     
  145.                     
  146.                         
  147.                            
  148.                                 
  149.                                     
  150.                                        
  151.                                             
  152.                                                 <a href="https://www.cnblogs.com/Product/Detail/@(product.Id)" target="_blank" rel="noopener noreferrer" >
  153.                                                     <img  src="https://www.cnblogs.com/@(product.ImageUrl)">
  154.                                                 </a>
  155.                                                 
  156.                                                     <a href="https://www.cnblogs.com/Product/Detail/@(product.Id)" target="_blank" rel="noopener noreferrer" >@(product.Name)</a>
  157.                                                    
  158.                                                         
  159.                                                             <a href="https://www.cnblogs.com/##" target="_blank" rel="noopener noreferrer" title="如实描述 - 消费者保障服务,卖家承诺商品如实描述" >
  160.                                                                 <img src="https://www.cnblogs.com/~/imgs/others/quanyi.png">
  161.                                                             </a>
  162.                                                             <a target="_blank" rel="noopener noreferrer" title="7天无理由退货" ><img></a>
  163.                                                         
  164.                                                    
  165.                                                 
  166.                                             
  167.                                             
  168.                                                 <p>
  169.                                                     基础风格:@(product.BasicStyle)
  170.                                                 </p>
  171.                                                 <p>
  172.                                                     商品类型:@(product.ProductStyle)
  173.                                                 </p>
  174.                                             
  175.                                             @(Math.Round(product.Price, 2))
  176.                                        
  177.                                        
  178.                                             
  179.                                                 <p><input type="text" name="quantity_@(product.Id)" id="quantity_@(product.Id)" value="@(quantity)"  onchange="javascript:confirmTotalPrice(@(product.Id));" /></p>
  180.                                             
  181.                                        
  182.                                         <p >@(product.Preferential > 0 ? Math.Round(product.Preferential * 100, 2).ToString() + "%" : "无优惠")</p>
  183.                                        
  184.                                             
  185.                                                 <input type="hidden" value="@(Math.Round(product.PreferentialPrice,2))" id="preferentitalprice_@(product.Id)" />
  186.                                                 @(Math.Round(product.PreferentialPrice * quantity, 2))
  187.                                             
  188.                                        
  189.                                     
  190.                                 
  191.                            
  192.                         
  193.                     
  194.                     
  195.                         
  196.                            
  197.                                 
  198.                                     
  199.                                        
  200.                                             
  201.                                                 
  202.                                                    
  203.                                                         
  204.                                                             
  205.                                                                 <label >
  206.                                                                     给卖家留言:
  207.                                                                 </label>
  208.                                                                
  209.                                                                     
  210.                                                                         <textarea placeholder="选填,请先和商家协商一致,付款后商家可见" id="textarea_@(product.Id)" name="textarea_@(product.Id)" maxlength="200" data-real="true" rows="1">@(remark)</textarea>
  211.                                                                         0/200
  212.                                                                     
  213.                                                                
  214.                                                             
  215.                                                         
  216.                                                    
  217.                                                 
  218.                                             
  219.                                        
  220.                                        
  221.                                             
  222.                                                 
  223.                                                    
  224.                                                         
  225.                                                             
  226.                                                                
  227.                                                                     运送方式:
  228.                                                                     
  229.                                                                         
  230.                                                                             <label >普通配送</label>
  231.                                                                             <label ></label>
  232.                                                                             快递¥10.00
  233.                                                                         
  234.                                                                         
  235.                                                                     
  236.                                                                 10.00
  237.                                                             
  238.                                                         
  239.                                                    
  240.                                                    
  241.                                                         
  242.                                                             
  243.                                                                 运费险:
  244.                                                                
  245.                                                                     <label >
  246.                                                                         
  247.                                                                             <i ></i>
  248.                                                                             <input type="checkbox" aria-checked="false" >
  249.                                                                         
  250.                                                                         
  251.                                                                             运费险
  252.                                                                             退换货可赔付10元
  253.                                                                         
  254.                                                                     </label>
  255.                                                                     
  256.                                                                         <img src="https://www.cnblogs.com/~/imgs/others/msg.png" >
  257.                                                                         
  258.                                                                            
  259.                                                                             退换货可赔付10元
  260.                                                                         
  261.                                                                     
  262.                                                                     <a href="https://www.cnblogs.com/##" target="_blank" >
  263.                                                                         <img  src="https://www.cnblogs.com/~/imgs/others/ask.png">
  264.                                                                     </a>
  265.                                                                
  266.                                                                 0.00
  267.                                                             
  268.                                                         
  269.                                                    
  270.                                                 
  271.                                             
  272.                                        
  273.                                     
  274.                                 
  275.                            
  276.                                 
  277.                                     
  278.                                        
  279.                                             
  280.                                                 
  281.                                                     店铺合计(含运费)
  282.                                                     ¥@(Math.Round(product.PreferentialPrice * quantity, 2))
  283.                                                 
  284.                                             
  285.                                        
  286.                                        
  287.                                             
  288.                                        
  289.                                     
  290.                                 
  291.                            
  292.                         
  293.                     
  294.                
  295.             }
  296.         }
  297.         
  298.             
  299.                
  300.                     
  301.                         
  302.                            
  303.                                 实付款:
  304.                                 ¥
  305.                                 @(Math.Round(total, 2))
  306.                            
  307.                            
  308.                                 
  309.                                     寄送至:
  310.                                     @defaultAddr.ToString();
  311.                                 
  312.                                 
  313.                                     收货人:
  314.                                     @defaultAddr.Name @defaultAddr.Phone
  315.                                 
  316.                            
  317.                            
  318.                         
  319.                     
  320.                
  321.             
  322.         
  323.         
  324.             
  325.                
  326.                     <a  target="_self" role="button" title="返回购物车" href="//cart.taobao.com/cart.htm">返回购物车</a>
  327.                     <input type="submit" title="提交订单"   value="提交订单"></input>
  328.                
  329.                 若价格变动,请在提交订单后联系卖家改价,并查看已买到的宝贝
  330.             
  331.         
  332.     </form>
复制代码
订单管理页面
订单管理页面,主要查看已经购买过从商品信息。如下所示:
  1. @{
  2.     var purchases = ViewData["Purchases"] as List<Purchase>;
  3.     var products = ViewData["ProductList"] as List<Product>;
  4.     var shops = ViewData["Shops"] as List<Shop>;
  5. }
  6.    
  7.         
  8.             
  9.                
  10.                     所有订单
  11.                     
  12.                
  13.                 |
  14.             
  15.             
  16.                
  17.                     待付款
  18.                     
  19.                
  20.                 |
  21.             
  22.             
  23.                
  24.                     待发货
  25.                     
  26.                
  27.                 |
  28.             
  29.             
  30.                
  31.                     待收货
  32.                     
  33.                
  34.                 |
  35.             
  36.             
  37.                
  38.                     待评价
  39.                     
  40.                
  41.                 |
  42.             
  43.             
  44.                
  45.                     分阶段
  46.                     
  47.                
  48.             
  49.         
  50.         
  51.             
  52.                
  53.                     <img  src="https://www.cnblogs.com/~/imgs/TB1G5QqIFXXXXbvXFXXcmA2.FXX-11-12.png" alt="订单回收站">
  54.                     订单回收站
  55.                
  56.             
  57.         
  58.    
  59.    
  60.         
  61.             
  62.                
  63.             
  64.         
  65.    
  66.     <form >
  67.         
  68.             <input type="text" placeholder="输入商品标题或订单号进行搜索" >
  69.             <button type="submit" >订单搜索</button>
  70.             <button type="button" >
  71.                 更多筛选条件
  72.                 <img src="https://www.cnblogs.com/~/imgs/TB1jK1dIVXXXXXzXVXXXXXXXXXX.png">
  73.             </button>
  74.         
  75.         
  76.             
  77.                
  78.                     <label>
  79.                         订单类型
  80.                         
  81.                            
  82.                                 
  83.                                     全部
  84.                                 
  85.                                 
  86.                                     <b></b>
  87.                                 
  88.                            
  89.                         
  90.                     </label>
  91.                
  92.                     成交时间
  93.                     <input  placeholder="请选择时间范围起始" type="text">
  94.                     -
  95.                     <input  placeholder="请选择时间范围结束" type="text">
  96.                
  97.                
  98.                     <label >
  99.                         卖家昵称
  100.                         <input  type="text">
  101.                     </label>
  102.                
  103.             
  104.             
  105.                
  106.                     <label>
  107.                         评价状态
  108.                         
  109.                            
  110.                                 
  111.                                     全部
  112.                                 
  113.                                 
  114.                                     <b></b>
  115.                                 
  116.                            
  117.                         
  118.                     </label>
  119.                
  120.                
  121.                     <label data-reactid=".0.2.1.1.1.0">
  122.                         交易状态
  123.                         
  124.                            
  125.                                 
  126.                                     全部
  127.                                 
  128.                                 
  129.                                     <b></b>
  130.                                 
  131.                            
  132.                         
  133.                     </label>
  134.                
  135.                
  136.                     <label >
  137.                         售后服务
  138.                         
  139.                            
  140.                                 
  141.                                     全部
  142.                                 
  143.                                 
  144.                                     <b></b>
  145.                                 
  146.                            
  147.                         
  148.                     </label>
  149.                
  150.             
  151.         
  152.     </form>
  153.    
  154.     <table >
  155.         <colgroup data-reactid=".0.4.0">
  156.             <col >
  157.             <col >
  158.             <col >
  159.             <col >
  160.             <col >
  161.             <col >
  162.             <col >
  163.         </colgroup>
  164.         <tbody data-reactid=".0.4.1">
  165.             <tr data-reactid=".0.4.1.0">
  166.                 <th>宝贝</th>
  167.                 <th>单价</th>
  168.                 <th>数量</th>
  169.                 <th>商品操作</th>
  170.                 <th>实付款</th>
  171.                 <th>
  172.                     
  173.                         
  174.                            
  175.                                 交易状态
  176.                            
  177.                            
  178.                                 <b></b>
  179.                            
  180.                         
  181.                     
  182.                 </th>
  183.                 <th>交易操作</th>
  184.             </tr>
  185.         </tbody>
  186.     </table>
  187.    
  188.         
  189.             
  190.         
  191.         
  192.             
  193.                 <button  disabled="">上一页</button>
  194.                 <button >下一页</button>
  195.             
  196.         
  197.    
  198.     @if (purchases != null && purchases.Count > 0)
  199.     {
  200.         foreach (var purchase in purchases)
  201.         {
  202.             var product = products.FirstOrDefault(r => r.Id == purchase.ProductId);
  203.             var shop = shops.FirstOrDefault(r => r.Id == product.ShopId);
  204.             
  205.                
  206.                     <table >
  207.                         <colgroup>
  208.                             <col >
  209.                             <col >
  210.                             <col >
  211.                             <col >
  212.                             <col >
  213.                             <col >
  214.                             <col >
  215.                         </colgroup>
  216.                         <tbody >
  217.                             <tr>
  218.                                 <td >
  219.                                     <label >
  220.                                        
  221.                                             <input type="checkbox" disabled="">
  222.                                        
  223.                                         @(purchase.CreateTime.ToString("yyyy-MM-dd"))
  224.                                     </label>
  225.                                     
  226.                                         订单号
  227.                                         :
  228.                                         @purchase.Id
  229.                                     
  230.                                 </td>
  231.                                 <td colspan="2" >
  232.                                     
  233.                                         <a href="https://www.cnblogs.com/"  title="@shop.Name" target="_blank" rel="noopener noreferrer">@shop.Name</a>
  234.                                     
  235.                                 </td>
  236.                                 <td>
  237.                                     
  238.                                         <a href="https://www.cnblogs.com/" target="_blank"  title=""></a>
  239.                                     
  240.                                 </td>
  241.                                 <td colspan="3" >
  242.                                     
  243.                                     <a href="https://www.cnblogs.com/"  title="编辑标记信息,仅自己可见" target="_blank" rel="noopener noreferrer" id="flag">
  244.                                         <i ></i>
  245.                                     </a>
  246.                                     <a href="https://www.cnblogs.com/###"  title="删除订单" target="_blank" rel="noopener noreferrer" action="a7" data="[object Object]" id="delOrder">
  247.                                         <i ></i>
  248.                                     </a>
  249.                                 </td>
  250.                             </tr>
  251.                         </tbody>
  252.                         <tbody>
  253.                             <tr>
  254.                                 <td >
  255.                                     
  256.                                        
  257.                                             <a href="https://www.cnblogs.com/Product/Detail/@(product.Id)"  target="_blank" rel="noopener noreferrer">
  258.                                                 <img src="https://www.cnblogs.com/@(product.ImageUrl)">
  259.                                                 
  260.                                             </a>
  261.                                        
  262.                                        
  263.                                             <p>
  264.                                                 <a href="https://www.cnblogs.com/Product/Detail/@(product.Id)" target="_blank" rel="noopener noreferrer">
  265.                                                      
  266.                                                     @product.Name
  267.                                                      
  268.                                                 </a>
  269.                                                 
  270.                                                 
  271.                                                 
  272.                                             </p>
  273.                                             <p>
  274.                                                 <a href="https://www.cnblogs.com/Rule/Real" title="正品保证" type="3"  target="_blank">
  275.                                                     <img src="https://www.cnblogs.com/~/imgs/T1SyeXFpliXXaSQP_X-16-16.png">
  276.                                                 </a>
  277.                                                 <a href="https://www.cnblogs.com/Rule/XiaoBao" title="如实描述" type="3"  target="_blank"><img src="https://www.cnblogs.com/~/imgs/TB1PDB6IVXXXXaVaXXXXXXXXXXX.png"></a>
  278.                                             </p>
  279.                                        
  280.                                     
  281.                                 </td>
  282.                                 <td >
  283.                                     
  284.                                         <p>
  285.                                             ¥
  286.                                             @(Math.Round(product.PreferentialPrice, 2))
  287.                                         </p>
  288.                                     
  289.                                 </td>
  290.                                 <td >
  291.                                     
  292.                                         <p>@(purchase.BuyCount)</p>
  293.                                     
  294.                                 </td>
  295.                                 <td>
  296.                                     
  297.                                         <p >
  298.                                             申请售后
  299.                                         </p>
  300.                                     
  301.                                 </td>
  302.                                 <td >
  303.                                     
  304.                                        
  305.                                             <p>
  306.                                                 <strong>
  307.                                                     ¥
  308.                                                     @(purchase.TotalPrice)
  309.                                                 </strong>
  310.                                             </p>
  311.                                        
  312.                                         <p >
  313.                                             
  314.                                             
  315.                                             
  316.                                             
  317.                                         </p>
  318.                                        
  319.                                             
  320.                                        
  321.                                        
  322.                                     
  323.                                 </td>
  324.                                 <td >
  325.                                     
  326.                                         <p >购买成功</p>
  327.                                        
  328.                                             <p >
  329.                                                 <a href="https://www.cnblogs.com/"  target="_blank" rel="noopener noreferrer" id="viewDetail">订单详情</a>
  330.                                             </p>
  331.                                        
  332.                                     
  333.                                 </td>
  334.                                 <td >
  335.                                     
  336.                                         <p >
  337.                                             <a href="https://www.cnblogs.com/"  target="_blank" rel="noopener noreferrer">追加评论</a>
  338.                                         </p>
  339.                                         <p >
  340.                                             再次购买
  341.                                         </p>
  342.                                     
  343.                                 </td>
  344.                             </tr>
  345.                         </tbody>
  346.                     </table>
  347.                
  348.             
  349.         }
  350.     }
  351.     else
  352.     {
  353.         
  354.             <img  src="https://www.cnblogs.com/~/imgs/avif/noorder.avif">
  355.             没有符合条件的宝贝,请尝试其他搜索条件。
  356.         
  357.     }
  358.    
  359.         
  360.             
  361.         
  362.         
  363.             <ul  unselectable="unselectable">
  364.                 <li title="上一页" ><a></a></li>
  365.                 <li title="1" ><a>1</a></li>
  366.                 <li title="2" ><a>2</a></li>
  367.                 <li title="3" ><a>3</a></li>
  368.                 <li title="4" ><a>4</a></li>
  369.                 <li title="下一页" ><a></a></li>
  370.                 <noscript></noscript>
  371.             </ul>
  372.         
  373.    
  374.    
  375.         
  376.         
  377.         
  378.    
复制代码
 
下单及订单管理展示

 
运行程序,点击登录,在登录成功后,选择商品点击【立即购买】或者购物车页面点击【购买】,然后跳转到下单页面,如下所示:

订单管理页面
运行程序,点击登录,在登录成功后,在右上角个人名称,点击下拉菜单,选择订单管理,然后打开订单管理页面,如下所示:

以上就是ASP.NET Core MVC开发实战之商城系统第六部分内容,后续将继续介绍其他模块,敬请期待。

来源:https://www.cnblogs.com/hsiang/archive/2023/08/27/17659726.html
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x

举报 回复 使用道具