DelegationInfoRepository.cs 46 KB

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