private void threadProc()
    {
        while (!_isbreak)
        {
            int week      = Convert.ToInt32(DateTime.Now.DayOfWeek.ToString("d"));
            int beginHour = 8;
            int endHour   = 21;
            if (week > 0 && week < 6)
            //if (true)
            {
                if (DateTime.Now.Hour >= beginHour && DateTime.Now.Hour <= endHour)
                //if (true)
                {
                    List <DebitUserRecord> taskList = BusinessDao.GetReadyReleaseDebitRecords();
                    LoanBank bank = new LoanBank();
                    Log.WriteDebugLog("TaskThread::threadProc", "今天是星期:{0} 是放款日,放款时间段:{1}点- {2}点,待放款数据为:{3}条"
                                      , week, beginHour, endHour, taskList.Count);

                    if (taskList.Count > 0)
                    {
                        foreach (DebitUserRecord record in taskList)
                        {
                            try
                            {
                                BusinessDao.SetDebitRecordStatus(record.debitId, 5, "Pencairan dana sedang dalam proses(10002)");
                                string errMsg = String.Empty;
                                if (bank.Transfer(record, out errMsg))
                                {
                                    BusinessDao.SetDebitRecordStatus(record.debitId, 1, "Uang anda telah berhasil di transfer(10002).");
                                    //在此处可增加放款成功的短信通知
                                    WaveCellSMSSingleSender sms = new WaveCellSMSSingleSender();
                                    WaveCellSMSSingleSender.Authorization  = "Bearer yCCTxuCM7nIbdEuIxENllGMuqlF90qjtMlhb201S0bI";
                                    WaveCellSMSSingleSender.SubAccountName = "Prodigy_DANA";
                                }
                                else
                                {
                                    BusinessDao.SetDebitRecordStatus(record.debitId, -1, errMsg);
                                }
                            }
                            catch (Exception ex)
                            {
                                Log.WriteErrorLog("TaskThread::threadProc", ex.Message);
                            }
                        }
                    }
                }
                else
                {
                    Log.WriteDebugLog("TaskThread::threadProc", "今天是星期:{0} 放款时间段:{1}点- {2}点,现在是:{3}点"
                                      , week, beginHour, endHour, DateTime.Now.Hour);
                }
            }
            else
            {
                Log.WriteDebugLog("TaskThread::threadProc", "今天是星期:{0} 不放款。", week);
            }
            Thread.Sleep(3 * 60 * 1000);
        }
    }
    void monitor(object state)
    {
        while (!_isBreak)
        {
            if (DateTime.Now.Hour > 9)
            {
                List <DebitRecord> list = SMSSendDao.GetDebitRecords();

                Console.WriteLine("总共有:" + list.Count + "需要检查是否发送短信。");
                WaveCellSMSSingleSender sms = new WaveCellSMSSingleSender();
                WaveCellSMSSingleSender.Authorization  = "Bearer yCCTxuCM7nIbdEuIxENllGMuqlF90qjtMlhb201S0bI";
                WaveCellSMSSingleSender.SubAccountName = "Prodigy_DANA";
                int day2 = 0, day1 = 0, day0 = 0;

                foreach (DebitRecord debitRecord in list)
                {
                    WaveCellSMSResponseModels result = new WaveCellSMSResponseModels();

                    bool hasSend = false;
                    switch (debitRecord.overdueDay)
                    {
                    case 2:
                        if (debitRecord.smsSendTimes == 0)
                        {
                            hasSend = true;
                            result  = sms.Send("+62" + debitRecord.phone,
                                               String.Format(@"Pinjaman anda akan jatuh 2 hari lagi,Jumlah: Rp.{0}. Info cara pengembalian dan perpanjangan ada di aplikasi. Terima kasih", debitRecord.money));
                        }
                        break;

                    case 1:
                        if (debitRecord.smsSendTimes <= 1)
                        {
                            hasSend = true;
                            result  = sms.Send("+62" + debitRecord.phone,
                                               String.Format(@"1 hari lagi akan jatuh Tempo Pinjaman anda.Jumlah:Rp.{0}.Info cara pengembalian dan perpanjangan ada diaplikasi.Terima kasih", debitRecord.money));
                        }
                        break;

                    case 0:
                        if (debitRecord.smsSendTimes <= 2)
                        {
                            hasSend = true;
                            result  = sms.Send("+62" + debitRecord.phone, @"Pinjaman anda jatuh tempo hari ini,Jika anda terlambat membayar anda akan di kenakan denda keterlambatan.Silakan buka Aplikasi anda dan pilih pengembalian.Jika ada pertanyaan,hubungi:087788876279");
                        }
                        break;

                    default:
                        break;
                    }

                    if (result != null && result.status != null && result.status.code == "QUEUED")
                    {
                        if (debitRecord.overdueDay == 2)
                        {
                            day2++;
                            SMSSendDao.UpdateDebitSMSStatus(debitRecord);
                            Log.WriteSystemLog("PinjamSMSSendter::moniter", "发送成功:{0} , {1}", debitRecord.phone, debitRecord.overdueDay);
                        }

                        if (debitRecord.overdueDay == 1)
                        {
                            day1++;
                            SMSSendDao.UpdateDebitSMSStatus(debitRecord);
                            Log.WriteSystemLog("PinjamSMSSendter::moniter", "发送成功:{0} , {1}", debitRecord.phone, debitRecord.overdueDay);
                        }

                        if (debitRecord.overdueDay == 0)
                        {
                            day0++;

                            SMSSendDao.UpdateDebitSMSStatus(debitRecord);
                            Log.WriteSystemLog("PinjamSMSSendter::moniter", "发送成功:{0} , {1}", debitRecord.phone, debitRecord.overdueDay);
                        }
                    }
                    else
                    {
                        if (hasSend)
                        {
                            Log.WriteErrorLog("PinjamSMSSendter::moniter", "发送失败:{0} , {1}", debitRecord.phone, JsonConvert.SerializeObject(result));
                        }
                    }
                }
                Log.WriteSystemLog("PinjamSMSSendter::moniter", "day2 = {0}| day1 = {1} | day0 = {2}", day2, day1, day0);
            }
            else
            {
                Log.WriteSystemLog("PinjamSMSSendter::moniter", "未到发送时:09-15点");
            }
            int sleepTime = 10;

            ///10 分钟监控一次数据
            Thread.Sleep(1000 * 60 * sleepTime);
        }
    }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="debitMoney"></param>
        /// <param name="debitPeroid"></param>
        /// <param name="bankId"></param>
        /// <param name="description"></param>
        /// <returns></returns>
        public ActionResult <string> SubmitDebitRequest(int userId, float debitMoney, string description, int bankId = 0, int debitPeriod = 0, int debitPeroid = 0, string deviceId = "")
        {
            HttpResultModel ret = new HttpResultModel();

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

            try
            {
                string pkgName = HttpContext.Request.Headers["pkgName"];
                if (String.IsNullOrEmpty(pkgName) && String.IsNullOrEmpty(redis.StringGet(String.Format("attention_{0}", userId))))
                {
                    Log.WriteDebugLog("DebitController::SubmitDebitRequest", "[{0}] 用的是老版本,发短信通知他去下载最新版", userId);
                    WaveCellSMSSingleSender.Authorization  = ConfigSettings.WaveCellSMSAuthorization;
                    WaveCellSMSSingleSender.SubAccountName = ConfigSettings.WaveCellSMSAccountName;
                    WaveCellSMSSingleSender waveCellSMSSender = new WaveCellSMSSingleSender();

                    string key  = String.Format("UserAllInfoV5_{0}", userId);
                    string info = redis.StringGet(key);
                    if (!String.IsNullOrEmpty(info))
                    {
                        UserAllInfoModel          userInfo = JsonConvert.DeserializeObject <UserAllInfoModel>(info);
                        string                    phone    = "+62" + userInfo.userPersonalInfo.userName;
                        string                    msg      = "Anda masih menggunakan aplikasi versi lama, silahkan klik  https://play.google.com/store/apps/details?id=com.danapinjam.vip untuk mengunduh versi terbaru.";
                        WaveCellSMSResponseModels sendRet  = waveCellSMSSender.Send(phone, msg);
                    }
                    redis.StringSet(String.Format("attention_{0}", userId), "1");
                }

                if (userId > 146724 && String.IsNullOrEmpty(pkgName))
                {
                    ret.result    = Result.ERROR;
                    ret.errorCode = MainErrorModels.PARAMETER_ERROR;
                    ret.message   = "Anda masih menggunakan aplikasi versi lama, silahkan klik  https://play.google.com/store/apps/details?id=com.danapinjam.vip untuk mengunduh versi terbaru.";

                    Log.WriteWarning("DebitController::SubmitDebitRequest", "新用户,老版本将不允许借款。{0}", HelperProvider.GetHeader(HttpContext));
                    return(JsonConvert.SerializeObject(ret));
                }
                string lockKey = "submitdebit";
                if (redis.LockTake(lockKey, userId))
                {
                    debitPeriod = debitPeriod == 0 ? debitPeroid : debitPeriod;
                    if (String.IsNullOrEmpty(deviceId))
                    {
                        deviceId = HttpContext.Request.Headers["deviceNo"];
                    }

                    if (bankId == 0)
                    {
                        DataProviderResultModel bankInfoResult = DebitProvider.GetUserBankId(userId);
                        if (bankInfoResult.result == Result.SUCCESS)
                        {
                            int.TryParse(Convert.ToString(bankInfoResult.data), out bankId);
                        }
                        else
                        {
                            ret.result    = Result.ERROR;
                            ret.errorCode = MainErrorModels.PARAMETER_ERROR;
                            ret.message   = bankInfoResult.message;
                            redis.LockRelease(lockKey, userId);
                            return(JsonConvert.SerializeObject(ret));
                        }
                        Log.WriteWarning("DebitController::SubmitDebitRequest", "警告:用户【{0}】提交时BankId为空,可能是老版本。", userId);
                    }

                    ///逻辑
                    DataProviderResultModel result = DebitProvider.SubmitDebitReuqest(userId, debitMoney, debitPeriod, bankId, description, deviceId);
                    ret.result = result.result;
                    if (result.result == Result.SUCCESS)
                    {
                        ret.data = result.data;
                    }
                    else
                    {
                        ret.result    = Result.ERROR;
                        ret.errorCode = result.result;
                        ret.message   = result.message;
                    }
                    redis.LockRelease(lockKey, userId);
                }
                else
                {
                    ret.result    = Result.ERROR;
                    ret.errorCode = MainErrorModels.ALREADY_SUBMIT_REQUEST;
                    ret.message   = "already submit request.";

                    Log.WriteDebugLog("DebitController::SubmitDebitRequest", "[{0}] 重复请求。", userId);
                }
            }
            catch (Exception ex)
            {
                ret.result    = Result.ERROR;
                ret.errorCode = MainErrorModels.LOGIC_ERROR;
                ret.message   = Convert.ToString(MainErrorModels.LOGIC_ERROR);

                Log.WriteErrorLog("DebitController::SubmitDebitRequest", "异常:{0}", ex.Message);
            }
            finally
            {
                Log.WriteDebugLog("UserController::SubmitDebitRequest", "{0}", HelperProvider.GetHeader(HttpContext));
            }
            return(JsonConvert.SerializeObject(ret));
        }