DelegationInfoRepository.cs 29 KB

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