/// <summary>
        /// 获取贷款种类
        /// </summary>
        /// <returns></returns>
        public ActionResult <string> GetInitDebitStyle()
        {
            HttpResultModel ret = new HttpResultModel();

            ret.result = Result.SUCCESS;
            Redis redis = HelperProvider.GetRedis();

            try
            {
                string userId    = HttpContext.Request.Headers["userId"];
                var    iUserId   = 0;
                var    userLevel = 0;
                int.TryParse(userId, out iUserId);
                if (iUserId > 0)
                {
                    string key  = String.Format("UserAllInfoV5_{0}", userId);
                    string info = redis.StringGet(key);
                    if (!String.IsNullOrEmpty(info))
                    {
                        UserAllInfoModel userInfo = JsonConvert.DeserializeObject <UserAllInfoModel>(info);
                        userLevel = userInfo.userLevel;

                        Log.WriteDebugLog("v2::MainController::GetInitDebitStyle", "用户的等级是:{0}", userLevel);
                    }
                    else
                    {
                        DataProviderResultModel dataProviderResult = UserProvider.GetUserAllInfo(userId);
                        if (dataProviderResult.result == Result.SUCCESS)
                        {
                            UserAllInfoModel userInfo = dataProviderResult.data as UserAllInfoModel;
                            userLevel = userInfo.userLevel;
                            redis.StringSet(key, JsonConvert.SerializeObject(userInfo));
                        }
                        else
                        {
                            Log.WriteDebugLog("v2::MainController::GetInitDebitStyle", "获取缓存与数据库为空:{0}", userId);
                        }
                    }
                }
                else
                {
                    Log.WriteDebugLog("v2::MainController::GetInitDebitStyle", "用户ID没有传入");
                    userLevel = 0;
                }

                var debitStyle = new List <float> {
                    1500000.00f, 2100000.00f, 2700000.00f
                };
                var debitDesc = new SortedList <float, string>();
                debitDesc.Add(1500000.00f, "ISI LENGKAP DATA PRIBADI ANDA DENGAN BENAR MAKA SYSTEM CREDIT KITA AKAN MELAKUKAN PENGECEKAN DAN PINJAMAN AKAN DIBERIKAN SECARA AUTOMATIS BILA LOLOS VERIFIKASI. TERIMA KASIH");
                debitDesc.Add(2100000.00f, "PEMINJAMAN DENGAN NOMINAL INI HANYA BISA DIPINJAMKAN KALAU SUDAH PERNAH MELAKUKAN PEMBAYARAN TEPAT WAKTU ATAU PERPANJANGAN PRODUCT A DENGAN NOMINAL RP 1.500.000 SEBANYAK 2 KALI PEMINJAMAN");
                debitDesc.Add(2700000.00f, "PEMINJAMAN DENGAN NOMINAL INI HANYA BISA DIPINJAMKAN KALAU SUDAH PERNAH MELAKUKAN PEMBAYARAN TEPAT WAKTU ATAU PERPANJANGAN PRODUCT B DENGAN NOMINAL RP 2.100.000 SEBANYAK 2 KALI PEMINJAMAN");

                var debitPeriod = new List <int> {
                    7
                };
                //List<object> retList = new List<object>();
                List <DebitInfo> list = new List <DebitInfo>();
                foreach (var style in debitStyle)
                {
                    foreach (var period in debitPeriod)
                    {
                        DebitInfo info = new DebitInfo();
                        info.debitMoney  = style;
                        info.debitPeriod = period;

                        info.description = "Ketika Anda melakukan pinjam\r\nBiaya admin harus dibayar diawal";
                        DataProviderResultModel result = DebitProvider.GetInterestRateByDebitStyle(style, period);
                        if (result.result == Result.SUCCESS)
                        {
                            float rate        = 0f;
                            float overdueRate = 0f;

                            if (null != result.data)
                            {
                                List <float> rates = result.data as List <float>;

                                rate        = rates[0];
                                overdueRate = rates[1];
                                //贷多少,还多少
                                info.payBackMoney = style;
                                //手续费,一次性
                                if (rate >= 1)
                                {
                                    info.debitFee = rate;
                                    //日息
                                    info.dailyInterest = rate / period;
                                }
                                else
                                {
                                    info.debitFee = style * rate;
                                    //日息
                                    info.dailyInterest = style * rate / period;
                                }
                                info.adminFee = String.Format("Biaya Admin Rp {0}", info.debitFee);
                                //实际到帐,减去手续费
                                info.actualMoney = style - info.debitFee;

                                //逾期日息
                                info.overdueDayInterest = info.actualMoney * overdueRate;

                                //描述
                                info.description  = debitDesc[style];
                                info.displayStyle = 1;
                                if (userLevel == 0)
                                {
                                    if (style > 1500000)
                                    {
                                        info.displayStyle = 0;
                                    }
                                }
                                if (userLevel == 1)
                                {
                                    if (style > 2100000)
                                    {
                                        info.displayStyle = 0;
                                    }
                                }
                                list.Add(info);
                            }
                        }
                    }
                }
                ret.data = list;
            }
            catch (Exception ex)
            {
                ret.result    = Result.ERROR;
                ret.errorCode = MainErrorModels.LOGIC_ERROR;
                ret.message   = Convert.ToString(MainErrorModels.LOGIC_ERROR);

                Log.WriteErrorLog("v2::MainController::GetInitDebitStyle", "异常:{0}", ex.Message);
            }
            return(JsonConvert.SerializeObject(ret));
        }
Exemple #2
0
        /// <summary>
        /// 计算利率 2
        /// </summary>
        /// <param name="debitMoney"></param>
        /// <param name="debitPeroid"></param>
        /// <returns></returns>
        public ActionResult <string> CalcInterestRate(float debitMoney, int debitPeriod)
        {
            HttpResultModel ret = new HttpResultModel();

            ret.result = Result.SUCCESS;
            try
            {
                ///逻辑
                DebitInfo info = new DebitInfo();
                info.debitMoney  = debitMoney;
                info.debitPeriod = debitPeriod;
                info.description = String.Format("no interest rate fees\r\nonly pay back {0} after {1} days", debitMoney.ToString("#,##0.00 "), debitPeriod);
                DataProviderResultModel result = DebitProvider.GetInterestRateByDebitStyle(debitMoney, debitPeriod);
                if (result.result == Result.SUCCESS)
                {
                    float rate        = 0f;
                    float overdueRate = 0f;

                    if (null != result.data)
                    {
                        List <float> rates = result.data as List <float>;

                        rate        = rates[0];
                        overdueRate = rates[1];
                        //贷多少,还多少
                        info.payBackMoney = debitMoney;

                        //手续费,一次性
                        if (rate >= 1)
                        {
                            info.debitFee = rate;
                            //日息
                            info.dailyInterest = rate / debitPeriod;
                        }
                        else
                        {
                            info.debitFee = debitMoney * rate;
                            //日息
                            info.dailyInterest = debitMoney * rate / debitPeriod;
                        }
                        //实际到帐,减去手续费
                        info.actualMoney = debitMoney - info.debitFee;
                        //日息
                        info.dailyInterest = debitMoney * rate / debitPeriod;
                        //逾期日息
                        info.overdueDayInterest = debitMoney * overdueRate;
                        ret.data = info;
                    }
                    else
                    {
                        ret.result  = MainErrorModels.LOGIC_ERROR;
                        ret.message = "logic error,The rate calc result is 0.";
                    }
                }
                else
                {
                    ret.result    = Result.ERROR;
                    ret.errorCode = result.result;
                    ret.message   = result.message;
                }
            }
            catch (Exception ex)
            {
                ret.result    = Result.ERROR;
                ret.errorCode = MainErrorModels.LOGIC_ERROR;
                ret.message   = Convert.ToString(MainErrorModels.LOGIC_ERROR);

                Log.WriteErrorLog("DebitController::CalcInterestRate", "异常:{0}", ex.Message);
            }

            return(JsonConvert.SerializeObject(ret));
        }
        /// <summary>
        /// 获取贷款种类
        /// </summary>
        /// <returns></returns>
        public ActionResult <string> GetInitDebitStyleV2()
        {
            HttpResultModel ret = new HttpResultModel();

            ret.result = Result.SUCCESS;
            try
            {
                var debitStyle = new List <float> {
                    1500000.00f
                };
                var debitPeriod = new List <int> {
                    7
                };
                List <object> retList = new List <object>();
                foreach (var style in debitStyle)
                {
                    List <DebitInfo> list = new List <DebitInfo>();
                    foreach (var period in debitPeriod)
                    {
                        DebitInfo info = new DebitInfo();
                        info.debitMoney  = style;
                        info.debitPeriod = period;

                        info.description = "Ketika Anda melakukan pinjam\r\nBiaya admin harus dibayar diawal";
                        DataProviderResultModel result = DebitProvider.GetInterestRateByDebitStyle(style, period);
                        if (result.result == Result.SUCCESS)
                        {
                            float rate        = 0f;
                            float overdueRate = 0f;

                            if (null != result.data)
                            {
                                List <float> rates = result.data as List <float>;

                                rate        = rates[0];
                                overdueRate = rates[1];
                                //贷多少,还多少
                                info.payBackMoney = style;
                                //手续费,一次性
                                if (rate >= 1)
                                {
                                    info.debitFee = rate;
                                    //日息
                                    info.dailyInterest = rate / period;
                                }
                                else
                                {
                                    info.debitFee = style * rate;
                                    //日息
                                    info.dailyInterest = style * rate / period;
                                }
                                info.adminFee = String.Format("Biaya Admin Rp {0}", info.debitFee);
                                //实际到帐,减去手续费
                                info.actualMoney = style - info.debitFee;

                                //逾期日息
                                info.overdueDayInterest = style * overdueRate;
                                list.Add(info);
                            }
                        }
                    }
                    retList.Add(new { debitMoney = style, debitCombination = list });
                }

                ret.data = retList;
            }
            catch (Exception ex)
            {
                ret.result    = Result.ERROR;
                ret.errorCode = MainErrorModels.LOGIC_ERROR;
                ret.message   = Convert.ToString(MainErrorModels.LOGIC_ERROR);

                Log.WriteErrorLog("MainController::GetInitDebitStyle", "异常:{0}", ex.Message);
            }
            return(JsonConvert.SerializeObject(ret));
        }