足力健后端,使用.netcore版本,合并1个项目使用

CallOutOptController.cs 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Common;
  4. using System.IRepositories;
  5. using System.Linq;
  6. using System.Model;
  7. using System.Security.Claims;
  8. using System.Threading.Tasks;
  9. using System.Utility;
  10. using Microsoft.AspNetCore.Authorization;
  11. using Microsoft.AspNetCore.Mvc;
  12. using Microsoft.Extensions.Configuration;
  13. namespace TVShoppingCallCenter_ZLJ.Controllers.CallCenter
  14. {
  15. /// <summary>
  16. /// 外呼控制器
  17. /// </summary>
  18. [Authorize]
  19. [Produces("application/json")]
  20. [Route("api/[controller]")]
  21. public class CallOutOptController : BaseController
  22. {
  23. private readonly IConfiguration config;
  24. private readonly ISys_MobileDataRepository busMobileDataRepository;
  25. public CallOutOptController( IConfiguration _configuration, ISys_MobileDataRepository _busMobileDataRepository)
  26. {
  27. config = _configuration;
  28. busMobileDataRepository = _busMobileDataRepository;
  29. }
  30. /// <summary>
  31. /// 外呼判断本地外地以及加前缀返回
  32. /// </summary>
  33. /// <param name="phone"></param>
  34. /// <returns></returns>
  35. [HttpPost("GetCallOutprefix")]
  36. public async Task<IActionResult> GetCallOutprefix(string phone)
  37. {
  38. string phone1 = StringHelper.ToDBC(StringHelper.RemoveNotNumber(StringHelper.NoHtml(phone)));
  39. string tophone = phone1;
  40. string fix = ""; string bfix = ""; string wfix = "";
  41. string zipcode = config["appSettings:CallOutZipCode"];
  42. bfix = config["appSettings:CallOutBPre"];
  43. wfix = config["appSettings:CallOutWPre"];
  44. int zip =await GetZipCodeByPhone(phone1, zipcode);
  45. if (zip == 1)
  46. {
  47. fix = bfix;
  48. }
  49. else if (zip == 2)
  50. {
  51. fix = wfix;
  52. }
  53. else
  54. {
  55. tophone = phone1.TrimStart('0');
  56. if (zip == 3)
  57. {//本地固话去0加9 比如:988888517,937188888517
  58. fix = bfix;
  59. }
  60. else if (zip == 4)
  61. {//外地固话前加9 比如:9037188888517
  62. fix = wfix;
  63. }
  64. }
  65. var obj = new
  66. {
  67. phone = fix + tophone,
  68. fix = fix
  69. };
  70. return Success("外呼号码加前缀", obj);
  71. }
  72. /// <summary>
  73. /// 根据号码和区号判断号码是否为归属地号码
  74. /// 返回0为分机号或特殊号码
  75. /// 返回1为本地号码
  76. /// 返回2为外地号码
  77. /// </summary>
  78. /// <param name="phone"></param>
  79. /// <param name="zipcode"></param>
  80. /// <returns></returns>
  81. [NonAction]
  82. public async Task<int> GetZipCodeByPhone(string phone, string zipcode)
  83. {
  84. int res = 0;
  85. if (phone.Trim().Length >= 7)
  86. {
  87. //7位及7位以上是固定电话或手机
  88. //判断是否手机
  89. if (phone.Trim().Length == 11 && phone[0] == '1')
  90. {//号码为11位,首位是1,为手机号
  91. string p7 = phone.Substring(0, 7);
  92. T_Sys_MobileData mobileModel = await busMobileDataRepository.GetFirst(q=>q.F_MobileNum== p7);
  93. if (mobileModel != null)
  94. {
  95. if (mobileModel.F_ZipCode.Equals(zipcode))
  96. {
  97. res = 1;
  98. }
  99. else
  100. {
  101. res = 2;
  102. }
  103. }
  104. }
  105. else
  106. {
  107. if (phone.Trim().Length == 11 && phone.Substring(0, 3).Equals(zipcode))
  108. {//号码为11位
  109. //截取前三位区号判断是否本地
  110. bool resbd3 = phone.Substring(0, 3).Equals(zipcode);
  111. //截取前四位区号判断是否本地
  112. bool resbd4 = phone.Substring(0, 4).Equals(zipcode);
  113. if (resbd3 || resbd4)
  114. {
  115. res = 3;
  116. }
  117. else
  118. {
  119. res = 4;
  120. }
  121. }
  122. else if (phone.Trim().Length < 11)
  123. {//号码小于11位,为本地
  124. res = 1;
  125. }
  126. else if (phone.Trim().Length < 11)
  127. {//号码小于11位,为本地
  128. res = 3;
  129. }
  130. else if (phone.Trim().Length > 11 && phone.Substring(0, 4).Equals(zipcode))
  131. {//号码大于11位,截取前四位区号判断是否本地
  132. res = 3;
  133. }
  134. else
  135. {
  136. res = 4;
  137. }
  138. }
  139. }
  140. return res;
  141. }
  142. }
  143. }