DelegationInfoRepository.cs 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514
  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. //额外超支参数处理
  690. decimal extOverLimit = decimal.TryParse(dto.ExtOverLimit, out decimal tempLimit) ? tempLimit : 0.00M;
  691. int extOverCurrency = int.TryParse(dto.ExtOverLimit, out int tempCurrency) ? tempCurrency : 836; //默认人名币
  692. #region 添加出访起止时间
  693. var startTime = new DateTime();
  694. var endTime = new DateTime();
  695. if (DateTime.TryParse(dto.VisitDate, out startTime))
  696. {
  697. endTime = startTime.AddDays(dto.VisitDays - 1);//含当天
  698. }
  699. #endregion
  700. if (dto.Status == 1) //添加
  701. {
  702. string selectSql = string.Format(@"Select * From Grp_DelegationInfo
  703. Where IsDel = 0
  704. And TeamName = '{0}'
  705. And ClientName = '{1}'
  706. And ClientUnit ='{2}'
  707. And VisitDate ='{3}'", dto.TeamName, dto.ClientName, dto.ClientUnit, dto.VisitDate);
  708. var selectGroupInfo = _sqlSugar.SqlQueryable<Grp_DelegationInfo>(selectSql).First();
  709. if (selectGroupInfo != null)
  710. {
  711. result.Msg = "数据已存在,请勿重复添加!";
  712. return result;
  713. }
  714. //string teamCodeSql = string.Format("Select SalesQuoteNo From Grp_DelegationInfo");
  715. //var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  716. //string SalesQuoteNo = "";
  717. //while (true)
  718. //{
  719. // SalesQuoteNo = Tools.CommonFun.GetRandomStr(6);
  720. // if (!teamCodeItem.Equals(SalesQuoteNo))
  721. // {
  722. // break;
  723. // }
  724. //}
  725. string countrys = string.Empty;
  726. string countryReq = dto.VisitCountry;
  727. if (!string.IsNullOrEmpty(countryReq))
  728. {
  729. if (countryReq.Contains(",")) countrys = countryReq.Replace(',', '|');
  730. else if (countryReq.Contains(",")) countrys = countryReq.Replace(',', '|');
  731. else if (countryReq.Contains(" ")) countrys = countryReq.Replace(' ', '|');
  732. else if (countryReq.Contains("、")) countrys = countryReq.Replace('、', '|');
  733. else if (countryReq.Contains(".")) countrys = countryReq.Replace('.', '|');
  734. else countrys = countryReq;
  735. }
  736. //建团时 默认出团 设置 团组code
  737. string teamCode = "";
  738. string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
  739. var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  740. while (true)
  741. {
  742. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  743. if (!teamCodeItem.Equals(teamCode))
  744. {
  745. break;
  746. }
  747. }
  748. var delegationInfo = new Grp_DelegationInfo()
  749. {
  750. CityId = dto.CityId,
  751. SalesQuoteNo = dto.SalesQuoteNo,
  752. TeamLevSId = dto.TeamLevSId,
  753. ClientName = dto.ClientName,
  754. ClientUnit = dto.ClientUnit,
  755. TeamName = dto.TeamName,
  756. TeamDid = dto.TeamDid,
  757. VisitDate = Convert.ToDateTime(dto.VisitDate),
  758. VisitCountry = countrys,
  759. VisitPurpose = dto.VisitPurpose,
  760. VisitDays = dto.VisitDays,
  761. VisitPNumber = dto.VisitPNumber,
  762. SpecialNeeds = dto.SpecialNeeds,
  763. OtherNeeds = dto.OtherNeeds,
  764. Remark = dto.Remark,
  765. JietuanOperator = dto.JietuanOperator,
  766. TellPhone = dto.TellPhone,
  767. WeChatNo = dto.WeChatNo,
  768. CGRWSPBMMC = dto.CGRWSPBMMC,
  769. CGRWSPWH = dto.CGRWSPWH,
  770. ZZSCBMMC = dto.ZZSCBMMC,
  771. ZZSCSPWH = dto.ZZSCSPWH,
  772. TontractTime = string.IsNullOrEmpty(dto.TontractTime) ? null : Convert.ToDateTime(dto.TontractTime),
  773. IsBid = dto.IsBid,
  774. PaymentMoney = dto.PaymentMoney,
  775. PayDay = dto.PayDay,
  776. TourCode = teamCode,
  777. GroupsOperator = dto.UserId,
  778. GroupsTime = DateTime.Now,
  779. SalesDate = DateTime.Now,
  780. IsState = 0, //默认团组未完成 0
  781. JietuanTime = DateTime.Now,
  782. IsDel = 0,
  783. BudgetCost = 0.00M,
  784. HotelComplain = 0,
  785. OPComplain = 0,
  786. OAComplain = 0,
  787. AirComplain = 0,
  788. VisaComplain = 0,
  789. CreateUserId = dto.UserId,
  790. CreateTime = DateTime.Now,
  791. DeleteUserId = null,
  792. DeleteTime = new DateTime(1990, 1, 1).ToString("yyyy-MM-dd HH:mm:ss"),
  793. OpRoyaltyLv = dto.OpRoyaltyLv,
  794. OpRoyaltyRemark = dto.opRoyaltyRemark,
  795. Officialneeds = dto.Officialneeds,
  796. VisitStartDate = startTime,
  797. VisitEndDate = endTime,
  798. ExtOverLimit = extOverLimit,
  799. ExtOverCurrency = extOverCurrency
  800. };
  801. var addId = _sqlSugar.Insertable(delegationInfo).ExecuteReturnIdentity();
  802. if (addId > 0)
  803. {
  804. result.Code = 0;
  805. result.Msg = "添加成功!";
  806. result.Data = addId;
  807. }
  808. else
  809. {
  810. result.Msg = "添加失败!";
  811. }
  812. }
  813. else if (dto.Status == 2) //修改
  814. {
  815. var updateStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo
  816. {
  817. CityId = dto.CityId,
  818. SalesQuoteNo = dto.SalesQuoteNo,
  819. TeamLevSId = dto.TeamLevSId,
  820. ClientName = dto.ClientName,
  821. ClientUnit = dto.ClientUnit,
  822. TeamName = dto.TeamName,
  823. TeamDid = dto.TeamDid,
  824. VisitDate = Convert.ToDateTime(dto.VisitDate),
  825. VisitCountry = dto.VisitCountry,
  826. VisitPurpose = dto.VisitPurpose,
  827. VisitDays = dto.VisitDays,
  828. VisitPNumber = dto.VisitPNumber,
  829. SpecialNeeds = dto.SpecialNeeds,
  830. OtherNeeds = dto.OtherNeeds,
  831. Remark = dto.Remark,
  832. JietuanOperator = dto.JietuanOperator,
  833. TellPhone = dto.TellPhone,
  834. WeChatNo = dto.WeChatNo,
  835. CGRWSPBMMC = dto.CGRWSPBMMC,
  836. CGRWSPWH = dto.CGRWSPWH,
  837. ZZSCBMMC = dto.ZZSCBMMC,
  838. ZZSCSPWH = dto.ZZSCSPWH,
  839. TontractTime = string.IsNullOrEmpty(dto.TontractTime) ? null : Convert.ToDateTime(dto.TontractTime),
  840. IsBid = dto.IsBid,
  841. PaymentMoney = dto.PaymentMoney,
  842. PayDay = dto.PayDay,
  843. OpRoyaltyLv = dto.OpRoyaltyLv,
  844. OpRoyaltyRemark = dto.opRoyaltyRemark,
  845. Officialneeds = dto.Officialneeds,
  846. VisitStartDate = startTime,
  847. VisitEndDate = endTime,
  848. ExtOverLimit = extOverLimit,
  849. ExtOverCurrency = extOverCurrency
  850. });
  851. if (updateStatus)
  852. {
  853. result.Code = 0;
  854. result.Msg = "修改成功!";
  855. }
  856. else
  857. {
  858. result.Msg = "修改失败!";
  859. }
  860. }
  861. else if (dto.Status == 3) //删除
  862. {
  863. var deleteStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo
  864. {
  865. DeleteUserId = dto.UserId,
  866. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  867. IsDel = 1
  868. });
  869. if (deleteStatus)
  870. {
  871. result.Code = 0;
  872. result.Msg = "删除成功!";
  873. }
  874. else
  875. {
  876. result.Msg = "删除失败!";
  877. }
  878. }
  879. }
  880. return result;
  881. }
  882. /// <summary>
  883. /// 团组信息操作 - 删除
  884. /// </summary>
  885. /// <param name="dto"></param>
  886. /// <returns></returns>
  887. public async Task<Result> GroupDel(GroupDelDto dto)
  888. {
  889. var result = new Result() { Code = -2, Msg = "未知错误" };
  890. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  891. {
  892. var deleteStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo
  893. {
  894. DeleteUserId = dto.UserId,
  895. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  896. IsDel = 1
  897. });
  898. if (deleteStatus)
  899. {
  900. result.Code = 0;
  901. result.Msg = "删除成功!";
  902. }
  903. else
  904. {
  905. result.Msg = "删除失败!";
  906. }
  907. }
  908. return result;
  909. }
  910. /// <summary>
  911. /// 获取销售报价号
  912. /// </summary>
  913. /// <returns></returns>
  914. public async Task<Result> GetGroupSalesQuoteNo()
  915. {
  916. var result = new Result() { Code = -2, Msg = "未知错误" };
  917. string teamCodeSql = string.Format("Select SalesQuoteNo From Grp_DelegationInfo");
  918. var teamCodeItem = await _sqlSugar.SqlQueryable<SalesQuoteNoView>(teamCodeSql).ToListAsync();
  919. string teamCode;
  920. while (true)
  921. {
  922. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  923. if (!teamCodeItem.Equals(teamCode))
  924. {
  925. break;
  926. }
  927. }
  928. result.Code = 0;
  929. result.Msg = "成功!";
  930. result.Data = teamCode;
  931. return result;
  932. }
  933. /// <summary>
  934. /// 团组删除
  935. /// </summary>
  936. /// <returns></returns>
  937. public async Task<Result> GroupDeleteById()
  938. {
  939. var result = new Result() { Code = -2, Msg = "未知错误" };
  940. string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
  941. var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  942. string teamCode;
  943. while (true)
  944. {
  945. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  946. if (!teamCodeItem.Equals(teamCode))
  947. {
  948. break;
  949. }
  950. }
  951. result.Code = 0;
  952. result.Msg = "成功!";
  953. result.Data = teamCode;
  954. return result;
  955. }
  956. /// <summary>
  957. /// 团组确认出团
  958. /// </summary>
  959. /// <returns></returns>
  960. public async Task<Result> ConfirmationGroup(ConfirmationGroupDto dto)
  961. {
  962. var result = new Result() { Code = -2, Msg = "未知错误" };
  963. string teamCode = "";
  964. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  965. {
  966. string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
  967. var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  968. while (true)
  969. {
  970. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  971. if (!teamCodeItem.Equals(teamCode))
  972. {
  973. break;
  974. }
  975. }
  976. var deleteStatus = await UpdateAsync(a => a.Id == dto.GroupId, a => new Grp_DelegationInfo
  977. {
  978. TourCode = teamCode,
  979. GroupsOperator = dto.GroupsOperator,
  980. GroupsTime = DateTime.Now
  981. });
  982. if (deleteStatus)
  983. {
  984. result.Code = 0;
  985. result.Msg = "确认出团设置成功!";
  986. }
  987. else
  988. {
  989. result.Msg = "确认出团设置失败!";
  990. }
  991. }
  992. result.Code = 0;
  993. result.Msg = "成功!";
  994. result.Data = teamCode;
  995. return result;
  996. }
  997. /// <summary>
  998. /// 获取接团名称List
  999. /// </summary>
  1000. /// <param name="dto"></param>
  1001. /// <returns></returns>
  1002. public async Task<JsonView> GetGroupNameList(GroupNameDto dto)
  1003. {
  1004. var view = new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "操作失败!" };
  1005. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  1006. {
  1007. //2025-02-17 更改团组列表排序功能 按照团出访时间排序(降序)
  1008. string sql = string.Format(@"Select Id,TeamName GroupName From Grp_DelegationInfo
  1009. Where TeamName != '' And IsDel = 0
  1010. Order By VisitStartDate Desc");
  1011. var _groupNameList = await _sqlSugar.SqlQueryable<GroupNameView>(sql).ToListAsync();
  1012. if (_groupNameList.Any())
  1013. {
  1014. for (int i = 0; i < _groupNameList.Count; i++)
  1015. {
  1016. var info = _groupNameList[i];
  1017. _groupNameList[i].GroupName = FormartTeamName(info.GroupName);
  1018. }
  1019. //_groupNameList.Insert(0, new GroupNameView() { Id = 0, GroupName = "未选择" });
  1020. view.Code = StatusCodes.Status200OK;
  1021. view.Msg = "成功!";
  1022. view.Data = _groupNameList;
  1023. }
  1024. else
  1025. {
  1026. view.Msg = "暂无团组信息";
  1027. }
  1028. }
  1029. return view;
  1030. }
  1031. //PostGroupNameScreen
  1032. /// <summary>
  1033. /// 获取接团名称 Page List
  1034. /// </summary>
  1035. /// <param name="dto"></param>
  1036. /// <returns></returns>
  1037. public async Task<JsonView> GetGroupNameList(int portType, int pageIndex, int pageSize, string groupName, int userId)
  1038. {
  1039. var _res = new JsonView() { Code = 400, Msg = MsgTips.Fail };
  1040. string sql = "";
  1041. string sqlWhere = "";
  1042. string mobileSqlWhere = "";
  1043. if (!string.IsNullOrEmpty(groupName))
  1044. {
  1045. sqlWhere += string.Format($@"And TeamName Like '%{groupName}%'");
  1046. mobileSqlWhere += string.Format($@"GroupName Like '%{groupName}%'");
  1047. }
  1048. var userIds = new List<int>() { -1, 21 };
  1049. if (!userIds.Contains(userId))
  1050. {
  1051. sqlWhere += string.Format($@"And JietuanOperator = {userId}");
  1052. }
  1053. sql = string.Format($@"Select ROW_NUMBER()Over(Order By Id Desc) as RowNumber,Id,TeamName GroupName From Grp_DelegationInfo
  1054. Where IsDel = 0 {sqlWhere}");
  1055. if (portType == 1) //web
  1056. { }
  1057. else if (portType == 2 || portType == 3)
  1058. {
  1059. //国交部 7 (主管 22,经理 32)团操操作权限 市场部 6 接团人
  1060. var userInfo = await _sqlSugar.Queryable<Sys_Users>().Where(it => it.Id == userId && it.IsDel == 0).FirstAsync();
  1061. if (userInfo != null)
  1062. {
  1063. if (userInfo.DepId == 7)
  1064. {
  1065. if (userInfo.JobPostId != 22 || userInfo.JobPostId != 32)
  1066. {
  1067. if (!string.IsNullOrEmpty(mobileSqlWhere)) mobileSqlWhere = $" Where {mobileSqlWhere}";
  1068. sql = string.Format($@"Select
  1069. ROW_NUMBER()Over(Order By Id Desc) as RowNumber,
  1070. Id,
  1071. GroupName
  1072. From (
  1073. Select
  1074. distinct
  1075. di.Id,
  1076. di.TeamName GroupName
  1077. From Grp_GroupsTaskAssignment gta With(NoLock)
  1078. Inner Join Grp_DelegationInfo di With(NoLock) On gta.DIId = di.Id
  1079. Where gta.IsDel = 0 And di.IsDel = 0 And gta.UId = {userId}
  1080. ) Temp {mobileSqlWhere}");
  1081. }
  1082. }
  1083. }
  1084. }
  1085. RefAsync<int> total = 0;
  1086. var groupNamePageData = await _sqlSugar.SqlQueryable<GroupNamePageView>(sql).ToPageListAsync(pageIndex, pageSize, total);
  1087. _res.Code = 200;
  1088. _res.Data = groupNamePageData;
  1089. _res.Msg = MsgTips.Succeed;
  1090. _res.Count = total;
  1091. return _res;
  1092. }
  1093. /// <summary>
  1094. /// 获取接团名称List And 签证国别
  1095. /// </summary>
  1096. /// <param name="dto"></param>
  1097. /// <returns></returns>
  1098. public async Task<Result> GetGroupNameAndVisaNationality(GroupNameDto dto)
  1099. {
  1100. var result = new Result() { Code = -2, Msg = "未知错误" };
  1101. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  1102. {
  1103. string sql = string.Format(@"Select Id,TeamName GroupName From Grp_DelegationInfo
  1104. Where TeamName != '' And IsDel = 0
  1105. Order By VisitDate Desc");
  1106. var _groupNameList = await _sqlSugar.SqlQueryable<GroupNameView>(sql).ToListAsync();
  1107. string visaSql = string.Format(@"Select Id,Name From Sys_SetData Where STid = 41 And IsDel = 0");
  1108. var _setDataList = await _sqlSugar.SqlQueryable<SetDataInfoView>(visaSql).ToListAsync();
  1109. var data = new
  1110. {
  1111. groupNameData = _groupNameList,
  1112. visaNationalityData = _setDataList
  1113. };
  1114. result.Data = data;
  1115. result.Code = 0;
  1116. }
  1117. return result;
  1118. }
  1119. #endregion
  1120. #region 团组&签证
  1121. /// <summary>
  1122. /// 根据团组Id查询客户
  1123. /// </summary>
  1124. /// <param name="dto"></param>
  1125. /// <returns></returns>
  1126. public async Task<Result> GetCrmByGroupId(ClientByGroupIdDto dto)
  1127. {
  1128. var result = new Result() { Code = -2 };
  1129. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3)
  1130. {
  1131. var clientInfos = await _sqlSugar.Queryable<Grp_TourClientList>().Where(x => x.IsDel == 0 && x.DiId == dto.GroupId).ToListAsync();
  1132. var clientIds = clientInfos.Select(x => x.ClientId).ToList();
  1133. var visaClientInfos = await _sqlSugar.Queryable<Crm_DeleClient>().Where(x => x.IsDel == 0 && clientIds.Contains(x.Id))
  1134. .Select(x => new Crm_DeleClient
  1135. {
  1136. DiId = dto.GroupId,
  1137. Id = x.Id,
  1138. FirstName = x.FirstName,
  1139. LastName = x.LastName,
  1140. Tel = x.Tel
  1141. })
  1142. .ToListAsync();
  1143. var clientCertInfos = await _sqlSugar.Queryable<Crm_CustomerCert>().Where(x => x.IsDel == 0 && x.SdId == 773 && clientIds.Contains(x.DcId))
  1144. .Select(x => new Crm_CustomerCert
  1145. {
  1146. DcId = x.DcId,
  1147. CertNo = x.CertNo
  1148. })
  1149. .ToListAsync();
  1150. //解密
  1151. foreach (var item in visaClientInfos)
  1152. {
  1153. EncryptionProcessor.DecryptProperties(item);
  1154. }
  1155. //信息整合
  1156. var view = new List<CrmByGroupIdView>();
  1157. foreach (var item in visaClientInfos)
  1158. {
  1159. var idNo = AesEncryptionHelper.Decrypt(clientCertInfos.FirstOrDefault(x => x.DcId == item.Id)?.CertNo ?? "") ?? "-";
  1160. if (string.IsNullOrEmpty(idNo)) idNo = "-";
  1161. view.Add(new() {
  1162. GrpId = dto.GroupId,
  1163. ClientName = item.LastName + item.FirstName,
  1164. Tel = item.Tel ?? "-",
  1165. CerdNo = idNo
  1166. });
  1167. }
  1168. if (view.Count > 0)
  1169. {
  1170. result.Code = 0;
  1171. result.Msg = "成功!";
  1172. result.Data = view;
  1173. }
  1174. else
  1175. {
  1176. result.Code = 1;
  1177. result.Msg = "暂无数据!";
  1178. }
  1179. }
  1180. return result;
  1181. }
  1182. #endregion
  1183. #region 团组&出入境费用
  1184. /// <summary>
  1185. /// 获取单组名称并验证出入境费用明细是否填写
  1186. /// </summary>
  1187. /// <param name="dto"></param>
  1188. /// <returns></returns>
  1189. public async Task<EnterExitCostGroupNameView[]> EnterExitCostGroupNameAsync()
  1190. {
  1191. var groupSql = string.Format(@$"SELECT
  1192. Id,
  1193. TeamName GroupName,
  1194. CityId ProvinceId,
  1195. CASE
  1196. WHEN (
  1197. SELECT
  1198. COUNT(*)
  1199. FROM
  1200. Grp_EnterExitCost
  1201. WHERE
  1202. IsDel = 0
  1203. AND DiId = di.Id
  1204. ) > 0 THEN 'false'
  1205. ELSE 'true'
  1206. END AS [IsNull]
  1207. FROM
  1208. Grp_DelegationInfo di
  1209. WHERE
  1210. di.Isdel = 0
  1211. ORDER BY
  1212. VisitStartDate Desc");
  1213. var groupDatas = await _sqlSugar.SqlQueryable<EnterExitCostGroupNameView>(groupSql).ToArrayAsync();
  1214. var provCityDatas = await ProvinceCityBasicSource();
  1215. if (provCityDatas.Any() && groupDatas.Any())
  1216. {
  1217. foreach (var item in groupDatas)
  1218. {
  1219. var provinceId = item.ProvinceId;
  1220. var isDefualtVal = true;
  1221. if (provinceId > 0)
  1222. {
  1223. var parentId = FindParentIdByChildId(provCityDatas, provinceId);
  1224. if (parentId != null)
  1225. {
  1226. isDefualtVal = false;
  1227. item.ProvinceId = (int)parentId;
  1228. }
  1229. }
  1230. if (isDefualtVal)
  1231. {
  1232. item.ProvinceId = 122; //默认四川
  1233. }
  1234. }
  1235. }
  1236. return groupDatas;
  1237. }
  1238. /// <summary>
  1239. /// 获取单组名称并验证出入境费用明细是否填写
  1240. /// </summary>
  1241. /// <param name="dto"></param>
  1242. /// <returns></returns>
  1243. public async Task<EnterExitCostGroupNameView> EnterExitCostGroupNameInfoAsync(int groupId)
  1244. {
  1245. var groupSql = string.Format(@$"SELECT
  1246. Id,
  1247. TeamName GroupName,
  1248. CityId ProvinceId,
  1249. CASE
  1250. WHEN (
  1251. SELECT
  1252. COUNT(*)
  1253. FROM
  1254. Grp_EnterExitCost
  1255. WHERE
  1256. IsDel = 0
  1257. AND DiId = di.Id
  1258. ) > 0 THEN 'false'
  1259. ELSE 'true'
  1260. END AS [IsNull]
  1261. FROM
  1262. Grp_DelegationInfo di
  1263. WHERE
  1264. di.Isdel = 0
  1265. And Id = {groupId} ");
  1266. var groupData = await _sqlSugar.SqlQueryable<EnterExitCostGroupNameView>(groupSql).FirstAsync();
  1267. var provCityDatas = await ProvinceCityBasicSource();
  1268. if (provCityDatas.Any() && groupData != null)
  1269. {
  1270. var provinceId = groupData.ProvinceId;
  1271. var isDefualtVal = true;
  1272. if (provinceId > 0)
  1273. {
  1274. var parentId = FindParentIdByChildId(provCityDatas, provinceId);
  1275. if (parentId != null)
  1276. {
  1277. isDefualtVal = false;
  1278. groupData.ProvinceId = (int)parentId;
  1279. }
  1280. }
  1281. if (isDefualtVal)
  1282. {
  1283. groupData.ProvinceId = 0; //
  1284. }
  1285. }
  1286. return groupData;
  1287. }
  1288. /// <summary>
  1289. /// 递归地遍历树状结构,查找子项的父类 Id。
  1290. /// </summary>
  1291. /// <param name="tree"></param>
  1292. /// <param name="childId"></param>
  1293. /// <returns></returns>
  1294. public int? FindParentIdByChildId(List<CityTree> tree, int childId)
  1295. {
  1296. foreach (var node in tree)
  1297. {
  1298. if (node.Child != null && node.Child.Any())
  1299. {
  1300. if (node.Child.Any(c => c.Id == childId))
  1301. {
  1302. return node.Id;
  1303. }
  1304. var parentId = FindParentIdByChildId(node.Child, childId);
  1305. if (parentId.HasValue)
  1306. {
  1307. return parentId;
  1308. }
  1309. }
  1310. }
  1311. return null;
  1312. }
  1313. #endregion
  1314. }
  1315. }