GeneralMethod.cs 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303
  1. 
  2. using Microsoft.AspNetCore.SignalR;
  3. using Microsoft.International.Converters.PinYinConverter;
  4. using NPOI.HSSF.Util;
  5. using OASystem.API.OAMethodLib.Hub.HubClients;
  6. using OASystem.API.OAMethodLib.Hub.Hubs;
  7. using OASystem.API.OAMethodLib.JuHeAPI;
  8. using OASystem.API.OAMethodLib.SignalR.Hubs;
  9. using OASystem.Domain.Entities.Customer;
  10. using OASystem.Domain.Entities.District;
  11. using OASystem.Domain.Entities.Financial;
  12. using OASystem.Domain.Entities.Groups;
  13. using OASystem.Domain.ViewModels.Financial;
  14. using OASystem.Domain.ViewModels.Groups;
  15. using OASystem.Domain.ViewModels.JuHeExchangeRate;
  16. using OASystem.Infrastructure.Repositories.CRM;
  17. using OASystem.Infrastructure.Repositories.Groups;
  18. using System.IdentityModel.Tokens.Jwt;
  19. using System.IO.Compression;
  20. using System.Security.Claims;
  21. using System.Web;
  22. namespace OASystem.API.OAMethodLib
  23. {
  24. public static class GeneralMethod
  25. {
  26. //团组信息
  27. private readonly static DelegationInfoRepository _dirRep = AutofacIocManager.Instance.GetService<DelegationInfoRepository>();
  28. private readonly static TeamRateRepository _teamRateRep = AutofacIocManager.Instance.GetService<TeamRateRepository>();
  29. private readonly static IJuHeApiService _juHeApi = AutofacIocManager.Instance.GetService<IJuHeApiService>();
  30. private readonly static SetDataRepository _setDataRep = AutofacIocManager.Instance.GetService<SetDataRepository>();
  31. private readonly static TableOperationRecordRepository _tableOperationRecordRep = AutofacIocManager.Instance.GetService<TableOperationRecordRepository>();
  32. private readonly static MessageRepository _messageRep = AutofacIocManager.Instance.GetService<MessageRepository>();
  33. private readonly static IHubContext<ChatHub, IChatClient> _hubContext = AutofacIocManager.Instance.GetService<IHubContext<ChatHub, IChatClient>>();
  34. #region 员工注册默认添加基础页面
  35. /// <summary>
  36. /// 默认职位权限 View
  37. /// </summary>
  38. public static bool DefaultPostAuth(int depId,int postId, int userId)
  39. {
  40. if (depId < 1) return false;
  41. if (postId < 1) return false;
  42. if (userId < 1) return false;
  43. List<DefaultPostPageAuthView> _defaultData = AppSettingsHelper.Get<DefaultPostPageAuthView>("DefaultPostPageData");
  44. if (_defaultData.Count < 1) return false;
  45. List<int> pageData = new List<int>();
  46. //添加公司公共页面
  47. pageData.AddRange(_defaultData.Find(it => it.DepId == -1)?.PostPageAuths[0].PageIds ?? new List<int>());
  48. //添加部门页面
  49. var depPublicPageData = _defaultData.Find(it => it.DepId == depId);
  50. if (depPublicPageData != null) //特殊部门
  51. {
  52. //公共页面
  53. pageData.AddRange(depPublicPageData.PostPageAuths.Find(it => it.PostId == -1)?.PageIds ?? new List<int>());
  54. //岗位页面
  55. pageData.AddRange(depPublicPageData.PostPageAuths.Find(it => it.PostId == postId)?.PageIds ?? new List<int>());
  56. }
  57. else //通用部门
  58. {
  59. pageData.AddRange(_defaultData.Find(it => it.DepId == 0)?.PostPageAuths[0].PageIds ?? new List<int>());
  60. }
  61. if (pageData.Count > 0)
  62. {
  63. //页面操作权限数据(添加修改等...)
  64. var pageFunctionData = _dirRep._sqlSugar.Queryable<Sys_SystemMenuAndFunction>().Where(it => pageData.Contains(it.SmId) && it.IsDel == 0 ).ToList();
  65. var defaultPageData = pageFunctionData.Select(it => new Sys_UserAuthority() {
  66. UId = userId,
  67. SmId = it.SmId,
  68. FId = it.FId,
  69. CreateUserId = 4, //管理员
  70. CreateTime = DateTime.Now,
  71. IsDel = 0,
  72. IsTemp = 1
  73. }).ToList();
  74. if (defaultPageData.Count > 0)
  75. {
  76. //添加页面操作权限
  77. var s = _dirRep._sqlSugar.Fastest<Sys_UserAuthority>().PageSize(100000).BulkCopy(defaultPageData);
  78. if (s > 0)
  79. {
  80. return true;
  81. }
  82. }
  83. }
  84. return false;
  85. }
  86. #endregion
  87. #region 消息
  88. /// <summary>
  89. /// 消息 发布And 通知
  90. /// </summary>
  91. /// <param name="msgTypeEnum">
  92. /// 消息类型
  93. /// 1 公告通知
  94. /// 2 团组流程管控通知
  95. /// 3 团组业务操作通知
  96. /// 4 团组费用审核消息
  97. /// 5 团组签证进度通知
  98. /// 6 团组任务进度通知
  99. /// </param>
  100. /// <param name="title">消息标题</param>
  101. /// <param name="content">消息内容</param>
  102. /// <param name="userIds"></param>
  103. /// <param name="diId">团组id</param>
  104. /// <param name="param">团组id</param>
  105. /// <returns></returns>
  106. public static async Task<bool> MessageIssueAndNotification(MessageTypeEnum msgTypeEnum, string title, string content, List<int> userIds, int diId = 0, string param = "")
  107. {
  108. MessageDto messageDto = new()
  109. {
  110. Type = msgTypeEnum,
  111. IssuerId = 4,//管理员
  112. DiId = diId,
  113. Title = title,
  114. Content = content,
  115. ReleaseTime = DateTime.Now,
  116. UIdList = userIds,
  117. Param = param
  118. };
  119. var status = await _messageRep.AddMsg(messageDto);//添加消息
  120. if (status)
  121. {
  122. //给在线在用户发送消息
  123. List<string> connIds = UserStore.OnlineUser.Where(it => userIds.Contains(it.UserId)).Select(it => it.ConnectionId).ToList();
  124. string notificationTypeStr1 = GetMsgNotificationType(msgTypeEnum);
  125. string notificationTypeStr = JsonConvert.SerializeObject(
  126. new
  127. {
  128. UserIds = userIds,
  129. Msg = $"您有一条{notificationTypeStr1}相关的消息!"
  130. }
  131. );
  132. await _hubContext.Clients.Clients(connIds).ReceiveMessage($"您有一条{notificationTypeStr1}相关的消息!");
  133. return true;
  134. }
  135. return false;
  136. }
  137. /// <summary>
  138. /// 根据消息类型 获取 消息通知类型
  139. /// </summary>
  140. /// <returns></returns>
  141. public static string GetMsgNotificationType(MessageTypeEnum msgTypeEnum)
  142. {
  143. int notificationType = 0;
  144. string notificationStr = "";
  145. List<NotificationTypeView> notificationTypeViews = AppSettingsHelper.Get<NotificationTypeView>("MessageNotificationType");
  146. notificationType = notificationTypeViews.Where(it => it.MsgTypeIds.Contains((int)msgTypeEnum)).Select(it => it.TypeId).FirstOrDefault();
  147. if (notificationType == 1021) notificationStr = "操作";
  148. else if (notificationType == 1020) notificationStr = "任务";
  149. return notificationStr;
  150. }
  151. #endregion
  152. #region md5 加密
  153. /// <summary>
  154. /// MD5加密,和动网上的16/32位MD5加密结果相同,
  155. /// 使用的UTF8编码
  156. /// </summary>
  157. /// <param name="source">待加密字串</param>
  158. /// <param name="length">16或32值之一,其它则采用.net默认MD5加密算法</param>
  159. /// <returns>加密后的字串</returns>
  160. public static string Encrypt(string source, int length = 32)
  161. {
  162. if (string.IsNullOrWhiteSpace(source))
  163. return string.Empty;
  164. HashAlgorithm hashAlgorithm = CryptoConfig.CreateFromName("MD5") as HashAlgorithm;
  165. byte[] bytes = Encoding.UTF8.GetBytes(source);
  166. byte[] hashValue = hashAlgorithm.ComputeHash(bytes);
  167. StringBuilder sb = new StringBuilder();
  168. switch (length)
  169. {
  170. case 16://16位密文是32位密文的9到24位字符
  171. for (int i = 4; i < 12; i++)
  172. {
  173. sb.Append(hashValue[i].ToString("x2"));
  174. }
  175. break;
  176. case 32:
  177. for (int i = 0; i < 16; i++)
  178. {
  179. sb.Append(hashValue[i].ToString("x2"));
  180. }
  181. break;
  182. default:
  183. for (int i = 0; i < hashValue.Length; i++)
  184. {
  185. sb.Append(hashValue[i].ToString("x2"));
  186. }
  187. break;
  188. }
  189. return sb.ToString();
  190. }
  191. #endregion
  192. #region jwt
  193. /// <summary>
  194. /// 获取token
  195. /// </summary>
  196. /// <param name="_config"></param>
  197. /// <param name="Number"></param>
  198. /// <param name="exp"></param>
  199. /// <returns></returns>
  200. public static async Task<string> GetToken(IConfiguration _config, string Number, int uId, string uName, DateTime exp)
  201. {
  202. string userId = Guid.NewGuid().ToString().Replace("-", "");
  203. var claims = new[] {
  204. new Claim(ClaimTypes.NameIdentifier, uName),
  205. new Claim(ClaimTypes.NameIdentifier, uId.ToString()),
  206. new Claim(ClaimTypes.NameIdentifier, userId),
  207. new Claim("Number",Number)
  208. };
  209. var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["JwtSecurityKey"]));
  210. var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
  211. var token = new JwtSecurityToken(
  212. issuer: "OASystem.com",
  213. audience: "OASystem.com",
  214. claims: claims,
  215. expires: exp,
  216. signingCredentials: creds);
  217. var indentity = new ClaimsIdentity(claims, "formlogin");
  218. var principal = new ClaimsPrincipal(indentity);
  219. // await _httpContext.SignInAsync (CookieAuthenticationDefaults.AuthenticationScheme, principal);
  220. return new JwtSecurityTokenHandler().WriteToken(token);
  221. }
  222. #endregion
  223. #region 数据类型转换
  224. /// <summary>
  225. /// object 转 Int
  226. /// </summary>
  227. /// <param name="obj"></param>
  228. /// <returns></returns>
  229. public static int GetInt(this object obj)
  230. {
  231. if (obj == null)
  232. return 0;
  233. int _number = 0;
  234. bool reslut = Int32.TryParse(obj.ToString(), out _number);
  235. return _number;
  236. }
  237. private static DateTime dateStart = new DateTime(1970, 1, 1, 8, 0, 0);
  238. private static long longTime = 621355968000000000;
  239. private static int samllTime = 10000000;
  240. /// <summary>
  241. /// 时间戳 转 datetime
  242. /// </summary>
  243. /// <param name="timeStamp"></param>
  244. /// <returns></returns>
  245. public static DateTime GetTimeSpmpToDate(this object timeStamp)
  246. {
  247. if (timeStamp == null) return dateStart;
  248. DateTime dateTime = new DateTime(longTime + Convert.ToInt64(timeStamp) * samllTime, DateTimeKind.Utc).ToLocalTime();
  249. return dateTime;
  250. }
  251. #endregion
  252. #region 用户页面操作功能 权限
  253. /// <summary>
  254. /// 用户页面操作功能(可使用)
  255. /// </summary>
  256. /// <param name="userId">用户Id</param>
  257. /// <param name="PageId">页面Id</param>
  258. /// <returns></returns>
  259. public static async Task<PageFunAuthViewBase> PostUserPageFuncDatas(int userId, int PageId)
  260. {
  261. PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
  262. List<UserPageFuncView> userPageFuncDatas = new List<UserPageFuncView>();
  263. string sql = string.Format(@"Select ua.UId As UserId, u.CnName As UserName, pa.ModuleId,pa.ModuleName,pa.PageId,pa.PageName,pa.PageIsEnable,
  264. pa.PagePhoneIsEnable,pa.FuncId,pa.FuncName,pa.FuncIsEnable
  265. From Sys_UserAuthority ua
  266. Left Join Sys_Users u On ua.UId = u.Id
  267. Left Join (
  268. Select sd.Id As ModuleId,sd.Name As ModuleName, smp.Id As PageId,smp.Name As PageName,smp.IsEnable As PageIsEnable,
  269. smp.phoneIsEnable As PagePhoneIsEnable,pfp.Id As FuncId,pfp.FunctionName As FuncName,pfp.IsEnable As FuncIsEnable
  270. From Sys_SystemMenuAndFunction smaf
  271. Left Join Sys_SystemMenuPermission smp On smaf.SmId = smp.Id
  272. Left Join Sys_SetData sd On sd.STid = 5 And smp.Mid = sd.Id
  273. Left Join Sys_PageFunctionPermission pfp On smaf.FId = pfp.Id
  274. Where smaf.IsDel = 0 And smp.IsDel = 0 And pfp.IsDel = 0 And sd.IsDel = 0 And smp.IsEnable = 1
  275. ) As pa On ua.SmId = pa.PageId And ua.FId = pa.FuncId
  276. Where ua.IsDel = 0 And ua.UId = {0} And pa.PageId = {1}
  277. Order By ModuleId,PageId,FuncId Asc", userId, PageId);
  278. userPageFuncDatas = await _dirRep._sqlSugar.SqlQueryable<UserPageFuncView>(sql).ToListAsync();
  279. if (userPageFuncDatas.Count <= 0)
  280. {
  281. return pageFunAuth;
  282. }
  283. UserPageFuncView userPageFunc = new UserPageFuncView();
  284. //查询 1
  285. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 1).FirstOrDefault();
  286. if (userPageFunc != null) pageFunAuth.CheckAuth = 1;
  287. //删除 2
  288. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 2).FirstOrDefault();
  289. if (userPageFunc != null) pageFunAuth.DeleteAuth = 1;
  290. //编辑 3
  291. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 3).FirstOrDefault();
  292. if (userPageFunc != null) pageFunAuth.EditAuth = 1;
  293. //下载 4
  294. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 4).FirstOrDefault();
  295. if (userPageFunc != null) pageFunAuth.FilesDownloadAuth = 1;
  296. //上传 5
  297. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 5).FirstOrDefault();
  298. if (userPageFunc != null) pageFunAuth.FilesUploadAuth = 1;
  299. //添加 11
  300. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 11).FirstOrDefault();
  301. if (userPageFunc != null) pageFunAuth.AddAuth = 1;
  302. //审核 12
  303. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 12).FirstOrDefault();
  304. if (userPageFunc != null) pageFunAuth.AuditAuth = 1;
  305. return pageFunAuth;
  306. }
  307. #endregion
  308. #region 业务模块 团组权限
  309. /// <summary>
  310. /// 业务模块 团组操作权限
  311. /// 验证 并返回可操作的团
  312. /// </summary>
  313. /// <param name="diId">团组Id</param>
  314. /// <param name="userId">用户Id</param>
  315. /// <param name="CTable">业务模块Id</param>
  316. /// <returns></returns>
  317. public static async Task<Result> PostGroupOperationAuth(int diId, int userId, int CTable)
  318. {
  319. Result _result = new Result { Code = -1, Msg = "No Operation Authorty!" };
  320. if (CTable < 1)
  321. {
  322. _result.Msg = "请填写正确的用户Id!";
  323. return _result;
  324. }
  325. var data = _dirRep._sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(it => it.DIId == diId && it.UId == userId && it.CTId == CTable && it.IsDel == 0).First();
  326. if (data == null)
  327. {
  328. _result.Msg = "你没有本团下的该业务模块操作,请联系主管分配操作权限!";
  329. }
  330. else
  331. {
  332. _result.Code = 0;
  333. }
  334. return _result;
  335. }
  336. /// <summary>
  337. /// 业务模块 团组操作权限
  338. /// 返回可操作的团
  339. /// </summary>
  340. /// <param name="diId">团组Id</param>
  341. /// <param name="userId">用户Id</param>
  342. /// <param name="CTable">业务模块Id</param>
  343. /// <returns></returns>
  344. public static async Task<List<Web_ShareGroupInfoView>> PostOperationAuthReturnGroupInfosAsync(int userId, int CTable)
  345. {
  346. List<Web_ShareGroupInfoView> _ShareGroupInfoViews = new List<Web_ShareGroupInfoView>();
  347. var taskDatas = _dirRep._sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(it => it.UId == userId && it.CTId == CTable && it.IsDel == 0).ToList();
  348. if (taskDatas.Count < 1) return _ShareGroupInfoViews;
  349. string diIds = string.Join(",", taskDatas.Select(it => it.DIId).ToList());
  350. string sql = string.Format(@"Select Id,TeamName,TourCode,ClientName,VisitCountry,VisitStartDate,VisitEndDate,VisitDays,VisitPNumber
  351. From Grp_DelegationInfo Where Id In({0}) And IsDel = 0 Order By Id Desc", diIds);
  352. _ShareGroupInfoViews = await _dirRep._sqlSugar.SqlQueryable<Web_ShareGroupInfoView>(sql).ToListAsync();
  353. return _ShareGroupInfoViews;
  354. }
  355. #endregion
  356. #region 团组相关
  357. #region 建团按国家默认添加汇率 / 默认权限分配
  358. /// <summary>
  359. /// 团组汇率
  360. /// 建团时 添加基础汇率 CNY
  361. /// 按国家 添加 默认币种
  362. /// </summary>
  363. /// <param name="userId"></param>
  364. /// <param name="diId"></param>
  365. /// <returns></returns>
  366. public static async Task<Result> PostGroupRateAddInit(int userId, int diId)
  367. {
  368. Result result = new() { Code = -2 };
  369. if (userId < 1)
  370. {
  371. result.Msg = string.Format(@"请传入正确的userId");
  372. return result;
  373. }
  374. if (diId < 1)
  375. {
  376. result.Msg = string.Format(@"请传入正确的DiId");
  377. return result;
  378. }
  379. //美元(USD):1.0000|欧元(EUR):1.0000|墨西哥比索(MXN):1.0000
  380. string rateInit = string.Format(@"人名币(CNY):1.0000");
  381. //var gropInfo = _dirRep._sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && it.Id == diId).First();
  382. //if (gropInfo == null)
  383. //{
  384. // result.Msg = $@"未查询到团组信息!";
  385. // return result;
  386. //}
  387. var juheRateData = await _juHeApi.GetExchangeRateAsync();
  388. if (juheRateData.Error_code != 0)
  389. {
  390. result.Msg = juheRateData.Reason;
  391. return result;
  392. }
  393. List<ExchangeRateModel> exchangeRateModels = (List<ExchangeRateModel>)juheRateData.Result;
  394. if (exchangeRateModels.Count <= 0)
  395. {
  396. result.Msg = $@"未查询到聚合接口汇率信息!";
  397. return result;
  398. }
  399. if (exchangeRateModels.Count > 0)
  400. {
  401. var codes = _dirRep._sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66).ToList();
  402. for (int i = 0; i < exchangeRateModels.Count; i++)
  403. {
  404. string currencyName = exchangeRateModels[i].Name;
  405. string code = "";
  406. var currencyData = codes.Where(it => it.Remark == currencyName).FirstOrDefault();
  407. if (currencyData != null)
  408. {
  409. code = currencyData.Name;
  410. decimal currRate = 0.00M;
  411. string MSellPri = exchangeRateModels[i].MSellPri;
  412. if (!string.IsNullOrEmpty(MSellPri))
  413. {
  414. currRate = Convert.ToDecimal(MSellPri) / 100M;
  415. }
  416. rateInit += $@"|{currencyName}({code}):{currRate.ToString("#0.0000")}";
  417. }
  418. }
  419. }
  420. var cTableIds = _dirRep._sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 16).ToList();
  421. if (cTableIds.Count < 1)
  422. {
  423. result.Msg = $@"未查询到操作模块信息!";
  424. return result;
  425. }
  426. List<Grp_TeamRate> grp_TeamRates = new List<Grp_TeamRate>();
  427. foreach (var item in cTableIds)
  428. {
  429. grp_TeamRates.Add(
  430. new Grp_TeamRate() { DiId = diId, CTable = item.Id, Remark = rateInit, CreateUserId = userId }
  431. );
  432. }
  433. if (grp_TeamRates.Count > 0)
  434. {
  435. var addId = _teamRateRep._sqlSugar.Insertable(grp_TeamRates).ExecuteCommand();
  436. if (addId < 1)
  437. {
  438. result.Msg = string.Format(@"添加失败!");
  439. return result;
  440. }
  441. }
  442. result.Code = 0;
  443. result.Msg = string.Format(@"操作成功!");
  444. return result;
  445. }
  446. /// <summary>
  447. /// 团组汇率
  448. /// 建团时 默认按照岗位分配权限
  449. /// </summary>
  450. /// <param name="userId"></param>
  451. /// <param name="diId"></param>
  452. /// <param name="companyId"></param>
  453. /// <returns></returns>
  454. public static async Task<Result> PostGroupAuthAddInit(int userId, int diId, int companyId = 2)
  455. {
  456. Result result = new() { Code = -2 };
  457. if (userId < 0)
  458. {
  459. result.Msg = string.Format(@"请传入正确的userId");
  460. return result;
  461. }
  462. if (companyId < 0)
  463. {
  464. result.Msg = string.Format(@"请传入正确的companyId");
  465. return result;
  466. }
  467. if (diId < 0)
  468. {
  469. result.Msg = string.Format(@"请传入正确的DiId");
  470. return result;
  471. }
  472. var userDatas = await _teamRateRep._sqlSugar
  473. .Queryable<Sys_Users>()
  474. .LeftJoin<Sys_Department>((su,sd) => su.DepId == sd.Id && sd.IsDel == 0)
  475. .LeftJoin<Sys_JobPost>((su,sd,sjp) => su.JobPostId == sjp.Id && sjp.IsDel == 0)
  476. .Where(su => su.IsDel == 0)
  477. .Select((su,sd,sjp) => new {
  478. su.DepId,
  479. sd.DepName,
  480. su.JobPostId,
  481. sjp.JobName,
  482. su.Id,
  483. su.CnName
  484. })
  485. .ToListAsync();
  486. /*
  487. * 76 酒店预订 --> 国交部门 酒店 岗位
  488. * 77 行程 --> 国交部门 经理,主管 岗位
  489. * 79 车/导游地接 --> 国交部门 OP 岗位
  490. * 80 签证 --> 国交部门 签证 岗位
  491. * 81 邀请/公务活动 --> 国交部门 商邀 岗位
  492. * 82 团组客户保险 --> 国交部 经理,主管 岗位
  493. * 85 机票预订 --> 国交部门 机票 岗位
  494. * 98 其他款项 --> 总经办部门 总经理 岗位/国交部门(ALL) 岗位/财务部门(ALL) 岗位/策划部门(ALL) 岗位/人事部门 采购 岗位
  495. * 1015 超支费用 --> 财务部门(ALL)岗位
  496. */
  497. List<Grp_GroupsTaskAssignment> _GroupsTaskAssignments = new List<Grp_GroupsTaskAssignment>();
  498. // 76 酒店预订 --> 国交部门(7) 酒店(25) 岗位
  499. _GroupsTaskAssignments.AddRange(
  500. userDatas
  501. .Where(it => it.DepId == 7 && it.JobPostId == 25)
  502. .Select(it => new Grp_GroupsTaskAssignment()
  503. {
  504. DIId = diId,
  505. CTId = 76,
  506. UId = it.Id,
  507. CreateUserId = userId
  508. }).ToList()
  509. );
  510. // 77 行程 --> 国交部门(7) 经理(32),主管(22) 岗位
  511. _GroupsTaskAssignments.AddRange(
  512. userDatas
  513. .Where(it => it.DepId == 7 && (it.JobPostId == 22 || it.JobPostId == 32))
  514. .Select(it => new Grp_GroupsTaskAssignment()
  515. {
  516. DIId = diId,
  517. CTId = 77,
  518. UId = it.Id,
  519. CreateUserId = userId
  520. }).ToList()
  521. );
  522. //79 车/导游地接 --> 国交部门(7) OP(28) 岗位
  523. _GroupsTaskAssignments.AddRange(
  524. userDatas.Where(it => it.DepId == 7 && it.JobPostId == 28)
  525. .Select(it => new Grp_GroupsTaskAssignment()
  526. {
  527. DIId = diId,
  528. CTId = 79,
  529. UId = it.Id,
  530. CreateUserId = userId
  531. }).ToList()
  532. );
  533. //81 邀请/公务活动 --> 国交部门(7) 商邀(27) 岗位
  534. _GroupsTaskAssignments.AddRange(
  535. userDatas
  536. .Where(it => it.DepId == 7 && it.JobPostId == 27)
  537. .Select(it => new Grp_GroupsTaskAssignment()
  538. {
  539. DIId = diId,
  540. CTId = 81,
  541. UId = it.Id,
  542. CreateUserId = userId
  543. }).ToList()
  544. );
  545. //80 签证 --> 国交部门(7) 签证(26) 岗位
  546. _GroupsTaskAssignments.AddRange(
  547. userDatas
  548. .Where(it => it.DepId == 7 && it.JobPostId == 26)
  549. .Select(it => new Grp_GroupsTaskAssignment()
  550. {
  551. DIId = diId,
  552. CTId = 80,
  553. UId = it.Id,
  554. CreateUserId = userId
  555. }).ToList()
  556. );
  557. //82 团组客户保险 --> 国交部(7) 经理(32),主管(22) 岗位
  558. _GroupsTaskAssignments.AddRange(
  559. userDatas
  560. .Where(it => it.DepId == 7 && (it.JobPostId == 22 || it.JobPostId == 32))
  561. .Select(it => new Grp_GroupsTaskAssignment()
  562. {
  563. DIId = diId,
  564. CTId = 82,
  565. UId = it.Id,
  566. CreateUserId = userId
  567. }).ToList()
  568. );
  569. //85 机票预订 --> 国交部门(7) 机票(24) 岗位
  570. _GroupsTaskAssignments.AddRange(
  571. userDatas
  572. .Where(it => it.DepId == 7 && it.JobPostId == 24)
  573. .Select(it => new Grp_GroupsTaskAssignment()
  574. {
  575. DIId = diId,
  576. CTId = 85,
  577. UId = it.Id,
  578. CreateUserId = userId
  579. }).ToList()
  580. );
  581. //98 其他款项 --> 总经办部门(1) 总经理(1) 岗位/国交部门(7)(ALL) 岗位/财务部门(3)(ALL) 岗位/策划部门(5)(ALL) 岗位/人事部门(4) 采购(74) 岗位
  582. List<int> depIds = new List<int>() { 7,3,5 };
  583. List<int> jobIds = new List<int>() { 1,74};
  584. _GroupsTaskAssignments.AddRange(
  585. userDatas
  586. .Where(it => depIds.Contains(it.DepId) || jobIds.Contains(it.JobPostId))
  587. .Select(it => new Grp_GroupsTaskAssignment()
  588. {
  589. DIId = diId,
  590. CTId = 98,
  591. UId = it.Id,
  592. CreateUserId = userId
  593. }).ToList()
  594. );
  595. //1015 超支费用 --> 财务部门(3)(ALL)岗位
  596. _GroupsTaskAssignments.AddRange(
  597. userDatas
  598. .Where(it => it.DepId == 3)
  599. .Select(it => new Grp_GroupsTaskAssignment()
  600. {
  601. DIId = diId,
  602. CTId = 1015,
  603. UId = it.Id,
  604. CreateUserId = userId
  605. }).ToList()
  606. );
  607. if (_GroupsTaskAssignments.Count > 0)
  608. {
  609. var addId =_teamRateRep._sqlSugar.Insertable(_GroupsTaskAssignments).ExecuteCommand();
  610. }
  611. result.Code = 0;
  612. result.Msg = string.Format(@"操作成功!");
  613. return result;
  614. }
  615. #endregion
  616. #endregion
  617. #region 团组汇率
  618. /// <summary>
  619. /// 团组汇率
  620. /// 获取板块 币种 及 汇率
  621. /// 76 酒店预订 77 行程 79 车/导游地接
  622. /// 80 签证 82 团组客户保险 85 机票预订
  623. /// 98 其他款项 285 收款退还
  624. /// </summary>
  625. /// <param name="teamRateModels"></param>
  626. /// <param name="cTable"></param>
  627. /// <param name="currencyCode"></param>
  628. /// <returns>
  629. /// string
  630. /// eg: CNY 1.0000
  631. /// </returns>
  632. public static async Task<string> PostGroupRateByCTableAndCurrency(List<TeamRateModelView> teamRateModels, int cTable, List<string> currencyCodes)
  633. {
  634. string str = "";
  635. List<string> currencyRates = new List<string>();
  636. TeamRateModelView hotelRateData = teamRateModels.Where(it => it.CTableId == cTable).FirstOrDefault();
  637. if (hotelRateData != null)
  638. {
  639. var hotelRates = hotelRateData.TeamRates;
  640. foreach (var item in currencyCodes)
  641. {
  642. if (!string.IsNullOrEmpty(item))
  643. {
  644. var hotelRateInfo = hotelRates.Where(it => it.CurrencyCode.Equals(item)).FirstOrDefault();
  645. if (hotelRateInfo != null)
  646. {
  647. string str1 = string.Format("{0} {1}\r\n", hotelRateInfo.CurrencyCode, hotelRateInfo.Rate.ToString("#0.0000"));
  648. currencyRates.Add(str1);
  649. }
  650. }
  651. }
  652. if (currencyRates != null || currencyRates.Count > 0)
  653. {
  654. currencyRates = currencyRates.Distinct().ToList();
  655. foreach (var item in currencyRates)
  656. {
  657. str += item;
  658. }
  659. }
  660. }
  661. return str;
  662. }
  663. /// <summary>
  664. /// 团组汇率 币种 Item (来源:团组汇率)
  665. /// 根据 团组Id And 业务类型(CTable)Id
  666. /// api处理CTable = 285,默认返回CNY
  667. /// </summary>
  668. /// <param name="portType"></param>
  669. /// <param name="diId"></param>
  670. /// <param name="cTable"></param>
  671. /// <returns></returns>
  672. public static async Task<TeamRateModelGeneralView> PostGroupTeamRateByDiIdAndCTableId(int portType, int diId, int cTable)
  673. {
  674. TeamRateModelGeneralView _view = new TeamRateModelGeneralView();
  675. _view = await _teamRateRep.PostGroupTeamRateByDiIdAndCTableId(portType, diId, cTable);
  676. return _view;
  677. }
  678. /// <summary>
  679. /// 汇率备注拆分
  680. /// (美元(USD):7.2370|日元(JPY):0.0499|欧元(EUR):8.3000|英镑(GBP):9.1996|港币(HKD):0.9291)
  681. /// </summary>
  682. /// <param name="rateRemark"></param>
  683. /// <returns></returns>
  684. public static async Task<List<TeamRateDescAddCurrencyIdView>> SplitExchangeRate(this string rateRemark)
  685. {
  686. List<TeamRateDescAddCurrencyIdView> _view = new List<TeamRateDescAddCurrencyIdView>();
  687. List<SetDataInfoView> currencyDatas = new List<SetDataInfoView>();
  688. #region 获取所有币种
  689. string sql = string.Format(@"select * from Sys_SetData where STid = {0} and isdel = 0", 66);
  690. var DBdata = _setDataRep.GetListBySqlWithNolock(sql);
  691. if (DBdata == null || DBdata.Count == 0)
  692. {
  693. return _view;
  694. }
  695. currencyDatas = DBdata.Select(x => new SetDataInfoView
  696. {
  697. Name = x.Name,
  698. Id = x.Id,
  699. Remark = x.Remark,
  700. }).ToList();
  701. #endregion
  702. #region 拆分remark里的汇率
  703. if (string.IsNullOrEmpty(rateRemark))
  704. {
  705. return _view;
  706. }
  707. if (rateRemark.Contains("|"))
  708. {
  709. string[] currencyArr = rateRemark.Split("|");
  710. foreach (string currency in currencyArr)
  711. {
  712. string[] currency1 = currency.Split(":");
  713. string[] currency2 = currency1[0].Split("(");
  714. string currencyCode = currency2[1].Replace(")", "").TrimEnd();
  715. TeamRateDescAddCurrencyIdView rateDescView = new TeamRateDescAddCurrencyIdView()
  716. {
  717. CurrencyId = currencyDatas.Find(it => it.Name == currencyCode).Id,
  718. CurrencyCode = currencyCode,
  719. CurrencyName = currency2[0],
  720. Rate = decimal.Parse(currency1[1]),
  721. };
  722. _view.Add(rateDescView);
  723. }
  724. }
  725. else
  726. {
  727. try
  728. {
  729. string[] currency1 = rateRemark.Split(":");
  730. string[] currency2 = currency1[0].Split("(");
  731. string currencyCode = currency2[1].Replace(")", "").TrimEnd();
  732. TeamRateDescAddCurrencyIdView rateDescView = new TeamRateDescAddCurrencyIdView()
  733. {
  734. CurrencyId = currencyDatas.Find(it => it.Name == currencyCode).Id,
  735. CurrencyCode = currencyCode,
  736. CurrencyName = currency2[0],
  737. Rate = decimal.Parse(currency1[1]),
  738. };
  739. _view.Add(rateDescView);
  740. }
  741. catch (Exception)
  742. {
  743. return _view;
  744. }
  745. }
  746. #endregion
  747. return _view;
  748. }
  749. #endregion
  750. #region 汉字转换拼音
  751. private static Dictionary<int, List<string>> GetTotalPingYinDictionary(string text)
  752. {
  753. var chs = text.ToCharArray();
  754. //记录每个汉字的全拼
  755. Dictionary<int, List<string>> totalPingYinList = new Dictionary<int, List<string>>();
  756. for (int i = 0; i < chs.Length; i++)
  757. {
  758. var pinyinList = new List<string>();
  759. //是否是有效的汉字
  760. if (ChineseChar.IsValidChar(chs[i]))
  761. {
  762. ChineseChar cc = new ChineseChar(chs[i]);
  763. pinyinList = cc.Pinyins.Where(p => !string.IsNullOrWhiteSpace(p)).ToList();
  764. }
  765. else
  766. {
  767. pinyinList.Add(chs[i].ToString());
  768. }
  769. //去除声调,转小写
  770. pinyinList = pinyinList.ConvertAll(p => Regex.Replace(p, @"\d", "").ToLower());
  771. //去重
  772. pinyinList = pinyinList.Where(p => !string.IsNullOrWhiteSpace(p)).Distinct().ToList();
  773. if (pinyinList.Any())
  774. {
  775. totalPingYinList[i] = pinyinList;
  776. }
  777. }
  778. return totalPingYinList;
  779. }
  780. /// <summary>
  781. /// 获取汉语拼音全拼
  782. /// </summary>
  783. /// <param name="text">The string.</param>
  784. /// <returns></returns>
  785. public static List<string> GetTotalPingYin(this string text)
  786. {
  787. var result = new List<string>();
  788. foreach (var pys in GetTotalPingYinDictionary(text))
  789. {
  790. var items = pys.Value;
  791. if (result.Count <= 0)
  792. {
  793. result = items;
  794. }
  795. else
  796. {
  797. //全拼循环匹配
  798. var newTotalPingYinList = new List<string>();
  799. foreach (var totalPingYin in result)
  800. {
  801. newTotalPingYinList.AddRange(items.Select(item => totalPingYin + item));
  802. }
  803. newTotalPingYinList = newTotalPingYinList.Distinct().ToList();
  804. result = newTotalPingYinList;
  805. }
  806. }
  807. return result;
  808. }
  809. /// <summary>
  810. /// 获取汉语拼音首字母
  811. /// </summary>
  812. /// <param name="text"></param>
  813. /// <returns></returns>
  814. public static List<string> GetFirstPingYin(this string text)
  815. {
  816. var result = new List<string>();
  817. foreach (var pys in GetTotalPingYinDictionary(text))
  818. {
  819. var items = pys.Value;
  820. if (result.Count <= 0)
  821. {
  822. result = items.ConvertAll(p => p.Substring(0, 1)).Distinct().ToList();
  823. }
  824. else
  825. {
  826. //首字母循环匹配
  827. var newFirstPingYinList = new List<string>();
  828. foreach (var firstPingYin in result)
  829. {
  830. newFirstPingYinList.AddRange(items.Select(item => firstPingYin + item.Substring(0, 1)));
  831. }
  832. newFirstPingYinList = newFirstPingYinList.Distinct().ToList();
  833. result = newFirstPingYinList;
  834. }
  835. }
  836. return result;
  837. }
  838. #endregion
  839. #region 新客户资料表 操作记录
  840. /// <summary>
  841. /// 新客户资料表
  842. /// 操作记录添加
  843. /// </summary>
  844. /// <param name="portType"></param>
  845. /// <param name="operationEnum"></param>
  846. /// <param name="userId"></param>
  847. /// <param name="dataId"></param>
  848. /// <param name="remark"></param>
  849. /// <returns></returns>
  850. public static async Task<bool> NewClientOperationRecord(int portType, OperationEnum operationEnum, int userId, int dataId, string remark)
  851. {
  852. Crm_TableOperationRecord _TableOperationRecord = new Crm_TableOperationRecord()
  853. {
  854. TableName = "Crm_NewClientData",
  855. PortType = portType,
  856. OperationItem = operationEnum,
  857. DataId = dataId,
  858. CreateUserId = userId,
  859. CreateTime = DateTime.Now,
  860. Remark = remark
  861. };
  862. bool add = await _tableOperationRecordRep._Add(_TableOperationRecord);
  863. if (add) return false;
  864. return false;
  865. }
  866. #endregion
  867. #region 金额转大写
  868. /// <summary>
  869. /// 金额转换为大写数字
  870. /// <para>1、支持的最大数字:999999999999.99(玖仟玖佰玖拾玖亿玖仟玖佰玖拾玖万玖仟玖佰玖拾玖元玖角玖分)</para>
  871. /// <para>2、小数点后最多支持两位</para>
  872. /// </summary>
  873. /// <param name="num">数值</param>
  874. /// <returns></returns>
  875. public static string ConvertCNYUpper(this decimal num)
  876. {
  877. if (num == 0)
  878. {
  879. return "零元";
  880. }
  881. // 解决327000000转换后缺少单位万的问题
  882. return ConvertToChinese(num);
  883. }
  884. #region 实例
  885. /// <summary>
  886. /// 要转换的数字
  887. /// </summary>
  888. private static decimal j;
  889. /// <summary>
  890. ///
  891. /// </summary>
  892. private static string[] NumChineseCharacter = new string[] { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
  893. /// <summary>
  894. /// 判断输入的数字是否大于double类型
  895. /// </summary>
  896. private static bool IsNumber
  897. {
  898. get
  899. {
  900. if (j > decimal.MaxValue || j <= 0)
  901. return false;
  902. else
  903. return true;
  904. }
  905. }
  906. /// <summary>
  907. /// 数字转换成大写汉字主函数
  908. /// </summary>
  909. /// <returns>返回转换后的大写汉字</returns>
  910. public static string ConvertToChinese(decimal m)
  911. {
  912. j = m;
  913. string bb = "";
  914. if (IsNumber)
  915. {
  916. string str = j.ToString();
  917. string[] Num = str.Split('.');
  918. if (Num.Length == 1)
  919. {
  920. bb = NumberString(Num[0]) + "元整";
  921. bb = bb.Replace("零零", "零");
  922. }
  923. else
  924. {
  925. bb = NumberString(Num[0]) + "元";
  926. bb += FloatString(Num[1]);
  927. bb = bb.Replace("零零", "零");
  928. }
  929. }
  930. else
  931. {
  932. throw new FormatException("你输入的数字格式不正确或不是数字!");
  933. }
  934. return bb;
  935. }
  936. /// <summary>
  937. /// 小数位转换只支持两位的小数
  938. /// </summary>
  939. /// <param name="Num">转换的小数</param>
  940. /// <returns>小数转换成汉字</returns>
  941. private static string FloatString(string Num)
  942. {
  943. string cc = "";
  944. if (Num.Length > 2)
  945. {
  946. throw new FormatException("小数位数过多.");
  947. }
  948. else
  949. {
  950. string bb = ConvertString(Num);
  951. int len = bb.IndexOf("零");
  952. if (len != 0)
  953. {
  954. bb = bb.Replace("零", "");
  955. if (bb.Length == 1)
  956. {
  957. cc = bb.Substring(0, 1) + "角";
  958. }
  959. else
  960. {
  961. cc = bb.Substring(0, 1) + "角";
  962. cc += bb.Substring(1, 1) + "分";
  963. }
  964. }
  965. else
  966. cc = bb + "分";
  967. }
  968. return cc;
  969. }
  970. /// <summary>
  971. /// 判断数字位数以进行拆分转换
  972. /// </summary>
  973. /// <param name="Num">要进行拆分的数字</param>
  974. /// <returns>转换成的汉字</returns>
  975. private static string NumberString(string Num)
  976. {
  977. string bb = "";
  978. if (Num.Length <= 4)
  979. {
  980. bb = Convert4(Num);
  981. }
  982. else if (Num.Length > 4 && Num.Length <= 8)
  983. {
  984. bb = Convert4(Num.Substring(0, Num.Length - 4)) + "万";
  985. bb += Convert4(Num.Substring(Num.Length - 4, 4));
  986. }
  987. else if (Num.Length > 8 && Num.Length <= 12)
  988. {
  989. bb = Convert4(Num.Substring(0, Num.Length - 8)) + "亿";
  990. if (Convert4(Num.Substring(Num.Length - 8, 4)) == "")
  991. if (Convert4(Num.Substring(Num.Length - 4, 4)) != "")
  992. bb += "零";
  993. else
  994. bb += "";
  995. else
  996. bb += Convert4(Num.Substring(Num.Length - 8, 4)) + "万";
  997. bb += Convert4(Num.Substring(Num.Length - 4, 4));
  998. }
  999. else
  1000. {
  1001. throw new Exception("整数部分最多支持12位");
  1002. }
  1003. return bb;
  1004. }
  1005. /// <summary>
  1006. /// 四位数字的转换
  1007. /// </summary>
  1008. /// <param name="Num">准备转换的四位数字</param>
  1009. /// <returns>转换以后的汉字</returns>
  1010. private static string Convert4(string Num)
  1011. {
  1012. string bb = "";
  1013. if (Num.Length == 1)
  1014. {
  1015. bb = ConvertString(Num);
  1016. }
  1017. else if (Num.Length == 2)
  1018. {
  1019. bb = ConvertString(Num);
  1020. bb = Convert2(bb);
  1021. }
  1022. else if (Num.Length == 3)
  1023. {
  1024. bb = ConvertString(Num);
  1025. bb = Convert3(bb);
  1026. }
  1027. else
  1028. {
  1029. bb = ConvertString(Num);
  1030. string cc = "";
  1031. string len = bb.Substring(0, 4);
  1032. if (len != "零零零零")
  1033. {
  1034. len = bb.Substring(0, 3);
  1035. if (len != "零零零")
  1036. {
  1037. bb = bb.Replace("零零零", "");
  1038. if (bb.Length == 1)
  1039. {
  1040. bb = bb.Substring(0, 1) + "仟";
  1041. }
  1042. else
  1043. {
  1044. if (bb.Substring(0, 1) != "零" && bb.Substring(0, 2) != "零")
  1045. cc = bb.Substring(0, 1) + "仟";
  1046. else
  1047. cc = bb.Substring(0, 1);
  1048. bb = cc + Convert3(bb.Substring(1, 3));
  1049. }
  1050. }
  1051. else
  1052. {
  1053. bb = bb.Replace("零零零", "零");
  1054. }
  1055. }
  1056. else
  1057. {
  1058. bb = bb.Replace("零零零零", "");
  1059. }
  1060. }
  1061. return bb;
  1062. }
  1063. /// <summary>
  1064. /// 将数字转换成汉字
  1065. /// </summary>
  1066. /// <param name="Num">需要转换的数字</param>
  1067. /// <returns>转换后的汉字</returns>
  1068. private static string ConvertString(string Num)
  1069. {
  1070. string bb = "";
  1071. for (int i = 0; i < Num.Length; i++)
  1072. {
  1073. bb += NumChineseCharacter[int.Parse(Num.Substring(i, 1))];
  1074. }
  1075. return bb;
  1076. }
  1077. /// <summary>
  1078. /// 两位数字的转换
  1079. /// </summary>
  1080. /// <param name="Num">两位数字</param>
  1081. /// <returns>转换后的汉字</returns>
  1082. private static string Convert2(string Num)
  1083. {
  1084. string bb = ""; string cc = "";
  1085. string len = Num.Substring(0, 1);
  1086. if (len != "零")
  1087. {
  1088. bb = Num.Replace("零", "");
  1089. if (bb.Length == 1)
  1090. {
  1091. cc = bb.Substring(0, 1) + "拾";
  1092. }
  1093. else
  1094. {
  1095. cc = bb.Substring(0, 1) + "拾";
  1096. cc += bb.Substring(1, 1);
  1097. }
  1098. }
  1099. else
  1100. cc = Num;
  1101. return cc;
  1102. }
  1103. /// <summary>
  1104. /// 三位数字的转换
  1105. /// </summary>
  1106. /// <param name="Num">三位数字</param>
  1107. /// <returns>转换后的汉字</returns>
  1108. private static string Convert3(string Num)
  1109. {
  1110. string bb = ""; string cc = "";
  1111. string len = Num.Substring(0, 2);
  1112. if (len != "零零")
  1113. {
  1114. bb = Num.Replace("零零", "");
  1115. if (bb.Length == 1)
  1116. {
  1117. bb = bb.Substring(0, 1) + "佰";
  1118. }
  1119. else
  1120. {
  1121. if (bb.Substring(0, 1) != "零")
  1122. cc = bb.Substring(0, 1) + "佰";
  1123. else
  1124. cc = bb.Substring(0, 1);
  1125. bb = cc + Convert2(bb.Substring(1, 2));
  1126. }
  1127. }
  1128. else
  1129. {
  1130. bb = Num.Replace("零零", "零");
  1131. }
  1132. return bb;
  1133. }
  1134. #endregion
  1135. #endregion
  1136. #region 数字验证
  1137. /// <summary>
  1138. /// 验证数字字符串
  1139. /// </summary>
  1140. /// <param name="num"></param>
  1141. /// <returns></returns>
  1142. public static bool IsNumeric(this string numStr)
  1143. {
  1144. bool isNumeric = Regex.IsMatch(numStr, @"^\d+$");
  1145. if (isNumeric)
  1146. {
  1147. return true;
  1148. }
  1149. return false;
  1150. }
  1151. #endregion
  1152. }
  1153. }