DelegationInfoRepository.cs 47 KB

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