public DataOperation(List<Model.MigrationDataSet> mds, MainForm form) { this.mds = mds; this.connectionString = System.Configuration.ConfigurationSettings.AppSettings["MySqlConnectionString"]; prod = new Product(); pItem = new ProductItem(); pM = new PriceMaster(); iPrice = new ItemPrice(); categorySet = new ProductCategorySet(); pMap = new ProductMigrationMap(); _prodMgr = new ProductMgr(this.connectionString); _priceMgr = new PriceMasterMgr(this.connectionString); _prodItemMgr = new ProductItemMgr(this.connectionString); _itemPriceMgr = new ItemPriceMgr(this.connectionString); _vendorBrandMgr = new VendorBrandMgr(this.connectionString); _vendorMgr = new VendorMgr(this.connectionString); _pMap = new ProductMigrationMgr(this.connectionString); _productCategorySetMgr = new ProductCategorySetMgr(this.connectionString); _productNoticeSetMgr = new ProductNoticeSetMgr(this.connectionString); _productTagSetMgr = new ProductTagSetMgr(this.connectionString); _productPictureMgr = new ProductPictureMgr(this.connectionString); _proStatusHistoryMgr = new ProductStatusHistoryMgr(connectionString); _proSpecMgr = new ProductSpecMgr(connectionString); _siteMgr = new SiteMgr(connectionString); this.form = form; }
public HttpResponseBase SaveItemPrice() { string json = string.Empty; string msg = string.Empty; try { if (!PriceMaster.CheckProdName(Request.Form["product_name"])) { json = "{success:false,msg:'" + Resources.Product.FORBIDDEN_CHARACTER + "'}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; } JavaScriptSerializer jsSer = new JavaScriptSerializer(); string items = Request.Form["Items"]; float default_bonus_percent = 0; float.TryParse(Request.Form["default_bonus_percent"] ?? "1", out default_bonus_percent); float bonus_percent = 0; float.TryParse(Request.Form["bonus_percent"] ?? "1", out bonus_percent); int same_price = (Request.Form["same_price"] ?? "") == "on" ? 1 : 0; int accumulated_bonus = (Request.Form["accumulated_bonus"] ?? "") == "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 bonus_start = Request.Form["bonus_percent_start"]; string bonus_end = Request.Form["bonus_percent_end"]; string valid_start = Request.Form["valid_start"]; string valid_end = Request.Form["valid_end"]; if (!string.IsNullOrEmpty(Request.Form["ProductId"]) && !string.IsNullOrEmpty(Request.Form["site_name"])) { #region price_master,item_price 新增站台价格 List<ItemPrice> itemPrices = jsSer.Deserialize<List<ItemPrice>>(items); PriceMaster priceMaster = new PriceMaster { bonus_percent = bonus_percent, default_bonus_percent = default_bonus_percent }; if (!string.IsNullOrEmpty(start)) { priceMaster.event_start = Convert.ToUInt32(CommonFunction.GetPHPTime(start)); } if (!string.IsNullOrEmpty(end)) { priceMaster.event_end = Convert.ToUInt32(CommonFunction.GetPHPTime(end)); } priceMaster.product_name = PriceMaster.Product_Name_FM(Request.Form["product_name"]); priceMaster.site_id = uint.Parse(Request.Form["site_name"]); priceMaster.product_id = uint.Parse(Request.Form["ProductId"]); priceMaster.user_level = uint.Parse(Request.Form["user_level"] ?? "1"); priceMaster.same_price = same_price; priceMaster.accumulated_bonus = Convert.ToUInt32(accumulated_bonus); priceMaster.price_status = 2;//申請審核 priceMaster.price = Convert.ToInt32(itemPrices.Min(m => m.item_money)); priceMaster.event_price = Convert.ToInt32(itemPrices.Min(m => m.event_money)); priceMaster.cost = Convert.ToInt32(itemPrices.Min(m => m.item_cost)); priceMaster.event_cost = Convert.ToInt32(itemPrices.Min(m => m.event_cost)); if (same_price == 0) { priceMaster.max_price = Convert.ToInt32(itemPrices.Max(m => m.item_money)); priceMaster.max_event_price = Convert.ToInt32(itemPrices.Max(m => m.event_money)); } if (!string.IsNullOrEmpty(bonus_start)) { priceMaster.bonus_percent_start = Convert.ToUInt32(CommonFunction.GetPHPTime(bonus_start)); } if (!string.IsNullOrEmpty(bonus_start)) { priceMaster.bonus_percent_end = Convert.ToUInt32(CommonFunction.GetPHPTime(bonus_end)); } if (!string.IsNullOrEmpty(valid_start)) { priceMaster.valid_start = Convert.ToInt32(CommonFunction.GetPHPTime(valid_start)); } if (!string.IsNullOrEmpty(valid_end)) { priceMaster.valid_end = Convert.ToInt32(CommonFunction.GetPHPTime(valid_end)); } _usersMgr = new UsersMgr(connectionString); System.Data.DataTable dt_User = _usersMgr.Query(Request.Form["user_id"] ?? ""); if (dt_User != null && dt_User.Rows.Count > 0) { priceMaster.user_id = Convert.ToUInt32(dt_User.Rows[0]["user_id"]); } Resource.CoreMessage = new CoreResource("Product"); _priceMasterMgr = new PriceMasterMgr(connectionString); _priceMasterTsMgr = new PriceMasterTsMgr(""); int priceMasterId = _priceMasterMgr.Save(priceMaster, itemPrices, null, ref msg); if (priceMasterId != -1) { //價格修改 申請審核 PriceUpdateApply priceUpdateApply = new PriceUpdateApply { price_master_id = Convert.ToUInt32(priceMasterId) }; priceUpdateApply.apply_user = Convert.ToUInt32((Session["caller"] as Caller).user_id); //價格審核記錄 PriceUpdateApplyHistory applyHistroy = new PriceUpdateApplyHistory(); applyHistroy.user_id = Convert.ToInt32(priceUpdateApply.apply_user); //applyHistroy.price_status = 1; //applyHistroy.type = 3; applyHistroy.price_status = 1; //edit by wwei0216w 2014/12/16 價格修改時 price_status為 2申請審核 applyHistroy.type = 1;//edit by wwei0216w 所作操作為 1:申請審核的操作 _priceUpdateApplyMgr = new PriceUpdateApplyMgr(connectionString); _priceUpdateApplyHistoryMgr = new PriceUpdateApplyHistoryMgr(connectionString); int apply_id = _priceUpdateApplyMgr.Save(priceUpdateApply); if (apply_id != -1) { priceMaster = _priceMasterMgr.Query(new PriceMaster { price_master_id = Convert.ToUInt32(priceMasterId) }).FirstOrDefault(); priceMaster.apply_id = Convert.ToUInt32(apply_id); applyHistroy.apply_id = apply_id; ArrayList excuteSql = new ArrayList(); excuteSql.Add(_priceMasterMgr.Update(priceMaster)); excuteSql.Add(_priceMasterTsMgr.UpdateTs(priceMaster));//edit by xiangwang0413w 2014/07/22 更新price_master_ts表後用時更新price_master_ts表,以便價格審核 excuteSql.Add(_priceUpdateApplyHistoryMgr.SaveSql(applyHistroy)); _functionMgr = new FunctionMgr(connectionString); string function = Request.Params["function"] ?? ""; Function fun = _functionMgr.QueryFunction(function, "/Product/ProductSave"); int functionid = fun == null ? 0 : fun.RowId; HistoryBatch batch = new HistoryBatch { functionid = functionid }; batch.batchno = Request.Params["batch"] ?? ""; batch.kuser = (Session["caller"] as Caller).user_email; _tableHistoryMgr = new TableHistoryMgr(connectionString); if (_tableHistoryMgr.SaveHistory<PriceMaster>(priceMaster, batch, excuteSql)) { json = "{success:true}"; } else { json = "{success:false,msg:'" + Resources.Product.SAVE_FAIL + "'}"; } } else { json = "{success:false,msg:'" + Resources.Product.SAVE_FAIL + "'}"; } } else { json = "{success:false,msg:'" + msg + "'}"; } #endregion } else { #region product_item_temp 修改临时表数据 ProductTemp proTemp = new ProductTemp { Bonus_Percent = bonus_percent, Default_Bonus_Percent = default_bonus_percent }; List<ProductItemTemp> proItemTemps = jsSer.Deserialize<List<ProductItemTemp>>(items); if (!string.IsNullOrEmpty(Request.Form["OldProductId"])) { proTemp.Product_Id = Request.Form["OldProductId"]; proItemTemps.ForEach(m => m.Product_Id = proTemp.Product_Id); } if (!string.IsNullOrEmpty(start)) { proTemp.Bonus_Percent_Start = Convert.ToUInt32(CommonFunction.GetPHPTime(start)); proItemTemps.ForEach(m => m.Event_Product_Start = proTemp.Bonus_Percent_Start); } if (!string.IsNullOrEmpty(end)) { proTemp.Bonus_Percent_End = Convert.ToUInt32(CommonFunction.GetPHPTime(end)); proItemTemps.ForEach(m => m.Event_Product_End = proTemp.Bonus_Percent_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 = (Session["caller"] as Caller).user_id; proTemp.Combo_Type = COMBO_TYPE; proItemTemps.ForEach(m => m.Writer_Id = proTemp.Writer_Id); _productTempMgr = new ProductTempMgr(connectionString); #region PriceMasterTemp PriceMasterTemp priceMasterTemp = new PriceMasterTemp { price_status = 1, default_bonus_percent = default_bonus_percent, bonus_percent = bonus_percent, same_price = same_price }; priceMasterTemp.accumulated_bonus = Convert.ToUInt32(accumulated_bonus); priceMasterTemp.product_id = proTemp.Product_Id; priceMasterTemp.combo_type = COMBO_TYPE; priceMasterTemp.product_name = PriceMaster.Product_Name_FM(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(bonus_start)) { priceMasterTemp.bonus_percent_start = Convert.ToUInt32(CommonFunction.GetPHPTime(bonus_start)); } if (!string.IsNullOrEmpty(bonus_start)) { priceMasterTemp.bonus_percent_end = Convert.ToUInt32(CommonFunction.GetPHPTime(bonus_end)); } 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.PriceBonusInfoSave(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.Query(query) == null)//插入 { result = _priceMasterTempMgr.Save(new List<PriceMasterTemp> { priceMasterTemp }, null, null); } else//更新 { result = _priceMasterTempMgr.Update(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.Product.SAVE_FAIL + "'}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public HttpResponseBase ProductPreview() { _siteConfigMgr = new SiteConfigMgr(Server.MapPath(xmlPath)); _pMaster = new PriceMasterMgr(connectionString); List<SiteConfig> configList = _siteConfigMgr.Query(); PriceMaster Pm = new PriceMaster(); BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt(); string DomainName = configList.Where(m => m.Name.Equals("DoMain_Name")).FirstOrDefault().Value; string json = string.Empty; try { if (!string.IsNullOrEmpty(Request.Form["Product_Id"]))//商品ID { string type = Request.Form["Type"]; string product_id = Request.Form["Product_Id"].ToString(); string site_id = Request.Form["Site_Id"] == null ? "" : Request.Form["Site_Id"].ToString(); string user_level = Request.Form["Level"] == null ? "" : Request.Form["Level"].ToString(); string user_id = Request.Form["Master_User_Id"] == null ? "" : Request.Form["Master_User_Id"].ToString(); string result = ""; if (type == "0") { result += "http://" + DomainName + "/product.php?pid=" + product_id + "&view=" + DateTime.Now.ToString("yyyyMMdd");//商品預覽 } if (type == "1") { //商品預覽+價格頁面 result += "http://" + DomainName + "/product.php?pid=" + product_id + "&view=" + DateTime.Now.ToString("yyyyMMdd") + "&sid=" + site_id + "&ulv=" + user_level + "&uid=" + user_id + "&view=" + DateTime.Now.ToString("yyyyMMdd"); result += "|"; result += "http://" + DomainName + "/product.php?pid=" + product_id + "&sid=" + site_id + "&code=" + hash.Md5Encrypt(product_id + "&sid=" + site_id, "32");//商品隱賣連結: + "&ulv=" + user_level } json = result.ToString().ToLower(); } } 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 = "無預覽信息"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
/// <summary> /// 調用儲存過程為price_master 裱中的name添加前後綴 /// </summary> /// <param name="days">過期天數(超多少天的前後綴自動刪除)</param> /// <returns>受影響的行數</returns> public int ResetExtendName(Caller callId, uint product_id = 0) { try { IPriceMasterImplMgr pmMgr = new PriceMasterMgr(connectionStr); MySqlDao _mySqlDao = new MySqlDao(connectionStr); ArrayList sqlList = new ArrayList(); string msg = string.Empty; List<ProdNameExtendCustom> list = new List<ProdNameExtendCustom>(); if (product_id != 0) { list = peDao.GetPastProductById(product_id); } else { list = peDao.GetPastProduct(); } foreach (var pM in list) { //pM.Product_Name = pM.Product_Name.Replace(PriceMaster.L_HKH + pM.Product_Prefix + PriceMaster.R_HKH, "")//替換掉priceMaster中product_name的前綴 //.Replace(PriceMaster.L_HKH + pM.Product_Suffix + PriceMaster.R_HKH, "");//替換掉priceMaster中product_name的後綴 bool tempFlag = true; int index = 0;///定義index防止錯誤導致下面的while無限循環 while(tempFlag)///循環刪除前後綴 { index ++; pM.Product_Name = ClearPreSuName(pM.Product_Name, PriceMaster.L_HKH.ToString(), PriceMaster.R_HKH.ToString()); if (pM.Product_Name.IndexOf(PriceMaster.L_HKH.ToString()) == -1 && pM.Product_Name.IndexOf(PriceMaster.R_HKH.ToString()) == -1||index>10) { tempFlag = false; } } PriceMaster p = new PriceMaster(); p.price_master_id = pM.Price_Master_Id; p.product_name = pM.Product_Name; sqlList.Add(pmMgr.UpdateName(p)); //將去掉前後綴的名稱update到price_master表 pM.Flag = 3;//過期 pM.Event_End = pM.Event_End; pM.Event_Start = pM.Event_Start; } if (_mySqlDao.ExcuteSqls(sqlList)) { peDao.Update(list.Select(p => (ProdNameExtend)p).ToList()); } if (msg == "") { int days = 30;//過期多少天刪除 return peDao.DeleteExtendName(days); } else { return -1; } } catch (Exception ex) { throw new Exception("ProdNameExtendMgr-->ResetExtendName-->" + ex.Message, ex); } }
public HttpResponseBase OrderSave() { int orderType = Request.UrlReferrer.AbsolutePath == "/Order/InteriorOrderAdd" ? 2 : 1;//訂單類型,:1為普通訂單輸入,2為內部訂單輸入 string jsonStr = "{success:false,msg:'" + Resources.OrderAdd.ORDER_ADD_FAIL + "'}"; try { Caller _caller = (Session["caller"] as Caller); uint normalFright = 0, lowFright = 0, receipt_to = 0, productTotalPrice = 0, combChannelId = 0, combPayMent = 0, combStoreMode = 0, combOrderStatus = 0, storeType = 0, retrieve_mode = 0; string combOrderDate = "", combLatestDeliverDate = "", txtAdminNote = "", txtCartNote = "", txtTradeNumber = "", txtOrderId = "", txtDeliverNumber = ""; uint.TryParse(Request.Params["retrieve_mode"] ?? "0", out retrieve_mode); uint.TryParse(Request.Params["receipt_to"] ?? "0", out receipt_to); uint.TryParse(Request.Params["normalFright"] ?? "0", out normalFright); uint.TryParse(Request.Params["lowFright"] ?? "0", out lowFright); uint.TryParse(Request.Params["comboPrice"] ?? "0", out productTotalPrice); uint.TryParse(Request.Params["combChannelId"] ?? "0", out combChannelId); uint.TryParse(Request.Params["combPayMent"] ?? "0", out combPayMent);//付款方式 uint.TryParse(Request.Params["combStoreMode"] ?? "0", out combStoreMode); uint.TryParse(Request.Params["combOrderStatus"] ?? "0", out combOrderStatus);//訂單狀態 uint.TryParse(Request.Params["storeType"] ?? "0", out storeType); combOrderDate = Request.Params["combOrderDate"]; //txtOrderDateHour = Request.Params["txtOrderDateHour"]; //txtOrderDateMinute = Request.Params["txtOrderDateMinute"]; combLatestDeliverDate = Request.Params["combLatestDeliverDate"]; txtAdminNote = Request.Params["txtareAdminNote"]; txtCartNote = Request.Params["txtareCartNote"]; txtTradeNumber = Request.Params["txtTradeNumber"]; txtOrderId = Request.Params["txtOrderId"]; txtDeliverNumber = Request.Params["txtDeliverNumber"]; //combOrderDate += " " + txtOrderDateHour + ":" + txtOrderDateMinute; if (!string.IsNullOrEmpty(txtAdminNote)) { txtAdminNote = Resources.OrderAdd.NOTE + ":" + txtAdminNote; } #region 訂購人信息 string b_txtName = "", b_txtMobil = "", b_txtPhoneHead = "", b_txtPhoneContent = "", b_txtAddress = ""; uint b_combZip = 0; b_txtName = Request.Params["b_txtName"]; b_txtMobil = Request.Params["b_txtMobel"]; b_txtPhoneHead = Request.Params["b_txtPhoneHead"]; b_txtPhoneContent = Request.Params["b_txtPhoneContent"]; b_txtAddress = Request.Params["b_txtAddress"]; uint.TryParse(Request.Params["b_combZip"] ?? "0", out b_combZip); #endregion #region 收件人信息 string r_txtCNFullName = "", r_txtActionPhone = "", r_txtContactPhoneHead = "", r_txtContactPhoneContent = "", r_txtContactAddress = ""; uint r_combZip = 0; r_txtCNFullName = Request.Params["r_txtCNFullName"]; r_txtActionPhone = Request.Params["r_txtActionPhone"]; r_txtContactPhoneHead = Request.Params["r_txtContactPhoneHead"]; r_txtContactPhoneContent = Request.Params["r_txtContactPhoneContent"]; r_txtContactAddress = Request.Params["r_txtContactAddress"]; uint.TryParse(Request.Params["r_combZip"] ?? "0", out r_combZip); #endregion string dataStr = Request.Params["gridData"]; OrderAddCustom odc = new OrderAddCustom(); JavaScriptSerializer jss = new JavaScriptSerializer(); List<OrderAddCustom> errorOrder = new List<OrderAddCustom>(); List<CooperatorOrderCustom> coopErrorList = new List<CooperatorOrderCustom>(); //添加總和 抵用金 和 購物金 add by zhuoqin0830w uint productTotal = 0, deduct_bonusTotal = 0, deduct_welfareTotal = 0, acc_bonusTotal = 0; OrderImportMgr orderImportMgr = new OrderImportMgr(connectionString, 0); Resource.CoreMessage = new CoreResource("OrderImport"); List<OrderSlave> slaves = new List<OrderSlave>(); List<ChannelOrder> channelList = new List<ChannelOrder>(); //add by zhuoqin0830w 2015/02/26 公關單與報廢單功能 獲取前臺傳來的單據類型 string billtype = orderType == 1 ? "" : Request.Form["BillType"]; string dep = orderType == 1 ? "" : Request.Form["dep"]; //獲取前臺傳來 的 Cart_Delivery 和 Site_Id add by zhuoqin0830w 2015/07/03 uint Cart_Delivery = uint.Parse(Request.Params["Cart_Delivery"]); uint Site_Id = orderType == 1 ? 0 : uint.Parse(Request.Form["Site_Id"]); switch (storeType) { case 1: #region 合作外站新增訂單 List<CooperatorOrderCustom> odcList1 = jss.Deserialize<List<CooperatorOrderCustom>>(dataStr); IPriceMasterImplMgr _priceMgr = new PriceMasterMgr(connectionString); var parentList1 = from rec in odcList1 where rec.parent_id == "0" && rec.Item_Id == 0 select rec;//rec.price_type!=2:各自定價的價格是從表中讀取的,所以到後臺不需要重新計算價格 var singleList1 = from rec in odcList1 where rec.Item_Id != 0 && rec.parent_id == "0" select rec; foreach (var item in parentList1) { var totalPrice = item.Event_Item_Money == 0 ? item.product_cost : item.Event_Item_Money;//add by zhuoqin0830w 2015/12/02 判斷是否使用活動價 productTotal += uint.Parse((totalPrice * item.buynum).ToString()); productItemMapMgr = new ProductItemMapMgr(connectionString); ProductItemMap pMap = productItemMapMgr.QueryAll(new ProductItemMap { channel_id = uint.Parse(combChannelId.ToString()), channel_detail_id = item.coop_product_id }).FirstOrDefault(); PriceMaster pMaster = _priceMgr.QueryPriceMaster(new PriceMaster { product_id = uint.Parse(pMap.product_id.ToString()), //user_id = 0, //user_level = 1, //site_id = 1, price_master_id = pMap.price_master_id, child_id = int.Parse(pMap.product_id.ToString()) }); odcList1.Find(rec => rec.Product_Id == item.Product_Id && rec.group_id == item.group_id).price_master_id = pMaster.price_master_id; ////查找該父商品下的子商品 var childList = from rec in odcList1 where rec.parent_id == item.coop_product_id select rec; foreach (var child in childList) { IItemPriceImplMgr iPMgr = new ItemPriceMgr(connectionString); PriceMaster query = new PriceMaster { user_id = pMaster.user_id, user_level = pMaster.user_level, site_id = pMaster.site_id }; if (item.price_type == 1) { query.product_id = uint.Parse(child.coop_product_id); query.child_id = 0; } else if (item.price_type == 2) { query.product_id = uint.Parse(pMap.product_id.ToString()); query.child_id = int.Parse(child.coop_product_id); } PriceMaster pM = _priceMgr.QueryPriceMaster(query); List<ItemPriceCustom> ipList = new List<ItemPriceCustom>(); if (pM != null) { odcList1.Find(rec => rec.coop_product_id == child.coop_product_id && rec.group_id == child.group_id).price_master_id = pM.price_master_id; ipList = iPMgr.Query(new ItemPrice { item_id = child.Item_Id, price_master_id = pM.price_master_id }); if ((item.price_type == 1 && pM.same_price == 1) || (item.price_type == 2 && pMaster.same_price == 1)) { odcList1.Find(rec => rec.coop_product_id == child.coop_product_id && rec.group_id == child.group_id).Item_Money = uint.Parse(pM.price.ToString()); //odcList1.Find(rec => rec.coop_product_id == child.coop_product_id && rec.group_id == child.group_id).Item_Cost = uint.Parse(pM.cost.ToString()); odcList1.Find(rec => rec.coop_product_id == child.coop_product_id && rec.group_id == child.group_id).Event_Item_Cost = uint.Parse(pM.event_cost.ToString()); } else { odcList1.Find(rec => rec.coop_product_id == child.coop_product_id && rec.group_id == child.group_id).Item_Money = ipList[0].item_money; //odcList1.Find(rec => rec.coop_product_id == child.coop_product_id && rec.group_id == child.group_id).Item_Cost = ipList[0].item_cost; odcList1.Find(rec => rec.coop_product_id == child.coop_product_id && rec.group_id == child.group_id).Event_Item_Cost = ipList[0].event_cost; } } } } //單一商品 #region Channel_Order 資料 ChannelOrder chOrd; foreach (CooperatorOrderCustom coop in odcList1) { ChannelOrder existChl = channelList.Where(m => m.Channel_Detail_Id == coop.coop_product_id).FirstOrDefault(); if (existChl != null) { continue; } chOrd = new ChannelOrder(); chOrd.Channel_Detail_Id = coop.coop_product_id; chOrd.Channel_Id = int.Parse(combChannelId.ToString()); chOrd.Createtime = DateTime.Now; if (!string.IsNullOrEmpty(combOrderDate)) { chOrd.Ordertime = Convert.ToDateTime(combOrderDate); } chOrd.Order_Id = txtTradeNumber; if (!string.IsNullOrEmpty(combLatestDeliverDate)) { chOrd.Latest_Deliver_Date = Convert.ToDateTime(combLatestDeliverDate); } chOrd.Dispatch_Seq = txtDeliverNumber; channelList.Add(chOrd); } #endregion slaves = orderImportMgr.FillSlaveCooperator(odcList1, coopErrorList, combChannelId, combOrderStatus, txtOrderId); foreach (var item in singleList1) { var totalPrice = item.Event_Item_Money == 0 ? item.product_cost : item.Event_Item_Money;//add by zhuoqin0830w 2015/12/02 判斷是否使用活動價 productTotal += uint.Parse((totalPrice * item.buynum).ToString()); } #endregion break; case 2: //Gigade新增訂單 List<OrderAddCustom> odcList2 = jss.Deserialize<List<OrderAddCustom>>(dataStr); //將前臺傳來的 Site_Id 的值傳入到後臺 并插入數據庫 add by zhuoqin0830w 2015/07/03 odcList2.ForEach(m => { m.Site_Id = Site_Id; }); if (orderType == 1) { #region 重新計算組合商品價格 IPriceMasterImplMgr priceMgr = new PriceMasterMgr(connectionString); var parentList = from rec in odcList2 where rec.parent_id == 0 && rec.Item_Id == 0 && rec.price_type != 2 select rec; //rec.price_type!=2:各自定價的價格是從表中讀取的,所以到後臺不需要重新計算價格 var singleList = from rec in odcList2 where rec.Item_Id != 0 && rec.parent_id == 0 select rec; var priceSelfList = from rec in odcList2 where rec.Item_Id == 0 && rec.parent_id == 0 && rec.price_type == 2 select rec; //單一商品計算價格 foreach (var item in singleList) { //使 總價 減去 抵用金 和 購物金 edit by zhuoqin0830w 2015/05/14 var totalPrice = item.Event_Item_Money == 0 ? item.product_cost : item.Event_Item_Money;//add by zhuoqin0830w 2015/12/02 判斷是否使用活動價 productTotal += uint.Parse((totalPrice * item.buynum - item.deduct_bonus - item.deduct_welfare).ToString()); // 計算 購物金 和 抵用金 的 總和 add by zhuoqin0830w 2015/05/14 deduct_bonusTotal += uint.Parse(item.deduct_bonus.ToString()); deduct_welfareTotal += uint.Parse(item.deduct_welfare.ToString()); PriceMaster pM = priceMgr.QueryPriceMaster(new PriceMaster { product_id = uint.Parse(item.Product_Id.ToString()), user_id = 0, user_level = 1, site_id = Site_Id, child_id = 0 }); if (pM != null) { odcList2.Find(rec => rec.Product_Id == item.Product_Id).price_master_id = pM.price_master_id; } } //組合商品各自定價計算價格 foreach (var item in priceSelfList) { //使 總價 減去 抵用金 和 購物金 edit by zhuoqin0830w 2015/05/14 var totalPrice = item.Event_Item_Money == 0 ? item.product_cost : item.Event_Item_Money;//add by zhuoqin0830w 2015/12/02 判斷是否使用活動價 productTotal += uint.Parse((totalPrice * item.buynum - item.deduct_bonus - item.deduct_welfare).ToString()); // 計算 購物金 和 抵用金 的 總和 add by zhuoqin0830w 2015/05/14 deduct_bonusTotal += uint.Parse(item.deduct_bonus.ToString()); deduct_welfareTotal += uint.Parse(item.deduct_welfare.ToString()); PriceMaster pM = priceMgr.QueryPriceMaster(new PriceMaster { product_id = item.Product_Id, user_id = 0, user_level = 1, site_id = 1, child_id = Convert.ToInt32(item.Product_Id) }); if (pM != null) { odcList2.Find(rec => rec.Product_Id == item.Product_Id && rec.group_id == item.group_id).price_master_id = pM.price_master_id; } //找出當前父商品的子商品 var childList = from rec in odcList2 where rec.parent_id == item.Product_Id && rec.group_id == item.group_id select rec; foreach (var child in childList) { pM = priceMgr.QueryPriceMaster(new PriceMaster { product_id = item.Product_Id, user_id = 0, user_level = 1, site_id = 1, child_id = Convert.ToInt32(child.Product_Id) }); if (pM != null) { IItemPriceImplMgr iPMgr = new ItemPriceMgr(connectionString); ItemPrice price = iPMgr.Query(new ItemPrice { item_id = child.Item_Id, price_master_id = pM.price_master_id }).FirstOrDefault(); if (price != null) { odcList2.Find(rec => rec.Product_Id == child.Product_Id && rec.group_id == item.group_id).Item_Cost = price.item_cost; //成本 odcList2.Find(rec => rec.Product_Id == child.Product_Id && rec.group_id == item.group_id).Event_Item_Cost = price.event_cost;//活動成本 odcList2.Find(rec => rec.Product_Id == child.Product_Id && rec.group_id == item.group_id).Item_Money = price.item_money;//售價 } } } } //組合商品按比例拆分計算價格 foreach (var item in parentList) { var TotalPrice = 0.0; var TotalCost = 0.0; //使 總價 減去 抵用金 和 購物金 edit by zhuoqin0830w 2015/05/14 var totalPrice = item.Event_Item_Money == 0 ? item.product_cost : item.Event_Item_Money;//add by zhuoqin0830w 2015/12/02 判斷是否使用活動價 productTotal += uint.Parse((totalPrice * item.buynum - item.deduct_bonus - item.deduct_welfare).ToString()); // 計算 購物金 和 抵用金 的 總和 add by zhuoqin0830w 2015/05/14 deduct_bonusTotal += uint.Parse(item.deduct_bonus.ToString()); deduct_welfareTotal += uint.Parse(item.deduct_welfare.ToString()); PriceMaster pMaster = priceMgr.QueryPriceMaster(new PriceMaster { product_id = uint.Parse(item.Product_Id.ToString()), user_id = 0, user_level = 1, site_id = Site_Id, child_id = int.Parse(item.Product_Id.ToString()) }); odcList2.Find(rec => rec.Product_Id == item.Product_Id && rec.group_id == item.group_id).price_master_id = pMaster.price_master_id; //找出當前父商品的子商品 var childList = from rec in odcList2 where rec.parent_id == item.Product_Id && rec.group_id == item.group_id select rec; var parentPrice = item.product_cost; var parentCost = pMaster != null ? pMaster.cost : 0; //子商品總價 foreach (var child in childList) { //價格 IItemPriceImplMgr iPMgr = new ItemPriceMgr(connectionString); PriceMaster pM = priceMgr.QueryPriceMaster(new PriceMaster { product_id = uint.Parse(child.Product_Id.ToString()), user_id = 0, user_level = 1, site_id = Site_Id, child_id = 0 }); List<ItemPriceCustom> ipList = new List<ItemPriceCustom>(); if (pM != null) { //必購數量 _prodCombMgr = new ProductComboMgr(connectionString); List<ProductComboCustom> prodComList = _prodCombMgr.combQuery(new ProductComboCustom { Parent_Id = int.Parse(item.Product_Id.ToString()), Child_Id = child.Product_Id.ToString() //add by wangwei02016w 2014/9/24 }); var s_must_buy = prodComList[0].S_Must_Buy == 0 ? child.s_must_buy : prodComList[0].S_Must_Buy; if (pM.same_price == 1)//同價 { TotalPrice += pM.price * s_must_buy; TotalCost += pM.cost * s_must_buy; } else { ipList = iPMgr.Query(new ItemPrice { item_id = child.Item_Id, price_master_id = pM.price_master_id }); if (ipList.Count != 0) { TotalPrice += ipList[0].item_money * s_must_buy; TotalCost += ipList[0].item_cost * s_must_buy; } } } } //子商品按比例拆分后的價格 foreach (var child in childList) { _prodCombMgr = new ProductComboMgr(connectionString); List<ProductComboCustom> prodComList = _prodCombMgr.combQuery(new ProductComboCustom { Parent_Id = int.Parse(item.Product_Id.ToString()), Child_Id = child.Product_Id.ToString() //add by wangwei02016w 2014/9/24 }); var s_must_buy = prodComList[0].S_Must_Buy == 0 ? child.s_must_buy : prodComList[0].S_Must_Buy; IItemPriceImplMgr iPMgr = new ItemPriceMgr(connectionString); PriceMaster pM = priceMgr.QueryPriceMaster(new PriceMaster { product_id = uint.Parse(child.Product_Id.ToString()), user_id = 0, user_level = 1, site_id = Site_Id, child_id = 0 }); List<ItemPriceCustom> ipList = new List<ItemPriceCustom>(); if (pM != null) { odcList2.Find(rec => rec.Product_Id == child.Product_Id && rec.group_id == item.group_id).price_master_id = pM.price_master_id; if (pM.same_price == 1) { odcList2.Find(rec => rec.Product_Id == child.Product_Id && rec.group_id == item.group_id).Item_Cost = uint.Parse(pM.cost.ToString()); //成本 odcList2.Find(rec => rec.Product_Id == child.Product_Id && rec.group_id == item.group_id).Event_Item_Cost = uint.Parse(pM.event_cost.ToString());//活動成本 var afterPrice = 0; var afterCost = 0; if (TotalPrice <= 0) { afterPrice = 0; } else { afterPrice = Convert.ToInt16(Math.Round(parentPrice * (Convert.ToDouble(pM.price * s_must_buy) / TotalPrice / s_must_buy))); } if (TotalCost <= 0) { afterCost = 0; } else { afterCost = Convert.ToInt16(Math.Round(parentCost * (Convert.ToDouble(pM.cost * s_must_buy) / TotalCost / s_must_buy))); } //var singleTotal = afterPrice * s_must_buy; var singleTotal = afterPrice; parentPrice -= uint.Parse(singleTotal.ToString()); TotalPrice -= Convert.ToDouble(pM.price) * s_must_buy; odcList2.Find(rec => rec.Product_Id == child.Product_Id && rec.group_id == item.group_id).product_cost = uint.Parse(afterPrice.ToString()); //var singleCostTotal = afterCost * s_must_buy; var singleCostTotal = afterCost; parentCost -= singleCostTotal; TotalCost -= Convert.ToDouble(pM.cost) * s_must_buy; odcList2.Find(rec => rec.Product_Id == child.Product_Id && rec.group_id == item.group_id).Item_Cost = uint.Parse(afterCost.ToString()); } else { ipList = iPMgr.Query(new ItemPrice { item_id = child.Item_Id, price_master_id = pM.price_master_id }); if (ipList.Count != 0) { odcList2.Find(rec => rec.Product_Id == child.Product_Id && rec.group_id == item.group_id).Item_Cost = ipList[0].item_cost; //成本 odcList2.Find(rec => rec.Product_Id == child.Product_Id && rec.group_id == item.group_id).Event_Item_Cost = ipList[0].event_cost;//活動成本 //var afterPrice = CommonFunction.Math4Cut5Plus(parentPrice * ipList[0].item_money * s_must_buy / TotalPrice / s_must_buy); //beforePrice += afterPrice * s_must_buy; //new logic var afterPrice = 0; var afterCost = 0; if (TotalPrice <= 0) { afterPrice = 0; } else { afterPrice = Convert.ToInt16(Math.Round(parentPrice * (Convert.ToDouble(ipList[0].item_money * s_must_buy) / TotalPrice / s_must_buy))); } if (TotalCost <= 0) { afterCost = 0; } else { afterCost = Convert.ToInt16(Math.Round(parentCost * (Convert.ToDouble(ipList[0].item_cost * s_must_buy) / TotalCost / s_must_buy))); } //var singleTotal = afterPrice * s_must_buy; var singleTotal = afterPrice; parentPrice -= uint.Parse(singleTotal.ToString()); TotalPrice -= Convert.ToDouble(ipList[0].item_money) * s_must_buy; // beforePrice += singleTotal; //var singleCostTotal = afterCost * s_must_buy; var singleCostTotal = afterCost; parentCost -= singleCostTotal; TotalCost -= Convert.ToDouble(ipList[0].item_cost) * s_must_buy; odcList2.Find(rec => rec.Product_Id == child.Product_Id && rec.group_id == item.group_id).product_cost = uint.Parse(afterPrice.ToString()); odcList2.Find(rec => rec.Product_Id == child.Product_Id && rec.group_id == item.group_id).Item_Cost = uint.Parse(afterCost.ToString()); odcList2.Find(rec => rec.Product_Id == child.Product_Id && rec.group_id == item.group_id).s_must_buy = s_must_buy; } } } } } #endregion } else { foreach (var item in odcList2.FindAll(m => (m.parent_id == 0 && m.Item_Id == 0) || (m.Item_Id != 0 && m.parent_id == 0))) { //使 總價 減去 抵用金 和 購物金 edit by zhuoqin0830w 2015/05/14 var totalPrice = item.Event_Item_Money == 0 ? item.product_cost : item.Event_Item_Money;//add by zhuoqin0830w 2015/12/02 判斷是否使用活動價 productTotal += uint.Parse((totalPrice * item.buynum - item.deduct_bonus - item.deduct_welfare).ToString()); // 計算 購物金 和 抵用金 的 總和 add by zhuoqin0830w 2015/05/14 deduct_bonusTotal += uint.Parse(item.deduct_bonus.ToString()); deduct_welfareTotal += uint.Parse(item.deduct_welfare.ToString()); acc_bonusTotal += uint.Parse(item.accumulated_bonus.ToString()); } } slaves = orderImportMgr.FillSlave(odcList2, errorOrder, combOrderStatus, txtOrderId); break; default: break; } if (slaves != null && errorOrder.Count() == 0 && coopErrorList.Count() == 0) { channelMgr = new ChannelMgr(connectionString); #region OrderMaster 信息 #region receipt_to 發票開立方式 switch (receipt_to) { case 1: receipt_to = 2; break; case 2: receipt_to = 0; break; case 3: receipt_to = 2; break; } #endregion #region retrieve_mode 取貨方式 channelShipMgr = new ChannelShippingMgr(connectionString); ChannelShipping chip = new ChannelShipping(); chip.channel_id = int.Parse(combChannelId.ToString()); chip.shipping_carrior = int.Parse(combStoreMode.ToString()); retrieve_mode = uint.Parse(channelShipMgr.Query(chip)[0].retrieve_mode.ToString()); #endregion OrderMaster ordermaster = new OrderMaster(); //ordermaster.Order_Id = Convert.ToUInt32(orderImportMgr.NextOrderId()); ordermaster.Channel_Order_Id = txtTradeNumber; ordermaster.Invoice_Status = receipt_to; ordermaster.Order_Freight_Normal = normalFright; ordermaster.Order_Freight_Low = lowFright; ordermaster.Delivery_Store = combStoreMode; ordermaster.Channel = combChannelId; ordermaster.Order_Status = combOrderStatus; //orderType=2為内部订单输入 edit by xiangwang0413w 2014/10/29 ordermaster.User_Id = (orderType == 1) ? (uint)channelMgr.GetUserIdByChannelId((int)combChannelId) : uint.Parse(Request.Params["userId"]);//订单人的user_id ordermaster.Order_Product_Subtotal = productTotal; ordermaster.Order_Amount = productTotal + normalFright + lowFright; ordermaster.Order_Payment = combPayMent; //向 order_master 裱中 添加 從前臺獲取的 Cart_Delivery edit by zhuoqin0830w 2015/07/03 ordermaster.Cart_Id = Cart_Delivery; ordermaster.Note_Admin = string.Format(Resources.OrderAdd.NOTE_CONTENT, _caller.user_username, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), txtAdminNote); ordermaster.Note_Order = txtCartNote; ordermaster.Order_Date_Pay = Convert.ToUInt32(BLL.gigade.Common.CommonFunction.GetPHPTime()); ordermaster.Order_Createdate = Convert.ToUInt32(BLL.gigade.Common.CommonFunction.GetPHPTime(combOrderDate)); ordermaster.Import_Time = DateTime.Now; ordermaster.Retrieve_Mode = retrieve_mode; //向 order_master 裱中 添加 抵用金 和 購物金 add by zhuoqin0830w 2015/05/14 ordermaster.Deduct_Welfare = deduct_welfareTotal; ordermaster.Deduct_Bonus = deduct_bonusTotal; //向 order_master 表中 添加 返還購物金 add by zhuoqin0830w 2015/09/01 ordermaster.Accumulated_Bonus = (int)acc_bonusTotal; #endregion #region 出貨時間 if (orderType == 2)//內部訂單輸入 { ordermaster.Holiday_Deliver = Convert.ToInt32(Request.Form["HolidayDeliver"]); ordermaster.Estimated_Arrival_Period = Convert.ToInt32(Request.Form["EstimatedArrivalPeriod"]); } #endregion #region 訂購人信息 ordermaster.Order_Name = b_txtName; ordermaster.Order_Mobile = b_txtMobil; b_txtPhoneHead = !string.IsNullOrEmpty(b_txtPhoneHead) ? b_txtPhoneHead + "-" : b_txtPhoneHead; ordermaster.Order_Phone = b_txtPhoneHead + b_txtPhoneContent; ordermaster.Order_Zip = b_combZip; ordermaster.Order_Address = b_txtAddress; ordermaster.Order_Gender = Request.Params["ServiceSex"] == "1" ? true : false; //add by wwei0216w 2015/1/21 訂購人性別 #endregion #region 收件人信息 ordermaster.Delivery_Name = r_txtCNFullName; ordermaster.Delivery_Mobile = r_txtActionPhone; ordermaster.Delivery_Phone = r_txtContactPhoneHead + "-" + r_txtContactPhoneContent; ordermaster.Delivery_Zip = r_combZip; ordermaster.Delivery_Address = r_txtContactAddress; ordermaster.Delivery_Gender = Request.Params["AddresseeSex"] == "1" ? true : false; //add by wwei0216w 收件人性別 #endregion #region add by zhuoqin0830w 2015/02/26 公關單與報廢單功能 判斷單據類型是否為空值 如果不為空則執行添加功能 OrderMasterPattern op = null; if (!string.IsNullOrEmpty(billtype)) { op = new OrderMasterPattern { Pattern = int.Parse(billtype), Dep = int.Parse(dep) }; } #endregion #region add by zhuoqin0830w 2015/08/24 在內部訂單輸入時 同時將 輸入的 購物金 和 返還購物金 以及 抵用券 添加至 bonus_master 和 bonus_record 表中 BonusMaster bm = null; BonusRecord brBonus = null; BonusRecord brWelfare = null; //判斷返還購物金 是否 大於0 如果大於 0 表示需要在 bonus_master 新增一筆數據 if (acc_bonusTotal > 0) { bm = new BonusMaster { user_id = ordermaster.User_Id, type_id = 30,// 默認為 商品回饋購物金 master_writer = "商品回饋購物金", master_total = acc_bonusTotal, master_balance = (int)acc_bonusTotal, master_start = Convert.ToUInt32(BLL.gigade.Common.CommonFunction.GetPHPTime()), master_end = Convert.ToUInt32(BLL.gigade.Common.CommonFunction.GetPHPTime(DateTime.Now.AddDays(90).ToString())),//默認過期時間是當前時間+90天 master_createdate = Convert.ToUInt32(BLL.gigade.Common.CommonFunction.GetPHPTime()), master_updatedate = Convert.ToUInt32(BLL.gigade.Common.CommonFunction.GetPHPTime()), bonus_type = 1//默認為 購物金 }; } //判斷購物金是否大於 0 如果是 則表示 需要在 bonus_record 增加一筆數據 //並且需要 在 bonus_master 中 按照 過期日期 減去 相應的 參數 if (deduct_bonusTotal > 0) { brBonus = new BonusRecord { user_id = ordermaster.User_Id, record_use = deduct_bonusTotal, record_createdate = Convert.ToUInt32(BLL.gigade.Common.CommonFunction.GetPHPTime()), record_updatedate = Convert.ToUInt32(BLL.gigade.Common.CommonFunction.GetPHPTime()) }; //判斷購物金是否小於或等於數據庫中的購物金 _bonusMasterMgr = new BonusMasterMgr(connectionString); int userBonusTotal = _bonusMasterMgr.GetSumBouns(brBonus); if (deduct_bonusTotal > userBonusTotal) { jsonStr = "{success:false,msg:'" + Resources.OrderAdd.BONUS_PRICE_NULL + "'}"; this.Response.Clear(); this.Response.Write(jsonStr); this.Response.End(); return this.Response; } } //判斷 抵用卷 金額 是否 大於 0 if (deduct_welfareTotal > 0) { brWelfare = new BonusRecord { user_id = ordermaster.User_Id, record_use = deduct_welfareTotal, record_createdate = Convert.ToUInt32(BLL.gigade.Common.CommonFunction.GetPHPTime()), record_updatedate = Convert.ToUInt32(BLL.gigade.Common.CommonFunction.GetPHPTime()) }; //判斷購物金是否小於或等於數據庫中的購物金 _bonusMasterMgr = new BonusMasterMgr(connectionString); int userWelfateTotal = _bonusMasterMgr.GetSumWelfare(brWelfare); if (deduct_welfareTotal > userWelfateTotal) { jsonStr = "{success:false,msg:'" + Resources.OrderAdd.WELFARE_PRICE_NULL + "'}"; this.Response.Clear(); this.Response.Write(jsonStr); this.Response.End(); return this.Response; } } #endregion #region 保存至數據庫 bool result = orderImportMgr.Save2DB(ordermaster, slaves, channelList, null, op, bm, brBonus, brWelfare); #endregion if (result) { jsonStr = "{success:true,msg:'" + Resources.OrderAdd.ORDER_ADD_SUCCESS + "'}"; } } else { StringBuilder stb = new StringBuilder(); if (storeType == 1) { foreach (CooperatorOrderCustom item in coopErrorList) { stb.Append(item.coop_product_id + "\\n"); } stb.Append("\\n" + Resources.OrderAdd.EMPTY_NULL_FAIL); } else if (storeType == 2) { foreach (OrderAddCustom item in errorOrder) { stb.Append(item.Product_Id + item.Spec_Name_1 + item.Spec_Name_2 + "\\n"); } stb.Append("\\n" + Resources.OrderAdd.EMPTY_NULL_FAIL); } jsonStr = "{success:false,msg:'" + stb.ToString() + "'}"; } } 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); } this.Response.Clear(); this.Response.Write(jsonStr); this.Response.End(); return this.Response; }
/// <summary> /// 查询User_Id 为零的价格信息 /// </summary> /// <param name="query"></param> /// <returns></returns> public List<PriceMaster> QueryByUserId(PriceMaster query) { query.Replace4MySQL(); try { StringBuilder stb = new StringBuilder("select price_master_id,product_id,site_id,user_level,user_id,"); stb.Append("product_name,bonus_percent,default_bonus_percent,same_price,event_start,event_end,"); stb.Append("price_status,price,event_price,cost,event_cost,child_id,apply_id"); stb.Append(" from price_master where 1=1"); if (query.user_id != 0) { stb.AppendFormat(" and user_id = {0}", query.user_id); } else { stb.Append(" and user_id = 0"); } if (query.product_id != 0) { stb.AppendFormat(" and product_id = {0}", query.product_id); } if (query.site_id != 0) { stb.AppendFormat(" and site_id = {0}", query.site_id); } return _dbAccess.getDataTableForObj<PriceMaster>(stb.ToString()); } catch (Exception ex) { throw new Exception("PriceMasterDao.QueryByUserId(PriceMaster query)-->" + ex.Message, ex); } }
/// <summary> /// 根據條件只修改product_name /// edit by wwei0216w 2014/12/18 /// </summary> /// <returns></returns> public string UpdateName(PriceMaster pm) { try { StringBuilder sb = new StringBuilder(); sb.AppendFormat("UPDATE price_master SET product_name = '{0}' WHERE price_master_id = {1};", pm.product_name, pm.price_master_id); return sb.ToString(); } catch (Exception ex) { throw new Exception("PriceMasterDao.UpdateName-->" + ex.Message, ex); } }
public string ComboPriceSave() { string json = "{success:true}"; if (!PriceMaster.CheckProdName(Request.Form["product_name"])) { return "{success:false,msg:'" + Resources.Product.FORBIDDEN_CHARACTER + "'}"; } ProductTemp pTemp = new ProductTemp(); List<PriceMasterTemp> pMasterListT = new List<PriceMasterTemp>(); List<PriceMaster> pMasterList = new List<PriceMaster>(); List<List<ItemPrice>> ItemPList = new List<List<ItemPrice>>(); PriceMasterTemp pMasterTemp = new PriceMasterTemp(); if (!string.IsNullOrEmpty(Request.Form["OldProductId"])) { pTemp.Product_Id = Request.Form["OldProductId"]; pMasterTemp.product_id = Request.Form["OldProductId"]; } string paramValue = Request.Params["paramValue"]; #region 參數 int writer_id = (Session["caller"] as Caller).user_id; string product_name = PriceMaster.Product_Name_FM(Request.Params["product_name"]); string price_type = Request.Params["price_type"]; string product_price_list = Request.Params["product_price_list"]; string default_bonus_percent = Request.Params["default_bonus_percent"]; string price = Request.Params["price"]; string cost = Request.Params["cost"]; string max_price = Request.Params["max_price"]; string bonus_percent = Request.Params["bonus_percent"]; 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 site_id = Request.Params["site_id"]; string user_level = Request.Params["user_level"]; string user_mail = Request.Params["user_mail"]; string bag_check_money = Request.Params["bag_check_money"] == "" ? "0" : Request.Params["bag_check_money"]; string accumulated_bonus = Request.Params["accumulated_bonus"]; string bonus_percent_start = Request.Params["bonus_percent_start"]; string bonus_percent_end = Request.Params["bonus_percent_end"]; 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 List<MakePriceCustom> PriceStore = new List<MakePriceCustom>(); if (price_type == "2")//各自定價 { JavaScriptSerializer jss = new JavaScriptSerializer(); string priceStr = Request.Params["priceStr"]; PriceStore = jss.Deserialize<List<MakePriceCustom>>(priceStr); } if (!string.IsNullOrEmpty(Request.Params["product_id"])) { #region 正式表操作 List<PriceMaster> pMList = new List<PriceMaster>(); //插入price_master _priceMasterMgr = new PriceMasterMgr(connectionString); _priceMasterTsMgr = new PriceMasterTsMgr(connectionString); PriceMaster pMaster = new PriceMaster(); //查詢price_master if (!string.IsNullOrEmpty(Request.Params["price_master_id"])) { pMaster = _priceMasterMgr.Query(new PriceMaster { price_master_id = uint.Parse(Request.Params["price_master_id"]) }).FirstOrDefault(); } pMaster.product_id = uint.Parse(Request.Params["product_id"]); pMaster.child_id = int.Parse(Request.Params["product_id"]); pMaster.site_id = uint.Parse(site_id); uint userId = 0; if (!string.IsNullOrEmpty(Request.Form["user_mail"])) { _usersMgr = new UsersMgr(connectionString); System.Data.DataTable dt_User = _usersMgr.Query(Request.Form["user_mail"]); if (dt_User != null && dt_User.Rows.Count > 0) { userId = Convert.ToUInt32(dt_User.Rows[0]["user_id"]); } } if (userId != 0) { pMaster.user_id = userId; } if (user_level != "") { pMaster.user_level = uint.Parse(user_level); } pMaster.product_name = product_name; pMaster.bonus_percent = float.Parse(bonus_percent); pMaster.cost = int.Parse(cost); pMaster.price = int.Parse(price); pMaster.max_price = int.Parse(max_price); pMaster.max_event_price = int.Parse(max_event_price); pMaster.default_bonus_percent = float.Parse(default_bonus_percent); pMaster.event_price = int.Parse(event_price); pMaster.event_cost = int.Parse(event_cost); pMaster.same_price = int.Parse(same_price); pMaster.price_status = 2;//申請審核 pMaster.accumulated_bonus = uint.Parse(accumulated_bonus); #region 時間 活動時間 if (event_start != "") { pMaster.event_start = Convert.ToUInt32(CommonFunction.GetPHPTime(event_start)); } if (event_end != "") { pMaster.event_end = Convert.ToUInt32(CommonFunction.GetPHPTime(event_end)); } if (bonus_percent_start != "") { pMaster.bonus_percent_start = Convert.ToUInt32(CommonFunction.GetPHPTime(bonus_percent_start)); } if (bonus_percent_end != "") { pMaster.bonus_percent_end = Convert.ToUInt32(CommonFunction.GetPHPTime(bonus_percent_end)); } if (!string.IsNullOrEmpty(valid_start)) { pMaster.valid_start = Convert.ToInt32(CommonFunction.GetPHPTime(valid_start)); } if (!string.IsNullOrEmpty(valid_end)) { pMaster.valid_end = Convert.ToInt32(CommonFunction.GetPHPTime(valid_end)); } #endregion _functionMgr = new FunctionMgr(connectionString); string function = Request.Params["function"] ?? ""; Function fun = _functionMgr.QueryFunction(function, "/ProductCombo"); int functionid = fun == null ? 0 : fun.RowId; HistoryBatch batch = new HistoryBatch { functionid = functionid }; batch.batchno = Request.Params["batch"] ?? ""; batch.kuser = (Session["caller"] as Caller).user_email; List<ItemPrice> update = new List<ItemPrice>(); if (price_type == "2") //各自定價 { CreateList(PriceStore, pMaster, null, same_price, ItemPList, pMasterListT, pMasterList, update); } pMasterList.Add(pMaster); try { //價格修改 申請審核 PriceUpdateApply priceUpdateApply = new PriceUpdateApply(); priceUpdateApply.apply_user = Convert.ToUInt32((Session["caller"] as Caller).user_id); //價格審核記錄 PriceUpdateApplyHistory applyHistroy = new PriceUpdateApplyHistory(); applyHistroy.user_id = Convert.ToInt32(priceUpdateApply.apply_user); applyHistroy.price_status = 1; //applyHistroy.type = 3; applyHistroy.type = 1;//edit by wwei0216w 所作操作為 1:申請審核的操作 _priceUpdateApplyMgr = new PriceUpdateApplyMgr(connectionString); _priceUpdateApplyHistoryMgr = new PriceUpdateApplyHistoryMgr(connectionString); _tableHistoryMgr = new TableHistoryMgr(connectionString); ArrayList excuteSql = new ArrayList(); if (!string.IsNullOrEmpty(Request.Params["price_master_id"])) { #region 修改 priceUpdateApply.price_master_id = pMaster.price_master_id; PriceMaster priceMster = _priceMasterMgr.QueryPMaster(new PriceMaster() { site_id = uint.Parse(site_id), user_level = uint.Parse(user_level == "" ? "0" : user_level), user_id = userId, product_id = uint.Parse(Request.Params["product_id"]), price_master_id = uint.Parse(Request.Params["price_master_id"]) }); //更新price_master if (priceMster != null) { json = "{success:true,msg:'" + Resources.Product.SITE_EXIST + "'}"; } else { int apply_id = _priceUpdateApplyMgr.Save(priceUpdateApply); if (apply_id != -1) { bool flag = false; foreach (var item in pMasterList) { item.apply_id = (uint)apply_id; excuteSql = new ArrayList(); if (item == pMaster) { pMaster.apply_id = Convert.ToUInt32(apply_id); applyHistroy.apply_id = apply_id; excuteSql.Add(_priceUpdateApplyHistoryMgr.SaveSql(applyHistroy)); } //excuteSql.Add(_priceMasterMgr.Update(item)); excuteSql.Add(_priceMasterTsMgr.UpdateTs(item));//edit by xiangwang0413w 2014/07/16 將數據更新到pirce_master_ts表 flag = _tableHistoryMgr.SaveHistory<PriceMaster>(item, batch, excuteSql); } if (flag) { //更新item_price //_itemPriceMgr = new ItemPriceMgr(""); _itemPriceTsMgr = new ItemPriceTsMgr(connectionString); foreach (var iPrice in update) { iPrice.apply_id = (uint)apply_id; excuteSql = new ArrayList(); //excuteSql.Add(_itemPriceMgr.Update(iPrice)); excuteSql.Add(_itemPriceTsMgr.UpdateTs(iPrice));//edit by xiangwang0413w 2014/07/17 將數據更新到pirce_master_ts表 if (!_tableHistoryMgr.SaveHistory<ItemPrice>(iPrice, batch, excuteSql)) { json = "{success:true,msg:'" + Resources.Product.EDIT_FAIL + "'}"; } } json = "{success:true,msg:'" + Resources.Product.EDIT_SUCCESS + "'}"; } else { json = "{success:true,msg:'" + Resources.Product.EDIT_FAIL + "'}"; } } else { json = "{success:true,msg:'" + Resources.Product.EDIT_FAIL + "'}"; } } #endregion } else { #region 新增 string msg = string.Empty; int status = 0; List<ItemPrice> iprice = (ItemPList == null || ItemPList.Count == 0) ? null : ItemPList[pMasterList.IndexOf(pMaster)]; int priceMasterId = _priceMasterMgr.Save(pMaster, iprice, null, ref msg); if (priceMasterId != -1) { priceUpdateApply.price_master_id = Convert.ToUInt32(priceMasterId); int apply_id = _priceUpdateApplyMgr.Save(priceUpdateApply); if (apply_id != -1) { pMaster = _priceMasterMgr.Query(new PriceMaster { price_master_id = Convert.ToUInt32(priceMasterId) }).FirstOrDefault(); pMaster.apply_id = Convert.ToUInt32(apply_id); excuteSql.Add(_priceMasterMgr.Update(pMaster)); excuteSql.Add(_priceMasterTsMgr.UpdateTs(pMaster)); //edit by xiangwang0413w 2014/07/22 更新price_master_ts表後同時更新price_master_ts表,以便價格審核 foreach (var item in pMasterList.FindAll(m => m.product_id != m.child_id)) { iprice = (ItemPList == null || ItemPList.Count == 0) ? null : ItemPList[pMasterList.IndexOf(item)]; priceMasterId = _priceMasterMgr.Save(item, iprice, null, ref msg); pMaster = _priceMasterMgr.Query(new PriceMaster { price_master_id = Convert.ToUInt32(priceMasterId) }).FirstOrDefault(); if (priceMasterId != -1) { priceUpdateApply.price_master_id = Convert.ToUInt32(priceMasterId); pMaster = _priceMasterMgr.Query(new PriceMaster { price_master_id = Convert.ToUInt32(priceMasterId) }).FirstOrDefault(); pMaster.apply_id = Convert.ToUInt32(apply_id); excuteSql.Add(_priceMasterMgr.Update(pMaster)); excuteSql.Add(_priceMasterTsMgr.UpdateTs(pMaster)); //edit by xiangwang0413w 2014/07/22 更新price_master_ts表後同時更新price_master_ts表,以便價格審核 } else { status = 2; } } } else { status = 3; } } else { status = 3; } excuteSql.Add(_priceUpdateApplyHistoryMgr.SaveSql(applyHistroy)); _tableHistoryMgr = new TableHistoryMgr(connectionString); if (_tableHistoryMgr.SaveHistory<PriceMaster>(pMaster, batch, excuteSql)) { status = 1; } else { status = 2; } //foreach (var item in pMasterList) //{ // List<ItemPrice> iprice = (ItemPList == null || ItemPList.Count == 0) ? null : ItemPList[pMasterList.IndexOf(item)]; // int priceMasterId = _priceMasterMgr.Save(item, iprice, null, ref msg); // if (apply_id != -1) // { // pMaster = _priceMasterMgr.Query(new PriceMaster { price_master_id = Convert.ToUInt32(priceMasterId) }).FirstOrDefault(); // } // if (priceMasterId != -1) // { // if (item != pMaster) { status = 1; continue; } // priceUpdateApply.price_master_id = Convert.ToUInt32(priceMasterId); // int apply_id = _priceUpdateApplyMgr.Save(priceUpdateApply); // if (apply_id != -1) // { // pMaster = _priceMasterMgr.Query(new PriceMaster { price_master_id = Convert.ToUInt32(priceMasterId) }).FirstOrDefault(); // pMaster.apply_id = Convert.ToUInt32(apply_id); // applyHistroy.apply_id = apply_id; // excuteSql.Add(_priceMasterMgr.Update(pMaster)); // excuteSql.Add(_priceMasterTsMgr.UpdateTs(pMaster)); //edit by xiangwang0413w 2014/07/22 更新price_master_ts表後同時更新price_master_ts表,以便價格審核 // excuteSql.Add(_priceUpdateApplyHistoryMgr.SaveSql(applyHistroy)); // _tableHistoryMgr = new TableHistoryMgr(connectionString); // if (_tableHistoryMgr.SaveHistory<PriceMaster>(pMaster, batch, excuteSql)) // { // status = 1; // } // else { status = 2; } // } // else { status = 2; } // } // else { status = 3; } //} if (status == 1) { json = "{success:true,msg:'" + Resources.Product.ADD_SUCCESS + "'}"; } else if (status == 2) { json = "{success:false,msg:'" + Resources.Product.SAVE_FAIL + "'}"; } else { json = "{success:false,msg:'" + msg + "'}"; } #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.Product.SAVE_FAIL + "'}"; } #endregion } else { #region 新增至臨時表 try { _productTempMgr = new ProductTempMgr(connectionString); _pMasterTempMgr = new PriceMasterTempMgr(connectionString); //product_temp 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.Bonus_Percent = float.Parse(bonus_percent); pTemp.Default_Bonus_Percent = float.Parse(default_bonus_percent); //Price_Master pMasterTemp.product_name = product_name; ; pMasterTemp.default_bonus_percent = float.Parse(default_bonus_percent); 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.accumulated_bonus = uint.Parse(accumulated_bonus); pMasterTemp.bonus_percent = float.Parse(bonus_percent); 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); #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 (bonus_percent_start != "") { pMasterTemp.bonus_percent_start = Convert.ToUInt32(CommonFunction.GetPHPTime(bonus_percent_start)); pTemp.Bonus_Percent_Start = Convert.ToUInt32(CommonFunction.GetPHPTime(bonus_percent_start)); } if (bonus_percent_end != "") { pMasterTemp.bonus_percent_end = Convert.ToUInt32(CommonFunction.GetPHPTime(bonus_percent_end)); pTemp.Bonus_Percent_End = Convert.ToUInt32(CommonFunction.GetPHPTime(bonus_percent_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; _productItemMgr = new ProductItemMgr(connectionString); string oldProductId = "0"; if (!string.IsNullOrEmpty(Request.Form["OldProductId"])) { oldProductId = Request.Form["OldProductId"]; } List<ItemPrice> update = new List<ItemPrice>(); if (price_type == "2") { _combTempMgr = new ProductComboTempMgr(connectionString); List<ProductComboCustom> combResultList = _combTempMgr.priceComboQuery(new ProductComboCustom { Writer_Id = writer_id, Parent_Id = int.Parse(oldProductId.ToString()) }); bool match = true; if (combResultList.Count() > 0) { int countBySearchPile = combResultList.GroupBy(m => m.Pile_Id).Count(); //庫中原有價格數據 int countByStorePile = PriceStore.GroupBy(m => m.Pile_Id).Count(); //頁面store數據 //判斷群組數量是否相同 if (countBySearchPile == countByStorePile) { for (int i = 1; i <= countBySearchPile; i++) { //組合類型為固定或任選時pile_id為0; var tempSearch = combResultList.Where(m => m.Pile_Id == (combResultList[0].Pile_Id == 0 ? 0 : i)).ToList().GroupBy(m => m.Child_Id).ToList(); var tempPrice = PriceStore.Where(m => m.Pile_Id == (combResultList[0].Pile_Id == 0 ? 0 : i)).ToList().GroupBy(m => m.Child_Id).ToList(); //判斷當前組中子商品的數量是否相同 if (tempSearch.Count() == tempPrice.Count()) { foreach (var item in tempPrice) { if (tempSearch.Where(m => m.Key == item.Key.ToString()).ToList().Count() <= 0)//edit 2014/09/24 { match = false; break; } } } else { match = false; break; } } } else { match = false; } } else { match = false; } if (!match) { _combTempMgr = new ProductComboTempMgr(connectionString); _combTempMgr.comboPriceDelete(new ProductComboTemp { Writer_Id = writer_id, Combo_Type = COMBO_TYPE, Parent_Id = oldProductId }); PriceStore.ForEach(rec => rec.price_master_id = 0); } CreateList(PriceStore, null, pMasterTemp, same_price, ItemPList, pMasterListT, pMasterList, update); } pMasterListT.Add(pMasterTemp); //如果原價格為複製價格,則需刪除原複製價格並將child_id設為oldProductId if (oldProductId != "0") { pMasterListT.ForEach(m => { if (m.child_id == "0") { m.child_id = oldProductId; } }); } //查詢 PriceMasterProductCustom queryReust = _pMasterTempMgr.Query(new PriceMasterTemp() { writer_Id = writer_id, child_id = oldProductId, product_id = oldProductId, combo_type = COMBO_TYPE }); //檢查價格類型是否有變動,如果有則刪除原有價格數據 if (queryReust != null) { if (!price_type.Equals(queryReust.price_type.ToString())) { _combTempMgr = new ProductComboTempMgr(connectionString); _combTempMgr.comboPriceDelete(new ProductComboTemp { Writer_Id = writer_id, Combo_Type = COMBO_TYPE, Parent_Id = oldProductId.ToString() }); queryReust = null; } } if (queryReust == null)//插入 { if (price_type == "1") { _pMasterTempMgr.Save(pMasterListT, null, null); } else { _pMasterTempMgr.Save(pMasterListT, ItemPList, null); } } else//更新 { if (price_type == "1") { _pMasterTempMgr.Update(pMasterListT, null); } else { _pMasterTempMgr.Update(pMasterListT, update); } } _productTempMgr.PriceBonusInfoSave(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.Product.SAVE_FAIL + "'}"; } #endregion } return json; }
/// <summary> /// 批量新增組合商品價格 /// </summary> /// <param name="pmc"></param> /// <param name="batch"></param> /// <param name="typePrice"></param> /// <param name="list_priceMaster"></param> /// <param name="chkCost">0 為 活動成本 設定 原成本,1 為 活動成本 依 折數 計算</param> //add by zhuoqin0830w 2015/04/02 /// <returns></returns> public string AddItemProduct(PriceMasterCustom pmc, HistoryBatch batch, string typePrice, List<PriceMaster> list_priceMaster, int chkCost) { ProductTemp pTemp = new ProductTemp(); //List<List<ItemPrice>> ItemPList = new List<List<ItemPrice>>(); PriceMasterTemp pMasterTemp = new PriceMasterTemp(); string json = "{success:true}"; if (!string.IsNullOrEmpty(pmc.product_id.ToString())) { #region 正式表操作 //插入price_master _priceMasterMgr = new PriceMasterMgr(connectionString); _priceMasterTsMgr = new PriceMasterTsMgr(connectionString); PriceMaster gigade = list_priceMaster.Where(m => m.product_id == pmc.product_id).FirstOrDefault(); PriceMaster pMaster = new PriceMaster(); pMaster.product_id = pmc.product_id; if (pmc.combination == 1) { pMaster.child_id = 0; } else if (pmc.combination != 1 && pmc.combination != 0) { pMaster.child_id = Convert.ToInt32(pmc.product_id); } pMaster.site_id = pmc.site_id; uint userId = 0; if (userId != 0) { pMaster.user_id = userId; } if (pmc.user_level.ToString() != "") { pMaster.user_level = pmc.user_level; } pMaster.product_name = pmc.product_name; pMaster.bonus_percent = gigade.bonus_percent; pMaster.cost = pmc.cost_at; pMaster.price = pmc.price_at; pMaster.max_price = pmc.max_price; pMaster.max_event_price = pmc.max_price; pMaster.default_bonus_percent = gigade.default_bonus_percent; if (typePrice == "discount") { pMaster.event_price = CommonFunction.ArithmeticalDiscount(pmc.price, pmc.event_price_discount);//Convert.ToInt32(Convert.ToDouble(pmc.price) * (pmc.event_price_discount * 0.01)); //add by zhuoqin0830w 2015/04/02 判斷是否是 依原成本設定值 if (chkCost == 1) { //eidt by zhuoqin0830w 更改商品活動成本驗算公式使活動價乘以折扣 2015/02/27 pMaster.event_cost = CommonFunction.ArithmeticalDiscount(pmc.event_price, pmc.event_cost_discount);// Convert.ToInt32(Convert.ToDouble(pmc.cost) * (pmc.event_cost_discount * 0.01)); } else { pMaster.event_cost = pmc.event_cost; } } else { pMaster.event_price = pmc.event_price; pMaster.event_cost = pmc.event_cost; } pMaster.same_price = gigade.same_price; pMaster.price_status = 2;//申請審核 pMaster.accumulated_bonus = gigade.accumulated_bonus; #region 時間 活動時間 if (pmc.event_start.ToString() != "") { pMaster.event_start = pmc.event_start; } if (pmc.event_end.ToString() != "") { pMaster.event_end = pmc.event_end; } #endregion //價格修改 申請審核 PriceUpdateApply priceUpdateApply = new PriceUpdateApply(); priceUpdateApply.apply_user = Convert.ToUInt32((Session["caller"] as Caller).user_id); //價格審核記錄 PriceUpdateApplyHistory applyHistroy = new PriceUpdateApplyHistory(); applyHistroy.user_id = Convert.ToInt32(priceUpdateApply.apply_user); applyHistroy.price_status = 1; //applyHistroy.type = 3; applyHistroy.type = 1;//edit by wwei0216w 所作操作為 1:申請審核的操作 _priceUpdateApplyMgr = new PriceUpdateApplyMgr(connectionString); _priceUpdateApplyHistoryMgr = new PriceUpdateApplyHistoryMgr(connectionString); _tableHistoryMgr = new TableHistoryMgr(connectionString); ArrayList excuteSql = new ArrayList(); #region 新增 string msg = string.Empty; int status = 0; int priceMasterId = 0; IPriceMasterImplMgr i = new PriceMasterMgr(connectionString); List<ItemPrice> iprice = i.AddSingleProduct(pmc, typePrice); var result = _priceMasterMgr.Query(pMaster); if (result.Count > 0) { priceMasterId = -1; msg = pMaster.product_id.ToString(); return msg; } if (typePrice == "discount") { pMaster.price = CommonFunction.ArithmeticalDiscount(pmc.price, pmc.price_discount);// Convert.ToInt32(Convert.ToDouble(pmc.price) * (pmc._discount * 0.01)); pMaster.cost = CommonFunction.ArithmeticalDiscount(pmc.cost, pmc.cost_discount);// Convert.ToInt32(Convert.ToDouble(pmc.cost) * (pmc._cost_discount * 0.01)); pMaster.event_price = CommonFunction.ArithmeticalDiscount(pmc.price, pmc.event_price_discount);// Convert.ToInt32(Convert.ToDouble(pmc.price) * (pmc.event_price_discount * 0.01)); //add by zhuoqin0830w 2015/04/02 判斷是否是 依原成本設定值 if (chkCost == 1) { pMaster.event_cost = CommonFunction.ArithmeticalDiscount(pmc.event_price, pmc.event_cost_discount);// Convert.ToInt32(Convert.ToDouble(pmc.cost) * (pmc.event_cost_discount * 0.01)); } else { pMaster.event_cost = pmc.cost; } } priceMasterId = _priceMasterMgr.Save(pMaster, iprice, null, ref msg); if (priceMasterId != -1) { priceUpdateApply.price_master_id = Convert.ToUInt32(priceMasterId); //價格更新申請記錄(設置更新記錄中,更新的價格id) int apply_id = _priceUpdateApplyMgr.Save(priceUpdateApply);//價格更新申請記錄(新增或者更新價格后,將記錄下來插入該表)返回更新記錄的Id號 if (apply_id != -1) { pMaster = _priceMasterMgr.Query(new PriceMaster { price_master_id = Convert.ToUInt32(priceMasterId) }).FirstOrDefault(); pMaster.apply_id = Convert.ToUInt32(apply_id); applyHistroy.apply_id = apply_id; excuteSql.Add(_priceMasterMgr.Update(pMaster)); excuteSql.Add(_priceMasterTsMgr.UpdateTs(pMaster)); //edit by xiangwang0413w 2014/07/22 更新price_master_ts表後同時更新price_master_ts表,以便價格審核 excuteSql.Add(_priceUpdateApplyHistoryMgr.SaveSql(applyHistroy)); _tableHistoryMgr = new TableHistoryMgr(connectionString); if (_tableHistoryMgr.SaveHistory<PriceMaster>(pMaster, batch, excuteSql)) { status = 1; } else { status = 2; } } else { status = 2; } } else { status = 3; } if (status == 1) { return "success"; } else if (status == 2) { return json = "商品:" + pmc.product_name + Resources.Product.SAVE_FAIL + "'}"; } else { return json = msg; } #endregion #endregion } return ""; }
/// <summary> /// 組合商品按比例拆分 /// </summary> /// <param name="pMaster"></param> /// <returns></returns> public bool SaveComboProductRatio(PriceMaster priceMaster, HistoryBatch batch, int applyId, ArrayList excuteSql) { return _tableHistoryMgr.SaveHistory<PriceMaster>(priceMaster, batch, excuteSql); }
/// <summary> /// 根據條件只修改product_name /// edit by wwei0216w 2014/12/18 /// </summary> /// <returns></returns> public string UpdateName(PriceMaster pm) { return _priceMasterDao.UpdateName(pm); }
public override bool Exec() { bool result = true; PriceMaster priceMaster = new PriceMaster(); foreach (MigrationDataSet item in mds) { result = true; form.change(1); //如果价格档原料编号新旧为new,则从对照表取出formula对应的product_id. //if (item.New_old.Equals("new")) //{ ProductMigrationMap mapQuery = _pMap.GetSingle(new ProductMigrationMap { temp_id = item.Formula }); if (mapQuery != null) { item.Formula = mapQuery.product_id.ToString(); } else { item.OutMessage = "formula對照不存在"; result = false; continue; } //} #region 原逻辑 //如果价格档中无价格,则取formula对应PriceMaster中站台为gigade的价格. //if (string.IsNullOrEmpty(item.Price) || string.IsNullOrEmpty(item.Cost)) //{ // PriceMaster priceQuery = _priceMgr.PriceMasterQuery(new PriceMaster { product_id = uint.Parse(item.Formula), site_id = 1 }).FirstOrDefault(); // if (priceQuery != null) // { // item.Cost = priceQuery.cost.ToString(); // item.Price = priceQuery.price.ToString(); // } // else // { // item.OutMessage = "price,cost不存在"; // result = false; // continue; // } //} #endregion //获取product_id对应product_item中的价格 if (!item.Product_id.Equals("0")) { ProductItem itemQuery = _prodItemMgr.Query(new ProductItem { Product_Id = uint.Parse(item.Product_id) }).FirstOrDefault(); if (itemQuery != null) { item.Cost = itemQuery.Item_Cost.ToString(); item.Price = itemQuery.Item_Money.ToString(); } else { item.OutMessage = "product_item中无product_id信息;"; result = false; continue; } } else { item.OutMessage = "product_id不存在;"; result = false; continue; } //price_master priceMaster.product_id = uint.Parse(item.Formula); priceMaster.cost = int.Parse(item.Cost); priceMaster.price = int.Parse(item.Price); priceMaster.price_status = 1; priceMaster.user_level = 1; priceMaster.default_bonus_percent = 1; priceMaster.bonus_percent = 1; priceMaster.site_id = uint.Parse(item.Site); priceMaster.user_id = 0; priceMaster.product_name = item.Product_name; priceMaster.same_price = 1; priceMaster.child_id = 0; //item_price List<ItemPrice> ipList = new List<ItemPrice>(); List<ProductItem> queryList = _prodItemMgr.Query(new ProductItem { Product_Id = uint.Parse(item.Formula) }); foreach (ProductItem proItem in queryList) { iPrice = new ItemPrice(); iPrice.item_id = proItem.Item_Id; iPrice.item_money = uint.Parse(item.Price); iPrice.item_cost = uint.Parse(item.Cost); ipList.Add(iPrice); } ArrayList others = new ArrayList(); Site site = _siteMgr.Query(new Site { Site_Id = uint.Parse(item.Site) }).FirstOrDefault(); if (site.Site_Name.Trim().ToLower() == "chinatrust") { Product pro = _prodMgr.Query(new Product { Product_Id = mapQuery.product_id }).FirstOrDefault(); if (pro == null) { item.OutMessage = "商品不存在"; continue; } #region 更新該站臺商品的 product_category_set string[] cateArray = item.Display.Split(','); foreach (string strcate in cateArray) { ProductCategorySet category = new ProductCategorySet { Brand_Id = pro.Brand_Id, Category_Id = uint.Parse(strcate), Product_Id = mapQuery.product_id }; if (_productCategorySetMgr.Query(category).FirstOrDefault() == null) { others.Add(_productCategorySetMgr.Save(category)); } else { item.OutMessage = "display:" + strcate + " 已存在;"; result = false; break; } } if (!result) continue; } #endregion //保存 string strError = ""; if (_priceMgr.Save(priceMaster, ipList, others, ref strError) <= 0) { result = false; item.OutMessage = strError; if (strError == "") { item.OutMessage = "匯入失敗"; } } else { item.OutMessage = "匯入成功"; } } return result; }
public ActionResult QueryProdname(ProdNameExtendCustom pron, bool isOverdue) { string ids = Request["Ids"]; try { int state = 0;//判斷是否需要重新查詢的依據 _prodnameExtendMgr = new ProdNameExtendMgr(connectionString); IPriceMasterImplMgr pmMgr = new PriceMasterMgr(connectionString); MySqlDao _mySqlDao = new MySqlDao(connectionString); ArrayList sqlList = new ArrayList(); List<ProdNameExtendCustom> list = _prodnameExtendMgr.Query(pron, ids);//根據條件查詢商品信息 //判斷過期商品 和 審核商品 中是否存在錯誤數據 edit by zhuoqin0830w 2015/05/07 List<ProdNameExtendCustom> listDelete = list.FindAll(m => m.Flag == 3 || m.Flag == 1); //查詢過程中,為防止未去掉前後綴,卻到期的商品,進行一次遍歷,去掉前後綴 edit by wwei 0216w 2014/12/22 //獲取 前一天 時間的時間戳 edit by zhuoqin0830w 2015/05/07 long time = CommonFunction.GetPHPTime(Convert.ToString(DateTime.Now)) - 86400; foreach (ProdNameExtendCustom pec in listDelete) { pec.Product_Name = pec.Product_Name.Replace(PriceMaster.L_HKH + pec.Product_Prefix + PriceMaster.R_HKH, "").Replace(PriceMaster.L_HKH + pec.Product_Suffix + PriceMaster.R_HKH, ""); PriceMaster p = new PriceMaster(); p.price_master_id = pec.Price_Master_Id; p.product_name = pec.Product_Name; switch (pec.Flag) { case 1://審核商品 //判斷結束時間 是否 小於 前一天 時間的時間戳 edit by zhuoqin0830w 2015/05/07 if (pec.Event_End <= time) { sqlList.Add(pmMgr.UpdateName(p)); state = 1;//如果審核商品中結束時間小於前一天的時間,則賦值為1; _mySqlDao.ExcuteSqls(sqlList); break; } break; case 3://過期商品 //如果在過期的商品名稱中能找到前綴後綴~則調用刪除前後綴的方法 if ((pec.Product_Name.Contains(PriceMaster.L_HKH + pec.Product_Prefix + PriceMaster.R_HKH) || pec.Product_Name.Contains(PriceMaster.L_HKH + pec.Product_Suffix + PriceMaster.R_HKH))) { _prodnameExtendMgr.ResetExtendName(new Caller()); state = 1;//如果有過期商品包含前後綴,則賦值為1; break; } break; } } if (state == 1) { list = _prodnameExtendMgr.Query(pron, ids);//替換掉之前包含前後綴的商品名稱 } for (int i = 0; i < list.Count; i++) { list[i].Key_Id = i; }//add by wwei0216w 2014/12/30 為key_id賦值 if (isOverdue)//查詢過期 { list.RemoveAll(p => p.Flag != 3); } else //查詢未過期 { list.RemoveAll(p => p.Flag == 3); } return Json(new { item = list }); } 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); } return Json(new List<ProdNameExtendCustom>()); }
public void PrepareData(List<CombinationExcel> source) { if (source != null) { source.ForEach(m => m.Validate()); var parents = source.Where(m => m.combination.Trim() != "299" && string.IsNullOrEmpty(m.msg)); _productMgr = new ProductMgr(strConn); _productItemMgr = new ProductItemMgr(strConn); _vendorMgr = new VendorMgr(strConn); _vendorBrandMgr = new VendorBrandMgr(strConn); _siteMgr = new SiteMgr(strConn); _productMigrationMgr = new ProductMigrationMgr(strConn); _productComboMgr = new ProductComboMgr(strConn); _cateMgr = new ProductCategoryMgr(strConn); _productCategorySetMgr = new ProductCategorySetMgr(strConn); _productNoticeSetMgr = new ProductNoticeSetMgr(strConn); _productTagSetMgr = new ProductTagSetMgr(strConn); _productPictureMgr = new ProductPictureMgr(strConn); _productStatusHistoryMgr = new ProductStatusHistoryMgr(strConn); foreach (var parent in parents) { form.change(1); uint product_id = uint.Parse(parent.product_id); #region Product ProductMigrationMap prodMigra = _productMigrationMgr.GetSingle(new ProductMigrationMap { temp_id = parent.is_exist.ToUpper().Trim().Equals("OLD") ? parent.product_id : parent.temp_id }); if (prodMigra != null) { parent.msg = "此記錄暫時編號(temp_id)已經存在;"; continue; } Product newPro = parent.is_exist.ToUpper().Trim() == "OLD" ? _productMgr.Query(new Product { Product_Id = product_id }).FirstOrDefault() : new Product(); if (newPro == null) { parent.msg = "商品不存在"; continue; } newPro.Product_Name = parent.product_name.Trim(); VendorBrand brand = _vendorBrandMgr.GetProductBrand(new VendorBrand { Brand_Name = parent.brand_name.Trim() }); if (brand == null) { parent.msg = "品牌不存在"; continue; } newPro.Brand_Id = brand.Brand_Id; switch (parent.combination.Trim()) { case "2": newPro.Combination = 2; break; case "3": newPro.Combination = 3; break; case "4": newPro.Combination = 4; break; default: break; } switch (parent.status.Trim().ToUpper()) { case "SAME": break; case "ON": newPro.Product_Status = 5; break; case "OFF": newPro.Product_Status = 6; break; case "NEW": newPro.Product_Status = 0; break; default: break; } newPro.Price_type = 1; newPro.Product_Spec = 0; newPro.Spec_Title_1 = string.Empty; newPro.Spec_Title_2 = string.Empty; newPro.Ignore_Stock = 0;// parent.ignore_stock.ToUpper().Trim() == "Y" ? 1 : 0; newPro.Shortage = 0;// parent.shortage.ToUpper().Trim() == "Y" ? 1 : 0; newPro.Cate_Id = parent.cate_id.Trim(); var vendor = _vendorMgr.GetSingle(new Vendor { vendor_id = brand.Vendor_Id }); if (vendor == null) { parent.msg = "供應商不存在"; continue; } newPro.user_id = vendor.product_manage; if (!string.IsNullOrEmpty(parent.service_fee)) { uint bag_check_money=0; uint.TryParse(parent.service_fee,out bag_check_money); newPro.Bag_Check_Money = bag_check_money; } #endregion bool result = true; ArrayList sqls = new ArrayList(); #region PriceMaster Site site = _siteMgr.Query(new Site { Site_Name = parent.site.Trim() }).FirstOrDefault(); if (site == null) { parent.msg = "價格檔站臺不存在"; result = false; break; } List<PriceMaster> priceMasters = new List<PriceMaster>(); //首先默認加入一筆吉甲地站臺 PriceMaster newPriceMaster = new PriceMaster { site_id = 1, user_level = 1, same_price = 1, accumulated_bonus = 1, default_bonus_percent = 1, bonus_percent = 1 }; newPriceMaster.product_name = newPro.Product_Name; newPriceMaster.price_status = 1; var item = _productItemMgr.Query(new ProductItem { Product_Id = newPro.Product_Id }).FirstOrDefault(); if (item == null) { parent.msg = "商品細項不存在"; continue; } #region 成本 int cost = 0; if (!string.IsNullOrEmpty(parent.cost)) { int.TryParse(parent.cost, out cost); } else { cost = Convert.ToInt32(item.Item_Cost); } newPriceMaster.cost = cost; #endregion #region 售價 int price = 0; if (!string.IsNullOrEmpty(parent.price)) { int.TryParse(parent.price, out price); } else { price = Convert.ToInt32(item.Item_Money); } newPriceMaster.price = price; #endregion newPriceMaster.event_price = Convert.ToInt32(item.Event_Item_Money); newPriceMaster.event_start = item.Event_Product_Start; newPriceMaster.event_end = item.Event_Product_End; priceMasters.Add(newPriceMaster); if (site.Site_Id != 1) { //如果站臺不是吉甲地就把吉甲地站臺的價格狀態改為4(下架) priceMasters[0].price_status = 4; //再加入非吉甲地站臺 newPriceMaster = new PriceMaster { site_id = site.Site_Id, user_level = 1, same_price = 1, accumulated_bonus = 1, default_bonus_percent = 1, bonus_percent = 1 }; newPriceMaster.product_name = newPro.Product_Name; newPriceMaster.price_status = 1; #region 成本 cost = 0; if (!string.IsNullOrEmpty(parent.cost)) { int.TryParse(parent.cost, out cost); } else { cost = Convert.ToInt32(item.Item_Cost); } newPriceMaster.cost = cost; #endregion #region 售價 price = 0; if (!string.IsNullOrEmpty(parent.price)) { int.TryParse(parent.price, out price); } else { price = Convert.ToInt32(item.Item_Money); } newPriceMaster.price = price; #endregion newPriceMaster.event_price = Convert.ToInt32(item.Event_Item_Money); newPriceMaster.event_start = item.Event_Product_Start; newPriceMaster.event_end = item.Event_Product_End; priceMasters.Add(newPriceMaster); } #region 其他站臺價格 var child = source.Where(m => m.combination.Trim() == "299" && m.formula.ToUpper().Trim() == parent.temp_id.ToUpper().Trim() && string.IsNullOrEmpty(m.msg) && m.new_old.ToUpper().Trim() == "NEW" && m.formula.ToUpper().Trim().StartsWith("P")); if (child != null) { foreach (var c in child) { item = _productItemMgr.Query(new ProductItem { Product_Id = uint.Parse(c.product_id) }).FirstOrDefault(); if (item == null) { c.msg = "價格檔商品細項不存在"; result = false; break; } site = _siteMgr.Query(new Site { Site_Name = c.site.Trim() }).FirstOrDefault(); if (site == null) { c.msg = "站臺不存在"; result = false; break; } if (priceMasters.Exists(m => m.site_id == site.Site_Id)) { c.msg = "站臺重複"; result = false; break; } newPriceMaster = new PriceMaster { user_level = 1, same_price = 1, accumulated_bonus = 1, default_bonus_percent = 1, bonus_percent = 1 }; newPriceMaster.product_name = c.product_name.Trim(); newPriceMaster.site_id = site.Site_Id; newPriceMaster.price_status = 1; #region 成本 cost = 0; if (!string.IsNullOrEmpty(c.cost)) { int.TryParse(c.cost, out cost); } else { cost = Convert.ToInt32(item.Item_Cost); } newPriceMaster.cost = cost; #endregion #region 售價 price = 0; if (!string.IsNullOrEmpty(c.price)) { int.TryParse(c.price, out price); } else { price = Convert.ToInt32(item.Item_Money); } newPriceMaster.price = price; #endregion newPriceMaster.event_price = Convert.ToInt32(item.Event_Item_Money); newPriceMaster.event_start = item.Event_Product_Start; newPriceMaster.event_end = item.Event_Product_End; priceMasters.Add(newPriceMaster); if (site.Site_Name.Trim().ToLower() == "chinatrust") { ArrayList category_set = CategorySet(c, brand.Brand_Id); if (category_set == null) { result = false; break; } else { sqls.AddRange(category_set); } } } if (!result) continue; } #endregion #endregion #region ProductCombo string[] strIds = parent.formula.IndexOf(",") != -1 ? parent.formula.Trim().Split(',') : new string[] { parent.formula.Trim() }; string[] nums = parent.number.IndexOf(",") != -1 ? parent.number.Trim().Split(',') : new string[] { parent.number.Trim() }; List<Product> children = new List<Product>(); ProductCombo tmp; for (int i = 0; i < strIds.Length; i++) { tmp = new ProductCombo(); if (parent.combination.Trim() != "2") { tmp.Buy_Limit = parent.buylimit.Trim().ToUpper() == "Y" ? 1 : 0; } else { tmp.S_Must_Buy = int.Parse(i >= nums.Length ? nums[nums.Length - 1] : nums[i]); } if (parent.combination.Trim() == "3")//為3任選時 數量為G_Must_Buy { tmp.G_Must_Buy = int.Parse(nums[0]); } switch (parent.new_old.Trim().ToUpper()) { case "NEW": var map = _productMigrationMgr.GetSingle(new ProductMigrationMap { temp_id = strIds[i] }); if (map == null) { parent.msg = "原料編號未找到對應"; break; } tmp.Child_Id = Convert.ToInt32(map.product_id); break; case "OLD": tmp.Child_Id = int.Parse(strIds[i]); break; case "BOTH": if (strIds[i].ToUpper().Trim().StartsWith("P")) { var tMap = _productMigrationMgr.GetSingle(new ProductMigrationMap { temp_id = strIds[i] }); if (tMap == null) { parent.msg = "原料編號未找到對應"; break; } tmp.Child_Id = Convert.ToInt32(tMap.product_id); } else { tmp.Child_Id = int.Parse(strIds[i]); } break; } if (tmp.Child_Id == 0) { result = false; break; } else { Product tmpPro = _productMgr.Query(new Product { Product_Id = Convert.ToUInt32(tmp.Child_Id) }).FirstOrDefault(); if (tmpPro == null) { parent.msg = strIds[i] + "不存在"; result = false; break; } if (tmpPro.Product_Status == 0 || tmpPro.Product_Status ==1) { parent.msg = strIds[i] + "商品状态不為新增、申請審核"; result = false; break; } if (tmpPro.Combination != 0 && tmpPro.Combination != 1) { parent.msg = strIds[i] + "不是單一商品"; result = false; break; } switch (newPro.Product_Freight_Set) { case 1: case 3: if (tmpPro.Product_Freight_Set != 1 && tmpPro.Product_Freight_Set != 3) { parent.msg = strIds[i] + "运费模式与主商品不匹配"; result = false; } break; case 2: case 4: if (tmpPro.Product_Freight_Set != 2 && tmpPro.Product_Freight_Set != 4) { parent.msg = strIds[i] + "运费模式与主商品不匹配"; result = false; } break; case 5: case 6: if (tmpPro.Product_Freight_Set != 5 && tmpPro.Product_Freight_Set != 6) { parent.msg = strIds[i] + "运费模式与主商品不匹配"; result = false; } break; default: break; } if (!result) break; children.Add(tmpPro); } sqls.Add(_productComboMgr.Save(tmp)); } if (!result) continue; #endregion #region product_category_set if (!string.IsNullOrEmpty(parent.display)) { ArrayList category_set = CategorySet(parent, brand.Brand_Id); if (category_set == null) continue; else { foreach (var set in category_set) { if (!sqls.Contains(set)) { sqls.Add(set); } } } } else { sqls.Add(_productCategorySetMgr.SaveFromOtherPro(new ProductCategorySet { Product_Id = product_id })); } #endregion #region product_migration_map ProductMigrationMap pMap = new ProductMigrationMap(); if (parent.is_exist.ToUpper().Equals("OLD")) { pMap.temp_id = parent.product_id; } else if (parent.is_exist.ToUpper().Equals("NEW")) { pMap.temp_id = parent.temp_id; } sqls.Add(_productMigrationMgr.SaveNoPrid(pMap)); #endregion #region notice tag picture sqls.Add(_productNoticeSetMgr.SaveFromOtherPro(new ProductNoticeSet { product_id = product_id })); sqls.Add(_productTagSetMgr.SaveFromOtherPro(new ProductTagSet { product_id = product_id })); sqls.Add(_productPictureMgr.SaveFromOtherPro(new ProductPicture { product_id = Convert.ToInt32(product_id) })); sqls.Add(_productStatusHistoryMgr.SaveNoProductId(new ProductStatusHistory { type = 7, product_status = Convert.ToInt32(newPro.Product_Status) })); #endregion string str = string.Empty; if (_productMgr.ProductMigration(newPro, priceMasters, null, null, sqls, null)) { str = "匯入成功"; } else { str = "保存至數據庫失敗"; } parent.msg = str; source.FindAll(m => m.combination.Trim() == "299" && m.formula.ToUpper().Trim() == parent.temp_id.ToUpper().Trim() && string.IsNullOrEmpty(m.msg) && m.new_old.ToUpper().Trim() == "NEW" && m.formula.ToUpper().Trim().StartsWith("P")).ForEach(m => m.msg = str); } #region 其他站臺價格 var pChild = source.Where(m => m.combination.Trim() == "299" && m.new_old.ToUpper().Trim() == "OLD" && string.IsNullOrEmpty(m.msg)); if (pChild != null) { ProductItem item; PriceMaster newPriceMaster; Site site; _priceMasterMgr = new PriceMasterMgr(strConn); foreach (var c in pChild) { ProductMigrationMap prodMigra = _productMigrationMgr.GetSingle(new ProductMigrationMap { temp_id = c.formula.Trim() }); if (prodMigra == null) { c.msg = "原料編號對照不存在"; continue; } item = _productItemMgr.Query(new ProductItem { Product_Id = uint.Parse(c.product_id) }).FirstOrDefault(); if (item == null) { c.msg = "價格檔商品細項不存在"; continue; } site = _siteMgr.Query(new Site { Site_Name = c.site.Trim() }).FirstOrDefault(); if (site == null) { c.msg = "站臺不存在"; continue; } newPriceMaster = new PriceMaster { user_level = 1, same_price = 1, accumulated_bonus = 1, default_bonus_percent = 1, bonus_percent = 1 }; newPriceMaster.product_name = c.product_name.Trim(); newPriceMaster.product_id = prodMigra.product_id; newPriceMaster.child_id = Convert.ToInt32(prodMigra.product_id); newPriceMaster.site_id = site.Site_Id; newPriceMaster.price_status = 1; #region 成本 int cost = 0; if (!string.IsNullOrEmpty(c.cost)) { int.TryParse(c.cost, out cost); } else { cost = Convert.ToInt32(item.Item_Cost); } newPriceMaster.cost = cost; #endregion #region 售價 int price = 0; if (!string.IsNullOrEmpty(c.price)) { int.TryParse(c.price, out price); } else { price = Convert.ToInt32(item.Item_Money); } newPriceMaster.price = price; #endregion newPriceMaster.event_price = Convert.ToInt32(item.Event_Item_Money); newPriceMaster.event_start = item.Event_Product_Start; newPriceMaster.event_end = item.Event_Product_End; ArrayList category_set = new ArrayList(); if (site.Site_Name.Trim().ToLower() == "chinatrust") { Product pro= _productMgr.Query(new Product { Product_Id = item.Product_Id }).FirstOrDefault(); if (pro == null) { c.msg = "商品不存在"; continue; } #region 更新該站臺商品的 product_category_set bool result = true; System.Text.RegularExpressions.Regex regx = new System.Text.RegularExpressions.Regex("^[0-9]*$"); string[] cateArray = c.display.Split(','); foreach (string strcate in cateArray) { if (!string.IsNullOrEmpty(strcate)) { if (regx.IsMatch(strcate)) { ProductCategory query = _cateMgr.QueryAll(new ProductCategory { category_id = uint.Parse(strcate) }).FirstOrDefault(); if (query == null || strcate.Equals("0")) { c.msg = "display:" + strcate + " 不存在;"; result = false; break; } else { ProductCategorySet category = new ProductCategorySet { Brand_Id = pro.Brand_Id, Category_Id = uint.Parse(strcate), Product_Id = prodMigra.product_id }; if (_productCategorySetMgr.Query(category).FirstOrDefault() == null) { category_set.Add(_productCategorySetMgr.Save(category)); } else { c.msg = "display:" + strcate + " 已存在;"; result = false; break; } } } else { c.msg = "display:" + strcate + " 格式不正確 "; result = false; break; } } } if (!result) continue; #endregion } string str = string.Empty; if (_priceMasterMgr.Save(newPriceMaster, null, category_set, ref str) > 0) { c.msg = "匯入成功"; } else { c.msg = string.IsNullOrEmpty(str) ? "保存至數據庫失敗" : str; } } } #endregion } }
/// <summary> /// 讀取Excel文件 /// </summary> /// <param name="filePath"></param> /// <param name="channel_id"></param> /// <param name="fExtension"></param> /// <param name="isHeaderError"></param> /// <param name="errorPm"></param> /// <returns></returns> public List<ProductItemMapCustom> ReadFile(string filePath, int channel_id, string fExtension, ref bool isHeaderError, List<ProductItemMapCustom> errorPm) { try { NPOI4ExcelHelper fm = new NPOI4ExcelHelper(filePath); DataTable dt = fm.SheetData(); if (dt == null) { return null; } List<ProductItemMapCustom> result = new List<ProductItemMapCustom>(); Regex RegxProductId = new Regex("^\\d{5}$"); Regex RegxItemId = new Regex("^\\d{6}$"); Regex RegxMoney = new Regex("^\\d{1,9}$"); for (int i = 0, j = dt.Rows.Count; i < j; i++) { bool bl = true; bool el = true; bool isNull = false; bool Pro_id = false;//記錄商品編號是否為空 bool Itm_id = false;//記錄商品細項編號是否為空 PriceMaster prm = new PriceMaster(); ProductItemMapCustom pm = new ProductItemMapCustom(); pm.channel_id = Convert.ToUInt32(channel_id); for (int m = 0, n = dt.Columns.Count; m < n; m++) { string valStr = dt.Rows[i][m].ToString(); switch (dt.Columns[m].ToString().Trim()) { case "商品編號(5碼)": if (!string.IsNullOrEmpty(valStr)) { uint _ProductId = 0; uint.TryParse(valStr ?? "0", out _ProductId); pm.product_id = _ProductId; prm.product_id = _ProductId; if (!RegxProductId.IsMatch(pm.product_id.ToString())) { bl = false; } } else { Pro_id = true; isNull = true; break; } break; case "商品細項編號(6碼)": if (!string.IsNullOrEmpty(valStr)) { if (valStr.Split(',').Length > 1) { for (int k = 0; k < valStr.Split(',').Length; k++) { if (!RegxItemId.IsMatch(valStr.Split(',')[k])) { bl = false; } } pm.group_item_id = CommonFunction.Rank_ItemId(valStr); } else { uint _itemId = 0; uint.TryParse(valStr ?? "0", out _itemId); pm.item_id = _itemId; pm.group_item_id = _itemId.ToString(); if (!RegxItemId.IsMatch(pm.item_id.ToString())) { bl = false; } } } else { Itm_id = true; isNull = true; break; //bl = false; }; break; case "外站商品名稱": if (!string.IsNullOrEmpty(valStr)) { pm.product_name = valStr; } else { bl = false; }; break; case "外站商品編號": if (!string.IsNullOrEmpty(valStr)) { pm.channel_detail_id = valStr; } else { bl = false; }; break; case "外站商品成本": if (!string.IsNullOrEmpty(valStr)) { if (RegxMoney.IsMatch(valStr)) { pm.product_cost = int.Parse(valStr); } else { bl = false; } } else { bl = false; } ; break; case "外站商品售價": if (!string.IsNullOrEmpty(valStr)) { if (RegxMoney.IsMatch(valStr)) { pm.product_price = int.Parse(valStr); } else { bl = false; } } else { bl = false; } ; break; case "組合中之數量(0為照組合中之設定)": if (!string.IsNullOrEmpty(valStr)) { if (RegxMoney.IsMatch(valStr)) { pm.set_num = uint.Parse(valStr); } else { bl = false; } } else { bl = false; } break; case "user_email"://郵箱 if (!string.IsNullOrEmpty(valStr)) { if (_callerMgr.Login(valStr) != null) { prm.user_id = uint.Parse(_callerMgr.Login(valStr).user_id.ToString()); } } break; case "site_id"://站臺 if (!string.IsNullOrEmpty(valStr)) { if (RegxMoney.IsMatch(valStr)) { prm.site_id = uint.Parse(valStr); } else { bl = false; } } else { bl = false; } break; case "user_level"://站臺等級 if (!string.IsNullOrEmpty(valStr)) { if (RegxMoney.IsMatch(valStr)) { prm.user_level = uint.Parse(valStr); } else { bl = false; } } else { bl = false; } break; default: el = false; break; } //if (isNull) //{ // break; //} } //判斷Excel表頭格式 if (!el) { isHeaderError = true; break; } else { isHeaderError = false; } //若單一商品可以無商品編號,若固定組合可以無商品細項編號。其餘類型出現為空數據,則此行記錄無效,不做處理 if (Itm_id) { if (_productItemMapDao.CombinationQuery(pm).FirstOrDefault() != null && _productItemMapDao.CombinationQuery(pm).FirstOrDefault().combination == 2) { List<ProductComboMap> pMc = _productItemMapDao.QueryItemId(pm.product_id); if (pMc != null && pMc.Where(e => e.product_spec == 0).Count() == pMc.Count()) { string strItem = ""; for (int Itemi = 0, Itemj = pMc.Count(); Itemi < Itemj; Itemi++) { if (Itemi > 0) { strItem += ","; } strItem += pMc[Itemi].item_id; } pm.group_item_id = CommonFunction.Rank_ItemId(strItem); isNull = false; } } } //單一商品邏輯 add by hufeng0813w 2013/12/23 if (Pro_id) { ProductItem pIm = new ProductItem(); pIm.Item_Id = uint.Parse(pm.item_id.ToString()); //pm.product_id = _productItemDao.Query(pIm).FirstOrDefault().Product_Id; ProductItem itemResult = _productItemDao.Query(pIm).FirstOrDefault(); if (itemResult != null) { prm.product_id = pm.product_id = itemResult.Product_Id; ProductMapCustom mapcusResult = _productItemMapDao.CombinationQuery(pm).FirstOrDefault(); if (mapcusResult != null && mapcusResult.combination == 1) { isNull = false; } } } if (isNull) { continue; } //獲取price_master_id if (prm.product_id != 0) { pm.price_master_id = _priceMasterMgr.QueryPriceMasterId(prm); } else { bl = false; } //判斷內容格式 if (!bl) { pm.msg = Resource.CoreMessage.GetResource("ERROR_FORMAT"); } else { ProductMapCustom map = _productItemMapDao.CombinationQuery(pm).FirstOrDefault(); if (map != null) { uint Combination = map.combination; if (Combination != 2) { ProductItem pi = new ProductItem(); pi.Item_Id = uint.Parse(pm.item_id.ToString()); if (_productItemMgr.Query(pi).Count == 0) { pm.msg = Resource.CoreMessage.GetResource("ITEMID_ID_NOT_EXISTS"); bl = false; } else { if (_productItemMapDao.Exist(pm) > 0) { pm.msg = Resource.CoreMessage.GetResource("COMPARE_EXISTS"); bl = false; } else { ProductItemMapCustom existItem = result.Where(m => m.item_id == pm.item_id).FirstOrDefault(); if (existItem != null) { pm.msg = Resource.CoreMessage.GetResource("COMPARE_EXISTS"); bl = false; } } } } else { #region for (int l = 0; l < pm.group_item_id.Split(',').Length; l++) { if (_productItemMapDao.Comb_Compare(pm.product_id, uint.Parse(pm.group_item_id.Split(',')[l])) == 0) { pm.msg = Resource.CoreMessage.GetResource("ITEMID_ID_NOT_COMBINATION"); bl = false; } else { #region if (l == 0) { if (_productItemMapDao.Comb_Exist(pm) > 0) { pm.msg = Resource.CoreMessage.GetResource("COMPARE_EXISTS"); bl = false; } else { ProductItemMapCustom existItem = result.Where(m => m.group_item_id == pm.group_item_id).FirstOrDefault(); if (existItem != null) { pm.msg = Resource.CoreMessage.GetResource("COMPARE_EXISTS"); bl = false; } } } #endregion } } #endregion } } else { bl = false; pm.msg = Resource.CoreMessage.GetResource("PRODUCT_NOT_EXIST"); } } if (!bl) { errorPm.Add(pm); } else { result.Add(pm); } } return result; // _access.getObjByTable<ProductItemMap>(dt); } catch (Exception ex) { throw new Exception("ProductItemMapExcelMgr-->ReadFile-->" + ex.Message, ex); } }
//add by wwei0216w 2015/1/30 /// <summary> /// 獲取單一商品的子商品 /// </summary> /// <returns></returns> public ProductCustom QueryProductInfo(uint productId, out List<Product> prods, out List<ProductItem> prodItems, out PriceMaster gigaPM) { StringBuilder sb = new StringBuilder(); try { sb.AppendFormat(@"SELECT p.product_id,p.product_status,p.product_start,p.product_end,p.ignore_stock,p.shortage,p.price_type, p.product_type,p.sale_status,pm.price_status,pm.price,v.vendor_status,vb.brand_status, pm.same_price,pm.event_start,pm.event_end,pm.event_price FROM product p INNER JOIN vendor_brand vb ON vb.brand_id=p.brand_id INNER JOIN vendor v ON v.vendor_id=vb.vendor_id INNER JOIN price_master pm ON pm.product_id=p.product_id AND pm.site_id = 1 AND pm.user_level = 1 AND pm.user_id = 0 WHERE p.product_id={0}; SELECT p.sale_status FROM product p INNER JOIN product_combo c on p.product_id = c.child_id WHERE c.parent_id={0}; SELECT item_stock FROM product_item WHERE product_id={0} AND item_stock <= 0; SELECT pm.price,pm.same_price,pm.event_start,pm.event_end,pm.event_price FROM price_master pm WHERE pm.product_id={0} AND pm.site_id = 1 AND pm.user_level = 1 AND pm.user_id = 0;", productId); DataSet ds = _dbAccess.getDataSet(sb.ToString()); ProductCustom prodc = _dbAccess.getObjByTable<ProductCustom>(ds.Tables[0]).FirstOrDefault(); prods = _dbAccess.getObjByTable<Product>(ds.Tables[1]); prodItems = _dbAccess.getObjByTable<ProductItem>(ds.Tables[2]); gigaPM = _dbAccess.getObjByTable<PriceMaster>(ds.Tables[3]).FirstOrDefault(); return prodc; } catch (Exception ex) { throw new Exception("ProductDao-->QuerySingleItem" + ex.Message, ex); } }
public void CreateList(List<MakePriceCustom> PriceStore, PriceMaster pMaster, PriceMasterTemp pMasterTemp, string same_price, List<List<ItemPrice>> ItemPList, List<PriceMasterTemp> pMasterListT, List<PriceMaster> pMasterList, List<ItemPrice> update) { _productItemMgr = new ProductItemMgr(connectionString); if (PriceStore.Count > 0) { //先遍歷群組 var piles = PriceStore.GroupBy(rec => rec.Pile_Id).ToList(); piles.ForEach(rec => { if (same_price == "1") { //循環grid的每一行 rec.ToList().ForEach(row => { //生成price_master if (pMasterTemp != null) { PriceMasterTemp pmT = pMasterTemp.Clone() as PriceMasterTemp; pmT.product_name = row.Product_Name; pmT.child_id = row.Child_Id.ToString(); pmT.price = int.Parse(row.item_money.ToString()); pmT.max_price = int.Parse(row.item_money.ToString()); //edit by xinglu0624w reason 子商品需要给 max_price 值 pmT.max_event_price = 0; pmT.cost = int.Parse(row.item_cost.ToString()); pmT.event_price = int.Parse(row.event_money.ToString()); pmT.event_cost = int.Parse(row.event_cost.ToString()); pmT.valid_start = pMasterTemp.valid_start; pmT.valid_end = pMasterTemp.valid_end; pMasterListT.Add(pmT); } else { PriceMaster priceMa = pMaster.Clone() as PriceMaster; priceMa.product_name = row.Product_Name; priceMa.child_id = int.Parse(row.Child_Id.ToString()); priceMa.price = int.Parse(row.item_money.ToString()); priceMa.max_price = int.Parse(row.item_money.ToString()); priceMa.max_event_price = 0; priceMa.cost = int.Parse(row.item_cost.ToString()); priceMa.event_price = int.Parse(row.event_money.ToString()); priceMa.event_cost = int.Parse(row.event_cost.ToString()); priceMa.price_master_id = row.price_master_id; pMasterList.Add(priceMa); } if (row.price_master_id == 0)//新增 { //生成item_price List<ProductItem> piList = _productItemMgr.Query(new ProductItem { Product_Id = row.Child_Id }); List<ItemPrice> iList = new List<ItemPrice>(); piList.ForEach(item => { ItemPrice iP = new ItemPrice(); iP.item_id = item.Item_Id; iP.item_money = row.item_money; iP.item_cost = row.item_cost; iP.event_money = row.event_money; iP.event_cost = row.event_cost; iList.Add(iP); }); ItemPList.Add(iList); } else //更新 { ItemPrice ip = new ItemPrice(); ip.item_price_id = row.item_price_id; ip.price_master_id = row.price_master_id; ip.item_money = row.item_money; ip.item_cost = row.item_cost; ip.event_money = row.event_money; ip.event_cost = row.event_cost; update.Add(ip); } }); } else //處理各自定價-規格不同價 { var children = rec.GroupBy(c => c.Child_Id).ToList(); children.ForEach(c => { List<ItemPrice> differentPrice = new List<ItemPrice>(); //生成price_mater var rowData = (from ci in c where ci.Child_Id == c.Key select new { ci.Product_Name, ci.price_master_id }).ToList().First(); if (pMasterTemp != null) { PriceMasterTemp pmT = pMasterTemp.Clone() as PriceMasterTemp; pmT.product_name = rowData.Product_Name; pmT.child_id = c.Key.ToString(); pmT.price = int.Parse(c.FirstOrDefault().item_money.ToString()); pmT.max_price = int.Parse(c.FirstOrDefault().item_money.ToString()); //edit by hufeng0813w 2014/06/16 Reason:規格不同價時子商品也需要cost,event_cost,event_money pmT.max_event_price = int.Parse(c.FirstOrDefault().event_money.ToString()); pmT.cost = int.Parse(c.FirstOrDefault().item_cost.ToString()); pmT.event_price = int.Parse(c.FirstOrDefault().event_money.ToString()); pmT.event_cost = int.Parse(c.FirstOrDefault().event_cost.ToString()); //edit by hufeng0813w 2014/06/16 pMasterListT.Add(pmT); } else { PriceMaster priceMa = pMaster.Clone() as PriceMaster; priceMa.price_master_id = uint.Parse(rowData.price_master_id.ToString()); priceMa.product_name = rowData.Product_Name; priceMa.child_id = int.Parse(c.Key.ToString()); priceMa.price = int.Parse(c.FirstOrDefault().item_money.ToString()); priceMa.max_price = int.Parse(c.FirstOrDefault().item_money.ToString()); //edit by hufeng0813w 2014/06/16 Reason:規格不同價時子商品也需要cost,event_cost,event_money priceMa.max_event_price = int.Parse(c.FirstOrDefault().event_money.ToString()); priceMa.cost = int.Parse(c.FirstOrDefault().item_cost.ToString()); priceMa.event_price = int.Parse(c.FirstOrDefault().event_money.ToString()); priceMa.event_cost = int.Parse(c.FirstOrDefault().event_cost.ToString()); //edit by hufeng0813w 2014/06/16 pMasterList.Add(priceMa); } c.ToList().ForEach(row => { //生成item_price ItemPrice iP = new ItemPrice(); iP.item_id = row.item_id; iP.item_money = row.item_money; iP.item_cost = row.item_cost; iP.event_money = row.event_money; iP.event_cost = row.event_cost; iP.item_price_id = row.item_price_id; iP.price_master_id = row.price_master_id; differentPrice.Add(iP); update.Add(iP); }); ItemPList.Add(differentPrice); }); } }); } //為保證ItemPList.Count=pMasterListT.Count ItemPList.Add(null); }
public HttpResponseBase vaiteVerifyPass() { string resultStr = "{success:false}"; bool result = true; try { Caller _caller = (Session["caller"] as Caller); _applyMgr = new ProductStatusApplyMgr(connectionString); _statusHistoryMgr = new ProductStatusHistoryMgr(connectionString); _prodMgr = new ProductMgr(connectionString); _pMaster = new PriceMasterMgr(connectionString); _tableHistoryMgr = new TableHistoryMgr(connectionString); string productIds = Request.Params["prodcutIdStr"]; string[] products = productIds.Split(','); _functionMgr = new FunctionMgr(connectionString); string function = Request.Params["function"] ?? ""; Function fun = _functionMgr.QueryFunction(function, "/ProductList/VerifyList"); int functionid = fun == null ? 0 : fun.RowId; HistoryBatch batch = new HistoryBatch { functionid = functionid, kuser = (Session["caller"] as Caller).user_email }; string batchNo = CommonFunction.GetPHPTime().ToString() + "_" + (Session["caller"] as Caller).user_id + "_"; foreach (string item in products) { Product product = _prodMgr.Query(new Product { Product_Id = uint.Parse(item) }).FirstOrDefault(); ArrayList sqls = new ArrayList(); if (_applyMgr.Query(new ProductStatusApply { product_id = uint.Parse(item) }) != null) { batch.batchno = batchNo + product.Product_Id; //更改商品价格之状态 PriceMaster pmQuery = new PriceMaster(); if (product.Combination != 0 && product.Combination != 1) //组合商品 { pmQuery.child_id = int.Parse(item); } else { pmQuery.child_id = 0; } pmQuery.product_id = uint.Parse(item); pmQuery.price_status = 2; //只更改价格状态为申请审核的商品价格 List<PriceMaster> pmResultList = _pMaster.PriceMasterQuery(pmQuery); if (pmResultList != null && pmResultList.Count() > 0) { _pHMgr = new PriceUpdateApplyHistoryMgr(connectionString); List<PriceUpdateApplyHistory> pHList = new List<PriceUpdateApplyHistory>(); foreach (var pm in pmResultList) { ArrayList priceUpdateSqls = new ArrayList(); pm.price_status = 1; //价格状态为上架 pm.apply_id = 0; priceUpdateSqls.Add(_pMaster.Update(pm)); if (!_tableHistoryMgr.SaveHistory<PriceMaster>(pm, batch, priceUpdateSqls)) { result = false; break; } //价格异动记录(price_update_apply_history) PriceUpdateApplyHistory pH = new PriceUpdateApplyHistory(); pH.apply_id = int.Parse(pm.apply_id.ToString()); pH.user_id = (Session["caller"] as Caller).user_id; pH.price_status = 1; pH.type = 1; pHList.Add(pH); } if (!_pHMgr.Save(pHList)) { result = false; break; } } //更改商品之状态 ProductStatusApply queryApply = _applyMgr.Query(new ProductStatusApply { product_id = uint.Parse(item) }); uint online_mode = queryApply.online_mode; //申請狀態為審核後立即上架時將上架時間改為當前時間,商品狀態改為上架 if (online_mode == 2) { product.Product_Status = 5; product.Product_Start = uint.Parse(BLL.gigade.Common.CommonFunction.GetPHPTime(DateTime.Now.ToLongTimeString()).ToString()); } else { product.Product_Status = 2; //product.Product_Start = online_mode; } sqls.Add(_prodMgr.Update(product, _caller.user_id)); ProductStatusHistory save = new ProductStatusHistory(); save.product_id = product.Product_Id; save.user_id = uint.Parse(_caller.user_id.ToString()); save.type = 2; //操作類型(核可) save.product_status = int.Parse(product.Product_Status.ToString()); sqls.Add(_statusHistoryMgr.Save(save)); //保存历史记录 sqls.Add(_applyMgr.Delete(queryApply)); //刪除審核申請表中的數據 if (!_tableHistoryMgr.SaveHistory<Product>(product, batch, sqls)) { result = false; break; } } else { result = false; break; } } resultStr = "{success:" + result.ToString().ToLower() + "}"; } 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); } Response.Clear(); Response.Write(resultStr); Response.End(); return this.Response; }
/// <summary> /// 查詢自各定價 /// </summary> /// <param name="query"></param> /// <returns></returns> public List<PriceMaster> QuerySelf(PriceMaster query) { string sqlStr = string.Format(@"select * from price_master pm1 inner join price_master pm2 on pm1.product_id =pm2.product_id and pm1.site_id=pm2.site_id and pm1.user_level=pm2.user_level and pm1.user_id=pm2.user_id where pm2.price_master_id={0}", query.price_master_id); return _dbAccess.getDataTableForObj<Model.PriceMaster>(sqlStr); }
//add by wwei0216 2015/3/4 用來判斷商品的價格狀態是否為0 public bool EstimatePrice(PriceMaster p) { if (p == null) return false; Int64 now = Common.CommonFunction.GetPHPTime(DateTime.Now.ToString()); if (p.same_price == 1) { if (p.price != 0) { //如果當前時間小於開始時間,或者當前時間大於結束時間,證明不在活動區間內 if (now < p.event_start || now > p.event_end) { return false; } else { if (p.event_price != 0) { return false; } } } } else { IItemPriceImplMgr _piMgr = new ItemPriceMgr(connectionStr); List<ItemPrice> ipItem = _piMgr.GetItem(Convert.ToInt32(p.product_id)); //查找ipItem中item_money不等於0的 if (ipItem.FindAll(m => m.item_money != 0).Count > 0) { //如果當前時間小於開始時間,或者當前時間大於結束時間,證明不在活動區間內 if (now < p.event_start || now > p.event_end) { return false; } else { if (ipItem.FindAll(m => m.event_money != 0).Count > 0) { return false; } } } } return true; }
public string SelectChild(PriceMaster priceMaster) { try { StringBuilder strSql = new StringBuilder("select price_master_id,product_id,child_id from price_master where "); strSql.AppendFormat("product_id = {0} and site_id=1 and user_level=1 and user_id=0 ", priceMaster.product_id); return strSql.ToString(); } catch (Exception ex) { throw new Exception("PriceMasterDao.SelectChild-->" + ex.Message, ex); } }
//add by wwei0216w 2015/1/28 /// <summary> /// 查詢商品的Status信息 /// </summary> /// <param name="p">查詢條件</param> /// <returns>List<ProductCustom>集合</returns> public Product UpdateSaleStatus(uint porductId) { if (porductId == 0) return null; List<Product> prods; List<ProductItem> prodItems; PriceMaster gigaPriceMaster = new PriceMaster(); Int64 dateTime = Common.CommonFunction.GetPHPTime(DateTime.Now.ToString()); //獲得當前時間戳 ITableHistoryImplMgr _tableHistoryMgr = new TableHistoryMgr(connectionStr); ProductCustom product = _productDao.QueryProductInfo(porductId, out prods, out prodItems, out gigaPriceMaster);//查找單一商,子項庫存是否有為0 if (gigaPriceMaster == null) { gigaPriceMaster = new PriceMaster(); }; gigaPriceMaster.product_id = porductId; if (product == null) return product; try { if (product.Vendor_Status == 2) //供應商下架 { product.Sale_Status = 24; } else if (product.Brand_Status == 2) //品牌下架 { product.Sale_Status = 25; } else if (product.Product_Status != 5) //商品未上架 { product.Sale_Status = 21; } else if (product.Product_Start > dateTime || dateTime > product.Product_End) //上架時間未滿足 { product.Sale_Status = 22; } else if (product.Price_Status != 1 || EstimatePrice(gigaPriceMaster)) //價格未審核,或價格==0 { product.Sale_Status = 23; } else if (product.Shortage == 1) //商品停賣 { product.Sale_Status = 11; } else if (product.Ignore_Stock == 0 && prodItems.Count > 0) //庫存不足 { product.Sale_Status = 12; } else { if (product.Combination != 1 && prods != null) //非單一商品 { List<Product> li = prods.FindAll(m => m.Sale_Status == 11); //查詢該組合商品的子商品中是否有販售狀態等於停賣(11)的 List<Product> li2 = prods.FindAll(m => m.Sale_Status == 12);//查詢該組合商品的子商品中是否有販售狀態等於庫存不足(12)的 if (li.Count > 0) //子商品停賣(組合商品用) { product.Sale_Status = 13; } else if (li2.Count > 0)//子商品庫存不足(組合商品用) { product.Sale_Status = 14; } } else { product.Sale_Status = 0; } } } catch (Exception ex) { throw new Exception("ProductMgr-->QuerySaleStatus" + ex.Message, ex); } return product; }
/// <summary> /// 根據商品id、站點id、會員等級、用戶id查詢price_master_id /// </summary> /// <param name="query"></param> /// <returns></returns> public uint QueryPriceMasterId(PriceMaster query) { query.Replace4MySQL(); string strSql = string.Format("select price_master_id from price_master where product_id={0} and site_id={1} and user_level={2} and user_id={3} ", query.product_id, query.site_id, query.user_level, query.user_id); if (_dbAccess.getSinggleObj<PriceMaster>(strSql) != null) //edit by wangwei0216w 2014/08/06 (增加對_dbAccess.getSinggleObj<PriceMaster>(strSql)是否為空的判斷,以解決匯入失敗的情況) { uint price_master_id = _dbAccess.getSinggleObj<PriceMaster>(strSql).price_master_id; return price_master_id; } else { return 0; } }
/// <summary> /// 合作外站商品查詢 /// </summary> /// <returns></returns> public HttpResponseBase OrderInfoQueryByCooperator() { string jsonStr = "{success:false}"; string pid = Request.Params["pid"] ?? ""; uint channelId = 0; UInt32.TryParse(Request.Params["channelId"] ?? "0", out channelId); if (!string.IsNullOrEmpty(pid)) { IProductItemMapImplMgr _pMapMgr = new ProductItemMapMgr(connectionString); IProductItemImplMgr _proItemMgr = new ProductItemMgr(connectionString); try { ProductItemMap pMap = new ProductItemMap(); pMap.channel_detail_id = pid; pMap.channel_id = channelId; List<ProductItemMap> pMapList = _pMapMgr.QueryAll(pMap); IPriceMasterImplMgr priceMgr = new PriceMasterMgr(connectionString); IProductItemImplMgr _itemMgr = new ProductItemMgr(connectionString); PriceMaster priceMap = priceMgr.QueryPriceMaster(new PriceMaster { price_master_id = pMapList.FirstOrDefault().price_master_id }); if (pMapList.Count() == 0) { jsonStr = "{success:false}"; this.Response.Clear(); this.Response.Write(jsonStr); this.Response.End(); return this.Response; } uint product_id = pMapList[0].product_id; if (product_id == 0) { product_id = _itemMgr.Query(new ProductItem { Item_Id = uint.Parse(pMapList[0].item_id.ToString()) }).FirstOrDefault().Product_Id; } IProductImplMgr _proMgr = new ProductMgr(connectionString); Product prod = _proMgr.Query(new Product { Product_Id = product_id }).FirstOrDefault(); //判断商品是否上架 // long ltime = BLL.gigade.Common.CommonFunction.GetPHPTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); if (prod.Combination != 1 && prod.Combination != 0) { OrderComboAddCustom orderAdd = _proMgr.OrderQuery(new Product { Product_Id = product_id }, priceMap.user_level, priceMap.user_id, priceMap.site_id); orderAdd.product_id = 0; orderAdd.out_product_id = pMapList[0].channel_detail_id; orderAdd.product_name = pMapList[0].product_name; orderAdd.product_cost = pMapList[0].product_price; jsonStr = "{success:true"; string price_scale = "", cost_scale = ""; //查詢子商品信息 _prodCombMgr = new ProductComboMgr(connectionString); List<ProductComboCustom> prodComList = _prodCombMgr.combQuery(new ProductComboCustom { Parent_Id = int.Parse(product_id.ToString()) }); IPriceMasterImplMgr pMgr = new PriceMasterMgr(connectionString); PriceMaster query = new PriceMaster { user_id = priceMap.user_id, user_level = priceMap.user_level, site_id = priceMap.site_id }; jsonStr += ",child:["; double childTotalPrice = 0; double childTotalCost = 0; string[] itemList = pMapList[0].group_item_id.ToString().Split(','); foreach (var item in prodComList) { #region 計算子商品總價 for (int i = 0; i < itemList.Length; i++) { //在item_price中查找該itemid對應的價格 IItemPriceImplMgr iPMgr = new ItemPriceMgr(connectionString); if (prod.Price_type == 1) { query.product_id = uint.Parse(item.Child_Id.ToString()); query.child_id = 0; } else if (prod.Price_type == 2) { query.product_id = prod.Product_Id; query.child_id = int.Parse(item.Child_Id.ToString()); } PriceMaster pM = priceMgr.QueryPriceMaster(query); List<ItemPriceCustom> ipList = new List<ItemPriceCustom>(); //查詢子商品詳細信息(規格,庫存) ProductItem pItem = new ProductItem(); pItem.Item_Id = uint.Parse(itemList[i]); pItem.Product_Id = uint.Parse(item.Child_Id.ToString()); List<ProductItem> pItemList = _proItemMgr.Query(pItem); if (pM != null && pItemList.Count > 0) { //查找外站商品必購數量 IProductMapSetImplMgr msMgr = new ProductMapSetMgr(connectionString); List<ProductMapSet> mSetList = msMgr.Query(new ProductMapSet { map_rid = uint.Parse(pMapList[0].rid.ToString()), item_id = uint.Parse(itemList[i]) }); if (pM.same_price == 1) { childTotalPrice += int.Parse((pM.price * mSetList[0].set_num).ToString()); childTotalCost += int.Parse((pM.cost * mSetList[0].set_num).ToString()); } else { ipList = iPMgr.Query(new ItemPrice { item_id = uint.Parse(itemList[i]), price_master_id = pM.price_master_id }); if (ipList.Count != 0) { if (mSetList.Count == 1) { childTotalPrice += int.Parse((ipList[0].item_money * mSetList[0].set_num).ToString()); childTotalCost += int.Parse((ipList[0].item_cost * mSetList[0].set_num).ToString()); } else { //在item_price中未查出對應價格 this.Response.Clear(); this.Response.Write("{success:false,msg:'" + Resources.OrderAdd.COMBO_CHILD_PRICE_NULL + "'}"); this.Response.End(); return this.Response; } } } } } #endregion } double beforePrice = 0; double beforeCost = 0; int minStock = 0; int index = 0; double comboPrice = orderAdd.product_cost; int curIndex = 0; foreach (var item in prodComList) { curIndex++; OrderAddCustom oc = new OrderAddCustom(); List<Product> pList = _proMgr.Query(new Product { Product_Id = uint.Parse(item.Child_Id.ToString()) }); oc.price_type = prod.Price_type; oc.Product_Id = uint.Parse(item.Child_Id.ToString()); oc.ignore_stock = pList[0].Ignore_Stock; oc.newparent_id = pMapList[0].channel_detail_id; //補貨中是否還能販賣 if (pList.FirstOrDefault().Shortage == 1) { this.Response.Clear(); this.Response.Write("{success:false,msg:'" + Resources.OrderAdd.SHPRT_AGE + "'}"); this.Response.End(); return this.Response; } //讀取product_name if (prod.Price_type == 1) { query.product_id = oc.Product_Id; query.child_id = 0; } else if (prod.Price_type == 2) { query.product_id = prod.Product_Id; query.child_id = Convert.ToInt32(oc.Product_Id); } PriceMaster pm = pMgr.QueryPriceMaster(query); if (pm != null) { oc.product_name = pm.product_name; } for (int i = 0; i < itemList.Length; i++) { //查詢子商品詳細信息(規格,庫存) ProductItem pItem = new ProductItem(); pItem.Item_Id = uint.Parse(itemList[i]); pItem.Product_Id = uint.Parse(item.Child_Id.ToString()); oc.Item_Id = pItem.Item_Id; List<ProductItem> pItemList = _proItemMgr.Query(pItem); if (pItemList.Count() != 0) { index++; //在item_price中查找該itemid對應的價格 IItemPriceImplMgr iPMgr = new ItemPriceMgr(connectionString); List<ItemPriceCustom> ipList = new List<ItemPriceCustom>(); if (pm != null) { oc.price_master_id = pm.price_master_id; //查找外站商品必購數量 IProductMapSetImplMgr msMgr = new ProductMapSetMgr(connectionString); List<ProductMapSet> mSetList = msMgr.Query(new ProductMapSet { map_rid = uint.Parse(pMapList[0].rid.ToString()), item_id = uint.Parse(itemList[i]) }); if (mSetList.Count != 0) { oc.s_must_buy = int.Parse(mSetList[0].set_num.ToString()); } if (prod.Price_type == 1) { #region 按比例拆分 if (i == itemList.Length - 1 && curIndex == prodComList.Count) { oc.product_cost = uint.Parse(CommonFunction.Math4Cut5Plus((orderAdd.product_cost - beforePrice) / oc.s_must_buy).ToString()); oc.Item_Cost = uint.Parse(CommonFunction.Math4Cut5Plus((orderAdd.cost - beforeCost) / oc.s_must_buy).ToString()); } else { double price = 0.0; double cost = 0.0; string price_res = "0"; string cost_res = "0"; double price_result = 0.0; double cost_result = 0.0; //规格同价 if (pm.same_price == 1) { if (childTotalPrice != 0) { double singlePrice = double.Parse((pm.price * oc.s_must_buy).ToString()); double totalPrice = childTotalPrice; double c_scale = singlePrice / totalPrice; price = orderAdd.product_cost * c_scale / oc.s_must_buy; price_result = CommonFunction.Math4Cut5Plus(price); price_res = c_scale.ToString(); } beforePrice += price_result; oc.product_cost = uint.Parse(price_result.ToString()); price_scale += price_res + ","; if (childTotalCost != 0) { double singleCost = double.Parse((pm.cost * oc.s_must_buy).ToString()); double totalCost = childTotalCost; double c_scale = singleCost / totalCost; cost = orderAdd.cost * c_scale / oc.s_must_buy; cost_result = CommonFunction.Math4Cut5Plus(cost); cost_res = c_scale.ToString(); } beforeCost += cost_result; oc.Item_Cost = uint.Parse(cost_result.ToString()); cost_scale += cost_res + ","; } else { ipList = iPMgr.Query(new ItemPrice { item_id = uint.Parse(itemList[i]), price_master_id = pm.price_master_id }); if (ipList.Count != 0) { if (childTotalPrice != 0) { double singlePrice = double.Parse((ipList[0].item_money * oc.s_must_buy).ToString()); double totalPrice = childTotalPrice; double c_scale = singlePrice / totalPrice; price = orderAdd.product_cost * c_scale / oc.s_must_buy; price_result = CommonFunction.Math4Cut5Plus(price); price_res = c_scale.ToString(); } beforePrice += price_result; oc.product_cost = uint.Parse(price_result.ToString()); price_scale += price_res + ","; if (childTotalCost != 0) { double singleCost = double.Parse((ipList[0].item_cost * oc.s_must_buy).ToString()); double totalCost = childTotalCost; double c_scale = singleCost / totalCost; cost = orderAdd.cost * c_scale / oc.s_must_buy; cost_result = CommonFunction.Math4Cut5Plus(cost); cost_res = c_scale.ToString(); } beforeCost += cost_result; oc.Item_Cost = uint.Parse(cost_result.ToString()); cost_scale += cost_res + ","; } } } #endregion } else if (prod.Price_type == 2) { #region 各自定價 ipList = iPMgr.Query(new ItemPrice { item_id = uint.Parse(itemList[i]), price_master_id = pm.price_master_id }); if (ipList.FirstOrDefault() != null) { oc.product_cost = ipList.FirstOrDefault().item_money; } #endregion } } if (index == 1) { minStock = oc.s_must_buy > 0 ? Convert.ToInt32(pItemList[0].Item_Stock / oc.s_must_buy) : pItemList[0].Item_Stock; } oc.Item_Stock = pItemList[0].Item_Stock; int tmp_stock = oc.s_must_buy > 0 ? Convert.ToInt32(oc.Item_Stock / oc.s_must_buy) : oc.Item_Stock; if (tmp_stock < minStock) { minStock = tmp_stock; } //根據spec_id找出spec_name IProductSpecImplMgr _specMgr = new BLL.gigade.Mgr.ProductSpecMgr(connectionString); ProductSpec ps1 = _specMgr.query(int.Parse(pItemList[0].Spec_Id_1.ToString())); if (ps1 != null) { oc.Spec_Name_1 = ps1.spec_name; oc.Spec_Id_1 = ps1.spec_id; } ProductSpec ps2 = _specMgr.query(int.Parse(pItemList[0].Spec_Id_2.ToString())); if (ps2 != null) { oc.Spec_Name_2 = ps2.spec_name; oc.Spec_Id_2 = ps2.spec_id; } jsonStr += "{"; jsonStr += "'product_id':'" + oc.Product_Id + "','product_name':'" + oc.product_name + "','item_id':'" + oc.Item_Id + "'"; jsonStr += ",'spec1':'" + oc.Spec_Id_1 + "','spec2':'" + oc.Spec_Id_2 + "','spec1_show':'" + oc.Spec_Name_1 + "',s_must_buy:'" + oc.s_must_buy + "'"; jsonStr += ",'spec2_show':'" + oc.Spec_Name_2 + "','product_cost':'" + oc.product_cost + "',Item_Cost:'" + oc.Item_Cost + "','stock':'" + oc.Item_Stock + "',price_master_id:" + oc.price_master_id; jsonStr += ",price_type:" + oc.price_type + ",ignore_stock:" + oc.ignore_stock; if (oc.parent_id != 0) { jsonStr += ",parent_id:'" + oc.parent_id + "'"; } else { jsonStr += ",parent_id:'" + oc.newparent_id + "'"; } jsonStr += "},"; } } } if (price_scale != "") { price_scale = price_scale.Substring(0, price_scale.Length - 1); } jsonStr = jsonStr.Substring(0, jsonStr.Length - 1) + "]"; jsonStr += ",data:["; jsonStr += "{product_id:'" + orderAdd.out_product_id + "',item_id:0,product_name:'" + orderAdd.product_name + "',product_cost:'" + orderAdd.product_cost + "'"; jsonStr += ",s_must_buy:'" + pMapList[0].group_item_id.ToString().Split(',').Length + "',Item_Cost:'" + orderAdd.cost + "',child_cost_scale:'" + cost_scale + "',child_scale:'" + price_scale + "',stock:'" + minStock + "',g_must_buy:'" + pMapList[0].group_item_id.ToString().Split(',').Length + "'}]}"; } else { if (prod.Combination == 0) { jsonStr = "{success:false,msg:\"" + Resources.OrderAdd.PRODUCT_NOT_USE_IN_ORDER + "\"}"; this.Response.Clear(); this.Response.Write(jsonStr); this.Response.End(); return this.Response; } else { //單一商品 ProductItem pItem = new ProductItem(); pItem.Item_Id = UInt32.Parse(pMapList[0].item_id.ToString()); List<ProductItem> pItemList = _proItemMgr.Query(pItem); List<Product> pList = _proMgr.Query(new Product { Product_Id = uint.Parse(pItemList[0].Product_Id.ToString()) }); //補貨時還能販賣 if (pList[0].Shortage == 1) { this.Response.Clear(); this.Response.Write("{success:false,msg:'" + Resources.OrderAdd.SHPRT_AGE + "'}"); this.Response.End(); return this.Response; } if (pItemList.Count() == 0) { jsonStr = "{success:false}"; this.Response.Clear(); this.Response.Write(jsonStr); this.Response.End(); return this.Response; } List<OrderAddCustom> oalist = new List<OrderAddCustom>(); OrderAddCustom oc = new OrderAddCustom(); oc.Spec_Id_1 = pItemList[0].Spec_Id_1; oc.Spec_Id_2 = pItemList[0].Spec_Id_2; oc.Item_Stock = pItemList[0].Item_Stock; oc.ignore_stock = pList[0].Ignore_Stock; IProductSpecImplMgr _specMgr = new BLL.gigade.Mgr.ProductSpecMgr(connectionString); ProductSpec spec1 = _specMgr.query(Convert.ToInt32(pItemList[0].Spec_Id_1)); ProductSpec spec2 = _specMgr.query(Convert.ToInt32(pItemList[0].Spec_Id_2)); if (spec1 != null) { oc.Spec_Name_1 = spec1.spec_name; } if (spec2 != null) { oc.Spec_Name_2 = spec2.spec_name; } oalist.Add(oc); StringBuilder stb = new StringBuilder(); stb.Append("["); stb.Append("{product_id:'" + pMapList[0].channel_detail_id + "',item_id:" + pMapList[0].item_id + ",product_name:'" + HttpUtility.HtmlEncode(pMapList[0].product_name) + "',spec1:'" + oc.Spec_Id_1.ToString() + "',"); stb.Append("spec2:'" + oc.Spec_Id_2.ToString() + "',spec1_show:'" + oc.Spec_Name_1 + "',spec2_show:'" + oc.Spec_Name_2 + "',product_cost:" + pMapList[0].product_price + ","); stb.Append("stock:" + oc.Item_Stock + ",price_master_id:" + oc.price_master_id + ",ignore_stock:" + oc.ignore_stock + "}"); stb.Append("]"); jsonStr = "{success:true,data:" + stb.ToString() + "}"; } } } 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); } } else { jsonStr = "{success:true,data:{product_id:''}}"; } this.Response.Clear(); this.Response.Write(jsonStr); this.Response.End(); return this.Response; }