コード例 #1
0
        private void 开始执行()
        {
            Button_确认订单发起.Enabled = false;//防止重复操作
            long OperatorId = GetTimeStamp();
            int  Sindex     = 0;

            using (SqlSugarClient dbClient = new DBClient().GetClient())
            {
                for (int i = 0; i < Gridview1.Rows.Count; i++)
                {
                    string 交易方卡号 = ((TextBox)Gridview1.Rows[i].Cells[1].FindControl("TextBox1")).Text;
                    string 交易方姓名 = ((TextBox)Gridview1.Rows[i].Cells[2].FindControl("TextBox2")).Text;
                    string 交易方银行 = ((TextBox)Gridview1.Rows[i].Cells[3].FindControl("TextBox3")).Text;
                    string 交易金额  = ((TextBox)Gridview1.Rows[i].Cells[4].FindControl("TextBox4")).Text;
                    string 备注    = ((TextBox)Gridview1.Rows[i].Cells[5].FindControl("TextBox5")).Text;

                    DateTime now = DateTime.Now;

                    if (!ClassLibrary1.ClassYZ.IsNumber(交易金额))
                    {
                        ClassLibrary1.ClassMessage.HinXi(Page, "金额 不是数字或者小数 忽略该笔继续执行");
                        continue;
                    }

                    string Cookie_UserName = ClassLibrary1.ClassAccount.检查商户端cookie2();
                    dbClient.Ado.UseTran(() => { }); // select 之前保证一次 commit,即使什么都不做
                    table_商户账号 record = null;
                    dbClient.Ado.UseTran(() =>
                    {
                        record = dbClient.Queryable <table_商户账号>().Where(it => it.商户ID == Cookie_UserName).First();
                    });
                    if (record == null)
                    {
                        return;
                    }
                    double 提款金额 = double.Parse(交易金额);

                    double 提款余额     = record.提款余额.Value;
                    double 手续费余额    = record.手续费余额.Value;
                    double 手续费比率    = record.手续费比率.Value;
                    double 单笔手续费    = record.单笔手续费.Value;
                    double 提款最低单笔金额 = double.Parse(record.提款最低单笔金额);
                    double 提款最高单笔金额 = double.Parse(record.提款最高单笔金额);
                    if (提款余额 - 提款金额 < 0)
                    {
                        ClassLibrary1.ClassMessage.HinXi(Page, "目标提款金额 账户提款余额不足支付");
                        return;
                    }
                    if (手续费余额 - 单笔手续费 < 0)
                    {
                        ClassLibrary1.ClassMessage.HinXi(Page, "手续费余额不足");
                        return;
                    }

                    if (提款最高单笔金额 - 提款金额 < 0)
                    {
                        ClassLibrary1.ClassMessage.HinXi(Page, "目标提款金额 大于账户提款金额限制 忽略该笔继续执行");
                        continue;
                    }
                    if (提款最低单笔金额 - 提款金额 > 0)
                    {
                        ClassLibrary1.ClassMessage.HinXi(Page, "目标提款金额 小于账户提款金额限制 忽略该笔继续执行");
                        continue;
                    }

                    dbClient.Ado.UseTran(() =>
                    {
                        dbClient.Ado.ExecuteCommand("UPDATE `table_商户账号` SET `提款余额` = `提款余额` - '" + 提款金额 + "', " +
                                                    "`手续费余额` = `手续费余额` - '" + 单笔手续费 + "' WHERE `商户ID` = '" + record.商户ID + "';");

                        string 类型 = "提款";

                        table_商户明细手续费 fee = new table_商户明细手续费()
                        {
                            订单号      = "MHFON" + now.ToString("yyyyMMddHHmmss") + Convert.ToString(ClassLibrary1.ClassHelpMe.GenerateRandomCode(1, 1000, 9999)),
                            商户ID     = int.Parse(record.商户ID),
                            手续费支出    = 单笔手续费,
                            交易金额     = 提款金额,
                            交易前手续费余额 = 手续费余额,
                            交易后手续费余额 = 手续费余额 - 单笔手续费,
                            类型       = 类型,
                            时间创建     = now
                        };

                        dbClient.Insertable(fee).ExecuteCommand();

                        table_商户明细余额 balance = new table_商户明细余额()
                        {
                            订单号     = "MBON" + now.ToString("yyyyMMddHHmmss") + Convert.ToString(ClassLibrary1.ClassHelpMe.GenerateRandomCode(1, 1000, 9999)),
                            商户ID    = int.Parse(record.商户ID),
                            类型      = 类型,
                            手续费     = 单笔手续费.ToString(),
                            交易金额    = 交易金额,
                            交易前账户余额 = 提款余额.ToString(),
                            交易后账户余额 = (提款余额 - 提款金额).ToString(),
                            时间创建    = now
                        };

                        dbClient.Insertable(balance).ExecuteCommand();

                        table_商户明细提款 detail = new table_商户明细提款()
                        {
                            订单号       = "MST" + now.ToString("yyyyMMddHHmmss") + Convert.ToString(ClassLibrary1.ClassHelpMe.GenerateRandomCode(1, 1000, 9999)),
                            商户ID      = record.商户ID,
                            交易方卡号     = 交易方卡号,
                            交易方姓名     = 交易方姓名,
                            交易方银行     = 交易方银行,
                            交易金额      = 提款金额,
                            手续费       = 单笔手续费,
                            创建方式      = "手动",
                            备注商户写     = 备注,
                            状态        = "待处理",
                            类型        = 类型,
                            时间创建      = now,
                            订单源IP     = ClassLibrary1.ClassAccount.来源IP(),
                            商户提交批次ID组 = OperatorId,
                            商户提交序号    = Sindex++
                        };

                        dbClient.Insertable(detail).ExecuteCommand();
                    });
                }
            }
            Response.Redirect("./商户提款记录.aspx");
        }
コード例 #2
0
        public ActionResult OrderCreate(int?timeunix, string signature, OrderCreateRequest request)
        {
            table_商户账号 account = null;

            sqlSugarClient.Ado.UseTran(() => { });
            sqlSugarClient.Ado.UseTran(() =>
            {
                account = sqlSugarClient.Queryable <table_商户账号>().Where(it => it.商户ID == request.UserName).First();
            });
            if (Convert.ToDouble(account.手续费余额) - Convert.ToDouble(account.单笔手续费) < 0)
            {
                return(GetStandardError(BaseErrors.ERROR_NUMBER.LX1010, request.UserName, request.UserPassword));
            }
            if (Convert.ToDouble(request.AimsMoney) - Convert.ToDouble(account.提款最低单笔金额) < 0)
            {
                return(GetStandardError(BaseErrors.ERROR_NUMBER.LX1011, request.UserName, request.UserPassword));
            }
            if (Convert.ToDouble(request.AimsMoney) - Convert.ToDouble(account.提款最高单笔金额) > 0)
            {
                return(GetStandardError(BaseErrors.ERROR_NUMBER.LX1012, request.UserName, request.UserPassword));
            }
            if (account.提款余额.Value - Convert.ToDouble(request.AimsMoney) < 0)
            {
                return(GetStandardError(BaseErrors.ERROR_NUMBER.LX1013, request.UserName, request.UserPassword));
            }
            JsonResult jsonResult = null;

            sqlSugarClient.Ado.UseTran(() => { });
            sqlSugarClient.Ado.UseTran(() =>
            {
                var getByWhere = sqlSugarClient.Queryable <table_商户明细提款>()
                                 .Where(it => it.商户ID == request.UserName && it.商户API订单号 == request.OrderNumberMerchant).ToList();
                if (getByWhere.Count > 0)
                {
                    jsonResult = GetStandardError(BaseErrors.ERROR_NUMBER.LX1020, request.UserName, request.UserPassword);
                }
            });
            if (jsonResult != null)
            {
                return(jsonResult);
            }
            sqlSugarClient.Ado.UseTran(() => { });
            var result = sqlSugarClient.Ado.UseTran(() =>
            {
                account       = sqlSugarClient.Queryable <table_商户账号>().Where(it => it.商户ID == request.UserName).First();
                string 状态     = "待处理";
                string 类型     = "提款";
                DateTime 时间创建 = DateTime.Now;

                double preFee     = Convert.ToDouble(account.手续费余额);
                double preBalance = account.提款余额.Value;

                account.提款余额  -= Convert.ToDouble(request.AimsMoney);
                account.手续费余额 -= Convert.ToDouble(account.单笔手续费);
                account.API回调  = request.CallBack;

                // sqlSugarClient.Updateable(account).UpdateColumns(it => new { it.提款余额, it.手续费余额, it.API回调 }).ExecuteCommand();
                sqlSugarClient.Updateable <table_商户账号>().Where(it => it.商户ID == account.商户ID)
                .SetColumns(it => it.提款余额 == it.提款余额 - Convert.ToDouble(request.AimsMoney))
                .SetColumns(it => it.手续费余额 == it.手续费余额 - Convert.ToDouble(account.单笔手续费))
                .SetColumns(it => it.API回调 == request.CallBack)
                .ExecuteCommand();

                table_商户明细手续费 fee = new table_商户明细手续费();
                fee.订单号           = "MHFON" + DateTime.Now.ToString("yyyyMMddHHmmss") + Convert.ToString(ClassLibrary1.ClassHelpMe.GenerateRandomCode(1, 1000, 9999));
                fee.商户ID          = Convert.ToInt32(account.商户ID);
                fee.手续费支出         = account.单笔手续费;
                fee.交易金额          = Convert.ToDouble(request.AimsMoney);
                fee.交易前手续费余额      = preFee;
                fee.交易后手续费余额      = account.手续费余额;
                fee.类型            = 类型;
                fee.状态            = 状态;
                fee.时间创建          = 时间创建;
                sqlSugarClient.Insertable(fee).ExecuteCommand();

                table_商户明细余额 balance = new table_商户明细余额();
                balance.订单号          = "MBON" + DateTime.Now.ToString("yyyyMMddHHmmss") + Convert.ToString(ClassLibrary1.ClassHelpMe.GenerateRandomCode(1, 1000, 9999));
                balance.商户ID         = Convert.ToInt32(account.商户ID);
                balance.类型           = 类型;
                balance.手续费          = Convert.ToString(account.单笔手续费);
                balance.交易金额         = request.AimsMoney;
                balance.交易前账户余额      = Convert.ToString(preBalance);
                balance.交易后账户余额      = Convert.ToString(account.提款余额);
                balance.状态           = 状态;
                balance.时间创建         = 时间创建;
                sqlSugarClient.Insertable(balance).ExecuteCommand();

                table_商户明细提款 detail = new table_商户明细提款();
                detail.订单号          = "MST" + DateTime.Now.ToString("yyyyMMddHHmmss") + Convert.ToString(ClassLibrary1.ClassHelpMe.GenerateRandomCode(1, 1000, 9999));
                detail.商户ID         = account.商户ID;
                detail.交易方卡号        = request.AimsCardNumber;
                detail.交易方姓名        = request.AimsCardName;
                detail.交易方银行        = request.AimsCardBank;
                detail.商户API订单号     = request.OrderNumberMerchant;
                detail.交易金额         = Convert.ToDouble(request.AimsMoney);
                detail.手续费          = account.单笔手续费;
                detail.创建方式         = "接口";
                detail.备注商户写        = "";
                detail.状态           = 状态;
                detail.类型           = 类型;
                detail.时间创建         = 时间创建;
                detail.API回调次数      = 0;
                detail.订单源IP        = ClassLibrary1.ClassAccount.来源IP();
                sqlSugarClient.Insertable(detail).ExecuteCommand();

                OrderCreateResponse orderCreateResponse = AutoCopy <BaseResponse, OrderCreateResponse>(baseSuccess);
                orderCreateResponse.Username            = request.UserName;
                orderCreateResponse.Userpassword        = request.UserPassword;
                orderCreateResponse.OrderNumberMerchant = request.OrderNumberMerchant;
                orderCreateResponse.OrderNumberSite     = detail.订单号;
                orderCreateResponse.AimsCardBank        = request.AimsCardBank;
                orderCreateResponse.AimsCardName        = request.AimsCardName;
                orderCreateResponse.AimsCardNumber      = request.AimsCardNumber;
                orderCreateResponse.AimsMoney           = request.AimsMoney;

                jsonResult      = new JsonResult();
                jsonResult.Data = orderCreateResponse;
            });

            sqlSugarClient.Ado.UseTran(() => { });
            if (!result.IsSuccess)
            {
                jsonResult = GetStandardError(BaseErrors.ERROR_NUMBER.LX1016, request.UserName, request.UserPassword);
                BaseResponse baseResponse = (BaseResponse)jsonResult.Data;
                baseResponse.StatusReply = string.Format(baseResponse.StatusReply, result.ErrorMessage);
            }
            return(jsonResult);
        }