DelegationInfoRepository.cs 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075
  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. result.Code = 0;
  313. result.Msg = "成功!";
  314. result.Data = _DelegationInfo;
  315. if (dto.PortType == 2)
  316. {
  317. var GroupProcessOperationDtoParam = new GroupProcessOperationDto();
  318. GroupProcessOperationDtoParam = _mapper.Map<DelegationInfoWebView, GroupProcessOperationDto>(_DelegationInfo);
  319. List<Crm_DeleClient> DeleClientArr = await _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0).ToListAsync(); //客户信息
  320. List<Grp_TourClientList> _DeleClients = await _sqlSugar.Queryable<Grp_TourClientList>().Where(it => it.IsDel == 0 && it.DiId == dto.Id).ToListAsync(); // 接团客户名单
  321. List<Crm_CustomerCert> _CustomerCerts = await _sqlSugar.Queryable<Crm_CustomerCert>().Where(it => it.IsDel == 0 && it.SdId == 773).ToListAsync(); // 身份证类型证件信息
  322. List<Crm_CustomerCompany> CompanyArr = await _sqlSugar.Queryable<Crm_CustomerCompany>().Where(it => it.IsDel == 0).ToListAsync();
  323. var TourClientListInfoArr = new List<TourClientListProcessInfo>();
  324. var timeParam = new DateTime();
  325. foreach (var item in _DeleClients)
  326. {
  327. var param = new TourClientListProcessInfo();
  328. var clientInfo = DeleClientArr.FirstOrDefault(x => x.Id == item.ClientId);
  329. if (clientInfo == null) clientInfo = new Crm_DeleClient();
  330. var clientIDInfo = _CustomerCerts.FirstOrDefault(x=>x.DcId == item.ClientId); //身份证信息
  331. if (clientIDInfo == null) clientIDInfo = new Crm_CustomerCert();
  332. var Company = CompanyArr.FirstOrDefault(x => x.Id == clientInfo.CrmCompanyId);
  333. if(Company == null) Company = new Crm_CustomerCompany();
  334. param.IDCardNo = clientIDInfo.CertNo;
  335. param.Remark = item.Remark;
  336. param.BirthDay = clientInfo.BirthDay == null ? "" : DateTime.TryParse(Convert.ToDateTime( clientInfo.BirthDay).ToString("yyyy-MM-dd"), out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  337. param.FirstName = clientInfo.FirstName;
  338. param.LastName = clientInfo.LastName;
  339. param.CompanyFullName = Company.CompanyFullName;
  340. param.Job = clientInfo.Job;
  341. param.Sex = clientInfo.Sex;
  342. param.Phone = clientInfo.Phone;
  343. param.Pinyin = clientInfo.Pinyin;
  344. param.HotelSpecialNeeds = item.HotelSpecialNeeds;
  345. param.MealSpecialNeeds = item.MealSpecialNeeds;
  346. param.ShippingSpaceSpecialNeeds = item.ShippingSpaceSpecialNeeds;
  347. param.ShippingSpaceTypeId = item.ShippingSpaceTypeId;
  348. param.Id = clientInfo.Id;
  349. TourClientListInfoArr.Add(param);
  350. }
  351. GroupProcessOperationDtoParam.PortType = dto.PortType;
  352. GroupProcessOperationDtoParam.TourClientListInfos = TourClientListInfoArr;
  353. GroupProcessOperationDtoParam.VisitDate = DateTime.TryParse(GroupProcessOperationDtoParam.VisitDate, out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  354. GroupProcessOperationDtoParam.TontractTime = DateTime.TryParse(GroupProcessOperationDtoParam.TontractTime, out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  355. result.Data = GroupProcessOperationDtoParam;
  356. }
  357. else if (dto.PortType == 3)
  358. {
  359. var GroupProcessOperationDtoParam = new GroupProcessOperationDto();
  360. GroupProcessOperationDtoParam = _mapper.Map<DelegationInfoWebView, GroupProcessOperationDto>(_DelegationInfo);
  361. List<Crm_DeleClient> DeleClientArr = await _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0).ToListAsync(); //客户信息
  362. List<Grp_TourClientList> _DeleClients = await _sqlSugar.Queryable<Grp_TourClientList>().Where(it => it.IsDel == 0 && it.DiId == dto.Id).ToListAsync(); // 接团客户名单
  363. List<Crm_CustomerCert> _CustomerCerts = await _sqlSugar.Queryable<Crm_CustomerCert>().Where(it => it.IsDel == 0 && it.SdId == 773).ToListAsync(); // 身份证类型证件信息
  364. List<Crm_CustomerCompany> CompanyArr = await _sqlSugar.Queryable<Crm_CustomerCompany>().Where(it => it.IsDel == 0).ToListAsync();
  365. var TourClientListInfoArr = new List<TourClientListProcessInfo>();
  366. var timeParam = new DateTime();
  367. foreach (var item in _DeleClients)
  368. {
  369. var param = new TourClientListProcessInfo();
  370. var clientInfo = DeleClientArr.FirstOrDefault(x => x.Id == item.ClientId);
  371. if (clientInfo == null) clientInfo = new Crm_DeleClient();
  372. var clientIDInfo = _CustomerCerts.FirstOrDefault(x => x.DcId == item.ClientId); //身份证信息
  373. if (clientIDInfo == null) clientIDInfo = new Crm_CustomerCert();
  374. var Company = CompanyArr.FirstOrDefault(x => x.Id == clientInfo.CrmCompanyId);
  375. if (Company == null) Company = new Crm_CustomerCompany();
  376. param.IDCardNo = clientIDInfo.CertNo;
  377. param.Remark = item.Remark;
  378. param.BirthDay = clientInfo.BirthDay == null ? "" : DateTime.TryParse(Convert.ToDateTime(clientInfo.BirthDay).ToString("yyyy-MM-dd"), out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  379. param.FirstName = clientInfo.FirstName;
  380. param.LastName = clientInfo.LastName;
  381. param.CompanyFullName = Company.CompanyFullName;
  382. param.Job = clientInfo.Job;
  383. param.Sex = clientInfo.Sex;
  384. param.Phone = clientInfo.Phone;
  385. param.Pinyin = clientInfo.Pinyin;
  386. param.HotelSpecialNeeds = item.HotelSpecialNeeds;
  387. param.MealSpecialNeeds = item.MealSpecialNeeds;
  388. param.ShippingSpaceSpecialNeeds = item.ShippingSpaceSpecialNeeds;
  389. param.ShippingSpaceTypeId = item.ShippingSpaceTypeId;
  390. param.Id = item.Id;
  391. TourClientListInfoArr.Add(param);
  392. }
  393. GroupProcessOperationDtoParam.PortType = dto.PortType;
  394. GroupProcessOperationDtoParam.TourClientListInfos = TourClientListInfoArr;
  395. GroupProcessOperationDtoParam.VisitDate = DateTime.TryParse(GroupProcessOperationDtoParam.VisitDate, out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  396. GroupProcessOperationDtoParam.TontractTime = DateTime.TryParse(GroupProcessOperationDtoParam.TontractTime, out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  397. result.Data = GroupProcessOperationDtoParam;
  398. }
  399. }
  400. else result.Msg = "暂无该团组信息";
  401. }
  402. return result;
  403. }
  404. /// <summary>
  405. /// 获取接团信息 编辑
  406. /// 基础 数据源
  407. /// </summary>
  408. /// <param name="dto"></param>
  409. /// <returns></returns>
  410. public async Task<Result> GroupEditBasicSource(GroupListDto dto)
  411. {
  412. Result result = new Result() { Code = -2, Msg = "未知错误" };
  413. try
  414. {
  415. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  416. {
  417. dynamic? teamTypeData1 = null;
  418. string teamTypeSql = string.Format(@"Select Id,Name From Sys_SetData Where STid = {0} And IsDel = {1}", 10, 0);
  419. var teamTypeData = await _sqlSugar.SqlQueryable<SetDataInfoView>(teamTypeSql).ToListAsync(); ; //团组分类 10
  420. if (teamTypeData.Count > 0)
  421. {
  422. teamTypeData1 = teamTypeData;
  423. }
  424. dynamic? teamLevData1 = null;
  425. string teamLevSql = string.Format(@"Select Id,Name From Sys_SetData Where STid = {0} And IsDel = {1}", 56, 0);
  426. var teamLevData = await _sqlSugar.SqlQueryable<SetDataInfoView>(teamLevSql).ToListAsync(); ; //团组等级 56
  427. if (teamLevData.Count > 0)
  428. {
  429. teamLevData1 = teamLevData;
  430. }
  431. dynamic? userData1 = null;
  432. string userSql = string.Format(@"Select Id,CnName From Sys_Users Where IsDel = {0}", 0);
  433. var userData = await _sqlSugar.SqlQueryable<UserNameView>(userSql).ToListAsync();
  434. if (userData.Count > 0)
  435. {
  436. userData1 = userData;
  437. }
  438. //客户单位数据源 来源市场客户资料
  439. dynamic? clientData1 = null;
  440. string clientSql = $@"Select Client,Contact,Telephone,WeChat From Crm_NewClientData Where IsDel = 0";
  441. var clientData = await _sqlSugar.SqlQueryable<Crm_NewClientData>(clientSql).ToListAsync();
  442. if (clientData.Count > 0)
  443. {
  444. clientData1 = clientData.Select(it => new { it.Client,it.Contact,it.Telephone,it.Wechat }).ToList();
  445. }
  446. result.Code = 0;
  447. result.Msg = "成功!";
  448. result.Data = new
  449. {
  450. teamTypeData = teamTypeData1,
  451. teamLevData = teamLevData1,
  452. userData = userData1,
  453. clientData = clientData1
  454. };
  455. }
  456. }
  457. catch (Exception ex)
  458. {
  459. result.Msg = ex.Message;
  460. }
  461. return result;
  462. }
  463. /// <summary>
  464. /// 团组信息操作
  465. /// </summary>
  466. /// <param name="dto"></param>
  467. /// <returns></returns>
  468. public async Task<Result>GroupOperation(GroupOperationDto dto)
  469. {
  470. Result result = new Result() { Code = -2, Msg = "未知错误" };
  471. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  472. {
  473. #region 添加出访起止时间
  474. var startTime = new DateTime();
  475. var endTime = new DateTime();
  476. if (DateTime.TryParse(dto.VisitDate, out startTime))
  477. {
  478. endTime = startTime.AddDays(dto.VisitDays - 1);//含当天
  479. }
  480. #endregion
  481. if (dto.Status == 1) //添加
  482. {
  483. string selectSql = string.Format(@"Select * From Grp_DelegationInfo
  484. Where IsDel = 0
  485. And TeamName = '{0}'
  486. And ClientName = '{1}'
  487. And ClientUnit ='{2}'
  488. And VisitDate ='{3}'",dto.TeamName, dto.ClientName, dto.ClientUnit, dto.VisitDate);
  489. var selectGroupInfo = _sqlSugar.SqlQueryable<Grp_DelegationInfo>(selectSql).First();
  490. if (selectGroupInfo != null)
  491. {
  492. result.Msg = "数据已存在,请勿重复添加!";
  493. return result;
  494. }
  495. //string teamCodeSql = string.Format("Select SalesQuoteNo From Grp_DelegationInfo");
  496. //var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  497. //string SalesQuoteNo = "";
  498. //while (true)
  499. //{
  500. // SalesQuoteNo = Tools.CommonFun.GetRandomStr(6);
  501. // if (!teamCodeItem.Equals(SalesQuoteNo))
  502. // {
  503. // break;
  504. // }
  505. //}
  506. string countrys = string.Empty;
  507. string countryReq = dto.VisitCountry;
  508. if (!string.IsNullOrEmpty(countryReq))
  509. {
  510. if (countryReq.Contains(",")) countrys = countryReq.Replace(',','|');
  511. else if (countryReq.Contains(",")) countrys = countryReq.Replace(',', '|');
  512. else if (countryReq.Contains(" ")) countrys = countryReq.Replace(' ', '|');
  513. else if (countryReq.Contains("、")) countrys = countryReq.Replace('、', '|');
  514. else if (countryReq.Contains(".")) countrys = countryReq.Replace('.', '|');
  515. else countrys = countryReq;
  516. }
  517. //建团时 默认出团 设置 团组code
  518. string teamCode="";
  519. string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
  520. var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  521. while (true)
  522. {
  523. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  524. if (!teamCodeItem.Equals(teamCode))
  525. {
  526. break;
  527. }
  528. }
  529. Grp_DelegationInfo delegationInfo = new Grp_DelegationInfo()
  530. {
  531. SalesQuoteNo = dto.SalesQuoteNo,
  532. TeamLevSId = dto.TeamLevSId,
  533. ClientName = dto.ClientName,
  534. ClientUnit = dto.ClientUnit,
  535. TeamName = dto.TeamName,
  536. TeamDid = dto.TeamDid,
  537. VisitDate = Convert.ToDateTime(dto.VisitDate),
  538. VisitCountry = countrys,
  539. VisitPurpose = dto.VisitPurpose,
  540. VisitDays = dto.VisitDays,
  541. VisitPNumber = dto.VisitPNumber,
  542. SpecialNeeds = dto.SpecialNeeds,
  543. OtherNeeds = dto.OtherNeeds,
  544. Remark = dto.Remark,
  545. JietuanOperator = dto.JietuanOperator,
  546. TellPhone = dto.TellPhone,
  547. WeChatNo = dto.WeChatNo,
  548. CGRWSPBMMC = dto.CGRWSPBMMC,
  549. CGRWSPWH = dto.CGRWSPWH,
  550. ZZSCBMMC = dto.ZZSCBMMC,
  551. ZZSCSPWH = dto.ZZSCSPWH,
  552. TontractTime = Convert.ToDateTime(dto.TontractTime),
  553. IsBid = dto.IsBid,
  554. PaymentMoney = dto.PaymentMoney,
  555. PayDay = dto.PayDay,
  556. TourCode = teamCode,
  557. GroupsOperator = dto.UserId,
  558. GroupsTime = DateTime.Now,
  559. SalesDate = DateTime.Now,
  560. IsState = 0, //默认团组未完成 0
  561. JietuanTime = DateTime.Now,
  562. IsDel = 0,
  563. BudgetCost = 0.00M,
  564. HotelComplain = 0,
  565. OPComplain = 0,
  566. OAComplain = 0,
  567. AirComplain = 0,
  568. VisaComplain = 0,
  569. CreateUserId = dto.UserId,
  570. CreateTime = DateTime.Now,
  571. DeleteUserId = null,
  572. DeleteTime = new DateTime(1990, 1, 1).ToString("yyyy-MM-dd HH:mm:ss"),
  573. OpRoyaltyLv = dto.OpRoyaltyLv,
  574. OpRoyaltyRemark=dto.opRoyaltyRemark,
  575. Officialneeds = dto.Officialneeds,
  576. VisitStartDate = startTime,
  577. VisitEndDate = endTime,
  578. };
  579. var addId = _sqlSugar.Insertable(delegationInfo).ExecuteReturnIdentity();
  580. if (addId > 0)
  581. {
  582. result.Code = 0;
  583. result.Msg = "添加成功!";
  584. result.Data = addId;
  585. }
  586. else
  587. {
  588. result.Msg = "添加失败!";
  589. }
  590. }
  591. else if (dto.Status == 2) //修改
  592. {
  593. var updateStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo
  594. {
  595. SalesQuoteNo = dto.SalesQuoteNo,
  596. TeamLevSId = dto.TeamLevSId,
  597. ClientName = dto.ClientName,
  598. ClientUnit = dto.ClientUnit,
  599. TeamName = dto.TeamName,
  600. TeamDid = dto.TeamDid,
  601. VisitDate = Convert.ToDateTime(dto.VisitDate),
  602. VisitCountry = dto.VisitCountry,
  603. VisitPurpose = dto.VisitPurpose,
  604. VisitDays = dto.VisitDays,
  605. VisitPNumber = dto.VisitPNumber,
  606. SpecialNeeds = dto.SpecialNeeds,
  607. OtherNeeds = dto.OtherNeeds,
  608. Remark = dto.Remark,
  609. JietuanOperator = dto.JietuanOperator,
  610. TellPhone = dto.TellPhone,
  611. WeChatNo = dto.WeChatNo,
  612. CGRWSPBMMC = dto.CGRWSPBMMC,
  613. CGRWSPWH = dto.CGRWSPWH,
  614. ZZSCBMMC = dto.ZZSCBMMC,
  615. ZZSCSPWH = dto.ZZSCSPWH,
  616. TontractTime = Convert.ToDateTime(dto.TontractTime),
  617. IsBid = dto.IsBid,
  618. PaymentMoney = dto.PaymentMoney,
  619. PayDay = dto.PayDay,
  620. OpRoyaltyLv = dto.OpRoyaltyLv,
  621. OpRoyaltyRemark = dto.opRoyaltyRemark,
  622. Officialneeds = dto.Officialneeds,
  623. VisitStartDate = startTime,
  624. VisitEndDate = endTime,
  625. });
  626. if (updateStatus)
  627. {
  628. result.Code = 0;
  629. result.Msg = "修改成功!";
  630. }
  631. else
  632. {
  633. result.Msg = "修改失败!";
  634. }
  635. }
  636. else if (dto.Status == 3) //删除
  637. {
  638. var deleteStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo
  639. {
  640. DeleteUserId = dto.UserId,
  641. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  642. IsDel = 1
  643. });
  644. if (deleteStatus)
  645. {
  646. result.Code = 0;
  647. result.Msg = "删除成功!";
  648. }
  649. else
  650. {
  651. result.Msg = "删除失败!";
  652. }
  653. }
  654. }
  655. return result;
  656. }
  657. /// <summary>
  658. /// 团组信息操作 - 删除
  659. /// </summary>
  660. /// <param name="dto"></param>
  661. /// <returns></returns>
  662. public async Task<Result> GroupDel(GroupDelDto dto)
  663. {
  664. Result result = new Result() { Code = -2, Msg = "未知错误" };
  665. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  666. {
  667. var deleteStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo
  668. {
  669. DeleteUserId = dto.UserId,
  670. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  671. IsDel = 1
  672. });
  673. if (deleteStatus)
  674. {
  675. result.Code = 0;
  676. result.Msg = "删除成功!";
  677. }
  678. else
  679. {
  680. result.Msg = "删除失败!";
  681. }
  682. }
  683. return result;
  684. }
  685. /// <summary>
  686. /// 获取销售报价号
  687. /// </summary>
  688. /// <returns></returns>
  689. public async Task<Result> GetGroupSalesQuoteNo()
  690. {
  691. Result result = new Result() { Code = -2, Msg = "未知错误" };
  692. string teamCodeSql = string.Format("Select SalesQuoteNo From Grp_DelegationInfo");
  693. var teamCodeItem = await _sqlSugar.SqlQueryable<SalesQuoteNoView>(teamCodeSql).ToListAsync();
  694. string teamCode = "";
  695. while (true)
  696. {
  697. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  698. if (!teamCodeItem.Equals(teamCode))
  699. {
  700. break;
  701. }
  702. }
  703. result.Code = 0;
  704. result.Msg = "成功!";
  705. result.Data = teamCode;
  706. return result;
  707. }
  708. /// <summary>
  709. /// 团组删除
  710. /// </summary>
  711. /// <returns></returns>
  712. public async Task<Result> GroupDeleteById()
  713. {
  714. Result result = new Result() { Code = -2, Msg = "未知错误" };
  715. string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
  716. var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  717. string teamCode = "";
  718. while (true)
  719. {
  720. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  721. if (!teamCodeItem.Equals(teamCode))
  722. {
  723. break;
  724. }
  725. }
  726. result.Code = 0;
  727. result.Msg = "成功!";
  728. result.Data = teamCode;
  729. return result;
  730. }
  731. /// <summary>
  732. /// 团组确认出团
  733. /// </summary>
  734. /// <returns></returns>
  735. public async Task<Result> ConfirmationGroup(ConfirmationGroupDto dto)
  736. {
  737. Result result = new Result() { Code = -2, Msg = "未知错误" };
  738. string teamCode = "";
  739. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  740. {
  741. string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
  742. var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  743. while (true)
  744. {
  745. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  746. if (!teamCodeItem.Equals(teamCode))
  747. {
  748. break;
  749. }
  750. }
  751. var deleteStatus = await UpdateAsync(a => a.Id == dto.GroupId, a => new Grp_DelegationInfo
  752. {
  753. TourCode = teamCode,
  754. GroupsOperator = dto.GroupsOperator,
  755. GroupsTime = DateTime.Now
  756. });
  757. if (deleteStatus)
  758. {
  759. result.Code = 0;
  760. result.Msg = "确认出团设置成功!";
  761. }
  762. else
  763. {
  764. result.Msg = "确认出团设置失败!";
  765. }
  766. }
  767. result.Code = 0;
  768. result.Msg = "成功!";
  769. result.Data = teamCode;
  770. return result;
  771. }
  772. /// <summary>
  773. /// 获取接团名称List
  774. /// </summary>
  775. /// <param name="dto"></param>
  776. /// <returns></returns>
  777. public async Task<Result> GetGroupNameList(GroupNameDto dto)
  778. {
  779. Result result = new Result() { Code = -2, Msg = "未知错误" };
  780. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  781. {
  782. string sql = string.Format(@"Select Id,TeamName GroupName From Grp_DelegationInfo
  783. Where TeamName != '' And IsDel = 0
  784. Order By Id Desc");
  785. var _groupNameList = await _sqlSugar.SqlQueryable<GroupNameView>(sql).ToListAsync();
  786. if (_groupNameList.Count > 0)
  787. {
  788. result.Code = 0;
  789. result.Msg = "成功!";
  790. result.Data = _groupNameList;
  791. }
  792. else
  793. {
  794. result.Msg = "暂无团组信息";
  795. }
  796. }
  797. return result;
  798. }
  799. //PostGroupNameScreen
  800. /// <summary>
  801. /// 获取接团名称 Page List
  802. /// </summary>
  803. /// <param name="dto"></param>
  804. /// <returns></returns>
  805. public async Task<JsonView> GetGroupNameList(int portType,int pageIndex,int pageSize, string groupName,int userId)
  806. {
  807. var _res = new JsonView() { Code = 400 , Msg = MsgTips.Fail };
  808. string sql = "";
  809. string sqlWhere = "";
  810. string mobileSqlWhere = "";
  811. if (!string.IsNullOrEmpty(groupName))
  812. {
  813. sqlWhere += string.Format($@"And TeamName Like '%{groupName}%'");
  814. mobileSqlWhere += string.Format($@"GroupName Like '%{groupName}%'");
  815. }
  816. List<int> userIds = new List<int>() { -1, 21 };
  817. if (!userIds.Contains(userId))
  818. {
  819. sqlWhere += string.Format($@"And JietuanOperator = {userId}");
  820. }
  821. sql = string.Format($@"Select ROW_NUMBER()Over(Order By Id Desc) as RowNumber,Id,TeamName GroupName From Grp_DelegationInfo
  822. Where IsDel = 0 {sqlWhere}");
  823. if (portType == 1) //web
  824. { }
  825. else if (portType == 2 || portType == 3)
  826. {
  827. //国交部 7 (主管 22,经理 32)团操操作权限 市场部 6 接团人
  828. var userInfo = await _sqlSugar.Queryable<Sys_Users>().Where(it => it.Id == userId && it.IsDel == 0).FirstAsync();
  829. if (userInfo != null)
  830. {
  831. if (userInfo.DepId == 7)
  832. {
  833. if (userInfo.JobPostId != 22 || userInfo.JobPostId != 32)
  834. {
  835. if (!string.IsNullOrEmpty(mobileSqlWhere)) mobileSqlWhere = $" Where {mobileSqlWhere}";
  836. sql = string.Format($@"Select
  837. ROW_NUMBER()Over(Order By Id Desc) as RowNumber,
  838. Id,
  839. GroupName
  840. From (
  841. Select
  842. distinct
  843. di.Id,
  844. di.TeamName GroupName
  845. From Grp_GroupsTaskAssignment gta With(NoLock)
  846. Inner Join Grp_DelegationInfo di With(NoLock) On gta.DIId = di.Id
  847. Where gta.IsDel = 0 And di.IsDel = 0 And gta.UId = {userId}
  848. ) Temp {mobileSqlWhere}");
  849. }
  850. }
  851. }
  852. }
  853. RefAsync<int> total = 0;
  854. var groupNamePageData = await _sqlSugar.SqlQueryable<GroupNamePageView>(sql).ToPageListAsync(pageIndex, pageSize, total);
  855. _res.Code = 200;
  856. _res.Data = groupNamePageData;
  857. _res.Msg = MsgTips.Succeed;
  858. _res.Count = total;
  859. return _res;
  860. }
  861. /// <summary>
  862. /// 获取接团名称List And 签证国别
  863. /// </summary>
  864. /// <param name="dto"></param>
  865. /// <returns></returns>
  866. public async Task<Result> GetGroupNameAndVisaNationality(GroupNameDto dto)
  867. {
  868. Result result = new Result() { Code = -2, Msg = "未知错误" };
  869. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  870. {
  871. string sql = string.Format(@"Select Id,TeamName GroupName From Grp_DelegationInfo
  872. Where TeamName != '' And IsDel = 0
  873. Order By Id Desc");
  874. var _groupNameList = await _sqlSugar.SqlQueryable<GroupNameView>(sql).ToListAsync();
  875. string visaSql = string.Format(@"Select Id,Name From Sys_SetData Where STid = 41 And IsDel = 0");
  876. var _setDataList = await _sqlSugar.SqlQueryable<SetDataInfoView>(visaSql).ToListAsync();
  877. var data = new {
  878. groupNameData = _groupNameList,
  879. visaNationalityData = _setDataList
  880. };
  881. result.Data = data;
  882. result.Code = 0;
  883. }
  884. return result;
  885. }
  886. #endregion
  887. #region 团组&签证
  888. /// <summary>
  889. /// 根据团组Id查询客户
  890. /// </summary>
  891. /// <param name="dto"></param>
  892. /// <returns></returns>
  893. public async Task<Result> GetCrmByGroupId(ClientByGroupIdDto dto)
  894. {
  895. Result result = new Result() { Code = -2 };
  896. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3)
  897. {
  898. string sql = string.Format(@"Select gdjc.GrpDCId grpId,cdc.Id,cdc.LastName+cdc.FirstName clientName,cdc.Tel,ccc.CertNo CerdNo
  899. From Grp_DelegationJoinCustomer gdjc
  900. Inner join Crm_DeleClient cdc On gdjc.CrmDCId = cdc.Id
  901. Left Join Crm_CustomerCert ccc On ccc.SdId = 773 And cdc.Id = ccc.DcId
  902. Where gdjc.GrpDCId = {0}", dto.GroupId);
  903. var clientList = await _sqlSugar.SqlQueryable<CrmByGroupIdView>(sql).ToListAsync();
  904. if (clientList.Count > 0)
  905. {
  906. result.Code = 0;
  907. result.Msg = "成功!";
  908. result.Data = clientList;
  909. }
  910. else
  911. {
  912. result.Msg = "暂无数据!";
  913. }
  914. }
  915. return result;
  916. }
  917. #endregion
  918. }
  919. }