No Description

CallOutOptController.cs 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using CallCenter.Utility;
  2. using CallCenterApi.Interface.Controllers.Base;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Web;
  7. using System.Web.Mvc;
  8. namespace CallCenterApi.Interface.Controllers
  9. {
  10. public class CallOutOptController : BaseController
  11. {
  12. // GET: CallOutOpt
  13. //外呼判断本地外地以及加前缀返回
  14. [Authority]
  15. public ActionResult GetCallOutprefix(string phone)
  16. {
  17. string phone1 = RequestString.ToDBC(RequestString.RemoveNotNumber(WebHelper.NoHtml(phone)));
  18. string tophone = phone1;
  19. string fix = ""; string bfix = ""; string wfix = "";
  20. string zipcode = Configs.GetValue("CallOutZipCode");
  21. bfix = Configs.GetValue("CallOutBPre");
  22. wfix = Configs.GetValue("CallOutWPre");
  23. int zip = GetZipCodeByPhone(phone1, zipcode);
  24. if (phone.Trim().Length != 4)
  25. {
  26. if (zip == 1)
  27. {
  28. fix = bfix;
  29. }
  30. else if (zip == 2)
  31. {
  32. fix = wfix;
  33. }
  34. else
  35. {
  36. tophone = phone1.TrimStart('0');
  37. if (zip == 3)
  38. {//本地固话去0加9 比如:988888517,937188888517
  39. fix = bfix;
  40. }
  41. else if (zip == 4)
  42. {//外地固话前加9 比如:9037188888517
  43. fix = wfix;
  44. }
  45. else
  46. {
  47. fix = bfix;
  48. }
  49. }
  50. }
  51. var obj = new
  52. {
  53. phone = fix + tophone,
  54. fix = fix
  55. };
  56. return Success("外呼号码加前缀", obj);
  57. }
  58. /// <summary>
  59. /// 根据号码和区号判断号码是否为归属地号码
  60. /// 返回0为分机号或特殊号码
  61. /// 返回1为本地号码
  62. /// 返回2为外地号码
  63. /// </summary>
  64. /// <param name="phone"></param>
  65. /// <param name="zipcode"></param>
  66. /// <returns></returns>
  67. [NonAction]
  68. public int GetZipCodeByPhone(string phone, string zipcode)
  69. {
  70. int res = 0;
  71. if (phone.Trim().Length >= 7)
  72. {
  73. //7位及7位以上是固定电话或手机
  74. //判断是否手机
  75. if (phone.Trim().Length == 11 && phone[0] == '1')
  76. {//号码为11位,首位是1,为手机号
  77. BLL.T_Sys_MobileData mobile_Bll = new BLL.T_Sys_MobileData();
  78. Model.T_Sys_MobileData mobileModel = mobile_Bll.GetModelList(" F_MobileNum = '" + phone.Substring(0, 7) + "' and F_IsDelete =0").FirstOrDefault();
  79. if (mobileModel != null)
  80. {
  81. if (mobileModel.F_ZipCode.Equals(zipcode))
  82. {
  83. res = 1;
  84. }
  85. else
  86. {
  87. res = 2;
  88. }
  89. }
  90. }
  91. else
  92. {
  93. if (phone.Trim().Length == 11 && phone.Substring(0, 3).Equals(zipcode))
  94. {//号码为11位
  95. //截取前三位区号判断是否本地
  96. bool resbd3 = phone.Substring(0, 3).Equals(zipcode);
  97. //截取前四位区号判断是否本地
  98. bool resbd4 = phone.Substring(0, 4).Equals(zipcode);
  99. if (resbd3 || resbd4)
  100. {
  101. res = 3;
  102. }
  103. else
  104. {
  105. res = 4;
  106. }
  107. }
  108. else if (phone.Trim().Length < 11)
  109. {//号码小于11位,为本地
  110. res = 3;
  111. }
  112. else if (phone.Trim().Length > 11 && phone.Substring(0, 4).Equals(zipcode))
  113. {//号码大于11位,截取前四位区号判断是否本地
  114. res = 3;
  115. }
  116. else
  117. {
  118. res = 4;
  119. }
  120. }
  121. }
  122. return res;
  123. }
  124. }
  125. }