public HttpResponseBase specTempSave() { string resultStr = "{success:true}"; bool result = true; try { Caller _caller = (Session["caller"] as Caller); string specType = Request.Params["specType"]; string spec1Name = Request.Params["spec1Name"]; string spec1Result = Request.Params["spec1Result"]; string spec2Name = ""; string spec2Result; _specMgr = new ProductSpecMgr(connectionString); _specTempMgr = new ProductSpecTempMgr(connectionString); _productTempMgr = new ProductTempMgr(connectionString); _productItemMgr = new ProductItemMgr(connectionString); _productItemTempMgr = new ProductItemTempMgr(connectionString); _serialMgr = new SerialMgr(connectionString); if (!string.IsNullOrEmpty(Request.Params["ProductId"])) { uint proId = uint.Parse(Request.Params["ProductId"]); _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; #region 正式表修改 List<ProductSpec> spec1List = null; List<ProductSpec> spec2List = null; List<ProductSpec> specUpdateList = new List<ProductSpec>(); List<ProductSpec> specAddList = new List<ProductSpec>(); JavaScriptSerializer jss = new JavaScriptSerializer(); spec1List = jss.Deserialize<List<ProductSpec>>(spec1Result); if (spec1List != null) { //規格一處理 spec1List.ForEach(m => { m.product_id = proId; m.spec_type = 1; if (m.spec_id != 0) { specUpdateList.Add(m); } else { specAddList.Add(m); } }); } //規格二處理 if (specType.Equals("2")) { spec2Name = Request.Params["spec2Name"]; spec2Result = Request.Params["spec2Result"]; spec2List = jss.Deserialize<List<ProductSpec>>(spec2Result); spec2List.ForEach(m => { m.product_id = proId; m.spec_type = 2; if (m.spec_id != 0) { specUpdateList.Add(m); } else { specAddList.Add(m); } }); } Product proModel = new Product(); _productMgr = new ProductMgr(connectionString); _tableHistoryMgr = new TableHistoryMgr(connectionString); proModel = _productMgr.Query(new Product { Product_Id = proId }).FirstOrDefault(); proModel.Spec_Title_1 = spec1Name; proModel.Spec_Title_2 = spec2Name; if (specUpdateList.Count() > 0) { for (int i = 0, j = specUpdateList.Count(); i < j; i++) { ArrayList sqls = new ArrayList(); sqls.Add(_specMgr.Update(specUpdateList[i])); if (i == 0) { sqls.Add(_productMgr.Update(proModel)); } if (!_tableHistoryMgr.SaveHistory<ProductSpec>(specUpdateList[i], batch, sqls)) { result = false; } } } if (specAddList.Count() > 0) { List<ProductItem> saveItemList = new List<ProductItem>(); List<ProductSpec> spec1ExistList = spec1List.Where(m => m.spec_id != 0).ToList(); //規格一中原本就存在的規格 specAddList.ForEach(p => p.spec_id = uint.Parse(_serialMgr.NextSerial(18).ToString())); ProductItem saveTemp; List<PriceMaster> list_price = new List<PriceMaster>(); PriceMasterMgr pm = new PriceMasterMgr(connectionString); list_price = pm.GetPriceMasterInfoByID2(proId.ToString());//獲取同一個ID下其他產品的價格信息 PriceMaster _p = list_price.FirstOrDefault();//add by wangwei0216w 2014/9/19 獲取同一個ID下其他產品的信息 //List<ProductItem> pro_list = new List<ProductItem>(); //ProductItemMgr pig = new ProductItemMgr(connectionString); //pro_list = pig.GetProductItemByID(Convert.ToInt32(proId)); //ProductItem _product = pro_list.FirstOrDefault();//獲取同一個ID下其他產品的信息 foreach (var m in specAddList) { if (specType.Equals("1")) { if (m.spec_type == 1) { saveTemp = new ProductItem(); if (_p.same_price == 1) //add by wangwei 0216w 2014/9/19 如果同價 就將價格賦予新增規格 { //saveTemp.Item_Cost = Convert.ToUInt32(_p.cost); //saveTemp.Item_Money = Convert.ToUInt32(_p.price); } else { resultStr = "{success:true,Msg:true}"; } saveTemp.Spec_Id_1 = m.spec_id; saveTemp.Product_Id = proId; // saveTemp.Item_Stock = 10; saveTemp.Item_Alarm = 1; saveItemList.Add(saveTemp); } else { saveTemp = new ProductItem(); if (_p.same_price == 1) //add by wangwei 0216w 2014/9/19 如果同價 就將價格賦予新增規格 { //saveTemp.Item_Cost = Convert.ToUInt32(_p.cost); //saveTemp.Item_Money = Convert.ToUInt32(_p.price); } else { resultStr = "{success:true,Msg:true}"; } saveTemp.Spec_Id_2 = m.spec_id; saveTemp.Product_Id = proId; //saveTemp.Item_Stock = 10; saveTemp.Item_Alarm = 1; saveItemList.Add(saveTemp); } } else { if (m.spec_type == 1) { foreach (ProductSpec item in spec2List) { saveTemp = new ProductItem(); if (_p.same_price == 1) //add by wangwei 0216w 2014/9/19 如果同價 就將價格賦予新增規格 { //saveTemp.Item_Cost = Convert.ToUInt32(_p.cost); //saveTemp.Item_Money = Convert.ToUInt32(_p.price); } else { resultStr = "{success:true,Msg:true}"; } saveTemp.Spec_Id_1 = m.spec_id; saveTemp.Spec_Id_2 = item.spec_id; //saveTemp.Item_Stock = 10; saveTemp.Item_Alarm = 1; saveTemp.Product_Id = proId; saveItemList.Add(saveTemp); } } else { foreach (ProductSpec item2 in spec1ExistList) { saveTemp = new ProductItem(); if (_p.same_price == 1) //add by wangwei 0216w 2014/9/19 如果同價 就將價格賦予新增規格 { //saveTemp.Item_Cost = Convert.ToUInt32(_p.cost); //saveTemp.Item_Money = Convert.ToUInt32(_p.price); } else { resultStr = "{success:true,Msg:true}"; } saveTemp.Spec_Id_1 = item2.spec_id; saveTemp.Spec_Id_2 = m.spec_id; //saveTemp.Item_Stock = 10; saveTemp.Item_Alarm = 1; saveTemp.Product_Id = proId; saveItemList.Add(saveTemp); } } } } _specMgr.Save(specAddList); _productItemMgr.Save(saveItemList); ProductItem pro; if (proModel.Product_Status != 0) //add by wangwei0216w 2014/9/18 作用:將Export_flag的值設置為1 { pro = new ProductItem() { Product_Id = proModel.Product_Id, Export_flag = 1 }; _productItemMgr.UpdateExportFlag(pro); } if (result) //如果之前保存規格,插入臨時表登操作有誤,則不執行插入itemprice的操作 { List<ProductItem> item_list = _productItemMgr.GetProductNewItem_ID(Convert.ToInt32(proModel.Product_Id)); //得到product_item的新增ID ItemPrice i = new ItemPrice(); ItemPriceMgr ipm = new ItemPriceMgr(connectionString); ArrayList liststr = new ArrayList(); foreach (PriceMaster p in list_price) { foreach (ProductItem pi in item_list) { if (p.same_price == 1) { i.price_master_id = p.price_master_id; i.item_id = pi.Item_Id; i.item_money = Convert.ToUInt32(p.price); i.item_cost = Convert.ToUInt32(p.cost); i.event_cost = Convert.ToUInt32(p.event_cost); i.event_money = Convert.ToUInt32(p.event_price); } else { i.price_master_id = p.price_master_id; i.item_id = pi.Item_Id; i.item_money = 0; i.item_cost = 0; i.event_money = 0; i.event_cost = 0; resultStr = "{success:true,Msg:true}"; } liststr.Add(ipm.Save(i)); } } ipm.AddItemPricBySpec(liststr, connectionString); } } //若為單一商品,則把product_item.export_flag改為2 edit by xiangwang0413w 2014/06/30 //if (proModel.Combination == 1) //{ // _productItemMgr = new ProductItemMgr(connectionString); // ProductItem pro_Item = new ProductItem() { Product_Id = proModel.Product_Id, Export_flag = 2 }; // _productItemMgr.UpdateExportFlag(pro_Item); //} #endregion } else { #region 臨時表修改 _productTempMgr = new ProductTempMgr(connectionString); //add by xiangwang 2014.09.26 可修改庫存預設值為99 string product_id = "0"; if (!string.IsNullOrEmpty(Request.Form["OldProductId"])) { product_id = Request.Form["OldProductId"]; } //add by xiangwang 2014.09.26 可修改庫存預設值為99 ProductTemp query = _productTempMgr.GetProTemp(new ProductTemp { Writer_Id = _caller.user_id, Combo_Type = COMBO_TYPE, Product_Id = product_id }); if (!specType.Equals("0") && !string.IsNullOrEmpty(specType)) { #region 有規格 List<ProductSpecTemp> spec1List; List<ProductSpecTemp> spec2List; List<ProductSpecTemp> specAllList = new List<ProductSpecTemp>(); JavaScriptSerializer jss = new JavaScriptSerializer(); spec1List = jss.Deserialize<List<ProductSpecTemp>>(spec1Result); foreach (ProductSpecTemp item in spec1List) { // specid = _serialMgr.NextSerial(18); //item.spec_id = uint.Parse(specid.ToString()); item.Writer_Id = _caller.user_id; item.product_id = product_id; item.spec_type = 1; item.spec_image = ""; specAllList.Add(item); } if (specType.Equals("2")) { spec2Name = Request.Params["spec2Name"]; spec2Result = Request.Params["spec2Result"]; spec2List = jss.Deserialize<List<ProductSpecTemp>>(spec2Result); foreach (ProductSpecTemp item in spec2List) { // specid = _serialMgr.NextSerial(18); //item.spec_id = uint.Parse(specid.ToString()); item.Writer_Id = _caller.user_id; item.product_id = product_id; item.spec_type = 2; item.spec_image = ""; specAllList.Add(item); } } List<ProductSpecTemp> tempList = _specTempMgr.Query(new ProductSpecTemp { Writer_Id = _caller.user_id, product_id = product_id }); if (tempList == null || tempList.Count() <= 0) { #region 保存 specAllList.ForEach(p => p.spec_id = uint.Parse(_serialMgr.NextSerial(18).ToString())); bool saveSpecResult = _specTempMgr.Save(specAllList); if (saveSpecResult) { _productItemTempMgr.Delete(new ProductItemTemp { Writer_Id = _caller.user_id, Product_Id = product_id }); #region 保存ProductItemTemp List<ProductSpecTemp> specAllResultList = _specTempMgr.Query(new ProductSpecTemp { Writer_Id = _caller.user_id, product_id = product_id }); List<ProductSpecTemp> spec1ResultList = specAllResultList.Where(m => m.spec_type == 1).ToList(); List<ProductSpecTemp> spec2ResultList = specAllResultList.Where(m => m.spec_type == 2).ToList(); List<ProductItemTemp> saveItemList = new List<ProductItemTemp>(); if (specType.Equals("1")) { foreach (ProductSpecTemp specTemp1 in spec1ResultList) { ProductItemTemp itemTemp = new ProductItemTemp(); itemTemp.Writer_Id = _caller.user_id; itemTemp.Product_Id = product_id; itemTemp.Spec_Id_1 = specTemp1.spec_id; //itemTemp.Item_Stock = 10; itemTemp.Item_Alarm = 1; saveItemList.Add(itemTemp); } } else if (specType.Equals("2")) { foreach (ProductSpecTemp specTemp1 in spec1ResultList) { foreach (ProductSpecTemp specTemp2 in spec2ResultList) { ProductItemTemp itemTemp = new ProductItemTemp(); itemTemp.Writer_Id = _caller.user_id; itemTemp.Product_Id = product_id; itemTemp.Spec_Id_1 = specTemp1.spec_id; itemTemp.Spec_Id_2 = specTemp2.spec_id; //itemTemp.Item_Stock = 10; itemTemp.Item_Alarm = 1; itemTemp.Item_Code = ""; itemTemp.Barcode = ""; saveItemList.Add(itemTemp); } } } //add by xiangwang 2014.09.26 可修改庫存預設值為99 //saveItemList.ForEach(m => m.SetDefaultItemStock(query)); bool saveItemResult = _productItemTempMgr.Save(saveItemList); if (!saveItemResult) { result = false; } #endregion } else { result = false; } #endregion } else { #region 更新 string strSpecInit = Request.Params["specInit"]; string[] specs = strSpecInit.Split(','); List<ProductSpecTemp> addList = specAllList.Where(p => p.spec_id == 0).ToList(); if (addList.Count() > 0) { addList.ForEach(p => p.spec_id = uint.Parse(_serialMgr.NextSerial(18).ToString())); List<ProductSpecTemp> specAllResultList = _specTempMgr.Query(new ProductSpecTemp { Writer_Id = _caller.user_id, product_id = product_id }); List<ProductSpecTemp> spec1ResultList = specAllResultList.Where(m => m.spec_type == 1).ToList(); List<ProductSpecTemp> spec2ResultList = specAllResultList.Where(m => m.spec_type == 2).ToList(); List<ProductItemTemp> saveItemList = new List<ProductItemTemp>(); foreach (ProductSpecTemp item in addList) { if (specType.Equals("1")) { if (item.spec_type == 1) { ProductItemTemp saveTemp = new ProductItemTemp(); saveTemp.Writer_Id = _caller.user_id; saveTemp.Spec_Id_1 = item.spec_id; saveTemp.Product_Id = product_id; //saveTemp.Item_Stock = 10; saveTemp.Item_Alarm = 1; saveItemList.Add(saveTemp); } else { ProductItemTemp saveTemp = new ProductItemTemp(); saveTemp.Writer_Id = _caller.user_id; saveTemp.Spec_Id_2 = item.spec_id; saveTemp.Product_Id = product_id; // saveTemp.Item_Stock = 10; saveTemp.Item_Alarm = 1; saveItemList.Add(saveTemp); } } else { if (item.spec_type == 1) { foreach (ProductSpecTemp item1 in spec2ResultList) { ProductItemTemp saveTemp = new ProductItemTemp(); saveTemp.Writer_Id = _caller.user_id; saveTemp.Spec_Id_1 = item.spec_id; saveTemp.Spec_Id_2 = item1.spec_id; //saveTemp.Item_Stock = 10; saveTemp.Item_Alarm = 1; saveTemp.Product_Id = product_id; saveItemList.Add(saveTemp); } foreach (ProductSpecTemp item1 in addList.Where(p => p.spec_type == 2).ToList()) { ProductItemTemp saveTemp = new ProductItemTemp(); saveTemp.Writer_Id = _caller.user_id; saveTemp.Spec_Id_1 = item.spec_id; saveTemp.Spec_Id_2 = item1.spec_id; //saveTemp.Item_Stock = 10; saveTemp.Item_Alarm = 1; saveTemp.Product_Id = product_id; saveItemList.Add(saveTemp); } } else { foreach (ProductSpecTemp item2 in spec1ResultList) { ProductItemTemp saveTemp = new ProductItemTemp(); saveTemp.Writer_Id = _caller.user_id; saveTemp.Spec_Id_1 = item2.spec_id; saveTemp.Spec_Id_2 = item.spec_id; saveTemp.Product_Id = product_id; // saveTemp.Item_Stock = 10; saveTemp.Item_Alarm = 1; saveItemList.Add(saveTemp); } } } } _specTempMgr.Save(addList); //add by xiangwang 2014.09.26 可修改庫存預設值為99 //saveItemList.ForEach(m => m.SetDefaultItemStock(query)); _productItemTempMgr.Save(saveItemList); } if (specs.Length > 0) { List<ProductSpecTemp> updateList = new List<ProductSpecTemp>(); foreach (string initSpecId in specs) { ProductSpecTemp nowItem = specAllList.Where(p => p.spec_id == uint.Parse(initSpecId)).FirstOrDefault(); if (nowItem != null) { updateList.Add(nowItem); } else { ProductItemTemp delTemp = new ProductItemTemp { Writer_Id = _caller.user_id, Product_Id = product_id }; uint spectype = _specTempMgr.Query(new ProductSpecTemp { spec_id = uint.Parse(initSpecId), product_id = product_id })[0].spec_type; if (spectype == 1) { delTemp.Spec_Id_1 = uint.Parse(initSpecId); } else if (spectype == 2) { delTemp.Spec_Id_2 = uint.Parse(initSpecId); } if (!_productItemTempMgr.Delete(delTemp)) { result = false; } if (!_specTempMgr.Delete(new ProductSpecTemp { spec_id = uint.Parse(initSpecId), Writer_Id = _caller.user_id, product_id = product_id })) { result = false; } DeletePicOnServer(false, true, false, uint.Parse(initSpecId), product_id); } } if (!_specTempMgr.Update(updateList, "spec")) { result = false; } } #endregion } #region 更新Product ProductTemp proTemp = new ProductTemp(); proTemp.Writer_Id = _caller.user_id; proTemp.Product_Spec = uint.Parse(specType); proTemp.Spec_Title_1 = spec1Name; proTemp.Spec_Title_2 = spec2Name; proTemp.Combo_Type = COMBO_TYPE; proTemp.Product_Id = product_id; bool saveProductResult = _productTempMgr.SpecInfoSave(proTemp); if (!saveProductResult) { result = false; } #endregion #endregion } else { #region 無規格 List<ProductItemTemp> saveList = new List<ProductItemTemp>(); //如果原數據有規格 if (query.Product_Spec != 0) { //刪除服務器上對應的圖片 DeletePicOnServer(false, true, false, 0, product_id); _productItemTempMgr.Delete(new ProductItemTemp { Writer_Id = _caller.user_id, Product_Id = product_id }); _specTempMgr.Delete(new ProductSpecTemp { Writer_Id = _caller.user_id, product_id = product_id }); _productTempMgr.SpecInfoSave(new ProductTemp { Product_Spec = 0, Spec_Title_1 = "", Spec_Title_2 = "", Writer_Id = _caller.user_id, Combo_Type = COMBO_TYPE, Product_Id = product_id }); saveList = new List<ProductItemTemp>(); saveList.Add(new ProductItemTemp { Writer_Id = _caller.user_id, Product_Id = product_id/*, Item_Stock = 10*/, Item_Alarm = 1 }); } else { List<ProductItemTemp> itemQuery = _productItemTempMgr.Query(new ProductItemTemp { Writer_Id = _caller.user_id, Product_Id = product_id }); if (itemQuery.Count() <= 0) { saveList = new List<ProductItemTemp>(); saveList.Add(new ProductItemTemp { Writer_Id = _caller.user_id, Product_Id = product_id, /*Item_Stock = 10,*/ Item_Alarm = 1 }); // _productItemTempMgr.Save(saveList); } } //add by xiangwang 2014.09.26 可修改庫存預設值為99 //saveList.ForEach(m => m.SetDefaultItemStock(query)); _productItemTempMgr.Save(saveList); #endregion } #endregion #region 調度或自出商品,商品庫存預設為99 var proditemTemp = new ProductItemTemp { Product_Id = product_id, Writer_Id = _caller.user_id }; proditemTemp.SetDefaultItemStock(query); _productItemTempMgr.UpdateItemStock(proditemTemp); #endregion } } catch (Exception ex) { result = false; 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); } if (!result) { resultStr = "{success:false,Msg:false}"; } this.Response.Clear(); this.Response.Write(resultStr); 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 bool AddProductExtentName(Caller caller) { try { string msg = string.Empty; var productExtent = peDao.QueryStart(); IPriceMasterImplMgr _priceMasterMgr = new PriceMasterMgr(connectionStr); List<PriceMaster> priceMasters = _priceMasterMgr.Query(productExtent.Select(p => p.Price_Master_Id).ToArray()); foreach (PriceMaster pm in priceMasters) { var item = productExtent.Find(m => m.Price_Master_Id == pm.price_master_id); pm.product_name = (item.Product_Prefix == "" ? "" : PriceMaster.L_HKH + item.Product_Prefix + PriceMaster.R_HKH) + pm.product_name + (item.Product_Suffix == "" ? "" : PriceMaster.L_HKH + item.Product_Suffix + PriceMaster.R_HKH); } if (_priceMasterMgr.UpdatePriceMasters(priceMasters, caller, out msg)) { productExtent.ForEach(p => { p.Apply_id = priceMasters.Find(m => m.price_master_id == p.Price_Master_Id).apply_id; p.Flag = 1;//待審核 }); return Update(productExtent); } return false; } catch (Exception ex) { throw new Exception("ProdNameExtendMgr.AddProductExtentName-->" + ex.Message, ex); } }
public bool CopyProduct(int writerId, int combo_type, string product_Id) { try { if (DeleteTemp(writerId, combo_type, product_Id)) { ArrayList sqls = new ArrayList(); var prodTemp = new ProductTemp { Writer_Id = writerId, Combo_Type = combo_type, Product_Id = product_Id, Create_Channel = 1 }; sqls.Add(SaveFromPro(prodTemp)); //add by xiangwang0413w 2014/11/06 ProductDeliverySetTempMgr proDelSetTempMgr = new ProductDeliverySetTempMgr(""); sqls.Add(proDelSetTempMgr.SaveFromProDeliverySet(new ProductDeliverySetTemp { Writer_Id = writerId, Combo_Type = combo_type, Product_id = int.Parse(product_Id) })); ProductNoticeSetTempMgr proNoticeSetTempMgr = new ProductNoticeSetTempMgr(""); sqls.Add(proNoticeSetTempMgr.SaveFromProNotice(new ProductNoticeSetTemp { Writer_Id = writerId, Combo_Type = combo_type, product_id = product_Id })); ProductTagSetTempMgr proTagSetTempMgr = new ProductTagSetTempMgr(""); sqls.Add(proTagSetTempMgr.SaveFromTag(new ProductTagSetTemp { Writer_Id = writerId, Combo_Type = combo_type, product_id = product_Id })); ProductPictureTempImplMgr proPicTempMgr = new ProductPictureTempImplMgr(""); sqls.Add(proPicTempMgr.SaveFromProPicture(new ProductPictureTemp { writer_Id = writerId, combo_type = combo_type, product_id = product_Id },1));//複製商品說明圖 sqls.Add(proPicTempMgr.SaveFromProPicture(new ProductPictureTemp { writer_Id = writerId, combo_type = combo_type, product_id = product_Id }, 2));//複製手機app圖 ProductCategorySetTempMgr proCateSetTempMgr = new ProductCategorySetTempMgr(""); sqls.Add(proCateSetTempMgr.SaveFromCategorySet(new ProductCategorySetTemp { Writer_Id = writerId, Combo_Type = combo_type, Product_Id = product_Id })); PriceMasterTempMgr priceMasterTempMgr = new PriceMasterTempMgr(""); ArrayList specs = new ArrayList(); if (combo_type == 1)//單一商品 { sqls.Add(priceMasterTempMgr.SaveFromPriceMaster(new PriceMasterTemp { writer_Id = writerId, product_id = product_Id, combo_type = combo_type })); //add by dongya 2015/08/25 添加信息到商品推薦臨時表 用來複製商品 RecommendedProductAttributeMgr recommendAttributeMgr = new RecommendedProductAttributeMgr(""); sqls.Add(recommendAttributeMgr.SaveRecommendedProductAttributSet(new RecommendedRroductAttributeTemp{write_id = writerId, product_id = UInt32.Parse(product_Id),combo_type=combo_type})); ProductItemTempMgr proItemTempMgr = new ProductItemTempMgr(""); var prodItemTemp = new ProductItemTemp { Writer_Id = writerId, Product_Id = product_Id }; sqls.Add(proItemTempMgr.SaveFromProItem(prodItemTemp)); ProductSpecMgr proSpecMgr = new ProductSpecMgr(connStr); List<ProductSpec> proSpecs = proSpecMgr.Query(new ProductSpec { product_id = uint.Parse(product_Id) }); if (proSpecs != null) { ProductSpecTempMgr proSpecTempMgr = new ProductSpecTempMgr(""); StringBuilder str; foreach (var item in proSpecs) { sqls.Add(proSpecTempMgr.SaveFromSpec(new ProductSpecTemp { Writer_Id = writerId, product_id = product_Id, spec_id = item.spec_id })); str = new StringBuilder(); str.Append(proSpecTempMgr.UpdateCopySpecId(new ProductSpecTemp { Writer_Id = writerId, product_id = product_Id, spec_id = item.spec_id })); str.Append(proItemTempMgr.UpdateCopySpecId(new ProductItemTemp { Writer_Id = writerId, Product_Id = product_Id, Spec_Id_1 = item.spec_id, Spec_Id_2 = item.spec_id })); specs.Add(str.ToString()); } } return _pTempDao.CopyProduct(sqls, specs, null, null, null); } else { PriceMasterMgr priceMasterMgr = new PriceMasterMgr(""); string selMaster = priceMasterMgr.SelectChild(new PriceMaster { product_id = uint.Parse(product_Id) }); string moveMaster = priceMasterTempMgr.SaveFromPriceMasterByMasterId(new PriceMasterTemp { combo_type = combo_type, writer_Id = writerId }); ItemPriceTempMgr itemPriceTempMgr = new ItemPriceTempMgr(""); string movePrice = itemPriceTempMgr.SaveFromItemPriceByMasterId(); //add by dongya 2015/08/25 添加信息到商品推薦臨時表 用來複製商品 RecommendedProductAttributeMgr recommendAttributeMgr = new RecommendedProductAttributeMgr(""); sqls.Add(recommendAttributeMgr.SaveRecommendedProductAttributSet(new RecommendedRroductAttributeTemp { write_id = writerId, product_id = UInt32.Parse(product_Id),combo_type=combo_type })); ProductComboTempMgr proComboTempMgr = new ProductComboTempMgr(""); sqls.Add(proComboTempMgr.SaveFromCombo(new ProductComboTemp { Writer_Id = writerId, Parent_Id = product_Id })); return _pTempDao.CopyProduct(sqls, specs, selMaster, moveMaster, movePrice); } } return false; } catch (Exception ex) { throw new Exception("ProductTempMgr.CopyProduct-->" + ex.Message, ex); } }
public bool VendorCopyProduct(int writerId, int combo_type, string old_product_Id, ref string product_id, string product_Ipfrom) { int Vendor_rid = 0; try { List<ProductTemp> copynumber = _pTempDao.GetProTempByVendor(new ProductTemp { Writer_Id = writerId, Combo_Type = combo_type, Create_Channel = 2, Temp_Status = 13 }); if (copynumber.Count != 0) { foreach (var item in copynumber) { DeleteVendorProductTemp(writerId, combo_type, item.Product_Id); } } ArrayList sqls = new ArrayList(); Vendor_rid = VendorSaveFromPro(new ProductTemp { Writer_Id = writerId, Combo_Type = combo_type, Product_Id = old_product_Id, Product_Ipfrom = product_Ipfrom, Product_Createdate = uint.Parse(Common.CommonFunction.GetPHPTime(DateTime.Now.ToString()).ToString()) }); product_id = "T" + Vendor_rid; ProductNoticeSetTempMgr proNoticeSetTempMgr = new ProductNoticeSetTempMgr(""); sqls.Add(proNoticeSetTempMgr.VendorSaveFromProNotice(new ProductNoticeSetTemp { Writer_Id = writerId, Combo_Type = combo_type, product_id = product_id }, old_product_Id)); ProductTagSetTempMgr proTagSetTempMgr = new ProductTagSetTempMgr(""); sqls.Add(proTagSetTempMgr.VendorSaveFromTag(new ProductTagSetTemp { Writer_Id = writerId, Combo_Type = combo_type, product_id = product_id }, old_product_Id)); ProductPictureTempImplMgr proPicTempMgr = new ProductPictureTempImplMgr(""); sqls.Add(proPicTempMgr.VendorSaveFromProPicture(new ProductPictureTemp { writer_Id = writerId, combo_type = combo_type, product_id = product_id }, old_product_Id)); ProductCategorySetTempMgr proCateSetTempMgr = new ProductCategorySetTempMgr(""); sqls.Add(proCateSetTempMgr.VendorSaveFromCategorySet(new ProductCategorySetTemp { Writer_Id = writerId, Combo_Type = combo_type, Product_Id = product_id }, old_product_Id)); PriceMasterTempMgr priceMasterTempMgr = new PriceMasterTempMgr(""); ArrayList specs = new ArrayList(); if (combo_type == 1)//單一商品 { sqls.Add(priceMasterTempMgr.VendorSaveFromPriceMaster(new PriceMasterTemp { writer_Id = writerId, product_id = product_id, combo_type = combo_type }, old_product_Id)); ProductItemTempMgr proItemTempMgr = new ProductItemTempMgr(""); sqls.Add(proItemTempMgr.VendorSaveFromProItem(new ProductItemTemp { Writer_Id = writerId, Product_Id = product_id }, old_product_Id)); //因為複製的是臨時表所以換成productspectemp ProductSpecTempMgr ProSpecTemp = new ProductSpecTempMgr(connStr); //查詢出要複製的商品裡面的規格是否為空 List<ProductSpecTemp> proSpecs = ProSpecTemp.VendorQuery(new ProductSpecTemp { product_id = old_product_Id }); //ProductSpecMgr proSpecMgr = new ProductSpecMgr(connStr); if (proSpecs != null) { ProductSpecTempMgr proSpecTempMgr = new ProductSpecTempMgr(connStr); StringBuilder str; foreach (var item in proSpecs) { str = new StringBuilder(); str.Append(proSpecTempMgr.VendorSaveFromSpec(new ProductSpecTemp { Writer_Id = writerId, product_id = product_id, spec_id = item.spec_id }, old_product_Id)); str.Append(proItemTempMgr.VendorUpdateCopySpecId(new ProductItemTemp { Writer_Id = writerId, Product_Id = product_id, Spec_Id_1 = item.spec_id, Spec_Id_2 = item.spec_id })); specs.Add(str.ToString()); } } return _pTempDao.VendorCopyProduct(sqls, specs, null, null, null); } else { PriceMasterMgr priceMasterMgr = new PriceMasterMgr(""); string selMaster = priceMasterMgr.VendorSelectChild(new PriceMasterTemp { product_id = old_product_Id }); string moveMaster = priceMasterTempMgr.VendorSaveFromPriceMaster(new PriceMasterTemp { combo_type = combo_type, product_id = product_id, writer_Id = writerId }, old_product_Id); ItemPriceTempMgr itemPriceTempMgr = new ItemPriceTempMgr(""); string movePrice = itemPriceTempMgr.SaveFromItemPriceByMasterId(); ProductComboTempMgr proComboTempMgr = new ProductComboTempMgr(""); sqls.Add(proComboTempMgr.VendorSaveFromCombo(new ProductComboTemp { Writer_Id = writerId, Parent_Id = product_id }, old_product_Id)); return _pTempDao.VendorCopyProduct(sqls, specs, selMaster, moveMaster, movePrice); } } catch (Exception ex) { throw new Exception("ProductTempMgr.VendorCopyProduct-->" + ex.Message, ex); } }
public bool ProductMigration(Product pro, List<PriceMaster> priceMasters, List<ProductItem> items, List<List<ItemPrice>> itemPrices, ArrayList sqls, ArrayList specs) { string proSql = _productDao.Save(pro); ArrayList prices = new ArrayList(); if (priceMasters != null) { PriceMasterMgr priceMasterMgr = new PriceMasterMgr(""); foreach (var item in priceMasters) { prices.Add(priceMasterMgr.SaveNoProId(item)); } } ArrayList proItems = new ArrayList(); if (items != null) { ProductItemMgr productItemMgr = new ProductItemMgr(""); foreach (var item in items) { proItems.Add(productItemMgr.SaveSql(item)); } } ArrayList itemPrice = new ArrayList(); if (itemPrices != null) { ArrayList temp; ItemPriceMgr itemPriceMgr = new ItemPriceMgr(""); foreach (var item in itemPrices) { temp = new ArrayList(); foreach (var p in item) { temp.Add(itemPriceMgr.SaveNoItemId(p)); } itemPrice.Add(temp); } } return _productDao.ProductMigration(proSql, prices, proItems, itemPrice, sqls, specs); }
/// <summary> /// 根據查詢條件匯出對應欄位 /// </summary> /// <param name="query">查詢條件</param> /// <param name="columns">對應欄位</param> /// <returns></returns> public MemoryStream ExportProductToExcel(Model.Query.QueryVerifyCondition query, int exportFlag, string cols, string fileName) { XDocument xml = XDocument.Load(fileName);//加载xml Dictionary<string, string> columns = xml.Elements().Elements().ToDictionary(p => p.Attribute("key").Value, p => p.Value);//將xml轉換成Dictionary query.IsPage = false; string price_master_id = ""; switch (exportFlag) { case 1://庫存資料匯出(單一商品) List<ProductItemCustom> productItems = _productDao.GetStockInfo(query); return ExcelHelperXhf.ExportExcel(productItems, columns);//break; case 2://商品資料匯出 case 3://商品價格匯出:權限控管 int total = 0; List<QueryandVerifyCustom> items = _productDao.QueryByProSite(query, out total); List<string> authority = exportFlag == 3 ? cols.Split(',').ToList() : null; return ExcelHelperXhf.ExportExcel(items, columns, authority); case 4:///子商品價格信息匯出 int sum = 0; List<QueryandVerifyCustom> product = _productDao.QueryByProSite(query, out sum);///獲得根據條件查詢到的相關信息 foreach (var p in product) { price_master_id += p.price_master_id + ","; } if (price_master_id == "")///如果該字符串無值 { return null;//return } price_master_id = price_master_id.Remove(price_master_id.Length - 1, 1);//否則刪去最後一個, IPriceMasterImplMgr _priceMgr = new PriceMasterMgr(connectionStr); List<PriceMasterCustom> listPirce = _priceMgr.GetExcelItemIdInfo(price_master_id); IParametersrcImplDao _paramerDao = new ParametersrcDao(connectionStr); List<Parametersrc> listParameter = _paramerDao.QueryParametersrcByTypes("price_status", "product_status"); foreach (PriceMasterCustom p in listPirce) { var listTemp = listParameter.Find(m => m.ParameterCode == p.price_status.ToString()); var listTemp2 = listParameter.Find(m => m.ParameterCode == p.product_status.ToString()); if (listTemp != null) { p.price_status_str = listTemp.parameterName; } if (listTemp2 != null) { p.product_status_str = listTemp2.parameterName; } } return ExcelHelperXhf.ExportExcel(listPirce, columns); case 5: //預購商品匯出 int totalYugou = 0; List<QueryandVerifyCustom> itemsYugou = _productDao.QueryForPurchase_in_advance(query, out totalYugou); DataTable dtnewYuGuo = new DataTable();//保存沒有過期的 DataTable dtoldYuGuo = new DataTable();//保存過期的 //產生列 dtnewYuGuo.Columns.Add("商品編號", typeof(String)); dtnewYuGuo.Columns.Add("商品名稱", typeof(String)); dtnewYuGuo.Columns.Add("品牌名稱", typeof(String)); dtnewYuGuo.Columns.Add("供應商名稱", typeof(String)); dtnewYuGuo.Columns.Add("商品類型", typeof(String)); dtnewYuGuo.Columns.Add("預購商品開始時間", typeof(String)); dtnewYuGuo.Columns.Add("預購商品結束時間", typeof(String)); dtnewYuGuo.Columns.Add("預計出貨時間", typeof(String)); dtnewYuGuo.Columns.Add("排程設定", typeof(String)); dtnewYuGuo.Columns.Add("庫存數", typeof(String)); dtnewYuGuo.Columns.Add("未出貨數量", typeof(String)); //複製 dtoldYuGuo = dtnewYuGuo.Clone(); foreach (QueryandVerifyCustom qcustom in itemsYugou) { string endtime = qcustom.purchase_in_advance_end_time; if (DateTime.Parse(endtime == "" ? DateTime.Now.AddDays(1).ToString() : endtime) > DateTime.Now) { DataRow newrow = dtnewYuGuo.NewRow(); newrow[0] = qcustom.product_id; newrow[1] = qcustom.product_name; newrow[2] = qcustom.brand_name; newrow[3] = qcustom.vendor_name_full; newrow[4] = qcustom.combination; newrow[5] = qcustom.purchase_in_advance_start_time; newrow[6] = qcustom.purchase_in_advance_end_time; newrow[7] = qcustom.expect_time_time; newrow[8] = qcustom.schedule_name; newrow[9] = qcustom.Item_Stock; newrow[10] = qcustom.bnum; dtnewYuGuo.Rows.Add(newrow); } else { DataRow oldrow = dtoldYuGuo.NewRow(); oldrow[0] = qcustom.product_id; oldrow[1] = qcustom.product_name; oldrow[2] = qcustom.brand_name; oldrow[3] = qcustom.vendor_name_full; oldrow[4] = qcustom.combination; oldrow[5] = qcustom.purchase_in_advance_start_time; oldrow[6] = qcustom.purchase_in_advance_end_time; oldrow[7] = qcustom.expect_time_time; oldrow[8] = qcustom.schedule_name; oldrow[9] = qcustom.Item_Stock; oldrow[10] = qcustom.bnum; dtoldYuGuo.Rows.Add(oldrow); } } List<string> NameList = new List<string>(); NameList.Add("有效期內的預購商品"); NameList.Add("過期的預購商品"); List<DataTable> Elist = new List<DataTable>(); Elist.Add(dtnewYuGuo); Elist.Add(dtoldYuGuo); List<bool> comName = new List<bool>(); comName.Add(true); comName.Add(true); return ExcelHelperXhf.ExportDTNoColumnsBySdy(Elist, NameList, comName); default: throw new Exception("unaccepted exportFlag!!!"); } }
/// <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> /// <returns></returns> public bool Delete(uint product_Id) { ArrayList delList = new ArrayList(); ProductComboMgr proComboMgr = new ProductComboMgr(""); delList.Add(proComboMgr.Delete(Convert.ToInt32(product_Id))); ItemPriceMgr itemPriceMgr = new ItemPriceMgr(""); delList.Add(itemPriceMgr.DeleteByProductId(Convert.ToInt32(product_Id))); PriceMasterMgr priceMaster = new PriceMasterMgr(""); delList.Add(priceMaster.DeleteByProductId(Convert.ToInt32(product_Id))); ProductTagSetMgr proTagSetMgr = new ProductTagSetMgr(""); delList.Add(proTagSetMgr.Delete(new ProductTagSet { product_id = product_Id })); ProductNoticeSetMgr proNoticeSetMgr = new ProductNoticeSetMgr(""); delList.Add(proNoticeSetMgr.Delete(new ProductNoticeSet { product_id = product_Id })); ProductPictureMgr proPicMgr = new ProductPictureMgr(""); delList.Add(proPicMgr.Delete(Convert.ToInt32(product_Id))); ProductSpecMgr proSpecMgr = new ProductSpecMgr(""); delList.Add(proSpecMgr.Delete(product_Id)); ProductCategorySetMgr proCategorySetMgr = new ProductCategorySetMgr(""); delList.Add(proCategorySetMgr.Delete(new ProductCategorySet { Product_Id = product_Id })); #region 課程相關 CourseProductMgr courProdMgr = new CourseProductMgr(""); delList.Add(courProdMgr.Delete(product_Id)); CourseDetailItemMgr courDetaItemMgr = new CourseDetailItemMgr(""); delList.Add(courDetaItemMgr.Delete(product_Id)); #endregion ProductItemMgr proItemMgr = new ProductItemMgr(""); delList.Add(proItemMgr.Delete(new ProductItem { Product_Id = product_Id })); ProductStatusHistoryMgr proStatusHistoryMgr = new ProductStatusHistoryMgr(""); delList.Add(proStatusHistoryMgr.Delete(new ProductStatusHistory { product_id = product_Id })); #region 推薦商品刪除 add by zhuoqin0830w 2015/10/08 RecommendedProductAttributeMgr recommendedProductAttributeMgr = new RecommendedProductAttributeMgr(""); delList.Add(recommendedProductAttributeMgr.DeleteProductAttribute(Convert.ToInt32(product_Id))); #endregion delList.Add(_productDao.Delete(product_Id)); MySqlDao mySqlDao = new MySqlDao(connectionStr); return mySqlDao.ExcuteSqls(delList); }
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>()); }
/// <summary> /// 使用商品細項查詢商品信息 add by zhuoqin0830w 2015/07/10 (內部訂單輸入單一商品>商品細項查詢) /// </summary> /// <returns></returns> public HttpResponseBase OrderInfoQueryBySoleGigade() { string jsonStr = "{success:false}"; uint itemID = 0; UInt32.TryParse(Request.Params["item_id"] ?? "0", out itemID); IProductItemImplMgr _productItemMgr = new ProductItemMgr(connectionString); IProductImplMgr _proMgr = new ProductMgr(connectionString); IPriceMasterImplMgr priceMgr = new PriceMasterMgr(connectionString); IItemPriceImplMgr iPMgr = new ItemPriceMgr(connectionString); try { if (itemID != 0) { //查詢出 product_item 中商品的價格 List<ProductItem> proItem = _productItemMgr.QueryPrice(new ProductItem { Item_Id = itemID }); if (proItem.Count != 0) { //查詢出 商品 信息 Product prod = _proMgr.Query(new Product { Product_Id = proItem[0].Product_Id }).FirstOrDefault(); if (prod != null) { //判断商品是否上架 long ltime = BLL.gigade.Common.CommonFunction.GetPHPTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); bool upFlag = prod.Product_Status == 5 && ltime >= prod.Product_Start && ltime <= prod.Product_End;//判斷商品是否上架 //判斷是否是內部訂單輸入 if (Request.UrlReferrer.AbsolutePath == "/Order/InteriorOrderAdd" || upFlag) { #region 單一商品 Product p = new Product(); p.Product_Id = proItem[0].Product_Id; List<Product> pList = _proMgr.Query(p); //判斷商品是否存在 if (pList.Count() <= 0) { jsonStr = "{success:false,msg:'" + Resources.OrderAdd.PRODUCT_NOT_EXIST + "'}";//商品不存在 this.Response.Clear(); this.Response.Write(jsonStr); this.Response.End(); return this.Response; } //補貨中停止販售 1:是 0:否 if (pList[0].Shortage == 1) { jsonStr = "{success:false,msg:'" + Resources.OrderAdd.SHPRT_AGE + "'}";//補貨中不能販賣 this.Response.Clear(); this.Response.Write(jsonStr); this.Response.End(); return this.Response; } List<OrderAddCustom> oalist = new List<OrderAddCustom>(); OrderAddCustom oc = new OrderAddCustom(); int c_buy_limit = 0; uint c_combination = 0; PriceMaster pM = priceMgr.QueryPriceMaster(new PriceMaster { product_id = pList[0].Product_Id, user_id = 0, user_level = 1, site_id = uint.Parse(Request.Params["Site_Id"]), //edit by zhuoqin0830w 2015/11/16 添加站台欄位詳細查詢是哪一個站台下的價格 child_id = 0 }); if (pM != null) { oc.price_master_id = pM.price_master_id; List<ItemPriceCustom> ipList = iPMgr.Query(new ItemPrice { item_id = uint.Parse(proItem[0].Item_Id.ToString()), price_master_id = pM.price_master_id }); oc.Product_Id = pList[0].Product_Id; oc.product_name = pList[0].Product_Name; oc.Spec_Id_1 = proItem[0].Spec_Id_1; oc.Spec_Id_2 = proItem[0].Spec_Id_2; oc.Item_Id = proItem[0].Item_Id; oc.Item_Stock = proItem[0].Item_Stock; long time = BLL.gigade.Common.CommonFunction.GetPHPTime(Request.Params["combOrderDate"]);//獲取頁面上的訂單日期 edit by zhuoqin0830w 2015/11/17 if (ipList.Count() > 0) { //edit by zhuoqin0830w 2015/11/16 將售價和活動售價的邏輯改為與成本和活動成本的邏輯一樣 eric說需要修改 if (pM.same_price == 1) { oc.Item_Cost = uint.Parse(pM.cost.ToString());//成本 oc.Item_Money = uint.Parse(pM.price.ToString());//定價 } else { oc.Item_Cost = ipList[0].item_cost; oc.Item_Money = ipList[0].item_money; } //add by zhuoqin0830w 2015/11/06 添加判斷 活動時間是否過期 如果過期則在頁面上顯示的活動成本為 0 如果沒有過期則顯示活動成本 if (time > pM.event_start && time < pM.event_end) { oc.Event_Item_Cost = uint.Parse(pM.event_cost.ToString()); //add by zhuoqin0830w 2015/11/16 添加判斷 活動時間是否過期 如果過期則在頁面上顯示的活動售價為 0 如果沒有過期則顯示活動售價 oc.Event_Item_Money = uint.Parse(pM.event_price.ToString()); } else { oc.Event_Item_Cost = 0; oc.Event_Item_Money = 0; } } else { this.Response.Clear(); this.Response.Write("{success:false,msg:'" + Resources.OrderAdd.SINGLE_SPEC_PRICE_WRONG + "'}"); this.Response.End(); return this.Response; } oalist.Add(oc); StringBuilder stb = new StringBuilder(); stb.Append("["); stb.Append("{product_id:" + oc.Product_Id + ",price_type:" + oc.price_type + ",child:" + c_combination + ",buy_limit:" + c_buy_limit + ",item_id:" + oc.Item_Id + ",product_name:'" + oc.product_name + "',"); //添加 活動成本 金額顯示 ",Event_Item_Cost:" + oc.Event_Item_Cost zhuoqin0830w 2015/04/30 添加活動售價 ",Event_Item_Money:" + oc.Event_Item_Money zhuoqin0830w 2015/11/16 stb.Append("product_cost:" + oc.Item_Money + ",Event_Item_Money:" + oc.Event_Item_Money + ",Item_Cost:" + oc.Item_Cost + ",Event_Item_Cost:" + oc.Event_Item_Cost + ",stock:" + oc.Item_Stock + ",s_must_buy:" + oc.s_must_buy + ",Spec_Name_1:'" + proItem[0].Spec_Name_1 + "',Spec_Name_2:'" + proItem[0].Spec_Name_2 + "',spec1:" + proItem[0].Spec_Id_1 + ",spec2:" + proItem[0].Spec_Id_2 + ",price_master_id:" + oc.price_master_id + ",ignore_stock:" + pList[0].Ignore_Stock + ",product_status_name:'" + (upFlag ? "上架" : "未上架") + "'}"); stb.Append("]"); jsonStr = "{success:true,data:" + stb.ToString() + "}"; } else { jsonStr = "{success:false,msg:'" + Resources.OrderAdd.PRODUCT_PRICE_NOT_EXIST + "'}"; } #endregion } else { jsonStr = "{success:false,msg:'" + Resources.OrderAdd.PRODUCT_DOWN + "'}"; } } else { jsonStr = "{success:false,msg:'" + Resources.OrderAdd.PRODUCT_NOT_EXIST + "'}"; } } else { jsonStr = "{success:false,msg:'" + Resources.OrderAdd.PRODUCT_NOT_EXIST + "'}"; } } else { jsonStr = "[{success:true,data:{item_id:''}}]"; } } 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; }
public HttpResponseBase OrderInfoQueryByGigade() { string jsonStr = "{success:false}"; uint pid = 0; uint spec1 = 0; uint spec2 = 0; UInt32.TryParse(Request.Params["pid"] ?? "0", out pid); IProductImplMgr _proMgr = new ProductMgr(connectionString); ProductCombo pcombo = new ProductCombo(); if (pid != 0) { long time = BLL.gigade.Common.CommonFunction.GetPHPTime(Request.Params["combOrderDate"]);//獲取頁面上的訂單日期 edit by zhuoqin0830w 2015/11/17 Product prod = _proMgr.Query(new Product { Product_Id = pid }).FirstOrDefault(); if (prod != null) { //判断商品是否上架 long ltime = BLL.gigade.Common.CommonFunction.GetPHPTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); bool upFlag = prod.Product_Status == 5 && ltime >= prod.Product_Start && ltime <= prod.Product_End;//判斷商品是否上架 if (Request.UrlReferrer.AbsolutePath == "/Order/InteriorOrderAdd" || upFlag)//edit by xiangwang0413w 內部訂單輸入不進行商品是否上架判斷 { if (prod.Combination == 3) { #region 無規格任選 try { bool hasSpec = false; //查詢子商品信息 _prodCombMgr = new ProductComboMgr(connectionString); _proItemMgr = new ProductItemMgr(connectionString); _priceMasterMgr = new PriceMasterMgr(connectionString); List<ProductComboCustom> prodComList = _prodCombMgr.combQuery(new ProductComboCustom { Parent_Id = int.Parse(pid.ToString()) }); //組合商品信息 OrderComboAddCustom orderAdd = _proMgr.OrderQuery(new Product { Product_Id = pid }, 1, 0, 1); // add by wwei0216w 2015/2/10 將之前的0,1,1改成 1,0,1 因為參數不對查詢不出結果 orderAdd.childCount = prodComList.Count(); jsonStr = "{success:true"; double comboPrice = 0.0; //組合商品的價格 =sum( 子商品價格 * 子商品必選數量(s_must_buy); double comboCost = 0.0; //組合商品的成本 double comboEventCost = 0.0; //組合商品的活動成本 add by zhuoqin0830w 2015/11/09 int childSum = 0; //必選商品的必購數量之和 int minStock = 0; int stockIndex = 0; List<OrderAddCustom> orderAddList = new List<OrderAddCustom>(); //存放必選商品集 //此循環是計算子商品的庫存,總價(供按比例拆分時計算子商品的價格使用)等其它信息 for (int i = 0, j = prodComList.Count(); i < j; i++) { ProductComboCustom item = prodComList[i]; uint c_product_id = uint.Parse(item.Child_Id.ToString()); Product pResult = _proMgr.Query(new Product { Product_Id = c_product_id }).FirstOrDefault(); //判斷子商品是否有規格 if (pResult.Product_Spec > 0) { hasSpec = true; break; } //補貨中停止販售 1:是 0:否 if (pResult.Shortage == 1) { jsonStr = "{success:false,msg:'" + Resources.OrderAdd.SHPRT_AGE + "'}"; this.Response.Clear(); this.Response.Write(jsonStr); this.Response.End(); return this.Response; } OrderAddCustom oc = new OrderAddCustom(); ProductItem pItemResult = _proItemMgr.Query(new ProductItem { Product_Id = c_product_id }).FirstOrDefault(); if (pItemResult != null) { oc.Item_Id = pItemResult.Item_Id; oc.Item_Stock = pItemResult.Item_Stock; oc.s_must_buy = item.S_Must_Buy; oc.parent_id = int.Parse(pid.ToString()); oc.ignore_stock = pResult.Ignore_Stock; //計算必先商品之最小庫存 if (item.S_Must_Buy > 0) { oc.Product_Id = c_product_id; childSum += item.S_Must_Buy; if (stockIndex == 0) { minStock = int.Parse((pItemResult.Item_Stock / item.S_Must_Buy).ToString()); } else { int curStock = int.Parse((pItemResult.Item_Stock / item.S_Must_Buy).ToString()); if (curStock < minStock) { minStock = curStock; } } stockIndex++; } } PriceMaster pm = null; if (prod.Price_type == 1) //按比例拆分 { pm = _priceMasterMgr.QueryPriceMaster(new PriceMaster { site_id = 1, child_id = 0, user_level = 1, user_id = 0, product_id = c_product_id }); } else if (prod.Price_type == 2) //各自定價 { pm = _priceMasterMgr.QueryPriceMaster(new PriceMaster { site_id = 1, child_id = int.Parse(c_product_id.ToString()), user_level = 1, user_id = 0, product_id = pid }); } if (pm != null) { //計算Item的價格 ItemPriceCustom ipResult = new ItemPriceCustom(); IItemPriceImplMgr iPMgr = new ItemPriceMgr(connectionString); ipResult = iPMgr.Query(new ItemPrice { item_id = pItemResult.Item_Id, price_master_id = pm.price_master_id }).FirstOrDefault(); oc.product_name = pm.product_name; oc.price_master_id = pm.price_master_id; oc.Item_Money = ipResult.item_money; oc.product_cost = ipResult.item_money; oc.original_price = int.Parse(ipResult.item_money.ToString()); oc.Item_Cost = ipResult.item_cost; //計算必選商品之總價 if (item.S_Must_Buy > 0) { comboPrice += int.Parse((ipResult.item_money * item.S_Must_Buy).ToString()); comboCost += int.Parse((ipResult.item_cost * item.S_Must_Buy).ToString()); } orderAddList.Add(oc); } else { jsonStr = "{success:false,msg:'" + Resources.OrderAdd.PRODUCT_PRICE_NOT_EXIST + "'}"; this.Response.Clear(); this.Response.Write(jsonStr); this.Response.End(); return this.Response; } } //將計算的最小庫存價賦值給組合商品 orderAdd.stock = minStock; //各自定價時將組合商品的定價賦值給組合商品 if (prod.Price_type == 2) { orderAdd.product_cost = int.Parse(comboPrice.ToString()); } //如果子商品含有規格則提示 if (hasSpec) { jsonStr = "{success:false,msg:'" + Resources.OrderAdd.COMBO_CHILD_NO_SPEC + "'}"; this.Response.Clear(); this.Response.Write(jsonStr); this.Response.End(); return this.Response; } jsonStr += ",child:["; string priceScales = "";//單一商品價格所占比例 string costScalses = ""; //單一商品成本所占比例 var rightList = orderAddList.Where(rec => rec.s_must_buy > 0).ToList(); var totalPrice = orderAdd.product_cost; //組合商品的定價 var totalCost = orderAdd.cost; //組合商品的成本 foreach (var item in rightList) { //如果組合商品的價格類型為 按比例拆分 則需重新為必選子商品定價 if (prod.Price_type == 1) { //if (comboCost != 0) if (comboPrice != 0) { //new logic 计算按比例拆分之比例 double priceScale = double.Parse((item.Item_Money * item.s_must_buy / comboPrice).ToString()); //double costScale = double.Parse((item.Item_Cost * item.s_must_buy / comboCost).ToString()); priceScales += priceScale + ","; //costScalses += costScale + ","; int afterPrice = Convert.ToInt16(Math.Round(totalPrice * priceScale / item.s_must_buy)); //int afterCost = Convert.ToInt16(Math.Round(totalCost * costScale / item.s_must_buy)); comboPrice -= Convert.ToInt16(item.Item_Money * item.s_must_buy); //comboCost -= Convert.ToInt16(item.Item_Cost * item.s_must_buy); totalPrice -= afterPrice * item.s_must_buy; //totalCost -= afterCost * item.s_must_buy; item.product_cost = uint.Parse(afterPrice.ToString()); //item.Item_Cost = uint.Parse(afterCost.ToString()); } else { priceScales += "0"; //costScalses += "0"; item.product_cost = 0; } } jsonStr += JsonConvert.SerializeObject(item); } //jsonStr = jsonStr.Substring(0, jsonStr.Length - 1); jsonStr = jsonStr.Replace("}{", "},{"); jsonStr += "],data:["; //拼接組合商品 s_must_buy:當前任選中必選商品的記錄數 jsonStr += "{product_id:'" + orderAdd.product_id + "',product_name:'" + orderAdd.product_name + "',Item_Cost:'" + orderAdd.cost + "',product_cost:'" + orderAdd.product_cost + "',item_id:0"; jsonStr += ",child_scale:'" + priceScales + "',child_cost_scale:'" + costScalses + "',stock:'" + minStock + "',g_must_buy:'" + prodComList[0].G_Must_Buy + "',s_must_buy:" + rightList.Count() + ""; jsonStr += ",combination:" + orderAdd.child + ",buy_limit:" + prodComList[0].Buy_Limit + ",child:" + orderAdd.child + ",childCount:" + orderAdd.childCount + ",childSum:" + childSum + ",price_type:" + orderAdd.price_type + ",product_status_name:'" + (upFlag ? "上架" : "未上架") + "'}]}"; } 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); } #endregion } else if (prod.Combination == 2) { #region 固定組合 try { OrderComboAddCustom orderAdd = _proMgr.OrderQuery(new Product { Product_Id = pid }, 1, 0, 1); jsonStr = "{success:true"; //查詢子商品信息 _prodCombMgr = new ProductComboMgr(connectionString); List<ProductComboCustom> prodComList = _prodCombMgr.combQuery(new ProductComboCustom { Parent_Id = int.Parse(pid.ToString()) }); IProductItemImplMgr _proItemMgr = new ProductItemMgr(connectionString); IPriceMasterImplMgr priceMgr = new PriceMasterMgr(connectionString); foreach (var item in prodComList) { Product pResult = _proMgr.Query(new Product { Product_Id = uint.Parse(item.Child_Id.ToString()) }).FirstOrDefault(); //補貨中停止販售 1:是 0:否 if (pResult.Shortage == 1) { jsonStr = "{success:false,msg:'" + Resources.OrderAdd.SHPRT_AGE + "'}"; this.Response.Clear(); this.Response.Write(jsonStr); this.Response.End(); return this.Response; } } jsonStr += ",child:["; double totalPrice = 0; double totalCost = 0; double totalEventCost = 0; //add by zhuoqin0830w 2015/11/09 double totalEventPrice = 0;//add by zhuoqin0830w 2015/11/17 string priceScales = "";//單一商品價格所占比例 string costScales = ""; //單一商品成本所占比例 string eventcostScales = "";//單一商品活動成本所占比例 add by zhuoqin0830w 2015/11/09 string eventpriceScales = "";//單一商品活動價所占比例 add by zhuoqin0830w 2015/11/17 int minStock = 0; if (prod.Price_type == 1) { #region 按比例拆分 //計算子商品的總價 List<ProductItem> price_data_right_list = new List<ProductItem>(); foreach (var item in prodComList) { bool findState = false; List<Product> pList = _proMgr.Query(new Product { Product_Id = uint.Parse(item.Child_Id.ToString()) }); List<ProductItem> pItemList = _proItemMgr.Query(new ProductItem { Product_Id = uint.Parse(item.Child_Id.ToString()) }); //在item_price中查找對應item_id的商品規格價格 IItemPriceImplMgr iPMgr = new ItemPriceMgr(connectionString); PriceMaster pM = priceMgr.QueryPriceMaster(new PriceMaster { product_id = uint.Parse(item.Child_Id.ToString()), user_id = 0, user_level = 1, site_id = uint.Parse(Request.Params["Site_Id"]), //edit by zhuoqin0830w 2015/11/16 添加站台欄位詳細查詢是哪一個站台下的價格 child_id = 0 }); List<ItemPriceCustom> ipList = new List<ItemPriceCustom>(); if (pM != null) { //add by zhuoqin0830w 2015/11/06 添加判斷 活動時間是否過期 如果過期則在頁面上顯示的活動成本為 0 如果沒有過期則顯示活動成本 if (time > pM.event_end) { pM.event_cost = 0; pM.event_price = 0; } //遍歷此商品所有item_id,找出第一筆在item_price中的item_id返回,若無,則此組合商品不能加入訂單 foreach (ProductItem items in pItemList) { ipList = iPMgr.Query(new ItemPrice { item_id = uint.Parse(items.Item_Id.ToString()), price_master_id = pM.price_master_id }); if (ipList.Count == 1) { if (pM.same_price == 1) { totalPrice += pM.price * item.S_Must_Buy; totalCost += pM.cost * item.S_Must_Buy; totalEventCost += pM.event_cost * item.S_Must_Buy;//add by zhuoqin0830w 2015/11/09 totalEventPrice += pM.event_price * item.S_Must_Buy;//add by zhuoqin0830w 2015/11/17 } else { totalPrice += ipList[0].item_money * item.S_Must_Buy; totalCost += ipList[0].item_cost * item.S_Must_Buy; totalEventCost += ipList[0].event_cost * item.S_Must_Buy;//add by zhuoqin0830w 2015/11/09 totalEventPrice += ipList[0].event_money * item.S_Must_Buy;//add by zhuoqin0830w 2015/11/17 } price_data_right_list.Add(items); findState = true; break; } } if (!findState) { //在item_price中未查出對應價格 this.Response.Clear(); this.Response.Write("{success:false,msg:'" + Resources.OrderAdd.COMBO_CHILD_PRICE_NULL + "'}"); this.Response.End(); return this.Response; } } else { //price_master表中沒有相對應的站台價格 add by zhuoqin0830w 2015/11/16 jsonStr = "{success:false,msg:'" + Resources.OrderAdd.PRODUCT_PRICE_NOT_EXIST + "'}"; this.Response.Clear(); this.Response.Write(jsonStr); this.Response.End(); return this.Response; } } int index = 0; int comboPrice = orderAdd.product_cost; //組合商品的定價 int comboCost = orderAdd.cost; int comboEventCost = 0; int comboEventPrice = 0; //add by zhuoqin0830w 2015/11/06 添加判斷 活動時間是否過期 如果過期則在頁面上顯示的活動成本為 0 如果沒有過期則顯示活動成本 if (orderAdd != null) { if (time > orderAdd.event_start && time < orderAdd.event_end) { comboEventCost = orderAdd.event_cost; comboEventPrice = orderAdd.event_price; } else { orderAdd.event_cost = 0; orderAdd.event_price = 0; } } for (int i = 0; i < prodComList.Count; i++) { index++; OrderAddCustom oc = new OrderAddCustom(); oc.Product_Id = uint.Parse(prodComList[i].Child_Id.ToString()); oc.parent_id = prodComList[i].Parent_Id; //讀取product_name IPriceMasterImplMgr pMgr = new PriceMasterMgr(connectionString); PriceMaster pm = pMgr.QueryPriceMaster(new PriceMaster { site_id = uint.Parse(Request.Params["Site_Id"]), //edit by zhuoqin0830w 2015/11/16 添加站台欄位詳細查詢是哪一個站台下的價格 child_id = 0, user_level = 1, user_id = 0, product_id = oc.Product_Id }); if (pm != null) { oc.product_name = pm.product_name; } oc.s_must_buy = prodComList[i].S_Must_Buy; if (price_data_right_list.Count != 0) { if (index == 1) { //最小庫存為組合下子商品的最小庫存/該子商品必購數量(如果必購數量為0則按1計算) minStock = int.Parse((price_data_right_list[i].Item_Stock / (prodComList[i].S_Must_Buy == 0 ? 1 : prodComList[i].S_Must_Buy)).ToString()); } Product pResult = _proMgr.Query(new Product { Product_Id = uint.Parse(prodComList[i].Child_Id.ToString()) }).FirstOrDefault(); //有規格 oc.Spec_Name_1 = price_data_right_list[i].Spec_Name_1; oc.Spec_Name_2 = price_data_right_list[i].Spec_Name_2; oc.Item_Stock = price_data_right_list[i].Item_Stock; oc.Item_Id = price_data_right_list[i].Item_Id; int curStock = int.Parse((oc.Item_Stock / (prodComList[i].S_Must_Buy == 0 ? 1 : prodComList[i].S_Must_Buy)).ToString()); if (curStock < minStock) { minStock = curStock; } oc.Spec_Id_1 = price_data_right_list[i].Spec_Id_1; oc.Spec_Id_2 = price_data_right_list[i].Spec_Id_2; oc.ignore_stock = pResult.Ignore_Stock; //在item_price中查找對應item_id的商品規格價格 IItemPriceImplMgr iPMgr = new ItemPriceMgr(connectionString); PriceMaster pM = priceMgr.QueryPriceMaster(new PriceMaster { product_id = uint.Parse(price_data_right_list[i].Product_Id.ToString()), user_id = 0, user_level = 1, site_id = uint.Parse(Request.Params["Site_Id"]), //edit by zhuoqin0830w 2015/11/16 添加站台欄位詳細查詢是哪一個站台下的價格 child_id = 0 }); List<ItemPriceCustom> ipList = new List<ItemPriceCustom>(); if (pM != null) { double singlePrice = 0; double singleCost = 0; double singleEventCost = 0;//add by zhuoqin0830w 2015/11/09 double singleEventPrice = 0;//add by zhuoqin0830w 2015/11/17 if (pM.same_price == 1) { oc.original_price = pM.price; oc.Item_Cost = uint.Parse(pM.cost.ToString()); oc.Event_Item_Cost = uint.Parse(pm.event_cost.ToString());//add by zhuoqin0830w 2015/11/09 oc.Event_Item_Money = uint.Parse(pm.event_price.ToString());//add by zhuoqin0830w 2015/11/17 singlePrice = pM.price * oc.s_must_buy; singleCost = pM.cost * oc.s_must_buy; singleEventCost = pM.event_cost * oc.s_must_buy;//add by zhuoqin0830w 2015/11/09 singleEventPrice = pM.event_price * oc.s_must_buy;//add by zhuoqin0830w 2015/11/17 } else { ipList = iPMgr.Query(new ItemPrice { item_id = uint.Parse(price_data_right_list[i].Item_Id.ToString()), price_master_id = pM.price_master_id }); if (ipList.Count == 1) { oc.original_price = int.Parse(ipList[0].item_money.ToString()); oc.Item_Cost = ipList[0].item_cost; oc.Event_Item_Cost = ipList[0].event_cost;//add by zhuoqin0830w 2015/11/09 oc.Event_Item_Money = ipList[0].event_money;//add by zhuoqin0830w 2015/11/17 singlePrice = ipList[0].item_money * oc.s_must_buy; singleCost = ipList[0].item_cost * oc.s_must_buy; singleEventCost = ipList[0].event_cost * oc.s_must_buy;//add by zhuoqin0830w 2015/11/09 singleEventPrice = ipList[0].event_money * oc.s_must_buy;//add by zhuoqin0830w 2015/11/17 } } if (totalPrice == 0) { priceScales += "0"; costScales += "0"; eventcostScales += "0";//add by zhuoqin0830w 2015/11/09 eventpriceScales += "0";//add by zhuoqin0830w 2015/11/09 oc.product_cost = 0; } else { //new logic 算比例 double priceScale = double.Parse((singlePrice / totalPrice).ToString()); double costScale = double.Parse((singleCost / totalCost).ToString()); //add by zhuoqin0830w 2015/11/09 添加活動成本的比例 double eventcostScale = 0; if (totalEventCost != 0) { eventcostScale = double.Parse((singleEventCost / totalEventCost).ToString()); } else { eventcostScale = priceScale;// 如果 活動成本的比例為0 則表示沒有活動成本則按照價格的比例進行計算 } double eventpriceScale = 0; if (totalEventPrice != 0) { eventpriceScale = double.Parse((singleEventPrice / totalEventPrice).ToString()); } else { eventpriceScale = priceScale;// 如果 活動價的比例為0 則表示沒有活動成本則按照價格的比例進行計算 } priceScales += priceScale + ","; costScales += costScale + ","; eventcostScales += eventcostScale + ",";//add by zhuoqin0830w 2015/11/09 eventpriceScales += eventpriceScale + ",";//add by zhuoqin0830w 2015/11/17 var afterprice = Convert.ToInt16(Math.Round(comboPrice * priceScale / oc.s_must_buy)); var aftercost = Convert.ToInt16(Math.Round(comboCost * costScale / oc.s_must_buy)); var aftereventcost = Convert.ToInt16(Math.Round(comboEventCost * eventcostScale / oc.s_must_buy));//add by zhuoqin0830w 2015/11/09 var aftereventprice = Convert.ToInt16(Math.Round(comboEventPrice * eventpriceScale / oc.s_must_buy));//add by zhuoqin0830w 2015/11/17 comboPrice -= afterprice * oc.s_must_buy; comboCost -= aftercost * oc.s_must_buy; comboEventCost -= aftereventcost * oc.s_must_buy;//add by zhuoqin0830w 2015/11/09 comboEventPrice -= aftereventprice * oc.s_must_buy;//add by zhuoqin0830w 2015/11/17 totalPrice -= singlePrice; totalCost -= singleCost; totalEventCost -= singleEventCost;//add by zhuoqin0830w 2015/11/09 totalEventPrice -= singleEventPrice;//add by zhuoqin0830w 2015/11/17 oc.product_cost = uint.Parse(afterprice.ToString()); oc.Item_Cost = uint.Parse(aftercost.ToString()); oc.Event_Item_Cost = uint.Parse(aftereventcost.ToString());//add by zhuoqin0830w 2015/11/09 oc.Event_Item_Money = uint.Parse(aftereventprice.ToString());//add by zhuoqin0830w 2015/11/17 } } } jsonStr += JsonConvert.SerializeObject(oc) + ","; } #endregion } else { #region 各自定價 orderAdd.product_cost = 0; foreach (var item in prodComList) { Product pResult = _proMgr.Query(new Product { Product_Id = uint.Parse(item.Child_Id.ToString()) }).FirstOrDefault(); OrderAddCustom oc = new OrderAddCustom(); oc.price_type = prod.Price_type; oc.parent_id = item.Parent_Id; oc.Product_Id = uint.Parse(item.Child_Id.ToString()); List<ProductItem> pItemList = _proItemMgr.Query(new ProductItem { Product_Id = uint.Parse(item.Child_Id.ToString()) }); if (prodComList.IndexOf(item) == 0) { minStock = int.Parse((pItemList[0].Item_Stock / (item.S_Must_Buy == 0 ? 1 : item.S_Must_Buy)).ToString()); //最小庫存為組合下子商品的最小庫存/該子商品必購數量(如果必購數量為0則按1計算) } PriceMaster pM = priceMgr.QueryPriceMaster(new PriceMaster { product_id = pid, user_id = 0, user_level = 1, site_id = uint.Parse(Request.Params["Site_Id"]), //edit by zhuoqin0830w 2015/11/16 添加站台欄位詳細查詢是哪一個站台下的價格 child_id = Int32.Parse(item.Child_Id) //add by wangwei02016w 2014/9/24 }); ItemPriceCustom ip = new ItemPriceCustom(); IItemPriceImplMgr iPMgr = new ItemPriceMgr(connectionString); if (pM != null) { oc.product_name = pM.product_name; oc.price_master_id = pM.price_master_id; ip = iPMgr.Query(new ItemPrice { item_id = uint.Parse(pItemList[0].Item_Id.ToString()), price_master_id = pM.price_master_id }).First(); oc.Spec_Name_1 = pItemList[0].Spec_Name_1; oc.Spec_Name_2 = pItemList[0].Spec_Name_2; oc.Item_Stock = pItemList[0].Item_Stock; oc.Spec_Id_1 = pItemList[0].Spec_Id_1; oc.Spec_Id_2 = pItemList[0].Spec_Id_2; oc.ignore_stock = pResult.Ignore_Stock; int curStock = int.Parse((pItemList[0].Item_Stock / (item.S_Must_Buy == 0 ? 1 : item.S_Must_Buy)).ToString()); if (curStock < minStock) { minStock = curStock; } oc.Item_Id = pItemList[0].Item_Id; oc.product_cost = ip.item_money; oc.original_price = int.Parse(ip.item_money.ToString()); orderAdd.product_cost += Convert.ToInt32(oc.product_cost * item.S_Must_Buy); } oc.s_must_buy = item.S_Must_Buy; jsonStr += JsonConvert.SerializeObject(oc) + ","; } #endregion } jsonStr = jsonStr.Substring(0, jsonStr.Length - 1) + "]"; jsonStr += ",data:["; //拼接組合商品 cost為組合商品之成本,product_cost為組合商品之售價 jsonStr += "{product_id:'" + orderAdd.product_id + "',product_name:'" + orderAdd.product_name + "',Item_Cost:'" + orderAdd.cost + "',product_cost:'" + orderAdd.product_cost + "',item_id:0" + ",Event_Item_Cost:" + orderAdd.event_cost + ",Event_Item_Money:" + orderAdd.event_price; jsonStr += ",s_must_buy:'" + prodComList.Count + "',child_scale:'" + priceScales + "',child_cost_scale:'" + costScales + "',child_event_cost_scale:'" + eventcostScales + "',stock:'" + minStock + "',g_must_buy:'" + prodComList.Count + "',child:" + orderAdd.child + ",product_status_name:'" + (upFlag ? "上架" : "未上架") + "'}"; jsonStr += "]}"; } 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); } #endregion } else { #region 單一商品 // 判斷 輸入的商品是否是單一商品 並且是 內部訂單輸入 如果是 則彈出提示框 add by zhuoqin0830w 2015/07/10 if (Request.UrlReferrer.AbsolutePath == "/Order/InteriorOrderAdd") { if (prod.Combination == 1 && Convert.ToInt32(Request.Params["pid"].Length) != 6 && Request.Params["parent_id"] == "") { this.Response.Clear(); this.Response.Write("{success:false,msg:'單一商品必須輸入六碼編號!'}"); this.Response.End(); return this.Response; } } IProductItemImplMgr _proItemMgr = new ProductItemMgr(connectionString); Product p = new Product(); p.Product_Id = pid; ProductItem pItem = new ProductItem(); pItem.Product_Id = pid; UInt32.TryParse(Request.Params["spec1"] ?? "0", out spec1); UInt32.TryParse(Request.Params["spec2"] ?? "0", out spec2); pItem.Spec_Id_1 = spec1; pItem.Spec_Id_2 = spec2; try { List<OrderAddCustom> oalist = new List<OrderAddCustom>(); OrderAddCustom oc = new OrderAddCustom(); List<Product> pList = _proMgr.Query(p); List<ProductItem> pItemList = _proItemMgr.Query(pItem); if (pList.Count() <= 0 || pItemList.Count() <= 0) { jsonStr = "{success:false,msg:'" + Resources.OrderAdd.PRODUCT_NOT_EXIST + "'}";//商品不存在 this.Response.Clear(); this.Response.Write(jsonStr); this.Response.End(); return this.Response; } //補貨中停止販售 1:是 0:否 if (pList[0].Shortage == 1) { jsonStr = "{success:false,msg:'" + Resources.OrderAdd.SHPRT_AGE + "'}";//補貨中不能販賣 this.Response.Clear(); this.Response.Write(jsonStr); this.Response.End(); return this.Response; } int parent_id = 0; int price_type = 0; uint c_combination = 0; int c_buy_limit = 0; //組合商品子商品查詢 if (!string.IsNullOrEmpty(Request.Params["parent_id"])) { parent_id = int.Parse(Request.Params["parent_id"]); //查詢組合商品的價格類型 Product parentResult = _proMgr.Query(new Product { Product_Id = uint.Parse(parent_id.ToString()) }).FirstOrDefault(); if (parentResult != null) { price_type = parentResult.Price_type; c_combination = parentResult.Combination; } oc.price_type = price_type; //找出該商品在組合商品中的必購數量 _prodCombMgr = new ProductComboMgr(connectionString); List<ProductComboCustom> prodComList = _prodCombMgr.combQuery(new ProductComboCustom { Parent_Id = parent_id, Child_Id = pid.ToString() });//add by wangwei02016w 2014/9/24 if (prodComList.Count == 1) { oc.s_must_buy = prodComList[0].S_Must_Buy; c_buy_limit = prodComList[0].Buy_Limit; } } //在item_price中查找對應item_id的商品規格價格 IPriceMasterImplMgr priceMgr = new PriceMasterMgr(connectionString); IItemPriceImplMgr iPMgr = new ItemPriceMgr(connectionString); PriceMaster pM = null; if (price_type == 2) //各自定價時取價格 { pM = priceMgr.QueryPriceMaster(new PriceMaster { product_id = uint.Parse(parent_id.ToString()), user_id = 0, user_level = 1, site_id = uint.Parse(Request.Params["Site_Id"]), //edit by zhuoqin0830w 2015/11/16 添加站台欄位詳細查詢是哪一個站台下的價格 child_id = int.Parse(pList[0].Product_Id.ToString()) }); } else { pM = priceMgr.QueryPriceMaster(new PriceMaster { product_id = pList[0].Product_Id, user_id = 0, user_level = 1, site_id = uint.Parse(Request.Params["Site_Id"]), //edit by zhuoqin0830w 2015/11/16 添加站台欄位詳細查詢是哪一個站台下的價格 child_id = 0 }); } if (pM != null) { oc.price_master_id = pM.price_master_id; List<ItemPriceCustom> ipList = iPMgr.Query(new ItemPrice { item_id = uint.Parse(pItemList[0].Item_Id.ToString()), price_master_id = pM.price_master_id }); oc.Product_Id = pList[0].Product_Id; oc.product_name = pList[0].Product_Name; oc.Spec_Id_1 = pItemList[0].Spec_Id_1; oc.Spec_Id_2 = pItemList[0].Spec_Id_2; oc.Item_Id = pItemList[0].Item_Id; oc.Item_Stock = pItemList[0].Item_Stock; if (ipList.Count() > 0) { //edit by zhuoqin0830w 2015/11/16 將售價和活動售價的邏輯改為與成本和活動成本的邏輯一樣 eric說需要修改 if (pM.same_price == 1) { oc.Item_Cost = uint.Parse(pM.cost.ToString());//成本 oc.Item_Money = uint.Parse(pM.price.ToString());//定價 } else { oc.Item_Cost = ipList[0].item_cost; oc.Item_Money = ipList[0].item_money; } //add by zhuoqin0830w 2015/11/06 添加判斷 活動時間是否過期 如果過期則在頁面上顯示的活動成本為 0 如果沒有過期則顯示活動成本 if (time > pM.event_start && time < pM.event_end) { oc.Event_Item_Cost = uint.Parse(pM.event_cost.ToString()); //add by zhuoqin0830w 2015/11/16 添加判斷 活動時間是否過期 如果過期則在頁面上顯示的活動售價為 0 如果沒有過期則顯示活動售價 oc.Event_Item_Money = uint.Parse(pM.event_price.ToString()); } else { oc.Event_Item_Cost = 0; oc.Event_Item_Money = 0; } } else { this.Response.Clear(); this.Response.Write("{success:false,msg:'" + Resources.OrderAdd.SINGLE_SPEC_PRICE_WRONG + "'}"); this.Response.End(); return this.Response; } IProductSpecImplMgr _specMgr = new BLL.gigade.Mgr.ProductSpecMgr(connectionString); List<ProductSpec> specList1 = _specMgr.query(Int32.Parse(pItemList[0].Product_Id.ToString()), "spec_id_1"); List<ProductSpec> specList2 = _specMgr.query(Int32.Parse(pItemList[0].Product_Id.ToString()), "spec_id_2"); oc.specList1 = specList1; oc.specList2 = specList2; oalist.Add(oc); StringBuilder stb = new StringBuilder(); stb.Append("["); stb.Append("{product_id:" + oc.Product_Id + ",price_type:" + oc.price_type + ",child:" + c_combination + ",buy_limit:" + c_buy_limit + ",item_id:" + oc.Item_Id + ",product_name:'" + oc.product_name + "',"); //添加 活動成本 金額顯示 ",Event_Item_Cost:" + pM.event_cost zhuoqin0830w 2015/04/30 添加活動售價 ",Event_Item_Money:" + oc.Event_Item_Money zhuoqin0830w 2015/11/16 stb.Append("product_cost:" + oc.Item_Money + ",Event_Item_Money:" + oc.Event_Item_Money + ",Item_Cost:" + oc.Item_Cost + ",Event_Item_Cost:" + pM.event_cost + ",stock:" + oc.Item_Stock + ",s_must_buy:" + oc.s_must_buy + ",Spec_Name_1:'" + pItemList[0].Spec_Name_1 + "',Spec_Name_2:'" + pItemList[0].Spec_Name_2 + "',spec1:" + pItemList[0].Spec_Id_1 + ",spec2:" + pItemList[0].Spec_Id_2 + ",price_master_id:" + oc.price_master_id + ",ignore_stock:" + pList[0].Ignore_Stock + ",product_status_name:'" + (upFlag ? "上架" : "未上架") + "'}"); stb.Append("]"); jsonStr = "{success:true,data:" + stb.ToString() + "}"; } else { jsonStr = "{success:false,msg:'" + Resources.OrderAdd.PRODUCT_PRICE_NOT_EXIST + "'}"; } } 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); } #endregion } } else { jsonStr = "{success:false,msg:'" + Resources.OrderAdd.PRODUCT_DOWN + "'}"; } } else { jsonStr = "{success:false,msg:'" + Resources.OrderAdd.PRODUCT_NOT_EXIST + "'}"; } } else { jsonStr = "[{success:true,data:{product_id:''}}]"; } this.Response.Clear(); this.Response.Write(jsonStr); this.Response.End(); return this.Response; }
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> /// 合作外站商品查詢 /// </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; }