public void ExportCSV()// yachao1120j 2015-9-10 匯出商品庫存查詢記錄
        {
            ProductItemQuery query = new ProductItemQuery();
            try
            {
                if (!string.IsNullOrEmpty(Request.Params["vendor_name_full_OR_vendor_id"]))
                {
                    query.vendor_name_full_OR_vendor_id = Request.Params["vendor_name_full_OR_vendor_id"];//供应商名称/编号
                }
                if (!string.IsNullOrEmpty(Request.Params["product_id_OR_product_name"]))
                {
                    query.product_id_OR_product_name = Request.Params["product_id_OR_product_name"];//商品编号/名称
                }
                if (!string.IsNullOrEmpty(Request.Params["brand_id_OR_brand_name"]))
                {
                    query.brand_id_OR_brand_name = Request.Params["brand_id_OR_brand_name"];//品牌编号/名称
                }
                if (!string.IsNullOrEmpty(Request.Params["product_status"]))
                {
                    query.product_status = Convert.ToUInt32(Request.Params["product_status"]);//商品状态
                }
                if (!string.IsNullOrEmpty(Request.Params["sale_status"]))
                {
                    query.sale_status = Convert.ToUInt32(Request.Params["sale_status"]);//商品販售狀態
                }
                if (!string.IsNullOrEmpty(Request.Params["item_stock_start"]) && Request.Params["item_stock_start"] != "null")
                {
                    query.item_stock_start = Convert.ToInt32(Request.Params["item_stock_start"]);//库存数量--开始
                }
                else 
                {
                    query.item_stock_start = 0;
                }
                if (!string.IsNullOrEmpty(Request.Params["item_stock_end"]) && Request.Params["item_stock_end"] != "null")
                {
                    query.item_stock_end = Convert.ToInt32(Request.Params["item_stock_end"]);//库存数量--结束
                }
                else
                {
                    query.item_stock_end = 0;
                }
                if (!string.IsNullOrEmpty(Request.Params["ignore_stockRdo"]))
                {
                    query.ignore_stock = Convert.ToInt32(Request.Params["ignore_stockRdo"]);//补货中停止贩售
                }
                DataTable dtHZ = new DataTable();
                int totalcount = 0;
                query.IsPage = false;
                string newExcelName = string.Empty;
                dtHZ.Columns.Add("供應商編號", typeof(String));
                dtHZ.Columns.Add("供應商名稱", typeof(String));
                dtHZ.Columns.Add("品牌編號", typeof(String));
                dtHZ.Columns.Add("品牌名稱", typeof(String));
                dtHZ.Columns.Add("商品編號", typeof(String));
                dtHZ.Columns.Add("商品名稱", typeof(String));
                dtHZ.Columns.Add("商品細項編號", typeof(String));
                dtHZ.Columns.Add("商品規格", typeof(String));
                dtHZ.Columns.Add("商品狀態", typeof(String));
                dtHZ.Columns.Add("商品販售狀態", typeof(String));
                dtHZ.Columns.Add("庫存為0時是否還能販售", typeof(String));
                dtHZ.Columns.Add("庫存數量", typeof(String));
                List<ProductItemQuery> list = new List<ProductItemQuery>();
                productitemMgr = new ProductItemMgr(connectionString);
                list = productitemMgr.GetInventoryQueryList(query, out totalcount);
                if (list.Count > 0)
                {
                    for (int i = 0; i < list.Count; i++)
                    {
                        DataRow dr = dtHZ.NewRow();

                        dr[0] = list[i].vendor_id;
                        dr[1] = list[i].vendor_name_full;
                        dr[2] = list[i].brand_id;
                        dr[3] = list[i].brand_name;
                        dr[4] = list[i].Product_Id;
                        dr[5] = list[i].product_name;
                        dr[6] = list[i].Item_Id;
                        dr[7] = list[i].product_spec;
                        dr[8] = list[i].product_status_string;
                        dr[9] = list[i].sale_status_string;
                        dr[10] = list[i].ignore_stock_string;
                        dr[11] = list[i].Item_Stock;
                        dtHZ.Rows.Add(dr);
                    }
                    string fileName = "product_stock_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";
                    MemoryStream ms = ExcelHelperXhf.ExportDT(dtHZ, "");
                    Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
                    Response.BinaryWrite(ms.ToArray());
                }
                else
                {
                    Response.Clear();
                    this.Response.Write("無數據存在<br/>");
                }
            }
            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);
            }


        }
 public uint GetProductIdByItemId(uint id)
 {
     uint ret = 0;
     try
     {
         IProductItemImplMgr _productItemMgr = new ProductItemMgr(connectionString);
         List<ProductItem> proItemList = _productItemMgr.Query(new ProductItem { Item_Id = id });
         if (proItemList.Count > 0)
         {
             ret = proItemList[0].Product_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);
     }
     return ret;
 }
        public HttpResponseBase GetInventoryQueryList()// yachoa1120j 2015-9-10 商品庫存查詢
        {

            string json = string.Empty;
            int totalcount = 0;
            try
            {
                ProductItemQuery query = new ProductItemQuery();
                query.Start = Convert.ToInt32(Request.Params["start"] ?? "0");
                query.Limit = Convert.ToInt32(Request.Params["limit"] ?? "25");
                productitemMgr = new ProductItemMgr(connectionString);
                if (!string.IsNullOrEmpty(Request.Params["vendor_name_full_OR_vendor_id"]))
                {
                    query.vendor_name_full_OR_vendor_id = Request.Params["vendor_name_full_OR_vendor_id"];//供应商名称/编号
                }
                if (!string.IsNullOrEmpty(Request.Params["product_id_OR_product_name"]))
                {
                    query.product_id_OR_product_name = Request.Params["product_id_OR_product_name"];//商品编号/名称/商品細項編號
                }
                if (!string.IsNullOrEmpty(Request.Params["brand_id_OR_brand_name"]))
                {
                    query.brand_id_OR_brand_name = Request.Params["brand_id_OR_brand_name"];//品牌编号/名称
                }
                if (!string.IsNullOrEmpty(Request.Params["product_status"]))
                {
                    query.product_status = Convert.ToUInt32(Request.Params["product_status"]);//商品状态
                }
                if (!string.IsNullOrEmpty(Request.Params["sale_status"]))
                {
                    query.sale_status = Convert.ToUInt32(Request.Params["sale_status"]);//商品販售狀態
                }
                if (!string.IsNullOrEmpty(Request.Params["item_stock_start"]))
                {
                    query.item_stock_start = Convert.ToInt32(Request.Params["item_stock_start"]);//库存数量--开始
                }
                if (!string.IsNullOrEmpty(Request.Params["item_stock_end"]))
                {
                    query.item_stock_end = Convert.ToInt32(Request.Params["item_stock_end"]);//库存数量--结束
                }
                if (!string.IsNullOrEmpty(Request.Params["ignore_stockRdo"]))
                {
                    query.ignore_stock = Convert.ToInt32(Request.Params["ignore_stockRdo"]);//庫存為0時是否還能販售
                }
                List<ProductItemQuery> list = productitemMgr.GetInventoryQueryList(query, out totalcount);
                IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
                timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
                timeConverter.DateTimeFormat = "yyyy-MM-dd";
                json = "{success:true,totalCount:" + totalcount + ",data:" + JsonConvert.SerializeObject(list, Formatting.Indented, timeConverter) + "}";
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                json = "{success:false}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return Response;
        }
Beispiel #4
0
        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);
        }
        //單一商品
        public List<ProductItemMapCustom> SingleProductItemMapExc(PriceMasterCustom pmc)
        {
            IProductItemImplMgr _proItem = new ProductItemMgr(connectionString);
            List<ProductItem> resultList = _proItem.Query(pmc);
            List<ProductItemMapCustom> pimcs = new List<ProductItemMapCustom>();
            int i=1;
            foreach (var item in resultList)
            {
                var p = new ProductItemMapCustom();
                p.channel_detail_id = pmc.product_id + ((resultList.Count > 1) ? ("-" + i) : "");//如果該商品只有一個子項,則不拼接序號
                p.product_name = pmc.product_name + ((item.Spec_Name_1 == "" && item.Spec_Name_2 == "") ? "" : ("-" + item.Spec_Name_1 + item.Spec_Name_2));
                p.product_id = pmc.product_id;
                p.group_item_id = item.Item_Id.ToString() ;
                p.product_price = pmc.price;
                p.product_cost = pmc.cost;

                p.site_id = pmc.site_id;
                p.user_level = pmc.user_level;
                p.user_id = pmc.user_id;
                pimcs.Add(p);
                i++;
            }
            return pimcs;
        }
 public ActionResult QueryItemId()///add by wwei0216w 2015/8/12
 {
     string itemIdStr = "";
     string requestProduct_id = Request["product_id"];
     int product_id = requestProduct_id == null ? 0 : Convert.ToInt32(requestProduct_id);
     List<ProductItem> productItem_list = new List<ProductItem>();
     try
     {
         IProductItemImplMgr _productItemMgr = new ProductItemMgr(connectionString);
         productItem_list = _productItemMgr.GetProductItemByID(product_id);
         if (productItem_list.Count == 0)  return Json(new { itemIds = itemIdStr});
         foreach (ProductItem pi in productItem_list)
         {
             itemIdStr += pi.Item_Id + ",";
         }
         itemIdStr = itemIdStr.Remove(itemIdStr.ToString().Length - 1, 1);
         return Json(new { itemIds = itemIdStr});
     }
     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 new EmptyResult();
     }
 }
Beispiel #7
0
        /// <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 HttpResponseBase GetWaitLiaoWeiList()// createTime 2015/10/19 by yachao1120j
        {
            string json = string.Empty;
            int totalcount = 0;
            ProductItemQuery query = new ProductItemQuery();
            query.Start = Convert.ToInt32(Request.Params["start"] ?? "0");
            query.Limit = Convert.ToInt32(Request.Params["limit"] ?? "25");
            productitemMgr = new ProductItemMgr(mySqlConnectionString);

            if (!string.IsNullOrEmpty(Request.Params["product_mode"]))
            {
                query.product_mode = Convert.ToInt32(Request.Params["product_mode"]);//出貨方式
            }
            if (!string.IsNullOrEmpty(Request.Params["freight"]))
            {
                query.product_freight_set = Convert.ToUInt32(Request.Params["freight"]);//溫層
            }
            //if (!string.IsNullOrEmpty(Request.Params["product_status"]))
            //{
            //    query.product_status = Convert.ToUInt32(Request.Params["product_status"]);//商品状态
            //}
            if (!string.IsNullOrEmpty(Request.Params["start_time"]))//開始時間
            {
                //query.start_time = Convert.ToDateTime(Request.Params["start_time"]).ToString("yyyy-MM-dd 00:00:00");
                query.start_time = (int)CommonFunction.GetPHPTime(Convert.ToDateTime(Request.Params["start_time"]).ToString("yyyy-MM-dd HH:mm:ss"));
            }
            if (!string.IsNullOrEmpty(Request.Params["end_time"]))//結束時間
            {
                //query.end_time = Convert.ToDateTime(Request.Params["end_time"]).ToString("yyyy-MM-dd 23:59:59");
                query.end_time = (int)CommonFunction.GetPHPTime(Convert.ToDateTime(Request.Params["end_time"]).ToString("yyyy-MM-dd HH:mm:ss"));
            }
            List<ProductItemQuery> list = productitemMgr.GetWaitLiaoWeiList(query, out totalcount);
            IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
            timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
            json = "{success:true,totalCount:" + totalcount + ",data:" + JsonConvert.SerializeObject(list, Formatting.Indented, timeConverter) + "}";
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return Response;

        }
        //匯出 等待料位報表
        public void ExportCSV() // createTime 2015/10/21 by yachao1120j
        {
            ProductItemQuery query = new ProductItemQuery();
            try
            {
                if (!string.IsNullOrEmpty(Request.Params["product_mode"]))
                {
                    query.product_mode = Convert.ToInt32(Request.Params["product_mode"]);//出貨方式
                }
                if (!string.IsNullOrEmpty(Request.Params["freight"]))
                {
                    query.product_freight_set = Convert.ToUInt32(Request.Params["freight"]);//溫層
                }
                //if (!string.IsNullOrEmpty(Request.Params["product_status"]))
                //{
                //    query.product_status = Convert.ToUInt32(Request.Params["product_status"]);//商品状态
                //}
                if (!string.IsNullOrEmpty(Request.Params["start_time"]))//開始時間
                {
                    //query.start_time = Convert.ToDateTime(Request.Params["start_time"]).ToString("yyyy-MM-dd 00:00:00");
                    query.start_time = (int)CommonFunction.GetPHPTime(Convert.ToDateTime(Request.Params["start_time"]).ToString("yyyy-MM-dd HH:mm:ss"));
                }
                if (!string.IsNullOrEmpty(Request.Params["end_time"]))//結束時間
                {
                    //query.end_time = Convert.ToDateTime(Request.Params["end_time"]).ToString("yyyy-MM-dd 23:59:59");
                    query.end_time = (int)CommonFunction.GetPHPTime(Convert.ToDateTime(Request.Params["end_time"]).ToString("yyyy-MM-dd HH:mm:ss"));
                }
                DataTable dtHZ = new DataTable();
                int totalcount = 0;
                query.IsPage = false;
                string newExcelName = string.Empty;
                dtHZ.Columns.Add("料位編號", typeof(String));
                dtHZ.Columns.Add("商品細項編號", typeof(String));
                dtHZ.Columns.Add("商品名稱", typeof(String));
                dtHZ.Columns.Add("商品規格", typeof(String));
                dtHZ.Columns.Add("商品類型", typeof(String));
                dtHZ.Columns.Add("分類--大類", typeof(String));
                dtHZ.Columns.Add("分類--小類", typeof(String));
                dtHZ.Columns.Add("商品狀態", typeof(String));
                dtHZ.Columns.Add("出貨方式", typeof(String));
                dtHZ.Columns.Add("溫層", typeof(String));
                dtHZ.Columns.Add("商品建立日期", typeof(String));
                dtHZ.Columns.Add("商品上架時間", typeof(String));
                dtHZ.Columns.Add("採購單單號", typeof(String));
                productitemMgr = new ProductItemMgr(mySqlConnectionString);
                List<ProductItemQuery> list = productitemMgr.GetWaitLiaoWeiList(query, out totalcount);
                if (list.Count > 0)
                {
                    for (int i = 0; i < list.Count; i++)
                    {
                        DataRow dr = dtHZ.NewRow();
                        dr[0] = list[i].plas_id_string;
                        dr[1] = list[i].item_id;
                        dr[2] = list[i].product_name;
                        dr[3] = list[i].product_spec;
                        dr[4] = list[i].combination_string;
                        dr[5] = list[i].product_fenlei_dalei;
                        dr[6] = list[i].product_fenlei_xiaolei;
                        dr[7] = list[i].product_status_string;
                        dr[8] = list[i].product_mode_string;
                        dr[9] = list[i].product_freight_set_string;
                        dr[10] = list[i].product_createdate_string;
                        dr[11] = list[i].product_start_string;
                        dr[12] = list[i].po_id;
                        dtHZ.Rows.Add(dr);
                    }
                    string fileName = "等待料位報表匯出_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";
                    MemoryStream ms = ExcelHelperXhf.ExportDT(dtHZ, "");
                    Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
                    Response.BinaryWrite(ms.ToArray());
                }
                else
                {
                    Response.Clear();
                    this.Response.Write("無數據存在<br/>");
                }

            }
            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);

            }
        }
Beispiel #10
0
        private DateTime GetArriveTimeCombo(string dateTime,out int msgFlag, string itemIds = "")
        {
            /*定義變量*/
            DateTime lastDateTime = DateTime.Now;///變量,用於保存最晚商品到達時間
            int numDays = 0;///用於保存最晚商品途中運輸天數,
            int diffDay = 0;///用於保存最晚商品天數差的變量
            int expendDay = 0;///用於保存最晚商品到達用戶手中總共的天數
            DateTime implementTime = DateTime.Now;///定義變量 用於表示排程開始時間
            DateTime date = DateTime.MinValue;///定義變量 用於表示排程是否執行成功
            DateTime payDay = DateTime.Now;///定義初始化下單時間
            int deliver_Days = 0;    
            bool isSchedule = true;///定義變量 用於判斷是否是按排程時間出貨
            string msg = "";///定義變量 用於表示錯誤的具體信息
            DateTime dtTime = DateTime.Now;
            int days = 0;///定義變量 用於表示貨物途中運輸所需要的天數
            int itemIdFlag = 0;///用於判斷循環中 是否所有的pi是否都為空,如果都為null則itemIdFlag =0;否則為1;

            /*
             實例化對象
             */
            _srMgr = new ScheduleRelationMgr(connectionString);
            ProductItemCustom pi = new ProductItemCustom();
            IProductItemImplMgr _productItemMgr = new ProductItemMgr(connectionString);
            IOrderDetailImplMgr _orderDetailMgr = new OrderDetailMgr(connectionString);
            IProductImplMgr _pMgr = new ProductMgr(connectionString);


            ///邏輯計算
            try
            {
                if (!string.IsNullOrEmpty(dateTime))///如果時間不正確,直接返回時間錯誤
                {
                    if (!DateTime.TryParse(dateTime, out dtTime))
                    {
                        msgFlag = -1;///錯誤變量 -1:TimeException!
                        return DateTime.MinValue;
                    }
                }

                payDay = dtTime == null ? implementTime : (DateTime)dtTime;///得到下單時間


                string[] itemIdsArray = itemIds.Split(',');
                if (itemIds == "" || itemIdsArray.Length==0)
                {
                    msgFlag = -3;
                    return DateTime.Now;
                }

                foreach (string i in itemIdsArray)
                {
                    //pi = _productItemMgr.GetProductArriveDay(new ProductItem { Product_Id = i }, "product");///獲得prdocut_item中的array_days
                   
                    if (i != null)
                    {
                        itemIdFlag = 1;
                        pi = _productItemMgr.GetProductArriveDay(new ProductItem { Item_Id = Convert.ToUInt32(i) }, "item");//得到product_item中的出貨天數
                        deliver_Days = _pMgr.GetDefaultArriveDays(new Product { Product_Id = pi.Product_Id });///獲取供應商所對應的出貨天數
                        days = pi.Arrive_Days + deliver_Days;///獲得貨物運輸途中所需要的天數
                        date = _srMgr.GetRecentlyTime(Convert.ToInt32(pi.Product_Id), "product");///調用GetRecentlyTime()方法 獲得最近出貨時間
                        long tsDate = CommonFunction.GetPHPTime(DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss")) - (CommonFunction.GetPHPTime(date.ToString("yyyy/MM/dd hh:mm:ss")) + 10800);
                        ///獲得的最近出貨時間默認為12:00 加上10800 代碼再加3小時 代表 15:00 作為一天是否有效的標準判斷
                        if (date == DateTime.MinValue || date == null || tsDate > 0)///如果得到的最近出貨天數  為最小時間   或者   小于當前時間
                        {
                            isSchedule = false;
                            date = payDay;///則按下單時間開始計算到貨日期
                        }
                        TimeSpan ts = date - payDay; ///預計出貨天數 - 下單時間(中間購買者要等的時間)
                        expendDay = ts.Days + days;///(總共用戶要等的天數)
                        if (expendDay > diffDay)
                        {
                            diffDay = expendDay;
                            lastDateTime = date;///最終確定的出貨時間
                            numDays = days;///運輸天數
                        }
                    }
                }
                if (itemIdFlag == 0)
                {
                    msgFlag = -4;
                    return DateTime.MinValue;
                }
                lastDateTime = restDay(lastDateTime, payDay, numDays, isSchedule);///計算具體到貨日期
                msgFlag = 1;///正確返回結果
                return lastDateTime;
            }
            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);
                msg = ex.Message;
                msgFlag = -2;///錯誤變量 -2:其他錯誤異常!請參考系統錯誤日誌
                return DateTime.MinValue;
            }
        }
Beispiel #11
0
        /// <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;
        }
Beispiel #12
0
        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;
        }
Beispiel #13
0
        /// <summary>
        /// 合作外站商品查詢
        /// </summary>
        /// <returns></returns>
        public HttpResponseBase OrderInfoQueryByCooperator()
        {
            string jsonStr = "{success:false}";
            string pid = Request.Params["pid"] ?? "";
            uint channelId = 0;
            UInt32.TryParse(Request.Params["channelId"] ?? "0", out channelId);
            if (!string.IsNullOrEmpty(pid))
            {
                IProductItemMapImplMgr _pMapMgr = new ProductItemMapMgr(connectionString);
                IProductItemImplMgr _proItemMgr = new ProductItemMgr(connectionString);
                try
                {
                    ProductItemMap pMap = new ProductItemMap();

                    pMap.channel_detail_id = pid;
                    pMap.channel_id = channelId;
                    List<ProductItemMap> pMapList = _pMapMgr.QueryAll(pMap);
                    IPriceMasterImplMgr priceMgr = new PriceMasterMgr(connectionString);
                    IProductItemImplMgr _itemMgr = new ProductItemMgr(connectionString);
                    PriceMaster priceMap = priceMgr.QueryPriceMaster(new PriceMaster { price_master_id = pMapList.FirstOrDefault().price_master_id });
                    if (pMapList.Count() == 0)
                    {
                        jsonStr = "{success:false}";
                        this.Response.Clear();
                        this.Response.Write(jsonStr);
                        this.Response.End();
                        return this.Response;
                    }
                    uint product_id = pMapList[0].product_id;
                    if (product_id == 0)
                    {
                        product_id = _itemMgr.Query(new ProductItem { Item_Id = uint.Parse(pMapList[0].item_id.ToString()) }).FirstOrDefault().Product_Id;
                    }

                    IProductImplMgr _proMgr = new ProductMgr(connectionString);
                    Product prod = _proMgr.Query(new Product { Product_Id = product_id }).FirstOrDefault();

                    //判断商品是否上架
                    // long ltime = BLL.gigade.Common.CommonFunction.GetPHPTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));

                    if (prod.Combination != 1 && prod.Combination != 0)
                    {
                        OrderComboAddCustom orderAdd = _proMgr.OrderQuery(new Product { Product_Id = product_id }, priceMap.user_level, priceMap.user_id, priceMap.site_id);
                        orderAdd.product_id = 0;
                        orderAdd.out_product_id = pMapList[0].channel_detail_id;
                        orderAdd.product_name = pMapList[0].product_name;
                        orderAdd.product_cost = pMapList[0].product_price;
                        jsonStr = "{success:true";
                        string price_scale = "", cost_scale = "";
                        //查詢子商品信息
                        _prodCombMgr = new ProductComboMgr(connectionString);
                        List<ProductComboCustom> prodComList = _prodCombMgr.combQuery(new ProductComboCustom { Parent_Id = int.Parse(product_id.ToString()) });

                        IPriceMasterImplMgr pMgr = new PriceMasterMgr(connectionString);
                        PriceMaster query = new PriceMaster { user_id = priceMap.user_id, user_level = priceMap.user_level, site_id = priceMap.site_id };

                        jsonStr += ",child:[";
                        double childTotalPrice = 0;
                        double childTotalCost = 0;
                        string[] itemList = pMapList[0].group_item_id.ToString().Split(',');
                        foreach (var item in prodComList)
                        {
                            #region 計算子商品總價

                            for (int i = 0; i < itemList.Length; i++)
                            {
                                //在item_price中查找該itemid對應的價格
                                IItemPriceImplMgr iPMgr = new ItemPriceMgr(connectionString);

                                if (prod.Price_type == 1)
                                {
                                    query.product_id = uint.Parse(item.Child_Id.ToString());
                                    query.child_id = 0;
                                }
                                else if (prod.Price_type == 2)
                                {
                                    query.product_id = prod.Product_Id;
                                    query.child_id = int.Parse(item.Child_Id.ToString());
                                }


                                PriceMaster pM = priceMgr.QueryPriceMaster(query);
                                List<ItemPriceCustom> ipList = new List<ItemPriceCustom>();

                                //查詢子商品詳細信息(規格,庫存)
                                ProductItem pItem = new ProductItem();
                                pItem.Item_Id = uint.Parse(itemList[i]);
                                pItem.Product_Id = uint.Parse(item.Child_Id.ToString());
                                List<ProductItem> pItemList = _proItemMgr.Query(pItem);

                                if (pM != null && pItemList.Count > 0)
                                {
                                    //查找外站商品必購數量
                                    IProductMapSetImplMgr msMgr = new ProductMapSetMgr(connectionString);
                                    List<ProductMapSet> mSetList = msMgr.Query(new ProductMapSet { map_rid = uint.Parse(pMapList[0].rid.ToString()), item_id = uint.Parse(itemList[i]) });
                                    if (pM.same_price == 1)
                                    {
                                        childTotalPrice += int.Parse((pM.price * mSetList[0].set_num).ToString());
                                        childTotalCost += int.Parse((pM.cost * mSetList[0].set_num).ToString());
                                    }
                                    else
                                    {
                                        ipList = iPMgr.Query(new ItemPrice
                                        {
                                            item_id = uint.Parse(itemList[i]),
                                            price_master_id = pM.price_master_id
                                        });
                                        if (ipList.Count != 0)
                                        {
                                            if (mSetList.Count == 1)
                                            {
                                                childTotalPrice += int.Parse((ipList[0].item_money * mSetList[0].set_num).ToString());
                                                childTotalCost += int.Parse((ipList[0].item_cost * mSetList[0].set_num).ToString());
                                            }
                                            else
                                            {
                                                //在item_price中未查出對應價格
                                                this.Response.Clear();
                                                this.Response.Write("{success:false,msg:'" + Resources.OrderAdd.COMBO_CHILD_PRICE_NULL + "'}");
                                                this.Response.End();
                                                return this.Response;
                                            }
                                        }
                                    }
                                }


                            }
                            #endregion
                        }

                        double beforePrice = 0;
                        double beforeCost = 0;
                        int minStock = 0;
                        int index = 0;
                        double comboPrice = orderAdd.product_cost;
                        int curIndex = 0;
                        foreach (var item in prodComList)
                        {
                            curIndex++;
                            OrderAddCustom oc = new OrderAddCustom();
                            List<Product> pList = _proMgr.Query(new Product { Product_Id = uint.Parse(item.Child_Id.ToString()) });
                            oc.price_type = prod.Price_type;
                            oc.Product_Id = uint.Parse(item.Child_Id.ToString());
                            oc.ignore_stock = pList[0].Ignore_Stock;
                            oc.newparent_id = pMapList[0].channel_detail_id;
                            //補貨中是否還能販賣
                            if (pList.FirstOrDefault().Shortage == 1)
                            {
                                this.Response.Clear();
                                this.Response.Write("{success:false,msg:'" + Resources.OrderAdd.SHPRT_AGE + "'}");
                                this.Response.End();
                                return this.Response;
                            }
                            //讀取product_name
                            if (prod.Price_type == 1)
                            {
                                query.product_id = oc.Product_Id;
                                query.child_id = 0;
                            }
                            else if (prod.Price_type == 2)
                            {
                                query.product_id = prod.Product_Id;
                                query.child_id = Convert.ToInt32(oc.Product_Id);
                            }
                            PriceMaster pm = pMgr.QueryPriceMaster(query);
                            if (pm != null)
                            {
                                oc.product_name = pm.product_name;
                            }


                            for (int i = 0; i < itemList.Length; i++)
                            {
                                //查詢子商品詳細信息(規格,庫存)
                                ProductItem pItem = new ProductItem();
                                pItem.Item_Id = uint.Parse(itemList[i]);
                                pItem.Product_Id = uint.Parse(item.Child_Id.ToString());
                                oc.Item_Id = pItem.Item_Id;
                                List<ProductItem> pItemList = _proItemMgr.Query(pItem);
                                if (pItemList.Count() != 0)
                                {
                                    index++;

                                    //在item_price中查找該itemid對應的價格
                                    IItemPriceImplMgr iPMgr = new ItemPriceMgr(connectionString);
                                    List<ItemPriceCustom> ipList = new List<ItemPriceCustom>();
                                    if (pm != null)
                                    {
                                        oc.price_master_id = pm.price_master_id;
                                        //查找外站商品必購數量
                                        IProductMapSetImplMgr msMgr = new ProductMapSetMgr(connectionString);
                                        List<ProductMapSet> mSetList = msMgr.Query(new ProductMapSet { map_rid = uint.Parse(pMapList[0].rid.ToString()), item_id = uint.Parse(itemList[i]) });
                                        if (mSetList.Count != 0)
                                        {
                                            oc.s_must_buy = int.Parse(mSetList[0].set_num.ToString());
                                        }
                                        if (prod.Price_type == 1)
                                        {
                                            #region 按比例拆分


                                            if (i == itemList.Length - 1 && curIndex == prodComList.Count)
                                            {
                                                oc.product_cost = uint.Parse(CommonFunction.Math4Cut5Plus((orderAdd.product_cost - beforePrice) / oc.s_must_buy).ToString());
                                                oc.Item_Cost = uint.Parse(CommonFunction.Math4Cut5Plus((orderAdd.cost - beforeCost) / oc.s_must_buy).ToString());

                                            }
                                            else
                                            {
                                                double price = 0.0;
                                                double cost = 0.0;
                                                string price_res = "0";
                                                string cost_res = "0";
                                                double price_result = 0.0;
                                                double cost_result = 0.0;

                                                //规格同价
                                                if (pm.same_price == 1)
                                                {
                                                    if (childTotalPrice != 0)
                                                    {
                                                        double singlePrice = double.Parse((pm.price * oc.s_must_buy).ToString());
                                                        double totalPrice = childTotalPrice;
                                                        double c_scale = singlePrice / totalPrice;
                                                        price = orderAdd.product_cost * c_scale / oc.s_must_buy;
                                                        price_result = CommonFunction.Math4Cut5Plus(price);
                                                        price_res = c_scale.ToString();
                                                    }
                                                    beforePrice += price_result;
                                                    oc.product_cost = uint.Parse(price_result.ToString());
                                                    price_scale += price_res + ",";

                                                    if (childTotalCost != 0)
                                                    {
                                                        double singleCost = double.Parse((pm.cost * oc.s_must_buy).ToString());
                                                        double totalCost = childTotalCost;
                                                        double c_scale = singleCost / totalCost;
                                                        cost = orderAdd.cost * c_scale / oc.s_must_buy;
                                                        cost_result = CommonFunction.Math4Cut5Plus(cost);
                                                        cost_res = c_scale.ToString();
                                                    }
                                                    beforeCost += cost_result;
                                                    oc.Item_Cost = uint.Parse(cost_result.ToString());
                                                    cost_scale += cost_res + ",";


                                                }
                                                else
                                                {
                                                    ipList = iPMgr.Query(new ItemPrice
                                                    {
                                                        item_id = uint.Parse(itemList[i]),
                                                        price_master_id = pm.price_master_id
                                                    });
                                                    if (ipList.Count != 0)
                                                    {
                                                        if (childTotalPrice != 0)
                                                        {
                                                            double singlePrice = double.Parse((ipList[0].item_money * oc.s_must_buy).ToString());
                                                            double totalPrice = childTotalPrice;
                                                            double c_scale = singlePrice / totalPrice;
                                                            price = orderAdd.product_cost * c_scale / oc.s_must_buy;
                                                            price_result = CommonFunction.Math4Cut5Plus(price);
                                                            price_res = c_scale.ToString();
                                                        }
                                                        beforePrice += price_result;
                                                        oc.product_cost = uint.Parse(price_result.ToString());
                                                        price_scale += price_res + ",";

                                                        if (childTotalCost != 0)
                                                        {
                                                            double singleCost = double.Parse((ipList[0].item_cost * oc.s_must_buy).ToString());
                                                            double totalCost = childTotalCost;
                                                            double c_scale = singleCost / totalCost;
                                                            cost = orderAdd.cost * c_scale / oc.s_must_buy;
                                                            cost_result = CommonFunction.Math4Cut5Plus(cost);
                                                            cost_res = c_scale.ToString();
                                                        }
                                                        beforeCost += cost_result;
                                                        oc.Item_Cost = uint.Parse(cost_result.ToString());
                                                        cost_scale += cost_res + ",";
                                                    }
                                                }
                                            }
                                            #endregion
                                        }
                                        else if (prod.Price_type == 2)
                                        {
                                            #region 各自定價

                                            ipList = iPMgr.Query(new ItemPrice { item_id = uint.Parse(itemList[i]), price_master_id = pm.price_master_id });
                                            if (ipList.FirstOrDefault() != null)
                                            {
                                                oc.product_cost = ipList.FirstOrDefault().item_money;
                                            }
                                            #endregion
                                        }
                                    }


                                    if (index == 1)
                                    {
                                        minStock = oc.s_must_buy > 0 ? Convert.ToInt32(pItemList[0].Item_Stock / oc.s_must_buy) : pItemList[0].Item_Stock;
                                    }
                                    oc.Item_Stock = pItemList[0].Item_Stock;
                                    int tmp_stock = oc.s_must_buy > 0 ? Convert.ToInt32(oc.Item_Stock / oc.s_must_buy) : oc.Item_Stock;
                                    if (tmp_stock < minStock)
                                    {
                                        minStock = tmp_stock;
                                    }
                                    //根據spec_id找出spec_name
                                    IProductSpecImplMgr _specMgr = new BLL.gigade.Mgr.ProductSpecMgr(connectionString);
                                    ProductSpec ps1 = _specMgr.query(int.Parse(pItemList[0].Spec_Id_1.ToString()));
                                    if (ps1 != null)
                                    {
                                        oc.Spec_Name_1 = ps1.spec_name;
                                        oc.Spec_Id_1 = ps1.spec_id;
                                    }
                                    ProductSpec ps2 = _specMgr.query(int.Parse(pItemList[0].Spec_Id_2.ToString()));
                                    if (ps2 != null)
                                    {
                                        oc.Spec_Name_2 = ps2.spec_name;
                                        oc.Spec_Id_2 = ps2.spec_id;
                                    }
                                    jsonStr += "{";
                                    jsonStr += "'product_id':'" + oc.Product_Id + "','product_name':'" + oc.product_name + "','item_id':'" + oc.Item_Id + "'";
                                    jsonStr += ",'spec1':'" + oc.Spec_Id_1 + "','spec2':'" + oc.Spec_Id_2 + "','spec1_show':'" + oc.Spec_Name_1 + "',s_must_buy:'" + oc.s_must_buy + "'";
                                    jsonStr += ",'spec2_show':'" + oc.Spec_Name_2 + "','product_cost':'" + oc.product_cost + "',Item_Cost:'" + oc.Item_Cost + "','stock':'" + oc.Item_Stock + "',price_master_id:" + oc.price_master_id;
                                    jsonStr += ",price_type:" + oc.price_type + ",ignore_stock:" + oc.ignore_stock;
                                    if (oc.parent_id != 0)
                                    {
                                        jsonStr += ",parent_id:'" + oc.parent_id + "'";
                                    }
                                    else
                                    {
                                        jsonStr += ",parent_id:'" + oc.newparent_id + "'";
                                    }
                                    jsonStr += "},";
                                }
                            }
                        }
                        if (price_scale != "")
                        {
                            price_scale = price_scale.Substring(0, price_scale.Length - 1);
                        }
                        jsonStr = jsonStr.Substring(0, jsonStr.Length - 1) + "]";
                        jsonStr += ",data:[";
                        jsonStr += "{product_id:'" + orderAdd.out_product_id + "',item_id:0,product_name:'" + orderAdd.product_name + "',product_cost:'" + orderAdd.product_cost + "'";
                        jsonStr += ",s_must_buy:'" + pMapList[0].group_item_id.ToString().Split(',').Length + "',Item_Cost:'" + orderAdd.cost + "',child_cost_scale:'" + cost_scale + "',child_scale:'" + price_scale + "',stock:'" + minStock + "',g_must_buy:'" + pMapList[0].group_item_id.ToString().Split(',').Length + "'}]}";


                    }
                    else
                    {
                        if (prod.Combination == 0)
                        {
                            jsonStr = "{success:false,msg:\"" + Resources.OrderAdd.PRODUCT_NOT_USE_IN_ORDER + "\"}";
                            this.Response.Clear();
                            this.Response.Write(jsonStr);
                            this.Response.End();
                            return this.Response;
                        }
                        else
                        {
                            //單一商品
                            ProductItem pItem = new ProductItem();
                            pItem.Item_Id = UInt32.Parse(pMapList[0].item_id.ToString());


                            List<ProductItem> pItemList = _proItemMgr.Query(pItem);
                            List<Product> pList = _proMgr.Query(new Product { Product_Id = uint.Parse(pItemList[0].Product_Id.ToString()) });
                            //補貨時還能販賣
                            if (pList[0].Shortage == 1)
                            {
                                this.Response.Clear();
                                this.Response.Write("{success:false,msg:'" + Resources.OrderAdd.SHPRT_AGE + "'}");
                                this.Response.End();
                                return this.Response;
                            }
                            if (pItemList.Count() == 0)
                            {
                                jsonStr = "{success:false}";
                                this.Response.Clear();
                                this.Response.Write(jsonStr);
                                this.Response.End();
                                return this.Response;
                            }


                            List<OrderAddCustom> oalist = new List<OrderAddCustom>();

                            OrderAddCustom oc = new OrderAddCustom();

                            oc.Spec_Id_1 = pItemList[0].Spec_Id_1;
                            oc.Spec_Id_2 = pItemList[0].Spec_Id_2;
                            oc.Item_Stock = pItemList[0].Item_Stock;
                            oc.ignore_stock = pList[0].Ignore_Stock;

                            IProductSpecImplMgr _specMgr = new BLL.gigade.Mgr.ProductSpecMgr(connectionString);
                            ProductSpec spec1 = _specMgr.query(Convert.ToInt32(pItemList[0].Spec_Id_1));
                            ProductSpec spec2 = _specMgr.query(Convert.ToInt32(pItemList[0].Spec_Id_2));
                            if (spec1 != null)
                            {
                                oc.Spec_Name_1 = spec1.spec_name;
                            }
                            if (spec2 != null)
                            {
                                oc.Spec_Name_2 = spec2.spec_name;
                            }

                            oalist.Add(oc);

                            StringBuilder stb = new StringBuilder();

                            stb.Append("[");
                            stb.Append("{product_id:'" + pMapList[0].channel_detail_id + "',item_id:" + pMapList[0].item_id + ",product_name:'" + HttpUtility.HtmlEncode(pMapList[0].product_name) + "',spec1:'" + oc.Spec_Id_1.ToString() + "',");
                            stb.Append("spec2:'" + oc.Spec_Id_2.ToString() + "',spec1_show:'" + oc.Spec_Name_1 + "',spec2_show:'" + oc.Spec_Name_2 + "',product_cost:" + pMapList[0].product_price + ",");
                            stb.Append("stock:" + oc.Item_Stock + ",price_master_id:" + oc.price_master_id + ",ignore_stock:" + oc.ignore_stock + "}");
                            stb.Append("]");

                            jsonStr = "{success:true,data:" + stb.ToString() + "}";
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                    logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                    logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                    log.Error(logMessage);
                }
            }
            else
            {
                jsonStr = "{success:true,data:{product_id:''}}";
            }

            this.Response.Clear();
            this.Response.Write(jsonStr);
            this.Response.End();
            return this.Response;
        }
        public HttpResponseBase GetProductName()
        {
            ProductItemQuery pItem = new ProductItemQuery();
            if (!string.IsNullOrEmpty(Request.Params["item_id"]))
            {
                pItem.Item_Id = uint.Parse(Request.Params["item_id"]);
            }


            productItemMgr = new ProductItemMgr(mySqlConnectionString);
            string jsonStr = string.Empty;

            try
            {
                List<ProductItemQuery> ItemList = new List<ProductItemQuery>();
                ItemList = productItemMgr.GetProductItemByID(pItem);
                if (ItemList.Count > 0)
                {
                    jsonStr = "{success:true,msg:\"[" + ItemList[0].Product_Id + "]" + ItemList[0].Remark +" "+ ItemList[0].Spec_Name_1 + ItemList[0].Spec_Name_2 + "\",product_id:\"" + ItemList[0].Product_Id + "\"}";
                }
                else
                {
                    jsonStr = "{success:true,msg:\"" + 100 + "\"}";
                }
            }
            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);
                jsonStr = "{success:false}";
            }
            this.Response.Clear();
            this.Response.Write(jsonStr);
            this.Response.End();
            return this.Response;
        }