DelegationInfoRepository.cs 41 KB

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