Exemplo n.º 1
0
        /// <summary>
        /// 把购物车添加到订单
        /// </summary>
        void setAddOrder()
        {
            string uname = string.Empty; string uphone = string.Empty; string address = string.Empty;
            string payway = string.Empty; string carryway = string.Empty; string countcost = string.Empty;
            string leavemsg = string.Empty; string zipcode = string.Empty; string num = string.Empty;

            #region --------------获取请求信息---------------
            if (Request["num"] != null && Request["num"] != "")
            {
                num = Request["num"];
            }
            if (Request["uname"] != null && Request["uname"] != "")
            {
                uname = Common.Common.NoHtml(Request["uname"]);
            }
            if (Request["uphone"] != null && Request["uphone"] != "")
            {
                uphone = Common.Common.NoHtml(Request["uphone"]);
            }
            if (Request["address"] != null && Request["address"] != "")
            {
                address = Request["address"];
            }
            if (Request["payway"] != null && Request["payway"] != "")
            {
                payway = Common.Common.NoHtml(Request["payway"]);
            }
            if (Request["carryway"] != null && Request["carryway"] != "")
            {
                carryway = Common.Common.NoHtml(Request["carryway"]);
            }
            if (Request["countcost"] != null && Request["countcost"] != "")
            {
                countcost = Common.Common.NoHtml(Request["countcost"]);
            }
            if (Request["leavemsg"] != null && Request["leavemsg"] != "")
            {
                leavemsg = Common.Common.NoHtml(Request["leavemsg"]);
            }
            if (Request["zipcode"] != null && Request["zipcode"] != "")
            {
                zipcode = Common.Common.NoHtml(Request["zipcode"]);
            }
            #endregion
            if (customid.Trim() != null && customid.Trim() != "")
            {
                MSShoppingCartDAL cartDal  = new MSShoppingCartDAL();
                MSProductOrderDAL OrderDal = new MSProductOrderDAL();
                if (OrderDal.ExistOrderByUID(customid, strpid))
                {
                    Response.Write("{\"error\":true,\"exist\":true}");
                }
                else
                {
                    try
                    {
                        string strOrdernum = cartDal.SubOrder(customid, uname, uphone, leavemsg,
                                                              address, zipcode, strpid, countcost, num, mid);
                        if (strOrdernum != null && strOrdernum != "")
                        {
                            strSiteCode = "VYIGO";
                            MSOrderLogDAL.AddMSOrderLog("客户【" + customid + "】下单成功,订单号为【" + strOrdernum + "】");
                            MSProductDAL productDal = new MSProductDAL();
                            string       pnam       = string.Empty;
                            if (strpid != null && strpid != "")
                            {
                                pnam = productDal.GetMSProductVaueByID("Ptitle", strpid).ToString();
                            }

                            #region -发消息到店铺注册用户
                            string p_uid = string.Empty; string p_openid = string.Empty;
                            if (strpid != null && strpid != "")
                            {
                                try
                                {
                                    p_uid = productDal.GetMSProductVaueByID("CustomerID", strpid).ToString();
                                }
                                catch (Exception)
                                {
                                }
                            }
                            if (p_uid != null && p_uid != "")
                            {
                                MSCustomersDAL P_UDal = new MSCustomersDAL();
                                try
                                {
                                    p_openid = P_UDal.GetCustomerValueByID("OpenID", p_uid).ToString();
                                }
                                catch (Exception)
                                {
                                }
                            }
                            if (p_openid != null && p_openid != "" && strSiteCode != null && strSiteCode != "")
                            {
                                JQDialog.SendWeiXinMsg(strSiteCode, p_openid,
                                                       "亲爱的店长大人,您的宝贝【" + pnam + "】已于" +
                                                       DateTime.Now.ToString("yyyy年MM月dd日 HH:mm:ss") +
                                                       "被" + uname + "成功买下,单号【" + strOrdernum + "】赶紧去小店看看吧!");
                            }
                            MSOrderLogDAL.AddMSOrderLog("下单成功,通知到OpenID为【" + p_openid + "】的店长");
                            #endregion

                            #region -产品属性
                            MSProductParaDAL paraDal = new MSProductParaDAL();
                            int stock = 0;
                            if (paraDal.ExistMSPPara("", strpid) && mid != null && mid != "")
                            {
                                try
                                {
                                    stock = int.Parse(paraDal.GetMSPParaValueByID("Stock", mid).ToString());
                                }
                                catch (Exception)
                                {
                                }
                                if (stock > 0)
                                {
                                    int buynum = 0;
                                    try
                                    {
                                        buynum = Convert.ToInt32(quantity);
                                    }
                                    catch (Exception)
                                    {
                                    }
                                    if (buynum != 0 && buynum < stock)
                                    {
                                        stock = stock - buynum;
                                        paraDal.UpdateStock(stock, mid);
                                    }
                                }
                            }
                            #endregion
                            DataSet orderds     = cartDal.GetMyOrderDetail(strOrdernum);
                            string  payinfo     = string.Empty;
                            string  productname = string.Empty; //用户购买的商品名称
                            string  ordernum    = string.Empty; //订单号
                            if (orderds != null && orderds.Tables.Count > 0 && orderds.Tables[0].Rows.Count > 0)
                            {
                                productname = orderds.Tables[0].Rows[0]["Ptitle"].ToString();
                                ordernum    = orderds.Tables[0].Rows[0]["ID"].ToString();
                                //payinfo= WapPayHelper.BuildRequest(productname, ordernum, countcost, customid);
                            }
                            if (productname.Trim() != null && productname.Trim() != "" && ordernum != null && ordernum != "")
                            {
                                //Response.Write("{\"success\":true,\"payinfo\":\"" + payinfo + "\"}");
                                Response.Write("{\"success\":true,\"pname\":\"" + productname +
                                               "\",\"ordernum\":\"" + ordernum + "\",\"countcost\":\"" + countcost +
                                               "\",\"customid\":\"" + customid + "\",\"openid\":\"" + openid + "\"}");
                            }
                        }
                        else
                        {
                            Response.Write("{\"error\":true,\"msg\":\"操作失败,重新操作\"}");
                        }
                    }
                    catch (Exception)
                    {
                        Response.Write("{\"error\":true,\"msg\":\"操作失败,重新操作\"}");
                    }
                }
            }
            else
            {
                setCookies();
                Response.Write("{\"error\":true,\"msg\":\"操作失败,请登录后再操作\",\"loginurl\":\"UserLogin.aspx\"}");
            }
            Response.End();
        }