Example #1
0
        public ActionResult Order()
        {//完成訂購
            var      open = openLogic();
            Purchase md   = new Purchase();

            using (var db0 = getDB0())
            {
                md        = db0.Purchase.FirstOrDefault();//隨便抓第一筆
                md.Deatil = md.PurchaseDetail.ToList();
            }
            OrderEmail emd = new OrderEmail()
            {
                purchase      = md,
                AccountName   = (string)open.getParmValue(ParmDefine.AccountName),
                AccountNumber = (string)open.getParmValue(ParmDefine.AccountNumber),
                BankCode      = (string)open.getParmValue(ParmDefine.BankCode),
                BankName      = (string)open.getParmValue(ParmDefine.BankName)
            };

            return(View("Email_order", emd));
        }
Example #2
0
        /// <summary>
        /// 送出訂單
        /// </summary>
        /// <param name="md"></param>
        /// <param name="ctr"></param>
        /// <returns></returns>
        public ResultInfo sendOrderMail(OrderEmail md)
        {
            ResultInfo r = new ResultInfo();

            try
            {
                #region 信件發送
                string  Body = getMailBody("../Email/Email_order", md, newContext);//套用信件版面
                Boolean mail;

                #region 收信人及寄信人
                string sendMail = openLogic().getReceiveMails()[0];

                List <string> r_mails = openLogic().getReceiveMails().ToList();
                if (!r_mails.Any(x => x == md.purchase.receive_name))
                {
                    r_mails.Add(md.purchase.receive_name + ":" + md.purchase.receive_email);
                }
                #endregion

                mail = Mail_Send(sendMail,                                                                     //寄信人
                                 r_mails.ToArray(),                                                            //收信人
                                 string.Format(Resources.Res.MailTitle_Order, Resources.Res.System_FrontName), //信件標題
                                 Body,                                                                         //信件內容
                                 true);                                                                        //是否為html格式
                if (mail == false)
                {                                                                                              //送信失敗
                    r.result  = false;
                    r.message = Resources.Res.Log_Err_SendMailFail;
                    return(r);
                }
                #endregion
            }
            catch (Exception ex)
            {
                r.result  = false;
                r.message = ex.Message;
            }
            return(r);
        }
        public string setOrder(Purchase md)
        {
            ResultInfo r = new ResultInfo();

            r.result = true; r.hasData = true;             //預設
            HttpCookie cart = getCookie(this.CartSession); //改用cookie+json格式方式記錄購物車內容

            try
            {
                #region 送出訂單
                using (var db0 = getDB0())
                {
                    #region  產品不存在或下架
                    bool p_check = false; List <string> err = new List <string>();
                    foreach (var d in md.Deatil)
                    {
                        bool d_check = db0.ProductDetail.Any(x => x.product_detail_id == d.product_detail_id & x.product_id == d.product_id &
                                                             x.Product.stock_state == (int)IStockState.on_store_shelves & x.stock_state == (int)IStockState.on_store_shelves &
                                                             !x.Product.i_Hide);
                        if (d_check)
                        {
                            var item = db0.ProductDetail.Find(d.product_detail_id);
                            d.p_d_sn        = item.sn;                   //產品料號
                            d.p_name        = item.Product.product_name; //產品名稱
                            d.p_d_pack_name = item.pack_name;            //產品包裝
                            d.price         = item.price;                //產品價格
                            d.sub_total     = item.price * d.qty;
                        }
                        else
                        {
                            p_check = true;
                            err.Add(d.p_name);
                        }
                    }
                    if (p_check)
                    {//有產品不存在或下架
                        r.result  = false;
                        r.message = string.Format(Resources.Res.Log_Err_AddCart_Exist, String.Join("、", err.ToArray()));
                        return(defJSON(r));
                    }
                    md.total = md.Deatil.Sum(x => x.sub_total) + md.ship_fee + md.bank_charges + md.discount;
                    #endregion
                }
                #region 加入會員
                if (!this.isLogin)
                {
                    var customer = new Customer()
                    {
                        email   = md.receive_email,
                        c_pw    = Server.UrlEncode(EncryptString.desEncryptBase64(md.receive_mobile)),//預設密碼改為手機
                        c_name  = md.receive_name,
                        tel     = md.receive_tel,
                        mobile  = md.receive_mobile,
                        zip     = md.receive_zip,
                        address = md.receive_address
                    };
                    r = addCustomer(customer);
                    if (r.result)
                    {
                        md.customer_id = r.id;
                    }
                    else
                    {//會員註冊失敗
                        r.result  = false;
                        r.message = r.message;
                        return(defJSON(r));
                    }
                }

                #endregion
                r = addPurchase(md);
                if (md.receive_email != null & r.result)
                {//寄送email
                    var        open = openLogic();
                    OrderEmail emd  = new OrderEmail()
                    {
                        purchase      = md,
                        isLogin       = this.isLogin,
                        AccountName   = (string)open.getParmValue(ParmDefine.AccountName),
                        AccountNumber = (string)open.getParmValue(ParmDefine.AccountNumber),
                        BankCode      = (string)open.getParmValue(ParmDefine.BankCode),
                        BankName      = (string)open.getParmValue(ParmDefine.BankName)
                    };

                    #region 信件發送
                    ResultInfo sendmail = (new EmailController()).sendOrderMail(emd);
                    #endregion
                    if (!sendmail.result)
                    {//送信失敗
                        r.result  = true;
                        r.hasData = false;
                        r.message = sendmail.message;
                    }
                    else
                    {
                        r.message = Resources.Res.Log_Success_Order;
                    }

                    #region 刪除Cookie
                    if (cart != null)
                    {
                        cart.Expires = DateTime.Now.AddDays(-1);
                        Response.AppendCookie(cart);
                    }
                    #endregion
                }
                #endregion
            }
            catch (Exception ex)
            {
                r.result  = false;
                r.message = ex.Message;
            }
            return(defJSON(r));
        }
        /// <summary>
        /// 結帳
        /// </summary>
        /// <returns></returns>
        public string PutPurchaseData(receive md)
        {
            ResultInfo r = new ResultInfo();
            bool send_mail = false;
            try
            {
                if (!this.isLogin)
                {
                    r.result = false;
                    r.message = "請登入會員後再結帳!";
                    return defJSON(r);
                }
                //if (md.email == null)
                //{
                //    r.result = false;
                //    r.message = "信箱號碼未填寫!";
                //    return defJSON(r);
                //}
                if (Session["PurchaseOnline"] != null)
                {
                    Cart cart = (Cart)Session["PurchaseOnline"];
                    PEmailInfo info = addPurchase(cart, md);
                    if (info.result)
                    {
                        Session["PurchaseOnline"] = null;
                        #region 取得資訊
                        var open = openLogic();
                        r.no = info.purchase_no;
                        OrderEmail emd = new OrderEmail();
                        emd.receive = md;
                        emd.detail = info.detail;
                        emd.purchase_no = info.purchase_no;
                        emd.set_date = info.set_date.ToString("yyyy-MM-dd HH:mm");
                        emd.total = info.total;
                        emd.AccountName = (string)open.getParmValue(ParmDefine.AccountName);
                        emd.AccountNumber = (string)open.getParmValue(ParmDefine.AccountNumber);
                        emd.BankCode = (string)open.getParmValue(ParmDefine.BankCode);
                        emd.BankName = (string)open.getParmValue(ParmDefine.BankName);
                        #endregion

                        if (md.email != null)
                        {//有填寫email才寄信
                            #region 信件發送
                            string Body = getMailBody("../Email/Email_order", emd);//套用信件版面
                            Boolean mail;

                            #region 收信人及寄信人
                            string sendMail = openLogic().getReceiveMails()[0];

                            List<string> r_mails = openLogic().getReceiveMails().ToList();
                            if (!r_mails.Any(x => x == md.email)) { r_mails.Add(md.receive_person + ":" + md.email); }
                            #endregion

                            string mailfrom = md.email;

                            mail = Mail_Send(sendMail, //寄信人
                                            r_mails.ToArray(), //收信人
                                            CommWebSetup.MailTitle_Order, //信件標題
                                            Body, //信件內容
                                            true); //是否為html格式
                            if (mail == false)
                            {
                                r.result = true;
                                r.message = "信箱號碼不正確或送信失敗!";
                                return defJSON(new { data = r, mail = send_mail });
                            }
                            #endregion
                        }
                        r.result = true;
                        send_mail = true;
                    }
                    else {
                        r.result = false;
                    }
                }
                else
                {
                    r.result = false;
                    r.message = "購物車內無商品~!";
                }
            }
            catch (Exception ex)
            {
                r.result = false;
                r.message = ex.ToString();
            }
            return defJSON(new { data = r, mail = send_mail });
        }