Пример #1
0
        /// <summary>
        /// Replies trade with operation, adds a new record to table TradeHistory.
        /// </summary>
        /// <param name="history"></param>
        /// <param name="conn"></param>
        /// <returns></returns>
        public bool ReplyTradeWithOperation(TradeHistory history, SqlConnection conn)
        {
            SqlParameter[] sqlParameters = new SqlParameter[]
            {
                new SqlParameter("@HistorySubject", history.HistorySubject),
                new SqlParameter("@HistoryBody", history.HistoryBody),
                new SqlParameter("@TradeId", history.TradeId),
                new SqlParameter("@UserId", history.UserId),
                new SqlParameter("@UserName", history.UserName),
                new SqlParameter("@IsAdminUpdate", history.IsAdminUpdate),
                new SqlParameter("@TradeState", history.TradeState),
                new SqlParameter("@CreatedTime", history.CreatedTime)
            };

            return DBHelper.RunNonQueryProcedure(conn, "sp_ReplyTradeWithOperation", sqlParameters) > 0;
        }
Пример #2
0
        /// <summary>
        /// Updates order state
        /// </summary>
        /// <param name="orderId"></param>
        /// <param name="newState"></param>
        /// <returns></returns>
        public bool UpdateOrderState(string orderId, int newState)
        {
            bool result = false;

            var conn = DBHelper.GetSqlConnection();
            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    conn.Open();
                    TradeOrder order = orderDao.GetOrderByOrderId(conn, orderId);

                    if (order != null)
                    {
                        #region 处理中介交易在线支付结果

                        if (order.OrderType.Value == (int)OrderType.Trade && newState == (int)OrderState.Succeed)
                        {
                            Trade trade = tradeDao.SelectTradeByTradeId(order.ResourceId.Value, conn);

                            if (tradeDao.UpdateTradeOrderIdAndBuyerPaid(trade.TradeId, orderId, true, conn))
                            {
                                string subject = "买家" + order.UserName + "在线支付中介交易款项成功";
                                string body = "买家已在线支付中介交易款项成功,卖家可以发货";

                                TradeHistory history = new TradeHistory
                                {
                                    HistorySubject = subject,
                                    HistoryBody = body,
                                    TradeId = trade.TradeId,
                                    UserId = trade.BuyerId,
                                    UserName = order.UserName,
                                    IsAdminUpdate = false,
                                    TradeState = trade.State,
                                    CreatedTime = DateTime.Now
                                };

                                result = tradeDao.ReplyTradeWithOperation(history, conn);
                            }
                        }
                        #endregion

                        #region 处理升级为VIP会员在线支付结果
                        else if (order.OrderType.Value == (int)OrderType.ToVip && newState == (int)OrderState.Succeed)
                        {
                            UserVip vipInfo = userDao.SelectUserVipInfoByUserId(conn, order.ResourceId.Value);

                            vipInfo.State = (int)VipState.VIP;
                            vipInfo.StartTime = DateTime.Now;
                            vipInfo.EndTime = DateTime.Now.AddYears(vipInfo.Duration.Value);
                            vipInfo.LastUpdatedTime = DateTime.Now;

                            result = userDao.UpdateUserVipState(conn, order.ResourceId.Value, (int)VipState.VIP);
                            if (result)
                            {
                                result = userDao.UpdateUserVipInfo(conn, vipInfo);
                            }
                        }
                        //else if (order.OrderType.Value == (int)OrderType.WeChatDemand && newState == (int)OrderState.Succeed)
                        //{

                        //}
                        else
                        {
                            result = true;
                        }
                        #endregion

                        // 更新订单信息
                        if (result)
                        {
                            result = orderDao.UpdateOrderState(conn, orderId, newState, DateTime.Now);
                        }
                    }

                    scope.Complete();
                }
            }
            catch (Exception e)
            {
                LogService.Log("更新订单状态失败--" + e.Message, e.ToString());
            }
            finally
            {
                conn.Close();
            }

            return result;
        }
Пример #3
0
        /// <summary>
        /// Replies trade with operation, adds a new record to table TradeHistory.
        /// </summary>
        /// <param name="history"></param>
        /// <returns></returns>
        public bool ReplyTradeWithOperation(string historySubject, string historyBody, int tradeId,
            int userId, string username, bool isAdminUpdate, int tradeState, DateTime createdTime)
        {
            var conn = DBHelper.GetSqlConnection();
            bool result = false;

            try
            {
                TradeHistory history = new TradeHistory
                {
                    HistorySubject = historySubject,
                    HistoryBody = historyBody,
                    TradeId = tradeId,
                    UserId = userId,
                    UserName = username,
                    IsAdminUpdate = isAdminUpdate,
                    TradeState = tradeState,
                    CreatedTime = createdTime
                };

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    conn.Open();
                    result = tradeDao.ReplyTradeWithOperation(history, conn) &&
                        tradeDao.UpdateTradeState(tradeId, tradeState, conn);

                    scope.Complete();
                }
            }
            catch (Exception e)
            {
                LogService.Log("回复中介失败", e.ToString());
                result = false;
            }
            finally
            {
                conn.Close();
            }

            return result;
        }