GeneralMethod.cs 50 KB

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