DelegationInfoRepository.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. using Newtonsoft.Json;
  2. using NPOI.OpenXmlFormats.Wordprocessing;
  3. using OASystem.Domain;
  4. using OASystem.Domain.Dtos;
  5. using OASystem.Domain.Dtos.Financial;
  6. using OASystem.Domain.Dtos.Groups;
  7. using OASystem.Domain.Dtos.UserDto;
  8. using OASystem.Domain.Entities.Groups;
  9. using OASystem.Domain.ViewModels.CRM;
  10. using OASystem.Domain.ViewModels.Financial;
  11. using OASystem.Domain.ViewModels.Groups;
  12. using OASystem.Infrastructure.Repositories.System;
  13. using Org.BouncyCastle.Asn1.Cms;
  14. using Org.BouncyCastle.Utilities.Collections;
  15. using Serilog;
  16. using SqlSugar;
  17. using System;
  18. using System.Collections.Generic;
  19. using System.Linq;
  20. using System.Text;
  21. using System.Threading.Tasks;
  22. namespace OASystem.Infrastructure.Repositories.Groups
  23. {
  24. /// <summary>
  25. /// 接团信息
  26. /// </summary>
  27. public class DelegationInfoRepository : BaseRepository<Grp_DelegationInfo, DelegationInfoView>
  28. {
  29. private readonly SetDataRepository _setDataRepository;
  30. private readonly UsersRepository _usersRepository;
  31. private readonly TaskAssignmentRepository _taskAssignmentRep;
  32. //private readonly TeamRateRepository _teamRateRep;
  33. //public readonly Logs _logs;
  34. public DelegationInfoRepository(SqlSugarClient sqlSugar, SetDataRepository setDataRepository, UsersRepository usersRepository,
  35. TaskAssignmentRepository taskAssignmentRep)
  36. : base(sqlSugar)
  37. {
  38. _setDataRepository = setDataRepository;
  39. _usersRepository = usersRepository;
  40. _taskAssignmentRep = taskAssignmentRep;
  41. //_teamRateRep = teamRateRep;
  42. }
  43. #region 团组信息 团组详情共享Api
  44. /// <summary>
  45. /// 团组信息 团组预览详情共享Api
  46. /// </summary>
  47. /// <param name="dto"></param>
  48. /// <returns></returns>
  49. public async Task<Result> PostShareGroupInfo(ShareGroupInfoDto dto)
  50. {
  51. Result result = new Result() { Code = -2, Msg = "未知错误" };
  52. string sql = string.Format(@"Select Id,TeamName,TourCode,ClientName,VisitCountry,VisitStartDate,VisitEndDate,VisitDays,VisitPNumber
  53. From Grp_DelegationInfo Where Id = {0} And IsDel = 0", dto.Id);
  54. if (dto.PortType == 1) //Web
  55. {
  56. var _DelegationInfo = await _sqlSugar.SqlQueryable<Web_ShareGroupInfoView>(sql).FirstAsync();
  57. if (_DelegationInfo != null)
  58. {
  59. if (!string.IsNullOrEmpty(_DelegationInfo.VisitCountry))
  60. {
  61. if (_DelegationInfo.VisitCountry.Contains("|"))
  62. {
  63. _DelegationInfo.VisitCountry = _DelegationInfo.VisitCountry.Replace("|", "、");
  64. }
  65. }
  66. else _DelegationInfo.VisitCountry = " - ";
  67. result.Data = _DelegationInfo;
  68. }
  69. else result.Msg = "暂无该团组信息";
  70. }
  71. else if (dto.PortType == 2 || dto.PortType == 3) //IOS Or Android
  72. {
  73. var _DelegationInfo = await _sqlSugar.SqlQueryable<IOSOrAndroid_ShareGroupInfoView>(sql).FirstAsync();
  74. if (_DelegationInfo != null)
  75. {
  76. if (!string.IsNullOrEmpty(_DelegationInfo.VisitCountry))
  77. {
  78. if (_DelegationInfo.VisitCountry.Contains("|"))
  79. {
  80. _DelegationInfo.VisitCountry = _DelegationInfo.VisitCountry.Replace("|", "、");
  81. }
  82. }
  83. else _DelegationInfo.VisitCountry = " - ";
  84. result.Data = _DelegationInfo;
  85. }
  86. else result.Msg = "暂无该团组信息";
  87. }
  88. else result.Msg = "请输入正确的端口号。1 Web 2 Android 3 IOS";
  89. result.Code = 0;
  90. result.Msg = "成功!";
  91. return result;
  92. }
  93. #endregion
  94. /// <summary>
  95. /// 获取接团信息Info
  96. /// </summary>
  97. /// <param name="dto"></param>
  98. /// <returns></returns>
  99. public async Task<Result> PostGroupInfo(GroupInfoDto dto)
  100. {
  101. Result result = new Result() { Code = -2, Msg = "未知错误" };
  102. if (dto.PortType == 1 || dto.PortType == 2) //Web Or Android
  103. {
  104. string sql = string.Format(@"Select Id,SalesQuoteNo,TourCode,JietuanOperator,TeamLevSId,TeamDid,TeamName,ClientName,
  105. ClientUnit,VisitCountry,VisitDate,VisitDays,VisitPNumber,TontractTime,
  106. PayDay,PaymentMoney,VisitPurpose,SpecialNeeds,OtherNeeds,CGRWSPBMMC,CGRWSPWH,
  107. ZZSCBMMC,ZZSCSPWH,Remark,TellPhone,Officialneeds
  108. From Grp_DelegationInfo Where Id = {0} And IsDel = 0", dto.Id);
  109. var _DelegationInfo = await _sqlSugar.SqlQueryable<DelegationInfoWebView>(sql).FirstAsync();
  110. if (_DelegationInfo != null)
  111. {
  112. result.Code = 0;
  113. result.Msg = "成功!";
  114. result.Data = _DelegationInfo;
  115. }
  116. else result.Msg = "暂无该团组信息";
  117. }
  118. return result;
  119. }
  120. #region 团组
  121. /// <summary>
  122. /// 获取接团信息 Page List
  123. /// </summary>
  124. /// <param name="dto"></param>
  125. /// <returns></returns>
  126. public async Task<Result> GetGroupPageList(GroupCommissionDto dto)
  127. {
  128. Result result = new Result() { Code = -2, Msg = "未知错误" };
  129. ListViewBase<DelegationPageListView> groupsInfoPageList = new ListViewBase<DelegationPageListView>()
  130. {
  131. ReceiveDt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  132. };
  133. if (dto.PortType == 1 || dto.PortType == 2) //web
  134. {
  135. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  136. int endIndex = startIndex + dto.PageSize - 1;
  137. int taskUserId = -1;
  138. string taskGroupIds = string.Empty;
  139. #region 处理用户团组操作权限
  140. if (dto.UserId != -1)
  141. {
  142. }
  143. #endregion
  144. string sql = string.Format(@"Select * From(Select row_number() over (order by gdi.Id Desc) as RowNumber,
  145. gdi.Id,SalesQuoteNo,TourCode,ssd.Id TeamTypeId, ssd.Name TeamType,ssd1.Id TeamLevId,
  146. ssd1.Name TeamLev,TeamName,ClientName,ClientUnit,VisitDate,VisitDays,VisitPNumber,
  147. su.CnName JietuanOperator,IsSure
  148. From Grp_DelegationInfo gdi
  149. Inner Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  150. Inner Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  151. Left Join Sys_Users su On gdi.JietuanOperator = su.Id
  152. Where gdi.IsDel = 0
  153. )temp Where RowNumber Between {0} and {1}", startIndex, endIndex);
  154. string sqlCount = string.Format(@"Select Count(1) as Count From Grp_DelegationInfo gdi
  155. Inner Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  156. Inner Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  157. Left Join Sys_Users su On gdi.JietuanOperator = su.Id
  158. Where gdi.IsDel = 0 ");
  159. List<DelegationPageListView> _DeleInfoList = await _sqlSugar.SqlQueryable<DelegationPageListView>(sql).ToListAsync();
  160. DelegationPageCountView _DeleCount = await _sqlSugar.SqlQueryable<DelegationPageCountView>(sqlCount).FirstAsync();
  161. int count = _DeleCount.Count;
  162. groupsInfoPageList = new ListViewBase<DelegationPageListView>
  163. {
  164. CurrPageIndex = dto.PageIndex,
  165. CurrPageSize = dto.PageSize,
  166. DataCount = count,
  167. DataList = _DeleInfoList
  168. };
  169. result.Code = 0;
  170. result.Msg = "成功!";
  171. result.Data = groupsInfoPageList;
  172. }
  173. return result;
  174. }
  175. /// <summary>
  176. /// 获取接团信息List
  177. /// </summary>
  178. /// <param name="dto"></param>
  179. /// <returns></returns>
  180. public async Task<Result> GetGroupList(GroupListDto dto)
  181. {
  182. Result result = new Result() { Code = -2, Msg = "未知错误" };
  183. if (dto.PortType == 1 || dto.PortType == 2) //web
  184. {
  185. 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
  186. From Grp_DelegationInfo gdi
  187. Inner Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  188. Inner Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  189. Left Join Sys_Users su On gdi.JietuanOperator = su.Id
  190. Where gdi.IsDel = 0
  191. Order By gdi.CreateTime Desc");
  192. var _DelegationList = await _sqlSugar.SqlQueryable<DelegationListView>(sql).ToListAsync();
  193. if (_DelegationList.Count > 0)
  194. {
  195. result.Code = 0;
  196. result.Msg = "成功!";
  197. result.Data = _DelegationList;
  198. }
  199. else
  200. {
  201. result.Msg = "暂无该团组信息";
  202. }
  203. }
  204. return result;
  205. }
  206. /// <summary>
  207. /// 获取接团信息Info
  208. /// </summary>
  209. /// <param name="dto"></param>
  210. /// <returns></returns>
  211. public async Task<Result> GetGroupInfo(GroupInfoDto dto)
  212. {
  213. Result result = new Result() { Code = -2, Msg = "未知错误" };
  214. if (dto.PortType == 1 || dto.PortType == 2) //Web Or Android
  215. {
  216. string sql = string.Format(@"Select Id,SalesQuoteNo,TourCode,JietuanOperator,TeamLevSId,TeamDid,TeamName,ClientName,
  217. ClientUnit,VisitCountry,VisitDate,VisitDays,VisitPNumber,TontractTime,
  218. PayDay,PaymentMoney,VisitPurpose,SpecialNeeds,OtherNeeds,CGRWSPBMMC,CGRWSPWH,
  219. ZZSCBMMC,ZZSCSPWH,Remark,TellPhone,OpRoyaltyLv,OpRoyaltyRemark,Officialneeds
  220. From Grp_DelegationInfo Where Id = {0} And IsDel = 0", dto.Id);
  221. var _DelegationInfo = await _sqlSugar.SqlQueryable<DelegationInfoWebView>(sql).FirstAsync();
  222. if (_DelegationInfo != null)
  223. {
  224. result.Code = 0;
  225. result.Msg = "成功!";
  226. result.Data = _DelegationInfo;
  227. }
  228. else result.Msg = "暂无该团组信息";
  229. }
  230. return result;
  231. }
  232. /// <summary>
  233. /// 获取接团信息 编辑
  234. /// 基础 数据源
  235. /// </summary>
  236. /// <param name="dto"></param>
  237. /// <returns></returns>
  238. public async Task<Result> GroupEditBasicSource(GroupListDto dto)
  239. {
  240. Result result = new Result() { Code = -2, Msg = "未知错误" };
  241. try
  242. {
  243. if (dto.PortType == 1 || dto.PortType == 2) //web
  244. {
  245. dynamic? teamTypeData1 = null;
  246. string teamTypeSql = string.Format(@"Select Id,Name From Sys_SetData Where STid = {0} And IsDel = {1}", 10, 0);
  247. var teamTypeData = await _sqlSugar.SqlQueryable<SetDataInfoView>(teamTypeSql).ToListAsync(); ; //团组分类 10
  248. if (teamTypeData.Count > 0)
  249. {
  250. teamTypeData1 = teamTypeData;
  251. }
  252. dynamic? teamLevData1 = null;
  253. string teamLevSql = string.Format(@"Select Id,Name From Sys_SetData Where STid = {0} And IsDel = {1}", 56, 0);
  254. var teamLevData = await _sqlSugar.SqlQueryable<SetDataInfoView>(teamLevSql).ToListAsync(); ; //团组等级 56
  255. if (teamLevData.Count > 0)
  256. {
  257. teamLevData1 = teamLevData;
  258. }
  259. dynamic? userData1 = null;
  260. string userSql = string.Format(@"Select Id,CnName From Sys_Users Where IsDel = {0}", 0);
  261. var userData = await _sqlSugar.SqlQueryable<UserNameView>(userSql).ToListAsync(); ;
  262. if (userData.Count > 0)
  263. {
  264. userData1 = userData;
  265. }
  266. result.Code = 0;
  267. result.Msg = "成功!";
  268. result.Data = new
  269. {
  270. teamTypeData = teamTypeData1,
  271. teamLevData = teamLevData1,
  272. userData = userData1
  273. };
  274. }
  275. }
  276. catch (Exception)
  277. {
  278. throw;
  279. }
  280. return result;
  281. }
  282. /// <summary>
  283. /// 团组信息操作
  284. /// </summary>
  285. /// <param name="dto"></param>
  286. /// <returns></returns>
  287. public async Task<Result> GroupOperation(GroupOperationDto dto)
  288. {
  289. Result result = new Result() { Code = -2, Msg = "未知错误" };
  290. if (dto.PortType == 1 || dto.PortType == 2) //web
  291. {
  292. if (dto.Status == 1) //添加
  293. {
  294. string selectSql = string.Format(@"Select * From Grp_DelegationInfo
  295. Where IsDel = 0
  296. And TeamName = '{0}'
  297. And ClientName = '{1}'
  298. And ClientUnit ='{2}'
  299. And VisitDate ='{3}'",dto.TeamName, dto.ClientName, dto.ClientUnit, dto.VisitDate);
  300. var selectGroupInfo = await _sqlSugar.SqlQueryable<Grp_DelegationInfo>(selectSql).FirstAsync();
  301. if (selectGroupInfo != null)
  302. {
  303. result.Msg = "数据已存在,请勿重复添加!";
  304. return result;
  305. }
  306. //string teamCodeSql = string.Format("Select SalesQuoteNo From Grp_DelegationInfo");
  307. //var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  308. //string SalesQuoteNo = "";
  309. //while (true)
  310. //{
  311. // SalesQuoteNo = Tools.CommonFun.GetRandomStr(6);
  312. // if (!teamCodeItem.Equals(SalesQuoteNo))
  313. // {
  314. // break;
  315. // }
  316. //}
  317. string countrys = string.Empty;
  318. string countryReq = dto.VisitCountry;
  319. if (!string.IsNullOrEmpty(countryReq))
  320. {
  321. if (countryReq.Contains(",")) countrys = countryReq.Replace(',','|');
  322. else if (countryReq.Contains(",")) countrys = countryReq.Replace(',', '|');
  323. else if (countryReq.Contains(" ")) countrys = countryReq.Replace(' ', '|');
  324. else if (countryReq.Contains("、")) countrys = countryReq.Replace('、', '|');
  325. else if (countryReq.Contains(".")) countrys = countryReq.Replace('.', '|');
  326. else countrys = countryReq;
  327. }
  328. Grp_DelegationInfo delegationInfo = new Grp_DelegationInfo()
  329. {
  330. SalesQuoteNo = dto.SalesQuoteNo,
  331. TeamLevSId = dto.TeamLevSId,
  332. ClientName = dto.ClientName,
  333. ClientUnit = dto.ClientUnit,
  334. TeamName = dto.TeamName,
  335. TeamDid = dto.TeamDid,
  336. VisitDate = Convert.ToDateTime(dto.VisitDate),
  337. VisitCountry = countrys,
  338. VisitPurpose = dto.VisitPurpose,
  339. VisitDays = dto.VisitDays,
  340. VisitPNumber = dto.VisitPNumber,
  341. SpecialNeeds = dto.SpecialNeeds,
  342. OtherNeeds = dto.OtherNeeds,
  343. Remark = dto.Remark,
  344. JietuanOperator = dto.UserId,
  345. TellPhone = dto.TellPhone,
  346. CGRWSPBMMC = dto.CGRWSPBMMC,
  347. CGRWSPWH = dto.CGRWSPWH,
  348. ZZSCBMMC = dto.ZZSCBMMC,
  349. ZZSCSPWH = dto.ZZSCSPWH,
  350. TontractTime = Convert.ToDateTime(dto.TontractTime),
  351. PaymentMoney = dto.PaymentMoney,
  352. PayDay = dto.PayDay,
  353. TourCode = "",
  354. SalesDate = DateTime.Now,
  355. IsState = 0, //默认团组未完成 0
  356. JietuanTime = DateTime.Now,
  357. IsDel = 0,
  358. BudgetCost = 0.00M,
  359. HotelComplain = 0,
  360. OPComplain = 0,
  361. OAComplain = 0,
  362. AirComplain = 0,
  363. VisaComplain = 0,
  364. CreateUserId = dto.UserId,
  365. CreateTime = DateTime.Now,
  366. DeleteUserId = null,
  367. DeleteTime = new DateTime(1990, 1, 1).ToString("yyyy-MM-dd HH:mm:ss"),
  368. OpRoyaltyLv = dto.OpRoyaltyLv,
  369. OpRoyaltyRemark=dto.opRoyaltyRemark,
  370. Officialneeds = dto.Officialneeds
  371. };
  372. var addId = await _sqlSugar.Insertable(delegationInfo).ExecuteReturnIdentityAsync();
  373. if (addId > 0)
  374. {
  375. result.Code = 0;
  376. result.Msg = "添加成功!";
  377. result.Data = addId;
  378. }
  379. else
  380. {
  381. result.Msg = "添加失败!";
  382. }
  383. }
  384. else if (dto.Status == 2) //修改
  385. {
  386. var updateStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo
  387. {
  388. SalesQuoteNo = dto.SalesQuoteNo,
  389. TeamLevSId = dto.TeamLevSId,
  390. ClientName = dto.ClientName,
  391. ClientUnit = dto.ClientUnit,
  392. TeamName = dto.TeamName,
  393. TeamDid = dto.TeamDid,
  394. VisitDate = Convert.ToDateTime(dto.VisitDate),
  395. VisitCountry = dto.VisitCountry,
  396. VisitPurpose = dto.VisitPurpose,
  397. VisitDays = dto.VisitDays,
  398. VisitPNumber = dto.VisitPNumber,
  399. SpecialNeeds = dto.SpecialNeeds,
  400. OtherNeeds = dto.OtherNeeds,
  401. Remark = dto.Remark,
  402. JietuanOperator = dto.UserId,
  403. TellPhone = dto.TellPhone,
  404. CGRWSPBMMC = dto.CGRWSPBMMC,
  405. CGRWSPWH = dto.CGRWSPWH,
  406. ZZSCBMMC = dto.ZZSCBMMC,
  407. ZZSCSPWH = dto.ZZSCSPWH,
  408. TontractTime = Convert.ToDateTime(dto.TontractTime),
  409. PaymentMoney = dto.PaymentMoney,
  410. PayDay = dto.PayDay,
  411. OpRoyaltyLv = dto.OpRoyaltyLv,
  412. OpRoyaltyRemark = dto.opRoyaltyRemark,
  413. Officialneeds = dto.Officialneeds
  414. });
  415. if (updateStatus)
  416. {
  417. result.Code = 0;
  418. result.Msg = "修改成功!";
  419. }
  420. else
  421. {
  422. result.Msg = "修改失败!";
  423. }
  424. }
  425. else if (dto.Status == 3) //删除
  426. {
  427. var deleteStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo
  428. {
  429. DeleteUserId = dto.UserId,
  430. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  431. IsDel = 1
  432. });
  433. if (deleteStatus)
  434. {
  435. result.Code = 0;
  436. result.Msg = "删除成功!";
  437. }
  438. else
  439. {
  440. result.Msg = "删除失败!";
  441. }
  442. }
  443. }
  444. return result;
  445. }
  446. /// <summary>
  447. /// 团组信息操作 - 删除
  448. /// </summary>
  449. /// <param name="dto"></param>
  450. /// <returns></returns>
  451. public async Task<Result> GroupDel(GroupDelDto dto)
  452. {
  453. Result result = new Result() { Code = -2, Msg = "未知错误" };
  454. if (dto.PortType == 1 || dto.PortType == 2) //web
  455. {
  456. var deleteStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo
  457. {
  458. DeleteUserId = dto.UserId,
  459. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  460. IsDel = 1
  461. });
  462. if (deleteStatus)
  463. {
  464. result.Code = 0;
  465. result.Msg = "删除成功!";
  466. }
  467. else
  468. {
  469. result.Msg = "删除失败!";
  470. }
  471. }
  472. return result;
  473. }
  474. /// <summary>
  475. /// 获取销售报价号
  476. /// </summary>
  477. /// <returns></returns>
  478. public async Task<Result> GetGroupSalesQuoteNo()
  479. {
  480. Result result = new Result() { Code = -2, Msg = "未知错误" };
  481. string teamCodeSql = string.Format("Select SalesQuoteNo From Grp_DelegationInfo");
  482. var teamCodeItem = await _sqlSugar.SqlQueryable<SalesQuoteNoView>(teamCodeSql).ToListAsync();
  483. string teamCode = "";
  484. while (true)
  485. {
  486. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  487. if (!teamCodeItem.Equals(teamCode))
  488. {
  489. break;
  490. }
  491. }
  492. result.Code = 0;
  493. result.Msg = "成功!";
  494. result.Data = teamCode;
  495. return result;
  496. }
  497. /// <summary>
  498. /// 团组删除
  499. /// </summary>
  500. /// <returns></returns>
  501. public async Task<Result> GroupDeleteById()
  502. {
  503. Result result = new Result() { Code = -2, Msg = "未知错误" };
  504. string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
  505. var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  506. string teamCode = "";
  507. while (true)
  508. {
  509. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  510. if (!teamCodeItem.Equals(teamCode))
  511. {
  512. break;
  513. }
  514. }
  515. result.Code = 0;
  516. result.Msg = "成功!";
  517. result.Data = teamCode;
  518. return result;
  519. }
  520. /// <summary>
  521. /// 团组确认出团
  522. /// </summary>
  523. /// <returns></returns>
  524. public async Task<Result> ConfirmationGroup(ConfirmationGroupDto dto)
  525. {
  526. Result result = new Result() { Code = -2, Msg = "未知错误" };
  527. string teamCode = "";
  528. if (dto.PortType == 1 || dto.PortType == 2) //web
  529. {
  530. string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
  531. var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  532. while (true)
  533. {
  534. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  535. if (!teamCodeItem.Equals(teamCode))
  536. {
  537. break;
  538. }
  539. }
  540. var deleteStatus = await UpdateAsync(a => a.Id == dto.GroupId, a => new Grp_DelegationInfo
  541. {
  542. TourCode = teamCode,
  543. GroupsOperator = dto.GroupsOperator,
  544. GroupsTime = DateTime.Now
  545. });
  546. if (deleteStatus)
  547. {
  548. result.Code = 0;
  549. result.Msg = "确认出团设置成功!";
  550. }
  551. else
  552. {
  553. result.Msg = "确认出团设置失败!";
  554. }
  555. }
  556. result.Code = 0;
  557. result.Msg = "成功!";
  558. result.Data = teamCode;
  559. return result;
  560. }
  561. /// <summary>
  562. /// 获取接团名称List
  563. /// </summary>
  564. /// <param name="dto"></param>
  565. /// <returns></returns>
  566. public async Task<Result> GetGroupNameList(GroupNameDto dto)
  567. {
  568. Result result = new Result() { Code = -2, Msg = "未知错误" };
  569. if (dto.PortType == 1 || dto.PortType == 2) //web
  570. {
  571. string sql = string.Format(@"Select Id,TeamName GroupName From Grp_DelegationInfo
  572. Where TeamName != '' And IsDel = 0
  573. Order By Id Desc");
  574. var _groupNameList = await _sqlSugar.SqlQueryable<GroupNameView>(sql).ToListAsync();
  575. if (_groupNameList.Count > 0)
  576. {
  577. result.Code = 0;
  578. result.Msg = "成功!";
  579. result.Data = _groupNameList;
  580. }
  581. else
  582. {
  583. result.Msg = "暂无团组信息";
  584. }
  585. }
  586. return result;
  587. }
  588. /// <summary>
  589. /// 获取接团名称List And 签证国别
  590. /// </summary>
  591. /// <param name="dto"></param>
  592. /// <returns></returns>
  593. public async Task<Result> GetGroupNameAndVisaNationality(GroupNameDto dto)
  594. {
  595. Result result = new Result() { Code = -2, Msg = "未知错误" };
  596. if (dto.PortType == 1 || dto.PortType == 2) //web
  597. {
  598. string sql = string.Format(@"Select Id,TeamName GroupName From Grp_DelegationInfo
  599. Where TeamName != '' And IsDel = 0
  600. Order By Id Desc");
  601. var _groupNameList = await _sqlSugar.SqlQueryable<GroupNameView>(sql).ToListAsync();
  602. string visaSql = string.Format(@"Select Id,Name From Sys_SetData Where STid = 41 And IsDel = 0");
  603. var _setDataList = await _sqlSugar.SqlQueryable<SetDataInfoView>(visaSql).ToListAsync();
  604. var data = new {
  605. groupNameData = _groupNameList,
  606. visaNationalityData = _setDataList
  607. };
  608. result.Data = data;
  609. result.Code = 0;
  610. }
  611. return result;
  612. }
  613. #endregion
  614. #region 团组&签证
  615. /// <summary>
  616. /// 根据团组Id查询客户
  617. /// </summary>
  618. /// <param name="dto"></param>
  619. /// <returns></returns>
  620. public async Task<Result> GetCrmByGroupId(ClientByGroupIdDto dto)
  621. {
  622. Result result = new Result() { Code = -2 };
  623. if (dto.PortType == 1 || dto.PortType == 2)
  624. {
  625. string sql = string.Format(@"Select gdjc.GrpDCId grpId,cdc.Id,cdc.LastName+cdc.FirstName clientName,cdc.Tel,ccc.CertNo CerdNo
  626. From Grp_DelegationJoinCustomer gdjc
  627. Inner join Crm_DeleClient cdc On gdjc.CrmDCId = cdc.Id
  628. Left Join Crm_CustomerCert ccc On ccc.SdId = 773 And cdc.Id = ccc.DcId
  629. Where gdjc.GrpDCId = {0}", dto.GroupId);
  630. var clientList = await _sqlSugar.SqlQueryable<CrmByGroupIdView>(sql).ToListAsync();
  631. if (clientList.Count > 0)
  632. {
  633. result.Code = 0;
  634. result.Msg = "成功!";
  635. result.Data = clientList;
  636. }
  637. else
  638. {
  639. result.Msg = "暂无数据!";
  640. }
  641. }
  642. return result;
  643. }
  644. #endregion
  645. }
  646. }