GeneralMethod.cs 49 KB

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