//批量删除 protected void btnDelete_Click(object sender, EventArgs e) { ChkAdminLevel("coupon_list", Vincent._DTcms.DTEnums.ActionEnum.Delete.ToString()); //检查权限 int sucCount = 0; int errorCount = 0; BLL.user_coupon bll = new BLL.user_coupon(); for (int i = 0; i < rptList.Items.Count; i++) { int id = Convert.ToInt32(((HiddenField)rptList.Items[i].FindControl("hidId")).Value); CheckBox cb = (CheckBox)rptList.Items[i].FindControl("chkId"); if (cb.Checked) { if (bll.Delete(id)) { sucCount += 1; } else { errorCount += 1; } } } AddAdminLog(Vincent._DTcms.DTEnums.ActionEnum.Delete.ToString(), "删除优惠券成功" + sucCount + "条,失败" + errorCount + "条"); //记录日志 JscriptMsg("删除成功" + sucCount + "条,失败" + errorCount + "条!", Vincent._DTcms.Utils.CombUrlTxt("coupon_list.aspx", "status={0}&coupon_stype={1}&keywords={2}", this.status.ToString(), this.coupon_stype.ToString(), this.keywords), "Success"); }
private bool DoAdd() { bool result = true; Model.user_coupon model = new Model.user_coupon(); BLL.user_coupon bll = new BLL.user_coupon(); model.title = txtTitle.Text.Trim(); model.remark = txtRemark.Text.Trim(); model.type = RadioBut1.Checked == true ? "平台优惠券" : "品牌优惠券"; model.amount = Convert.ToDecimal(txtDecimal.Text); model.start_time = Convert.ToDateTime(txtStartTime.Text); model.end_time = Convert.ToDateTime(txtEndTime.Text); int num = Convert.ToInt32(txtNum.Text); string st = ""; for (int i = 1; i <= num; i++) { st = i.ToString().PadLeft(5, '0');//补齐优惠券的位数 string str_code = txtStrCode.Text + DateTime.Now.ToString("yyyyMMddhhmmss") + st; model.str_code = Vincent._MD5Encrypt.GetMD5(str_code); if (bll.Add(model) > 0) { result = true; } } AddAdminLog(Vincent._DTcms.DTEnums.ActionEnum.Add.ToString(), "发布了" + num + "张优惠券:");//记录日志 return(result); }
private void couponBind() { BLL.user_coupon bll = new BLL.user_coupon(); DataTable dt = bll.GetList(" datediff(dd,end_time,'" + DateTime.Now + "')<0", " id").Tables[0]; this.ddlGroupId.Items.Clear(); this.ddlGroupId.Items.Add(new ListItem("请选择...", "")); foreach (DataRow dr in dt.Rows) { string Id = dr["id"].ToString(); string Title = dr["title"].ToString().Trim(); this.ddlGroupId.Items.Add(new ListItem(Title, Id)); } }
protected string GetCouponStatus(int _id) { string _title = string.Empty; Model.user_coupon model = new BLL.user_coupon().GetModel(_id); switch (model.status) { case 1: _title = "未使用"; break; case 2: _title = "已使用"; break; case 3: _title = "已过期"; break; } return(_title); }
private void RptBind(string _strWhere, string _orderby) { this.page = Vincent._DTcms.DTRequest.GetQueryInt("page", 1); if (this.status > 0) { this.ddlStatus.SelectedValue = this.status.ToString(); } if (this.coupon_stype > 0) { this.ddlPaymentStatus.SelectedValue = this.coupon_stype.ToString(); } txtKeywords.Text = this.keywords; BLL.user_coupon bll = new BLL.user_coupon(); this.rptList.DataSource = bll.GetList(this.pageSize, this.page, _strWhere, _orderby, out this.totalCount); this.rptList.DataBind(); //绑定页码 txtPageNum.Text = this.pageSize.ToString(); string pageUrl = Vincent._DTcms.Utils.CombUrlTxt("coupon_list.aspx", "status={0}&coupon_stype={1}&page={2}&page={3}", this.status.ToString(), this.coupon_stype.ToString(), this.keywords, "__id__"); PageContent.InnerHtml = Vincent._DTcms.Utils.OutPageList(this.pageSize, this.page, this.totalCount, pageUrl, 8); }
/// <summary> /// 获取订单总金额 /// </summary> /// <param name="total_amount"></param> protected void getTotalAmount() { total_amount = 0M; coupon_amount = 0M; refund_amount = 0M; if (datetime == null) { BLL.orders bll = new BLL.orders(); DataTable dt; if (this.outlet_id > 0) { dt = bll.GetOrderAmount(0, " status!=1 and status!=99 and store_id=" + this.outlet_id, " add_time desc,id desc").Tables[0]; } else if (this.city_id > 0) { BLL.openarea open = new BLL.openarea(); Model.openarea openm = open.GetModel(this.city_id); StringBuilder strTemp = new StringBuilder(); if (openm != null) { BLL.outlet outlet = new BLL.outlet(); DataTable dts = outlet.GetList(0, " city='" + openm.city + "'", " id").Tables[0]; if (dts.Rows.Count > 0) { StringBuilder st = new StringBuilder(); string ss = string.Empty; st.Append("("); foreach (DataRow item in dts.Rows) { st.Append(item["id"] + ","); } if (st.ToString().Trim() != "(") { ss = DelLastComma(st.ToString().Trim()); st.Append(")"); } strTemp.Append(" and store_id in" + ss + ")"); } else { strTemp.Append(" and store_id in(null)"); } } dt = bll.GetOrderAmount(0, " status!=1 and status!=99" + strTemp, " add_time desc,id desc").Tables[0]; } else { dt = bll.GetOrderAmount(0, " status!=1 and status!=99", " add_time desc,id desc").Tables[0]; } foreach (DataRow row in dt.Rows) { total_amount += decimal.Parse(row["order_amount"].ToString()); if (row["refund_status"].ToString() != "" && int.Parse(row["refund_status"].ToString()) == 3) //统计退款 { refund_amount += decimal.Parse(row["order_amount"].ToString()); } BLL.user_coupon_log couponbll = new BLL.user_coupon_log();//统计优惠券 if (row["str_code"].ToString() != "") { Model.user_coupon_log couponmodel = couponbll.GetModel(row["str_code"].ToString()); if (couponmodel != null && couponmodel.status == 2) { BLL.user_coupon copbl = new BLL.user_coupon(); Model.user_coupon copmo = copbl.GetModel(couponmodel.coupon_id); if (copmo != null) { if (copmo.amount > decimal.Parse(row["order_amount"].ToString())) { coupon_amount += decimal.Parse(row["order_amount"].ToString()); } else { coupon_amount += copmo.amount; } } } } } } else { BLL.orders bll = new BLL.orders(); DataTable dt; if (this.outlet_id > 0) { dt = bll.GetOrderAmount(0, " status!=1 and status!=99 and store_id=" + this.outlet_id, " add_time desc,id desc").Tables[0]; } else { dt = bll.GetOrderAmount(0, " status!=1 and status!=99", " add_time desc,id desc").Tables[0]; } //DataTable dt = bll.GetOrderAmount(0, " status!=1 and status!=99 and datediff(dd,add_time,'" + datetime + "')=0", " add_time desc,id desc").Tables[0]; foreach (DataRow row in dt.Rows) { total_amount += decimal.Parse(row["order_amount"].ToString()); if (row["refund_status"].ToString() != "" && int.Parse(row["refund_status"].ToString()) == 3) { refund_amount += decimal.Parse(row["order_amount"].ToString()); } BLL.user_coupon_log couponbll = new BLL.user_coupon_log();//统计优惠券 if (row["str_code"].ToString() != "") { Model.user_coupon_log couponmodel = couponbll.GetModel(row["str_code"].ToString()); if (couponmodel != null && couponmodel.status == 2) { BLL.user_coupon copbl = new BLL.user_coupon(); Model.user_coupon copmo = copbl.GetModel(couponmodel.coupon_id); if (copmo != null) { if (copmo.amount > decimal.Parse(row["order_amount"].ToString())) { coupon_amount += decimal.Parse(row["order_amount"].ToString()); } else { coupon_amount += copmo.amount; } } } } } } }
/// <summary> /// 获取订单总金额 /// </summary> /// <param name="total_amount"></param> protected void getTotalAmount() { total_amount = 0M; coupon_amount = 0M; refund_amount = 0M; if (date == null || date == "") { BLL.orders bll = new BLL.orders(); DataTable dt = bll.GetOrderAmount(0, " status!=1 and status!=99", " add_time desc,id desc").Tables[0]; foreach (DataRow row in dt.Rows) { total_amount += decimal.Parse(row["order_amount"].ToString()); if (row["refund_status"].ToString() != "" && int.Parse(row["refund_status"].ToString()) == 3) //统计退款 { refund_amount += decimal.Parse(row["order_amount"].ToString()); } BLL.user_coupon_log couponbll = new BLL.user_coupon_log();//统计优惠券 if (row["str_code"].ToString() != "") { Model.user_coupon_log couponmodel = couponbll.GetModel(row["str_code"].ToString()); if (couponmodel != null && couponmodel.status == 2) { BLL.user_coupon copbl = new BLL.user_coupon(); Model.user_coupon copmo = copbl.GetModel(couponmodel.coupon_id); if (copmo != null) { if (copmo.amount > decimal.Parse(row["order_amount"].ToString())) { coupon_amount += decimal.Parse(row["order_amount"].ToString()); } else { coupon_amount += copmo.amount; } } } } } } else { BLL.orders bll = new BLL.orders(); DataTable dt = bll.GetOrderAmount(0, " status!=1 and status!=99 and datediff(dd,add_time,'" + date + "')=0", " add_time desc,id desc").Tables[0]; foreach (DataRow row in dt.Rows) { total_amount += decimal.Parse(row["order_amount"].ToString()); if (row["refund_status"].ToString() != "" && int.Parse(row["refund_status"].ToString()) == 3) { refund_amount += decimal.Parse(row["order_amount"].ToString()); } BLL.user_coupon_log couponbll = new BLL.user_coupon_log();//统计优惠券 if (row["str_code"].ToString() != "") { Model.user_coupon_log couponmodel = couponbll.GetModel(row["str_code"].ToString()); if (couponmodel != null && couponmodel.status == 2) { BLL.user_coupon copbl = new BLL.user_coupon(); Model.user_coupon copmo = copbl.GetModel(couponmodel.coupon_id); if (copmo != null) { if (copmo.amount > decimal.Parse(row["order_amount"].ToString())) { coupon_amount += decimal.Parse(row["order_amount"].ToString()); } else { coupon_amount += copmo.amount; } } } } } } }
public string SubmitOrder(string goods, string addressId, string expressId, string totalprice, string bill_type, string bill_rise, string down_order, string coupon_no, string store_name, string store_address, string store_id, string user_id, string remark) { string returnvalue = ""; Model.orders model = new Model.orders(); BLL.orders bll = new BLL.orders(); //验证优惠券 var j = 0; BLL.user_coupon couponbll = new BLL.user_coupon(); Model.user_coupon coupon = null; if (coupon_no != "") { coupon = couponbll.GetModel(" str_code='" + coupon_no + "'"); if (coupon == null) { j = 1; } else { if (DateTime.Compare(coupon.end_time, DateTime.Now) <= 0) { j = 2; } if (coupon.status == 2) { j = 3; } } } if (j == 1) { return(returnvalue = "{\"status\":0,\"msg\":\"优惠券编码输入有误!\"}"); } if (j == 2) { return(returnvalue = "{\"status\":0,\"msg\":\"优惠券已经过期!\"}"); } if (j == 3) { return(returnvalue = "{\"status\":0,\"msg\":\"优惠券已使用!\"}"); } BLL.users bll1 = new BLL.users(); Model.users userinfo = bll1.GetModel(int.Parse(user_id)); if (addressId != "0")//快递收货 { //订单信息 Model.user_address modelAddress = new BLL.user_address().GetModel(int.Parse(addressId)); Model.express modelExpress = new BLL.express().GetModel(int.Parse(expressId)); model.order_no = CreateOrderNo(); model.accept_name = modelAddress.acceptName; model.area = modelAddress.id.ToString(); model.mobile = modelAddress.mobile; model.address = modelAddress.address; model.post_code = modelAddress.postcode.ToString(); model.add_time = DateTime.Now; model.user_id = userinfo.id; model.user_name = userinfo.user_name; model.express_id = int.Parse(expressId); model.express_fee = modelExpress.express_fee; model.express_status = 1; model.status = 1; decimal real_amount = Decimal.Parse(totalprice) - modelExpress.express_fee; model.real_amount = real_amount; model.order_amount = Decimal.Parse(totalprice); model.bill_type = int.Parse(bill_type); if (int.Parse(bill_type) != 0) { model.is_bill = 1; } model.invoice_rise = bill_rise; model.down_order = down_order; model.remark = remark; } else { //订单信息 Model.express modelExpress = new BLL.express().GetModel(int.Parse(expressId)); model.order_no = CreateOrderNo(); model.add_time = DateTime.Now; model.user_id = userinfo.id; model.user_name = userinfo.user_name; model.express_id = int.Parse(expressId); model.express_fee = modelExpress.express_fee; model.express_status = 1; model.status = 1; decimal real_amount = Decimal.Parse(totalprice) - modelExpress.express_fee; model.real_amount = real_amount; model.order_amount = Decimal.Parse(totalprice); model.bill_type = int.Parse(bill_type); if (int.Parse(bill_type) != 0) { model.is_bill = 1; } model.invoice_rise = bill_rise; model.down_order = down_order; model.store_name = store_name; model.store_address = store_address; model.store_id = int.Parse(store_id); model.remark = remark; } var k = 0; var p = 0; if (coupon != null) { decimal payamount = Decimal.Parse(totalprice) - coupon.amount; if (payamount > 0) { model.payable_amount = payamount;//实付款 model.str_code = coupon_no; } else { model.payable_amount = 0M;//实付款 model.str_code = coupon_no; model.status = 2; model.payment_status = 2; p = bll.Add(model); k = 1; } } ////商品信息value="<%#Eval("id") %>|<%#Eval("type") %>|<%#Eval("price") %>|<%#Eval("quantity") %>|<%#Eval("weight") %>|<%#Eval("img_url") %>" List <Model.order_goods> list = new List <Model.order_goods>(); string[] strArr = Vincent._DTcms.Utils.DelLastChar(goods, "&").Split('&'); foreach (var item in strArr) { string[] strArr2 = item.Split('|'); Model.order_goods modelGoods = new Model.order_goods(); modelGoods.goods_id = int.Parse(strArr2[0].ToString()); modelGoods.goods_price = decimal.Parse(strArr2[1].ToString()); modelGoods.quantity = int.Parse(strArr2[2].ToString()); modelGoods.goods_pic = strArr2[3].ToString(); modelGoods.goods_title = strArr2[4].ToString(); list.Add(modelGoods); } model.order_goods = list; int orderId = bll.Add(model); //优惠券使用记录 BLL.user_coupon_log cbll = new BLL.user_coupon_log(); Model.user_coupon_log cmodel = new Model.user_coupon_log(); if (coupon != null) { cmodel.user_id = userinfo.id; cmodel.user_name = userinfo.user_name; cmodel.coupon_id = coupon.id; cmodel.str_code = coupon.str_code; cmodel.order_id = orderId; cmodel.order_no = model.order_no; cmodel.add_time = coupon.add_time; cmodel.use_time = DateTime.Now; cmodel.status = 1; } if (k == 1 && p > 0) { cmodel.status = 2; cbll.Add(cmodel); return(returnvalue = "{\"status\":3,\"msg\":\"订单提交成功!\"}"); } if (orderId > 0) { if (coupon != null) { cbll.Add(cmodel); } return(returnvalue = "{\"status\":1,\"msg\":\"订单提交成功,请付款!\",\"orderId\":" + orderId + "}"); Web.UI.ShopCart.ClearCart("0"); } else { if (coupon != null) { cbll.Add(cmodel); } return(returnvalue = "{\"status\":0,\"msg\":\"订单提交失败,请重新提交订单!\"}"); } }
//提交发送 protected void btnSubmit_Click(object sender, EventArgs e) { ChkAdminLevel("issue_coupon", Vincent._DTcms.DTEnums.ActionEnum.Add.ToString()); //检查权限 //优惠券类型 if (ddlGroupId.SelectedValue == "") { JscriptMsg("请选择优惠券类型!", "", "Error"); return; } //检查短信内容 if (txtSmsContent.Text.Trim() == "") { JscriptMsg("请输入短信内容!", "", "Error"); return; } //检查发送类型 if (rblSmsType.SelectedValue == "1") { if (txtMobileNumbers.Text.Trim() == "") { JscriptMsg("请输入手机号码!", "", "Error"); return; } string[] oldMobileArr = txtMobileNumbers.Text.Trim().Split(',');//将手机号存入数组 DataTable dt = new BLL.user_coupon().GetList(0, " title='" + ddlGroupId.SelectedValue + "' and status!=2 and status!=4", " id").Tables[0]; if (dt.Rows.Count < 0) { JscriptMsg("没有可发放的优惠券!", "", "Error"); return; } if (oldMobileArr.Length > dt.Rows.Count) { JscriptMsg("该类型优惠券数量不够!", "", "Error"); return; } for (int i = 0; i < oldMobileArr.Length; i++) { Model.users model = new BLL.users().GetModelMobile(oldMobileArr[i]); if (model != null) { Model.user_coupon couponm = new BLL.user_coupon().GetModel(int.Parse(dt.Rows[i]["id"].ToString())); couponm.userid = model.id; couponm.status = 4; new BLL.user_coupon().Update(couponm); } } //开始发送短信 string msg = string.Empty; bool result = new BLL.sms_message().Send(txtMobileNumbers.Text.Trim(), txtSmsContent.Text.Trim(), 2, out msg); if (result) { AddAdminLog(Vincent._DTcms.DTEnums.ActionEnum.Add.ToString(), "发送手机短信"); //记录日志 JscriptMsg(msg, "../coupon/coupon_list.aspx", "Success"); return; } JscriptMsg(msg, "", "Error"); return; } else { ArrayList al = new ArrayList(); for (int i = 0; i < cblGroupId.Items.Count; i++) { if (cblGroupId.Items[i].Selected) { al.Add(cblGroupId.Items[i].Value); } } if (al.Count < 1) { JscriptMsg("请选择会员组别!", "", "Error"); return; } string _mobiles = GetGroupMobile(al); string[] oldMobileArr = _mobiles.Split(',');//将手机号存入数组 DataTable dt = new BLL.user_coupon().GetList(0, " title='" + ddlGroupId.SelectedValue + "' and status!=2 and status!=4", " id").Tables[0]; if (dt.Rows.Count < 0) { JscriptMsg("没有可发放的优惠券!", "", "Error"); return; } if (oldMobileArr.Length > dt.Rows.Count) { JscriptMsg("该类型优惠券数量不够!", "", "Error"); return; } for (int i = 0; i < oldMobileArr.Length; i++) { Model.users model = new BLL.users().GetModelMobile(oldMobileArr[i]); if (model != null) { Model.user_coupon couponm = new BLL.user_coupon().GetModel(int.Parse(dt.Rows[i]["id"].ToString())); couponm.userid = model.id; couponm.status = 4; new BLL.user_coupon().Update(couponm); } } //开始发送短信 string msg = string.Empty; bool result = new BLL.sms_message().Send(_mobiles, txtSmsContent.Text.Trim(), 2, out msg); if (result) { AddAdminLog(Vincent._DTcms.DTEnums.ActionEnum.Add.ToString(), "发送手机短信"); //记录日志 JscriptMsg(msg, "issue_coupon.aspx", "Success"); return; } JscriptMsg(msg, "", "Error"); return; } }