示例#1
0
        /// <summary>
        /// 根据订单编号,完成订单支付后续操作
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public int FinshPackageOrder(int orderId)
        {
            int number = 0;//实际操作影响行数

            using (SqlConnection conn = (SqlConnection)DataSource.GetConnection())
            {
                conn.Open();
                using (SqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        //第一步骤:修改订单状态为支付完成但未配货
                        string strSql1 = $"update CsOrder set OrderState=2 where OrderId={orderId}";
                        number += DbClient.ExecuteSql(conn, trans, strSql1, null);
                        //第二步骤:修改套餐库存
                        CsOrderDetailDal orderDetailDal = new CsOrderDetailDal();
                        //查询出本次订单中购买螃蟹列表
                        List <CsOrderDetail> DetailList = orderDetailDal.GetModelList(" and OrderId=" + orderId + " and ChoseType=3");
                        if (DetailList.Count > 0)
                        {
                            foreach (CsOrderDetail OrderDetail in DetailList)
                            {
                                string strSql2 = $"update CsPackage set PackageStock=PackageStock-{OrderDetail.ProductNumber} where PackageId={OrderDetail.ProductId}";
                                number += DbClient.ExecuteSql(conn, trans, strSql2, null);
                            }
                        }
                        //第三步,修改用户的购买累计重量
                        //decimal total = totalWeight * orderCopies;
                        //string strSql3 = $"update CsUsers set TotalWight=TotalWight+{total} where UserId={userId}";
                        //number += DbClient.ExecuteSql(conn, trans, strSql3, null);
                        if (number == (DetailList.Count + 1))
                        {
                            trans.Commit();
                            return(number);
                        }
                        else
                        {
                            trans.Rollback();
                            return(0);
                        }
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Log(ex.Message);
                        trans.Rollback();
                        return(0);
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// 支付完成,修改订单状态,生成扣除库存与修改用户购买重量
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public int FinshOrder(int orderId, int userId, decimal totalWeight, int orderCopies)
        {
            int number = 0;//实际操作影响行数

            try
            {
                //第一步骤:修改订单状态为支付完成但未配货
                string strSql1 = $"update CsOrder set OrderState=2 where OrderId={orderId}";
                number = DbClient.Excute(strSql1);
                //第二步骤:修改螃蟹库存
                CsOrderDetailDal orderDetailDal = new CsOrderDetailDal();
                //查询出本次订单中购买螃蟹列表
                List <CsOrderDetail> DetailList = orderDetailDal.GetModelList(" and OrderId=" + orderId + " and ChoseType=1");
                if (DetailList.Count > 0)
                {
                    foreach (CsOrderDetail OrderDetail in DetailList)
                    {
                        string strSql2 = $"update CsProducts set ProductStock=ProductStock-{OrderDetail.ProductNumber} where ProductId={OrderDetail.ProductId}";
                        DbClient.Excute(strSql2);
                    }
                }
                //第三步,修改用户的购买累计重量
                decimal total   = totalWeight * orderCopies;
                string  strSql3 = $"update CsUsers set TotalWight=TotalWight+{total} where UserId={userId}";
                DbClient.Excute(strSql3);
                if (number > 0)
                {
                    return(number);
                }
                else
                {
                    return(0);
                }
            }
            catch (Exception ex)
            {
                LogHelper.Log(ex.Message, "完成支付出错");
                return(0);
            }
        }