/// <summary> /// 獲得最近出貨時間 /// </summary> /// <param name="v">關聯表的主鍵</param> /// <param name="relationType">關聯表的表名稱</param> /// <returns>error:MinValue success:CriterionTime</returns> public ActionResult ExpectTime(string t, int v = 0) { DateTime dtNow = DateTime.Now;///當前時間 int isSuccess = 1;//1:success 0: fail string Msg = ""; DateTime date = DateTime.MinValue; try { _srMgr = new ScheduleRelationMgr(connectionString); date = _srMgr.GetRecentlyTime(v, t); if (date == DateTime.MinValue) { isSuccess = 0; Msg = "該商品沒有預計出貨時間或出貨時間超出合理範圍"; } } 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); isSuccess = 0; Msg = "ExpectTime Exception!"; } DateTime functionEnd = DateTime.Now; TimeSpan ts = functionEnd - dtNow; double second = ts.TotalMilliseconds; return Json(new { data = date.ToString("yyyy/MM/dd"), success = isSuccess, errMsg = Msg,des ="最近出貨時間", execTime = dtNow.ToString("yyyy/MM/dd"), elapsed = second }, JsonRequestBehavior.AllowGet); }
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; } }