DelegationInfoRepository.cs 41 KB

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