DelegationInfoRepository.cs 52 KB

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