public async Task <int> DeleteCarts(string MemberMobile, List <CartsViewModel> Carts) { int ret = 0; try { // 5.系統在Action【Cart/DeleteCarts】刪除多筆購物項目。 MemberCartsViewModel mcvm; List <MemberCartsViewModel> lstMCVM = new List <MemberCartsViewModel>(); foreach (CartsViewModel item in Carts) { mcvm = new MemberCartsViewModel(); mcvm.MemberMobile = MemberMobile; mcvm.ProductId = item.productId; mcvm.ProducSizeId = item.sizeId; mcvm.ProductColorId = item.colorId; mcvm.Quantity = item.quantity; lstMCVM.Add(mcvm); } // 5.系統在Action【Cart/DeleteCarts】刪除多筆購物項目。 ret = await IMER.DeleteMemberCarts(lstMCVM); // 6.系統判斷5執行成功。 // 7.系統傳回5傳回值。 } catch (Exception ex) { // 6a.系統判斷5執行時發生例外。 // 6a-1.系統傳回1。 ret = 1; } return(ret); }
public async Task <int> GetCancelOrderState(string OrderId) { var ret = 0; ret = await IMER.UpdateOrderState(OrderId, 8); return(ret); }
public async Task <int> UpdateCart(string MemberMobile, CartsViewModel Cart, int ProducSizeIdN, int ProductColorIdN, string ProductSize, string ProductColor, int QuantityN) { int ret = 0; try { // 5.系統在Action【Cart/UpdateCart】更新一筆購物項目。 ret = await IMER.UpdateMemberCart(MemberMobile, Cart.productId, Cart.sizeId, Cart.colorId, ProducSizeIdN, ProductColorIdN, ProductSize, ProductColor, QuantityN); // 6.系統判斷5執行成功。 // 7.系統傳回5傳回值。 } catch (Exception ex) { // 6a.系統判斷5執行時發生例外。 // 6a-1.系統傳回1。 ret = 1; } return(ret); }
public async Task <int> DeleteCart(string MemberMobile, CartsViewModel Cart) { int ret = 0; try { // 5.系統在Action【Cart/DeleteCart】刪除一筆購物項目。 ret = await IMER.DeleteMemberCart(MemberMobile, Cart.productId, Cart.sizeId, Cart.colorId); // 6.系統判斷5執行成功。 // 7.系統傳回5傳回值。 } catch (Exception ex) { // 6a.系統判斷5執行時發生例外。 // 6a-1.系統傳回1。 ret = 1; } return(ret); }
public async Task <IActionResult> Index(string MemberMobile, List <CartsViewModel> Carts) { List <CartListViewModel> lstCLVM = new List <CartListViewModel>(); CartListViewModel CLVM; MemberViewModel MVM = null; if (MemberMobile != "" && MemberMobile != null) { // 3-1.系統在Action【Cart/Index】判斷MemberMobile!=""。 // 4.系統在Action【Cart/Index】讀取購物車清單。 lstCLVM = await IMER.GetCartList(MemberMobile); // 4-1.系統讀取會員基本資料。 MVM = await IMER.GetMember(MemberMobile); } else { // 3-1a.系統在Action【Cart/Index】判斷MemberMobile!="" // 3-1a-1.系統將carts轉換為List<CartListViewModel>。 foreach (CartsViewModel item in Carts) { CLVM = new CartListViewModel(); CLVM.ProductId = item.productId; CLVM.Product = item.product; CLVM.ProducSizeId = item.sizeId; CLVM.ProductColorId = item.colorId; CLVM.Quantity = item.quantity; CLVM.Price = item.price; CLVM.ProductSize = item.size; CLVM.ProductColor = item.color; lstCLVM.Add(CLVM); } // 3-1a-2.回4-2。 } // 4-2.系統讀取運費: int total = 0; foreach (var item in lstCLVM) { total += (item.Quantity * item.Price); } OrderFreightViewModel ofvm = await IPR.GetOrderFreight(total); // 5.系統在Action【Cart/Index】依4讀取值(List<CartListViewModel>)中每一筆記錄之ProductId, // 讀取對應之List<ProductSizeViewModel>與List<ProductColorViewModel>再分別指定給List<CartListViewModel>中的lstPSVM和lstPCVM。 for (int i = 0; i <= lstCLVM.Count - 1; i++) { // 5-1.系統讀取商品尺寸資料。 lstCLVM[i].lstPSVM = await IPRR.GetProductSize(lstCLVM[i].ProductId); // 5-2.系統讀取商品顏色資料。 lstCLVM[i].lstPCVM = await IPRR.GetProductColor(lstCLVM[i].ProductId); } List <MemberDeliveryAddressListViewModel> MDAL = await IMER.GetMemberDeliveryAddressList(MemberMobile, null, null, null, 0, 10); // 5-3.系統回傳View【Cart/Index】,並回傳new CartHomesViewModel { lstCLVM=4傳回值, MVM=4-1傳回值, Freight=4-2讀取值}。 return(View(new CartHomesViewModel { lstCLVM = lstCLVM, MVM = MVM, Freight = ofvm, MDAL = MDAL })); }
public async Task <IActionResult> Success(ContactDataViewModel ContactData, string OrderId, string MemberMobile, byte OrderStateId = 40) { PostOrderViewModel1 povm = null; int ret = 0; try { if (OrderStateId == 1) { // 3.系統在Action【Cart/Success】判斷2傳送OrderStateId==1。 // 4.系統變更訂單狀態為1。 ret = await IMER.UpdateOrderState(OrderId, OrderStateId); if (ret != 0) { return(View(new PostOrderViewModel1 { OrderDetail = null, ContactData = null, CartTobal = -1, OrderId = "", RtnModel = null, MemberMobile = MemberMobile, ret = ret })); } } if (OrderStateId == 2) { // 3.系統在Action【Cart/Success】判斷2傳送OrderStateId==2。 // 4.系統變更訂單狀態為2。 ret = await IMER.UpdateOrderState(OrderId, OrderStateId); if (ret != 0) { return(View(new PostOrderViewModel1 { OrderDetail = null, ContactData = null, CartTobal = -1, OrderId = "", RtnModel = null, MemberMobile = MemberMobile, ret = ret })); } } List <OrderCheckProductStockEnoughViewModel> OCPSE = await IOR.OrderCheckProductStockEnough(OrderId); if (OCPSE == null) { return(View(new PostOrderViewModel1 { OrderDetail = null, ContactData = null, CartTobal = -1, OrderId = "", RtnModel = null, MemberMobile = MemberMobile, ret = ret, OCPSE = OCPSE })); } // 3a.系統在Action【Cart/Success】判斷2傳送OrderStateId!=1。 // 3a-1.回4-1。 // 4-1.系統刪除會員之所有購物車資料。 ret = await IMER.DeleteAllMemberCarts(MemberMobile); if (ret != 0) { return(View(new PostOrderViewModel1 { OrderDetail = null, ContactData = null, CartTobal = -1, OrderId = "", RtnModel = null, MemberMobile = MemberMobile })); } // 16.系統讀取訂單明細。 List <CartListViewModel> lstCLVM = await IOR.GetOrderDetail(OrderId); // 17.系統更新商品庫存。 ret = await IOR.UpdateProductStock(lstCLVM); if (ret != 0) { return(View(new PostOrderViewModel1 { OrderDetail = null, ContactData = null, CartTobal = -1, OrderId = "", RtnModel = null, MemberMobile = MemberMobile })); } // 5.系統在Action【Cart/Success】寄發建立訂單eMail(含平台連結)。 //EmailMessage em = new EmailMessage(); //EmailAddress fAdd = new EmailAddress(); //fAdd.Name = IEC.SmtpUsername; //fAdd.Address = $@"{IEC.SmtpUsername}"; ////fAdd.Address = $@"{IEC.SmtpUsername}@{IEC.SmtpServer}"; //em.FromAddresses.Add(fAdd); //EmailAddress tAdd = new EmailAddress(); //tAdd.Name = ContactData.MemberName; //tAdd.Address = ContactData.eMail; //em.ToAddresses.Add(tAdd); //em.Subject = "288訂購訊息"; //em.Content = "您好,\n"; //em.Content += $"您在288建立的訂單己完成,訂單代碼為{OrderId},<br>"; //em.Content += $"若為會員,請至本平台會員中心查詢訂單處理狀態,<br>"; //em.Content += $"若非會員,本平台會寄送eMail告知訂單處理狀況,<br>"; //em.Content += $"288網址:http://dreammaker.game.tw/YunQiWholesale,<br>"; //em.Content += $"客服專線:04-28825252"; //em.Content += $"288應謝您!"; // System.Net.Mail.MailMessage Message //IES.Send(em); // 5.系統在Action【Cart/Success】寄發建立訂單eMail(含平台連結)。 System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(); mail.To.Add(ContactData.eMail); mail.From = new System.Net.Mail.MailAddress($@"{IEC.SmtpUsername}@{IEC.SmtpServer}"); mail.Subject = "288訂購訊息"; mail.Body = "您好,\n"; mail.Body += $"您在288建立的訂單己完成,訂單代碼為{OrderId},<br>"; mail.Body += $"若為會員,請至本平台會員中心查詢訂單處理狀態,<br>"; mail.Body += $"若非會員,本平台會寄送eMail告知訂單處理狀況,<br>"; mail.Body += $"288網址:http://dreammaker.game.tw/YunQiWholesale,<br>"; mail.Body += $"客服專線:04-28825252"; mail.Body += $"288應謝您!"; mail.IsBodyHtml = true; IES.SendMail(mail); // 6.系統判斷5執行成功。 // 7.系統回傳View【Cart/Success】,並傳回new PostOrderViewModel1 { OrderDetail=null, ContactData=contactData, CartTobal= null, OrderId=4上傳orderId, RtnModel=null }。 povm = new PostOrderViewModel1 { OrderDetail = null, ContactData = ContactData, CartTobal = -1, OrderId = OrderId, RtnModel = null, MemberMobile = MemberMobile }; } catch (Exception ex) { string msg = ex.Message; // 6a.系統判斷5執行失敗。 // 6a-1.系統回傳View【Cart/Success】,並傳回new PostOrderViewModel1 { OrderDetail=null, ContactData=null, CartTobal= null, OrderId="", RtnModel=null }。 povm = new PostOrderViewModel1 { OrderDetail = null, ContactData = null, CartTobal = -1, OrderId = "", RtnModel = null, MemberMobile = MemberMobile }; } return(View(povm)); }
public async Task <IViewComponentResult> InvokeAsync(string MemberMobile, List <CartsViewModel> Carts, ContactDataViewModel ContactData, int CartTobal) { TradeSPToken RtnModel = null; List <CartListViewModel> lstCLVM = null; string OrderId = ""; try { //檢查商品庫存 foreach (var o in Carts) { int stock = await IMR.MemberCartCheck(o.productId, o.sizeId, o.colorId, o.quantity); if (stock != 0) { return(View(new PostOrderViewModel1 { ret = stock, product = o.product })); } } // 8.系統讀取當日最後一張訂單號。 DateTime dt = DateTime.Now; OrderIdViewModel Order = await IMR.GetNewOrderId(dt); if (Order != null) { // 9.系統判斷8傳回值!=null。 // 10.系統設定OrderId=年月日+<8讀取值最後4碼加1>。 OrderId = Data.GetNewId(Order.OrderId, 9, 4); } else { // 9a.系統判斷8傳回值==null。 // 9a-1.系統設定OrderId=年月日+<0201>。 // 9a-2.回11。 OrderId = Data.GetStartId("B", dt); } // 6.系統在ViewComponent【Cart/PostOrder】中建立一筆綠界訂單。 string MerchantIDTmp = config["MerchantID"]; string TradeDesc = config["TradeDesc"]; //測試環境轉正式環境 //測試 //string MerchantID = "2000132"; //string HashKey = "5294y06JbISpM5x9"; //string HashIV = "v77hoKGq4kWxNNIS"; //string PostURL = "https://payment-stage.ecpay.com.tw/SP/CreateTrade"; //正式 string MerchantID = "3084097"; string HashKey = "AIlPEruFqmb1fZmz"; string HashIV = "oKf58WmB9vgevdrj"; string PostURL = "https://payment.ecpay.com.tw/SP/CreateTrade"; SortedDictionary <string, string> PostCollection = new SortedDictionary <string, string>(); PostCollection.Add("MerchantID", MerchantID); PostCollection.Add("MerchantTradeNo", $"{OrderId}{MerchantIDTmp}"); //PostCollection.Add("MerchantTradeNo", DateTime.Now.ToString("yyyyMMddHHmmss")); //PostCollection.Add("MerchantTradeNo", "sdfg1561/"); PostCollection.Add("MerchantTradeDate", dt.ToString("yyyy/MM/dd HH:mm:ss")); PostCollection.Add("PaymentType", "aio"); PostCollection.Add("TotalAmount", CartTobal.ToString()); PostCollection.Add("TradeDesc", TradeDesc); string ItemName = ""; foreach (var item in Carts) { ItemName += $"{item.product}{item.price}元#"; } ItemName = ItemName.Substring(0, ItemName.Length - 1); PostCollection.Add("ItemName", ItemName); PostCollection.Add("ReturnURL", config.GetConnectionString("ReturnURL")); PostCollection.Add("PaymentInfoURL", config.GetConnectionString("PaymentInfoURL")); PostCollection.Add("ChoosePayment", "ALL"); PostCollection.Add("EncryptType", "1"); PostCollection.Add("NeedExtraPaidInfo", "N"); PostCollection.Add("IgnorePayment", ""); //記憶卡號 //PostCollection.Add("BidingCard", ""); //PostCollection.Add("MerchantMemberID", ""); //分期付款 //PostCollection.Add("StoreID", ""); // PostCollection.Add("CustomField1", ""); //PostCollection.Add("CustomField2", ""); //PostCollection.Add("CustomField3", ""); // PostCollection.Add("CustomField4", ""); //定期定額 //PostCollection.Add("PeriodAmount", "5"); //PostCollection.Add("PeriodType", "Y"); //PostCollection.Add("Frequency", "1"); //PostCollection.Add("ExecTimes", "6"); //PostCollection.Add("PeriodReturnURL", "http://127.0.0.1/01/CheckOutFeedback.php"); //紅利折抵 //PostCollection.Add("Redeem", "Y"); //ATM繳費期限 //PostCollection.Add("ExpireDate", ""); //CVS&BARCODE繳費期限 //PostCollection.Add("StoreExpireDate", ""); //電子發票 //PostCollection.Add("InvoiceMark", "N");//電子發票開立註記 //PostCollection.Add("RelateNumber", DateTime.Now.ToString("yyyyMMddHHmmss")); //會員自訂編號 //PostCollection.Add("CustomerID", "");//客戶代號 //PostCollection.Add("CustomerName", "");//客戶名稱 //PostCollection.Add("CustomerAddr", "");//客戶地址 //PostCollection.Add("CustomerPhone", "0912345678");//客戶手機號碼 //PostCollection.Add("CustomerEmail", ""); //PostCollection.Add("TaxType", "1");//課稅類別 //PostCollection.Add("CarruerType", "");//載具類別 //PostCollection.Add("CarruerNum", ""); //PostCollection.Add("Donation", "2");//捐贈註記 //PostCollection.Add("LoveCode", "");//捐贈註記 //PostCollection.Add("Print", "0");//列印註記 //PostCollection.Add("InvoiceItemName", "商品名稱");//商品名稱 //PostCollection.Add("InvoiceItemCount", "1");//商品數量 //PostCollection.Add("InvoiceItemWord", "個");//商品單位 //PostCollection.Add("InvoiceItemPrice", "100");//商品價格 //PostCollection.Add("InvoiceItemTaxType", "");//商品課稅別 //PostCollection.Add("InvoiceRemark", "");//備註 //PostCollection.Add("DelayDay", "0");//延遲天數 //PostCollection.Add("InvType", "07");//字軌類別 //計算檢查碼 string str = string.Empty; string str_pre = string.Empty; foreach (var test in PostCollection) { str += string.Format("&{0}={1}", test.Key, test.Value); } str_pre += string.Format("HashKey={0}" + str + "&HashIV={1}", HashKey, HashIV); string urlEncodeStrPost = HttpUtility.UrlEncode(str_pre); string ToLower = urlEncodeStrPost.ToLower(); string sCheckMacValue = Data.GetSHA256(ToLower); PostCollection.Add("CheckMacValue", sCheckMacValue); string Result = ""; string ParameterString = string.Join("&", PostCollection.Select(p => p.Key + "=" + p.Value)); //### Server Post using (WebClient wc = new System.Net.WebClient()) { ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; wc.Encoding = Encoding.UTF8; wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; Result = wc.UploadString(PostURL, ParameterString); } //### 轉Model RtnModel = JsonConvert.DeserializeObject <TradeSPToken>(Result); if (RtnModel.RtnCode != "1") { // 7a.系統判斷6執行失敗。 // 7a-1.系統回傳null。 RtnModel = null; } // 7.系統判斷6成功執行。 lstCLVM = new List <CartListViewModel>(); CartListViewModel CLVM; if (MemberMobile != "" && MemberMobile != null) { // 11.系統判斷MemberMobile!=""。 // 12.系統讀取購物車清單。 lstCLVM = await IMER.GetCartList(MemberMobile); foreach (var item in lstCLVM) { item.OrderId = OrderId; } } else { // 11a.系統判斷MemberMobile==""。 // 11a-1.系統將carts轉換為List<CartListViewModel>。 foreach (CartsViewModel item in Carts) { CLVM = new CartListViewModel(); CLVM.ProductId = item.productId; CLVM.Product = item.product; CLVM.ProducSizeId = item.sizeId; CLVM.ProductColorId = item.colorId; CLVM.Quantity = item.quantity; CLVM.Price = item.price; CLVM.ProductSize = item.size; CLVM.ProductColor = item.color; CLVM.OrderId = OrderId; lstCLVM.Add(CLVM); } // 11a-2.回13。 } // 13.系統新增一筆內部訂單。 int ret = await IMR.InsertOrder(OrderId, dt, MemberMobile, ContactData.Freight, CartTobal - ContactData.Freight, CartTobal, ContactData.MemberName, ContactData.eMail, ContactData.Phone, ContactData.ContactAddress, sCheckMacValue, lstCLVM, $"{OrderId}{MerchantIDTmp}", ContactData.MemberMobile); if (ret == 0) { // 14.系統判斷13執行成功。 // 15.系統設定傳回值=12讀取值。 } else { // 14a.系統判斷13執行失敗。 // 14a-1.系統設定傳回Model=null。 lstCLVM = null; RtnModel = null; // 14a-2.回16。 } } catch (Exception ex) { RtnModel = null; } // 16.系統回傳View【Cart/PostOrder】,並傳回new PostOrderViewModel1 // { OrderDetail=15設定傳回值, ContactData=contactData, CartTobal= cartTobal, OrderId=10設定OrderId, RtnModel=金流公司的TradeSPToken }。 return(View(new PostOrderViewModel1 { OrderDetail = lstCLVM, ContactData = ContactData, CartTobal = CartTobal, OrderId = OrderId, RtnModel = RtnModel })); }