public string DeleteProductRemoveReason(ProductRemoveReason prr) { try { return _iproductRemoveReason.DeleteProductRemoveReason(prr); } catch (Exception ex) { throw new Exception("ProductRemoveReasonMgr-->DeleteProductRemoveReason-->" + ex.Message, ex); } }
public string DeleteProductRemoveReason(ProductRemoveReason prr) { StringBuilder sb = new StringBuilder(); sb.AppendFormat(@"set sql_safe_updates = 0;delete from product_remove_reason where product_id='{0}';set sql_safe_updates = 1;", prr.product_id); //獲取到上架商品庫存<=0,並且排除掉庫存為0可販賣機暫停售賣的商品 try { return sb.ToString(); } catch (Exception ex) { throw new Exception("ProductRemoveReasonDao.InsertProductRemoveReason-->" + ex.Message + sb.ToString(), ex); } }
public string InsertProductRemoveReason(ProductRemoveReason prr) { StringBuilder sb = new StringBuilder(); sb.AppendFormat(@"insert into product_remove_reason(product_id,product_num,create_name,create_time)values('{0}','{1}','{2}','{3}');",prr.product_id,prr.product_num,prr.create_name,prr.create_time); //獲取到上架商品庫存<=0,並且排除掉庫存為0可販賣機暫停售賣的商品 try { return sb.ToString(); } catch (Exception ex) { throw new Exception("ProductRemoveReasonDao.InsertProductRemoveReason-->" + ex.Message + sb.ToString(), ex); } }
public string SetProductRmoveDown() { int resultone = 0; int resulttwo = 0; int resultthree = 0; string startRunInfo = ""; string endRunInfo = ""; try { //if (Request.Url.Host == "mng.gigade100.com")//判断是否为正式线 //{ // return "{success:false,data:'',msg:'未驗收,暫不執行!'}"; //} //else //{ startRunInfo = DateTime.Now.ToString() + ": SetProductRmoveDown Start"; _proRemoveMgr = new ProductRemoveReasonMgr(connectionString); ProductRemoveReason prr = new ProductRemoveReason(); ProductRemoveReason prrtwo = new ProductRemoveReason(); Product pt = new Product(); ProductStatusHistory psh = new ProductStatusHistory(); #region 往临时表中插入数据/或者更新数据 sql可以统一执行 //獲取到上架商品庫存<=0,並且排除掉庫存為0可販賣機暫停售賣的商品 DataTable _dt = _proRemoveMgr.GetStockLessThanZero(); //获取到临时表中的数据 DataTable _dttwo = _proRemoveMgr.GetProductRemoveReasonList(); //判断临时表是否存在,如果不存在,则插入数据 StringBuilder str = new StringBuilder(); if (_dt.Rows.Count > 0) { for (int i = 0; i < _dt.Rows.Count; i++) { DataRow[] dr = _dttwo.Select("product_id=" + _dt.Rows[i]["product_id"]); if (dr.Length <= 0)//小于等于0 无需处理编辑数据,因为获取的库存都是等于或者小于0的 { prr.create_name = "system"; prr.create_time = Convert.ToInt32(CommonFunction.GetPHPTime(CommonFunction.DateTimeToString(DateTime.Now))); prr.product_id = Convert.ToUInt32(_dt.Rows[i]["product_id"]); prr.product_num = Convert.ToInt32(_dt.Rows[i]["item_stock"]); str.AppendFormat(_proRemoveMgr.InsertProductRemoveReason(prr)); } } } //获取出临时表中要删除的数据 DataTable _dtthree = _proRemoveMgr.GetDeleteProductRemoveReasonList(); for (int b = 0; b < _dtthree.Rows.Count; b++) { prr.product_id = Convert.ToUInt32(_dtthree.Rows[b]["product_id"]); str.AppendFormat(_proRemoveMgr.DeleteProductRemoveReason(prr)); } if (str.ToString().Length > 0) { resultone = _proRemoveMgr.ProductRemoveReasonTransact(str.ToString()); } else { resultone = 1; } #endregion #region 缺货商品下架 DataTable _dtNew = _proRemoveMgr.GetStockMsg(); StringBuilder strsql = new StringBuilder(); if (_dtNew.Rows.Count > 0) { for (int j = 0; j < _dtNew.Rows.Count; j++) { int time = Convert.ToInt32(_dtNew.Rows[j]["create_time"]); DateTime dttime = CommonFunction.GetNetTime(time); TimeSpan ts = DateTime.Now - dttime; prrtwo.product_id = Convert.ToUInt32(_dtNew.Rows[j]["product_id"]); pt.Product_Id = Convert.ToUInt32(_dtNew.Rows[j]["product_id"]); pt.Product_Status = 7;//7为缺货系统下架 psh.product_id = Convert.ToUInt32(_dtNew.Rows[j]["product_id"]); psh.user_id = 2; psh.create_time = DateTime.Now; psh.type = 9;//缺货系统下架 psh.product_status = 7; psh.remark = "系统账号插入"; if (ts.Days >= (_dtNew.Rows[j]["outofstock_days_stopselling"] == "" ? 0 : Convert.ToInt32(_dtNew.Rows[j]["outofstock_days_stopselling"])))//表示可以下架,执行下架工作 { //改变product表中商品的状态 strsql.AppendFormat(_proRemoveMgr.UpdateProductStatus(pt)); //网记录表中插入一条数据 strsql.AppendFormat(_proRemoveMgr.InsertIntoProductStatusHistory(psh)); //删除临时表中的数据 strsql.AppendFormat(_proRemoveMgr.DeleteProductRemoveReason(prrtwo)); } } } if (strsql.ToString().Length > 0) { resulttwo = _proRemoveMgr.ProductRemoveReasonTransact(strsql.ToString()); } else { resulttwo = 1; } #endregion #region 缺货商品状态改为申请审核 DataTable _dtOutofStock = _proRemoveMgr.GetOutofStockMsg(); StringBuilder strslqmsg = new StringBuilder(); StringBuilder strslqmsgtwo = new StringBuilder(); if (_dtOutofStock.Rows.Count > 0) { for (int z = 0; z < _dtOutofStock.Rows.Count; z++) { if (Convert.ToInt32(_dtOutofStock.Rows[z]["item_stock"]) > 0) { pt.Product_Id = Convert.ToUInt32(_dtOutofStock.Rows[z]["product_id"]); pt.Product_Status = 1;//1表示申请审核 _proRemoveMgr.UpdateProductStatus(pt); psh.product_id = Convert.ToUInt32(_dtOutofStock.Rows[z]["product_id"]); psh.user_id = 2; psh.create_time = DateTime.Now; psh.type = 1;//1表示申请审核 psh.product_status = 1;//申请审核 psh.remark = "系统账号插入"; strslqmsg.AppendFormat(_proRemoveMgr.UpdateProductStatus(pt)); strslqmsg.AppendFormat(_proRemoveMgr.InsertIntoProductStatusHistory(psh)); } prr.product_id = Convert.ToUInt32(_dtOutofStock.Rows[z]["product_id"]);//根据product_id删除数据 strslqmsgtwo.AppendFormat(_proRemoveMgr.DeleteProductRemoveReason(prr)); } } if (strslqmsg.ToString().Length > 0) { resultthree = _proRemoveMgr.ProductRemoveReasonTransact(strslqmsg.ToString() + strslqmsgtwo.ToString()); } else { if (strslqmsgtwo.ToString().Length > 0) { _proRemoveMgr.ProductRemoveReasonTransact(strslqmsgtwo.ToString()); } resultthree = 1; } #endregion if (resultone > 0 && resulttwo > 0 && resultthree > 0) { SaleStatus(); //DataTable _excelMsg = _proRemoveMgr.GetStockMsg(); //ExeclProductRmoveDownMsg(_excelMsg); endRunInfo = DateTime.Now.ToString() + ": SetProductRmoveDown End "; WriterInfo("SetProductRmoveDown-Success", startRunInfo, endRunInfo); return "{success:true}"; } else { endRunInfo = DateTime.Now.ToString() + ": SetProductRmoveDown End "; WriterInfo("SetProductRmoveDown-Fail", startRunInfo, endRunInfo); return "{success:false}"; } //} } 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); endRunInfo = DateTime.Now.ToString() + "SetProductRmoveDown: " + ex.Message; WriterInfo("SetProductRmoveDown", startRunInfo, endRunInfo); return "{success:false,data:'',msg:" + ex.Message + "}"; } }