/// <summary> /// 增加一条数据 /// </summary> public int Add(Lebi_Agent_Product model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into [Lebi_Agent_Product]("); strSql.Append("User_id,User_UserName,Product_id)"); strSql.Append(" values ("); strSql.Append("@User_id,@User_UserName,@Product_id)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@User_id", model.User_id), new SqlParameter("@User_UserName", model.User_UserName), new SqlParameter("@Product_id", model.Product_id) }; object obj = SqlUtils.SqlUtilsInstance.TextExecuteNonQuery(strSql.ToString(), parameters); if (obj == null) { return(1); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 by SQLpara /// </summary> public Lebi_Agent_Product GetModel(SQLPara para) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 * from [Lebi_Agent_Product] "); if (para.Where != "") { strSql.Append(" where " + para.Where + ""); } Lebi_Agent_Product model = new Lebi_Agent_Product(); DataSet ds = SqlUtils.SqlUtilsInstance.TextExecuteDataset(strSql.ToString(), para.Para); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["id"].ToString() != "") { model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } if (ds.Tables[0].Rows[0]["User_id"].ToString() != "") { model.User_id = int.Parse(ds.Tables[0].Rows[0]["User_id"].ToString()); } model.User_UserName = ds.Tables[0].Rows[0]["User_UserName"].ToString(); if (ds.Tables[0].Rows[0]["Product_id"].ToString() != "") { model.Product_id = int.Parse(ds.Tables[0].Rows[0]["Product_id"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 添加代理商品 /// </summary> public void Product_Add() { SearchProduct sp = new SearchProduct(CurrentAdmin, CurrentLanguage.Code); List <Lebi_Product> models = B_Lebi_Product.GetList("Product_id=0 " + sp.SQL, ""); if (models.Count == 0) { Response.Write("{\"msg\":\"" + Tag("没有商品") + "\"}"); return; } Lebi_Agent_Product pro; string ids = ""; foreach (Lebi_Product model in models) { pro = B_Lebi_Agent_Product.GetModel("Product_id=" + model.id + ""); if (pro == null) { pro = new Lebi_Agent_Product(); pro.Product_id = model.id; B_Lebi_Agent_Product.Add(pro); ids += pro.id + ","; } } Log.Add("添加代理区商品", "Agent_Product", ids, CurrentAdmin, ""); Response.Write("{\"msg\":\"OK\"}"); }
/// <summary> /// 请求代理一个商品 /// </summary> public void Product_Request() { int id = RequestTool.RequestInt("id"); int oldid = RequestTool.RequestInt("oldid"); Lebi_Agent_Product apro = B_Lebi_Agent_Product.GetModel(id); if (apro == null) { Response.Write("{\"msg\":\"" + Tag("参数错误") + "\"}"); return; } if (apro.User_id > 0) { Response.Write("{\"msg\":\"" + Tag("参数错误") + "\"}"); return; } Lebi_Agent_Product_User user = B_Lebi_Agent_Product_User.GetModel("User_id=" + CurrentUser.id + ""); if (user == null) { user = new Lebi_Agent_Product_User(); } if (user.Count_product_change - user.Count_product_change_used < 1) { //验证是否超过可用的修改次数 Response.Write("{\"msg\":\"" + Tag("无权修改") + "\"}"); return; } if (oldid == 0 && B_Lebi_Agent_Product.Counts("User_id=" + CurrentUser.id + "") >= user.Count_Product) { //验证是否超过代理商品的上限 Response.Write("{\"msg\":\"" + Tag("不能申请更多商品") + "\"}"); return; } Lebi_Agent_Product_request model = B_Lebi_Agent_Product_request.GetModel("User_id=" + CurrentUser.id + " and Product_id=" + apro.Product_id + " and Type_id_AgentProductRequestStatus=370"); if (model != null) { Response.Write("{\"msg\":\"" + Tag("不能重复申请") + "\"}"); return; } model = new Lebi_Agent_Product_request(); model.Product_id = apro.Product_id; model.Type_id_AgentProductRequestStatus = 370; model.User_id = CurrentUser.id; model.User_UserName = CurrentUser.UserName; model.Product_id_old = oldid; B_Lebi_Agent_Product_request.Add(model); Response.Write("{\"msg\":\"OK\"}"); }
/// <summary> /// 安全方式绑定对象表单 /// </summary> public Lebi_Agent_Product SafeBindForm(Lebi_Agent_Product model) { if (HttpContext.Current.Request["User_id"] != null) { model.User_id = Shop.Tools.RequestTool.RequestInt("User_id", 0); } if (HttpContext.Current.Request["User_UserName"] != null) { model.User_UserName = Shop.Tools.RequestTool.RequestSafeString("User_UserName"); } if (HttpContext.Current.Request["Product_id"] != null) { model.Product_id = Shop.Tools.RequestTool.RequestInt("Product_id", 0); } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public void Update(Lebi_Agent_Product model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update [Lebi_Agent_Product] set "); strSql.Append("[User_id]=@User_id,"); strSql.Append("[User_UserName]=@User_UserName,"); strSql.Append("[Product_id]=@Product_id"); strSql.Append(" where id=" + model.id); OleDbParameter[] parameters = { new OleDbParameter("@User_id", model.User_id), new OleDbParameter("@User_UserName", model.User_UserName), new OleDbParameter("@Product_id", model.Product_id) }; AccessUtils.Instance.TextExecuteNonQuery(strSql.ToString(), parameters); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Lebi_Agent_Product model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into [Lebi_Agent_Product]("); strSql.Append("[User_id],[User_UserName],[Product_id])"); strSql.Append(" values ("); strSql.Append("@User_id,@User_UserName,@Product_id)"); OleDbParameter[] parameters = { new OleDbParameter("@User_id", model.User_id), new OleDbParameter("@User_UserName", model.User_UserName), new OleDbParameter("@Product_id", model.Product_id) }; AccessUtils.Instance.TextExecuteNonQuery(strSql.ToString(), parameters); return(1); }
/// <summary> /// 单品代理佣金 /// </summary> private void AgentProductMoney() { List <Lebi_Order_Product> Products = B_Lebi_Order_Product.GetList("Order_id=" + Order.id + "", ""); if (Products == null) { return; } int pid = 0; decimal money = 0; Lebi_Agent_Product_User auser; foreach (Lebi_Order_Product model in Products) { Lebi_Product pro = B_Lebi_Product.GetModel(model.Product_id); pid = pro.Product_id == 0 ? pro.id : pro.Product_id; Lebi_Agent_Product apro = B_Lebi_Agent_Product.GetModel("Product_id=" + pid + ""); if (apro == null) { continue; } auser = B_Lebi_Agent_Product_User.GetModel("User_id=" + apro.User_id + " and IsFailure=0"); if (auser == null) { continue; } if (auser.Time_end.Date < System.DateTime.Now.Date) { continue; } Lebi_User user = B_Lebi_User.GetModel(apro.User_id); if (user == null) { continue; } money = model.Price * model.Count * auser.Commission / 100; AddMoney(money, user, 392, 0, model.Product_id, pid, pro.Number); } }
/// <summary> /// 对象实体绑定数据 /// </summary> public Lebi_Agent_Product ReaderBind(IDataReader dataReader) { Lebi_Agent_Product model = new Lebi_Agent_Product(); object ojb; ojb = dataReader["id"]; if (ojb != null && ojb != DBNull.Value) { model.id = (int)ojb; } ojb = dataReader["User_id"]; if (ojb != null && ojb != DBNull.Value) { model.User_id = (int)ojb; } model.User_UserName = dataReader["User_UserName"].ToString(); ojb = dataReader["Product_id"]; if (ojb != null && ojb != DBNull.Value) { model.Product_id = (int)ojb; } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public void Update(Lebi_Agent_Product model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update [Lebi_Agent_Product] set "); strSql.Append("User_id= @User_id,"); strSql.Append("User_UserName= @User_UserName,"); strSql.Append("Product_id= @Product_id"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4), new SqlParameter("@User_id", SqlDbType.Int, 4), new SqlParameter("@User_UserName", SqlDbType.NVarChar, 50), new SqlParameter("@Product_id", SqlDbType.Int, 4) }; parameters[0].Value = model.id; parameters[1].Value = model.User_id; parameters[2].Value = model.User_UserName; parameters[3].Value = model.Product_id; SqlUtils.SqlUtilsInstance.TextExecuteNonQuery(strSql.ToString(), parameters); }
/// <summary> /// 得到一个对象实体 by id /// </summary> public Lebi_Agent_Product GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 * from [Lebi_Agent_Product] "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; Lebi_Agent_Product model = new Lebi_Agent_Product(); DataSet ds = SqlUtils.SqlUtilsInstance.TextExecuteDataset(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["id"].ToString() != "") { model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } if (ds.Tables[0].Rows[0]["User_id"].ToString() != "") { model.User_id = int.Parse(ds.Tables[0].Rows[0]["User_id"].ToString()); } model.User_UserName = ds.Tables[0].Rows[0]["User_UserName"].ToString(); if (ds.Tables[0].Rows[0]["Product_id"].ToString() != "") { model.Product_id = int.Parse(ds.Tables[0].Rows[0]["Product_id"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public static void Update(Lebi_Agent_Product model) { D_Lebi_Agent_Product.Instance.Update(model); }
/// <summary> /// 增加一条数据 /// </summary> public static int Add(Lebi_Agent_Product model) { return(D_Lebi_Agent_Product.Instance.Add(model)); }
/// <summary> /// 安全方式绑定表单数据 /// </summary> public static Lebi_Agent_Product SafeBindForm(Lebi_Agent_Product model) { return(D_Lebi_Agent_Product.Instance.SafeBindForm(model)); }
/// <summary> /// 处理商品代理申请 /// </summary> public void ProductRequest_Manage() { int id = RequestTool.RequestInt("id"); int t = RequestTool.RequestInt("t"); Lebi_Agent_Product_request model = B_Lebi_Agent_Product_request.GetModel(id); if (model == null) { Response.Write("{\"msg\":\"" + Tag("参数错误") + "\"}"); return; } Lebi_Agent_Product pro = B_Lebi_Agent_Product.GetModel("Product_id=" + model.Product_id); if (pro == null) { Response.Write("{\"msg\":\"" + Tag("参数错误") + "\"}"); return; } Lebi_Agent_Product_User user = B_Lebi_Agent_Product_User.GetModel("User_id=" + model.User_id + ""); if (user == null) { Response.Write("{\"msg\":\"" + Tag("此用户无代理资格") + "\"}"); return; } if (pro.User_id > 0) { Response.Write("{\"msg\":\"" + Tag("其他用户已代理此商品") + "\"}"); return; } if (t == 1) { if (model.Product_id_old > 0)//替换商品的情况。修改旧数据 { Lebi_Agent_Product oldpro = B_Lebi_Agent_Product.GetModel("Product_id=" + model.Product_id_old + ""); if (oldpro != null) { if (oldpro.User_id != model.User_id) { Response.Write("{\"msg\":\"" + Tag("提换商品非此用户代理") + "\"}"); return; } oldpro.User_id = 0; oldpro.User_UserName = ""; B_Lebi_Agent_Product.Update(oldpro); } } model.Type_id_AgentProductRequestStatus = 371; pro.User_id = model.User_id; pro.User_UserName = model.User_UserName; //pro.Commission = user.Commission; B_Lebi_Agent_Product.Update(pro); } else { model.Type_id_AgentProductRequestStatus = 372; } model.Admin_id = CurrentAdmin.id; model.Admin_UserName = CurrentAdmin.UserName; B_Lebi_Agent_Product_request.Update(model); Log.Add("处理代理商品申请", "Agent_Product", id.ToString(), CurrentAdmin); Response.Write("{\"msg\":\"OK\"}"); }