DelegationInfoRepository.cs 39 KB

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