DelegationInfoRepository.cs 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510
  1. using AutoMapper;
  2. using OASystem.Domain;
  3. using OASystem.Domain.AesEncryption;
  4. using OASystem.Domain.Dtos.Financial;
  5. using OASystem.Domain.Dtos.Groups;
  6. using OASystem.Domain.Entities.Customer;
  7. using OASystem.Domain.Entities.Groups;
  8. using OASystem.Domain.ViewModels.Groups;
  9. using OASystem.Domain.ViewModels.JuHeExchangeRate;
  10. using OASystem.Infrastructure.Repositories.System;
  11. using OASystem.Infrastructure.Tools;
  12. using System.Diagnostics;
  13. namespace OASystem.Infrastructure.Repositories.Groups
  14. {
  15. /// <summary>
  16. /// 接团信息
  17. /// </summary>
  18. public class DelegationInfoRepository : BaseRepository<Grp_DelegationInfo, DelegationInfoView>
  19. {
  20. private readonly SetDataRepository _setDataRepository;
  21. private readonly UsersRepository _usersRepository;
  22. private readonly TaskAssignmentRepository _taskAssignmentRep;
  23. private readonly IMapper _mapper;
  24. //private readonly TeamRateRepository _teamRateRep;
  25. //public readonly Logs _logs;
  26. public DelegationInfoRepository(SqlSugarClient sqlSugar, SetDataRepository setDataRepository, UsersRepository usersRepository,
  27. TaskAssignmentRepository taskAssignmentRep, IMapper mapper)
  28. : base(sqlSugar)
  29. {
  30. _setDataRepository = setDataRepository;
  31. _usersRepository = usersRepository;
  32. _taskAssignmentRep = taskAssignmentRep;
  33. _mapper = mapper;
  34. //_teamRateRep = teamRateRep;
  35. }
  36. #region 团组信息 团组详情共享Api
  37. /// <summary>
  38. /// 查询团组简略详情列表
  39. /// Page 根据Ctable And User 返回可操作的团
  40. /// </summary>
  41. /// <param name="dto"></param>
  42. /// <returns></returns>
  43. public async Task<JsonView> ListByCTableAndUserId(GroupListByCTableAndUserIdDto dto)
  44. {
  45. var view = new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "操作失败!" };
  46. if (dto.CTable < 1)
  47. {
  48. view.Msg = MsgTips.UserId;
  49. return view;
  50. }
  51. if (dto.CTable < 1)
  52. {
  53. view.Msg = "请输入正确的CTable Id !76 酒店预订<br/>77 行程<br/>79 车/导游地接<br/>80 签证<br/>81 邀请/公务活动<br/>82 团组客户保险<br/>85 机票预订<br/>98 其他款项<br/>751 酒店早餐";
  54. return view;
  55. }
  56. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3)
  57. {
  58. //2025-02-17 更改团组列表排序功能 按照团出访时间排序(降序)
  59. string sql = string.Format(@"Select row_number() over(order by di.VisitStartDate Desc) as Row_Number,
  60. di.Id,di.TeamName,di.TourCode,di.ClientName,di.VisitCountry,di.VisitStartDate,
  61. di.VisitEndDate,di.VisitDays,di.VisitPNumber,di.CreateTime
  62. From Grp_GroupsTaskAssignment gta
  63. Inner Join Grp_DelegationInfo di On gta.DIId = di.Id
  64. Where gta.IsDel = 0 And di.IsDel = 0 And gta.IsEnable = 1
  65. And gta.CTId = {0} And gta.UId = {1}", dto.CTable, dto.UserId);
  66. if (!string.IsNullOrEmpty(dto.TeamName))
  67. {
  68. sql = string.Format($"{sql} And di.TeamName Like '%{dto.TeamName}%'");
  69. }
  70. //去重
  71. sql = $"{sql} GROUP BY di.Id,di.TeamName,di.TourCode,di.ClientName,di.VisitCountry,di.VisitStartDate,di.VisitEndDate,di.VisitDays,di.VisitPNumber,di.CreateTime";
  72. RefAsync<int> total = 0;//REF和OUT不支持异步,想要真的异步这是最优解
  73. var data = await _sqlSugar.SqlQueryable<GroupListByCTableAndUserIdView>(sql).ToPageListAsync(dto.PageIndex, dto.PageSize, total); //ToPageAsync
  74. foreach (var item in data)
  75. {
  76. item.VisitStartDate = item.VisitStartDate == "" ? "" : Convert.ToDateTime(item.VisitStartDate).ToString("yyyy-MM-dd");
  77. item.VisitEndDate = item.VisitEndDate == "" ? "" : Convert.ToDateTime(item.VisitEndDate).ToString("yyyy-MM-dd");
  78. item.VisitCountry = !string.IsNullOrEmpty(item.VisitCountry) && item.VisitCountry.Contains("|") ? item.VisitCountry.Replace("|", "、") : item.VisitCountry;
  79. }
  80. view.Code = StatusCodes.Status200OK;
  81. view.Msg = "操作成功!";
  82. view.Data = data;
  83. view.Count = total;
  84. return view;
  85. }
  86. else
  87. {
  88. view.Msg = "请输入正确的PortType 1 Web 2 Android 3 IOS ";
  89. return view;
  90. }
  91. }
  92. /// <summary>
  93. /// 团组信息 团组预览详情共享Api
  94. /// </summary>
  95. /// <param name="dto"></param>
  96. /// <returns></returns>
  97. public async Task<JsonView> PostShareGroupInfo(ShareGroupInfoDto dto)
  98. {
  99. var view = new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "操作失败!" };
  100. string sql = string.Format(@"Select Id,TeamName,TourCode,ClientName,VisitCountry,VisitStartDate,VisitEndDate,VisitDays,VisitPNumber
  101. From Grp_DelegationInfo Where Id = {0} And IsDel = 0", dto.Id);
  102. if (dto.PortType == 1) //Web
  103. {
  104. var _DelegationInfo = await _sqlSugar.SqlQueryable<Web_ShareGroupInfoView>(sql).FirstAsync();
  105. if (_DelegationInfo != null)
  106. {
  107. _DelegationInfo.VisitCountry = FormartTeamName(_DelegationInfo.VisitCountry);
  108. }
  109. else
  110. {
  111. view.Msg = "暂无该团组信息";
  112. return view;
  113. }
  114. view.Data = _DelegationInfo;
  115. }
  116. else if (dto.PortType == 2 || dto.PortType == 3) //IOS Or Android
  117. {
  118. var _DelegationInfo = await _sqlSugar.SqlQueryable<IOSOrAndroid_ShareGroupInfoView>(sql).FirstAsync();
  119. if (_DelegationInfo != null)
  120. {
  121. _DelegationInfo.VisitCountry = FormartTeamName(_DelegationInfo.VisitCountry);
  122. view.Data = _DelegationInfo;
  123. }
  124. else
  125. {
  126. view.Msg = "暂无该团组信息";
  127. return view;
  128. }
  129. view.Data = _DelegationInfo;
  130. }
  131. else
  132. {
  133. view.Msg = "请输入正确的端口号。1 Web 2 Android 3 IOS";
  134. return view;
  135. }
  136. view.Code = StatusCodes.Status200OK;
  137. view.Msg = "成功!";
  138. return view;
  139. }
  140. /// <summary>
  141. /// 团组信息List 团组预览详情共享Api
  142. /// </summary>
  143. /// <param name="dto"></param>
  144. /// <returns></returns>
  145. public async Task<Result> PostShareGroupInfos(int portType)
  146. {
  147. var result = new Result() { Code = -2, Msg = "未知错误", Data = new List<object>() { } };
  148. string sql = string.Format(@"Select Id,TeamName,TourCode,ClientName,VisitCountry,VisitStartDate,VisitEndDate,VisitDays,VisitPNumber
  149. From Grp_DelegationInfo With(NoLock) Where IsDel = 0 Order By VisitStartDate Desc");
  150. var _DelegationInfo = await _sqlSugar.SqlQueryable<Web_ShareGroupInfoView>(sql).ToListAsync();
  151. if (_DelegationInfo.Count > 0)
  152. {
  153. foreach (var item in _DelegationInfo)
  154. {
  155. item.VisitCountry = FormartTeamName(item.VisitCountry);
  156. }
  157. }
  158. else { result.Msg = "暂无该团组信息"; return result; }
  159. if (portType == 1) //Web
  160. {
  161. result.Data = _DelegationInfo;
  162. }
  163. else if (portType == 2 || portType == 3) //IOS Or Android
  164. {
  165. result.Data = _DelegationInfo;
  166. }
  167. else { result.Msg = "请输入正确的端口号。1 Web 2 Android 3 IOS"; return result; }
  168. result.Code = 0;
  169. result.Msg = "成功!";
  170. return result;
  171. }
  172. #endregion
  173. /// <summary>
  174. /// 获取接团信息Info
  175. /// </summary>
  176. /// <param name="dto"></param>
  177. /// <returns></returns>
  178. public async Task<Result> PostGroupInfo(GroupInfoDto dto)
  179. {
  180. var result = new Result() { Code = -2, Msg = "未知错误" };
  181. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //Web Or Android
  182. {
  183. string sql = string.Format(@"Select Id,SalesQuoteNo,TourCode,JietuanOperator,TeamLevSId,TeamDid,TeamName,ClientName,
  184. ClientUnit,VisitCountry,VisitDate,VisitDays,VisitPNumber,TontractTime,
  185. PayDay,PaymentMoney,VisitPurpose,SpecialNeeds,OtherNeeds,CGRWSPBMMC,CGRWSPWH,
  186. ZZSCBMMC,ZZSCSPWH,Remark,TellPhone,Officialneeds
  187. From Grp_DelegationInfo Where Id = {0} And IsDel = 0", dto.Id);
  188. var _DelegationInfo = await _sqlSugar.SqlQueryable<DelegationInfoWebView>(sql).FirstAsync();
  189. if (_DelegationInfo != null)
  190. {
  191. _DelegationInfo.TeamName = FormartTeamName(_DelegationInfo.TeamName);
  192. result.Code = 0;
  193. result.Msg = "成功!";
  194. result.Data = _DelegationInfo;
  195. }
  196. else result.Msg = "暂无该团组信息";
  197. }
  198. return result;
  199. }
  200. #region 团组
  201. /// <summary>
  202. /// 统一团组国家分割字符
  203. /// </summary>
  204. /// <param name="teamName"></param>
  205. /// <returns></returns>
  206. public string FormartTeamName(string? teamName)
  207. {
  208. string str = "";
  209. if (!string.IsNullOrEmpty(teamName))
  210. {
  211. str = teamName;
  212. var searchreplaces = new List<string>() { "|", " ", "/", ",", "," };
  213. foreach (var item in searchreplaces)
  214. {
  215. if (str.Contains(item))
  216. {
  217. str = str.Replace(item, "、");
  218. break;
  219. }
  220. }
  221. }
  222. return str.Trim();
  223. }
  224. /// <summary>
  225. /// 团组国家分割字符
  226. /// 返回 国家数组
  227. /// </summary>
  228. /// <param name="countryString"></param>
  229. /// <returns></returns>
  230. public List<string> GroupSplitCountry(string countryString)
  231. {
  232. if (string.IsNullOrWhiteSpace(countryString))
  233. return new List<string>();
  234. // 预先定义分隔符
  235. var separators = new[]
  236. {
  237. ' ', '\t', '\n', '\r', // 空白字符
  238. '、', '|', ',', ',', ';', ';', '/', '\\', // 分隔符
  239. '(', ')', '[', ']', '{', '}', '<', '>', // 括号
  240. '【', '】', '(', ')', '《', '》', // 中文括号
  241. '\'', '"', '`', // 引号
  242. '-', '_', '+', '=', '~', '!', '@', '#', '$', '%', '^', '&', '*',
  243. '·', '。', '?', '!', ':', ';', ',', '、', '~', '—', // 中文标点
  244. '€', '£', '¥', '¢' // 货币符号
  245. };
  246. return countryString.Trim()
  247. .Split(separators, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
  248. .Distinct() // 去重
  249. .ToList();
  250. }
  251. /// <summary>
  252. /// 获取接团信息 Page List
  253. /// </summary>
  254. /// <param name="dto"></param>
  255. /// <returns></returns>
  256. public async Task<Result> GetGroupPageList(GroupCommissionDto dto)
  257. {
  258. var result = new Result() { Code = -2, Msg = "未知错误" };
  259. var groupsInfoPageList = new ListViewBase<DelegationPageListView>()
  260. {
  261. ReceiveDt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  262. };
  263. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  264. {
  265. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  266. int endIndex = startIndex + dto.PageSize - 1;
  267. //int taskUserId = -1;
  268. string taskGroupIds = string.Empty;
  269. #region 处理用户团组操作权限
  270. if (dto.UserId != -1)
  271. {
  272. }
  273. #endregion
  274. string sql = string.Format(@"Select * From(Select row_number() over (order by gdi.Id Desc) as RowNumber,
  275. gdi.Id,SalesQuoteNo,TourCode,ssd.Id TeamTypeId, ssd.Name TeamType,ssd1.Id TeamLevId,
  276. ssd1.Name TeamLev,TeamName,ClientName,ClientUnit,VisitDate,VisitDays,VisitPNumber,
  277. su.CnName JietuanOperator,IsSure
  278. From Grp_DelegationInfo gdi
  279. Inner Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  280. Inner Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  281. Left Join Sys_Users su On gdi.CreateUserId = su.Id
  282. Where gdi.IsDel = 0
  283. )temp Where RowNumber Between {0} and {1}", startIndex, endIndex);
  284. string sqlCount = string.Format(@"Select Count(1) as Count From Grp_DelegationInfo gdi
  285. Inner Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  286. Inner Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  287. Left Join Sys_Users su On gdi.CreateUserId = su.Id
  288. Where gdi.IsDel = 0 ");
  289. List<DelegationPageListView> _DeleInfoList = await _sqlSugar.SqlQueryable<DelegationPageListView>(sql).ToListAsync();
  290. DelegationPageCountView _DeleCount = await _sqlSugar.SqlQueryable<DelegationPageCountView>(sqlCount).FirstAsync();
  291. int count = _DeleCount.Count;
  292. groupsInfoPageList = new ListViewBase<DelegationPageListView>
  293. {
  294. CurrPageIndex = dto.PageIndex,
  295. CurrPageSize = dto.PageSize,
  296. DataCount = count,
  297. DataList = _DeleInfoList
  298. };
  299. result.Code = 0;
  300. result.Msg = "成功!";
  301. result.Data = groupsInfoPageList;
  302. }
  303. return result;
  304. }
  305. /// <summary>
  306. /// 获取接团信息List
  307. /// </summary>
  308. /// <param name="dto"></param>
  309. /// <returns></returns>
  310. public async Task<Result> GetGroupList(GroupListDto dto)
  311. {
  312. var result = new Result() { Code = -2, Msg = "未知错误" };
  313. if (dto.PortType == 1)
  314. {
  315. string sql = string.Format(@"Select gdi.Id,SalesQuoteNo,TourCode,ssd.Id TeamTypeId, ssd.Name TeamType,ssd1.Id TeamLevId,ssd1.Name TeamLev,TeamName,ClientName,ClientUnit,VisitDate,VisitDays,VisitPNumber,su.CnName JietuanOperator,IsSure
  316. ,gs.Id as GrpScheduleId
  317. From Grp_DelegationInfo gdi
  318. Inner Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  319. Inner Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  320. Left Join Sys_Users su On gdi.CreateUserId = su.Id
  321. left Join Grp_Schedule gs On gdi.Id = gs.DiId
  322. Where gdi.IsDel = 0
  323. Order By gdi.CreateTime Desc");
  324. var _DelegationList = await _sqlSugar.SqlQueryable<DelegationListView>(sql).ToListAsync();
  325. if (_DelegationList.Count > 0)
  326. {
  327. result.Code = 0;
  328. result.Msg = "成功!";
  329. result.Data = _DelegationList;
  330. }
  331. else
  332. {
  333. result.Msg = "暂无该团组信息";
  334. }
  335. }
  336. else if (dto.PortType == 2 || dto.PortType == 3) //web
  337. {
  338. string sql = string.Format(@"Select gdi.Id,SalesQuoteNo,TourCode,ssd.Id TeamTypeId, ssd.Name TeamType,ssd1.Id TeamLevId,ssd1.Name TeamLev,TeamName,ClientName,ClientUnit,VisitDate,VisitDays,VisitPNumber,su.CnName JietuanOperator,IsSure
  339. From Grp_DelegationInfo gdi
  340. Inner Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  341. Inner Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  342. Left Join Sys_Users su On gdi.CreateUserId = su.Id
  343. Where gdi.IsDel = 0
  344. Order By gdi.CreateTime Desc");
  345. var _DelegationList = await _sqlSugar.SqlQueryable<DelegationListView>(sql).ToListAsync();
  346. if (_DelegationList.Count > 0)
  347. {
  348. result.Code = 0;
  349. result.Msg = "成功!";
  350. result.Data = _DelegationList;
  351. }
  352. else
  353. {
  354. result.Msg = "暂无该团组信息";
  355. }
  356. }
  357. return result;
  358. }
  359. /// <summary>
  360. /// 获取接团信息Info
  361. /// </summary>
  362. /// <param name="dto"></param>
  363. /// <returns></returns>
  364. public async Task<Result> GetGroupInfo(GroupInfoDto dto)
  365. {
  366. var result = new Result() { Code = -2, Msg = "未知错误" };
  367. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //Web Or Android
  368. {
  369. string sql = string.Format(@"Select Id,CityId,SalesQuoteNo,TourCode,JietuanOperator,TeamLevSId,TeamDid,TeamName,ClientName,
  370. ClientUnit,VisitCountry,VisitDate,VisitDays,VisitPNumber,TontractTime,IsBid,
  371. PayDay,PaymentMoney,VisitPurpose,SpecialNeeds,OtherNeeds,CGRWSPBMMC,CGRWSPWH,
  372. ZZSCBMMC,ZZSCSPWH,Remark,TellPhone,WeChatNo,OpRoyaltyLv,OpRoyaltyRemark,Officialneeds,
  373. ExtOverLimit,ExtOverCurrency
  374. From Grp_DelegationInfo Where Id = {0} And IsDel = 0", dto.Id);
  375. var _DelegationInfo = await _sqlSugar.SqlQueryable<DelegationInfoWebView>(sql).FirstAsync();
  376. if (_DelegationInfo != null)
  377. {
  378. _DelegationInfo.TeamName = FormartTeamName(_DelegationInfo.TeamName);
  379. _DelegationInfo.VisitCountry = FormartTeamName(_DelegationInfo.VisitCountry);
  380. //验证城市值 不存在则设置默认值
  381. var cityInfo = await CityInfoById(_DelegationInfo.CityId);
  382. if (cityInfo != null)
  383. {
  384. _DelegationInfo.CityName = cityInfo.Name;
  385. }
  386. //else
  387. //{
  388. // _DelegationInfo.CityId = 3505;
  389. // _DelegationInfo.CityName = "四川-成都";
  390. //}
  391. //if (_DelegationInfo.TontractTime)
  392. //{
  393. //}
  394. result.Code = 0;
  395. result.Msg = "成功!";
  396. result.Data = _DelegationInfo;
  397. if (dto.PortType == 2)
  398. {
  399. var GroupProcessOperationDtoParam = new GroupProcessOperationDto();
  400. GroupProcessOperationDtoParam = _mapper.Map<DelegationInfoWebView, GroupProcessOperationDto>(_DelegationInfo);
  401. List<Crm_DeleClient> DeleClientArr = await _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0).ToListAsync(); //客户信息
  402. List<Grp_TourClientList> _DeleClients = await _sqlSugar.Queryable<Grp_TourClientList>().Where(it => it.IsDel == 0 && it.DiId == dto.Id).ToListAsync(); // 接团客户名单
  403. List<Crm_CustomerCert> _CustomerCerts = await _sqlSugar.Queryable<Crm_CustomerCert>().Where(it => it.IsDel == 0 && it.SdId == 773).ToListAsync(); // 身份证类型证件信息
  404. List<Crm_CustomerCompany> CompanyArr = await _sqlSugar.Queryable<Crm_CustomerCompany>().Where(it => it.IsDel == 0).ToListAsync();
  405. var TourClientListInfoArr = new List<TourClientListProcessInfo>();
  406. var timeParam = new DateTime();
  407. foreach (var item in _DeleClients)
  408. {
  409. var param = new TourClientListProcessInfo();
  410. var clientInfo = DeleClientArr.FirstOrDefault(x => x.Id == item.ClientId);
  411. clientInfo ??= new Crm_DeleClient();
  412. var clientIDInfo = _CustomerCerts.FirstOrDefault(x => x.DcId == item.ClientId); //身份证信息
  413. clientIDInfo ??= new Crm_CustomerCert();
  414. var Company = CompanyArr.FirstOrDefault(x => x.Id == clientInfo.CrmCompanyId);
  415. Company ??= new Crm_CustomerCompany();
  416. param.IDCardNo = clientIDInfo.CertNo;
  417. param.Remark = item.Remark;
  418. param.BirthDay = clientInfo.BirthDay == null ? "" : DateTime.TryParse(Convert.ToDateTime(clientInfo.BirthDay).ToString("yyyy-MM-dd"), out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  419. param.FirstName = clientInfo.FirstName;
  420. param.LastName = clientInfo.LastName;
  421. param.CompanyFullName = Company.CompanyFullName;
  422. param.Job = clientInfo.Job;
  423. param.Sex = clientInfo.Sex;
  424. param.Phone = clientInfo.Phone;
  425. param.Pinyin = clientInfo.Pinyin;
  426. param.HotelSpecialNeeds = item.HotelSpecialNeeds;
  427. param.MealSpecialNeeds = item.MealSpecialNeeds;
  428. param.ShippingSpaceSpecialNeeds = item.ShippingSpaceSpecialNeeds;
  429. param.ShippingSpaceTypeId = item.ShippingSpaceTypeId;
  430. param.Id = clientInfo.Id;
  431. EncryptionProcessor.DecryptProperties(param);
  432. TourClientListInfoArr.Add(param);
  433. }
  434. GroupProcessOperationDtoParam.PortType = dto.PortType;
  435. GroupProcessOperationDtoParam.TourClientListInfos = TourClientListInfoArr;
  436. GroupProcessOperationDtoParam.VisitDate = DateTime.TryParse(GroupProcessOperationDtoParam.VisitDate, out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  437. GroupProcessOperationDtoParam.VisitDate = DateTime.TryParse(GroupProcessOperationDtoParam.VisitDate, out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  438. GroupProcessOperationDtoParam.TontractTime = DateTime.TryParse(GroupProcessOperationDtoParam.TontractTime, out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  439. result.Data = GroupProcessOperationDtoParam;
  440. }
  441. else if (dto.PortType == 3)
  442. {
  443. var GroupProcessOperationDtoParam = new GroupProcessOperationDto();
  444. GroupProcessOperationDtoParam = _mapper.Map<DelegationInfoWebView, GroupProcessOperationDto>(_DelegationInfo);
  445. List<Crm_DeleClient> DeleClientArr = await _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0).ToListAsync(); //客户信息
  446. List<Grp_TourClientList> _DeleClients = await _sqlSugar.Queryable<Grp_TourClientList>().Where(it => it.IsDel == 0 && it.DiId == dto.Id).ToListAsync(); // 接团客户名单
  447. List<Crm_CustomerCert> _CustomerCerts = await _sqlSugar.Queryable<Crm_CustomerCert>().Where(it => it.IsDel == 0 && it.SdId == 773).ToListAsync(); // 身份证类型证件信息
  448. List<Crm_CustomerCompany> CompanyArr = await _sqlSugar.Queryable<Crm_CustomerCompany>().Where(it => it.IsDel == 0).ToListAsync();
  449. var TourClientListInfoArr = new List<TourClientListProcessInfo>();
  450. var timeParam = new DateTime();
  451. foreach (var item in _DeleClients)
  452. {
  453. var param = new TourClientListProcessInfo();
  454. var clientInfo = DeleClientArr.FirstOrDefault(x => x.Id == item.ClientId);
  455. clientInfo ??= new Crm_DeleClient();
  456. var clientIDInfo = _CustomerCerts.FirstOrDefault(x => x.DcId == item.ClientId); //身份证信息
  457. clientIDInfo ??= new Crm_CustomerCert();
  458. var Company = CompanyArr.FirstOrDefault(x => x.Id == clientInfo.CrmCompanyId);
  459. Company ??= new Crm_CustomerCompany();
  460. param.IDCardNo = clientIDInfo.CertNo;
  461. param.Remark = item.Remark;
  462. param.BirthDay = clientInfo.BirthDay == null ? "" : DateTime.TryParse(Convert.ToDateTime(clientInfo.BirthDay).ToString("yyyy-MM-dd"), out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  463. param.FirstName = clientInfo.FirstName;
  464. param.LastName = clientInfo.LastName;
  465. param.CompanyFullName = Company.CompanyFullName;
  466. param.Job = clientInfo.Job;
  467. param.Sex = clientInfo.Sex;
  468. param.Phone = clientInfo.Phone;
  469. param.Pinyin = clientInfo.Pinyin;
  470. param.HotelSpecialNeeds = item.HotelSpecialNeeds;
  471. param.MealSpecialNeeds = item.MealSpecialNeeds;
  472. param.ShippingSpaceSpecialNeeds = item.ShippingSpaceSpecialNeeds;
  473. param.ShippingSpaceTypeId = item.ShippingSpaceTypeId;
  474. param.Id = item.Id;
  475. EncryptionProcessor.DecryptProperties(param);
  476. TourClientListInfoArr.Add(param);
  477. }
  478. GroupProcessOperationDtoParam.PortType = dto.PortType;
  479. GroupProcessOperationDtoParam.TourClientListInfos = TourClientListInfoArr;
  480. GroupProcessOperationDtoParam.VisitDate = DateTime.TryParse(GroupProcessOperationDtoParam.VisitDate, out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  481. GroupProcessOperationDtoParam.TontractTime = DateTime.TryParse(GroupProcessOperationDtoParam.TontractTime, out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  482. result.Data = GroupProcessOperationDtoParam;
  483. }
  484. }
  485. else result.Msg = "暂无该团组信息";
  486. }
  487. return result;
  488. }
  489. /// <summary>
  490. /// 获取接团信息 编辑
  491. /// 城市基础 数据源
  492. /// </summary>
  493. /// <param name="dto"></param>
  494. /// <returns></returns>
  495. public async Task<List<CityTree>> ProvinceCityBasicSource()
  496. {
  497. var data = await _sqlSugar.Queryable<CityTree>().AS("Sys_Cities")
  498. .Where(x => x.IsDel == 0 && x.CountriesId == 44)
  499. .ToTreeAsync(it => it.Child, it => it.ParentId, 0);
  500. if (data.Any())
  501. {
  502. //移动指定数据在最前面
  503. data = MoveElementToFront(data, "云南");
  504. data = MoveElementToFront(data, "贵州");
  505. data = MoveElementToFront(data, "重庆");
  506. data = MoveElementToFront(data, "四川");
  507. }
  508. return data;
  509. }
  510. /// <summary>
  511. /// 获取接团信息 编辑
  512. /// 省份基础 数据源
  513. /// </summary>
  514. /// <param name="dto"></param>
  515. /// <returns></returns>
  516. public async Task<GroupCityBasicSourceView[]> ProvinceBasicSource()
  517. {
  518. var list = Array.Empty<GroupCityBasicSourceView>();
  519. var data = await ProvinceCityBasicSource();
  520. if (data.Any())
  521. {
  522. //移动指定数据在最前面
  523. data = MoveElementToFront(data, "北京");
  524. data = MoveElementToFront(data, "云南");
  525. data = MoveElementToFront(data, "贵州");
  526. data = MoveElementToFront(data, "重庆");
  527. data = MoveElementToFront(data, "四川");
  528. list = data.Select(x => new GroupCityBasicSourceView() { Id = x.Id, Name = x.Name_CN }).ToArray();
  529. }
  530. return list;
  531. }
  532. /// <summary>
  533. /// 获取接团信息 编辑
  534. /// 城市基础 数据源
  535. /// </summary>
  536. /// <param name="dto"></param>
  537. /// <returns></returns>
  538. public async Task<GroupCityBasicSourceView[]> CityBasicSource()
  539. {
  540. var list = new List<GroupCityBasicSourceView>();
  541. var data = await ProvinceCityBasicSource();
  542. if (data.Any())
  543. {
  544. //移动指定数据在最前面
  545. data = MoveElementToFront(data, "云南");
  546. data = MoveElementToFront(data, "贵州");
  547. data = MoveElementToFront(data, "重庆");
  548. data = MoveElementToFront(data, "四川");
  549. foreach (var province in data)
  550. {
  551. foreach (var city in province.Child)
  552. {
  553. list.Add(new GroupCityBasicSourceView()
  554. {
  555. Id = city.Id,
  556. Name = $"{province.Name_CN}-{city.Name_CN}"
  557. });
  558. }
  559. }
  560. //四川成都放在最前面
  561. var cdInfo = list.FirstOrDefault(x => x.Name.Equals("四川-成都"));
  562. if (cdInfo != null)
  563. {
  564. list.Remove(cdInfo);
  565. list.Insert(0, cdInfo);
  566. }
  567. }
  568. return list.ToArray();
  569. }
  570. /// <summary>
  571. /// 获取接团信息 编辑
  572. /// 基础 数据源
  573. /// </summary>
  574. /// <param name="dto"></param>
  575. /// <returns></returns>
  576. public async Task<GroupCityBasicSourceView> CityInfoById(int id)
  577. {
  578. var list = await CityBasicSource();
  579. var info = list.FirstOrDefault(x => x.Id == id);
  580. return info;
  581. }
  582. private static List<CityTree> MoveElementToFront(List<CityTree> list, string elementName)
  583. {
  584. var element = list.FirstOrDefault(x => x.Name_CN == elementName);
  585. if (element != null)
  586. {
  587. list.Remove(element);
  588. list.Insert(0, element);
  589. }
  590. return list;
  591. }
  592. /// <summary>
  593. /// 获取接团信息 编辑
  594. /// 基础 数据源
  595. /// </summary>
  596. /// <param name="dto"></param>
  597. /// <returns></returns>
  598. public async Task<Result> GroupEditBasicSource(GroupListDto dto)
  599. {
  600. var result = new Result() { Code = -2, Msg = "未知错误" };
  601. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  602. {
  603. dynamic? teamTypeData1 = null;
  604. string teamTypeSql = string.Format(@"Select Id,Name From Sys_SetData Where STid = {0} And IsDel = {1}", 10, 0);
  605. var teamTypeData = await _sqlSugar.SqlQueryable<SetDataInfoView>(teamTypeSql).ToListAsync(); ; //团组分类 10
  606. if (teamTypeData.Any())
  607. {
  608. teamTypeData1 = teamTypeData;
  609. if (teamTypeData.Any(x => x.Name.Equals("前期沟通")))
  610. {
  611. var info = teamTypeData.Find(x => x.Name.Equals("前期沟通"));
  612. if (info != null)
  613. {
  614. teamTypeData.Remove(info);
  615. teamTypeData.Insert(2, info);
  616. }
  617. }
  618. }
  619. dynamic? teamLevData1 = null;
  620. string teamLevSql = string.Format(@"Select Id,Name From Sys_SetData Where STid = {0} And IsDel = {1}", 56, 0);
  621. var teamLevData = await _sqlSugar.SqlQueryable<SetDataInfoView>(teamLevSql).ToListAsync(); ; //团组等级 56
  622. if (teamLevData.Any())
  623. {
  624. teamLevData1 = teamLevData;
  625. }
  626. dynamic? userData1 = null;
  627. string userSql = string.Format(@"Select Id,CnName From Sys_Users Where IsDel = {0}", 0);
  628. var userData = await _sqlSugar.SqlQueryable<UserNameView>(userSql).ToListAsync();
  629. if (userData.Any())
  630. {
  631. userData1 = userData;
  632. }
  633. //客户单位数据源 来源市场客户资料
  634. dynamic? clientData1 = null;
  635. string clientSql = $@"Select Client,Contact,Telephone,WeChat From Crm_NewClientData Where IsDel = 0";
  636. var clientData = await _sqlSugar.SqlQueryable<Crm_NewClientData>(clientSql).ToListAsync();
  637. if (clientData.Any())
  638. {
  639. clientData1 = clientData.Select(it => new
  640. {
  641. Client = AesEncryptionHelper.Decrypt(it.Client),
  642. Contact = AesEncryptionHelper.Decrypt(it.Contact),
  643. Telephone = AesEncryptionHelper.Decrypt(it.Telephone),
  644. Wechat = AesEncryptionHelper.Decrypt(it.Wechat)
  645. }).ToList();
  646. }
  647. var userDepDatas = new List<TextView>();
  648. userDepDatas.Insert(0, new TextView() { Text = "全部", Value = "全部" });
  649. userDepDatas.Insert(1, new TextView() { Text = "国交部", Value = "国交部" });
  650. userDepDatas.Insert(2, new TextView() { Text = "市场部", Value = "市场部" });
  651. userDepDatas.Insert(3, new TextView() { Text = "策划部", Value = "策划部" });
  652. var rankDatas = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 56).Select(x => new TextView { Value = x.Id.ToString(), Text = x.Name }).ToListAsync();
  653. rankDatas.Insert(0, new TextView { Value = "0", Text = "全部" });
  654. //币种信息
  655. var currencyDatas = await _sqlSugar.Queryable<Sys_SetData>()
  656. .Where(x => x.IsDel == 0 && x.STid == 66)
  657. .Select(x => new { x.Id,x.Name })
  658. .ToListAsync();
  659. var sortedList = currencyDatas
  660. .OrderBy(x => x.Name == "CNY" ? 0 : 1)
  661. .ThenBy(x => x.Name)
  662. .ToList();
  663. result.Code = 0;
  664. result.Msg = "成功!";
  665. result.Data = new
  666. {
  667. teamTypeData = teamTypeData1,
  668. teamLevData = teamLevData1,
  669. userData = userData1,
  670. clientData = clientData1,
  671. depData = userDepDatas,
  672. rankData = rankDatas,
  673. cityData = await CityBasicSource(),
  674. currencyData = sortedList
  675. };
  676. }
  677. return result;
  678. }
  679. /// <summary>
  680. /// 团组信息操作
  681. /// </summary>
  682. /// <param name="dto"></param>
  683. /// <returns></returns>
  684. public async Task<Result> GroupOperation(GroupOperationDto dto)
  685. {
  686. var result = new Result() { Code = -2, Msg = "未知错误" };
  687. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  688. {
  689. #region 添加出访起止时间
  690. var startTime = new DateTime();
  691. var endTime = new DateTime();
  692. if (DateTime.TryParse(dto.VisitDate, out startTime))
  693. {
  694. endTime = startTime.AddDays(dto.VisitDays - 1);//含当天
  695. }
  696. #endregion
  697. if (dto.Status == 1) //添加
  698. {
  699. string selectSql = string.Format(@"Select * From Grp_DelegationInfo
  700. Where IsDel = 0
  701. And TeamName = '{0}'
  702. And ClientName = '{1}'
  703. And ClientUnit ='{2}'
  704. And VisitDate ='{3}'", dto.TeamName, dto.ClientName, dto.ClientUnit, dto.VisitDate);
  705. var selectGroupInfo = _sqlSugar.SqlQueryable<Grp_DelegationInfo>(selectSql).First();
  706. if (selectGroupInfo != null)
  707. {
  708. result.Msg = "数据已存在,请勿重复添加!";
  709. return result;
  710. }
  711. //string teamCodeSql = string.Format("Select SalesQuoteNo From Grp_DelegationInfo");
  712. //var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  713. //string SalesQuoteNo = "";
  714. //while (true)
  715. //{
  716. // SalesQuoteNo = Tools.CommonFun.GetRandomStr(6);
  717. // if (!teamCodeItem.Equals(SalesQuoteNo))
  718. // {
  719. // break;
  720. // }
  721. //}
  722. string countrys = string.Empty;
  723. string countryReq = dto.VisitCountry;
  724. if (!string.IsNullOrEmpty(countryReq))
  725. {
  726. if (countryReq.Contains(",")) countrys = countryReq.Replace(',', '|');
  727. else if (countryReq.Contains(",")) countrys = countryReq.Replace(',', '|');
  728. else if (countryReq.Contains(" ")) countrys = countryReq.Replace(' ', '|');
  729. else if (countryReq.Contains("、")) countrys = countryReq.Replace('、', '|');
  730. else if (countryReq.Contains(".")) countrys = countryReq.Replace('.', '|');
  731. else countrys = countryReq;
  732. }
  733. //建团时 默认出团 设置 团组code
  734. string teamCode = "";
  735. string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
  736. var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  737. while (true)
  738. {
  739. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  740. if (!teamCodeItem.Equals(teamCode))
  741. {
  742. break;
  743. }
  744. }
  745. var delegationInfo = new Grp_DelegationInfo()
  746. {
  747. CityId = dto.CityId,
  748. SalesQuoteNo = dto.SalesQuoteNo,
  749. TeamLevSId = dto.TeamLevSId,
  750. ClientName = dto.ClientName,
  751. ClientUnit = dto.ClientUnit,
  752. TeamName = dto.TeamName,
  753. TeamDid = dto.TeamDid,
  754. VisitDate = Convert.ToDateTime(dto.VisitDate),
  755. VisitCountry = countrys,
  756. VisitPurpose = dto.VisitPurpose,
  757. VisitDays = dto.VisitDays,
  758. VisitPNumber = dto.VisitPNumber,
  759. SpecialNeeds = dto.SpecialNeeds,
  760. OtherNeeds = dto.OtherNeeds,
  761. Remark = dto.Remark,
  762. JietuanOperator = dto.JietuanOperator,
  763. TellPhone = dto.TellPhone,
  764. WeChatNo = dto.WeChatNo,
  765. CGRWSPBMMC = dto.CGRWSPBMMC,
  766. CGRWSPWH = dto.CGRWSPWH,
  767. ZZSCBMMC = dto.ZZSCBMMC,
  768. ZZSCSPWH = dto.ZZSCSPWH,
  769. TontractTime = string.IsNullOrEmpty(dto.TontractTime) ? null : Convert.ToDateTime(dto.TontractTime),
  770. IsBid = dto.IsBid,
  771. PaymentMoney = dto.PaymentMoney,
  772. PayDay = dto.PayDay,
  773. TourCode = teamCode,
  774. GroupsOperator = dto.UserId,
  775. GroupsTime = DateTime.Now,
  776. SalesDate = DateTime.Now,
  777. IsState = 0, //默认团组未完成 0
  778. JietuanTime = DateTime.Now,
  779. IsDel = 0,
  780. BudgetCost = 0.00M,
  781. HotelComplain = 0,
  782. OPComplain = 0,
  783. OAComplain = 0,
  784. AirComplain = 0,
  785. VisaComplain = 0,
  786. CreateUserId = dto.UserId,
  787. CreateTime = DateTime.Now,
  788. DeleteUserId = null,
  789. DeleteTime = new DateTime(1990, 1, 1).ToString("yyyy-MM-dd HH:mm:ss"),
  790. OpRoyaltyLv = dto.OpRoyaltyLv,
  791. OpRoyaltyRemark = dto.opRoyaltyRemark,
  792. Officialneeds = dto.Officialneeds,
  793. VisitStartDate = startTime,
  794. VisitEndDate = endTime,
  795. ExtOverLimit = dto.ExtOverLimit,
  796. ExtOverCurrency = dto.ExtOverCurrency
  797. };
  798. var addId = _sqlSugar.Insertable(delegationInfo).ExecuteReturnIdentity();
  799. if (addId > 0)
  800. {
  801. result.Code = 0;
  802. result.Msg = "添加成功!";
  803. result.Data = addId;
  804. }
  805. else
  806. {
  807. result.Msg = "添加失败!";
  808. }
  809. }
  810. else if (dto.Status == 2) //修改
  811. {
  812. var updateStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo
  813. {
  814. CityId = dto.CityId,
  815. SalesQuoteNo = dto.SalesQuoteNo,
  816. TeamLevSId = dto.TeamLevSId,
  817. ClientName = dto.ClientName,
  818. ClientUnit = dto.ClientUnit,
  819. TeamName = dto.TeamName,
  820. TeamDid = dto.TeamDid,
  821. VisitDate = Convert.ToDateTime(dto.VisitDate),
  822. VisitCountry = dto.VisitCountry,
  823. VisitPurpose = dto.VisitPurpose,
  824. VisitDays = dto.VisitDays,
  825. VisitPNumber = dto.VisitPNumber,
  826. SpecialNeeds = dto.SpecialNeeds,
  827. OtherNeeds = dto.OtherNeeds,
  828. Remark = dto.Remark,
  829. JietuanOperator = dto.JietuanOperator,
  830. TellPhone = dto.TellPhone,
  831. WeChatNo = dto.WeChatNo,
  832. CGRWSPBMMC = dto.CGRWSPBMMC,
  833. CGRWSPWH = dto.CGRWSPWH,
  834. ZZSCBMMC = dto.ZZSCBMMC,
  835. ZZSCSPWH = dto.ZZSCSPWH,
  836. TontractTime = string.IsNullOrEmpty(dto.TontractTime) ? null : Convert.ToDateTime(dto.TontractTime),
  837. IsBid = dto.IsBid,
  838. PaymentMoney = dto.PaymentMoney,
  839. PayDay = dto.PayDay,
  840. OpRoyaltyLv = dto.OpRoyaltyLv,
  841. OpRoyaltyRemark = dto.opRoyaltyRemark,
  842. Officialneeds = dto.Officialneeds,
  843. VisitStartDate = startTime,
  844. VisitEndDate = endTime,
  845. ExtOverLimit = dto.ExtOverLimit,
  846. ExtOverCurrency = dto.ExtOverCurrency
  847. });
  848. if (updateStatus)
  849. {
  850. result.Code = 0;
  851. result.Msg = "修改成功!";
  852. }
  853. else
  854. {
  855. result.Msg = "修改失败!";
  856. }
  857. }
  858. else if (dto.Status == 3) //删除
  859. {
  860. var deleteStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo
  861. {
  862. DeleteUserId = dto.UserId,
  863. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  864. IsDel = 1
  865. });
  866. if (deleteStatus)
  867. {
  868. result.Code = 0;
  869. result.Msg = "删除成功!";
  870. }
  871. else
  872. {
  873. result.Msg = "删除失败!";
  874. }
  875. }
  876. }
  877. return result;
  878. }
  879. /// <summary>
  880. /// 团组信息操作 - 删除
  881. /// </summary>
  882. /// <param name="dto"></param>
  883. /// <returns></returns>
  884. public async Task<Result> GroupDel(GroupDelDto dto)
  885. {
  886. var result = new Result() { Code = -2, Msg = "未知错误" };
  887. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  888. {
  889. var deleteStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo
  890. {
  891. DeleteUserId = dto.UserId,
  892. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  893. IsDel = 1
  894. });
  895. if (deleteStatus)
  896. {
  897. result.Code = 0;
  898. result.Msg = "删除成功!";
  899. }
  900. else
  901. {
  902. result.Msg = "删除失败!";
  903. }
  904. }
  905. return result;
  906. }
  907. /// <summary>
  908. /// 获取销售报价号
  909. /// </summary>
  910. /// <returns></returns>
  911. public async Task<Result> GetGroupSalesQuoteNo()
  912. {
  913. var result = new Result() { Code = -2, Msg = "未知错误" };
  914. string teamCodeSql = string.Format("Select SalesQuoteNo From Grp_DelegationInfo");
  915. var teamCodeItem = await _sqlSugar.SqlQueryable<SalesQuoteNoView>(teamCodeSql).ToListAsync();
  916. string teamCode;
  917. while (true)
  918. {
  919. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  920. if (!teamCodeItem.Equals(teamCode))
  921. {
  922. break;
  923. }
  924. }
  925. result.Code = 0;
  926. result.Msg = "成功!";
  927. result.Data = teamCode;
  928. return result;
  929. }
  930. /// <summary>
  931. /// 团组删除
  932. /// </summary>
  933. /// <returns></returns>
  934. public async Task<Result> GroupDeleteById()
  935. {
  936. var result = new Result() { Code = -2, Msg = "未知错误" };
  937. string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
  938. var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  939. string teamCode;
  940. while (true)
  941. {
  942. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  943. if (!teamCodeItem.Equals(teamCode))
  944. {
  945. break;
  946. }
  947. }
  948. result.Code = 0;
  949. result.Msg = "成功!";
  950. result.Data = teamCode;
  951. return result;
  952. }
  953. /// <summary>
  954. /// 团组确认出团
  955. /// </summary>
  956. /// <returns></returns>
  957. public async Task<Result> ConfirmationGroup(ConfirmationGroupDto dto)
  958. {
  959. var result = new Result() { Code = -2, Msg = "未知错误" };
  960. string teamCode = "";
  961. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  962. {
  963. string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
  964. var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  965. while (true)
  966. {
  967. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  968. if (!teamCodeItem.Equals(teamCode))
  969. {
  970. break;
  971. }
  972. }
  973. var deleteStatus = await UpdateAsync(a => a.Id == dto.GroupId, a => new Grp_DelegationInfo
  974. {
  975. TourCode = teamCode,
  976. GroupsOperator = dto.GroupsOperator,
  977. GroupsTime = DateTime.Now
  978. });
  979. if (deleteStatus)
  980. {
  981. result.Code = 0;
  982. result.Msg = "确认出团设置成功!";
  983. }
  984. else
  985. {
  986. result.Msg = "确认出团设置失败!";
  987. }
  988. }
  989. result.Code = 0;
  990. result.Msg = "成功!";
  991. result.Data = teamCode;
  992. return result;
  993. }
  994. /// <summary>
  995. /// 获取接团名称List
  996. /// </summary>
  997. /// <param name="dto"></param>
  998. /// <returns></returns>
  999. public async Task<JsonView> GetGroupNameList(GroupNameDto dto)
  1000. {
  1001. var view = new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "操作失败!" };
  1002. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  1003. {
  1004. //2025-02-17 更改团组列表排序功能 按照团出访时间排序(降序)
  1005. string sql = string.Format(@"Select Id,TeamName GroupName From Grp_DelegationInfo
  1006. Where TeamName != '' And IsDel = 0
  1007. Order By VisitStartDate Desc");
  1008. var _groupNameList = await _sqlSugar.SqlQueryable<GroupNameView>(sql).ToListAsync();
  1009. if (_groupNameList.Any())
  1010. {
  1011. for (int i = 0; i < _groupNameList.Count; i++)
  1012. {
  1013. var info = _groupNameList[i];
  1014. _groupNameList[i].GroupName = FormartTeamName(info.GroupName);
  1015. }
  1016. //_groupNameList.Insert(0, new GroupNameView() { Id = 0, GroupName = "未选择" });
  1017. view.Code = StatusCodes.Status200OK;
  1018. view.Msg = "成功!";
  1019. view.Data = _groupNameList;
  1020. }
  1021. else
  1022. {
  1023. view.Msg = "暂无团组信息";
  1024. }
  1025. }
  1026. return view;
  1027. }
  1028. //PostGroupNameScreen
  1029. /// <summary>
  1030. /// 获取接团名称 Page List
  1031. /// </summary>
  1032. /// <param name="dto"></param>
  1033. /// <returns></returns>
  1034. public async Task<JsonView> GetGroupNameList(int portType, int pageIndex, int pageSize, string groupName, int userId)
  1035. {
  1036. var _res = new JsonView() { Code = 400, Msg = MsgTips.Fail };
  1037. string sql = "";
  1038. string sqlWhere = "";
  1039. string mobileSqlWhere = "";
  1040. if (!string.IsNullOrEmpty(groupName))
  1041. {
  1042. sqlWhere += string.Format($@"And TeamName Like '%{groupName}%'");
  1043. mobileSqlWhere += string.Format($@"GroupName Like '%{groupName}%'");
  1044. }
  1045. var userIds = new List<int>() { -1, 21 };
  1046. if (!userIds.Contains(userId))
  1047. {
  1048. sqlWhere += string.Format($@"And JietuanOperator = {userId}");
  1049. }
  1050. sql = string.Format($@"Select ROW_NUMBER()Over(Order By Id Desc) as RowNumber,Id,TeamName GroupName From Grp_DelegationInfo
  1051. Where IsDel = 0 {sqlWhere}");
  1052. if (portType == 1) //web
  1053. { }
  1054. else if (portType == 2 || portType == 3)
  1055. {
  1056. //国交部 7 (主管 22,经理 32)团操操作权限 市场部 6 接团人
  1057. var userInfo = await _sqlSugar.Queryable<Sys_Users>().Where(it => it.Id == userId && it.IsDel == 0).FirstAsync();
  1058. if (userInfo != null)
  1059. {
  1060. if (userInfo.DepId == 7)
  1061. {
  1062. if (userInfo.JobPostId != 22 || userInfo.JobPostId != 32)
  1063. {
  1064. if (!string.IsNullOrEmpty(mobileSqlWhere)) mobileSqlWhere = $" Where {mobileSqlWhere}";
  1065. sql = string.Format($@"Select
  1066. ROW_NUMBER()Over(Order By Id Desc) as RowNumber,
  1067. Id,
  1068. GroupName
  1069. From (
  1070. Select
  1071. distinct
  1072. di.Id,
  1073. di.TeamName GroupName
  1074. From Grp_GroupsTaskAssignment gta With(NoLock)
  1075. Inner Join Grp_DelegationInfo di With(NoLock) On gta.DIId = di.Id
  1076. Where gta.IsDel = 0 And di.IsDel = 0 And gta.UId = {userId}
  1077. ) Temp {mobileSqlWhere}");
  1078. }
  1079. }
  1080. }
  1081. }
  1082. RefAsync<int> total = 0;
  1083. var groupNamePageData = await _sqlSugar.SqlQueryable<GroupNamePageView>(sql).ToPageListAsync(pageIndex, pageSize, total);
  1084. _res.Code = 200;
  1085. _res.Data = groupNamePageData;
  1086. _res.Msg = MsgTips.Succeed;
  1087. _res.Count = total;
  1088. return _res;
  1089. }
  1090. /// <summary>
  1091. /// 获取接团名称List And 签证国别
  1092. /// </summary>
  1093. /// <param name="dto"></param>
  1094. /// <returns></returns>
  1095. public async Task<Result> GetGroupNameAndVisaNationality(GroupNameDto dto)
  1096. {
  1097. var result = new Result() { Code = -2, Msg = "未知错误" };
  1098. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  1099. {
  1100. string sql = string.Format(@"Select Id,TeamName GroupName From Grp_DelegationInfo
  1101. Where TeamName != '' And IsDel = 0
  1102. Order By VisitDate Desc");
  1103. var _groupNameList = await _sqlSugar.SqlQueryable<GroupNameView>(sql).ToListAsync();
  1104. string visaSql = string.Format(@"Select Id,Name From Sys_SetData Where STid = 41 And IsDel = 0");
  1105. var _setDataList = await _sqlSugar.SqlQueryable<SetDataInfoView>(visaSql).ToListAsync();
  1106. var data = new
  1107. {
  1108. groupNameData = _groupNameList,
  1109. visaNationalityData = _setDataList
  1110. };
  1111. result.Data = data;
  1112. result.Code = 0;
  1113. }
  1114. return result;
  1115. }
  1116. #endregion
  1117. #region 团组&签证
  1118. /// <summary>
  1119. /// 根据团组Id查询客户
  1120. /// </summary>
  1121. /// <param name="dto"></param>
  1122. /// <returns></returns>
  1123. public async Task<Result> GetCrmByGroupId(ClientByGroupIdDto dto)
  1124. {
  1125. var result = new Result() { Code = -2 };
  1126. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3)
  1127. {
  1128. var clientInfos = await _sqlSugar.Queryable<Grp_TourClientList>().Where(x => x.IsDel == 0 && x.DiId == dto.GroupId).ToListAsync();
  1129. var clientIds = clientInfos.Select(x => x.ClientId).ToList();
  1130. var visaClientInfos = await _sqlSugar.Queryable<Crm_DeleClient>().Where(x => x.IsDel == 0 && clientIds.Contains(x.Id))
  1131. .Select(x => new Crm_DeleClient
  1132. {
  1133. DiId = dto.GroupId,
  1134. Id = x.Id,
  1135. FirstName = x.FirstName,
  1136. LastName = x.LastName,
  1137. Tel = x.Tel
  1138. })
  1139. .ToListAsync();
  1140. var clientCertInfos = await _sqlSugar.Queryable<Crm_CustomerCert>().Where(x => x.IsDel == 0 && x.SdId == 773 && clientIds.Contains(x.DcId))
  1141. .Select(x => new Crm_CustomerCert
  1142. {
  1143. DcId = x.DcId,
  1144. CertNo = x.CertNo
  1145. })
  1146. .ToListAsync();
  1147. //解密
  1148. foreach (var item in visaClientInfos)
  1149. {
  1150. EncryptionProcessor.DecryptProperties(item);
  1151. }
  1152. //信息整合
  1153. var view = new List<CrmByGroupIdView>();
  1154. foreach (var item in visaClientInfos)
  1155. {
  1156. var idNo = AesEncryptionHelper.Decrypt(clientCertInfos.FirstOrDefault(x => x.DcId == item.Id)?.CertNo ?? "") ?? "-";
  1157. if (string.IsNullOrEmpty(idNo)) idNo = "-";
  1158. view.Add(new() {
  1159. GrpId = dto.GroupId,
  1160. ClientName = item.LastName + item.FirstName,
  1161. Tel = item.Tel ?? "-",
  1162. CerdNo = idNo
  1163. });
  1164. }
  1165. if (view.Count > 0)
  1166. {
  1167. result.Code = 0;
  1168. result.Msg = "成功!";
  1169. result.Data = view;
  1170. }
  1171. else
  1172. {
  1173. result.Code = 1;
  1174. result.Msg = "暂无数据!";
  1175. }
  1176. }
  1177. return result;
  1178. }
  1179. #endregion
  1180. #region 团组&出入境费用
  1181. /// <summary>
  1182. /// 获取单组名称并验证出入境费用明细是否填写
  1183. /// </summary>
  1184. /// <param name="dto"></param>
  1185. /// <returns></returns>
  1186. public async Task<EnterExitCostGroupNameView[]> EnterExitCostGroupNameAsync()
  1187. {
  1188. var groupSql = string.Format(@$"SELECT
  1189. Id,
  1190. TeamName GroupName,
  1191. CityId ProvinceId,
  1192. CASE
  1193. WHEN (
  1194. SELECT
  1195. COUNT(*)
  1196. FROM
  1197. Grp_EnterExitCost
  1198. WHERE
  1199. IsDel = 0
  1200. AND DiId = di.Id
  1201. ) > 0 THEN 'false'
  1202. ELSE 'true'
  1203. END AS [IsNull]
  1204. FROM
  1205. Grp_DelegationInfo di
  1206. WHERE
  1207. di.Isdel = 0
  1208. ORDER BY
  1209. VisitStartDate Desc");
  1210. var groupDatas = await _sqlSugar.SqlQueryable<EnterExitCostGroupNameView>(groupSql).ToArrayAsync();
  1211. var provCityDatas = await ProvinceCityBasicSource();
  1212. if (provCityDatas.Any() && groupDatas.Any())
  1213. {
  1214. foreach (var item in groupDatas)
  1215. {
  1216. var provinceId = item.ProvinceId;
  1217. var isDefualtVal = true;
  1218. if (provinceId > 0)
  1219. {
  1220. var parentId = FindParentIdByChildId(provCityDatas, provinceId);
  1221. if (parentId != null)
  1222. {
  1223. isDefualtVal = false;
  1224. item.ProvinceId = (int)parentId;
  1225. }
  1226. }
  1227. if (isDefualtVal)
  1228. {
  1229. item.ProvinceId = 122; //默认四川
  1230. }
  1231. }
  1232. }
  1233. return groupDatas;
  1234. }
  1235. /// <summary>
  1236. /// 获取单组名称并验证出入境费用明细是否填写
  1237. /// </summary>
  1238. /// <param name="dto"></param>
  1239. /// <returns></returns>
  1240. public async Task<EnterExitCostGroupNameView> EnterExitCostGroupNameInfoAsync(int groupId)
  1241. {
  1242. var groupSql = string.Format(@$"SELECT
  1243. Id,
  1244. TeamName GroupName,
  1245. CityId ProvinceId,
  1246. CASE
  1247. WHEN (
  1248. SELECT
  1249. COUNT(*)
  1250. FROM
  1251. Grp_EnterExitCost
  1252. WHERE
  1253. IsDel = 0
  1254. AND DiId = di.Id
  1255. ) > 0 THEN 'false'
  1256. ELSE 'true'
  1257. END AS [IsNull]
  1258. FROM
  1259. Grp_DelegationInfo di
  1260. WHERE
  1261. di.Isdel = 0
  1262. And Id = {groupId} ");
  1263. var groupData = await _sqlSugar.SqlQueryable<EnterExitCostGroupNameView>(groupSql).FirstAsync();
  1264. var provCityDatas = await ProvinceCityBasicSource();
  1265. if (provCityDatas.Any() && groupData != null)
  1266. {
  1267. var provinceId = groupData.ProvinceId;
  1268. var isDefualtVal = true;
  1269. if (provinceId > 0)
  1270. {
  1271. var parentId = FindParentIdByChildId(provCityDatas, provinceId);
  1272. if (parentId != null)
  1273. {
  1274. isDefualtVal = false;
  1275. groupData.ProvinceId = (int)parentId;
  1276. }
  1277. }
  1278. if (isDefualtVal)
  1279. {
  1280. groupData.ProvinceId = 0; //
  1281. }
  1282. }
  1283. return groupData;
  1284. }
  1285. /// <summary>
  1286. /// 递归地遍历树状结构,查找子项的父类 Id。
  1287. /// </summary>
  1288. /// <param name="tree"></param>
  1289. /// <param name="childId"></param>
  1290. /// <returns></returns>
  1291. public int? FindParentIdByChildId(List<CityTree> tree, int childId)
  1292. {
  1293. foreach (var node in tree)
  1294. {
  1295. if (node.Child != null && node.Child.Any())
  1296. {
  1297. if (node.Child.Any(c => c.Id == childId))
  1298. {
  1299. return node.Id;
  1300. }
  1301. var parentId = FindParentIdByChildId(node.Child, childId);
  1302. if (parentId.HasValue)
  1303. {
  1304. return parentId;
  1305. }
  1306. }
  1307. }
  1308. return null;
  1309. }
  1310. #endregion
  1311. }
  1312. }