DelegationInfoRepository.cs 62 KB

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