DelegationInfoRepository.cs 28 KB

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