DelegationInfoRepository.cs 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493
  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. From Grp_DelegationInfo Where Id = {0} And IsDel = 0", dto.Id);
  374. var _DelegationInfo = await _sqlSugar.SqlQueryable<DelegationInfoWebView>(sql).FirstAsync();
  375. if (_DelegationInfo != null)
  376. {
  377. _DelegationInfo.TeamName = FormartTeamName(_DelegationInfo.TeamName);
  378. _DelegationInfo.VisitCountry = FormartTeamName(_DelegationInfo.VisitCountry);
  379. //验证城市值 不存在则设置默认值
  380. var cityInfo = await CityInfoById(_DelegationInfo.CityId);
  381. if (cityInfo != null)
  382. {
  383. _DelegationInfo.CityName = cityInfo.Name;
  384. }
  385. else
  386. {
  387. _DelegationInfo.CityId = 3505;
  388. _DelegationInfo.CityName = "四川-成都";
  389. }
  390. //if (_DelegationInfo.TontractTime)
  391. //{
  392. //}
  393. result.Code = 0;
  394. result.Msg = "成功!";
  395. result.Data = _DelegationInfo;
  396. if (dto.PortType == 2)
  397. {
  398. var GroupProcessOperationDtoParam = new GroupProcessOperationDto();
  399. GroupProcessOperationDtoParam = _mapper.Map<DelegationInfoWebView, GroupProcessOperationDto>(_DelegationInfo);
  400. List<Crm_DeleClient> DeleClientArr = await _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0).ToListAsync(); //客户信息
  401. List<Grp_TourClientList> _DeleClients = await _sqlSugar.Queryable<Grp_TourClientList>().Where(it => it.IsDel == 0 && it.DiId == dto.Id).ToListAsync(); // 接团客户名单
  402. List<Crm_CustomerCert> _CustomerCerts = await _sqlSugar.Queryable<Crm_CustomerCert>().Where(it => it.IsDel == 0 && it.SdId == 773).ToListAsync(); // 身份证类型证件信息
  403. List<Crm_CustomerCompany> CompanyArr = await _sqlSugar.Queryable<Crm_CustomerCompany>().Where(it => it.IsDel == 0).ToListAsync();
  404. var TourClientListInfoArr = new List<TourClientListProcessInfo>();
  405. var timeParam = new DateTime();
  406. foreach (var item in _DeleClients)
  407. {
  408. var param = new TourClientListProcessInfo();
  409. var clientInfo = DeleClientArr.FirstOrDefault(x => x.Id == item.ClientId);
  410. clientInfo ??= new Crm_DeleClient();
  411. var clientIDInfo = _CustomerCerts.FirstOrDefault(x => x.DcId == item.ClientId); //身份证信息
  412. clientIDInfo ??= new Crm_CustomerCert();
  413. var Company = CompanyArr.FirstOrDefault(x => x.Id == clientInfo.CrmCompanyId);
  414. Company ??= new Crm_CustomerCompany();
  415. param.IDCardNo = clientIDInfo.CertNo;
  416. param.Remark = item.Remark;
  417. param.BirthDay = clientInfo.BirthDay == null ? "" : DateTime.TryParse(Convert.ToDateTime(clientInfo.BirthDay).ToString("yyyy-MM-dd"), out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  418. param.FirstName = clientInfo.FirstName;
  419. param.LastName = clientInfo.LastName;
  420. param.CompanyFullName = Company.CompanyFullName;
  421. param.Job = clientInfo.Job;
  422. param.Sex = clientInfo.Sex;
  423. param.Phone = clientInfo.Phone;
  424. param.Pinyin = clientInfo.Pinyin;
  425. param.HotelSpecialNeeds = item.HotelSpecialNeeds;
  426. param.MealSpecialNeeds = item.MealSpecialNeeds;
  427. param.ShippingSpaceSpecialNeeds = item.ShippingSpaceSpecialNeeds;
  428. param.ShippingSpaceTypeId = item.ShippingSpaceTypeId;
  429. param.Id = clientInfo.Id;
  430. EncryptionProcessor.DecryptProperties(param);
  431. TourClientListInfoArr.Add(param);
  432. }
  433. GroupProcessOperationDtoParam.PortType = dto.PortType;
  434. GroupProcessOperationDtoParam.TourClientListInfos = TourClientListInfoArr;
  435. GroupProcessOperationDtoParam.VisitDate = DateTime.TryParse(GroupProcessOperationDtoParam.VisitDate, out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  436. GroupProcessOperationDtoParam.VisitDate = DateTime.TryParse(GroupProcessOperationDtoParam.VisitDate, out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  437. GroupProcessOperationDtoParam.TontractTime = DateTime.TryParse(GroupProcessOperationDtoParam.TontractTime, out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  438. result.Data = GroupProcessOperationDtoParam;
  439. }
  440. else if (dto.PortType == 3)
  441. {
  442. var GroupProcessOperationDtoParam = new GroupProcessOperationDto();
  443. GroupProcessOperationDtoParam = _mapper.Map<DelegationInfoWebView, GroupProcessOperationDto>(_DelegationInfo);
  444. List<Crm_DeleClient> DeleClientArr = await _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0).ToListAsync(); //客户信息
  445. List<Grp_TourClientList> _DeleClients = await _sqlSugar.Queryable<Grp_TourClientList>().Where(it => it.IsDel == 0 && it.DiId == dto.Id).ToListAsync(); // 接团客户名单
  446. List<Crm_CustomerCert> _CustomerCerts = await _sqlSugar.Queryable<Crm_CustomerCert>().Where(it => it.IsDel == 0 && it.SdId == 773).ToListAsync(); // 身份证类型证件信息
  447. List<Crm_CustomerCompany> CompanyArr = await _sqlSugar.Queryable<Crm_CustomerCompany>().Where(it => it.IsDel == 0).ToListAsync();
  448. var TourClientListInfoArr = new List<TourClientListProcessInfo>();
  449. var timeParam = new DateTime();
  450. foreach (var item in _DeleClients)
  451. {
  452. var param = new TourClientListProcessInfo();
  453. var clientInfo = DeleClientArr.FirstOrDefault(x => x.Id == item.ClientId);
  454. clientInfo ??= new Crm_DeleClient();
  455. var clientIDInfo = _CustomerCerts.FirstOrDefault(x => x.DcId == item.ClientId); //身份证信息
  456. clientIDInfo ??= new Crm_CustomerCert();
  457. var Company = CompanyArr.FirstOrDefault(x => x.Id == clientInfo.CrmCompanyId);
  458. Company ??= new Crm_CustomerCompany();
  459. param.IDCardNo = clientIDInfo.CertNo;
  460. param.Remark = item.Remark;
  461. param.BirthDay = clientInfo.BirthDay == null ? "" : DateTime.TryParse(Convert.ToDateTime(clientInfo.BirthDay).ToString("yyyy-MM-dd"), out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  462. param.FirstName = clientInfo.FirstName;
  463. param.LastName = clientInfo.LastName;
  464. param.CompanyFullName = Company.CompanyFullName;
  465. param.Job = clientInfo.Job;
  466. param.Sex = clientInfo.Sex;
  467. param.Phone = clientInfo.Phone;
  468. param.Pinyin = clientInfo.Pinyin;
  469. param.HotelSpecialNeeds = item.HotelSpecialNeeds;
  470. param.MealSpecialNeeds = item.MealSpecialNeeds;
  471. param.ShippingSpaceSpecialNeeds = item.ShippingSpaceSpecialNeeds;
  472. param.ShippingSpaceTypeId = item.ShippingSpaceTypeId;
  473. param.Id = item.Id;
  474. EncryptionProcessor.DecryptProperties(param);
  475. TourClientListInfoArr.Add(param);
  476. }
  477. GroupProcessOperationDtoParam.PortType = dto.PortType;
  478. GroupProcessOperationDtoParam.TourClientListInfos = TourClientListInfoArr;
  479. GroupProcessOperationDtoParam.VisitDate = DateTime.TryParse(GroupProcessOperationDtoParam.VisitDate, out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  480. GroupProcessOperationDtoParam.TontractTime = DateTime.TryParse(GroupProcessOperationDtoParam.TontractTime, out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  481. result.Data = GroupProcessOperationDtoParam;
  482. }
  483. }
  484. else result.Msg = "暂无该团组信息";
  485. }
  486. return result;
  487. }
  488. /// <summary>
  489. /// 获取接团信息 编辑
  490. /// 城市基础 数据源
  491. /// </summary>
  492. /// <param name="dto"></param>
  493. /// <returns></returns>
  494. public async Task<List<CityTree>> ProvinceCityBasicSource()
  495. {
  496. var data = await _sqlSugar.Queryable<CityTree>().AS("Sys_Cities")
  497. .Where(x => x.IsDel == 0 && x.CountriesId == 44)
  498. .ToTreeAsync(it => it.Child, it => it.ParentId, 0);
  499. if (data.Any())
  500. {
  501. //移动指定数据在最前面
  502. data = MoveElementToFront(data, "云南");
  503. data = MoveElementToFront(data, "贵州");
  504. data = MoveElementToFront(data, "重庆");
  505. data = MoveElementToFront(data, "四川");
  506. }
  507. return data;
  508. }
  509. /// <summary>
  510. /// 获取接团信息 编辑
  511. /// 省份基础 数据源
  512. /// </summary>
  513. /// <param name="dto"></param>
  514. /// <returns></returns>
  515. public async Task<GroupCityBasicSourceView[]> ProvinceBasicSource()
  516. {
  517. var list = Array.Empty<GroupCityBasicSourceView>();
  518. var data = await ProvinceCityBasicSource();
  519. if (data.Any())
  520. {
  521. //移动指定数据在最前面
  522. data = MoveElementToFront(data, "北京");
  523. data = MoveElementToFront(data, "云南");
  524. data = MoveElementToFront(data, "贵州");
  525. data = MoveElementToFront(data, "重庆");
  526. data = MoveElementToFront(data, "四川");
  527. list = data.Select(x => new GroupCityBasicSourceView() { Id = x.Id, Name = x.Name_CN }).ToArray();
  528. }
  529. return list;
  530. }
  531. /// <summary>
  532. /// 获取接团信息 编辑
  533. /// 城市基础 数据源
  534. /// </summary>
  535. /// <param name="dto"></param>
  536. /// <returns></returns>
  537. public async Task<GroupCityBasicSourceView[]> CityBasicSource()
  538. {
  539. var list = new List<GroupCityBasicSourceView>();
  540. var data = await ProvinceCityBasicSource();
  541. if (data.Any())
  542. {
  543. //移动指定数据在最前面
  544. data = MoveElementToFront(data, "云南");
  545. data = MoveElementToFront(data, "贵州");
  546. data = MoveElementToFront(data, "重庆");
  547. data = MoveElementToFront(data, "四川");
  548. foreach (var province in data)
  549. {
  550. foreach (var city in province.Child)
  551. {
  552. list.Add(new GroupCityBasicSourceView()
  553. {
  554. Id = city.Id,
  555. Name = $"{province.Name_CN}-{city.Name_CN}"
  556. });
  557. }
  558. }
  559. //四川成都放在最前面
  560. var cdInfo = list.FirstOrDefault(x => x.Name.Equals("四川-成都"));
  561. if (cdInfo != null)
  562. {
  563. list.Remove(cdInfo);
  564. list.Insert(0, cdInfo);
  565. }
  566. }
  567. return list.ToArray();
  568. }
  569. /// <summary>
  570. /// 获取接团信息 编辑
  571. /// 基础 数据源
  572. /// </summary>
  573. /// <param name="dto"></param>
  574. /// <returns></returns>
  575. public async Task<GroupCityBasicSourceView> CityInfoById(int id)
  576. {
  577. var list = await CityBasicSource();
  578. var info = list.FirstOrDefault(x => x.Id == id);
  579. return info;
  580. }
  581. private static List<CityTree> MoveElementToFront(List<CityTree> list, string elementName)
  582. {
  583. var element = list.FirstOrDefault(x => x.Name_CN == elementName);
  584. if (element != null)
  585. {
  586. list.Remove(element);
  587. list.Insert(0, element);
  588. }
  589. return list;
  590. }
  591. /// <summary>
  592. /// 获取接团信息 编辑
  593. /// 基础 数据源
  594. /// </summary>
  595. /// <param name="dto"></param>
  596. /// <returns></returns>
  597. public async Task<Result> GroupEditBasicSource(GroupListDto dto)
  598. {
  599. var result = new Result() { Code = -2, Msg = "未知错误" };
  600. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  601. {
  602. dynamic? teamTypeData1 = null;
  603. string teamTypeSql = string.Format(@"Select Id,Name From Sys_SetData Where STid = {0} And IsDel = {1}", 10, 0);
  604. var teamTypeData = await _sqlSugar.SqlQueryable<SetDataInfoView>(teamTypeSql).ToListAsync(); ; //团组分类 10
  605. if (teamTypeData.Any())
  606. {
  607. teamTypeData1 = teamTypeData;
  608. if (teamTypeData.Any(x => x.Name.Equals("前期沟通")))
  609. {
  610. var info = teamTypeData.Find(x => x.Name.Equals("前期沟通"));
  611. if (info != null)
  612. {
  613. teamTypeData.Remove(info);
  614. teamTypeData.Insert(2, info);
  615. }
  616. }
  617. }
  618. dynamic? teamLevData1 = null;
  619. string teamLevSql = string.Format(@"Select Id,Name From Sys_SetData Where STid = {0} And IsDel = {1}", 56, 0);
  620. var teamLevData = await _sqlSugar.SqlQueryable<SetDataInfoView>(teamLevSql).ToListAsync(); ; //团组等级 56
  621. if (teamLevData.Any())
  622. {
  623. teamLevData1 = teamLevData;
  624. }
  625. dynamic? userData1 = null;
  626. string userSql = string.Format(@"Select Id,CnName From Sys_Users Where IsDel = {0}", 0);
  627. var userData = await _sqlSugar.SqlQueryable<UserNameView>(userSql).ToListAsync();
  628. if (userData.Any())
  629. {
  630. userData1 = userData;
  631. }
  632. //客户单位数据源 来源市场客户资料
  633. dynamic? clientData1 = null;
  634. string clientSql = $@"Select Client,Contact,Telephone,WeChat From Crm_NewClientData Where IsDel = 0";
  635. var clientData = await _sqlSugar.SqlQueryable<Crm_NewClientData>(clientSql).ToListAsync();
  636. if (clientData.Any())
  637. {
  638. clientData1 = clientData.Select(it => new
  639. {
  640. Client = AesEncryptionHelper.Decrypt(it.Client),
  641. Contact = AesEncryptionHelper.Decrypt(it.Contact),
  642. Telephone = AesEncryptionHelper.Decrypt(it.Telephone),
  643. Wechat = AesEncryptionHelper.Decrypt(it.Wechat)
  644. }).ToList();
  645. }
  646. var userDepDatas = new List<TextView>();
  647. userDepDatas.Insert(0, new TextView() { Text = "全部", Value = "全部" });
  648. userDepDatas.Insert(1, new TextView() { Text = "国交部", Value = "国交部" });
  649. userDepDatas.Insert(2, new TextView() { Text = "市场部", Value = "市场部" });
  650. userDepDatas.Insert(3, new TextView() { Text = "策划部", Value = "策划部" });
  651. 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();
  652. rankDatas.Insert(0, new TextView { Value = "0", Text = "全部" });
  653. result.Code = 0;
  654. result.Msg = "成功!";
  655. result.Data = new
  656. {
  657. teamTypeData = teamTypeData1,
  658. teamLevData = teamLevData1,
  659. userData = userData1,
  660. clientData = clientData1,
  661. depData = userDepDatas,
  662. rankData = rankDatas,
  663. cityData = await CityBasicSource()
  664. };
  665. }
  666. return result;
  667. }
  668. /// <summary>
  669. /// 团组信息操作
  670. /// </summary>
  671. /// <param name="dto"></param>
  672. /// <returns></returns>
  673. public async Task<Result> GroupOperation(GroupOperationDto dto)
  674. {
  675. var result = new Result() { Code = -2, Msg = "未知错误" };
  676. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  677. {
  678. #region 添加出访起止时间
  679. var startTime = new DateTime();
  680. var endTime = new DateTime();
  681. if (DateTime.TryParse(dto.VisitDate, out startTime))
  682. {
  683. endTime = startTime.AddDays(dto.VisitDays - 1);//含当天
  684. }
  685. #endregion
  686. if (dto.Status == 1) //添加
  687. {
  688. string selectSql = string.Format(@"Select * From Grp_DelegationInfo
  689. Where IsDel = 0
  690. And TeamName = '{0}'
  691. And ClientName = '{1}'
  692. And ClientUnit ='{2}'
  693. And VisitDate ='{3}'", dto.TeamName, dto.ClientName, dto.ClientUnit, dto.VisitDate);
  694. var selectGroupInfo = _sqlSugar.SqlQueryable<Grp_DelegationInfo>(selectSql).First();
  695. if (selectGroupInfo != null)
  696. {
  697. result.Msg = "数据已存在,请勿重复添加!";
  698. return result;
  699. }
  700. //string teamCodeSql = string.Format("Select SalesQuoteNo From Grp_DelegationInfo");
  701. //var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  702. //string SalesQuoteNo = "";
  703. //while (true)
  704. //{
  705. // SalesQuoteNo = Tools.CommonFun.GetRandomStr(6);
  706. // if (!teamCodeItem.Equals(SalesQuoteNo))
  707. // {
  708. // break;
  709. // }
  710. //}
  711. string countrys = string.Empty;
  712. string countryReq = dto.VisitCountry;
  713. if (!string.IsNullOrEmpty(countryReq))
  714. {
  715. if (countryReq.Contains(",")) countrys = countryReq.Replace(',', '|');
  716. else if (countryReq.Contains(",")) countrys = countryReq.Replace(',', '|');
  717. else if (countryReq.Contains(" ")) countrys = countryReq.Replace(' ', '|');
  718. else if (countryReq.Contains("、")) countrys = countryReq.Replace('、', '|');
  719. else if (countryReq.Contains(".")) countrys = countryReq.Replace('.', '|');
  720. else countrys = countryReq;
  721. }
  722. //建团时 默认出团 设置 团组code
  723. string teamCode = "";
  724. string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
  725. var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  726. while (true)
  727. {
  728. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  729. if (!teamCodeItem.Equals(teamCode))
  730. {
  731. break;
  732. }
  733. }
  734. var delegationInfo = new Grp_DelegationInfo()
  735. {
  736. CityId = dto.CityId,
  737. SalesQuoteNo = dto.SalesQuoteNo,
  738. TeamLevSId = dto.TeamLevSId,
  739. ClientName = dto.ClientName,
  740. ClientUnit = dto.ClientUnit,
  741. TeamName = dto.TeamName,
  742. TeamDid = dto.TeamDid,
  743. VisitDate = Convert.ToDateTime(dto.VisitDate),
  744. VisitCountry = countrys,
  745. VisitPurpose = dto.VisitPurpose,
  746. VisitDays = dto.VisitDays,
  747. VisitPNumber = dto.VisitPNumber,
  748. SpecialNeeds = dto.SpecialNeeds,
  749. OtherNeeds = dto.OtherNeeds,
  750. Remark = dto.Remark,
  751. JietuanOperator = dto.JietuanOperator,
  752. TellPhone = dto.TellPhone,
  753. WeChatNo = dto.WeChatNo,
  754. CGRWSPBMMC = dto.CGRWSPBMMC,
  755. CGRWSPWH = dto.CGRWSPWH,
  756. ZZSCBMMC = dto.ZZSCBMMC,
  757. ZZSCSPWH = dto.ZZSCSPWH,
  758. TontractTime = string.IsNullOrEmpty(dto.TontractTime) ? null : Convert.ToDateTime(dto.TontractTime),
  759. IsBid = dto.IsBid,
  760. PaymentMoney = dto.PaymentMoney,
  761. PayDay = dto.PayDay,
  762. TourCode = teamCode,
  763. GroupsOperator = dto.UserId,
  764. GroupsTime = DateTime.Now,
  765. SalesDate = DateTime.Now,
  766. IsState = 0, //默认团组未完成 0
  767. JietuanTime = DateTime.Now,
  768. IsDel = 0,
  769. BudgetCost = 0.00M,
  770. HotelComplain = 0,
  771. OPComplain = 0,
  772. OAComplain = 0,
  773. AirComplain = 0,
  774. VisaComplain = 0,
  775. CreateUserId = dto.UserId,
  776. CreateTime = DateTime.Now,
  777. DeleteUserId = null,
  778. DeleteTime = new DateTime(1990, 1, 1).ToString("yyyy-MM-dd HH:mm:ss"),
  779. OpRoyaltyLv = dto.OpRoyaltyLv,
  780. OpRoyaltyRemark = dto.opRoyaltyRemark,
  781. Officialneeds = dto.Officialneeds,
  782. VisitStartDate = startTime,
  783. VisitEndDate = endTime,
  784. };
  785. var addId = _sqlSugar.Insertable(delegationInfo).ExecuteReturnIdentity();
  786. if (addId > 0)
  787. {
  788. result.Code = 0;
  789. result.Msg = "添加成功!";
  790. result.Data = addId;
  791. }
  792. else
  793. {
  794. result.Msg = "添加失败!";
  795. }
  796. }
  797. else if (dto.Status == 2) //修改
  798. {
  799. var updateStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo
  800. {
  801. CityId = dto.CityId,
  802. SalesQuoteNo = dto.SalesQuoteNo,
  803. TeamLevSId = dto.TeamLevSId,
  804. ClientName = dto.ClientName,
  805. ClientUnit = dto.ClientUnit,
  806. TeamName = dto.TeamName,
  807. TeamDid = dto.TeamDid,
  808. VisitDate = Convert.ToDateTime(dto.VisitDate),
  809. VisitCountry = dto.VisitCountry,
  810. VisitPurpose = dto.VisitPurpose,
  811. VisitDays = dto.VisitDays,
  812. VisitPNumber = dto.VisitPNumber,
  813. SpecialNeeds = dto.SpecialNeeds,
  814. OtherNeeds = dto.OtherNeeds,
  815. Remark = dto.Remark,
  816. JietuanOperator = dto.JietuanOperator,
  817. TellPhone = dto.TellPhone,
  818. WeChatNo = dto.WeChatNo,
  819. CGRWSPBMMC = dto.CGRWSPBMMC,
  820. CGRWSPWH = dto.CGRWSPWH,
  821. ZZSCBMMC = dto.ZZSCBMMC,
  822. ZZSCSPWH = dto.ZZSCSPWH,
  823. TontractTime = string.IsNullOrEmpty(dto.TontractTime) ? null : Convert.ToDateTime(dto.TontractTime),
  824. IsBid = dto.IsBid,
  825. PaymentMoney = dto.PaymentMoney,
  826. PayDay = dto.PayDay,
  827. OpRoyaltyLv = dto.OpRoyaltyLv,
  828. OpRoyaltyRemark = dto.opRoyaltyRemark,
  829. Officialneeds = dto.Officialneeds,
  830. VisitStartDate = startTime,
  831. VisitEndDate = endTime,
  832. });
  833. if (updateStatus)
  834. {
  835. result.Code = 0;
  836. result.Msg = "修改成功!";
  837. }
  838. else
  839. {
  840. result.Msg = "修改失败!";
  841. }
  842. }
  843. else if (dto.Status == 3) //删除
  844. {
  845. var deleteStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo
  846. {
  847. DeleteUserId = dto.UserId,
  848. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  849. IsDel = 1
  850. });
  851. if (deleteStatus)
  852. {
  853. result.Code = 0;
  854. result.Msg = "删除成功!";
  855. }
  856. else
  857. {
  858. result.Msg = "删除失败!";
  859. }
  860. }
  861. }
  862. return result;
  863. }
  864. /// <summary>
  865. /// 团组信息操作 - 删除
  866. /// </summary>
  867. /// <param name="dto"></param>
  868. /// <returns></returns>
  869. public async Task<Result> GroupDel(GroupDelDto dto)
  870. {
  871. var result = new Result() { Code = -2, Msg = "未知错误" };
  872. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  873. {
  874. var deleteStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo
  875. {
  876. DeleteUserId = dto.UserId,
  877. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  878. IsDel = 1
  879. });
  880. if (deleteStatus)
  881. {
  882. result.Code = 0;
  883. result.Msg = "删除成功!";
  884. }
  885. else
  886. {
  887. result.Msg = "删除失败!";
  888. }
  889. }
  890. return result;
  891. }
  892. /// <summary>
  893. /// 获取销售报价号
  894. /// </summary>
  895. /// <returns></returns>
  896. public async Task<Result> GetGroupSalesQuoteNo()
  897. {
  898. var result = new Result() { Code = -2, Msg = "未知错误" };
  899. string teamCodeSql = string.Format("Select SalesQuoteNo From Grp_DelegationInfo");
  900. var teamCodeItem = await _sqlSugar.SqlQueryable<SalesQuoteNoView>(teamCodeSql).ToListAsync();
  901. string teamCode;
  902. while (true)
  903. {
  904. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  905. if (!teamCodeItem.Equals(teamCode))
  906. {
  907. break;
  908. }
  909. }
  910. result.Code = 0;
  911. result.Msg = "成功!";
  912. result.Data = teamCode;
  913. return result;
  914. }
  915. /// <summary>
  916. /// 团组删除
  917. /// </summary>
  918. /// <returns></returns>
  919. public async Task<Result> GroupDeleteById()
  920. {
  921. var result = new Result() { Code = -2, Msg = "未知错误" };
  922. string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
  923. var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  924. string teamCode;
  925. while (true)
  926. {
  927. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  928. if (!teamCodeItem.Equals(teamCode))
  929. {
  930. break;
  931. }
  932. }
  933. result.Code = 0;
  934. result.Msg = "成功!";
  935. result.Data = teamCode;
  936. return result;
  937. }
  938. /// <summary>
  939. /// 团组确认出团
  940. /// </summary>
  941. /// <returns></returns>
  942. public async Task<Result> ConfirmationGroup(ConfirmationGroupDto dto)
  943. {
  944. var result = new Result() { Code = -2, Msg = "未知错误" };
  945. string teamCode = "";
  946. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  947. {
  948. string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
  949. var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  950. while (true)
  951. {
  952. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  953. if (!teamCodeItem.Equals(teamCode))
  954. {
  955. break;
  956. }
  957. }
  958. var deleteStatus = await UpdateAsync(a => a.Id == dto.GroupId, a => new Grp_DelegationInfo
  959. {
  960. TourCode = teamCode,
  961. GroupsOperator = dto.GroupsOperator,
  962. GroupsTime = DateTime.Now
  963. });
  964. if (deleteStatus)
  965. {
  966. result.Code = 0;
  967. result.Msg = "确认出团设置成功!";
  968. }
  969. else
  970. {
  971. result.Msg = "确认出团设置失败!";
  972. }
  973. }
  974. result.Code = 0;
  975. result.Msg = "成功!";
  976. result.Data = teamCode;
  977. return result;
  978. }
  979. /// <summary>
  980. /// 获取接团名称List
  981. /// </summary>
  982. /// <param name="dto"></param>
  983. /// <returns></returns>
  984. public async Task<JsonView> GetGroupNameList(GroupNameDto dto)
  985. {
  986. var view = new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "操作失败!" };
  987. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  988. {
  989. //2025-02-17 更改团组列表排序功能 按照团出访时间排序(降序)
  990. string sql = string.Format(@"Select Id,TeamName GroupName From Grp_DelegationInfo
  991. Where TeamName != '' And IsDel = 0
  992. Order By VisitStartDate Desc");
  993. var _groupNameList = await _sqlSugar.SqlQueryable<GroupNameView>(sql).ToListAsync();
  994. if (_groupNameList.Any())
  995. {
  996. for (int i = 0; i < _groupNameList.Count; i++)
  997. {
  998. var info = _groupNameList[i];
  999. _groupNameList[i].GroupName = FormartTeamName(info.GroupName);
  1000. }
  1001. //_groupNameList.Insert(0, new GroupNameView() { Id = 0, GroupName = "未选择" });
  1002. view.Code = StatusCodes.Status200OK;
  1003. view.Msg = "成功!";
  1004. view.Data = _groupNameList;
  1005. }
  1006. else
  1007. {
  1008. view.Msg = "暂无团组信息";
  1009. }
  1010. }
  1011. return view;
  1012. }
  1013. //PostGroupNameScreen
  1014. /// <summary>
  1015. /// 获取接团名称 Page List
  1016. /// </summary>
  1017. /// <param name="dto"></param>
  1018. /// <returns></returns>
  1019. public async Task<JsonView> GetGroupNameList(int portType, int pageIndex, int pageSize, string groupName, int userId)
  1020. {
  1021. var _res = new JsonView() { Code = 400, Msg = MsgTips.Fail };
  1022. string sql = "";
  1023. string sqlWhere = "";
  1024. string mobileSqlWhere = "";
  1025. if (!string.IsNullOrEmpty(groupName))
  1026. {
  1027. sqlWhere += string.Format($@"And TeamName Like '%{groupName}%'");
  1028. mobileSqlWhere += string.Format($@"GroupName Like '%{groupName}%'");
  1029. }
  1030. var userIds = new List<int>() { -1, 21 };
  1031. if (!userIds.Contains(userId))
  1032. {
  1033. sqlWhere += string.Format($@"And JietuanOperator = {userId}");
  1034. }
  1035. sql = string.Format($@"Select ROW_NUMBER()Over(Order By Id Desc) as RowNumber,Id,TeamName GroupName From Grp_DelegationInfo
  1036. Where IsDel = 0 {sqlWhere}");
  1037. if (portType == 1) //web
  1038. { }
  1039. else if (portType == 2 || portType == 3)
  1040. {
  1041. //国交部 7 (主管 22,经理 32)团操操作权限 市场部 6 接团人
  1042. var userInfo = await _sqlSugar.Queryable<Sys_Users>().Where(it => it.Id == userId && it.IsDel == 0).FirstAsync();
  1043. if (userInfo != null)
  1044. {
  1045. if (userInfo.DepId == 7)
  1046. {
  1047. if (userInfo.JobPostId != 22 || userInfo.JobPostId != 32)
  1048. {
  1049. if (!string.IsNullOrEmpty(mobileSqlWhere)) mobileSqlWhere = $" Where {mobileSqlWhere}";
  1050. sql = string.Format($@"Select
  1051. ROW_NUMBER()Over(Order By Id Desc) as RowNumber,
  1052. Id,
  1053. GroupName
  1054. From (
  1055. Select
  1056. distinct
  1057. di.Id,
  1058. di.TeamName GroupName
  1059. From Grp_GroupsTaskAssignment gta With(NoLock)
  1060. Inner Join Grp_DelegationInfo di With(NoLock) On gta.DIId = di.Id
  1061. Where gta.IsDel = 0 And di.IsDel = 0 And gta.UId = {userId}
  1062. ) Temp {mobileSqlWhere}");
  1063. }
  1064. }
  1065. }
  1066. }
  1067. RefAsync<int> total = 0;
  1068. var groupNamePageData = await _sqlSugar.SqlQueryable<GroupNamePageView>(sql).ToPageListAsync(pageIndex, pageSize, total);
  1069. _res.Code = 200;
  1070. _res.Data = groupNamePageData;
  1071. _res.Msg = MsgTips.Succeed;
  1072. _res.Count = total;
  1073. return _res;
  1074. }
  1075. /// <summary>
  1076. /// 获取接团名称List And 签证国别
  1077. /// </summary>
  1078. /// <param name="dto"></param>
  1079. /// <returns></returns>
  1080. public async Task<Result> GetGroupNameAndVisaNationality(GroupNameDto dto)
  1081. {
  1082. var result = new Result() { Code = -2, Msg = "未知错误" };
  1083. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  1084. {
  1085. string sql = string.Format(@"Select Id,TeamName GroupName From Grp_DelegationInfo
  1086. Where TeamName != '' And IsDel = 0
  1087. Order By VisitDate Desc");
  1088. var _groupNameList = await _sqlSugar.SqlQueryable<GroupNameView>(sql).ToListAsync();
  1089. string visaSql = string.Format(@"Select Id,Name From Sys_SetData Where STid = 41 And IsDel = 0");
  1090. var _setDataList = await _sqlSugar.SqlQueryable<SetDataInfoView>(visaSql).ToListAsync();
  1091. var data = new
  1092. {
  1093. groupNameData = _groupNameList,
  1094. visaNationalityData = _setDataList
  1095. };
  1096. result.Data = data;
  1097. result.Code = 0;
  1098. }
  1099. return result;
  1100. }
  1101. #endregion
  1102. #region 团组&签证
  1103. /// <summary>
  1104. /// 根据团组Id查询客户
  1105. /// </summary>
  1106. /// <param name="dto"></param>
  1107. /// <returns></returns>
  1108. public async Task<Result> GetCrmByGroupId(ClientByGroupIdDto dto)
  1109. {
  1110. var result = new Result() { Code = -2 };
  1111. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3)
  1112. {
  1113. var clientInfos = await _sqlSugar.Queryable<Grp_TourClientList>().Where(x => x.IsDel == 0 && x.DiId == dto.GroupId).ToListAsync();
  1114. var clientIds = clientInfos.Select(x => x.ClientId).ToList();
  1115. var visaClientInfos = await _sqlSugar.Queryable<Crm_DeleClient>().Where(x => x.IsDel == 0 && clientIds.Contains(x.Id))
  1116. .Select(x => new Crm_DeleClient
  1117. {
  1118. DiId = dto.GroupId,
  1119. Id = x.Id,
  1120. FirstName = x.FirstName,
  1121. LastName = x.LastName,
  1122. Tel = x.Tel
  1123. })
  1124. .ToListAsync();
  1125. var clientCertInfos = await _sqlSugar.Queryable<Crm_CustomerCert>().Where(x => x.IsDel == 0 && x.SdId == 773 && clientIds.Contains(x.DcId))
  1126. .Select(x => new Crm_CustomerCert
  1127. {
  1128. DcId = x.DcId,
  1129. CertNo = x.CertNo
  1130. })
  1131. .ToListAsync();
  1132. //解密
  1133. foreach (var item in visaClientInfos)
  1134. {
  1135. EncryptionProcessor.DecryptProperties(item);
  1136. }
  1137. //信息整合
  1138. var view = new List<CrmByGroupIdView>();
  1139. foreach (var item in visaClientInfos)
  1140. {
  1141. var idNo = AesEncryptionHelper.Decrypt(clientCertInfos.FirstOrDefault(x => x.DcId == item.Id)?.CertNo ?? "") ?? "-";
  1142. if (string.IsNullOrEmpty(idNo)) idNo = "-";
  1143. view.Add(new() {
  1144. GrpId = dto.GroupId,
  1145. ClientName = item.LastName + item.FirstName,
  1146. Tel = item.Tel ?? "-",
  1147. CerdNo = idNo
  1148. });
  1149. }
  1150. if (view.Count > 0)
  1151. {
  1152. result.Code = 0;
  1153. result.Msg = "成功!";
  1154. result.Data = view;
  1155. }
  1156. else
  1157. {
  1158. result.Code = 1;
  1159. result.Msg = "暂无数据!";
  1160. }
  1161. }
  1162. return result;
  1163. }
  1164. #endregion
  1165. #region 团组&出入境费用
  1166. /// <summary>
  1167. /// 获取单组名称并验证出入境费用明细是否填写
  1168. /// </summary>
  1169. /// <param name="dto"></param>
  1170. /// <returns></returns>
  1171. public async Task<EnterExitCostGroupNameView[]> EnterExitCostGroupNameAsync()
  1172. {
  1173. var groupSql = string.Format(@$"SELECT
  1174. Id,
  1175. TeamName GroupName,
  1176. CityId ProvinceId,
  1177. CASE
  1178. WHEN (
  1179. SELECT
  1180. COUNT(*)
  1181. FROM
  1182. Grp_EnterExitCost
  1183. WHERE
  1184. IsDel = 0
  1185. AND DiId = di.Id
  1186. ) > 0 THEN 'false'
  1187. ELSE 'true'
  1188. END AS [IsNull]
  1189. FROM
  1190. Grp_DelegationInfo di
  1191. WHERE
  1192. di.Isdel = 0
  1193. ORDER BY
  1194. VisitStartDate Desc");
  1195. var groupDatas = await _sqlSugar.SqlQueryable<EnterExitCostGroupNameView>(groupSql).ToArrayAsync();
  1196. var provCityDatas = await ProvinceCityBasicSource();
  1197. if (provCityDatas.Any() && groupDatas.Any())
  1198. {
  1199. foreach (var item in groupDatas)
  1200. {
  1201. var provinceId = item.ProvinceId;
  1202. var isDefualtVal = true;
  1203. if (provinceId > 0)
  1204. {
  1205. var parentId = FindParentIdByChildId(provCityDatas, provinceId);
  1206. if (parentId != null)
  1207. {
  1208. isDefualtVal = false;
  1209. item.ProvinceId = (int)parentId;
  1210. }
  1211. }
  1212. if (isDefualtVal)
  1213. {
  1214. item.ProvinceId = 122; //默认四川
  1215. }
  1216. }
  1217. }
  1218. return groupDatas;
  1219. }
  1220. /// <summary>
  1221. /// 获取单组名称并验证出入境费用明细是否填写
  1222. /// </summary>
  1223. /// <param name="dto"></param>
  1224. /// <returns></returns>
  1225. public async Task<EnterExitCostGroupNameView> EnterExitCostGroupNameInfoAsync(int groupId)
  1226. {
  1227. var groupSql = string.Format(@$"SELECT
  1228. Id,
  1229. TeamName GroupName,
  1230. CityId ProvinceId,
  1231. CASE
  1232. WHEN (
  1233. SELECT
  1234. COUNT(*)
  1235. FROM
  1236. Grp_EnterExitCost
  1237. WHERE
  1238. IsDel = 0
  1239. AND DiId = di.Id
  1240. ) > 0 THEN 'false'
  1241. ELSE 'true'
  1242. END AS [IsNull]
  1243. FROM
  1244. Grp_DelegationInfo di
  1245. WHERE
  1246. di.Isdel = 0
  1247. And Id = {groupId} ");
  1248. var groupData = await _sqlSugar.SqlQueryable<EnterExitCostGroupNameView>(groupSql).FirstAsync();
  1249. var provCityDatas = await ProvinceCityBasicSource();
  1250. if (provCityDatas.Any() && groupData != null)
  1251. {
  1252. var provinceId = groupData.ProvinceId;
  1253. var isDefualtVal = true;
  1254. if (provinceId > 0)
  1255. {
  1256. var parentId = FindParentIdByChildId(provCityDatas, provinceId);
  1257. if (parentId != null)
  1258. {
  1259. isDefualtVal = false;
  1260. groupData.ProvinceId = (int)parentId;
  1261. }
  1262. }
  1263. if (isDefualtVal)
  1264. {
  1265. groupData.ProvinceId = 0; //
  1266. }
  1267. }
  1268. return groupData;
  1269. }
  1270. /// <summary>
  1271. /// 递归地遍历树状结构,查找子项的父类 Id。
  1272. /// </summary>
  1273. /// <param name="tree"></param>
  1274. /// <param name="childId"></param>
  1275. /// <returns></returns>
  1276. public int? FindParentIdByChildId(List<CityTree> tree, int childId)
  1277. {
  1278. foreach (var node in tree)
  1279. {
  1280. if (node.Child != null && node.Child.Any())
  1281. {
  1282. if (node.Child.Any(c => c.Id == childId))
  1283. {
  1284. return node.Id;
  1285. }
  1286. var parentId = FindParentIdByChildId(node.Child, childId);
  1287. if (parentId.HasValue)
  1288. {
  1289. return parentId;
  1290. }
  1291. }
  1292. }
  1293. return null;
  1294. }
  1295. #endregion
  1296. }
  1297. }