DelegationInfoRepository.cs 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974
  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 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. str = str.Replace(item, "、");
  160. }
  161. }
  162. return str.Trim();
  163. }
  164. /// <summary>
  165. /// 团组国家分割字符
  166. /// 返回 国家数组
  167. /// </summary>
  168. /// <param name="teamName"></param>
  169. /// <returns></returns>
  170. public List<string> GroupSplitCountry (string visitCountry)
  171. {
  172. List<string> countrys = new List<string>();
  173. if (!string.IsNullOrEmpty(visitCountry))
  174. {
  175. if (visitCountry.Contains("、")) countrys = visitCountry.Split("、").ToList();
  176. else if (visitCountry.Contains("|")) countrys = visitCountry.Split("|").ToList();
  177. else countrys.Add(visitCountry);
  178. }
  179. return countrys;
  180. }
  181. /// <summary>
  182. /// 获取接团信息 Page List
  183. /// </summary>
  184. /// <param name="dto"></param>
  185. /// <returns></returns>
  186. public async Task<Result> GetGroupPageList(GroupCommissionDto dto)
  187. {
  188. Result result = new Result() { Code = -2, Msg = "未知错误" };
  189. ListViewBase<DelegationPageListView> groupsInfoPageList = new ListViewBase<DelegationPageListView>()
  190. {
  191. ReceiveDt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  192. };
  193. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  194. {
  195. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  196. int endIndex = startIndex + dto.PageSize - 1;
  197. int taskUserId = -1;
  198. string taskGroupIds = string.Empty;
  199. #region 处理用户团组操作权限
  200. if (dto.UserId != -1)
  201. {
  202. }
  203. #endregion
  204. string sql = string.Format(@"Select * From(Select row_number() over (order by gdi.Id Desc) as RowNumber,
  205. gdi.Id,SalesQuoteNo,TourCode,ssd.Id TeamTypeId, ssd.Name TeamType,ssd1.Id TeamLevId,
  206. ssd1.Name TeamLev,TeamName,ClientName,ClientUnit,VisitDate,VisitDays,VisitPNumber,
  207. su.CnName JietuanOperator,IsSure
  208. From Grp_DelegationInfo gdi
  209. Inner Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  210. Inner Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  211. Left Join Sys_Users su On gdi.CreateUserId = su.Id
  212. Where gdi.IsDel = 0
  213. )temp Where RowNumber Between {0} and {1}", startIndex, endIndex);
  214. string sqlCount = string.Format(@"Select Count(1) as Count From Grp_DelegationInfo gdi
  215. Inner Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  216. Inner Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  217. Left Join Sys_Users su On gdi.CreateUserId = su.Id
  218. Where gdi.IsDel = 0 ");
  219. List<DelegationPageListView> _DeleInfoList = await _sqlSugar.SqlQueryable<DelegationPageListView>(sql).ToListAsync();
  220. DelegationPageCountView _DeleCount = await _sqlSugar.SqlQueryable<DelegationPageCountView>(sqlCount).FirstAsync();
  221. int count = _DeleCount.Count;
  222. groupsInfoPageList = new ListViewBase<DelegationPageListView>
  223. {
  224. CurrPageIndex = dto.PageIndex,
  225. CurrPageSize = dto.PageSize,
  226. DataCount = count,
  227. DataList = _DeleInfoList
  228. };
  229. result.Code = 0;
  230. result.Msg = "成功!";
  231. result.Data = groupsInfoPageList;
  232. }
  233. return result;
  234. }
  235. /// <summary>
  236. /// 获取接团信息List
  237. /// </summary>
  238. /// <param name="dto"></param>
  239. /// <returns></returns>
  240. public async Task<Result> GetGroupList(GroupListDto dto)
  241. {
  242. Result result = new Result() { Code = -2, Msg = "未知错误" };
  243. if (dto.PortType == 1) {
  244. 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
  245. ,gs.Id as GrpScheduleId
  246. From Grp_DelegationInfo gdi
  247. Inner Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  248. Inner Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  249. Left Join Sys_Users su On gdi.CreateUserId = su.Id
  250. left Join Grp_Schedule gs On gdi.Id = gs.DiId
  251. Where gdi.IsDel = 0
  252. Order By gdi.CreateTime Desc");
  253. var _DelegationList = await _sqlSugar.SqlQueryable<DelegationListView>(sql).ToListAsync();
  254. if (_DelegationList.Count > 0)
  255. {
  256. result.Code = 0;
  257. result.Msg = "成功!";
  258. result.Data = _DelegationList;
  259. }
  260. else
  261. {
  262. result.Msg = "暂无该团组信息";
  263. }
  264. }
  265. else if (dto.PortType == 2 || dto.PortType == 3) //web
  266. {
  267. 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
  268. From Grp_DelegationInfo gdi
  269. Inner Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  270. Inner Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  271. Left Join Sys_Users su On gdi.CreateUserId = su.Id
  272. Where gdi.IsDel = 0
  273. Order By gdi.CreateTime Desc");
  274. var _DelegationList = await _sqlSugar.SqlQueryable<DelegationListView>(sql).ToListAsync();
  275. if (_DelegationList.Count > 0)
  276. {
  277. result.Code = 0;
  278. result.Msg = "成功!";
  279. result.Data = _DelegationList;
  280. }
  281. else
  282. {
  283. result.Msg = "暂无该团组信息";
  284. }
  285. }
  286. return result;
  287. }
  288. /// <summary>
  289. /// 获取接团信息Info
  290. /// </summary>
  291. /// <param name="dto"></param>
  292. /// <returns></returns>
  293. public async Task<Result> GetGroupInfo(GroupInfoDto dto)
  294. {
  295. Result result = new Result() { Code = -2, Msg = "未知错误" };
  296. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //Web Or Android
  297. {
  298. string sql = string.Format(@"Select Id,SalesQuoteNo,TourCode,JietuanOperator,TeamLevSId,TeamDid,TeamName,ClientName,
  299. ClientUnit,VisitCountry,VisitDate,VisitDays,VisitPNumber,TontractTime,
  300. PayDay,PaymentMoney,VisitPurpose,SpecialNeeds,OtherNeeds,CGRWSPBMMC,CGRWSPWH,
  301. ZZSCBMMC,ZZSCSPWH,Remark,TellPhone,WeChatNo,OpRoyaltyLv,OpRoyaltyRemark,Officialneeds
  302. From Grp_DelegationInfo Where Id = {0} And IsDel = 0", dto.Id);
  303. var _DelegationInfo = await _sqlSugar.SqlQueryable<DelegationInfoWebView>(sql).FirstAsync();
  304. if (_DelegationInfo != null)
  305. {
  306. result.Code = 0;
  307. result.Msg = "成功!";
  308. result.Data = _DelegationInfo;
  309. if (dto.PortType == 2)
  310. {
  311. var GroupProcessOperationDtoParam = new GroupProcessOperationDto();
  312. GroupProcessOperationDtoParam = _mapper.Map<DelegationInfoWebView, GroupProcessOperationDto>(_DelegationInfo);
  313. List<Crm_DeleClient> DeleClientArr = await _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0).ToListAsync(); //客户信息
  314. List<Grp_TourClientList> _DeleClients = await _sqlSugar.Queryable<Grp_TourClientList>().Where(it => it.IsDel == 0 && it.DiId == dto.Id).ToListAsync(); // 接团客户名单
  315. List<Crm_CustomerCert> _CustomerCerts = await _sqlSugar.Queryable<Crm_CustomerCert>().Where(it => it.IsDel == 0 && it.SdId == 773).ToListAsync(); // 身份证类型证件信息
  316. List<Crm_CustomerCompany> CompanyArr = await _sqlSugar.Queryable<Crm_CustomerCompany>().Where(it => it.IsDel == 0).ToListAsync();
  317. var TourClientListInfoArr = new List<TourClientListProcessInfo>();
  318. var timeParam = new DateTime();
  319. foreach (var item in _DeleClients)
  320. {
  321. var param = new TourClientListProcessInfo();
  322. var clientInfo = DeleClientArr.FirstOrDefault(x => x.Id == item.ClientId);
  323. if (clientInfo == null) clientInfo = new Crm_DeleClient();
  324. var clientIDInfo = _CustomerCerts.FirstOrDefault(x=>x.DcId == item.ClientId); //身份证信息
  325. if (clientIDInfo == null) clientIDInfo = new Crm_CustomerCert();
  326. var Company = CompanyArr.FirstOrDefault(x => x.Id == clientInfo.CrmCompanyId);
  327. if(Company == null) Company = new Crm_CustomerCompany();
  328. param.IDCardNo = clientIDInfo.CertNo;
  329. param.Remark = item.Remark;
  330. param.BirthDay = DateTime.TryParse(clientInfo.BirthDay, out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  331. param.FirstName = clientInfo.FirstName;
  332. param.LastName = clientInfo.LastName;
  333. param.CompanyFullName = Company.CompanyFullName;
  334. param.Job = clientInfo.Job;
  335. param.Sex = clientInfo.Sex;
  336. param.Phone = clientInfo.Phone;
  337. param.Pinyin = clientInfo.Pinyin;
  338. param.HotelSpecialNeeds = item.HotelSpecialNeeds;
  339. param.MealSpecialNeeds = item.MealSpecialNeeds;
  340. param.ShippingSpaceSpecialNeeds = item.ShippingSpaceSpecialNeeds;
  341. param.ShippingSpaceTypeId = item.ShippingSpaceTypeId;
  342. param.Id = clientInfo.Id;
  343. TourClientListInfoArr.Add(param);
  344. }
  345. GroupProcessOperationDtoParam.PortType = dto.PortType;
  346. GroupProcessOperationDtoParam.TourClientListInfos = TourClientListInfoArr;
  347. GroupProcessOperationDtoParam.VisitDate = DateTime.TryParse(GroupProcessOperationDtoParam.VisitDate, out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  348. GroupProcessOperationDtoParam.TontractTime = DateTime.TryParse(GroupProcessOperationDtoParam.TontractTime, out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  349. result.Data = GroupProcessOperationDtoParam;
  350. }
  351. else if (dto.PortType == 3)
  352. {
  353. var GroupProcessOperationDtoParam = new GroupProcessOperationDto();
  354. GroupProcessOperationDtoParam = _mapper.Map<DelegationInfoWebView, GroupProcessOperationDto>(_DelegationInfo);
  355. List<Crm_DeleClient> DeleClientArr = await _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0).ToListAsync(); //客户信息
  356. List<Grp_TourClientList> _DeleClients = await _sqlSugar.Queryable<Grp_TourClientList>().Where(it => it.IsDel == 0 && it.DiId == dto.Id).ToListAsync(); // 接团客户名单
  357. List<Crm_CustomerCert> _CustomerCerts = await _sqlSugar.Queryable<Crm_CustomerCert>().Where(it => it.IsDel == 0 && it.SdId == 773).ToListAsync(); // 身份证类型证件信息
  358. List<Crm_CustomerCompany> CompanyArr = await _sqlSugar.Queryable<Crm_CustomerCompany>().Where(it => it.IsDel == 0).ToListAsync();
  359. var TourClientListInfoArr = new List<TourClientListProcessInfo>();
  360. var timeParam = new DateTime();
  361. foreach (var item in _DeleClients)
  362. {
  363. var param = new TourClientListProcessInfo();
  364. var clientInfo = DeleClientArr.FirstOrDefault(x => x.Id == item.ClientId);
  365. if (clientInfo == null) clientInfo = new Crm_DeleClient();
  366. var clientIDInfo = _CustomerCerts.FirstOrDefault(x => x.DcId == item.ClientId); //身份证信息
  367. if (clientIDInfo == null) clientIDInfo = new Crm_CustomerCert();
  368. var Company = CompanyArr.FirstOrDefault(x => x.Id == clientInfo.CrmCompanyId);
  369. if (Company == null) Company = new Crm_CustomerCompany();
  370. param.IDCardNo = clientIDInfo.CertNo;
  371. param.Remark = item.Remark;
  372. param.BirthDay = DateTime.TryParse(clientInfo.BirthDay, out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  373. param.FirstName = clientInfo.FirstName;
  374. param.LastName = clientInfo.LastName;
  375. param.CompanyFullName = Company.CompanyFullName;
  376. param.Job = clientInfo.Job;
  377. param.Sex = clientInfo.Sex;
  378. param.Phone = clientInfo.Phone;
  379. param.Pinyin = clientInfo.Pinyin;
  380. param.HotelSpecialNeeds = item.HotelSpecialNeeds;
  381. param.MealSpecialNeeds = item.MealSpecialNeeds;
  382. param.ShippingSpaceSpecialNeeds = item.ShippingSpaceSpecialNeeds;
  383. param.ShippingSpaceTypeId = item.ShippingSpaceTypeId;
  384. param.Id = item.Id;
  385. TourClientListInfoArr.Add(param);
  386. }
  387. GroupProcessOperationDtoParam.PortType = dto.PortType;
  388. GroupProcessOperationDtoParam.TourClientListInfos = TourClientListInfoArr;
  389. GroupProcessOperationDtoParam.VisitDate = DateTime.TryParse(GroupProcessOperationDtoParam.VisitDate, out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  390. GroupProcessOperationDtoParam.TontractTime = DateTime.TryParse(GroupProcessOperationDtoParam.TontractTime, out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  391. result.Data = GroupProcessOperationDtoParam;
  392. }
  393. }
  394. else result.Msg = "暂无该团组信息";
  395. }
  396. return result;
  397. }
  398. /// <summary>
  399. /// 获取接团信息 编辑
  400. /// 基础 数据源
  401. /// </summary>
  402. /// <param name="dto"></param>
  403. /// <returns></returns>
  404. public async Task<Result> GroupEditBasicSource(GroupListDto dto)
  405. {
  406. Result result = new Result() { Code = -2, Msg = "未知错误" };
  407. try
  408. {
  409. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  410. {
  411. dynamic? teamTypeData1 = null;
  412. string teamTypeSql = string.Format(@"Select Id,Name From Sys_SetData Where STid = {0} And IsDel = {1}", 10, 0);
  413. var teamTypeData = await _sqlSugar.SqlQueryable<SetDataInfoView>(teamTypeSql).ToListAsync(); ; //团组分类 10
  414. if (teamTypeData.Count > 0)
  415. {
  416. teamTypeData1 = teamTypeData;
  417. }
  418. dynamic? teamLevData1 = null;
  419. string teamLevSql = string.Format(@"Select Id,Name From Sys_SetData Where STid = {0} And IsDel = {1}", 56, 0);
  420. var teamLevData = await _sqlSugar.SqlQueryable<SetDataInfoView>(teamLevSql).ToListAsync(); ; //团组等级 56
  421. if (teamLevData.Count > 0)
  422. {
  423. teamLevData1 = teamLevData;
  424. }
  425. dynamic? userData1 = null;
  426. string userSql = string.Format(@"Select Id,CnName From Sys_Users Where IsDel = {0}", 0);
  427. var userData = await _sqlSugar.SqlQueryable<UserNameView>(userSql).ToListAsync();
  428. if (userData.Count > 0)
  429. {
  430. userData1 = userData;
  431. }
  432. //客户单位数据源 来源市场客户资料
  433. dynamic? clientData1 = null;
  434. string clientSql = $@"Select Client,Contact,Telephone,WeChat From Crm_NewClientData Where IsDel = 0";
  435. var clientData = await _sqlSugar.SqlQueryable<Crm_NewClientData>(clientSql).ToListAsync();
  436. if (clientData.Count > 0)
  437. {
  438. clientData1 = clientData.Select(it => new { it.Client,it.Contact,it.Telephone,it.Wechat }).ToList();
  439. }
  440. result.Code = 0;
  441. result.Msg = "成功!";
  442. result.Data = new
  443. {
  444. teamTypeData = teamTypeData1,
  445. teamLevData = teamLevData1,
  446. userData = userData1,
  447. clientData = clientData1
  448. };
  449. }
  450. }
  451. catch (Exception ex)
  452. {
  453. result.Msg = ex.Message;
  454. }
  455. return result;
  456. }
  457. /// <summary>
  458. /// 团组信息操作
  459. /// </summary>
  460. /// <param name="dto"></param>
  461. /// <returns></returns>
  462. public async Task<Result>GroupOperation(GroupOperationDto dto)
  463. {
  464. Result result = new Result() { Code = -2, Msg = "未知错误" };
  465. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  466. {
  467. #region 添加出访起止时间
  468. var startTime = new DateTime();
  469. var endTime = new DateTime();
  470. if (DateTime.TryParse(dto.VisitDate, out startTime))
  471. {
  472. endTime = startTime.AddDays(dto.VisitDays);
  473. }
  474. #endregion
  475. if (dto.Status == 1) //添加
  476. {
  477. string selectSql = string.Format(@"Select * From Grp_DelegationInfo
  478. Where IsDel = 0
  479. And TeamName = '{0}'
  480. And ClientName = '{1}'
  481. And ClientUnit ='{2}'
  482. And VisitDate ='{3}'",dto.TeamName, dto.ClientName, dto.ClientUnit, dto.VisitDate);
  483. var selectGroupInfo = _sqlSugar.SqlQueryable<Grp_DelegationInfo>(selectSql).First();
  484. if (selectGroupInfo != null)
  485. {
  486. result.Msg = "数据已存在,请勿重复添加!";
  487. return result;
  488. }
  489. //string teamCodeSql = string.Format("Select SalesQuoteNo From Grp_DelegationInfo");
  490. //var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  491. //string SalesQuoteNo = "";
  492. //while (true)
  493. //{
  494. // SalesQuoteNo = Tools.CommonFun.GetRandomStr(6);
  495. // if (!teamCodeItem.Equals(SalesQuoteNo))
  496. // {
  497. // break;
  498. // }
  499. //}
  500. string countrys = string.Empty;
  501. string countryReq = dto.VisitCountry;
  502. if (!string.IsNullOrEmpty(countryReq))
  503. {
  504. if (countryReq.Contains(",")) countrys = countryReq.Replace(',','|');
  505. else if (countryReq.Contains(",")) countrys = countryReq.Replace(',', '|');
  506. else if (countryReq.Contains(" ")) countrys = countryReq.Replace(' ', '|');
  507. else if (countryReq.Contains("、")) countrys = countryReq.Replace('、', '|');
  508. else if (countryReq.Contains(".")) countrys = countryReq.Replace('.', '|');
  509. else countrys = countryReq;
  510. }
  511. Grp_DelegationInfo delegationInfo = new Grp_DelegationInfo()
  512. {
  513. SalesQuoteNo = dto.SalesQuoteNo,
  514. TeamLevSId = dto.TeamLevSId,
  515. ClientName = dto.ClientName,
  516. ClientUnit = dto.ClientUnit,
  517. TeamName = dto.TeamName,
  518. TeamDid = dto.TeamDid,
  519. VisitDate = Convert.ToDateTime(dto.VisitDate),
  520. VisitCountry = countrys,
  521. VisitPurpose = dto.VisitPurpose,
  522. VisitDays = dto.VisitDays,
  523. VisitPNumber = dto.VisitPNumber,
  524. SpecialNeeds = dto.SpecialNeeds,
  525. OtherNeeds = dto.OtherNeeds,
  526. Remark = dto.Remark,
  527. JietuanOperator = dto.JietuanOperator,
  528. TellPhone = dto.TellPhone,
  529. WeChatNo = dto.WeChatNo,
  530. CGRWSPBMMC = dto.CGRWSPBMMC,
  531. CGRWSPWH = dto.CGRWSPWH,
  532. ZZSCBMMC = dto.ZZSCBMMC,
  533. ZZSCSPWH = dto.ZZSCSPWH,
  534. TontractTime = Convert.ToDateTime(dto.TontractTime),
  535. PaymentMoney = dto.PaymentMoney,
  536. PayDay = dto.PayDay,
  537. TourCode = "",
  538. SalesDate = DateTime.Now,
  539. IsState = 0, //默认团组未完成 0
  540. JietuanTime = DateTime.Now,
  541. IsDel = 0,
  542. BudgetCost = 0.00M,
  543. HotelComplain = 0,
  544. OPComplain = 0,
  545. OAComplain = 0,
  546. AirComplain = 0,
  547. VisaComplain = 0,
  548. CreateUserId = dto.UserId,
  549. CreateTime = DateTime.Now,
  550. DeleteUserId = null,
  551. DeleteTime = new DateTime(1990, 1, 1).ToString("yyyy-MM-dd HH:mm:ss"),
  552. OpRoyaltyLv = dto.OpRoyaltyLv,
  553. OpRoyaltyRemark=dto.opRoyaltyRemark,
  554. Officialneeds = dto.Officialneeds,
  555. VisitStartDate = startTime,
  556. VisitEndDate = endTime,
  557. };
  558. var addId = _sqlSugar.Insertable(delegationInfo).ExecuteReturnIdentity();
  559. if (addId > 0)
  560. {
  561. result.Code = 0;
  562. result.Msg = "添加成功!";
  563. result.Data = addId;
  564. }
  565. else
  566. {
  567. result.Msg = "添加失败!";
  568. }
  569. }
  570. else if (dto.Status == 2) //修改
  571. {
  572. var updateStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo
  573. {
  574. SalesQuoteNo = dto.SalesQuoteNo,
  575. TeamLevSId = dto.TeamLevSId,
  576. ClientName = dto.ClientName,
  577. ClientUnit = dto.ClientUnit,
  578. TeamName = dto.TeamName,
  579. TeamDid = dto.TeamDid,
  580. VisitDate = Convert.ToDateTime(dto.VisitDate),
  581. VisitCountry = dto.VisitCountry,
  582. VisitPurpose = dto.VisitPurpose,
  583. VisitDays = dto.VisitDays,
  584. VisitPNumber = dto.VisitPNumber,
  585. SpecialNeeds = dto.SpecialNeeds,
  586. OtherNeeds = dto.OtherNeeds,
  587. Remark = dto.Remark,
  588. JietuanOperator = dto.JietuanOperator,
  589. TellPhone = dto.TellPhone,
  590. WeChatNo = dto.WeChatNo,
  591. CGRWSPBMMC = dto.CGRWSPBMMC,
  592. CGRWSPWH = dto.CGRWSPWH,
  593. ZZSCBMMC = dto.ZZSCBMMC,
  594. ZZSCSPWH = dto.ZZSCSPWH,
  595. TontractTime = Convert.ToDateTime(dto.TontractTime),
  596. PaymentMoney = dto.PaymentMoney,
  597. PayDay = dto.PayDay,
  598. OpRoyaltyLv = dto.OpRoyaltyLv,
  599. OpRoyaltyRemark = dto.opRoyaltyRemark,
  600. Officialneeds = dto.Officialneeds,
  601. VisitStartDate = startTime,
  602. VisitEndDate = endTime,
  603. });
  604. if (updateStatus)
  605. {
  606. result.Code = 0;
  607. result.Msg = "修改成功!";
  608. }
  609. else
  610. {
  611. result.Msg = "修改失败!";
  612. }
  613. }
  614. else if (dto.Status == 3) //删除
  615. {
  616. var deleteStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo
  617. {
  618. DeleteUserId = dto.UserId,
  619. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  620. IsDel = 1
  621. });
  622. if (deleteStatus)
  623. {
  624. result.Code = 0;
  625. result.Msg = "删除成功!";
  626. }
  627. else
  628. {
  629. result.Msg = "删除失败!";
  630. }
  631. }
  632. }
  633. return result;
  634. }
  635. /// <summary>
  636. /// 团组信息操作 - 删除
  637. /// </summary>
  638. /// <param name="dto"></param>
  639. /// <returns></returns>
  640. public async Task<Result> GroupDel(GroupDelDto dto)
  641. {
  642. Result result = new Result() { Code = -2, Msg = "未知错误" };
  643. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  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. return result;
  662. }
  663. /// <summary>
  664. /// 获取销售报价号
  665. /// </summary>
  666. /// <returns></returns>
  667. public async Task<Result> GetGroupSalesQuoteNo()
  668. {
  669. Result result = new Result() { Code = -2, Msg = "未知错误" };
  670. string teamCodeSql = string.Format("Select SalesQuoteNo From Grp_DelegationInfo");
  671. var teamCodeItem = await _sqlSugar.SqlQueryable<SalesQuoteNoView>(teamCodeSql).ToListAsync();
  672. string teamCode = "";
  673. while (true)
  674. {
  675. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  676. if (!teamCodeItem.Equals(teamCode))
  677. {
  678. break;
  679. }
  680. }
  681. result.Code = 0;
  682. result.Msg = "成功!";
  683. result.Data = teamCode;
  684. return result;
  685. }
  686. /// <summary>
  687. /// 团组删除
  688. /// </summary>
  689. /// <returns></returns>
  690. public async Task<Result> GroupDeleteById()
  691. {
  692. Result result = new Result() { Code = -2, Msg = "未知错误" };
  693. string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
  694. var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  695. string teamCode = "";
  696. while (true)
  697. {
  698. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  699. if (!teamCodeItem.Equals(teamCode))
  700. {
  701. break;
  702. }
  703. }
  704. result.Code = 0;
  705. result.Msg = "成功!";
  706. result.Data = teamCode;
  707. return result;
  708. }
  709. /// <summary>
  710. /// 团组确认出团
  711. /// </summary>
  712. /// <returns></returns>
  713. public async Task<Result> ConfirmationGroup(ConfirmationGroupDto dto)
  714. {
  715. Result result = new Result() { Code = -2, Msg = "未知错误" };
  716. string teamCode = "";
  717. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  718. {
  719. string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
  720. var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  721. while (true)
  722. {
  723. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  724. if (!teamCodeItem.Equals(teamCode))
  725. {
  726. break;
  727. }
  728. }
  729. var deleteStatus = await UpdateAsync(a => a.Id == dto.GroupId, a => new Grp_DelegationInfo
  730. {
  731. TourCode = teamCode,
  732. GroupsOperator = dto.GroupsOperator,
  733. GroupsTime = DateTime.Now
  734. });
  735. if (deleteStatus)
  736. {
  737. result.Code = 0;
  738. result.Msg = "确认出团设置成功!";
  739. }
  740. else
  741. {
  742. result.Msg = "确认出团设置失败!";
  743. }
  744. }
  745. result.Code = 0;
  746. result.Msg = "成功!";
  747. result.Data = teamCode;
  748. return result;
  749. }
  750. /// <summary>
  751. /// 获取接团名称List
  752. /// </summary>
  753. /// <param name="dto"></param>
  754. /// <returns></returns>
  755. public async Task<Result> GetGroupNameList(GroupNameDto dto)
  756. {
  757. Result result = new Result() { Code = -2, Msg = "未知错误" };
  758. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  759. {
  760. string sql = string.Format(@"Select Id,TeamName GroupName From Grp_DelegationInfo
  761. Where TeamName != '' And IsDel = 0
  762. Order By Id Desc");
  763. var _groupNameList = await _sqlSugar.SqlQueryable<GroupNameView>(sql).ToListAsync();
  764. if (_groupNameList.Count > 0)
  765. {
  766. result.Code = 0;
  767. result.Msg = "成功!";
  768. result.Data = _groupNameList;
  769. }
  770. else
  771. {
  772. result.Msg = "暂无团组信息";
  773. }
  774. }
  775. return result;
  776. }
  777. /// <summary>
  778. /// 获取接团名称List And 签证国别
  779. /// </summary>
  780. /// <param name="dto"></param>
  781. /// <returns></returns>
  782. public async Task<Result> GetGroupNameAndVisaNationality(GroupNameDto dto)
  783. {
  784. Result result = new Result() { Code = -2, Msg = "未知错误" };
  785. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  786. {
  787. string sql = string.Format(@"Select Id,TeamName GroupName From Grp_DelegationInfo
  788. Where TeamName != '' And IsDel = 0
  789. Order By Id Desc");
  790. var _groupNameList = await _sqlSugar.SqlQueryable<GroupNameView>(sql).ToListAsync();
  791. string visaSql = string.Format(@"Select Id,Name From Sys_SetData Where STid = 41 And IsDel = 0");
  792. var _setDataList = await _sqlSugar.SqlQueryable<SetDataInfoView>(visaSql).ToListAsync();
  793. var data = new {
  794. groupNameData = _groupNameList,
  795. visaNationalityData = _setDataList
  796. };
  797. result.Data = data;
  798. result.Code = 0;
  799. }
  800. return result;
  801. }
  802. #endregion
  803. #region 团组&签证
  804. /// <summary>
  805. /// 根据团组Id查询客户
  806. /// </summary>
  807. /// <param name="dto"></param>
  808. /// <returns></returns>
  809. public async Task<Result> GetCrmByGroupId(ClientByGroupIdDto dto)
  810. {
  811. Result result = new Result() { Code = -2 };
  812. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3)
  813. {
  814. string sql = string.Format(@"Select gdjc.GrpDCId grpId,cdc.Id,cdc.LastName+cdc.FirstName clientName,cdc.Tel,ccc.CertNo CerdNo
  815. From Grp_DelegationJoinCustomer gdjc
  816. Inner join Crm_DeleClient cdc On gdjc.CrmDCId = cdc.Id
  817. Left Join Crm_CustomerCert ccc On ccc.SdId = 773 And cdc.Id = ccc.DcId
  818. Where gdjc.GrpDCId = {0}", dto.GroupId);
  819. var clientList = await _sqlSugar.SqlQueryable<CrmByGroupIdView>(sql).ToListAsync();
  820. if (clientList.Count > 0)
  821. {
  822. result.Code = 0;
  823. result.Msg = "成功!";
  824. result.Data = clientList;
  825. }
  826. else
  827. {
  828. result.Msg = "暂无数据!";
  829. }
  830. }
  831. return result;
  832. }
  833. #endregion
  834. }
  835. }