Пример #1
0
        public string PayFeeTool(int UserId = 0, decimal Amount = 0M, int PayType = 0)
        {
            if (UserId <= 0)
            {
                return(ApiReturnStr.getError(-100, "用户ID不能为0"));
            }
            if (Amount < 500M)
            {
                return(ApiReturnStr.getError(-100, "支付金额不能小于500"));
            }
            ToolPay model = null;
            Users   user  = userDao.Single(UserId);

            Logic.VipType vip = (Logic.VipType)user.VipType;

            decimal[] r = Constant.GetRate(PayType, vip);
            model = new ToolPay(Amount, r[0], 0, r[1], 0, 0);

            JObject data = new JObject();

            data["Amount"]       = model.Amount.ToString("F2");
            data["Rate1"]        = model.Rate1.perCent();
            data["Rate2"]        = model.Rate2.ToString("F2");
            data["Rate3"]        = model.Rate3.ToString("F2");
            data["Rate4"]        = model.Rate4.ToString("F2");
            data["Rate5"]        = model.Rate5.ToString("F2");
            data["PayFee"]       = model.PayFee.ToString("F2");
            data["BasicFee"]     = model.BasicFee.ToString("F2");
            data["ExTargetFee"]  = model.ExTargetFee.ToString("F2");
            data["ActualAmount"] = model.ActualAmount.ToString("F2");
            return(ApiReturnStr.getApiData(data));
        }
Пример #2
0
        public ActionResult tool()
        {
            decimal Amount     = TQuery.GetDecimal("Amount", 10000);
            decimal Rate1      = TQuery.GetDecimal("Rate1", 0.0038M);
            decimal Rate3      = TQuery.GetDecimal("Rate3", 2M);
            decimal BasicRate1 = TQuery.GetDecimal("BasicRate1", 0.0038M);
            decimal BasicRate3 = TQuery.GetDecimal("BasicRate3", 2M);
            ToolPay model      = new ToolPay(Amount == 0M ? 10000 : Amount, Rate1 == 0M ? 0.0043M : Rate1, Rate3 == 0 ? 2 : Rate3, BasicRate1 == 0M ? 0.0038M : BasicRate1, BasicRate3 == 0M ? 2M : BasicRate3);

            return(View(model));
        }
Пример #3
0
        public string hhhh()
        {
            var list = payRecordDao.GetQuery(" ChannelType=4 ");

            foreach (var item in list)
            {
                //ToolPay tp = new ToolPay(Amount, r[0], 0, r[1], 0, 0);
                ToolPay tp = new ToolPay(item.Amount, item.Rate, item.Fee3, 0.0040M, 1);
                item.Income     = tp.Income;
                item.DrawIncome = tp.Rate3 - 1;//结算收益
                payRecordDao.Update(item);
            }
            return(DateTime.Now.ToString());
        }
Пример #4
0
        public ActionResult Pay(int UserId, decimal Amount = 0)
        {
            if (UserId == 0 || Amount < 500M)
            {
                return(new RedirectResult($"/Prompt?state=-100&msg=参数错误&url=/debug/"));
            }

            var user = userDao.Single(UserId);


            Logic.VipType vip   = (Logic.VipType)user.VipType;
            decimal[]     r     = Constant.GetRate(0, vip);
            ToolPay       tp    = new ToolPay(Amount, r[0], r[1], 0.0038M, 1M);
            PayRecord     model = new PayRecord();

            model.UserId         = UserId;
            model.Amount         = Amount;
            model.Platform       = 1;
            model.Ip             = "1.1.1.1";
            model.BankCard       = "622202XXXXXXXXXXXXXX";
            model.Fee            = tp.PayFee;
            model.Rate           = tp.Rate1;
            model.Fee3           = tp.Rate3;
            model.State          = 10;
            model.DrawState      = 10;
            model.WithDrawAmount = model.Amount - model.Fee;//结算金额
            model.ActualAmount   = tp.ActualAmount;
            model.DrawBankCard   = "622222XXXXXX";
            model.BankCode       = "ICBC";
            model.PayerName      = user.RealName;
            model.PayerPhone     = user.Mobile;
            model.ChannelType    = 4;
            model.Income         = tp.Income;
            model.DrawIncome     = tp.Rate3 - 1;//结算收益

            var result = payRecordDao.Insert(model);

            int    backState = result > 0 ? 0 : -100;
            string message   = result > 0 ? "操作成功" : "操作失败";

            //交易成功回调
            UsersDepository.NoticeSuccess(result, UserId);

            return(new RedirectResult($"/Prompt?state={backState}&msg={message}&url=/debug/"));
        }
Пример #5
0
        public int Init(int UserId, decimal Amount, int Platform, string IP, string BankCard)
        {
            var       yeepayUser = yeepayUserDao.Single("UserId=@UserId", new { UserId });
            ToolPay   tp         = new ToolPay(Amount, yeepayUser.Rate1, yeepayUser.Rate2, yeepayUser.Rate3, yeepayUser.Rate4, yeepayUser.Rate5);
            PayRecord model      = new PayRecord();

            model.UserId         = UserId;
            model.Amount         = Amount;
            model.Platform       = Platform;
            model.Ip             = IP;
            model.BankCard       = BankCard;
            model.Fee            = tp.PayFee;
            model.Rate           = tp.Rate1;
            model.Fee3           = tp.Rate3;
            model.DrawState      = 0;                        //未发起
            model.WithDrawAmount = model.Amount - model.Fee; //结算金额
            model.ActualAmount   = tp.ActualAmount;
            return(Insert(model));
        }
Пример #6
0
        public int Init(int UbkID, decimal Amount, int Platform, string IP, int ChannelType)
        {
            var ubk   = userBankCardDao.Single(UbkID);
            var users = usersDao.Single(ubk.UserId);
            //提现卡
            var ubkDraw = userBankCardDao.Single(" TypeId=0 and UserId=@UserId", new { ubk.UserId });

            int TypeId = (int)Logic.KeyValueType.支付通道管理;

            //获得通道列表
            var listChannelPay = MemcachHelper.Get <List <KeyValue> >(Constant.list_keyvalue_key + TypeId, DateTime.Now.AddDays(7), () =>
            {
                return(keyValueDao.GetQuery(" typeid=@TypeId ", new { TypeId }, "order by Sort desc,CTime desc"));
            });


            //var kv = keyValueDao.Single("KeyId=@ChannelType and TypeId=@TypeId", new { ChannelType , TypeId });

            var kv      = listChannelPay.Find(m => m.KeyId == ChannelType && m.TypeId == TypeId);
            int payType = 0;

            payType = (kv != null && kv.Value2 == "1") ? 1 : 0;//确定通道  积分类型

            JObject data       = JObject.Parse(kv.Value);
            decimal BasicRate1 = data["Rate1"].ToDecimal();
            decimal BasicRate3 = data["Rate3"].ToDecimal();

            Logic.VipType vip = (Logic.VipType)users.VipType;
            decimal[]     r   = Constant.GetRate(payType, vip);
            //ToolPay tp = new ToolPay(Amount, r[0], 0, r[1], 0, 0);
            ToolPay tp = new ToolPay(Amount, r[0], r[1], BasicRate1, BasicRate3);


            //ToolPay tp = null;
            //switch ((Logic.ChannelType)ChannelType)
            //{
            //    case Logic.ChannelType.易宝:
            //        var yeepayUser = yeepayUserDao.Single("UserId=@UserId", new { ubk.UserId });
            //        tp=new ToolPay(Amount, yeepayUser.Rate1, yeepayUser.Rate2, yeepayUser.Rate3, yeepayUser.Rate4, yeepayUser.Rate5);
            //        break;
            //    case Logic.ChannelType.荣邦科技积分:
            //        var mUser = masgetUserDao.Single(" UserId=@UserId and TypeId=@ChannelType ", new { ubk.UserId, ChannelType });
            //        tp = new ToolPay(Amount, mUser.Rate1, 0, mUser.Rate3, 0, 0);
            //        break;
            //    case Logic.ChannelType.荣邦科技无积分:
            //        var mUser2 = masgetUserDao.Single(" UserId=@UserId and TypeId=@ChannelType ", new { ubk.UserId, ChannelType });
            //        tp = new ToolPay(Amount, mUser2.Rate1, 0, mUser2.Rate3, 0, 0);
            //        break;
            //    default:
            //        break;
            //}


            PayRecord model = new PayRecord();

            model.UserId         = ubk.UserId;
            model.Amount         = Amount;
            model.Platform       = Platform;
            model.Ip             = IP;
            model.BankCard       = ubk.BankCard;
            model.Fee            = tp.PayFee;
            model.Rate           = tp.Rate1;
            model.Fee3           = tp.Rate3;
            model.DrawState      = 0;                        //未发起
            model.WithDrawAmount = model.Amount - model.Fee; //结算金额
            model.ActualAmount   = tp.ActualAmount;
            model.DrawBankCard   = ubkDraw.BankCard;
            model.BankCode       = ubk.BankCode;
            model.PayerName      = users.RealName;
            model.PayerPhone     = ubk.Mobile;
            model.ChannelType    = ChannelType;
            model.Income         = tp.Income;
            model.DrawIncome     = tp.Rate3 - BasicRate3;//结算收益
            return(Insert(model));
        }
Пример #7
0
        /// <summary>
        /// 选择最优通道
        /// 1.利润优先
        /// 2.满足额度
        /// 3.满足运营时间
        /// </summary>
        /// <param name="BankId"></param>
        /// <param name="PayType"></param>
        public static ResultModelData <int> Optimal(int UserId, decimal Amount = 0, string BankCode = "", int PayType = 0, string mobile = "", int BankID = 0)
        {
            ResultModelData <int> result = new ResultModelData <int>();
            //var bin= ITOrm.Utility.Helper.BankCardBindHelper.BankBinto(BankCard);
            //if (bin == null || string.IsNullOrEmpty(bin.BankCode))
            //{
            //    result.backState = -100;
            //    result.message = "银行卡卡Bin识别失败";
            //    return result;
            //}
            //获得通道支持的银行
            List <ViewBankQuota> listBankQuota = MemcachHelper.Get <List <ViewBankQuota> >(Constant.list_bank_quota_key, DateTime.Now.AddDays(7), () =>
            {
                return(viewBankQuotaDao.GetQuery(" state=0 ", null, " order by id asc "));
            });
            //筛选支持的BankCode的通道  并且 限额满足 并按限额排序
            var listBank = listBankQuota.FindAll(m => m.BankCode == BankCode.Trim() && Amount <= m.SingleQuota).OrderByDescending(m => m.SingleQuota).ToList();



            int TypeId = (int)Logic.KeyValueType.支付通道管理;
            //获得通道列表
            var listChannelPay = MemcachHelper.Get <List <KeyValue> >(Constant.list_keyvalue_key + TypeId, DateTime.Now.AddDays(7), () =>
            {
                return(keyValueDao.GetQuery(" typeid=@TypeId  ", new { TypeId }, "order by Sort desc,CTime desc"));
            });
            bool isallnotChannel = true;//标记有积分通道,是否全部关闭 true 是全部关闭

            foreach (var item in listChannelPay)
            {
                if (item.State == 0 && item.KeyId != 2)
                {
                    isallnotChannel = false;
                }
            }
            //只获得可用通道
            listChannelPay = listChannelPay.FindAll(m => m.State == 0);
            if (mobile.Substring(0, 3) == "177")//17号段的用户排除荣邦通道
            {
                listChannelPay = listChannelPay.FindAll(m => m.KeyId != 1 && m.KeyId != 4);
            }
            //获得卡ID排除通道的配置 begin
            var listDebarBankChannel = MemcachHelper.Get <List <DebarBankChannel> >(Constant.debarbankchannel_key, DateTime.Now.AddDays(7), () =>
            {
                return(debarBankChannelDao.GetQuery(" 1=1  ", null, "order by CTime desc"));
            });
            var itemDebarBankChannel = listDebarBankChannel.FindAll(m => m.BankID == BankID);

            if (itemDebarBankChannel != null && itemDebarBankChannel.Count > 0)
            {
                foreach (var item in itemDebarBankChannel)
                {
                    listChannelPay = listChannelPay.FindAll(m => m.KeyId != item.ChannelID);
                }
            }
            //获得卡ID排除通道的配置 end

            Users user = usersDao.Single(UserId);
            var   rate = Constant.GetRate(PayType, (Logic.VipType)user.VipType);


            Dictionary <string, decimal> dic = new Dictionary <string, decimal>();

            //遍历通道  取得可用通道
            foreach (var item in listChannelPay)
            {
                JObject  data       = JObject.Parse(item.Value);
                DateTime StartTime  = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " " + data["StartTime"]);
                DateTime EndTime    = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " " + data["EndTime"]);
                decimal  BasicRate1 = data["Rate1"].ToDecimal();
                decimal  BasicRate3 = data["Rate3"].ToDecimal();
                //判断通道是否是积分类型 并且满足时间范围 并且该通道支持改银行
                if (item.Value2 == PayType.ToString() && DateTime.Now > StartTime && DateTime.Now < EndTime && listBank.FindIndex(m => m.ChannelType == item.KeyId) > -1)
                {
                    ToolPay tp = new ToolPay(Amount, rate[0], rate[1], BasicRate1, BasicRate3);
                    dic.Add(item.KeyId.ToString(), tp.Income);
                }
            }
            if (dic.Count > 0)//计算最优利润
            {
                decimal maxIncom           = 0M;
                int     optimalChannelType = 0;
                foreach (var item in dic)
                {
                    if (maxIncom < item.Value || maxIncom == 0M)
                    {
                        maxIncom           = item.Value;
                        optimalChannelType = Convert.ToInt32(item.Key);
                    }
                }
                result.backState = 0;
                result.message   = $"匹配到最佳通道,收益:{maxIncom}";
                result.Data      = optimalChannelType;
                return(result);
            }

            if (isallnotChannel)
            {
                result.backState = -100;
                result.message   = "通道额度已用尽,请明日再试";
                return(result);
            }

            //未匹配成功,默认选第一条通道
            foreach (var item in listChannelPay)
            {
                if (item.Value2 == PayType.ToString())
                {
                    result.backState = -100;
                    result.message   = "未匹配到通道,请修改金额不超限额或选择支持的银行试试";
                    result.Data      = item.KeyId;


                    JObject  data      = JObject.Parse(item.Value);
                    DateTime StartTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " " + data["StartTime"]);
                    DateTime EndTime   = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " " + data["EndTime"]);
                    if (DateTime.Now < StartTime)
                    {
                        result.message = "未到通道开启时间";
                    }
                    if (DateTime.Now > EndTime)
                    {
                        result.message = "通道已关闭,请明天再试";
                    }
                    break;
                }
            }
            return(result);
        }