Beispiel #1
0
 private bool UpdateCount(BXTOrder order, SqlTransaction tran)
 {
     if (order.OrderType == 3)
     {
         //活动
         //插入相关报名成功信息
         var joinItem = ActivityJoinBLL.Instance.GetDetailJoinInfo(order.CreateUser.ToInt64(), order.ItemID.Value, tran);
         joinItem.IsFeed = 1;
         if (ActivityJoinBLL.Instance.Update(joinItem, tran).Ok)
         {
             return(ActivityFeeBLL.Instance.UpdateCount(order.BuyCount.Value, joinItem.ActivityFeeId.Value, tran));
         }
         else
         {
             return(false);
         }
     }
     else
     {
         //礼物/课程/数据
         //更新报名成功信息
         var buyItem = UserGiftBLL.Instance.GetDetailBuyInfo(order.CreateUser.ToInt64(), order.ItemID.Value, tran);
         buyItem.IsPay = 1;
         if (UserGiftBLL.Instance.Update(buyItem, tran).Ok)
         {
             return(GiftFeeBLL.Instance.UpdateCount(order.BuyCount.Value, buyItem.GiftFeeId.Value, tran));
         }
         else
         {
             return(false);
         }
     }
 }
Beispiel #2
0
        public string CreateOrder(long userid, decimal fee, long mainId, int orderType, string orerDesc, string seq, int count, DateTime now, SqlTransaction tran, out int result, out string payorderid)
        {
            result = 0;
            string msg = string.Empty;

            var bll = BXTOrderBLL.Instance;

            payorderid = seq + mainId.ToString() + now.ToString("yyyyMMddHHmmssfff") + orderType.ToString();

            BXTOrder order = new BXTOrder()
            {
                Fee        = fee * count,//计算总费用
                CreateTime = now,
                CreateUser = userid.ToString(),
                IsDelete   = 0,
                IsPay      = 0,
                ItemID     = mainId,
                OrderType  = orderType,
                OrerDesc   = orerDesc,
                PayOrderID = payorderid,
                BuyCount   = count,
            };

            if ((result = bll.Add(order, tran)) <= 0)
            {
                msg = "创建订单时失败,请重试!";
            }
            return(msg);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool Update(BXTOrder model, SqlTransaction tran = null)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update BXTOrder set ");
            strSql.Append("PayOrderID=@PayOrderID,OrderType=@OrderType,ItemID=@ItemID,Fee=@Fee,OrerDesc=@OrerDesc,CreateUser=@CreateUser,CreateTime=@CreateTime,IsPay=@IsPay,IsDelete=@IsDelete,BuyCount=@BuyCount");

            strSql.Append(" where OrderID=@OrderID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@PayOrderID", model.PayOrderID),
                new SqlParameter("@OrderType",  model.OrderType),
                new SqlParameter("@ItemID",     model.ItemID),
                new SqlParameter("@Fee",        model.Fee),
                new SqlParameter("@OrerDesc",   model.OrerDesc),
                new SqlParameter("@CreateUser", model.CreateUser),
                new SqlParameter("@CreateTime", model.CreateTime),
                new SqlParameter("@IsPay",      model.IsPay),
                new SqlParameter("@IsDelete",   model.IsDelete),
                new SqlParameter("@BuyCount",   model.BuyCount),


                new SqlParameter("@OrderID",    model.OrderID)
            };

            if (tran == null)
            {
                return(SqlHelper.ExecuteSql(strSql.ToString(), CommandType.Text, parameters) > 0);
            }
            else
            {
                return(SqlHelper.ExecuteSql(tran, CommandType.Text, strSql.ToString(), parameters) > 0);
            }
        }
        /// <summary>
        /// 添加一条数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Add(BXTOrder model, SqlTransaction tran = null)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into BXTOrder(");
            strSql.Append(" PayOrderID,OrderType,ItemID,Fee,OrerDesc,CreateUser,CreateTime,IsPay,IsDelete,BuyCount )");
            strSql.Append(" values (");
            strSql.Append("@PayOrderID,@OrderType,@ItemID,@Fee,@OrerDesc,@CreateUser,@CreateTime,@IsPay,@IsDelete,@BuyCount);select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@PayOrderID", model.PayOrderID),
                new SqlParameter("@OrderType",  model.OrderType),
                new SqlParameter("@ItemID",     model.ItemID),
                new SqlParameter("@Fee",        model.Fee),
                new SqlParameter("@OrerDesc",   model.OrerDesc),
                new SqlParameter("@CreateUser", model.CreateUser),
                new SqlParameter("@CreateTime", model.CreateTime),
                new SqlParameter("@IsPay",      model.IsPay),
                new SqlParameter("@IsDelete",   model.IsDelete),
                new SqlParameter("@BuyCount",   model.BuyCount),
            };

            object obj;

            if (tran == null)
            {
                obj = SqlHelper.GetSingle(strSql.ToString(), CommandType.Text, parameters);
            }
            else
            {
                obj = SqlHelper.GetSingle(tran, CommandType.Text, strSql.ToString(), parameters);
            }
            return(obj == null ? 0 : Convert.ToInt32(obj));
        }
Beispiel #5
0
        /// <summary>
        /// 修改 (可能有其他业务逻辑检查)
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResultInfo Update(BXTOrder model)
        {
            ResultInfo ri = new ResultInfo();

            if (Edit(model))
            {
                ri.Ok  = true;
                ri.Msg = "修改成功";
            }

            return(ri);
        }
Beispiel #6
0
        /// <summary>
        /// 保存 (可能有其他业务逻辑检查)
        /// </summary>
        /// <param name="model">实体</param>
        /// <returns></returns>
        public ResultInfo Create(BXTOrder model, SqlTransaction tran = null)
        {
            ResultInfo ri = new ResultInfo();

            if (model == null)
            {
                return(ri);
            }

            int result = Add(model, tran);

            if (result > 0)
            {
                ri.Ok  = true;
                ri.Msg = "添加成功";
            }

            return(ri);
        }
Beispiel #7
0
        private string PayCallBack(Action <BXTOrder> callback, string requestParams = null)
        {
            string        result = "fail";
            StringBuilder sb     = new StringBuilder();
            PayCBLog      paylog = new PayCBLog();

            paylog.IsPay = 0;

            string out_trade_no   = string.Empty;
            string total_amount   = string.Empty;
            string receipt_amount = string.Empty;
            string trade_status   = string.Empty;

            try
            {
                sb.AppendLine("开始获取参数组:");
                //string requestParams = Request.Form.ToString().Replace("?", string.Empty);
                sb.AppendLine(requestParams);
                //获取所有get请求的参数
                var parms = AliPayBLL.Instance.GetRequestGet(requestParams);
                sb.AppendLine(JsonHelper.ToJson(parms));
                //签名校验对比
                bool isSign = AlipaySignature.RSACheckV1(parms, AliPayConfig.alipay_public_key, AliPayConfig.charset, AliPayConfig.sign_type, false);
                if (Convert.ToDateTime(parms["notify_time"]) <= DateTime.Now.AddMonths(-10))
                {
                    return(result);
                }
                if (isSign)
                {
                    sb.AppendLine("两者签名一致");
                    out_trade_no   = parms["out_trade_no"];   //获取商户订单号
                    total_amount   = parms["total_amount"];   //订单金额
                    receipt_amount = parms["receipt_amount"]; //实收金额
                    trade_status   = parms["trade_status"];   //交易状态:交易支付成功-TRADE_SUCCESS  交易结束,不可退款-TRADE_FINISHED
                    sb.AppendLine("支付宝返回交易结果:商品订单号:{0},商品订单金额:{1},商品实收金额{2},商品交易状态:{3}".FormatWith(out_trade_no, total_amount, receipt_amount, trade_status));

                    //根据商品订单号获取实体数据
                    BXTOrder order = BXTOrderBLL.Instance.Search(out_trade_no);
                    if (order.IsPay != 1)
                    {
                        if (trade_status == "TRADE_FINISHED" || trade_status == "TRADE_SUCCESS")
                        {
                            result = "success";
                            //记录支付成功
                            order.IsPay  = 1;
                            paylog.IsPay = 1;
                            if (BXTOrderBLL.Instance.Update(order).Ok)
                            {
                                //回调
                                callback(order);
                            }
                        }
                    }
                    else
                    {
                        if (order.OrderType == 2 || order.OrderType == 4 || order.OrderType == 8)
                        {
                            result = "success";
                            callback(order);
                        }
                    }
                }
                else
                {
                    sb.AppendLine("两者签名不一致!");
                }
            }
            catch (Exception e)
            {
                sb.AppendLine("处理异常:" + e.ToString());
            }
            //防止多次回调插数据
            if (out_trade_no.IsNotNullOrEmpty() && PayCBLogBLL.Instance.Search(out_trade_no) == null)
            {
                paylog.CallBackTime = DateTime.Now;
                paylog.IsDelete     = 0;
                paylog.Memo         = sb.ToString();
                paylog.TradeNo      = out_trade_no;
                paylog.TradeStatus  = trade_status;
                PayCBLogBLL.Instance.Add(paylog);
            }
            return(result);
        }
 /// <summary>
 /// 修改一条记录
 /// </summary>
 /// <param name="model">实体对象</param>
 /// <returns></returns>
 public bool Edit(BXTOrder model)
 {
     return(dal.Update(model));
 }
 /// <summary>
 /// 添加一条记录,没有任何逻辑
 /// </summary>
 /// <param name="model">实体对象</param>
 /// <returns></returns>
 public int Add(BXTOrder model, SqlTransaction tran)
 {
     return(dal.Add(model, tran));
 }