DelegationInfoRepository.cs 38 KB

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