DelegationInfoRepository.cs 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224
  1. using AutoMapper;
  2. using Newtonsoft.Json;
  3. using NPOI.OpenXmlFormats.Wordprocessing;
  4. using NPOI.SS.Formula.Functions;
  5. using OASystem.Domain;
  6. using OASystem.Domain.AesEncryption;
  7. using OASystem.Domain.Dtos;
  8. using OASystem.Domain.Dtos.Financial;
  9. using OASystem.Domain.Dtos.Groups;
  10. using OASystem.Domain.Dtos.UserDto;
  11. using OASystem.Domain.Entities.Customer;
  12. using OASystem.Domain.Entities.Groups;
  13. using OASystem.Domain.ViewModels.CRM;
  14. using OASystem.Domain.ViewModels.Financial;
  15. using OASystem.Domain.ViewModels.Groups;
  16. using OASystem.Infrastructure.Repositories.System;
  17. using Org.BouncyCastle.Asn1.Cms;
  18. using Org.BouncyCastle.Utilities.Collections;
  19. using Serilog;
  20. using SqlSugar;
  21. using System;
  22. using System.Collections.Generic;
  23. using System.Linq;
  24. using System.Text;
  25. using System.Threading.Tasks;
  26. namespace OASystem.Infrastructure.Repositories.Groups
  27. {
  28. /// <summary>
  29. /// 接团信息
  30. /// </summary>
  31. public class DelegationInfoRepository : BaseRepository<Grp_DelegationInfo, DelegationInfoView>
  32. {
  33. private readonly SetDataRepository _setDataRepository;
  34. private readonly UsersRepository _usersRepository;
  35. private readonly TaskAssignmentRepository _taskAssignmentRep;
  36. private readonly IMapper _mapper;
  37. //private readonly TeamRateRepository _teamRateRep;
  38. //public readonly Logs _logs;
  39. public DelegationInfoRepository(SqlSugarClient sqlSugar, SetDataRepository setDataRepository, UsersRepository usersRepository,
  40. TaskAssignmentRepository taskAssignmentRep, IMapper mapper)
  41. : base(sqlSugar)
  42. {
  43. _setDataRepository = setDataRepository;
  44. _usersRepository = usersRepository;
  45. _taskAssignmentRep = taskAssignmentRep;
  46. _mapper = mapper;
  47. //_teamRateRep = teamRateRep;
  48. }
  49. #region 团组信息 团组详情共享Api
  50. /// <summary>
  51. /// 查询团组简略详情列表
  52. /// Page 根据Ctable And User 返回可操作的团
  53. /// </summary>
  54. /// <param name="dto"></param>
  55. /// <returns></returns>
  56. public async Task<JsonView> ListByCTableAndUserId(GroupListByCTableAndUserIdDto dto)
  57. {
  58. var view = new JsonView() { Code = StatusCodes.Status400BadRequest,Msg="操作失败!" };
  59. if (dto.CTable < 1)
  60. {
  61. view.Msg = MsgTips.UserId;
  62. return view;
  63. }
  64. if (dto.CTable < 1)
  65. {
  66. view.Msg = "请输入正确的CTable Id !76 酒店预订<br/>77 行程<br/>79 车/导游地接<br/>80 签证<br/>81 邀请/公务活动<br/>82 团组客户保险<br/>85 机票预订<br/>98 其他款项<br/>751 酒店早餐";
  67. return view;
  68. }
  69. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3)
  70. {
  71. //2025-02-17 更改团组列表排序功能 按照团出访时间排序(降序)
  72. string sql = string.Format(@"Select row_number() over(order by di.VisitStartDate Desc) as Row_Number,
  73. di.Id,di.TeamName,di.TourCode,di.ClientName,di.VisitCountry,di.VisitStartDate,
  74. di.VisitEndDate,di.VisitDays,di.VisitPNumber,di.CreateTime
  75. From Grp_GroupsTaskAssignment gta
  76. Inner Join Grp_DelegationInfo di On gta.DIId = di.Id
  77. Where gta.IsDel = 0 And di.IsDel = 0 And gta.IsEnable = 1
  78. And gta.CTId = {0} And gta.UId = {1}", dto.CTable, dto.UserId);
  79. if (!string.IsNullOrEmpty(dto.TeamName))
  80. {
  81. sql = string.Format($"{sql} And di.TeamName Like '%{dto.TeamName}%'");
  82. }
  83. //去重
  84. sql = $"{sql} GROUP BY di.Id,di.TeamName,di.TourCode,di.ClientName,di.VisitCountry,di.VisitStartDate,di.VisitEndDate,di.VisitDays,di.VisitPNumber,di.CreateTime";
  85. RefAsync<int> total = 0;//REF和OUT不支持异步,想要真的异步这是最优解
  86. var data = await _sqlSugar.SqlQueryable<GroupListByCTableAndUserIdView>(sql).ToPageListAsync(dto.PageIndex, dto.PageSize, total); //ToPageAsync
  87. foreach (var item in data)
  88. {
  89. item.VisitStartDate = item.VisitStartDate == "" ? "" : Convert.ToDateTime(item.VisitStartDate).ToString("yyyy-MM-dd");
  90. item.VisitEndDate = item.VisitEndDate == "" ? "" : Convert.ToDateTime(item.VisitEndDate).ToString("yyyy-MM-dd");
  91. }
  92. view.Msg = "操作成功!";
  93. view.Data = data;
  94. view.Count = total;
  95. return view;
  96. }
  97. else
  98. {
  99. view.Msg = "请输入正确的PortType 1 Web 2 Android 3 IOS ";
  100. return view;
  101. }
  102. }
  103. /// <summary>
  104. /// 团组信息 团组预览详情共享Api
  105. /// </summary>
  106. /// <param name="dto"></param>
  107. /// <returns></returns>
  108. public async Task<JsonView> PostShareGroupInfo(ShareGroupInfoDto dto)
  109. {
  110. var view = new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "操作失败!" };
  111. string sql = string.Format(@"Select Id,TeamName,TourCode,ClientName,VisitCountry,VisitStartDate,VisitEndDate,VisitDays,VisitPNumber
  112. From Grp_DelegationInfo Where Id = {0} And IsDel = 0", dto.Id);
  113. if (dto.PortType == 1) //Web
  114. {
  115. var _DelegationInfo = await _sqlSugar.SqlQueryable<Web_ShareGroupInfoView>(sql).FirstAsync();
  116. if (_DelegationInfo != null)
  117. {
  118. _DelegationInfo.VisitCountry = FormartTeamName(_DelegationInfo.VisitCountry);
  119. }
  120. else
  121. {
  122. view.Msg = "暂无该团组信息";
  123. return view;
  124. }
  125. view.Data = _DelegationInfo;
  126. }
  127. else if (dto.PortType == 2 || dto.PortType == 3) //IOS Or Android
  128. {
  129. var _DelegationInfo = await _sqlSugar.SqlQueryable<IOSOrAndroid_ShareGroupInfoView>(sql).FirstAsync();
  130. if (_DelegationInfo != null)
  131. {
  132. _DelegationInfo.VisitCountry = FormartTeamName(_DelegationInfo.VisitCountry);
  133. view.Data = _DelegationInfo;
  134. }
  135. else
  136. {
  137. view.Msg = "暂无该团组信息";
  138. return view;
  139. }
  140. view.Data = _DelegationInfo;
  141. }
  142. else
  143. {
  144. view.Msg = "请输入正确的端口号。1 Web 2 Android 3 IOS";
  145. return view;
  146. }
  147. view.Code = StatusCodes.Status200OK;
  148. view.Msg = "成功!";
  149. return view;
  150. }
  151. /// <summary>
  152. /// 团组信息List 团组预览详情共享Api
  153. /// </summary>
  154. /// <param name="dto"></param>
  155. /// <returns></returns>
  156. public async Task<Result> PostShareGroupInfos(int portType)
  157. {
  158. Result result = new Result() { Code = -2, Msg = "未知错误", Data = new List<object>() { } };
  159. string sql = string.Format(@"Select Id,TeamName,TourCode,ClientName,VisitCountry,VisitStartDate,VisitEndDate,VisitDays,VisitPNumber
  160. From Grp_DelegationInfo With(NoLock) Where IsDel = 0 Order By VisitStartDate Desc");
  161. var _DelegationInfo = await _sqlSugar.SqlQueryable<Web_ShareGroupInfoView>(sql).ToListAsync();
  162. if (_DelegationInfo.Count > 0)
  163. {
  164. foreach (var item in _DelegationInfo)
  165. {
  166. item.VisitCountry = FormartTeamName(item.VisitCountry);
  167. }
  168. }
  169. else { result.Msg = "暂无该团组信息"; return result; }
  170. if (portType == 1) //Web
  171. {
  172. result.Data = _DelegationInfo;
  173. }
  174. else if (portType == 2 || portType == 3) //IOS Or Android
  175. {
  176. result.Data = _DelegationInfo;
  177. }
  178. else { result.Msg = "请输入正确的端口号。1 Web 2 Android 3 IOS"; return result; }
  179. result.Code = 0;
  180. result.Msg = "成功!";
  181. return result;
  182. }
  183. #endregion
  184. /// <summary>
  185. /// 获取接团信息Info
  186. /// </summary>
  187. /// <param name="dto"></param>
  188. /// <returns></returns>
  189. public async Task<Result> PostGroupInfo(GroupInfoDto dto)
  190. {
  191. Result result = new Result() { Code = -2, Msg = "未知错误" };
  192. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //Web Or Android
  193. {
  194. string sql = string.Format(@"Select Id,SalesQuoteNo,TourCode,JietuanOperator,TeamLevSId,TeamDid,TeamName,ClientName,
  195. ClientUnit,VisitCountry,VisitDate,VisitDays,VisitPNumber,TontractTime,
  196. PayDay,PaymentMoney,VisitPurpose,SpecialNeeds,OtherNeeds,CGRWSPBMMC,CGRWSPWH,
  197. ZZSCBMMC,ZZSCSPWH,Remark,TellPhone,Officialneeds
  198. From Grp_DelegationInfo Where Id = {0} And IsDel = 0", dto.Id);
  199. var _DelegationInfo = await _sqlSugar.SqlQueryable<DelegationInfoWebView>(sql).FirstAsync();
  200. if (_DelegationInfo != null)
  201. {
  202. _DelegationInfo.TeamName = FormartTeamName(_DelegationInfo.TeamName);
  203. result.Code = 0;
  204. result.Msg = "成功!";
  205. result.Data = _DelegationInfo;
  206. }
  207. else result.Msg = "暂无该团组信息";
  208. }
  209. return result;
  210. }
  211. #region 团组
  212. /// <summary>
  213. /// 统一团组国家分割字符
  214. /// </summary>
  215. /// <param name="teamName"></param>
  216. /// <returns></returns>
  217. public string FormartTeamName(string? teamName)
  218. {
  219. string str = "";
  220. if (!string.IsNullOrEmpty(teamName))
  221. {
  222. str = teamName;
  223. List<string> searchreplaces = new List<string>() { "|", " ", "/", ",", "," };
  224. foreach (var item in searchreplaces)
  225. {
  226. if (str.Contains(item))
  227. {
  228. str = str.Replace(item, "、");
  229. break;
  230. }
  231. }
  232. }
  233. return str.Trim();
  234. }
  235. /// <summary>
  236. /// 团组国家分割字符
  237. /// 返回 国家数组
  238. /// </summary>
  239. /// <param name="teamName"></param>
  240. /// <returns></returns>
  241. public List<string> GroupSplitCountry (string visitCountry)
  242. {
  243. List<string> countrys = new List<string>();
  244. if (!string.IsNullOrEmpty(visitCountry))
  245. {
  246. if (visitCountry.Contains("、")) countrys = visitCountry.Split("、").ToList();
  247. else if (visitCountry.Contains("|")) countrys = visitCountry.Split("|").ToList();
  248. else countrys.Add(visitCountry);
  249. }
  250. return countrys;
  251. }
  252. /// <summary>
  253. /// 获取接团信息 Page List
  254. /// </summary>
  255. /// <param name="dto"></param>
  256. /// <returns></returns>
  257. public async Task<Result> GetGroupPageList(GroupCommissionDto dto)
  258. {
  259. Result result = new Result() { Code = -2, Msg = "未知错误" };
  260. ListViewBase<DelegationPageListView> groupsInfoPageList = new ListViewBase<DelegationPageListView>()
  261. {
  262. ReceiveDt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  263. };
  264. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  265. {
  266. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  267. int endIndex = startIndex + dto.PageSize - 1;
  268. //int taskUserId = -1;
  269. string taskGroupIds = string.Empty;
  270. #region 处理用户团组操作权限
  271. if (dto.UserId != -1)
  272. {
  273. }
  274. #endregion
  275. string sql = string.Format(@"Select * From(Select row_number() over (order by gdi.Id Desc) as RowNumber,
  276. gdi.Id,SalesQuoteNo,TourCode,ssd.Id TeamTypeId, ssd.Name TeamType,ssd1.Id TeamLevId,
  277. ssd1.Name TeamLev,TeamName,ClientName,ClientUnit,VisitDate,VisitDays,VisitPNumber,
  278. su.CnName JietuanOperator,IsSure
  279. From Grp_DelegationInfo gdi
  280. Inner Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  281. Inner Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  282. Left Join Sys_Users su On gdi.CreateUserId = su.Id
  283. Where gdi.IsDel = 0
  284. )temp Where RowNumber Between {0} and {1}", startIndex, endIndex);
  285. string sqlCount = string.Format(@"Select Count(1) as Count From Grp_DelegationInfo gdi
  286. Inner Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  287. Inner Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  288. Left Join Sys_Users su On gdi.CreateUserId = su.Id
  289. Where gdi.IsDel = 0 ");
  290. List<DelegationPageListView> _DeleInfoList = await _sqlSugar.SqlQueryable<DelegationPageListView>(sql).ToListAsync();
  291. DelegationPageCountView _DeleCount = await _sqlSugar.SqlQueryable<DelegationPageCountView>(sqlCount).FirstAsync();
  292. int count = _DeleCount.Count;
  293. groupsInfoPageList = new ListViewBase<DelegationPageListView>
  294. {
  295. CurrPageIndex = dto.PageIndex,
  296. CurrPageSize = dto.PageSize,
  297. DataCount = count,
  298. DataList = _DeleInfoList
  299. };
  300. result.Code = 0;
  301. result.Msg = "成功!";
  302. result.Data = groupsInfoPageList;
  303. }
  304. return result;
  305. }
  306. /// <summary>
  307. /// 获取接团信息List
  308. /// </summary>
  309. /// <param name="dto"></param>
  310. /// <returns></returns>
  311. public async Task<Result> GetGroupList(GroupListDto dto)
  312. {
  313. Result result = new Result() { Code = -2, Msg = "未知错误" };
  314. if (dto.PortType == 1) {
  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. Result 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,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. //if (_DelegationInfo.TontractTime)
  380. //{
  381. //}
  382. result.Code = 0;
  383. result.Msg = "成功!";
  384. result.Data = _DelegationInfo;
  385. if (dto.PortType == 2)
  386. {
  387. var GroupProcessOperationDtoParam = new GroupProcessOperationDto();
  388. GroupProcessOperationDtoParam = _mapper.Map<DelegationInfoWebView, GroupProcessOperationDto>(_DelegationInfo);
  389. List<Crm_DeleClient> DeleClientArr = await _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0).ToListAsync(); //客户信息
  390. List<Grp_TourClientList> _DeleClients = await _sqlSugar.Queryable<Grp_TourClientList>().Where(it => it.IsDel == 0 && it.DiId == dto.Id).ToListAsync(); // 接团客户名单
  391. List<Crm_CustomerCert> _CustomerCerts = await _sqlSugar.Queryable<Crm_CustomerCert>().Where(it => it.IsDel == 0 && it.SdId == 773).ToListAsync(); // 身份证类型证件信息
  392. List<Crm_CustomerCompany> CompanyArr = await _sqlSugar.Queryable<Crm_CustomerCompany>().Where(it => it.IsDel == 0).ToListAsync();
  393. var TourClientListInfoArr = new List<TourClientListProcessInfo>();
  394. var timeParam = new DateTime();
  395. foreach (var item in _DeleClients)
  396. {
  397. var param = new TourClientListProcessInfo();
  398. var clientInfo = DeleClientArr.FirstOrDefault(x => x.Id == item.ClientId);
  399. if (clientInfo == null) clientInfo = new Crm_DeleClient();
  400. var clientIDInfo = _CustomerCerts.FirstOrDefault(x=>x.DcId == item.ClientId); //身份证信息
  401. if (clientIDInfo == null) clientIDInfo = new Crm_CustomerCert();
  402. var Company = CompanyArr.FirstOrDefault(x => x.Id == clientInfo.CrmCompanyId);
  403. if(Company == null) Company = new Crm_CustomerCompany();
  404. param.IDCardNo = clientIDInfo.CertNo;
  405. param.Remark = item.Remark;
  406. param.BirthDay = clientInfo.BirthDay == null ? "" : DateTime.TryParse(Convert.ToDateTime( clientInfo.BirthDay).ToString("yyyy-MM-dd"), out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  407. param.FirstName = clientInfo.FirstName;
  408. param.LastName = clientInfo.LastName;
  409. param.CompanyFullName = Company.CompanyFullName;
  410. param.Job = clientInfo.Job;
  411. param.Sex = clientInfo.Sex;
  412. param.Phone = clientInfo.Phone;
  413. param.Pinyin = clientInfo.Pinyin;
  414. param.HotelSpecialNeeds = item.HotelSpecialNeeds;
  415. param.MealSpecialNeeds = item.MealSpecialNeeds;
  416. param.ShippingSpaceSpecialNeeds = item.ShippingSpaceSpecialNeeds;
  417. param.ShippingSpaceTypeId = item.ShippingSpaceTypeId;
  418. param.Id = clientInfo.Id;
  419. EncryptionProcessor.DecryptProperties(param);
  420. TourClientListInfoArr.Add(param);
  421. }
  422. GroupProcessOperationDtoParam.PortType = dto.PortType;
  423. GroupProcessOperationDtoParam.TourClientListInfos = TourClientListInfoArr;
  424. GroupProcessOperationDtoParam.VisitDate = DateTime.TryParse(GroupProcessOperationDtoParam.VisitDate, out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  425. GroupProcessOperationDtoParam.VisitDate = DateTime.TryParse(GroupProcessOperationDtoParam.VisitDate, out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  426. GroupProcessOperationDtoParam.TontractTime = DateTime.TryParse(GroupProcessOperationDtoParam.TontractTime, out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  427. result.Data = GroupProcessOperationDtoParam;
  428. }
  429. else if (dto.PortType == 3)
  430. {
  431. var GroupProcessOperationDtoParam = new GroupProcessOperationDto();
  432. GroupProcessOperationDtoParam = _mapper.Map<DelegationInfoWebView, GroupProcessOperationDto>(_DelegationInfo);
  433. List<Crm_DeleClient> DeleClientArr = await _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0).ToListAsync(); //客户信息
  434. List<Grp_TourClientList> _DeleClients = await _sqlSugar.Queryable<Grp_TourClientList>().Where(it => it.IsDel == 0 && it.DiId == dto.Id).ToListAsync(); // 接团客户名单
  435. List<Crm_CustomerCert> _CustomerCerts = await _sqlSugar.Queryable<Crm_CustomerCert>().Where(it => it.IsDel == 0 && it.SdId == 773).ToListAsync(); // 身份证类型证件信息
  436. List<Crm_CustomerCompany> CompanyArr = await _sqlSugar.Queryable<Crm_CustomerCompany>().Where(it => it.IsDel == 0).ToListAsync();
  437. var TourClientListInfoArr = new List<TourClientListProcessInfo>();
  438. var timeParam = new DateTime();
  439. foreach (var item in _DeleClients)
  440. {
  441. var param = new TourClientListProcessInfo();
  442. var clientInfo = DeleClientArr.FirstOrDefault(x => x.Id == item.ClientId);
  443. if (clientInfo == null) clientInfo = new Crm_DeleClient();
  444. var clientIDInfo = _CustomerCerts.FirstOrDefault(x => x.DcId == item.ClientId); //身份证信息
  445. if (clientIDInfo == null) clientIDInfo = new Crm_CustomerCert();
  446. var Company = CompanyArr.FirstOrDefault(x => x.Id == clientInfo.CrmCompanyId);
  447. if (Company == null) Company = new Crm_CustomerCompany();
  448. param.IDCardNo = clientIDInfo.CertNo;
  449. param.Remark = item.Remark;
  450. param.BirthDay = clientInfo.BirthDay == null ? "" : DateTime.TryParse(Convert.ToDateTime(clientInfo.BirthDay).ToString("yyyy-MM-dd"), out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  451. param.FirstName = clientInfo.FirstName;
  452. param.LastName = clientInfo.LastName;
  453. param.CompanyFullName = Company.CompanyFullName;
  454. param.Job = clientInfo.Job;
  455. param.Sex = clientInfo.Sex;
  456. param.Phone = clientInfo.Phone;
  457. param.Pinyin = clientInfo.Pinyin;
  458. param.HotelSpecialNeeds = item.HotelSpecialNeeds;
  459. param.MealSpecialNeeds = item.MealSpecialNeeds;
  460. param.ShippingSpaceSpecialNeeds = item.ShippingSpaceSpecialNeeds;
  461. param.ShippingSpaceTypeId = item.ShippingSpaceTypeId;
  462. param.Id = item.Id;
  463. EncryptionProcessor.DecryptProperties(param);
  464. TourClientListInfoArr.Add(param);
  465. }
  466. GroupProcessOperationDtoParam.PortType = dto.PortType;
  467. GroupProcessOperationDtoParam.TourClientListInfos = TourClientListInfoArr;
  468. GroupProcessOperationDtoParam.VisitDate = DateTime.TryParse(GroupProcessOperationDtoParam.VisitDate, out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  469. GroupProcessOperationDtoParam.TontractTime = DateTime.TryParse(GroupProcessOperationDtoParam.TontractTime, out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  470. result.Data = GroupProcessOperationDtoParam;
  471. }
  472. }
  473. else result.Msg = "暂无该团组信息";
  474. }
  475. return result;
  476. }
  477. /// <summary>
  478. /// 获取接团信息 编辑
  479. /// 基础 数据源
  480. /// </summary>
  481. /// <param name="dto"></param>
  482. /// <returns></returns>
  483. public async Task<Result> GroupEditBasicSource(GroupListDto dto)
  484. {
  485. Result result = new Result() { Code = -2, Msg = "未知错误" };
  486. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  487. {
  488. dynamic? teamTypeData1 = null;
  489. string teamTypeSql = string.Format(@"Select Id,Name From Sys_SetData Where STid = {0} And IsDel = {1}", 10, 0);
  490. var teamTypeData = await _sqlSugar.SqlQueryable<SetDataInfoView>(teamTypeSql).ToListAsync(); ; //团组分类 10
  491. if (teamTypeData.Any())
  492. {
  493. teamTypeData1 = teamTypeData;
  494. if (teamTypeData.Any(x => x.Name.Equals("前期沟通")))
  495. {
  496. var info = teamTypeData.Find(x => x.Name.Equals("前期沟通"));
  497. if (info != null)
  498. {
  499. teamTypeData.Remove(info);
  500. teamTypeData.Insert(2, info);
  501. }
  502. }
  503. }
  504. dynamic? teamLevData1 = null;
  505. string teamLevSql = string.Format(@"Select Id,Name From Sys_SetData Where STid = {0} And IsDel = {1}", 56, 0);
  506. var teamLevData = await _sqlSugar.SqlQueryable<SetDataInfoView>(teamLevSql).ToListAsync(); ; //团组等级 56
  507. if (teamLevData.Any())
  508. {
  509. teamLevData1 = teamLevData;
  510. }
  511. dynamic? userData1 = null;
  512. string userSql = string.Format(@"Select Id,CnName From Sys_Users Where IsDel = {0}", 0);
  513. var userData = await _sqlSugar.SqlQueryable<UserNameView>(userSql).ToListAsync();
  514. if (userData.Any())
  515. {
  516. userData1 = userData;
  517. }
  518. //客户单位数据源 来源市场客户资料
  519. dynamic? clientData1 = null;
  520. string clientSql = $@"Select Client,Contact,Telephone,WeChat From Crm_NewClientData Where IsDel = 0";
  521. var clientData = await _sqlSugar.SqlQueryable<Crm_NewClientData>(clientSql).ToListAsync();
  522. if (clientData.Any())
  523. {
  524. clientData1 = clientData.Select(it => new
  525. {
  526. Client = AesEncryptionHelper.Decrypt(it.Client),
  527. Contact = AesEncryptionHelper.Decrypt(it.Contact),
  528. Telephone = AesEncryptionHelper.Decrypt(it.Telephone),
  529. Wechat = AesEncryptionHelper.Decrypt(it.Wechat)
  530. }).ToList();
  531. }
  532. var userDepDatas = new List<TextView>();
  533. userDepDatas.Insert(0, new TextView() { Text = "全部", Value = "全部" });
  534. userDepDatas.Insert(1, new TextView() { Text = "国交部", Value = "国交部" });
  535. userDepDatas.Insert(2, new TextView() { Text = "市场部", Value = "市场部" });
  536. userDepDatas.Insert(3, new TextView() { Text = "策划部", Value = "策划部" });
  537. 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();
  538. rankDatas.Insert(0, new TextView { Value = "0", Text = "全部" });
  539. result.Code = 0;
  540. result.Msg = "成功!";
  541. result.Data = new
  542. {
  543. teamTypeData = teamTypeData1,
  544. teamLevData = teamLevData1,
  545. userData = userData1,
  546. clientData = clientData1,
  547. depData = userDepDatas,
  548. rankData = rankDatas
  549. };
  550. }
  551. return result;
  552. }
  553. /// <summary>
  554. /// 团组信息操作
  555. /// </summary>
  556. /// <param name="dto"></param>
  557. /// <returns></returns>
  558. public async Task<Result>GroupOperation(GroupOperationDto dto)
  559. {
  560. Result result = new Result() { Code = -2, Msg = "未知错误" };
  561. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  562. {
  563. #region 添加出访起止时间
  564. var startTime = new DateTime();
  565. var endTime = new DateTime();
  566. if (DateTime.TryParse(dto.VisitDate, out startTime))
  567. {
  568. endTime = startTime.AddDays(dto.VisitDays - 1);//含当天
  569. }
  570. #endregion
  571. if (dto.Status == 1) //添加
  572. {
  573. string selectSql = string.Format(@"Select * From Grp_DelegationInfo
  574. Where IsDel = 0
  575. And TeamName = '{0}'
  576. And ClientName = '{1}'
  577. And ClientUnit ='{2}'
  578. And VisitDate ='{3}'",dto.TeamName, dto.ClientName, dto.ClientUnit, dto.VisitDate);
  579. var selectGroupInfo = _sqlSugar.SqlQueryable<Grp_DelegationInfo>(selectSql).First();
  580. if (selectGroupInfo != null)
  581. {
  582. result.Msg = "数据已存在,请勿重复添加!";
  583. return result;
  584. }
  585. //string teamCodeSql = string.Format("Select SalesQuoteNo From Grp_DelegationInfo");
  586. //var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  587. //string SalesQuoteNo = "";
  588. //while (true)
  589. //{
  590. // SalesQuoteNo = Tools.CommonFun.GetRandomStr(6);
  591. // if (!teamCodeItem.Equals(SalesQuoteNo))
  592. // {
  593. // break;
  594. // }
  595. //}
  596. string countrys = string.Empty;
  597. string countryReq = dto.VisitCountry;
  598. if (!string.IsNullOrEmpty(countryReq))
  599. {
  600. if (countryReq.Contains(",")) countrys = countryReq.Replace(',','|');
  601. else if (countryReq.Contains(",")) countrys = countryReq.Replace(',', '|');
  602. else if (countryReq.Contains(" ")) countrys = countryReq.Replace(' ', '|');
  603. else if (countryReq.Contains("、")) countrys = countryReq.Replace('、', '|');
  604. else if (countryReq.Contains(".")) countrys = countryReq.Replace('.', '|');
  605. else countrys = countryReq;
  606. }
  607. //建团时 默认出团 设置 团组code
  608. string teamCode="";
  609. string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
  610. var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  611. while (true)
  612. {
  613. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  614. if (!teamCodeItem.Equals(teamCode))
  615. {
  616. break;
  617. }
  618. }
  619. Grp_DelegationInfo delegationInfo = new Grp_DelegationInfo()
  620. {
  621. SalesQuoteNo = dto.SalesQuoteNo,
  622. TeamLevSId = dto.TeamLevSId,
  623. ClientName = dto.ClientName,
  624. ClientUnit = dto.ClientUnit,
  625. TeamName = dto.TeamName,
  626. TeamDid = dto.TeamDid,
  627. VisitDate = Convert.ToDateTime(dto.VisitDate),
  628. VisitCountry = countrys,
  629. VisitPurpose = dto.VisitPurpose,
  630. VisitDays = dto.VisitDays,
  631. VisitPNumber = dto.VisitPNumber,
  632. SpecialNeeds = dto.SpecialNeeds,
  633. OtherNeeds = dto.OtherNeeds,
  634. Remark = dto.Remark,
  635. JietuanOperator = dto.JietuanOperator,
  636. TellPhone = dto.TellPhone,
  637. WeChatNo = dto.WeChatNo,
  638. CGRWSPBMMC = dto.CGRWSPBMMC,
  639. CGRWSPWH = dto.CGRWSPWH,
  640. ZZSCBMMC = dto.ZZSCBMMC,
  641. ZZSCSPWH = dto.ZZSCSPWH,
  642. TontractTime = string.IsNullOrEmpty(dto.TontractTime) ? null : Convert.ToDateTime(dto.TontractTime),
  643. IsBid = dto.IsBid,
  644. PaymentMoney = dto.PaymentMoney,
  645. PayDay = dto.PayDay,
  646. TourCode = teamCode,
  647. GroupsOperator = dto.UserId,
  648. GroupsTime = DateTime.Now,
  649. SalesDate = DateTime.Now,
  650. IsState = 0, //默认团组未完成 0
  651. JietuanTime = DateTime.Now,
  652. IsDel = 0,
  653. BudgetCost = 0.00M,
  654. HotelComplain = 0,
  655. OPComplain = 0,
  656. OAComplain = 0,
  657. AirComplain = 0,
  658. VisaComplain = 0,
  659. CreateUserId = dto.UserId,
  660. CreateTime = DateTime.Now,
  661. DeleteUserId = null,
  662. DeleteTime = new DateTime(1990, 1, 1).ToString("yyyy-MM-dd HH:mm:ss"),
  663. OpRoyaltyLv = dto.OpRoyaltyLv,
  664. OpRoyaltyRemark=dto.opRoyaltyRemark,
  665. Officialneeds = dto.Officialneeds,
  666. VisitStartDate = startTime,
  667. VisitEndDate = endTime,
  668. };
  669. var addId = _sqlSugar.Insertable(delegationInfo).ExecuteReturnIdentity();
  670. if (addId > 0)
  671. {
  672. result.Code = 0;
  673. result.Msg = "添加成功!";
  674. result.Data = addId;
  675. }
  676. else
  677. {
  678. result.Msg = "添加失败!";
  679. }
  680. }
  681. else if (dto.Status == 2) //修改
  682. {
  683. var updateStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo
  684. {
  685. SalesQuoteNo = dto.SalesQuoteNo,
  686. TeamLevSId = dto.TeamLevSId,
  687. ClientName = dto.ClientName,
  688. ClientUnit = dto.ClientUnit,
  689. TeamName = dto.TeamName,
  690. TeamDid = dto.TeamDid,
  691. VisitDate = Convert.ToDateTime(dto.VisitDate),
  692. VisitCountry = dto.VisitCountry,
  693. VisitPurpose = dto.VisitPurpose,
  694. VisitDays = dto.VisitDays,
  695. VisitPNumber = dto.VisitPNumber,
  696. SpecialNeeds = dto.SpecialNeeds,
  697. OtherNeeds = dto.OtherNeeds,
  698. Remark = dto.Remark,
  699. JietuanOperator = dto.JietuanOperator,
  700. TellPhone = dto.TellPhone,
  701. WeChatNo = dto.WeChatNo,
  702. CGRWSPBMMC = dto.CGRWSPBMMC,
  703. CGRWSPWH = dto.CGRWSPWH,
  704. ZZSCBMMC = dto.ZZSCBMMC,
  705. ZZSCSPWH = dto.ZZSCSPWH,
  706. TontractTime = string.IsNullOrEmpty(dto.TontractTime) ? null : Convert.ToDateTime(dto.TontractTime),
  707. IsBid = dto.IsBid,
  708. PaymentMoney = dto.PaymentMoney,
  709. PayDay = dto.PayDay,
  710. OpRoyaltyLv = dto.OpRoyaltyLv,
  711. OpRoyaltyRemark = dto.opRoyaltyRemark,
  712. Officialneeds = dto.Officialneeds,
  713. VisitStartDate = startTime,
  714. VisitEndDate = endTime,
  715. });
  716. if (updateStatus)
  717. {
  718. result.Code = 0;
  719. result.Msg = "修改成功!";
  720. }
  721. else
  722. {
  723. result.Msg = "修改失败!";
  724. }
  725. }
  726. else if (dto.Status == 3) //删除
  727. {
  728. var deleteStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo
  729. {
  730. DeleteUserId = dto.UserId,
  731. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  732. IsDel = 1
  733. });
  734. if (deleteStatus)
  735. {
  736. result.Code = 0;
  737. result.Msg = "删除成功!";
  738. }
  739. else
  740. {
  741. result.Msg = "删除失败!";
  742. }
  743. }
  744. }
  745. return result;
  746. }
  747. /// <summary>
  748. /// 团组信息操作 - 删除
  749. /// </summary>
  750. /// <param name="dto"></param>
  751. /// <returns></returns>
  752. public async Task<Result> GroupDel(GroupDelDto dto)
  753. {
  754. Result result = new Result() { Code = -2, Msg = "未知错误" };
  755. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  756. {
  757. var deleteStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo
  758. {
  759. DeleteUserId = dto.UserId,
  760. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  761. IsDel = 1
  762. });
  763. if (deleteStatus)
  764. {
  765. result.Code = 0;
  766. result.Msg = "删除成功!";
  767. }
  768. else
  769. {
  770. result.Msg = "删除失败!";
  771. }
  772. }
  773. return result;
  774. }
  775. /// <summary>
  776. /// 获取销售报价号
  777. /// </summary>
  778. /// <returns></returns>
  779. public async Task<Result> GetGroupSalesQuoteNo()
  780. {
  781. Result result = new Result() { Code = -2, Msg = "未知错误" };
  782. string teamCodeSql = string.Format("Select SalesQuoteNo From Grp_DelegationInfo");
  783. var teamCodeItem = await _sqlSugar.SqlQueryable<SalesQuoteNoView>(teamCodeSql).ToListAsync();
  784. string teamCode = "";
  785. while (true)
  786. {
  787. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  788. if (!teamCodeItem.Equals(teamCode))
  789. {
  790. break;
  791. }
  792. }
  793. result.Code = 0;
  794. result.Msg = "成功!";
  795. result.Data = teamCode;
  796. return result;
  797. }
  798. /// <summary>
  799. /// 团组删除
  800. /// </summary>
  801. /// <returns></returns>
  802. public async Task<Result> GroupDeleteById()
  803. {
  804. Result result = new Result() { Code = -2, Msg = "未知错误" };
  805. string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
  806. var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  807. string teamCode = "";
  808. while (true)
  809. {
  810. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  811. if (!teamCodeItem.Equals(teamCode))
  812. {
  813. break;
  814. }
  815. }
  816. result.Code = 0;
  817. result.Msg = "成功!";
  818. result.Data = teamCode;
  819. return result;
  820. }
  821. /// <summary>
  822. /// 团组确认出团
  823. /// </summary>
  824. /// <returns></returns>
  825. public async Task<Result> ConfirmationGroup(ConfirmationGroupDto dto)
  826. {
  827. Result result = new Result() { Code = -2, Msg = "未知错误" };
  828. string teamCode = "";
  829. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  830. {
  831. string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
  832. var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  833. while (true)
  834. {
  835. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  836. if (!teamCodeItem.Equals(teamCode))
  837. {
  838. break;
  839. }
  840. }
  841. var deleteStatus = await UpdateAsync(a => a.Id == dto.GroupId, a => new Grp_DelegationInfo
  842. {
  843. TourCode = teamCode,
  844. GroupsOperator = dto.GroupsOperator,
  845. GroupsTime = DateTime.Now
  846. });
  847. if (deleteStatus)
  848. {
  849. result.Code = 0;
  850. result.Msg = "确认出团设置成功!";
  851. }
  852. else
  853. {
  854. result.Msg = "确认出团设置失败!";
  855. }
  856. }
  857. result.Code = 0;
  858. result.Msg = "成功!";
  859. result.Data = teamCode;
  860. return result;
  861. }
  862. /// <summary>
  863. /// 获取接团名称List
  864. /// </summary>
  865. /// <param name="dto"></param>
  866. /// <returns></returns>
  867. public async Task<JsonView> GetGroupNameList(GroupNameDto dto)
  868. {
  869. var view = new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "操作失败!" };
  870. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  871. {
  872. //2025-02-17 更改团组列表排序功能 按照团出访时间排序(降序)
  873. string sql = string.Format(@"Select Id,TeamName GroupName From Grp_DelegationInfo
  874. Where TeamName != '' And IsDel = 0
  875. Order By VisitStartDate Desc");
  876. var _groupNameList = await _sqlSugar.SqlQueryable<GroupNameView>(sql).ToListAsync();
  877. if (_groupNameList.Count > 0)
  878. {
  879. for (int i = 0; i < _groupNameList.Count; i++)
  880. {
  881. var info = _groupNameList[i];
  882. _groupNameList[i].GroupName = FormartTeamName(info.GroupName);
  883. }
  884. view.Code = StatusCodes.Status200OK;
  885. view.Msg = "成功!";
  886. view.Data = _groupNameList;
  887. }
  888. else
  889. {
  890. view.Msg = "暂无团组信息";
  891. }
  892. }
  893. return view;
  894. }
  895. //PostGroupNameScreen
  896. /// <summary>
  897. /// 获取接团名称 Page List
  898. /// </summary>
  899. /// <param name="dto"></param>
  900. /// <returns></returns>
  901. public async Task<JsonView> GetGroupNameList(int portType,int pageIndex,int pageSize, string groupName,int userId)
  902. {
  903. var _res = new JsonView() { Code = 400 , Msg = MsgTips.Fail };
  904. string sql = "";
  905. string sqlWhere = "";
  906. string mobileSqlWhere = "";
  907. if (!string.IsNullOrEmpty(groupName))
  908. {
  909. sqlWhere += string.Format($@"And TeamName Like '%{groupName}%'");
  910. mobileSqlWhere += string.Format($@"GroupName Like '%{groupName}%'");
  911. }
  912. List<int> userIds = new List<int>() { -1, 21 };
  913. if (!userIds.Contains(userId))
  914. {
  915. sqlWhere += string.Format($@"And JietuanOperator = {userId}");
  916. }
  917. sql = string.Format($@"Select ROW_NUMBER()Over(Order By Id Desc) as RowNumber,Id,TeamName GroupName From Grp_DelegationInfo
  918. Where IsDel = 0 {sqlWhere}");
  919. if (portType == 1) //web
  920. { }
  921. else if (portType == 2 || portType == 3)
  922. {
  923. //国交部 7 (主管 22,经理 32)团操操作权限 市场部 6 接团人
  924. var userInfo = await _sqlSugar.Queryable<Sys_Users>().Where(it => it.Id == userId && it.IsDel == 0).FirstAsync();
  925. if (userInfo != null)
  926. {
  927. if (userInfo.DepId == 7)
  928. {
  929. if (userInfo.JobPostId != 22 || userInfo.JobPostId != 32)
  930. {
  931. if (!string.IsNullOrEmpty(mobileSqlWhere)) mobileSqlWhere = $" Where {mobileSqlWhere}";
  932. sql = string.Format($@"Select
  933. ROW_NUMBER()Over(Order By Id Desc) as RowNumber,
  934. Id,
  935. GroupName
  936. From (
  937. Select
  938. distinct
  939. di.Id,
  940. di.TeamName GroupName
  941. From Grp_GroupsTaskAssignment gta With(NoLock)
  942. Inner Join Grp_DelegationInfo di With(NoLock) On gta.DIId = di.Id
  943. Where gta.IsDel = 0 And di.IsDel = 0 And gta.UId = {userId}
  944. ) Temp {mobileSqlWhere}");
  945. }
  946. }
  947. }
  948. }
  949. RefAsync<int> total = 0;
  950. var groupNamePageData = await _sqlSugar.SqlQueryable<GroupNamePageView>(sql).ToPageListAsync(pageIndex, pageSize, total);
  951. _res.Code = 200;
  952. _res.Data = groupNamePageData;
  953. _res.Msg = MsgTips.Succeed;
  954. _res.Count = total;
  955. return _res;
  956. }
  957. /// <summary>
  958. /// 获取接团名称List And 签证国别
  959. /// </summary>
  960. /// <param name="dto"></param>
  961. /// <returns></returns>
  962. public async Task<Result> GetGroupNameAndVisaNationality(GroupNameDto dto)
  963. {
  964. Result result = new Result() { Code = -2, Msg = "未知错误" };
  965. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  966. {
  967. string sql = string.Format(@"Select Id,TeamName GroupName From Grp_DelegationInfo
  968. Where TeamName != '' And IsDel = 0
  969. Order By Id Desc");
  970. var _groupNameList = await _sqlSugar.SqlQueryable<GroupNameView>(sql).ToListAsync();
  971. string visaSql = string.Format(@"Select Id,Name From Sys_SetData Where STid = 41 And IsDel = 0");
  972. var _setDataList = await _sqlSugar.SqlQueryable<SetDataInfoView>(visaSql).ToListAsync();
  973. var data = new {
  974. groupNameData = _groupNameList,
  975. visaNationalityData = _setDataList
  976. };
  977. result.Data = data;
  978. result.Code = 0;
  979. }
  980. return result;
  981. }
  982. #endregion
  983. #region 团组&签证
  984. /// <summary>
  985. /// 根据团组Id查询客户
  986. /// </summary>
  987. /// <param name="dto"></param>
  988. /// <returns></returns>
  989. public async Task<Result> GetCrmByGroupId(ClientByGroupIdDto dto)
  990. {
  991. Result result = new Result() { Code = -2 };
  992. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3)
  993. {
  994. string sql = string.Format(@"Select gdjc.GrpDCId grpId,cdc.Id,cdc.LastName+cdc.FirstName clientName,cdc.Tel,ccc.CertNo CerdNo
  995. From Grp_DelegationJoinCustomer gdjc
  996. Inner join Crm_DeleClient cdc On gdjc.CrmDCId = cdc.Id
  997. Left Join Crm_CustomerCert ccc On ccc.SdId = 773 And cdc.Id = ccc.DcId
  998. Where gdjc.GrpDCId = {0}", dto.GroupId);
  999. var clientList = await _sqlSugar.SqlQueryable<CrmByGroupIdView>(sql).ToListAsync();
  1000. if (clientList.Count > 0)
  1001. {
  1002. result.Code = 0;
  1003. result.Msg = "成功!";
  1004. result.Data = clientList;
  1005. }
  1006. else
  1007. {
  1008. result.Msg = "暂无数据!";
  1009. }
  1010. }
  1011. return result;
  1012. }
  1013. #endregion
  1014. #region 团组&出入境费用
  1015. /// <summary>
  1016. /// 获取单组名称并验证出入境费用明细是否填写
  1017. /// </summary>
  1018. /// <param name="dto"></param>
  1019. /// <returns></returns>
  1020. public async Task<Result> EnterExitCostGroupNameAsync()
  1021. {
  1022. var result = new Result() { Code = -2, Msg = "未知错误" };
  1023. var groupSql = string.Format(@$"SELECT
  1024. Id,
  1025. TeamName GroupName,
  1026. CASE
  1027. WHEN (
  1028. SELECT
  1029. COUNT(*)
  1030. FROM
  1031. Grp_EnterExitCost
  1032. WHERE
  1033. IsDel = 0
  1034. AND DiId = di.Id
  1035. ) > 0 THEN 'false'
  1036. ELSE 'true'
  1037. END AS [IsNull]
  1038. FROM
  1039. Grp_DelegationInfo di
  1040. WHERE
  1041. di.Isdel = 0
  1042. ORDER BY
  1043. VisitStartDate Desc");
  1044. result.Data = await _sqlSugar.SqlQueryable<EnterExitCostGroupNameView>(groupSql).ToListAsync();
  1045. result.Code = 0;
  1046. return result;
  1047. }
  1048. #endregion
  1049. }
  1050. }