DelegationInfoRepository.cs 28 KB

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