public ResultDTO Refund(Refund refund) { ResultDTO result = new ResultDTO(); result.success = true; var user = db.Users.FirstOrDefault(u => u.Id == this.UserId); if (user != null) { var balance = db.Balances.FirstOrDefault(b => b.Id == (user.ActiveBalanceId ?? 0)); if (balance.TypeId != 2) { result.success = false; result.message = "不是实盘账户,无法出金"; return(result); } if (balance != null && balance.Amount >= refund.Amount) { balance.Amount -= refund.Amount; } else { result.success = false; result.message = "账户余额不足,无法出金"; return(result); } } db.Refunds.Add(new YJY_COMMON.Model.Entity.Refund() { Amount = refund.Amount, CreatedAt = DateTimes.UtcToChinaTime(DateTime.UtcNow), UserId = this.UserId, }); string adminPhone = db.Miscs.FirstOrDefault(m => m.Key == "refundAdmin").Value; string sendResult = YunPianSMS.SendSms("【盈交易】有一笔新的申请,请在后台查看", adminPhone); db.SaveChanges(); result.success = true; return(result); }
private ResultDTO CheckAndSendSMSVerifyCode(string phone) { var result = new ResultDTO(); if (string.IsNullOrWhiteSpace(phone)) { result.success = false; //result.message="" } //if (!Phone.IsValidPhoneNumber(phone)) //{ // result.message = __(TransKey.INVALID_PHONE_NUMBER); // result.success = false; // return result; //} string code = string.Empty; ////send last code instead of regenerating if within ? //if (verifyCodes.Any()) //{ // var lastCode = verifyCodes.OrderByDescending(c => c.CreatedAt).First(); //} ////day limit //if (verifyCodes.Count() >= 5) //{ // throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, __(TransKeys.SEND_CODE_LIMIT))); //} var r = new Random(); code = r.Next(10000).ToString("0000"); //string failMsg; //var sendSuccess = TwilioSMS.SendSMS(phone, Resources.Resource.VerificationCode.FormatWith(code), out failMsg); //if (sendSuccess) //{ // db.VerifyCodes.Add(new VerifyCode // { // Code = code, // SentAt = DateTime.UtcNow, // Phone = phone // }); // db.SaveChanges(); // result.success = true; // return result; //} //else //{ // result.success = false; // result.message = failMsg; // return result; //} YunPianSMS.TplSendCodeSms(string.Format("#code#={0}", code), phone); db.VerifyCodes.Add(new VerifyCode { Code = code, SentAt = DateTime.UtcNow, Phone = phone }); db.SaveChanges(); result.success = true; return(result); }