Example #1
0
        /// <summary>
        /// 确认支付
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public static bool ConfirmPay(int ID, int PayType, int pay)
        {
            orders bll = new orders("dt_");

            Model.orders model = bll.GetModel(ID);

            user_coupon coubll = new user_coupon("dt_");

            Model.user_coupon coumodel = new Model.user_coupon();
            if (model.str_code != "")
            {
                coumodel = coubll.GetModel(" str_code='" + model.str_code + "'");
            }

            if (model.status > 1 || model.payment_status == 2)
            {
                return(false);
            }
            model.payment_status = 2;
            model.payment_time   = DateTime.Now;
            model.status         = PayType;
            model.payment_id     = pay;
            model.confirm_time   = DateTime.Now;
            if (bll.Update(model))
            {
                if (model.str_code != "")
                {
                    coumodel.status = 2;
                    coubll.Update(coumodel);

                    users       bll1     = new users("dt_");
                    Model.users userinfo = bll1.GetModel(model.user_id);
                    //优惠券使用记录
                    user_coupon_log       cbll   = new user_coupon_log("dt_");
                    Model.user_coupon_log cmodel = new Model.user_coupon_log();
                    cmodel.user_id   = userinfo.id;
                    cmodel.user_name = userinfo.user_name;
                    cmodel.coupon_id = coumodel.id;
                    cmodel.str_code  = model.str_code;
                    cmodel.order_id  = model.id;
                    cmodel.order_no  = model.order_no;
                    cmodel.add_time  = coumodel.add_time;
                    cmodel.use_time  = DateTime.Now;
                    cmodel.status    = 2;
                }

                return(true);
            }

            return(false);
        }
Example #2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.user_coupon_log model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update " + databaseprefix + "user_coupon_log set ");
            strSql.Append("user_id=@user_id,");
            strSql.Append("user_name=@user_name,");
            strSql.Append("coupon_id=@coupon_id,");
            strSql.Append("str_code=@str_code,");
            strSql.Append("order_id=@order_id,");
            strSql.Append("order_no=@order_no,");
            strSql.Append("add_time=@add_time,");
            strSql.Append("use_time=@use_time,");
            strSql.Append("status=@status");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id",        SqlDbType.Int,         4),
                new SqlParameter("@user_id",   SqlDbType.Int,         4),
                new SqlParameter("@user_name", SqlDbType.NVarChar,  255),
                new SqlParameter("@coupon_id", SqlDbType.Int,         4),
                new SqlParameter("@str_code",  SqlDbType.NVarChar,  255),
                new SqlParameter("@order_id",  SqlDbType.Int,         4),
                new SqlParameter("@order_no",  SqlDbType.NVarChar,  100),
                new SqlParameter("@add_time",  SqlDbType.DateTime),
                new SqlParameter("@use_time",  SqlDbType.DateTime),
                new SqlParameter("@status",    SqlDbType.TinyInt, 1)
            };
            parameters[0].Value = model.id;
            parameters[1].Value = model.user_id;
            parameters[2].Value = model.user_name;
            parameters[3].Value = model.coupon_id;
            parameters[4].Value = model.str_code;
            parameters[5].Value = model.order_id;
            parameters[6].Value = model.order_no;
            parameters[7].Value = model.add_time;
            parameters[8].Value = model.use_time;
            parameters[9].Value = model.status;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.user_coupon_log model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into " + databaseprefix + "user_coupon_log(");
            strSql.Append("user_id,user_name,coupon_id,str_code,order_id,order_no,add_time,use_time,status)");
            strSql.Append(" values (");
            strSql.Append("@user_id,@user_name,@coupon_id,@str_code,@order_id,@order_no,@add_time,@use_time,@status)");
            strSql.Append(";set @ReturnValue= @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@user_id",   SqlDbType.Int,         4),
                new SqlParameter("@user_name", SqlDbType.NVarChar,  255),
                new SqlParameter("@coupon_id", SqlDbType.Int,         4),
                new SqlParameter("@str_code",  SqlDbType.NVarChar,  255),
                new SqlParameter("@order_id",  SqlDbType.Int,         4),
                new SqlParameter("@order_no",  SqlDbType.NVarChar,  100),
                new SqlParameter("@add_time",  SqlDbType.DateTime),
                new SqlParameter("@use_time",  SqlDbType.DateTime),
                new SqlParameter("@status",    SqlDbType.TinyInt,     1),new SqlParameter("@ReturnValue", SqlDbType.Int)
            };
            parameters[0].Value     = model.user_id;
            parameters[1].Value     = model.user_name;
            parameters[2].Value     = model.coupon_id;
            parameters[3].Value     = model.str_code;
            parameters[4].Value     = model.order_id;
            parameters[5].Value     = model.order_no;
            parameters[6].Value     = model.add_time;
            parameters[7].Value     = model.use_time;
            parameters[8].Value     = model.status;
            parameters[9].Direction = ParameterDirection.Output;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Example #4
0
        /// <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;
                                }
                            }
                        }
                    }
                }
            }
        }
Example #5
0
 /// <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;
                         }
                     }
                 }
             }
         }
     }
 }
Example #6
0
        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\":\"订单提交失败,请重新提交订单!\"}");
            }
        }
Example #7
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.user_coupon_log GetModel(string str_code)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 id,user_id,user_name,coupon_id,str_code,order_id,order_no,add_time,use_time,status from " + databaseprefix + "user_coupon_log ");
            strSql.Append(" where str_code=@str_code");
            SqlParameter[] parameters =
            {
                new SqlParameter("@str_code", SqlDbType.NVarChar, 50)
            };
            parameters[0].Value = str_code;

            Model.user_coupon_log model = new Model.user_coupon_log();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["id"] != null && 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"] != null && ds.Tables[0].Rows[0]["user_id"].ToString() != "")
                {
                    model.user_id = int.Parse(ds.Tables[0].Rows[0]["user_id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["user_name"] != null && ds.Tables[0].Rows[0]["user_name"].ToString() != "")
                {
                    model.user_name = ds.Tables[0].Rows[0]["user_name"].ToString();
                }
                if (ds.Tables[0].Rows[0]["coupon_id"] != null && ds.Tables[0].Rows[0]["coupon_id"].ToString() != "")
                {
                    model.coupon_id = int.Parse(ds.Tables[0].Rows[0]["coupon_id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["str_code"] != null && ds.Tables[0].Rows[0]["str_code"].ToString() != "")
                {
                    model.str_code = ds.Tables[0].Rows[0]["str_code"].ToString();
                }
                if (ds.Tables[0].Rows[0]["order_id"] != null && ds.Tables[0].Rows[0]["order_id"].ToString() != "")
                {
                    model.order_id = int.Parse(ds.Tables[0].Rows[0]["order_id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["order_no"] != null && ds.Tables[0].Rows[0]["order_no"].ToString() != "")
                {
                    model.order_no = ds.Tables[0].Rows[0]["order_no"].ToString();
                }
                if (ds.Tables[0].Rows[0]["add_time"] != null && ds.Tables[0].Rows[0]["add_time"].ToString() != "")
                {
                    model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString());
                }
                if (ds.Tables[0].Rows[0]["use_time"] != null && ds.Tables[0].Rows[0]["use_time"].ToString() != "")
                {
                    model.use_time = DateTime.Parse(ds.Tables[0].Rows[0]["use_time"].ToString());
                }
                if (ds.Tables[0].Rows[0]["status"] != null && ds.Tables[0].Rows[0]["status"].ToString() != "")
                {
                    model.status = int.Parse(ds.Tables[0].Rows[0]["status"].ToString());
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
Example #8
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Model.user_coupon_log model)
 {
     return(dal.Update(model));
 }
Example #9
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(Model.user_coupon_log model)
 {
     return(dal.Add(model));
 }