Пример #1
0
        public HttpResponseBase SaveItemPrice()
        {
            string json = string.Empty;
            string msg = string.Empty;

            try
            {
                BLL.gigade.Model.Vendor vendorModel = (BLL.gigade.Model.Vendor)Session["vendor"];
                int writerID = (int)vendorModel.vendor_id;
                //获取前台输入的信息
                JavaScriptSerializer jsSer = new JavaScriptSerializer();
                string items = Request.Form["Items"];
                int same_price = (Request.Form["same_price"] ?? "") == "on" ? 1 : 0;
                string start = Request.Form["event_product_start"] ?? Request.Form["event_start"];
                string end = Request.Form["event_product_end"] ?? Request.Form["event_end"];
                string valid_start = Request.Form["valid_start"];
                string valid_end = Request.Form["valid_end"];

                #region product_item_temp 获取product_item_temp和product_temp的数据

                ProductTemp proTemp = new ProductTemp();
                List<ProductItemTemp> proItemTemps = jsSer.Deserialize<List<ProductItemTemp>>(items);

                if (!string.IsNullOrEmpty(Request.Form["ProductId"]))
                {
                    proTemp.Product_Id = Request.Form["ProductId"].ToString();
                    proItemTemps.ForEach(m => m.Product_Id = proTemp.Product_Id);
                }
                //if (!string.IsNullOrEmpty(Request.Form["OldProductId"]))
                //{
                //    proTemp.Product_Id = Request.Form["OldProductId"].ToString();
                //    proItemTemps.ForEach(m => m.Product_Id = proTemp.Product_Id);
                //}

                if (!string.IsNullOrEmpty(start))
                {
                    proItemTemps.ForEach(m => m.Event_Product_Start = Convert.ToUInt32(CommonFunction.GetPHPTime(start)));
                }
                if (!string.IsNullOrEmpty(end))
                {
                    proItemTemps.ForEach(m => m.Event_Product_End = Convert.ToUInt32(CommonFunction.GetPHPTime(end)));
                }
                if (!string.IsNullOrEmpty(Request.Form["product_price_list"]))
                {
                    uint product_price_list = 0;
                    uint.TryParse(Request.Form["product_price_list"] ?? "0", out product_price_list);
                    proTemp.Product_Price_List = product_price_list;
                }
                if (!string.IsNullOrEmpty(Request.Form["bag_check_money"]))
                {
                    proTemp.Bag_Check_Money = uint.Parse(Request.Form["bag_check_money"]);
                }
                proTemp.show_listprice = Convert.ToUInt32((Request.Form["show_listprice"] ?? "") == "on" ? 1 : 0);
                proTemp.Writer_Id = writerID;
                proTemp.Combo_Type = COMBO_TYPE;
                proItemTemps.ForEach(m => m.Writer_Id = proTemp.Writer_Id);
                proTemp.Create_Channel = 2;
                _productTempMgr = new ProductTempMgr(connectionString);

                #region PriceMasterTemp 获取PriceMasterTemp的数据


                PriceMasterTemp priceMasterTemp = new PriceMasterTemp { price_status = 1, same_price = same_price };
                priceMasterTemp.product_id = proTemp.Product_Id;
                priceMasterTemp.combo_type = COMBO_TYPE;
                priceMasterTemp.product_name = Request.Form["product_name"] ?? "";
                priceMasterTemp.writer_Id = proTemp.Writer_Id;
                priceMasterTemp.site_id = 1;//默認站臺1:吉甲地
                priceMasterTemp.user_level = 1;
                priceMasterTemp.price = Convert.ToInt32(proItemTemps.Min(m => m.Item_Money));
                priceMasterTemp.event_price = Convert.ToInt32(proItemTemps.Min(m => m.Event_Item_Money));
                priceMasterTemp.cost = Convert.ToInt32(proItemTemps.Min(m => m.Item_Cost));
                priceMasterTemp.event_cost = Convert.ToInt32(proItemTemps.Min(m => m.Event_Item_Cost));
                if (same_price == 0)
                {
                    priceMasterTemp.max_price = Convert.ToInt32(proItemTemps.Max(m => m.Item_Money));
                    priceMasterTemp.max_event_price = Convert.ToInt32(proItemTemps.Max(m => m.Event_Item_Money));
                }
                if (!string.IsNullOrEmpty(start))
                {
                    priceMasterTemp.event_start = Convert.ToUInt32(CommonFunction.GetPHPTime(start));
                }
                if (!string.IsNullOrEmpty(end))
                {
                    priceMasterTemp.event_end = Convert.ToUInt32(CommonFunction.GetPHPTime(end));
                }
                if (!string.IsNullOrEmpty(valid_start))
                {
                    priceMasterTemp.valid_start = Convert.ToInt32(CommonFunction.GetPHPTime(valid_start));
                }
                if (!string.IsNullOrEmpty(valid_end))
                {
                    priceMasterTemp.valid_end = Convert.ToInt32(CommonFunction.GetPHPTime(valid_end));
                }
                #endregion
                //执行
                _productItemTempMgr = new ProductItemTempMgr(connectionString);
                _priceMasterTempMgr = new PriceMasterTempMgr(connectionString);
                if (_productItemTempMgr.UpdateCostMoney(proItemTemps) && _productTempMgr.PriceBonusInfoSaveByVendor(proTemp) > 0)//供應商商品無購物金
                {
                    bool result = false;
                    PriceMasterTemp query = new PriceMasterTemp { writer_Id = priceMasterTemp.writer_Id, product_id = proTemp.Product_Id, combo_type = COMBO_TYPE };
                    if (_priceMasterTempMgr.QueryByVendor(query) == null)//插入
                    {
                        result = _priceMasterTempMgr.Save(new List<PriceMasterTemp> { priceMasterTemp }, null, null);
                    }
                    else//更新
                    {
                        result = _priceMasterTempMgr.UpdateByVendor(new List<PriceMasterTemp> { priceMasterTemp }, null);
                    }
                    json = "{success:" + result.ToString().ToLower() + "}";
                }
                else
                {
                    json = "{success:false}";
                }
                #endregion

            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                json = "{success:false,msg:'" + Resources.VendorProduct.SAVE_FAIL + "'}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
        public string ComboPriceSave()
        {
            string json = "{success:true,msg:'" + Resources.VendorProduct.SAVE_SUCCESS + "'}";
            #region 參數

            BLL.gigade.Model.Vendor vendorModel = (BLL.gigade.Model.Vendor)Session["vendor"];
            int writer_id = Convert.ToInt32(vendorModel.vendor_id);

            string product_name = Request.Params["product_name"];
            string price_type = Request.Params["price_type"];
            string product_price_list = Request.Params["product_price_list"];
            string price = Request.Params["price"];
            string cost = Request.Params["cost"];
            string max_price = Request.Params["max_price"];
            string event_price = Request.Params["event_price"];
            string event_cost = Request.Params["event_cost"];
            string max_event_price = Request.Params["max_event_price"];
            string event_start = Request.Params["event_start"];
            string event_end = Request.Params["event_end"];
            string bag_check_money = Request.Params["bag_check_money"] == "" ? "0" : Request.Params["bag_check_money"];
            string same_price = Request.Params["same_price"];
            string show_listprice = Request.Params["show_listprice"];
            string valid_start = Request.Params["valid_start"];
            string valid_end = Request.Params["valid_end"];

            #endregion

            string Vendor_productId = string.Empty;
            if (!string.IsNullOrEmpty(Request.Params["product_id"]))
            {
                Vendor_productId = Request.Params["product_id"];
            }
            //if (!string.IsNullOrEmpty(Request.Form["OldProductId"]))
            //{
            //    Vendor_productId = Request.Params["OldProductId"];
            //}

            ProductTemp pTemp = new ProductTemp();
            List<PriceMasterTemp> pMasterListT = new List<PriceMasterTemp>();

            List<List<ItemPrice>> ItemPList = new List<List<ItemPrice>>();
            PriceMasterTemp pMasterTemp = new PriceMasterTemp();

            #region 臨時表數據修改
            try
            {
                #region product_temp
                //product_temp
                pTemp.Product_Id = Vendor_productId;
                pTemp.Product_Price_List = uint.Parse(product_price_list);
                pTemp.Writer_Id = writer_id;
                pTemp.Combo_Type = COMBO_TYPE;
                pTemp.Price_type = int.Parse(price_type);
                pTemp.Bag_Check_Money = uint.Parse(bag_check_money);
                pTemp.show_listprice = uint.Parse(show_listprice);
                pTemp.Create_Channel = 2;

                #endregion

                #region Price_Master
                //Price_Master
                pMasterTemp.product_id = Vendor_productId;
                pMasterTemp.product_name = product_name;
                pMasterTemp.writer_Id = writer_id;
                pMasterTemp.combo_type = COMBO_TYPE;
                //默認站臺1:吉甲地,(按統一價格比例拆分)會員等級1:普通會員
                pMasterTemp.site_id = 1;
                pMasterTemp.user_level = 1;
                pMasterTemp.same_price = int.Parse(same_price);
                pMasterTemp.price = int.Parse(price);
                pMasterTemp.cost = int.Parse(cost);
                pMasterTemp.max_price = int.Parse(max_price);
                pMasterTemp.max_event_price = int.Parse(max_event_price);
                pMasterTemp.event_price = int.Parse(event_price);
                pMasterTemp.event_cost = int.Parse(event_cost);
                #endregion

                #region 時間 活動時間
                if (event_start != "")
                {
                    pMasterTemp.event_start = Convert.ToUInt32(CommonFunction.GetPHPTime(event_start));
                }
                if (event_end != "")
                {
                    pMasterTemp.event_end = Convert.ToUInt32(CommonFunction.GetPHPTime(event_end));
                }
                if (!string.IsNullOrEmpty(valid_start))
                {
                    pMasterTemp.valid_start = Convert.ToInt32(CommonFunction.GetPHPTime(valid_start));
                }
                if (!string.IsNullOrEmpty(valid_end))
                {
                    pMasterTemp.valid_end = Convert.ToInt32(CommonFunction.GetPHPTime(valid_end));
                }

                #endregion

                pMasterTemp.price_status = 1;

                pMasterListT.Add(pMasterTemp);

                //如果原價格為複製價格,則需刪除原複製價格並將child_id設為oldProductId
                if (!string.IsNullOrEmpty(Vendor_productId))
                {
                    pMasterListT.ForEach(m =>
                    {
                        if (string.IsNullOrEmpty(m.child_id) || m.child_id == "0")
                        {
                            m.child_id = Vendor_productId.ToString();
                        }
                    });
                }

                //查詢                 
                _pMasterTempMgr = new PriceMasterTempMgr(connectionString);
                PriceMasterProductCustomTemp queryReust = _pMasterTempMgr.QueryByVendor(new PriceMasterTemp() { writer_Id = writer_id, child_id = Vendor_productId.ToString(), product_id = Vendor_productId, combo_type = COMBO_TYPE });
                //檢查價格類型是否有變動,如果有則刪除原有價格數據
                if (queryReust != null)
                {
                    if (!price_type.Equals(queryReust.price_type.ToString()))
                    {
                        _combTempMgr = new ProductComboTempMgr(connectionString);
                        _combTempMgr.comboPriceDeleteByVendor(new ProductComboTemp { Writer_Id = writer_id, Combo_Type = COMBO_TYPE, Parent_Id = Vendor_productId });
                        queryReust = null;
                    }
                }

                if (queryReust == null)//插入
                {
                    if (price_type == "1")
                    {
                        _pMasterTempMgr.SaveByVendor(pMasterListT, null, null);
                    }
                }
                else//更新
                {
                    if (price_type == "1")
                    {
                        _pMasterTempMgr.UpdateByVendor(pMasterListT, null);
                    }
                }
                _productTempMgr = new ProductTempMgr(connectionString);
                _productTempMgr.PriceBonusInfoSaveByVendor(pTemp);

            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                json = "{success:false,msg:'" + Resources.VendorProduct.SAVE_FAIL + "'}";
            }
            #endregion

            return json;

        }