Пример #1
0
        /// <summary>
        /// Adds new trade record.
        /// </summary>
        /// <param name="tradeEntiy"></param>
        /// <returns></returns>
        public bool AddTradeRecord(SqlConnection conn, Trade tradeEntiy)
        {
            SqlParameter[] parameters =
            {
                new SqlParameter("@TradeId", SqlDbType.Int, 4),
                new SqlParameter("@UserId", tradeEntiy.UserId),
                new SqlParameter("@UserQQ", tradeEntiy.UserQQ),
                new SqlParameter("@UserCellPhone", tradeEntiy.UserCellPhone),
                new SqlParameter("@UserEmail", tradeEntiy.UserEmail),
                new SqlParameter("@UserBankInfo", tradeEntiy.UserBankInfo),
                new SqlParameter("@UserAddress", tradeEntiy.UserAddress),
                new SqlParameter("@SellerId", tradeEntiy.SellerId),
                new SqlParameter("@BuyerId", tradeEntiy.BuyerId),
                new SqlParameter("@TradeAmount", tradeEntiy.TradeAmount),
                new SqlParameter("@TradeSubject", tradeEntiy.TradeSubject),
                new SqlParameter("@TradeBody", tradeEntiy.TradeBody),
                new SqlParameter("@Payer", tradeEntiy.Payer),
                new SqlParameter("@PayCommission", tradeEntiy.PayCommission),
                new SqlParameter("@PayCommissionPercent", tradeEntiy.PayCommissionPercent),
                new SqlParameter("@CreatedTime", tradeEntiy.CreatedTime),
                new SqlParameter("@LastUpdatedTime", tradeEntiy.LastUpdatedTime),
                new SqlParameter("@State", tradeEntiy.State),
                new SqlParameter("@SellerGet", tradeEntiy.SellerGet),
                new SqlParameter("@BuyerPay", tradeEntiy.BuyerPay),
                new SqlParameter("@ViewCount", tradeEntiy.ViewCount),
                new SqlParameter("@ResourceUrl", tradeEntiy.ResourceUrl),
                new SqlParameter("@IsBuyerPaid", tradeEntiy.IsBuyerPaid),
                new SqlParameter("@TradeOrderId", tradeEntiy.TradeOrderId),
               };

            parameters[0].Direction = ParameterDirection.Output;
            DBHelper.CheckSqlSpParameter(parameters);

            return DBHelper.RunNonQueryProcedure(conn, SP_AddNewTrade, parameters) > 0;
        }
Пример #2
0
 /// <summary>
 /// Adds new trade record.
 /// </summary>
 /// <param name="tradeEntity"></param>
 /// <returns></returns>
 public bool AddNewTradeRecord(Trade tradeEntity)
 {
     bool result = false;
     var conn = DBHelper.GetSqlConnection();
     try
     {
         conn.Open();
         result = tradeDao.AddTradeRecord(conn, tradeEntity);
     }
     catch (Exception e)
     {
         LogService.Log("中介申请失败--" + e.Message, e.ToString().ToString());
     }
     finally
     {
         conn.Close();
     }
     return result;
 }
Пример #3
0
        /// <summary>
        /// Gets trade list by trade id.
        /// </summary>
        public Trade SelectTradeByTradeId(int tradeId, SqlConnection conn)
        {
            Trade result = new Trade();
            result.Seller = new User();
            result.Buyer = new User();

            SqlParameter[] sqlParameters = new SqlParameter[]
            {
                new SqlParameter("@TradeId", tradeId)
            };

            Dictionary<string, DataTable> dts;
            dts = DBHelper.GetMuiltiDataFromDB(conn, SP_SelectTradeByTradeId, sqlParameters);
            List<Trade> tempTrades = DBHelper.DataTableToList<Trade>(dts["0"]);
            List<User> tempSellers = DBHelper.DataTableToList<User>(dts["1"]);
            List<User> tempBuyers = DBHelper.DataTableToList<User>(dts["2"]);
            List<UserBankInfo> tempBanks = DBHelper.DataTableToList<UserBankInfo>(dts["3"]);

            if (tempTrades != null && tempTrades.Count == 1)
            {
                result = tempTrades[0];

                if (result != null)
                {
                    if (tempSellers != null && tempSellers.Count == 1)
                    {
                        result.Seller = tempSellers[0] ?? new User();
                    }

                    if (tempBuyers != null && tempBuyers.Count == 1)
                    {
                        result.Buyer = tempBuyers[0] ?? new User();
                    }

                    result.BankInfos = tempBanks ?? new List<UserBankInfo>();
                    result.Histories = SelectTradeHistories(tradeId, conn)?? new List<TradeHistory>();
                }
            }

            return result;
        }
Пример #4
0
        public ActionResult New(
            string qq,
            string phone,
            string email,
            string relationship,
            string username,
            string amount,
            string bankid,
            string bankname,
            string bankaccount,
            string bankusername,
            string bankaddress,
            string address,
            string agreerule,
            string tradesubject,
            string tradedetail,
            string resourceurl
        )
        {
            if (!IsUserLogin)
            {
                return Content("当前未登录");
            }
            string result = "中介申请失败";
            bool valid = true;
            Model.User toUser = null;
            UserBankInfo bankInfo = null;
            int payCommissionPercent = -1;
            int minPayCommission = -1;
            decimal outAmount = -1;
            //如果用户新增的银行信息,但是后来中介申请失败,那么需要删除掉这条记录,这里不使用transaction
            bool isNewBankInfo = false;
            #region Checks request parameter value with get operation

            try
            {
                #region Null check

                qq.CheckEmptyString("QQ");
                phone.CheckEmptyString("联系手机");
                email.CheckEmptyString("联系邮箱");
                relationship.CheckEmptyString("买卖关系");
                username.CheckEmptyString("对方用户名");
                amount.CheckEmptyString("交易金额");
                bankname.CheckEmptyString("银行名称");
                bankaccount.CheckEmptyString("银行账号");
                bankusername.CheckEmptyString("银行用户名");
                address.CheckEmptyString("收货地址");
                agreerule.CheckEmptyString("同意中介规则");
                tradesubject.CheckEmptyString("交易标题");
                tradedetail.CheckEmptyString("交易详情");
                resourceurl.CheckEmptyString("资源链接地址");

                #endregion Null check

                toUser = ValidateUserWithGet(username);
                ValidatePayerRelationship(relationship);//, payer);
                bankInfo = ValidateBankInfoWithGet(bankid, bankname, bankaccount, bankusername, bankaddress, out isNewBankInfo);
                payCommissionPercent = ValidatePayCommissionWithGet("PayCommissionPercent");
                minPayCommission = ValidatePayCommissionWithGet("MinPayCommission");
                outAmount = ValidateAmountWithGet(amount, minPayCommission);
            }
            catch (ArgumentNullException e)
            {
                result = e.ParamName + "不能为空";
                valid = false;
            }
            catch (ArgumentException e)
            {
                result = e.Message;
                valid = false;
            }

            #endregion Checks request parameter value with get operation

            if (valid)
            {
                try
                {
                    Trade tradeEntity = new Trade();

                    #region 构造中介申请对象

                    tradeEntity.UserId = UserInfo == null ? -1 : UserInfo.UserId;
                    tradeEntity.UserQQ = qq;
                    tradeEntity.UserCellPhone = phone;
                    tradeEntity.UserEmail = email;
                    tradeEntity.UserBankInfo = "银行名称:" + bankInfo.BankName + "\r\n银行账号:"
                        + bankInfo.BankAccount + "\r\n用户姓名:" + bankInfo.BankUserName + "\r\n开户行地址:" + bankInfo.BankAddress;
                    tradeEntity.UserAddress = address;

                    // 我是卖家
                    if (relationship.Equals("seller"))
                    {
                        tradeEntity.SellerId = tradeEntity.UserId;
                        tradeEntity.BuyerId = toUser.UserId;
                    }
                    //我是买家
                    else if (relationship.Equals("buyer"))
                    {
                        tradeEntity.SellerId = toUser.UserId;
                        tradeEntity.BuyerId = tradeEntity.UserId;
                    }

                    tradeEntity.TradeAmount = outAmount;
                    tradeEntity.TradeSubject = tradesubject;
                    tradeEntity.TradeBody = tradedetail;

                    tradeEntity.PayCommissionPercent = double.Parse(payCommissionPercent.ToString()) / 100;
                    tradeEntity.PayCommission = tradeEntity.TradeAmount * (Convert.ToDecimal(tradeEntity.PayCommissionPercent));
                    //Sets the min pay commission value here if it is less than the min value.
                    if (tradeEntity.PayCommission < minPayCommission)
                    {
                        tradeEntity.PayCommission = minPayCommission;
                    }

                    // 中介手续费支付方
                    #region old code
                    //if (payer.Equals("buyer", StringComparison.CurrentCultureIgnoreCase))
                    //{
                    //    tradeEntity.Payer = (int)Payer.Buyer;
                    //    tradeEntity.BuyerPay = tradeEntity.TradeAmount + tradeEntity.PayCommission;
                    //    tradeEntity.SellerGet = tradeEntity.TradeAmount;
                    //}
                    //else if (payer.Equals("seller", StringComparison.CurrentCultureIgnoreCase))
                    //{
                    //    tradeEntity.Payer = (int)Payer.Seller;
                    //    tradeEntity.BuyerPay = tradeEntity.TradeAmount;
                    //    tradeEntity.SellerGet = tradeEntity.TradeAmount - tradeEntity.PayCommission;
                    //}
                    //else if (payer.Equals("both", StringComparison.CurrentCultureIgnoreCase))
                    //{
                    //    tradeEntity.Payer = (int)Payer.Both;
                    //    tradeEntity.BuyerPay = tradeEntity.TradeAmount + tradeEntity.PayCommission / 2;
                    //    tradeEntity.SellerGet = tradeEntity.TradeAmount - tradeEntity.PayCommission / 2;
                    //}
                    #endregion

                    // 中介手续费支付方为卖方
                    tradeEntity.Payer = (int)Payer.Seller;
                    tradeEntity.BuyerPay = tradeEntity.TradeAmount;
                    tradeEntity.SellerGet = tradeEntity.TradeAmount - tradeEntity.PayCommission;

                    tradeEntity.CreatedTime = DateTime.Now;
                    tradeEntity.LastUpdatedTime = DateTime.Now;
                    tradeEntity.State = (int)TradeState.New;
                    tradeEntity.ViewCount = 0;
                    tradeEntity.ResourceUrl = resourceurl;
                    tradeEntity.IsBuyerPaid = false;
                    tradeEntity.TradeOrderId = string.Empty;

                    #endregion 构造中介申请对象

                    //添加中介申请记录到数据库
                    valid = tradeService.AddNewTradeRecord(tradeEntity);

                    if (valid)
                    {
                        result = "success";
                    }
                    else
                    {
                        if (isNewBankInfo)
                        {
                            userService.DeleteUserBankInfo(bankInfo.BankId);
                        }
                        result = "中介申请失败,请重新尝试";
                    }

                }
                catch (Exception e)
                {
                    result = "中介申请失败,请重新尝试或联系管理员";
                    LogService.Log("中介申请发生异常", e.ToString());
                }
            }
            return Content(result);
        }