Beispiel #1
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public int Update(TB_BillCouponEntity Entity)
 {
     SqlParameter[] sqlParameters =
     {
         new SqlParameter("@Id",             Entity.Id),
         new SqlParameter("@BusCode",        Entity.BusCode),
         new SqlParameter("@StoCode",        Entity.StoCode),
         new SqlParameter("@CCode",          Entity.CCode),
         new SqlParameter("@CCname",         Entity.CCname),
         new SqlParameter("@TStatus",        Entity.TStatus),
         new SqlParameter("@BillCode",       Entity.BillCode),
         new SqlParameter("@CouponCode",     Entity.CouponCode),
         new SqlParameter("@CouponMoney",    Entity.CouponMoney),
         new SqlParameter("@MemberCardCode", Entity.MemberCardCode),
         new SqlParameter("@RealPay",        Entity.RealPay),
         new SqlParameter("@VIMoney",        Entity.VIMoney),
         new SqlParameter("@Remark",         Entity.Remark),
         new SqlParameter("@UseType",        Entity.UseType),
         new SqlParameter("@ShiftCode",      Entity.ShiftCode),
         new SqlParameter("@CouponName",     Entity.CouponName),
         new SqlParameter("@McCode",         Entity.McCode),
     };
     return(DBHelper.ExecuteNonQuery("dbo.p_TB_BillCoupon_Update", CommandType.StoredProcedure, sqlParameters));
 }
Beispiel #2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public DataTable Add(ref TB_BillCouponEntity Entity, ref string mescode)
        {
            intReturn = 0;
            SqlParameter[] sqlParameters =
            {
                new SqlParameter("@Id",             Entity.Id),
                new SqlParameter("@BusCode",        Entity.BusCode),
                new SqlParameter("@StoCode",        Entity.StoCode),
                new SqlParameter("@CCode",          Entity.CCode),
                new SqlParameter("@CCname",         Entity.CCname),
                new SqlParameter("@TStatus",        Entity.TStatus),
                new SqlParameter("@BillCode",       Entity.BillCode),
                new SqlParameter("@CouponCode",     Entity.CouponCode),
                new SqlParameter("@CouponMoney",    Entity.CouponMoney),
                new SqlParameter("@MemberCardCode", Entity.MemberCardCode),
                new SqlParameter("@RealPay",        Entity.RealPay),
                new SqlParameter("@VIMoney",        Entity.VIMoney),
                new SqlParameter("@Remark",         Entity.Remark),
                new SqlParameter("@UseType",        Entity.UseType),
                new SqlParameter("@ShiftCode",      Entity.ShiftCode),
                new SqlParameter("@CouponName",     Entity.CouponName),
                new SqlParameter("@McCode",         Entity.McCode),
                new SqlParameter("@mescode",        SqlDbType.NVarChar,256, mescode),
                new SqlParameter("@TicType",        Entity.TicType),
                new SqlParameter("@TicWay",         Entity.TicWay)
            };
            sqlParameters[0].Direction  = ParameterDirection.Output;
            sqlParameters[17].Direction = ParameterDirection.Output;
            DataTable dt = DBHelper.ExecuteDataTable("dbo.p_TB_BillCoupon_Add", CommandType.StoredProcedure, sqlParameters);

            if (dt != null && dt.Rows.Count > 0)
            {
                Entity.Id = int.Parse(sqlParameters[0].Value.ToString());
            }
            return(dt);
        }
Beispiel #3
0
        /// <summary>
        /// 使用优惠券
        /// </summary>
        /// <param name="dicPar"></param>
        public void AddCoupon(Dictionary <string, object> dicPar)
        {
            //要检测的参数信息
            List <string> pra = new List <string>()
            {
                "key", "buscode", "stocode", "billcode", "couponinfo"
            };

            //检测方法需要的参数
            if (!CheckActionParameters(dicPar, pra))
            {
                return;
            }
            //获取参数信息
            string guid     = "1";
            string uid      = "1";
            string buscode  = dicPar["buscode"].ToString();
            string stocode  = dicPar["stocode"].ToString();
            string billcode = dicPar["billcode"].ToString();
            //string couponJson = dicPar["couponinfo"].ToString();
            string  memcode   = "";
            dynamic couponObj = dicPar["couponinfo"];
            string  paymethod = couponObj["usepaytype"].ToString();
            //获取账单详情、菜品详情
            DataSet   ds       = new bllTB_Bill().GetDetail("", "", billcode, stocode, "");
            DataTable dtBill   = ds.Tables[0];
            DataTable dtPay    = ds.Tables[1];
            DataTable dtDish   = ds.Tables[2];
            DataTable dtCoupon = ds.Tables[4];

            //使用优惠券
            if (dtBill != null && dtBill.Rows.Count > 0)
            {
                string BillCode  = dtBill.Rows[0]["PKCode"].ToString();
                string ShiftCode = dtBill.Rows[0]["ShiftCode"].ToString();
                memcode = dtBill.Rows[0]["CCode"].ToString();
                decimal ToPayMoney = StringHelper.StringToDecimal(dtBill.Rows[0]["ToPayMoney"].ToString());
                decimal PayMoney   = StringHelper.StringToDecimal(dtBill.Rows[0]["PayMoney"].ToString());
                if (PayMoney > 0)
                {
                    ReturnResultJson("1", "账单已有支付,无法使用优惠券");
                    return;
                }
                if (ToPayMoney <= 0)
                {
                    ReturnResultJson("1", "付款金额为0,无法使用优惠券。");
                    return;
                }

                //使用优惠券
                TB_BillCouponEntity CouponEntity = new TB_BillCouponEntity();
                CouponEntity.BusCode   = buscode;
                CouponEntity.StoCode   = stocode;
                CouponEntity.BillCode  = billcode;
                CouponEntity.ShiftCode = ShiftCode;
                CouponEntity.TicType   = "0";
                CouponEntity.TicWay    = "";
                string msg = OrderHelper.UseCoupon(billcode, couponObj, ToPayMoney, ref dtDish, ref CouponEntity, dtCoupon);
                if (string.IsNullOrWhiteSpace(msg))
                {
                    //线上验券
                    string        MemcardUrl = Helper.GetAppSettings("ServiceUrl") + "/coupon/WScheckcoupon.ashx";
                    StringBuilder postStr    = new StringBuilder();
                    postStr.Append("actionname=couponrecoverynew&usercode=" + uid + "&parameters={\"GUID\":\"" + guid + "\",\"USER_ID\":\"" + guid + "\",\"buscode\":\"" + buscode + "\",\"couponcode\":\"" + CouponEntity.CouponCode + "\",\"stocode\":\"" + stocode + "\",\"way\":\"PC\",\"username\":\"线上点餐\",\"usercode\":\"" + memcode + "\",\"orderno\":\"" + billcode + "\"}");
                    string strAdminJson = Helper.HttpWebRequestByURL(MemcardUrl, postStr.ToString());
                    if (!string.IsNullOrEmpty(strAdminJson))
                    {
                        string  checkmsg       = string.Empty;
                        string  status         = string.Empty;
                        DataSet dsCheckCcoupon = JsonHelper.JsonToDataSet(strAdminJson, out status, out checkmsg);
                        if (status == "0")
                        {
                            //添加使用券记录
                            string    id       = "";
                            DataTable dtAdd    = new BLL.bllTB_BillCoupon().Add("", "", id, buscode, stocode, "", "线上点餐", "1", CouponEntity.BillCode, CouponEntity.CouponCode, CouponEntity.CouponMoney.ToString(), "", CouponEntity.RealPay.ToString(), CouponEntity.VIMoney.ToString(), CouponEntity.Remark, CouponEntity.UseType, ShiftCode, CouponEntity.CouponName, CouponEntity.McCode, CouponEntity.TicType, CouponEntity.TicWay);
                            string    restatus = "1";
                            string    remsg    = "优惠券使用失败";
                            if (dtAdd != null && dtAdd.Rows.Count > 0)
                            {
                                restatus = "0";
                                remsg    = "优惠券使用成功";
                                //更新菜品和账单信息
                                dtCoupon.Rows.Add(CouponEntity.CouponName, CouponEntity.CouponCode, CouponEntity.CouponMoney, CouponEntity.RealPay, CouponEntity.VIMoney, CouponEntity.BillCode, CouponEntity.McCode);
                                dtCoupon.AcceptChanges();
                                OrderHelper.ResetBillMoney(ref dtBill, dtDish, dtCoupon);
                                dtBill.Rows[0]["PayMethod"] = paymethod;
                                UpdateBillAndDish(dtBill, dtDish);
                                RefreshBill(billcode, stocode, "");
                                return;
                            }
                            if (restatus != "0")
                            {
                                //执行取消优惠券接口
                                postStr = new StringBuilder();
                                postStr.Append("actionname=couponrecoverycancelnew&usercode=" + uid + "&parameters=" +
                                               "{\"GUID\":\"" + guid + "\"," +
                                               "\"USER_ID\":\"" + guid + "\"," +
                                               "\"buscode\":\"" + buscode + "\"," +
                                               "\"couponcode\":\"" + CouponEntity.CouponCode + "\"," +
                                               "\"stocode\":\"" + stocode + "\"," +
                                               "\"username\":\"线上点餐\"," +
                                               "\"usercode\":\"" + memcode + "\"," +
                                               "\"way\":\"App\"}");
                                Helper.HttpWebRequestByURL(MemcardUrl, postStr.ToString());
                            }
                            ReturnResultJson(restatus, checkmsg);
                            return;
                        }
                    }
                    ReturnResultJson("1", "线上消券错误");
                    return;
                }
                else
                {
                    ReturnResultJson("1", msg);
                    return;
                }
            }
            else
            {
                ReturnResultJson("1", "账单获取错误,请重试");
            }
        }
Beispiel #4
0
        /// <summary>
        /// 使用优惠券逻辑
        /// </summary>
        /// <param name="dtCoupon"></param>
        /// <returns></returns>
        public static string UseCoupon(string BillCode, dynamic coupon, decimal NowPayMoney, ref DataTable dtOrderDish, ref TB_BillCouponEntity CouponEntity, DataTable dtBillCoupon)
        {
            string Msg        = "";
            string CouponCode = coupon["checkcode"].ToString();
            string CouponName = coupon["couname"].ToString();
            string sectype    = coupon["sectype"].ToString();  //券类型(ProCoupon-商品券,FilmCoupon-影城券,DIC00000045-代金券)
            string discode    = coupon["discodes"].ToString(); //抵用菜品编号

            discode = "'" + discode.TrimStart(',').TrimEnd(',').Replace(",", "','") + "'";
            string bigclass = coupon["fincodes"].ToString();    //财务类别

            if (!string.IsNullOrWhiteSpace(bigclass))
            {
                bigclass = "'" + bigclass.TrimStart(',').TrimEnd(',').Replace(",", "','") + "'";
            }
            decimal maxmoney    = StringHelper.StringToDecimal(coupon["maxmoney"].ToString());    //消费满金额
            int     uselimit    = StringHelper.StringToInt(coupon["uselimit"].ToString());        //使用上限
            decimal singlemoney = StringHelper.StringToDecimal(coupon["singlemoney"].ToString()); //优惠券金额
            decimal disuselack  = StringHelper.StringToDecimal(coupon["disuselack"].ToString());  //补差金额
            string  Remark      = CouponCode;
            string  McCode      = coupon["mccode"].ToString();

            decimal RealPay       = 0;
            decimal VIMoney       = 0;
            decimal DiscountPrice = 0;
            string  UseType       = "";
            string  OrderDishId   = "";

            //获取已点菜品信息
            DataRow[] drCoupon = new DataRow[] { };
            //使用上限判断
            if (dtBillCoupon != null && dtBillCoupon.Rows.Count > 0)
            {
                drCoupon = dtBillCoupon.Select("BillCode='" + BillCode + "' and McCode='" + McCode + "'");
                if (drCoupon.Length >= uselimit)
                {
                    Msg = "优惠券超过使用上限“" + uselimit.ToString() + "”张,请检查!";
                    return(Msg);
                }
            }

            //筛选掉退菜和套内菜品
            switch (sectype)
            {
            case "ProCoupon":        //商品券
                //按价格排序(先优惠最高金额的菜品)
                dtOrderDish.DefaultView.Sort = "Price DESC";
                DataTable dtNewOrderDish = dtOrderDish.DefaultView.ToTable();
                DataRow[] drDish         = dtNewOrderDish.Select("DisCode in(" + discode + ")");
                int       index          = 0;
                if (drDish.Length == 0)
                {
                    Msg = "没有可优惠的商品信息,请检查!";
                    return(Msg);
                }

                RealPay = StringHelper.StringToDecimal(drDish[index]["Price"].ToString()) - disuselack;
                VIMoney = 0;
                UseType = "4";
                break;

            default:        //满减券,代金券
                RealPay     = singlemoney;
                UseType     = "2";
                OrderDishId = "";
                decimal B_TCouponMoney   = 0;     //券总金额
                decimal B_CouponMoney    = 0;     //该类型券金额
                decimal B_TDish_bigclass = 0;
                decimal B_Dish_bigclass  = 0;

                decimal diff = 0;

                if (drCoupon.Length > 0)        //该同类型券已使用金额
                {
                    DataTable dt_BCoupon = drCoupon.CopyToDataTable();
                    B_TCouponMoney = GetConponRealMoney(dt_BCoupon, string.Empty);
                    B_CouponMoney  = GetConponRealMoney(dt_BCoupon, McCode);
                }
                B_TDish_bigclass = GetDishesRealMoney(dtOrderDish, McCode);        //已点菜品金额

                //获取订单菜品财务类别的合计金额
                if (bigclass.Length > 0)
                {
                    diff = B_Dish_bigclass - B_CouponMoney;
                }
                else
                {
                    diff = B_TDish_bigclass - B_TCouponMoney;
                }
                if (maxmoney > 0)                                  //消费满金额
                {
                    if (diff < maxmoney || NowPayMoney < maxmoney) //满额不够
                    {
                        Msg = "优惠券满" + maxmoney.ToString() + "元不满足,请检查!";
                        return(Msg);
                    }
                }

                if (diff < NowPayMoney)        //差额小于剩余金额
                {
                    NowPayMoney = diff;
                }

                if (NowPayMoney < singlemoney)        //剩余金额<优惠券金额
                {
                    RealPay = NowPayMoney;
                    VIMoney = singlemoney - NowPayMoney;
                }
                break;
            }
            //设置菜品的折扣
            if (OrderDishId.Length > 0)
            {
                DataRow[] arrdr = dtOrderDish.Select("orderdiscode='" + OrderDishId + "'");
                if (arrdr.Length > 0)
                {
                    arrdr[0]["DiscountType"]   = UseType;
                    arrdr[0]["DiscountPrice"]  = DiscountPrice;
                    arrdr[0]["DiscountRemark"] = CouponCode;
                }
            }

            CouponEntity.CouponCode     = CouponCode;
            CouponEntity.CouponMoney    = singlemoney;
            CouponEntity.MemberCardCode = "";
            CouponEntity.RealPay        = RealPay;
            CouponEntity.VIMoney        = VIMoney;
            CouponEntity.Remark         = OrderDishId;
            CouponEntity.UseType        = UseType;
            CouponEntity.CouponName     = CouponName;
            CouponEntity.McCode         = McCode;
            return(Msg);
        }