GeneralMethod.cs 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304
  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 超支费用 --> 财务部门(ALL)岗位
  497. */
  498. List<Grp_GroupsTaskAssignment> _GroupsTaskAssignments = new List<Grp_GroupsTaskAssignment>();
  499. // 76 酒店预订 --> 国交部门(7) 酒店(25) 岗位
  500. _GroupsTaskAssignments.AddRange(
  501. userDatas
  502. .Where(it => it.DepId == 7 && it.JobPostId == 25)
  503. .Select(it => new Grp_GroupsTaskAssignment()
  504. {
  505. DIId = diId,
  506. CTId = 76,
  507. UId = it.Id,
  508. CreateUserId = userId
  509. }).ToList()
  510. );
  511. // 77 行程 --> 国交部门(7) 经理(32),主管(22) 岗位
  512. _GroupsTaskAssignments.AddRange(
  513. userDatas
  514. .Where(it => it.DepId == 7 && (it.JobPostId == 22 || it.JobPostId == 32))
  515. .Select(it => new Grp_GroupsTaskAssignment()
  516. {
  517. DIId = diId,
  518. CTId = 77,
  519. UId = it.Id,
  520. CreateUserId = userId
  521. }).ToList()
  522. );
  523. //79 车/导游地接 --> 国交部门(7) OP(28) 岗位
  524. _GroupsTaskAssignments.AddRange(
  525. userDatas.Where(it => it.DepId == 7 && it.JobPostId == 28)
  526. .Select(it => new Grp_GroupsTaskAssignment()
  527. {
  528. DIId = diId,
  529. CTId = 79,
  530. UId = it.Id,
  531. CreateUserId = userId
  532. }).ToList()
  533. );
  534. //81 邀请/公务活动 --> 国交部门(7) 商邀(27) 岗位
  535. _GroupsTaskAssignments.AddRange(
  536. userDatas
  537. .Where(it => it.DepId == 7 && it.JobPostId == 27)
  538. .Select(it => new Grp_GroupsTaskAssignment()
  539. {
  540. DIId = diId,
  541. CTId = 81,
  542. UId = it.Id,
  543. CreateUserId = userId
  544. }).ToList()
  545. );
  546. //80 签证 --> 国交部门(7) 签证(26) 岗位
  547. _GroupsTaskAssignments.AddRange(
  548. userDatas
  549. .Where(it => it.DepId == 7 && it.JobPostId == 26)
  550. .Select(it => new Grp_GroupsTaskAssignment()
  551. {
  552. DIId = diId,
  553. CTId = 80,
  554. UId = it.Id,
  555. CreateUserId = userId
  556. }).ToList()
  557. );
  558. //82 团组客户保险 --> 国交部(7) 经理(32),主管(22) 岗位
  559. _GroupsTaskAssignments.AddRange(
  560. userDatas
  561. .Where(it => it.DepId == 7 && (it.JobPostId == 22 || it.JobPostId == 32))
  562. .Select(it => new Grp_GroupsTaskAssignment()
  563. {
  564. DIId = diId,
  565. CTId = 82,
  566. UId = it.Id,
  567. CreateUserId = userId
  568. }).ToList()
  569. );
  570. //85 机票预订 --> 国交部门(7) 机票(24) 岗位
  571. _GroupsTaskAssignments.AddRange(
  572. userDatas
  573. .Where(it => it.DepId == 7 && it.JobPostId == 24)
  574. .Select(it => new Grp_GroupsTaskAssignment()
  575. {
  576. DIId = diId,
  577. CTId = 85,
  578. UId = it.Id,
  579. CreateUserId = userId
  580. }).ToList()
  581. );
  582. //98 其他款项 --> 总经办部门(1) 总经理(1) 岗位/国交部门(7)(ALL) 岗位/财务部门(3)(ALL) 岗位/策划部门(5)(ALL) 岗位/人事部门(4) 采购(74) 岗位
  583. List<int> depIds = new List<int>() { 7,3,5 };
  584. List<int> jobIds = new List<int>() { 1,74};
  585. _GroupsTaskAssignments.AddRange(
  586. userDatas
  587. .Where(it => depIds.Contains(it.DepId) || jobIds.Contains(it.JobPostId))
  588. .Select(it => new Grp_GroupsTaskAssignment()
  589. {
  590. DIId = diId,
  591. CTId = 98,
  592. UId = it.Id,
  593. CreateUserId = userId
  594. }).ToList()
  595. );
  596. //1015 超支费用 --> 财务部门(3)(ALL)岗位
  597. _GroupsTaskAssignments.AddRange(
  598. userDatas
  599. .Where(it => it.DepId == 3)
  600. .Select(it => new Grp_GroupsTaskAssignment()
  601. {
  602. DIId = diId,
  603. CTId = 1015,
  604. UId = it.Id,
  605. CreateUserId = userId
  606. }).ToList()
  607. );
  608. if (_GroupsTaskAssignments.Count > 0)
  609. {
  610. var addId =_teamRateRep._sqlSugar.Insertable(_GroupsTaskAssignments).ExecuteCommand();
  611. }
  612. result.Code = 0;
  613. result.Msg = string.Format(@"操作成功!");
  614. return result;
  615. }
  616. #endregion
  617. #endregion
  618. #region 团组汇率
  619. /// <summary>
  620. /// 团组汇率
  621. /// 获取板块 币种 及 汇率
  622. /// 76 酒店预订 77 行程 79 车/导游地接
  623. /// 80 签证 82 团组客户保险 85 机票预订
  624. /// 98 其他款项 285 收款退还
  625. /// </summary>
  626. /// <param name="teamRateModels"></param>
  627. /// <param name="cTable"></param>
  628. /// <param name="currencyCode"></param>
  629. /// <returns>
  630. /// string
  631. /// eg: CNY 1.0000
  632. /// </returns>
  633. public static async Task<string> PostGroupRateByCTableAndCurrency(List<TeamRateModelView> teamRateModels, int cTable, List<string> currencyCodes)
  634. {
  635. string str = "";
  636. List<string> currencyRates = new List<string>();
  637. TeamRateModelView hotelRateData = teamRateModels.Where(it => it.CTableId == cTable).FirstOrDefault();
  638. if (hotelRateData != null)
  639. {
  640. var hotelRates = hotelRateData.TeamRates;
  641. foreach (var item in currencyCodes)
  642. {
  643. if (!string.IsNullOrEmpty(item))
  644. {
  645. var hotelRateInfo = hotelRates.Where(it => it.CurrencyCode.Equals(item)).FirstOrDefault();
  646. if (hotelRateInfo != null)
  647. {
  648. string str1 = string.Format("{0} {1}\r\n", hotelRateInfo.CurrencyCode, hotelRateInfo.Rate.ToString("#0.0000"));
  649. currencyRates.Add(str1);
  650. }
  651. }
  652. }
  653. if (currencyRates != null || currencyRates.Count > 0)
  654. {
  655. currencyRates = currencyRates.Distinct().ToList();
  656. foreach (var item in currencyRates)
  657. {
  658. str += item;
  659. }
  660. }
  661. }
  662. return str;
  663. }
  664. /// <summary>
  665. /// 团组汇率 币种 Item (来源:团组汇率)
  666. /// 根据 团组Id And 业务类型(CTable)Id
  667. /// api处理CTable = 285,默认返回CNY
  668. /// </summary>
  669. /// <param name="portType"></param>
  670. /// <param name="diId"></param>
  671. /// <param name="cTable"></param>
  672. /// <returns></returns>
  673. public static async Task<TeamRateModelGeneralView> PostGroupTeamRateByDiIdAndCTableId(int portType, int diId, int cTable)
  674. {
  675. TeamRateModelGeneralView _view = new TeamRateModelGeneralView();
  676. _view = await _teamRateRep.PostGroupTeamRateByDiIdAndCTableId(portType, diId, cTable);
  677. return _view;
  678. }
  679. /// <summary>
  680. /// 汇率备注拆分
  681. /// (美元(USD):7.2370|日元(JPY):0.0499|欧元(EUR):8.3000|英镑(GBP):9.1996|港币(HKD):0.9291)
  682. /// </summary>
  683. /// <param name="rateRemark"></param>
  684. /// <returns></returns>
  685. public static async Task<List<TeamRateDescAddCurrencyIdView>> SplitExchangeRate(this string rateRemark)
  686. {
  687. List<TeamRateDescAddCurrencyIdView> _view = new List<TeamRateDescAddCurrencyIdView>();
  688. List<SetDataInfoView> currencyDatas = new List<SetDataInfoView>();
  689. #region 获取所有币种
  690. string sql = string.Format(@"select * from Sys_SetData where STid = {0} and isdel = 0", 66);
  691. var DBdata = _setDataRep.GetListBySqlWithNolock(sql);
  692. if (DBdata == null || DBdata.Count == 0)
  693. {
  694. return _view;
  695. }
  696. currencyDatas = DBdata.Select(x => new SetDataInfoView
  697. {
  698. Name = x.Name,
  699. Id = x.Id,
  700. Remark = x.Remark,
  701. }).ToList();
  702. #endregion
  703. #region 拆分remark里的汇率
  704. if (string.IsNullOrEmpty(rateRemark))
  705. {
  706. return _view;
  707. }
  708. if (rateRemark.Contains("|"))
  709. {
  710. string[] currencyArr = rateRemark.Split("|");
  711. foreach (string currency in currencyArr)
  712. {
  713. string[] currency1 = currency.Split(":");
  714. string[] currency2 = currency1[0].Split("(");
  715. string currencyCode = currency2[1].Replace(")", "").TrimEnd();
  716. TeamRateDescAddCurrencyIdView rateDescView = new TeamRateDescAddCurrencyIdView()
  717. {
  718. CurrencyId = currencyDatas.Find(it => it.Name == currencyCode).Id,
  719. CurrencyCode = currencyCode,
  720. CurrencyName = currency2[0],
  721. Rate = decimal.Parse(currency1[1]),
  722. };
  723. _view.Add(rateDescView);
  724. }
  725. }
  726. else
  727. {
  728. try
  729. {
  730. string[] currency1 = rateRemark.Split(":");
  731. string[] currency2 = currency1[0].Split("(");
  732. string currencyCode = currency2[1].Replace(")", "").TrimEnd();
  733. TeamRateDescAddCurrencyIdView rateDescView = new TeamRateDescAddCurrencyIdView()
  734. {
  735. CurrencyId = currencyDatas.Find(it => it.Name == currencyCode).Id,
  736. CurrencyCode = currencyCode,
  737. CurrencyName = currency2[0],
  738. Rate = decimal.Parse(currency1[1]),
  739. };
  740. _view.Add(rateDescView);
  741. }
  742. catch (Exception)
  743. {
  744. return _view;
  745. }
  746. }
  747. #endregion
  748. return _view;
  749. }
  750. #endregion
  751. #region 汉字转换拼音
  752. private static Dictionary<int, List<string>> GetTotalPingYinDictionary(string text)
  753. {
  754. var chs = text.ToCharArray();
  755. //记录每个汉字的全拼
  756. Dictionary<int, List<string>> totalPingYinList = new Dictionary<int, List<string>>();
  757. for (int i = 0; i < chs.Length; i++)
  758. {
  759. var pinyinList = new List<string>();
  760. //是否是有效的汉字
  761. if (ChineseChar.IsValidChar(chs[i]))
  762. {
  763. ChineseChar cc = new ChineseChar(chs[i]);
  764. pinyinList = cc.Pinyins.Where(p => !string.IsNullOrWhiteSpace(p)).ToList();
  765. }
  766. else
  767. {
  768. pinyinList.Add(chs[i].ToString());
  769. }
  770. //去除声调,转小写
  771. pinyinList = pinyinList.ConvertAll(p => Regex.Replace(p, @"\d", "").ToLower());
  772. //去重
  773. pinyinList = pinyinList.Where(p => !string.IsNullOrWhiteSpace(p)).Distinct().ToList();
  774. if (pinyinList.Any())
  775. {
  776. totalPingYinList[i] = pinyinList;
  777. }
  778. }
  779. return totalPingYinList;
  780. }
  781. /// <summary>
  782. /// 获取汉语拼音全拼
  783. /// </summary>
  784. /// <param name="text">The string.</param>
  785. /// <returns></returns>
  786. public static List<string> GetTotalPingYin(this string text)
  787. {
  788. var result = new List<string>();
  789. foreach (var pys in GetTotalPingYinDictionary(text))
  790. {
  791. var items = pys.Value;
  792. if (result.Count <= 0)
  793. {
  794. result = items;
  795. }
  796. else
  797. {
  798. //全拼循环匹配
  799. var newTotalPingYinList = new List<string>();
  800. foreach (var totalPingYin in result)
  801. {
  802. newTotalPingYinList.AddRange(items.Select(item => totalPingYin + item));
  803. }
  804. newTotalPingYinList = newTotalPingYinList.Distinct().ToList();
  805. result = newTotalPingYinList;
  806. }
  807. }
  808. return result;
  809. }
  810. /// <summary>
  811. /// 获取汉语拼音首字母
  812. /// </summary>
  813. /// <param name="text"></param>
  814. /// <returns></returns>
  815. public static List<string> GetFirstPingYin(this string text)
  816. {
  817. var result = new List<string>();
  818. foreach (var pys in GetTotalPingYinDictionary(text))
  819. {
  820. var items = pys.Value;
  821. if (result.Count <= 0)
  822. {
  823. result = items.ConvertAll(p => p.Substring(0, 1)).Distinct().ToList();
  824. }
  825. else
  826. {
  827. //首字母循环匹配
  828. var newFirstPingYinList = new List<string>();
  829. foreach (var firstPingYin in result)
  830. {
  831. newFirstPingYinList.AddRange(items.Select(item => firstPingYin + item.Substring(0, 1)));
  832. }
  833. newFirstPingYinList = newFirstPingYinList.Distinct().ToList();
  834. result = newFirstPingYinList;
  835. }
  836. }
  837. return result;
  838. }
  839. #endregion
  840. #region 新客户资料表 操作记录
  841. /// <summary>
  842. /// 新客户资料表
  843. /// 操作记录添加
  844. /// </summary>
  845. /// <param name="portType"></param>
  846. /// <param name="operationEnum"></param>
  847. /// <param name="userId"></param>
  848. /// <param name="dataId"></param>
  849. /// <param name="remark"></param>
  850. /// <returns></returns>
  851. public static async Task<bool> NewClientOperationRecord(int portType, OperationEnum operationEnum, int userId, int dataId, string remark)
  852. {
  853. Crm_TableOperationRecord _TableOperationRecord = new Crm_TableOperationRecord()
  854. {
  855. TableName = "Crm_NewClientData",
  856. PortType = portType,
  857. OperationItem = operationEnum,
  858. DataId = dataId,
  859. CreateUserId = userId,
  860. CreateTime = DateTime.Now,
  861. Remark = remark
  862. };
  863. bool add = await _tableOperationRecordRep._Add(_TableOperationRecord);
  864. if (add) return false;
  865. return false;
  866. }
  867. #endregion
  868. #region 金额转大写
  869. /// <summary>
  870. /// 金额转换为大写数字
  871. /// <para>1、支持的最大数字:999999999999.99(玖仟玖佰玖拾玖亿玖仟玖佰玖拾玖万玖仟玖佰玖拾玖元玖角玖分)</para>
  872. /// <para>2、小数点后最多支持两位</para>
  873. /// </summary>
  874. /// <param name="num">数值</param>
  875. /// <returns></returns>
  876. public static string ConvertCNYUpper(this decimal num)
  877. {
  878. if (num == 0)
  879. {
  880. return "零元";
  881. }
  882. // 解决327000000转换后缺少单位万的问题
  883. return ConvertToChinese(num);
  884. }
  885. #region 实例
  886. /// <summary>
  887. /// 要转换的数字
  888. /// </summary>
  889. private static decimal j;
  890. /// <summary>
  891. ///
  892. /// </summary>
  893. private static string[] NumChineseCharacter = new string[] { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
  894. /// <summary>
  895. /// 判断输入的数字是否大于double类型
  896. /// </summary>
  897. private static bool IsNumber
  898. {
  899. get
  900. {
  901. if (j > decimal.MaxValue || j <= 0)
  902. return false;
  903. else
  904. return true;
  905. }
  906. }
  907. /// <summary>
  908. /// 数字转换成大写汉字主函数
  909. /// </summary>
  910. /// <returns>返回转换后的大写汉字</returns>
  911. public static string ConvertToChinese(decimal m)
  912. {
  913. j = m;
  914. string bb = "";
  915. if (IsNumber)
  916. {
  917. string str = j.ToString();
  918. string[] Num = str.Split('.');
  919. if (Num.Length == 1)
  920. {
  921. bb = NumberString(Num[0]) + "元整";
  922. bb = bb.Replace("零零", "零");
  923. }
  924. else
  925. {
  926. bb = NumberString(Num[0]) + "元";
  927. bb += FloatString(Num[1]);
  928. bb = bb.Replace("零零", "零");
  929. }
  930. }
  931. else
  932. {
  933. throw new FormatException("你输入的数字格式不正确或不是数字!");
  934. }
  935. return bb;
  936. }
  937. /// <summary>
  938. /// 小数位转换只支持两位的小数
  939. /// </summary>
  940. /// <param name="Num">转换的小数</param>
  941. /// <returns>小数转换成汉字</returns>
  942. private static string FloatString(string Num)
  943. {
  944. string cc = "";
  945. if (Num.Length > 2)
  946. {
  947. throw new FormatException("小数位数过多.");
  948. }
  949. else
  950. {
  951. string bb = ConvertString(Num);
  952. int len = bb.IndexOf("零");
  953. if (len != 0)
  954. {
  955. bb = bb.Replace("零", "");
  956. if (bb.Length == 1)
  957. {
  958. cc = bb.Substring(0, 1) + "角";
  959. }
  960. else
  961. {
  962. cc = bb.Substring(0, 1) + "角";
  963. cc += bb.Substring(1, 1) + "分";
  964. }
  965. }
  966. else
  967. cc = bb + "分";
  968. }
  969. return cc;
  970. }
  971. /// <summary>
  972. /// 判断数字位数以进行拆分转换
  973. /// </summary>
  974. /// <param name="Num">要进行拆分的数字</param>
  975. /// <returns>转换成的汉字</returns>
  976. private static string NumberString(string Num)
  977. {
  978. string bb = "";
  979. if (Num.Length <= 4)
  980. {
  981. bb = Convert4(Num);
  982. }
  983. else if (Num.Length > 4 && Num.Length <= 8)
  984. {
  985. bb = Convert4(Num.Substring(0, Num.Length - 4)) + "万";
  986. bb += Convert4(Num.Substring(Num.Length - 4, 4));
  987. }
  988. else if (Num.Length > 8 && Num.Length <= 12)
  989. {
  990. bb = Convert4(Num.Substring(0, Num.Length - 8)) + "亿";
  991. if (Convert4(Num.Substring(Num.Length - 8, 4)) == "")
  992. if (Convert4(Num.Substring(Num.Length - 4, 4)) != "")
  993. bb += "零";
  994. else
  995. bb += "";
  996. else
  997. bb += Convert4(Num.Substring(Num.Length - 8, 4)) + "万";
  998. bb += Convert4(Num.Substring(Num.Length - 4, 4));
  999. }
  1000. else
  1001. {
  1002. throw new Exception("整数部分最多支持12位");
  1003. }
  1004. return bb;
  1005. }
  1006. /// <summary>
  1007. /// 四位数字的转换
  1008. /// </summary>
  1009. /// <param name="Num">准备转换的四位数字</param>
  1010. /// <returns>转换以后的汉字</returns>
  1011. private static string Convert4(string Num)
  1012. {
  1013. string bb = "";
  1014. if (Num.Length == 1)
  1015. {
  1016. bb = ConvertString(Num);
  1017. }
  1018. else if (Num.Length == 2)
  1019. {
  1020. bb = ConvertString(Num);
  1021. bb = Convert2(bb);
  1022. }
  1023. else if (Num.Length == 3)
  1024. {
  1025. bb = ConvertString(Num);
  1026. bb = Convert3(bb);
  1027. }
  1028. else
  1029. {
  1030. bb = ConvertString(Num);
  1031. string cc = "";
  1032. string len = bb.Substring(0, 4);
  1033. if (len != "零零零零")
  1034. {
  1035. len = bb.Substring(0, 3);
  1036. if (len != "零零零")
  1037. {
  1038. bb = bb.Replace("零零零", "");
  1039. if (bb.Length == 1)
  1040. {
  1041. bb = bb.Substring(0, 1) + "仟";
  1042. }
  1043. else
  1044. {
  1045. if (bb.Substring(0, 1) != "零" && bb.Substring(0, 2) != "零")
  1046. cc = bb.Substring(0, 1) + "仟";
  1047. else
  1048. cc = bb.Substring(0, 1);
  1049. bb = cc + Convert3(bb.Substring(1, 3));
  1050. }
  1051. }
  1052. else
  1053. {
  1054. bb = bb.Replace("零零零", "零");
  1055. }
  1056. }
  1057. else
  1058. {
  1059. bb = bb.Replace("零零零零", "");
  1060. }
  1061. }
  1062. return bb;
  1063. }
  1064. /// <summary>
  1065. /// 将数字转换成汉字
  1066. /// </summary>
  1067. /// <param name="Num">需要转换的数字</param>
  1068. /// <returns>转换后的汉字</returns>
  1069. private static string ConvertString(string Num)
  1070. {
  1071. string bb = "";
  1072. for (int i = 0; i < Num.Length; i++)
  1073. {
  1074. bb += NumChineseCharacter[int.Parse(Num.Substring(i, 1))];
  1075. }
  1076. return bb;
  1077. }
  1078. /// <summary>
  1079. /// 两位数字的转换
  1080. /// </summary>
  1081. /// <param name="Num">两位数字</param>
  1082. /// <returns>转换后的汉字</returns>
  1083. private static string Convert2(string Num)
  1084. {
  1085. string bb = ""; string cc = "";
  1086. string len = Num.Substring(0, 1);
  1087. if (len != "零")
  1088. {
  1089. bb = Num.Replace("零", "");
  1090. if (bb.Length == 1)
  1091. {
  1092. cc = bb.Substring(0, 1) + "拾";
  1093. }
  1094. else
  1095. {
  1096. cc = bb.Substring(0, 1) + "拾";
  1097. cc += bb.Substring(1, 1);
  1098. }
  1099. }
  1100. else
  1101. cc = Num;
  1102. return cc;
  1103. }
  1104. /// <summary>
  1105. /// 三位数字的转换
  1106. /// </summary>
  1107. /// <param name="Num">三位数字</param>
  1108. /// <returns>转换后的汉字</returns>
  1109. private static string Convert3(string Num)
  1110. {
  1111. string bb = ""; string cc = "";
  1112. string len = Num.Substring(0, 2);
  1113. if (len != "零零")
  1114. {
  1115. bb = Num.Replace("零零", "");
  1116. if (bb.Length == 1)
  1117. {
  1118. bb = bb.Substring(0, 1) + "佰";
  1119. }
  1120. else
  1121. {
  1122. if (bb.Substring(0, 1) != "零")
  1123. cc = bb.Substring(0, 1) + "佰";
  1124. else
  1125. cc = bb.Substring(0, 1);
  1126. bb = cc + Convert2(bb.Substring(1, 2));
  1127. }
  1128. }
  1129. else
  1130. {
  1131. bb = Num.Replace("零零", "零");
  1132. }
  1133. return bb;
  1134. }
  1135. #endregion
  1136. #endregion
  1137. #region 数字验证
  1138. /// <summary>
  1139. /// 验证数字字符串
  1140. /// </summary>
  1141. /// <param name="num"></param>
  1142. /// <returns></returns>
  1143. public static bool IsNumeric(this string numStr)
  1144. {
  1145. bool isNumeric = Regex.IsMatch(numStr, @"^\d+$");
  1146. if (isNumeric)
  1147. {
  1148. return true;
  1149. }
  1150. return false;
  1151. }
  1152. #endregion
  1153. }
  1154. }