DelegationInfoRepository.cs 41 KB

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