DelegationInfoRepository.cs 46 KB

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