DelegationInfoRepository.cs 29 KB

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