DelegationInfoRepository.cs 28 KB

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