private bool DoAdd() { bool result = false; string check_good = DTRequest.GetFormString("ck_good"); if (string.IsNullOrEmpty(check_good)) { JscriptMsg("请选择商品!", "", "Error"); return false; } BLL.meal bll = new BLL.meal(); Model.meal model = new Model.meal(); model.title = txt_title.Text.Trim(); model.category_id = Convert.ToInt32(ddlCategoryId.SelectedValue); model.img_url = txtImgUrl.Text.Trim(); model.add_time = DateTime.Now; model.index_url = txtIndexUrl.Text.Trim(); model.sort_id = int.Parse(txtSortId.Text.ToString()); BLL.standard_price bll_standard_price = new BLL.standard_price(); int _meal_id = bll.Add(model); if (_meal_id > 0) { BLL.meal_good bll_meal_good = new BLL.meal_good(); string[] arr_str = check_good.Split(','); BLL.standard_group_price bll_standard_group_price = new BLL.standard_group_price(); for (int i = 0; i < arr_str.Length; i++) { Model.article model_good = new Model.article(); model_good = new BLL.article().GetModel(Convert.ToInt32(arr_str[i].Split('_')[0])); if (model_good != null) { if (!string.IsNullOrEmpty(arr_str[i])) { DataTable dt_standard_group_price = bll_standard_group_price.GetList("good_id=" + arr_str[i].Split('_')[0] + " and standard_price_id=" + arr_str[i].Split('_')[1]).Tables[0]; if (dt_standard_group_price != null && dt_standard_group_price.Rows.Count > 0) { //有会员规格价格 商品ID_规格价格ID_单位ID_数量 默认sell_price 规格价格standard_price(有规格未登入) 组别价格standard_group_price(不管有没有规格已登入) foreach (DataRow dr_group_price in dt_standard_group_price.Rows) { Model.meal_good model_meal_good = new Model.meal_good(); model_meal_good.good_id = Convert.ToInt32(arr_str[i].Split('_')[0]); model_meal_good.group_id = Convert.ToInt32(dr_group_price["group_id"]); model_meal_good.meal_id = _meal_id; model_meal_good.standard_price_id = Convert.ToDecimal(arr_str[i].Split('_')[1]); model_meal_good.unit_id = Convert.ToInt32(arr_str[i].Split('_')[2]); model_meal_good.quantity = Convert.ToInt32(arr_str[i].Split('_')[3]); model_meal_good.sell_price = Convert.ToDecimal(model_good.fields["sell_price"]); model_meal_good.standard_price = Convert.ToDecimal(model_good.fields["sell_price"]); Model.standard_price model_standard_price = bll_standard_price.GetModel(Convert.ToDecimal(arr_str[i].Split('_')[1])); if (model_standard_price != null) { //有库存价格 model_meal_good.standard_price = model_standard_price.sell_price; model_meal_good.action_price = model_standard_price.action_price; } model_meal_good.standard_group_price = Convert.ToDecimal(dr_group_price["group_price"]); model_meal_good.add_time = DateTime.Now; bll_meal_good.Add(model_meal_good); } } else { if (model_good.group_price.Count > 0) { foreach (Model.user_group_price model_user_group in model_good.group_price) { Model.meal_good model_meal_good = new Model.meal_good(); model_meal_good.good_id = Convert.ToInt32(arr_str[i].Split('_')[0]); model_meal_good.group_id = model_user_group.group_id; model_meal_good.meal_id = _meal_id; model_meal_good.standard_price_id = Convert.ToDecimal(arr_str[i].Split('_')[1]); model_meal_good.unit_id = Convert.ToInt32(arr_str[i].Split('_')[2]); model_meal_good.quantity = Convert.ToInt32(arr_str[i].Split('_')[3]); model_meal_good.sell_price = Convert.ToDecimal(model_good.fields["sell_price"]); model_meal_good.standard_price = Convert.ToDecimal(model_good.fields["sell_price"]); Model.standard_price model_standard_price = bll_standard_price.GetModel(Convert.ToDecimal(arr_str[i].Split('_')[1])); if (model_standard_price != null) { //有库存价格 model_meal_good.standard_price = model_standard_price.sell_price; model_meal_good.action_price = model_standard_price.action_price; } model_meal_good.standard_group_price = Convert.ToDecimal(model_user_group.price); model_meal_good.add_time = DateTime.Now; bll_meal_good.Add(model_meal_good); } } else { Model.meal_good model_meal_good = new Model.meal_good(); model_meal_good.good_id = Convert.ToInt32(arr_str[i].Split('_')[0]); model_meal_good.group_id = 0; model_meal_good.meal_id = _meal_id; model_meal_good.standard_price_id = Convert.ToDecimal(arr_str[i].Split('_')[1]); model_meal_good.unit_id = Convert.ToInt32(arr_str[i].Split('_')[2]); model_meal_good.quantity = Convert.ToInt32(arr_str[i].Split('_')[3]); model_meal_good.sell_price = Convert.ToDecimal(model_good.fields["sell_price"]); model_meal_good.standard_price = Convert.ToDecimal(model_good.fields["sell_price"]); Model.standard_price model_standard_price = bll_standard_price.GetModel(Convert.ToDecimal(arr_str[i].Split('_')[1])); if (model_standard_price != null) { //有库存价格 model_meal_good.standard_price = model_standard_price.sell_price; model_meal_good.action_price = model_standard_price.action_price; } model_meal_good.standard_group_price = Convert.ToDecimal(model_good.fields["sell_price"]); model_meal_good.add_time = DateTime.Now; bll_meal_good.Add(model_meal_good); } } } } } //AddAdminLog(DTEnums.ActionEnum.Add.ToString(), "添加用户:" + model.user_name); //记录日志 result = true; } return result; }
/// <summary> /// 获得购物车列表 /// </summary> public static IList<Model.cart_items> GetList(int group_id) { IDictionary<string, int> dic = GetCart(); if (dic==null || dic.Count <= 0) { #region 获取数据库购物车 Model.users model = new BasePage().GetUserInfo(); if (model != null) { BLL.cart cartbll = new BLL.cart(); DataTable dt = cartbll.GetList("UserID='" + model.id + "'").Tables[0]; if (dt.Rows.Count <= 0) { //return null; } else { dic = new Dictionary<string, int>(); for (int i = 0; i < dt.Rows.Count; i++) { dic.Add(dt.Rows[i]["ProductName"].ToString(), int.Parse(dt.Rows[i]["Counts"].ToString())); } } } #endregion } if (dic != null) { IList<Model.cart_items> iList = new List<Model.cart_items>(); foreach (var item in dic) { BLL.article bll = new BLL.article(); //key:1547-27|120,28|122-55 int goods_id = Convert.ToInt32(item.Key.Split('-')[0]); string standard = item.Key.Split('-')[1]; decimal unit_id = decimal.Parse(item.Key.Split('-')[2], 0);// Convert.ToDecimal(item.Key.Split('-')[2]); Model.article model = bll.GetModel(Convert.ToInt32(goods_id)); if (model == null || !model.fields.ContainsKey("sell_price")) { continue; } string standard_value_ids = ""; string[] arr_standard = standard.Split(','); foreach (string str in arr_standard) { if (!string.IsNullOrEmpty(str)) { standard_value_ids += str.Split('|')[1] + ","; } } if (!string.IsNullOrEmpty(standard_value_ids)) { standard_value_ids = standard_value_ids.Substring(0, standard_value_ids.Length - 1); } Model.cart_items modelt = new Model.cart_items(); modelt.id = model.id; modelt.title = model.title; modelt.img_url = model.img_url; modelt.standard = standard; modelt.unit_id = unit_id; if (model.fields.ContainsKey("point")) { modelt.point = Utils.StrToInt(model.fields["point"], 0); } modelt.price = Utils.StrToDecimal(model.fields["sell_price"], 0); modelt.user_price = Utils.StrToDecimal(model.fields["sell_price"], 0); //单位价格 -- 有单位 无会员 无规格 BLL.unit bll_unit = new BLL.unit(); Model.unit model_unit = bll_unit.GetModel(unit_id); if (model_unit != null) { modelt.price = Utils.StrToDecimal(model.fields["sell_price"], 0) * model_unit.quantity * (model_unit.rate / 100); modelt.user_price = Utils.StrToDecimal(model.fields["sell_price"], 0) * model_unit.quantity * (model_unit.rate / 100); } //规格价格 --有/无单位 无会员 有规格 BLL.standard_price bll_standard_price = new BLL.standard_price(); DataTable dt_standard_price = bll_standard_price.GetList("standard_value_ids='" + standard_value_ids + "' and good_id=" + goods_id).Tables[0]; if (dt_standard_price != null && dt_standard_price.Rows.Count > 0) { modelt.user_price = modelt.price = Utils.StrToDecimal(dt_standard_price.Rows[0]["sell_price"].ToString(), 0); if (model_unit != null) { modelt.user_price = modelt.price = Utils.StrToDecimal(dt_standard_price.Rows[0]["sell_price"].ToString(), 0) * model_unit.quantity * (model_unit.rate / 100); } } if (model.fields.ContainsKey("stock_quantity")) { modelt.stock_quantity = Utils.StrToInt(model.fields["stock_quantity"], 0); } //会员价格 if (model.group_price != null) { Model.user_group_price gmodel = model.group_price.Find(p => p.group_id == group_id); if (gmodel != null) { modelt.user_price = gmodel.price; //有规格才有规格等级价格 if (dt_standard_price != null && dt_standard_price.Rows.Count > 0) { BLL.standard_group_price bll_standard_group_price = new BLL.standard_group_price(); DataTable dt_standard_group_price = bll_standard_group_price.GetList("good_id=" + goods_id + " and standard_price_id=" + dt_standard_price.Rows[0]["id"].ToString() + " and group_id=" + group_id).Tables[0]; //有规格会员价格 if (dt_standard_group_price != null && dt_standard_group_price.Rows.Count > 0) { //规格会员价格 无单位-- 有规格 有会员 modelt.user_price = Convert.ToDecimal(dt_standard_group_price.Rows[0]["group_price"]); } } if (model_unit != null) { modelt.user_price = modelt.user_price * model_unit.quantity * (model_unit.rate / 100); } } } modelt.quantity = item.Value; iList.Add(modelt); } return iList; } return null; }
private bool DoEdit(int _id) { bool result = false; BLL.article bll = new BLL.article(); Model.article model = bll.GetModel(_id); decimal sell_price = 0; decimal standard_price = 0; decimal standard_group_price = 0; decimal action_price = 0; model.channel_id = this.channel_id; model.category_id = Utils.StrToInt(ddlCategoryId.SelectedValue, 0); model.call_index = txtCallIndex.Text.Trim(); model.title = txtTitle.Text.Trim(); model.link_url = txtLinkUrl.Text.Trim(); model.img_url = txtImgUrl.Text; model.seo_title = txtSeoTitle.Text.Trim(); model.seo_keywords = txtSeoKeywords.Text.Trim(); model.seo_description = txtSeoDescription.Text.Trim(); //内容摘要提取内容前255个字符 if (string.IsNullOrEmpty(txtZhaiyao.Text.Trim())) { model.zhaiyao = Utils.DropHTML(txtContent.Value, 255); } else { model.zhaiyao = Utils.DropHTML(txtZhaiyao.Text, 255); } model.content = txtContent.Value; model.sort_id = Utils.StrToInt(txtSortId.Text.Trim(), 99); model.click = int.Parse(txtClick.Text.Trim()); model.status = Utils.StrToInt(rblStatus.SelectedValue, 0); model.is_msg = 0; model.is_top = 0; model.is_red = 0; model.is_hot = 0; model.is_slide = 0; model.is_put = 1; if (isPut.Items[0].Selected) { model.is_put = 0; } if (cblItem.Items[0].Selected == true) { model.is_msg = 1; } if (cblItem.Items[1].Selected == true) { model.is_top = 1; } if (cblItem.Items[2].Selected == true) { model.is_red = 1; } if (cblItem.Items[3].Selected == true) { model.is_hot = 1; } if (cblItem.Items[4].Selected == true) { model.is_slide = 1; } model.add_time = Utils.StrToDateTime(txtAddTime.Text.Trim()); model.update_time = DateTime.Now; model.fields = SetFieldValues(this.channel_id); //扩展字段赋值 sell_price = Convert.ToDecimal(model.fields["sell_price"]); #region 保存相册==================== //检查是否有自定义图片 if (txtImgUrl.Text.Trim() == "") { model.img_url = hidFocusPhoto.Value; } if (model.albums != null) { model.albums.Clear(); } string[] albumArr = Request.Form.GetValues("hid_photo_name"); string[] remarkArr = Request.Form.GetValues("hid_photo_remark"); if (albumArr != null) { List<Model.article_albums> ls = new List<Model.article_albums>(); for (int i = 0; i < albumArr.Length; i++) { string[] imgArr = albumArr[i].Split('|'); int img_id = Utils.StrToInt(imgArr[0], 0); if (imgArr.Length == 3) { if (!string.IsNullOrEmpty(remarkArr[i])) { ls.Add(new Model.article_albums { id = img_id, article_id = _id, original_path = imgArr[1], thumb_path = imgArr[2], remark = remarkArr[i] }); } else { ls.Add(new Model.article_albums { id = img_id, article_id = _id, original_path = imgArr[1], thumb_path = imgArr[2] }); } } } model.albums = ls; } #endregion #region 保存附件==================== if (model.attach != null) { model.attach.Clear(); } string[] attachIdArr = Request.Form.GetValues("hid_attach_id"); string[] attachFileNameArr = Request.Form.GetValues("hid_attach_filename"); string[] attachFilePathArr = Request.Form.GetValues("hid_attach_filepath"); string[] attachFileSizeArr = Request.Form.GetValues("hid_attach_filesize"); string[] attachPointArr = Request.Form.GetValues("txt_attach_point"); if (attachIdArr != null && attachFileNameArr != null && attachFilePathArr != null && attachFileSizeArr != null && attachPointArr != null && attachIdArr.Length > 0 && attachFileNameArr.Length > 0 && attachFilePathArr.Length > 0 && attachFileSizeArr.Length > 0 && attachPointArr.Length > 0) { List<Model.article_attach> ls = new List<Model.article_attach>(); for (int i = 0; i < attachFileNameArr.Length; i++) { int attachId = Utils.StrToInt(attachIdArr[i], 0); int fileSize = Utils.StrToInt(attachFileSizeArr[i], 0); string fileExt = Utils.GetFileExt(attachFilePathArr[i]); int _point = Utils.StrToInt(attachPointArr[i], 0); ls.Add(new Model.article_attach { id = attachId, article_id = _id, file_name = attachFileNameArr[i], file_path = attachFilePathArr[i], file_size = fileSize, file_ext = fileExt, point = _point, }); } model.attach = ls; } #endregion #region 保存会员组价格============== List<Model.user_group_price> priceList = new List<Model.user_group_price>(); for (int i = 0; i < rptPrice.Items.Count; i++) { int hidPriceId = 0; if (!string.IsNullOrEmpty(((HiddenField)rptPrice.Items[i].FindControl("hidePriceId")).Value)) { hidPriceId = Convert.ToInt32(((HiddenField)rptPrice.Items[i].FindControl("hidePriceId")).Value); } int hidGroupId = Convert.ToInt32(((HiddenField)rptPrice.Items[i].FindControl("hideGroupId")).Value); decimal _price = Convert.ToDecimal(((TextBox)rptPrice.Items[i].FindControl("txtGroupPrice")).Text.Trim()); priceList.Add(new Model.user_group_price { id = hidPriceId, article_id = _id, group_id = hidGroupId, price = _price }); } model.group_price = priceList; #endregion if (bll.Update(model)) { #region 商品相关 if (channel_name == "goods") { //规格价格 BLL.standard_price bll_price = new BLL.standard_price(); DataTable dt = bll_price.GetList(0, "good_id=" + _id, "id asc").Tables[0]; if (dt != null && dt.Rows.Count > 0) { if (!bll_price.Delete("good_id=" + _id)) { JscriptMsg("价格信息清除失败!", "", "Error"); return false; } } string standard_ids = DTRequest.GetFormString("ck_standard"); string standard_value_ids = DTRequest.GetFormString("ck_standard_value"); string str_standards = ""; BLL.standard bll_standard = new BLL.standard(); string[] str_standard_arr = standard_ids.Split(','); foreach (string str in str_standard_arr) { if (!string.IsNullOrEmpty(str)) { Model.standard model_standard = bll_standard.GetModel(Convert.ToInt32(str)); if (model_standard != null) { str_standards += model_standard.title + ","; } } } BLL.standard_value bll_value = new BLL.standard_value(); string[] str_standard_value_arr = standard_value_ids.Split(','); BLL.standard_group_price bll_standard_group_price = new BLL.standard_group_price(); DataTable dt_standard_group_price = bll_standard_group_price.GetList("good_id=" + _id).Tables[0]; if (dt_standard_group_price != null && dt_standard_group_price.Rows.Count > 0) { if (!bll_standard_group_price.Delete(_id)) { JscriptMsg("清除商品规格会员价格失败!", "", "Error"); return false; } } foreach (string str in str_standard_value_arr) { if (!string.IsNullOrEmpty(str)) { string str_title = ""; string[] str_arr = str.Split('_'); foreach (string s in str_arr) { if (!string.IsNullOrEmpty(s)) { Model.standard_value model_value = bll_value.GetModel(Convert.ToInt32(s)); if (model_value != null) { str_title += model_value.value + ","; } } } Model.standard_price model_price = new Model.standard_price(); model_price.good_id = _id; model_price.standard_ids = standard_ids; model_price.good_no = DTRequest.GetFormString("good_no_" + str); model_price.standards = str_standards.Substring(0, str_standards.Length - 1); model_price.standard_value_ids = str.Replace('_', ','); model_price.standard_values = str_title.Substring(0, str_title.Length - 1); model_price.stock_quantity = DTRequest.GetFormInt("stock_quantity_" + str, 0); model_price.market_price = DTRequest.GetFormDecimal("market_price_" + str, 0); model_price.sell_price=sell_price=standard_price = DTRequest.GetFormDecimal("sell_price_" + str, 0); model_price.action_price=action_price = DTRequest.GetFormDecimal("action_price_" + str, 0); model_price.user_price = DTRequest.GetFormDecimal("user_price_" + str, 0); model_price.add_time = DateTime.Now; decimal _standard_price_id = bll_price.Add(model_price); if (_standard_price_id <= 0) { JscriptMsg("更新价格信息失败!", "", "Error"); return false; } //规格会员组价格 BLL.user_groups bll_user_group = new BLL.user_groups(); DataTable dt_user_group = bll_user_group.GetList(0, "", "grade asc,id desc").Tables[0]; foreach (DataRow dr_user_group in dt_user_group.Rows) { Model.standard_group_price model_standard_group_price = new Model.standard_group_price(); model_standard_group_price.good_id = _id; model_standard_group_price.group_id = Convert.ToInt32(dr_user_group["id"]); model_standard_group_price.standard_price_id = _standard_price_id; model_standard_group_price.group_price=standard_group_price = DTRequest.GetFormDecimal("user_price_" + dr_user_group["id"] + "_" + str, 0); model_standard_group_price.add_time = DateTime.Now; if (bll_standard_group_price.Add(model_standard_group_price) <= 0) { JscriptMsg("规格会员价格更新失败!", "", "Error"); return false; } } } } //BLL.meal_good bll_meal_good = new BLL.meal_good(); //if (!bll_meal_good.UpdateMealGoodPrice(_id, sell_price, standard_price, standard_group_price, action_price)) //{ // JscriptMsg("套餐商品价格更新失败!", "", "Error"); // return false; //} //单位 BLL.unit bll_unit = new BLL.unit(); bll_unit.Delete(_id); string str_unit = DTRequest.GetFormString("ck_unit"); if (!string.IsNullOrEmpty(str_unit)) { string[] arr_unit = str_unit.Split(','); foreach (string s_unit in arr_unit) { if (!string.IsNullOrEmpty(s_unit)) { string[] unit = s_unit.Split('_'); Model.unit model_unit = new Model.unit(); model_unit.good_id = _id; model_unit.title = unit[0]; model_unit.quantity = Convert.ToInt32(unit[1]); model_unit.rate = Convert.ToDecimal(unit[2]); model_unit.content = unit[3]; model_unit.add_time = DateTime.Now; if (bll_unit.Add(model_unit) <= 0) { JscriptMsg("更新单位失败!", "", "Error"); return false; } } } } //别名 BLL.alias_good bll_alias_good = new BLL.alias_good(); //删除 bll_alias_good.Delete(_id); for (int i = 0; i < ck_alias.Items.Count; i++) { if (ck_alias.Items[i].Selected) { Model.alias_good model_alias_good = new Model.alias_good(); model_alias_good.alias_id = Convert.ToInt32(ck_alias.Items[i].Value); model_alias_good.good_id = _id; bll_alias_good.Add(model_alias_good); } } //属性 BLL.property_value bll_property_value = new BLL.property_value(); BLL.property_good bll_property_good = new BLL.property_good(); bll_property_good.Delete(_id); string str_property_value = DTRequest.GetFormString("ck_property_value"); if (!string.IsNullOrEmpty(str_property_value)) { string[] arr_property_value = str_property_value.Split(','); foreach (string str_1 in arr_property_value) { Model.property_good model_property_good = new Model.property_good(); model_property_good.good_id = _id; model_property_good.property_value_id = Convert.ToInt32(str_1); Model.property_value model_property_value = bll_property_value.GetModel(Convert.ToInt32(str_1)); if (model_property_value != null) { model_property_good.property_id = model_property_value.property_id; } bll_property_good.Add(model_property_good); } } //标签 BLL.tag_good bll_tag_good = new BLL.tag_good(); bll_tag_good.Delete(_id); for (int i = 0; i < ck_tag.Items.Count; i++) { if (ck_tag.Items[i].Selected) { Model.tag_good model_tag_good = new Model.tag_good(); model_tag_good.tag_id = Convert.ToInt32(ck_tag.Items[i].Value); model_tag_good.good_id = _id; bll_tag_good.Add(model_tag_good); } } } #endregion AddAdminLog(DTEnums.ActionEnum.Edit.ToString(), "修改" + this.channel_name + "频道内容:" + model.title); //记录日志 result = true; } return result; }
private void check_standard_unit_price(HttpContext context) { int goods_id = DTRequest.GetQueryInt("goods_id"); string standard_value_id = DTRequest.GetQueryString("standard_value_id"); decimal unit_id = DTRequest.GetQueryDecimal("unit_id", 0); if (goods_id <= 0) { context.Response.Write("{\"status\":\"0\", \"msg\":\"参数错误!\"}"); return; } Model.article model_article = new BLL.article().GetModel(goods_id); if (model_article == null) { context.Response.Write("{\"status\":\"0\", \"msg\":\"商品不存在或已删除!\"}"); return; } BLL.unit bll_unit = new BLL.unit(); Model.unit model_unit = bll_unit.GetModel(unit_id); string real_standard_value_id = ""; if (!string.IsNullOrEmpty(standard_value_id)) { string[] str = standard_value_id.Split(','); foreach (string s in str) { if (!string.IsNullOrEmpty(s)) { real_standard_value_id += s.Split('|')[1] + ","; } } } if (!string.IsNullOrEmpty(real_standard_value_id)) { real_standard_value_id = real_standard_value_id.Substring(0, real_standard_value_id.Length - 1); } BLL.standard_price bll_standard_price = new BLL.standard_price(); DataTable dt_standard_price = bll_standard_price.GetList("good_id=" + goods_id + " and standard_value_ids='" + real_standard_value_id + "'").Tables[0]; if (dt_standard_price != null && dt_standard_price.Rows.Count > 0) { decimal sell_price = Convert.ToDecimal(dt_standard_price.Rows[0]["sell_price"]);//原价 Model.users model_user = new BasePage().GetUserInfo(); if (model_user != null) { //会员价 BLL.standard_group_price bll_standard_group_price = new BLL.standard_group_price(); DataTable dt_standard_group_price = bll_standard_group_price.GetList("good_id=" + goods_id + " and group_id=" + model_user.group_id + " and standard_price_id='" + dt_standard_price.Rows[0]["id"].ToString().Trim() + "'").Tables[0]; if (dt_standard_group_price != null && dt_standard_group_price.Rows.Count > 0) { sell_price = Convert.ToDecimal(dt_standard_group_price.Rows[0]["group_price"]); } if (model_unit != null) { sell_price = sell_price * model_unit.quantity * (model_unit.rate / 100); } } else { //非会员价 if (model_unit != null) { sell_price = sell_price * model_unit.quantity * (model_unit.rate / 100); } } //if (sell_price <= 0) //{ // context.Response.Write("{\"status\":\"0\", \"msg\":\"库存不足!\"}"); // return; //} context.Response.Write("{\"status\":\"1\", \"msg\":\"" + sell_price + "\"}"); return; } else { //没规格价格 //if (Convert.ToInt32(model_article.fields["stock_quantity"]) <= 0 || Convert.ToDecimal(model_article.fields["sell_price"]) <= 0) //{ // context.Response.Write("{\"status\":\"0\", \"msg\":\"库存不足!\"}"); // return; //} //else //{ decimal sell_price = Convert.ToDecimal(model_article.fields["sell_price"]) * model_unit.quantity * (model_unit.rate / 100); context.Response.Write("{\"status\":\"1\", \"msg\":\"" + sell_price + "\"}"); return; //} } }
private bool DoEdit(int _id) { string check_good = DTRequest.GetFormString("ck_good"); if (string.IsNullOrEmpty(check_good)) { JscriptMsg("请选择商品!", "", "Error"); return(false); } bool result = false; BLL.meal bll = new BLL.meal(); Model.meal model = bll.GetModel(_id); model.title = txt_title.Text.Trim(); model.img_url = txtImgUrl.Text.Trim(); model.category_id = Convert.ToInt32(ddlCategoryId.SelectedValue); model.index_url = txtIndexUrl.Text.Trim(); model.sort_id = int.Parse(txtSortId.Text.ToString()); if (bll.Update(model)) { BLL.standard_price bll_standard_price = new BLL.standard_price(); BLL.meal_good bll_meal_good = new BLL.meal_good(); bll_meal_good.Delete(_id); string[] arr_str = check_good.Split(','); BLL.standard_group_price bll_standard_group_price = new BLL.standard_group_price(); for (int i = 0; i < arr_str.Length; i++) { Model.article model_good = new Model.article(); model_good = new BLL.article().GetModel(Convert.ToInt32(arr_str[i].Split('_')[0])); if (model_good != null) { if (!string.IsNullOrEmpty(arr_str[i])) { DataTable dt_standard_group_price = bll_standard_group_price.GetList("good_id=" + arr_str[i].Split('_')[0] + " and standard_price_id=" + arr_str[i].Split('_')[1]).Tables[0]; if (dt_standard_group_price != null && dt_standard_group_price.Rows.Count > 0) { //有会员规格价格 foreach (DataRow dr_group_price in dt_standard_group_price.Rows) { Model.meal_good model_meal_good = new Model.meal_good(); model_meal_good.good_id = Convert.ToInt32(arr_str[i].Split('_')[0]); model_meal_good.group_id = Convert.ToInt32(dr_group_price["group_id"]); model_meal_good.meal_id = _id; model_meal_good.standard_price_id = Convert.ToDecimal(arr_str[i].Split('_')[1]); model_meal_good.unit_id = Convert.ToInt32(arr_str[i].Split('_')[2]); model_meal_good.quantity = Convert.ToInt32(arr_str[i].Split('_')[3]); model_meal_good.sell_price = Convert.ToDecimal(model_good.fields["sell_price"]); model_meal_good.standard_price = Convert.ToDecimal(model_good.fields["sell_price"]); Model.standard_price model_standard_price = bll_standard_price.GetModel(Convert.ToDecimal(arr_str[i].Split('_')[1])); if (model_standard_price != null) { //有库存价格 model_meal_good.standard_price = model_standard_price.sell_price; model_meal_good.action_price = model_standard_price.action_price; } model_meal_good.standard_group_price = Convert.ToDecimal(dr_group_price["group_price"]); model_meal_good.add_time = DateTime.Now; bll_meal_good.Add(model_meal_good); } } else { if (model_good.group_price.Count > 0) { foreach (Model.user_group_price model_user_group in model_good.group_price) { Model.meal_good model_meal_good = new Model.meal_good(); model_meal_good.good_id = Convert.ToInt32(arr_str[i].Split('_')[0]); model_meal_good.group_id = model_user_group.group_id; model_meal_good.meal_id = _id; model_meal_good.standard_price_id = Convert.ToDecimal(arr_str[i].Split('_')[1]); model_meal_good.unit_id = Convert.ToInt32(arr_str[i].Split('_')[2]); model_meal_good.quantity = Convert.ToInt32(arr_str[i].Split('_')[3]); model_meal_good.sell_price = Convert.ToDecimal(model_good.fields["sell_price"]); model_meal_good.standard_price = Convert.ToDecimal(model_good.fields["sell_price"]); Model.standard_price model_standard_price = bll_standard_price.GetModel(Convert.ToDecimal(arr_str[i].Split('_')[1])); if (model_standard_price != null) { //有库存价格 model_meal_good.standard_price = model_standard_price.sell_price; model_meal_good.action_price = model_standard_price.action_price; } model_meal_good.standard_group_price = Convert.ToDecimal(model_user_group.price); model_meal_good.add_time = DateTime.Now; bll_meal_good.Add(model_meal_good); } } else { Model.meal_good model_meal_good = new Model.meal_good(); model_meal_good.good_id = Convert.ToInt32(arr_str[i].Split('_')[0]); model_meal_good.group_id = 0; model_meal_good.meal_id = _id; model_meal_good.standard_price_id = Convert.ToDecimal(arr_str[i].Split('_')[1]); model_meal_good.unit_id = Convert.ToInt32(arr_str[i].Split('_')[2]); model_meal_good.quantity = Convert.ToInt32(arr_str[i].Split('_')[3]); model_meal_good.sell_price = Convert.ToDecimal(model_good.fields["sell_price"]); model_meal_good.standard_price = Convert.ToDecimal(model_good.fields["sell_price"]); Model.standard_price model_standard_price = bll_standard_price.GetModel(Convert.ToDecimal(arr_str[i].Split('_')[1])); if (model_standard_price != null) { //有库存价格 model_meal_good.standard_price = model_standard_price.sell_price; model_meal_good.action_price = model_standard_price.action_price; } model_meal_good.standard_group_price = Convert.ToDecimal(model_good.fields["sell_price"]); model_meal_good.add_time = DateTime.Now; bll_meal_good.Add(model_meal_good); } } } } } //AddAdminLog(DTEnums.ActionEnum.Edit.ToString(), "修改用户信息:" + model.user_name); //记录日志 result = true; } return(result); }
private void get_good_info(HttpContext context) { int good_id = DTRequest.GetQueryInt("good_id"); BLL.article bll_article = new BLL.article(); Model.article model_article = bll_article.GetModel(good_id); if (model_article == null) { context.Response.Write("NotFind"); return; } string str_header = ""; string str_body = ""; //会员组 BLL.user_groups bll_groups = new BLL.user_groups(); DataTable dt_groups = bll_groups.GetList(0, "", "grade asc,id desc").Tables[0]; string str_groups_header = ""; string str_groups_body = ""; BLL.standard_price bll_standard_price = new BLL.standard_price(); DataTable dt_standard_price = bll_standard_price.GetList("good_id=" + good_id).Tables[0]; if (dt_standard_price != null && dt_standard_price.Rows.Count > 0) { //有规格价格 foreach (DataRow dr in dt_standard_price.Rows) { decimal sell_price = Convert.ToDecimal(model_article.fields["sell_price"]); string str_standard = ""; string str_standard_value = ""; sell_price = Convert.ToDecimal(dr["sell_price"]); if (dr["standards"] != null && !string.IsNullOrEmpty(dr["standards"].ToString())) { string[] standard_arr = dr["standards"].ToString().Split(',');//规格名 string[] standard_value_arr = dr["standard_values"].ToString().Split(',');//规格值 string[] standard_value_id_arr = dr["standard_value_ids"].ToString().Split(',');//规格值ID for (int i = 0; i < standard_arr.Length; i++) { str_standard += "<td style='font-weight:bold;color:#33B5E5;padding-right:10px;'>" + standard_arr[i] + "</td>"; if (i < standard_value_arr.Length) { str_standard_value += "<td style='padding-right: 20px;'>" + standard_value_arr[i] + "</td>"; foreach (DataRow dr_group in dt_groups.Rows) { BLL.standard_group_price bll_standard_group_price = new BLL.standard_group_price(); DataTable dt_standard_group_price = bll_standard_group_price.GetList("good_id=" + model_article.id + " and group_id=" + Convert.ToInt32(dr_group["id"]) + " and standard_price_id=" + standard_value_id_arr[i]).Tables[0]; if (dt_standard_group_price != null && dt_standard_group_price.Rows.Count > 0) { str_groups_body += "<td style='padding-right: 20px;'>" + Convert.ToDecimal(dt_standard_group_price.Rows[0]["group_price"]) + "</td>"; } } } else { str_standard_value += "<td style='padding-right: 20px;'> </td>"; } } } str_header = "<table>" + "<thead><tr>" + "<td style='font-weight:bold;color:#33B5E5;padding-right:10px;'>名称</td>" + "<td style='font-weight:bold;color:#33B5E5;padding-right:10px;'>售价</td>" + str_standard + str_groups_header + "<td style='font-weight:bold;color:#33B5E5;padding-right:10px;'>数量</td>" + "<td style='font-weight:bold;color:#33B5E5;padding-right:10px;'>操作</td>" + "</tr></thead>"; str_body += "<tbody><tr>" + "<td style='padding-right: 20px;'>" + model_article.title + "</td>" + "<td style='padding-right: 20px;'>" + sell_price + "</td>" + str_groups_body + str_standard_value + "<td style='padding-right: 20px;'><input type='text' class='input small' id='quantity_" + model_article.id + "_" + dr["id"].ToString() + "'></td>" + "<td style='padding-right: 20px;'><a href='javascript:;' onclick='into_meal(" + model_article.id + "," + dr["id"].ToString() + ",this)'>选择</a></td>" + "</tr></tbody>" + "<table>"; } } else { //无规格价格 if (dt_groups != null && dt_groups.Rows.Count > 0) { for (int i = 0; i < dt_groups.Rows.Count; i++) { str_groups_header += "<td style='font-weight:bold;color:#33B5E5;padding-right:10px;'>" + dt_groups.Rows[i]["title"].ToString() + "</td>"; str_groups_body += "<td style='font-weight:bold;color:#33B5E5;padding-right:10px;'>" + bll_article.GetGroupPrice(model_article.id, Convert.ToInt32(dt_groups.Rows[i]["id"])) + "</td>"; } } str_header = "<table>" + "<thead><tr>" + "<td style='font-weight:bold;color:#33B5E5;padding-right:10px;'>名称</td>" + "<td style='font-weight:bold;color:#33B5E5;padding-right:10px;'>售价</td>" + str_groups_header + "<td style='font-weight:bold;color:#33B5E5;padding-right:10px;'>数量</td>" + "<td style='font-weight:bold;color:#33B5E5;padding-right:10px;'>操作</td>" + "</tr></thead>"; str_body += "<tbody><tr>" + "<td style='padding-right: 20px;'>" + model_article.title + "</td>" + "<td style='padding-right: 20px;'>" + model_article.fields["sell_price"] + "</td>" + str_groups_body + "<td style='padding-right: 20px;'><input type='text' class='input small' id='quantity_" + model_article.id + "_0'></td>" + "<td style='padding-right: 20px;'><a href='javascript:;' onclick='into_meal(" + model_article.id + ",0,this)'>选择</a></td>" + "</tr></tbody>" + "<table>"; } context.Response.Write(str_header + str_body); return; }
/// <summary> /// 获得购物车列表 /// </summary> public static IList <Model.cart_items> GetList(int group_id) { IDictionary <string, int> dic = GetCart(); if (dic == null || dic.Count <= 0) { #region 获取数据库购物车 Model.users model = new BasePage().GetUserInfo(); if (model != null) { BLL.cart cartbll = new BLL.cart(); DataTable dt = cartbll.GetList("UserID='" + model.id + "'").Tables[0]; if (dt.Rows.Count <= 0) { //return null; } else { dic = new Dictionary <string, int>(); for (int i = 0; i < dt.Rows.Count; i++) { dic.Add(dt.Rows[i]["ProductName"].ToString(), int.Parse(dt.Rows[i]["Counts"].ToString())); } } } #endregion } if (dic != null) { IList <Model.cart_items> iList = new List <Model.cart_items>(); foreach (var item in dic) { BLL.article bll = new BLL.article(); //key:1547-27|120,28|122-55 int goods_id = Convert.ToInt32(item.Key.Split('-')[0]); string standard = item.Key.Split('-')[1]; decimal unit_id = decimal.Parse(item.Key.Split('-')[2], 0);// Convert.ToDecimal(item.Key.Split('-')[2]); Model.article model = bll.GetModel(Convert.ToInt32(goods_id)); if (model == null || !model.fields.ContainsKey("sell_price")) { continue; } string standard_value_ids = ""; string[] arr_standard = standard.Split(','); foreach (string str in arr_standard) { if (!string.IsNullOrEmpty(str)) { standard_value_ids += str.Split('|')[1] + ","; } } if (!string.IsNullOrEmpty(standard_value_ids)) { standard_value_ids = standard_value_ids.Substring(0, standard_value_ids.Length - 1); } Model.cart_items modelt = new Model.cart_items(); modelt.id = model.id; modelt.title = model.title; modelt.img_url = model.img_url; modelt.standard = standard; modelt.unit_id = unit_id; if (model.fields.ContainsKey("point")) { modelt.point = Utils.StrToInt(model.fields["point"], 0); } modelt.price = Utils.StrToDecimal(model.fields["sell_price"], 0); modelt.user_price = Utils.StrToDecimal(model.fields["sell_price"], 0); //单位价格 -- 有单位 无会员 无规格 BLL.unit bll_unit = new BLL.unit(); Model.unit model_unit = bll_unit.GetModel(unit_id); if (model_unit != null) { modelt.price = Utils.StrToDecimal(model.fields["sell_price"], 0) * model_unit.quantity * (model_unit.rate / 100); modelt.user_price = Utils.StrToDecimal(model.fields["sell_price"], 0) * model_unit.quantity * (model_unit.rate / 100); } //规格价格 --有/无单位 无会员 有规格 BLL.standard_price bll_standard_price = new BLL.standard_price(); DataTable dt_standard_price = bll_standard_price.GetList("standard_value_ids='" + standard_value_ids + "' and good_id=" + goods_id).Tables[0]; if (dt_standard_price != null && dt_standard_price.Rows.Count > 0) { modelt.user_price = modelt.price = Utils.StrToDecimal(dt_standard_price.Rows[0]["sell_price"].ToString(), 0); if (model_unit != null) { modelt.user_price = modelt.price = Utils.StrToDecimal(dt_standard_price.Rows[0]["sell_price"].ToString(), 0) * model_unit.quantity * (model_unit.rate / 100); } } if (model.fields.ContainsKey("stock_quantity")) { modelt.stock_quantity = Utils.StrToInt(model.fields["stock_quantity"], 0); } //会员价格 if (model.group_price != null) { Model.user_group_price gmodel = model.group_price.Find(p => p.group_id == group_id); if (gmodel != null) { modelt.user_price = gmodel.price; //有规格才有规格等级价格 if (dt_standard_price != null && dt_standard_price.Rows.Count > 0) { BLL.standard_group_price bll_standard_group_price = new BLL.standard_group_price(); DataTable dt_standard_group_price = bll_standard_group_price.GetList("good_id=" + goods_id + " and standard_price_id=" + dt_standard_price.Rows[0]["id"].ToString() + " and group_id=" + group_id).Tables[0]; //有规格会员价格 if (dt_standard_group_price != null && dt_standard_group_price.Rows.Count > 0) { //规格会员价格 无单位-- 有规格 有会员 modelt.user_price = Convert.ToDecimal(dt_standard_group_price.Rows[0]["group_price"]); } } if (model_unit != null) { modelt.user_price = modelt.user_price * model_unit.quantity * (model_unit.rate / 100); } } } modelt.quantity = item.Value; iList.Add(modelt); } return(iList); } return(null); }