DelegationInfoRepository.cs 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088
  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 { it.Client,it.Contact,it.Telephone,it.Wechat }).ToList();
  452. }
  453. result.Code = 0;
  454. result.Msg = "成功!";
  455. result.Data = new
  456. {
  457. teamTypeData = teamTypeData1,
  458. teamLevData = teamLevData1,
  459. userData = userData1,
  460. clientData = clientData1
  461. };
  462. }
  463. }
  464. catch (Exception ex)
  465. {
  466. result.Msg = ex.Message;
  467. }
  468. return result;
  469. }
  470. /// <summary>
  471. /// 团组信息操作
  472. /// </summary>
  473. /// <param name="dto"></param>
  474. /// <returns></returns>
  475. public async Task<Result>GroupOperation(GroupOperationDto dto)
  476. {
  477. Result result = new Result() { Code = -2, Msg = "未知错误" };
  478. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  479. {
  480. #region 添加出访起止时间
  481. var startTime = new DateTime();
  482. var endTime = new DateTime();
  483. if (DateTime.TryParse(dto.VisitDate, out startTime))
  484. {
  485. endTime = startTime.AddDays(dto.VisitDays - 1);//含当天
  486. }
  487. #endregion
  488. if (dto.Status == 1) //添加
  489. {
  490. string selectSql = string.Format(@"Select * From Grp_DelegationInfo
  491. Where IsDel = 0
  492. And TeamName = '{0}'
  493. And ClientName = '{1}'
  494. And ClientUnit ='{2}'
  495. And VisitDate ='{3}'",dto.TeamName, dto.ClientName, dto.ClientUnit, dto.VisitDate);
  496. var selectGroupInfo = _sqlSugar.SqlQueryable<Grp_DelegationInfo>(selectSql).First();
  497. if (selectGroupInfo != null)
  498. {
  499. result.Msg = "数据已存在,请勿重复添加!";
  500. return result;
  501. }
  502. //string teamCodeSql = string.Format("Select SalesQuoteNo From Grp_DelegationInfo");
  503. //var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  504. //string SalesQuoteNo = "";
  505. //while (true)
  506. //{
  507. // SalesQuoteNo = Tools.CommonFun.GetRandomStr(6);
  508. // if (!teamCodeItem.Equals(SalesQuoteNo))
  509. // {
  510. // break;
  511. // }
  512. //}
  513. string countrys = string.Empty;
  514. string countryReq = dto.VisitCountry;
  515. if (!string.IsNullOrEmpty(countryReq))
  516. {
  517. if (countryReq.Contains(",")) countrys = countryReq.Replace(',','|');
  518. else if (countryReq.Contains(",")) countrys = countryReq.Replace(',', '|');
  519. else if (countryReq.Contains(" ")) countrys = countryReq.Replace(' ', '|');
  520. else if (countryReq.Contains("、")) countrys = countryReq.Replace('、', '|');
  521. else if (countryReq.Contains(".")) countrys = countryReq.Replace('.', '|');
  522. else countrys = countryReq;
  523. }
  524. //建团时 默认出团 设置 团组code
  525. string teamCode="";
  526. string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
  527. var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  528. while (true)
  529. {
  530. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  531. if (!teamCodeItem.Equals(teamCode))
  532. {
  533. break;
  534. }
  535. }
  536. Grp_DelegationInfo delegationInfo = new Grp_DelegationInfo()
  537. {
  538. SalesQuoteNo = dto.SalesQuoteNo,
  539. TeamLevSId = dto.TeamLevSId,
  540. ClientName = dto.ClientName,
  541. ClientUnit = dto.ClientUnit,
  542. TeamName = dto.TeamName,
  543. TeamDid = dto.TeamDid,
  544. VisitDate = Convert.ToDateTime(dto.VisitDate),
  545. VisitCountry = countrys,
  546. VisitPurpose = dto.VisitPurpose,
  547. VisitDays = dto.VisitDays,
  548. VisitPNumber = dto.VisitPNumber,
  549. SpecialNeeds = dto.SpecialNeeds,
  550. OtherNeeds = dto.OtherNeeds,
  551. Remark = dto.Remark,
  552. JietuanOperator = dto.JietuanOperator,
  553. TellPhone = dto.TellPhone,
  554. WeChatNo = dto.WeChatNo,
  555. CGRWSPBMMC = dto.CGRWSPBMMC,
  556. CGRWSPWH = dto.CGRWSPWH,
  557. ZZSCBMMC = dto.ZZSCBMMC,
  558. ZZSCSPWH = dto.ZZSCSPWH,
  559. TontractTime = string.IsNullOrEmpty(dto.TontractTime) ? null : Convert.ToDateTime(dto.TontractTime),
  560. IsBid = dto.IsBid,
  561. PaymentMoney = dto.PaymentMoney,
  562. PayDay = dto.PayDay,
  563. TourCode = teamCode,
  564. GroupsOperator = dto.UserId,
  565. GroupsTime = DateTime.Now,
  566. SalesDate = DateTime.Now,
  567. IsState = 0, //默认团组未完成 0
  568. JietuanTime = DateTime.Now,
  569. IsDel = 0,
  570. BudgetCost = 0.00M,
  571. HotelComplain = 0,
  572. OPComplain = 0,
  573. OAComplain = 0,
  574. AirComplain = 0,
  575. VisaComplain = 0,
  576. CreateUserId = dto.UserId,
  577. CreateTime = DateTime.Now,
  578. DeleteUserId = null,
  579. DeleteTime = new DateTime(1990, 1, 1).ToString("yyyy-MM-dd HH:mm:ss"),
  580. OpRoyaltyLv = dto.OpRoyaltyLv,
  581. OpRoyaltyRemark=dto.opRoyaltyRemark,
  582. Officialneeds = dto.Officialneeds,
  583. VisitStartDate = startTime,
  584. VisitEndDate = endTime,
  585. };
  586. var addId = _sqlSugar.Insertable(delegationInfo).ExecuteReturnIdentity();
  587. if (addId > 0)
  588. {
  589. result.Code = 0;
  590. result.Msg = "添加成功!";
  591. result.Data = addId;
  592. }
  593. else
  594. {
  595. result.Msg = "添加失败!";
  596. }
  597. }
  598. else if (dto.Status == 2) //修改
  599. {
  600. var updateStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo
  601. {
  602. SalesQuoteNo = dto.SalesQuoteNo,
  603. TeamLevSId = dto.TeamLevSId,
  604. ClientName = dto.ClientName,
  605. ClientUnit = dto.ClientUnit,
  606. TeamName = dto.TeamName,
  607. TeamDid = dto.TeamDid,
  608. VisitDate = Convert.ToDateTime(dto.VisitDate),
  609. VisitCountry = dto.VisitCountry,
  610. VisitPurpose = dto.VisitPurpose,
  611. VisitDays = dto.VisitDays,
  612. VisitPNumber = dto.VisitPNumber,
  613. SpecialNeeds = dto.SpecialNeeds,
  614. OtherNeeds = dto.OtherNeeds,
  615. Remark = dto.Remark,
  616. JietuanOperator = dto.JietuanOperator,
  617. TellPhone = dto.TellPhone,
  618. WeChatNo = dto.WeChatNo,
  619. CGRWSPBMMC = dto.CGRWSPBMMC,
  620. CGRWSPWH = dto.CGRWSPWH,
  621. ZZSCBMMC = dto.ZZSCBMMC,
  622. ZZSCSPWH = dto.ZZSCSPWH,
  623. TontractTime = string.IsNullOrEmpty(dto.TontractTime) ? null : Convert.ToDateTime(dto.TontractTime),
  624. IsBid = dto.IsBid,
  625. PaymentMoney = dto.PaymentMoney,
  626. PayDay = dto.PayDay,
  627. OpRoyaltyLv = dto.OpRoyaltyLv,
  628. OpRoyaltyRemark = dto.opRoyaltyRemark,
  629. Officialneeds = dto.Officialneeds,
  630. VisitStartDate = startTime,
  631. VisitEndDate = endTime,
  632. });
  633. if (updateStatus)
  634. {
  635. result.Code = 0;
  636. result.Msg = "修改成功!";
  637. }
  638. else
  639. {
  640. result.Msg = "修改失败!";
  641. }
  642. }
  643. else if (dto.Status == 3) //删除
  644. {
  645. var deleteStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo
  646. {
  647. DeleteUserId = dto.UserId,
  648. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  649. IsDel = 1
  650. });
  651. if (deleteStatus)
  652. {
  653. result.Code = 0;
  654. result.Msg = "删除成功!";
  655. }
  656. else
  657. {
  658. result.Msg = "删除失败!";
  659. }
  660. }
  661. }
  662. return result;
  663. }
  664. /// <summary>
  665. /// 团组信息操作 - 删除
  666. /// </summary>
  667. /// <param name="dto"></param>
  668. /// <returns></returns>
  669. public async Task<Result> GroupDel(GroupDelDto dto)
  670. {
  671. Result result = new Result() { Code = -2, Msg = "未知错误" };
  672. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  673. {
  674. var deleteStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo
  675. {
  676. DeleteUserId = dto.UserId,
  677. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  678. IsDel = 1
  679. });
  680. if (deleteStatus)
  681. {
  682. result.Code = 0;
  683. result.Msg = "删除成功!";
  684. }
  685. else
  686. {
  687. result.Msg = "删除失败!";
  688. }
  689. }
  690. return result;
  691. }
  692. /// <summary>
  693. /// 获取销售报价号
  694. /// </summary>
  695. /// <returns></returns>
  696. public async Task<Result> GetGroupSalesQuoteNo()
  697. {
  698. Result result = new Result() { Code = -2, Msg = "未知错误" };
  699. string teamCodeSql = string.Format("Select SalesQuoteNo From Grp_DelegationInfo");
  700. var teamCodeItem = await _sqlSugar.SqlQueryable<SalesQuoteNoView>(teamCodeSql).ToListAsync();
  701. string teamCode = "";
  702. while (true)
  703. {
  704. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  705. if (!teamCodeItem.Equals(teamCode))
  706. {
  707. break;
  708. }
  709. }
  710. result.Code = 0;
  711. result.Msg = "成功!";
  712. result.Data = teamCode;
  713. return result;
  714. }
  715. /// <summary>
  716. /// 团组删除
  717. /// </summary>
  718. /// <returns></returns>
  719. public async Task<Result> GroupDeleteById()
  720. {
  721. Result result = new Result() { Code = -2, Msg = "未知错误" };
  722. string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
  723. var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  724. string teamCode = "";
  725. while (true)
  726. {
  727. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  728. if (!teamCodeItem.Equals(teamCode))
  729. {
  730. break;
  731. }
  732. }
  733. result.Code = 0;
  734. result.Msg = "成功!";
  735. result.Data = teamCode;
  736. return result;
  737. }
  738. /// <summary>
  739. /// 团组确认出团
  740. /// </summary>
  741. /// <returns></returns>
  742. public async Task<Result> ConfirmationGroup(ConfirmationGroupDto dto)
  743. {
  744. Result result = new Result() { Code = -2, Msg = "未知错误" };
  745. string teamCode = "";
  746. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  747. {
  748. string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
  749. var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  750. while (true)
  751. {
  752. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  753. if (!teamCodeItem.Equals(teamCode))
  754. {
  755. break;
  756. }
  757. }
  758. var deleteStatus = await UpdateAsync(a => a.Id == dto.GroupId, a => new Grp_DelegationInfo
  759. {
  760. TourCode = teamCode,
  761. GroupsOperator = dto.GroupsOperator,
  762. GroupsTime = DateTime.Now
  763. });
  764. if (deleteStatus)
  765. {
  766. result.Code = 0;
  767. result.Msg = "确认出团设置成功!";
  768. }
  769. else
  770. {
  771. result.Msg = "确认出团设置失败!";
  772. }
  773. }
  774. result.Code = 0;
  775. result.Msg = "成功!";
  776. result.Data = teamCode;
  777. return result;
  778. }
  779. /// <summary>
  780. /// 获取接团名称List
  781. /// </summary>
  782. /// <param name="dto"></param>
  783. /// <returns></returns>
  784. public async Task<Result> GetGroupNameList(GroupNameDto dto)
  785. {
  786. Result result = new Result() { Code = -2, Msg = "未知错误" };
  787. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  788. {
  789. string sql = string.Format(@"Select Id,TeamName GroupName From Grp_DelegationInfo
  790. Where TeamName != '' And IsDel = 0
  791. Order By Id Desc");
  792. var _groupNameList = await _sqlSugar.SqlQueryable<GroupNameView>(sql).ToListAsync();
  793. if (_groupNameList.Count > 0)
  794. {
  795. for (int i = 0; i < _groupNameList.Count; i++)
  796. {
  797. var info = _groupNameList[i];
  798. _groupNameList[i].GroupName = FormartTeamName(info.GroupName);
  799. }
  800. result.Code = 0;
  801. result.Msg = "成功!";
  802. result.Data = _groupNameList;
  803. }
  804. else
  805. {
  806. result.Msg = "暂无团组信息";
  807. }
  808. }
  809. return result;
  810. }
  811. //PostGroupNameScreen
  812. /// <summary>
  813. /// 获取接团名称 Page List
  814. /// </summary>
  815. /// <param name="dto"></param>
  816. /// <returns></returns>
  817. public async Task<JsonView> GetGroupNameList(int portType,int pageIndex,int pageSize, string groupName,int userId)
  818. {
  819. var _res = new JsonView() { Code = 400 , Msg = MsgTips.Fail };
  820. string sql = "";
  821. string sqlWhere = "";
  822. string mobileSqlWhere = "";
  823. if (!string.IsNullOrEmpty(groupName))
  824. {
  825. sqlWhere += string.Format($@"And TeamName Like '%{groupName}%'");
  826. mobileSqlWhere += string.Format($@"GroupName Like '%{groupName}%'");
  827. }
  828. List<int> userIds = new List<int>() { -1, 21 };
  829. if (!userIds.Contains(userId))
  830. {
  831. sqlWhere += string.Format($@"And JietuanOperator = {userId}");
  832. }
  833. sql = string.Format($@"Select ROW_NUMBER()Over(Order By Id Desc) as RowNumber,Id,TeamName GroupName From Grp_DelegationInfo
  834. Where IsDel = 0 {sqlWhere}");
  835. if (portType == 1) //web
  836. { }
  837. else if (portType == 2 || portType == 3)
  838. {
  839. //国交部 7 (主管 22,经理 32)团操操作权限 市场部 6 接团人
  840. var userInfo = await _sqlSugar.Queryable<Sys_Users>().Where(it => it.Id == userId && it.IsDel == 0).FirstAsync();
  841. if (userInfo != null)
  842. {
  843. if (userInfo.DepId == 7)
  844. {
  845. if (userInfo.JobPostId != 22 || userInfo.JobPostId != 32)
  846. {
  847. if (!string.IsNullOrEmpty(mobileSqlWhere)) mobileSqlWhere = $" Where {mobileSqlWhere}";
  848. sql = string.Format($@"Select
  849. ROW_NUMBER()Over(Order By Id Desc) as RowNumber,
  850. Id,
  851. GroupName
  852. From (
  853. Select
  854. distinct
  855. di.Id,
  856. di.TeamName GroupName
  857. From Grp_GroupsTaskAssignment gta With(NoLock)
  858. Inner Join Grp_DelegationInfo di With(NoLock) On gta.DIId = di.Id
  859. Where gta.IsDel = 0 And di.IsDel = 0 And gta.UId = {userId}
  860. ) Temp {mobileSqlWhere}");
  861. }
  862. }
  863. }
  864. }
  865. RefAsync<int> total = 0;
  866. var groupNamePageData = await _sqlSugar.SqlQueryable<GroupNamePageView>(sql).ToPageListAsync(pageIndex, pageSize, total);
  867. _res.Code = 200;
  868. _res.Data = groupNamePageData;
  869. _res.Msg = MsgTips.Succeed;
  870. _res.Count = total;
  871. return _res;
  872. }
  873. /// <summary>
  874. /// 获取接团名称List And 签证国别
  875. /// </summary>
  876. /// <param name="dto"></param>
  877. /// <returns></returns>
  878. public async Task<Result> GetGroupNameAndVisaNationality(GroupNameDto dto)
  879. {
  880. Result result = new Result() { Code = -2, Msg = "未知错误" };
  881. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  882. {
  883. string sql = string.Format(@"Select Id,TeamName GroupName From Grp_DelegationInfo
  884. Where TeamName != '' And IsDel = 0
  885. Order By Id Desc");
  886. var _groupNameList = await _sqlSugar.SqlQueryable<GroupNameView>(sql).ToListAsync();
  887. string visaSql = string.Format(@"Select Id,Name From Sys_SetData Where STid = 41 And IsDel = 0");
  888. var _setDataList = await _sqlSugar.SqlQueryable<SetDataInfoView>(visaSql).ToListAsync();
  889. var data = new {
  890. groupNameData = _groupNameList,
  891. visaNationalityData = _setDataList
  892. };
  893. result.Data = data;
  894. result.Code = 0;
  895. }
  896. return result;
  897. }
  898. #endregion
  899. #region 团组&签证
  900. /// <summary>
  901. /// 根据团组Id查询客户
  902. /// </summary>
  903. /// <param name="dto"></param>
  904. /// <returns></returns>
  905. public async Task<Result> GetCrmByGroupId(ClientByGroupIdDto dto)
  906. {
  907. Result result = new Result() { Code = -2 };
  908. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3)
  909. {
  910. string sql = string.Format(@"Select gdjc.GrpDCId grpId,cdc.Id,cdc.LastName+cdc.FirstName clientName,cdc.Tel,ccc.CertNo CerdNo
  911. From Grp_DelegationJoinCustomer gdjc
  912. Inner join Crm_DeleClient cdc On gdjc.CrmDCId = cdc.Id
  913. Left Join Crm_CustomerCert ccc On ccc.SdId = 773 And cdc.Id = ccc.DcId
  914. Where gdjc.GrpDCId = {0}", dto.GroupId);
  915. var clientList = await _sqlSugar.SqlQueryable<CrmByGroupIdView>(sql).ToListAsync();
  916. if (clientList.Count > 0)
  917. {
  918. result.Code = 0;
  919. result.Msg = "成功!";
  920. result.Data = clientList;
  921. }
  922. else
  923. {
  924. result.Msg = "暂无数据!";
  925. }
  926. }
  927. return result;
  928. }
  929. #endregion
  930. }
  931. }