665 lines
30 KiB

3 years ago
  1. using EasyBL.WebApi.Message;
  2. using Entity.Sugar;
  3. using Entity.ViewModels;
  4. using SqlSugar;
  5. using SqlSugar.Base;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Web;
  9. namespace EasyBL.WEBSITE.Com
  10. {
  11. public class ComService : ServiceBase
  12. {
  13. #region 獲取組織信息
  14. /// <summary>
  15. /// 獲取組織信息
  16. /// </summary>
  17. /// <param name="i_crm"></param>
  18. /// <returns></returns>
  19. public ResponseMessage GetOrgInfo(RequestMessage i_crm)
  20. {
  21. ResponseMessage rm = null;
  22. string sMsg = null;
  23. var db = SugarBase.DB;
  24. try
  25. {
  26. do
  27. {
  28. var sdb = new SimpleClient<OTB_SYS_Organization>(db);
  29. var oOrg = sdb.GetById(i_crm.ORIGID);
  30. rm = new SuccessResponseMessage(null, i_crm);
  31. rm.DATA.Add(BLWording.REL, oOrg);
  32. } while (false);
  33. }
  34. catch (Exception ex)
  35. {
  36. sMsg = Util.GetLastExceptionMsg(ex);
  37. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.WEBSITE.Com.ComService", "", "GetOrgInfo(獲取組織信息)", "", "", "");
  38. }
  39. finally
  40. {
  41. if (null != sMsg)
  42. {
  43. rm = new ErrorResponseMessage(sMsg, i_crm);
  44. }
  45. }
  46. return rm;
  47. }
  48. #endregion 獲取組織信息
  49. #region 官網設定(分頁查詢)
  50. /// <summary>
  51. /// 官網設定(分頁查詢)
  52. /// </summary>
  53. /// <param name="i_crm"></param>
  54. /// <returns></returns>
  55. public ResponseMessage GetWebSiteSettingPage(RequestMessage i_crm)
  56. {
  57. ResponseMessage rm = null;
  58. string sMsg = null;
  59. var db = SugarBase.GetIntance();
  60. try
  61. {
  62. do
  63. {
  64. var pml = new PageModel
  65. {
  66. PageIndex = _fetchInt(i_crm, @"pageIndex"),
  67. PageSize = _fetchInt(i_crm, @"pageSize")
  68. };
  69. var iPageCount = 0;
  70. var sSetType = _fetchString(i_crm, @"SetType");
  71. var sLangId = _fetchString(i_crm, @"LangId");
  72. var sParentId = _fetchString(i_crm, @"ParentId");
  73. var bOnlyParent = _fetchBool(i_crm, @"OnlyParent");
  74. pml.DataList = db.Queryable<OTB_WSM_WebSiteSetting, OTB_SYS_Files, OTB_SYS_Files, OTB_SYS_Files>((t1, t2, t3, t4) =>
  75. new object[] {
  76. JoinType.Left, t1.OrgID == t2.OrgID && t1.IconId == t2.ParentID,
  77. JoinType.Left, t1.OrgID == t3.OrgID && t1.SubIconId == t3.ParentID,
  78. JoinType.Left, t1.OrgID == t4.OrgID && t1.CoverId == t4.ParentID
  79. })
  80. .Where((t1, t2, t3, t4) => t1.OrgID == i_crm.ORIGID && t1.SetType == sSetType && t1.LangId == i_crm.LANG && t1.Active)
  81. .WhereIF(!string.IsNullOrEmpty(sParentId), (t1, t2, t3, t4) => t1.ParentId == sParentId)
  82. .WhereIF(bOnlyParent, (t1, t2, t3, t4) => !SqlFunc.HasValue(t1.ParentId))
  83. .Select((t1, t2, t3, t4) => new View_WSM_WebSiteSetting
  84. {
  85. Guid = SqlFunc.GetSelfAndAutoFill(t1.Guid),
  86. IconFileName = t2.FileName,
  87. IconFilePath = t2.FilePath,
  88. SubIconFileName = t3.FileName,
  89. SubIconFilePath = t3.FilePath,
  90. CoverFileName = t4.FileName,
  91. CoverPath = t4.FilePath
  92. })
  93. .OrderBy("t1.ParentId,t1.OrderByValue", "asc")
  94. .ToPageList(pml.PageIndex, pml.PageSize, ref iPageCount);
  95. pml.Total = iPageCount;
  96. rm = new SuccessResponseMessage(null, i_crm);
  97. rm.DATA.Add(BLWording.REL, pml);
  98. } while (false);
  99. }
  100. catch (Exception ex)
  101. {
  102. sMsg = Util.GetLastExceptionMsg(ex);
  103. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.WEBSITE.Com.ComService", "", "GetWebSiteSettingPage(官網設定(分頁查詢))", "", "", "");
  104. }
  105. finally
  106. {
  107. if (null != sMsg)
  108. {
  109. rm = new ErrorResponseMessage(sMsg, i_crm);
  110. }
  111. }
  112. return rm;
  113. }
  114. #endregion 官網設定(分頁查詢)
  115. #region 官網設定(多筆)
  116. /// <summary>
  117. /// 官網設定(多筆)
  118. /// </summary>
  119. /// <param name="i_crm"></param>
  120. /// <returns></returns>
  121. public ResponseMessage GetWebSiteSetting(RequestMessage i_crm)
  122. {
  123. ResponseMessage rm = null;
  124. string sMsg = null;
  125. var db = SugarBase.GetIntance();
  126. try
  127. {
  128. do
  129. {
  130. var sSetType = _fetchString(i_crm, @"SetType");
  131. var sLangId = _fetchString(i_crm, @"LangId");
  132. var sParentId = _fetchString(i_crm, @"ParentId");
  133. var bHasChild = _fetchBool(i_crm, @"HasChild");
  134. var bSingle = _fetchBool(i_crm, @"Single");
  135. var saWebSiteSetting = db.Queryable<OTB_WSM_WebSiteSetting, OTB_SYS_Files, OTB_SYS_Files, OTB_SYS_Files>((t1, t2, t3, t4) =>
  136. new object[] {
  137. JoinType.Left, t1.OrgID == t2.OrgID && t1.IconId == t2.ParentID,
  138. JoinType.Left, t1.OrgID == t3.OrgID && t1.SubIconId == t3.ParentID,
  139. JoinType.Left, t1.OrgID == t4.OrgID && t1.CoverId == t4.ParentID
  140. })
  141. .Where((t1, t2, t3, t4) => t1.OrgID == i_crm.ORIGID && t1.SetType == sSetType && t1.LangId == sLangId && t1.Active)
  142. .WhereIF(!bSingle && !string.IsNullOrEmpty(sParentId), (t1, t2, t3, t4) => t1.ParentId == sParentId)
  143. .WhereIF(!bSingle && string.IsNullOrEmpty(sParentId), (t1, t2, t3, t4) => !SqlFunc.HasValue(t1.ParentId))
  144. .WhereIF(bSingle, (t1, t2, t3, t4) => t1.Guid == sParentId)
  145. .Select((t1, t2, t3, t4) => new View_WSM_WebSiteSetting
  146. {
  147. Guid = SqlFunc.GetSelfAndAutoFill(t1.Guid),
  148. IconFileName = t2.FileName,
  149. IconFilePath = t2.FilePath,
  150. SubIconFileName = t3.FileName,
  151. SubIconFilePath = t3.FilePath,
  152. CoverFileName = t4.FileName,
  153. CoverPath = t4.FilePath
  154. })
  155. .OrderBy("t1.ParentId,t1.OrderByValue", "asc")
  156. .ToList();
  157. if (bHasChild)
  158. {
  159. var saWebSiteSetting_Child = db.Queryable<OTB_WSM_WebSiteSetting, OTB_SYS_Files, OTB_SYS_Files, OTB_SYS_Files>((t1, t2, t3, t4) =>
  160. new object[] {
  161. JoinType.Left, t1.OrgID == t2.OrgID && t1.IconId == t2.ParentID,
  162. JoinType.Left, t1.OrgID == t3.OrgID && t1.SubIconId == t3.ParentID,
  163. JoinType.Left, t1.OrgID == t4.OrgID && t1.CoverId == t4.ParentID
  164. })
  165. .Where((t1, t2, t3, t4) => t1.OrgID == i_crm.ORIGID && t1.SetType == sSetType && t1.LangId == sLangId && t1.Active && SqlFunc.HasValue(t1.ParentId))
  166. .Select((t1, t2, t3, t4) => new View_WSM_WebSiteSetting
  167. {
  168. Guid = SqlFunc.GetSelfAndAutoFill(t1.Guid),
  169. IconFileName = t2.FileName,
  170. IconFilePath = t2.FilePath,
  171. SubIconFileName = t3.FileName,
  172. SubIconFilePath = t3.FilePath,
  173. CoverFileName = t4.FileName,
  174. CoverPath = t4.FilePath
  175. })
  176. .OrderBy(t1 => t1.OrderByValue)
  177. .ToList();
  178. foreach (var setting in saWebSiteSetting)
  179. {
  180. setting.Infos = saWebSiteSetting_Child.FindAll(x => x.ParentId == setting.Guid);
  181. }
  182. }
  183. rm = new SuccessResponseMessage(null, i_crm);
  184. if (bSingle)
  185. {
  186. rm.DATA.Add(BLWording.REL, saWebSiteSetting[0]);
  187. }
  188. else
  189. {
  190. rm.DATA.Add(BLWording.REL, saWebSiteSetting);
  191. }
  192. } while (false);
  193. }
  194. catch (Exception ex)
  195. {
  196. sMsg = Util.GetLastExceptionMsg(ex);
  197. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.WEBSITE.Com.ComService", "", "GetWebSiteSetting(官網設定(多筆))", "", "", "");
  198. }
  199. finally
  200. {
  201. if (null != sMsg)
  202. {
  203. rm = new ErrorResponseMessage(sMsg, i_crm);
  204. }
  205. }
  206. return rm;
  207. }
  208. #endregion 官網設定(多筆)
  209. #region 獲取最新消息分頁資料
  210. /// <summary>
  211. /// 獲取最新消息分頁資料
  212. /// </summary>
  213. /// <param name="i_crm"></param>
  214. /// <returns></returns>
  215. public ResponseMessage GetNewsPage(RequestMessage i_crm)
  216. {
  217. ResponseMessage rm = null;
  218. string sMsg = null;
  219. var db = SugarBase.DB;
  220. try
  221. {
  222. do
  223. {
  224. var pml = new PageModel
  225. {
  226. PageIndex = _fetchInt(i_crm, "pageIndex"),
  227. PageSize = _fetchInt(i_crm, "pageSize")
  228. };
  229. var iPageCount = 0;
  230. var sNewsType = _fetchString(i_crm, "NewsType");
  231. pml.DataList = db.Queryable<OTB_WSM_News, OTB_SYS_Files>((t1, t2) =>
  232. new object[] {
  233. JoinType.Left,t1.OrgID==t2.OrgID && t1.News_Pic==t2.ParentID
  234. })
  235. .OrderBy((t1) => t1.OrderByValue)
  236. .Where((t1) => t1.OrgID == i_crm.ORIGID && t1.News_Type == sNewsType && t1.News_Show == "Y" && t1.News_LanguageType == i_crm.LANG)
  237. .Select((t1, t2) => new { t1.SN, t1.News_Title, t1.CreateDate, t1.NewsContent, News_PicPath = t2.FilePath })
  238. .ToPageList(pml.PageIndex, pml.PageSize, ref iPageCount);
  239. pml.Total = iPageCount;
  240. rm = new SuccessResponseMessage(null, i_crm);
  241. rm.DATA.Add(BLWording.REL, pml);
  242. } while (false);
  243. }
  244. catch (Exception ex)
  245. {
  246. sMsg = Util.GetLastExceptionMsg(ex);
  247. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.WEBSITE.Com.ComService", "", "GetNewsPage(獲取最新消息分頁資料)", "", "", "");
  248. }
  249. finally
  250. {
  251. if (null != sMsg)
  252. {
  253. rm = new ErrorResponseMessage(sMsg, i_crm);
  254. }
  255. }
  256. return rm;
  257. }
  258. #endregion 獲取最新消息分頁資料
  259. #region 獲取展覽資訊分頁資料
  260. /// <summary>
  261. /// 獲取展覽資訊分頁資料
  262. /// </summary>
  263. /// <param name="i_crm"></param>
  264. /// <returns></returns>
  265. public ResponseMessage GetExhibitionPage(RequestMessage i_crm)
  266. {
  267. ResponseMessage rm = null;
  268. string sMsg = null;
  269. var db = SugarBase.DB;
  270. try
  271. {
  272. do
  273. {
  274. var pml = new PageModel
  275. {
  276. PageIndex = _fetchInt(i_crm, "pageIndex"),
  277. PageSize = _fetchInt(i_crm, "pageSize")
  278. };
  279. var iPageCount = 0;
  280. var sIsShowWebSim = _fetchString(i_crm, "IsShowWebSim");
  281. var bTop = _fetchBool(i_crm, "Top");
  282. var sKeyWords = _fetchString(i_crm, "KeyWords");
  283. var sArea = _fetchString(i_crm, "Area");
  284. var sDateStart = _fetchString(i_crm, "DateStart");
  285. var sDateEnd = _fetchString(i_crm, "DateEnd");
  286. var sNow = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  287. var sCategory = _fetchString(i_crm, "Category");
  288. var sCode = _fetchString(i_crm, "Code");
  289. pml.DataList = db.Queryable<OTB_OPM_Exhibition, OTB_SYS_Files, OTB_SYS_Arguments, OTB_SYS_Arguments>((t1, t2, t3, t4) => new object[] {
  290. JoinType.Left,t1.OrgID == t2.OrgID && t1.LogoFileId == t2.ParentID,
  291. JoinType.Left,t1.OrgID == t3.OrgID && t1.ExhibitionAddress == t3.ArgumentID && t3.ArgumentClassID == "Area" && t3.LevelOfArgument == 2,
  292. JoinType.Left,t1.OrgID == t4.OrgID && t1.State == t4.ArgumentID && t4.ArgumentClassID == "Area" && t4.LevelOfArgument == 1})
  293. .OrderBy((t1, t2) => t1.ExhibitionDateStart, OrderByType.Asc)
  294. .Where((t1, t2) => t1.OrgID == i_crm.ORIGID && t1.IsShowWebSite == "Y" && t1.Effective == "Y")
  295. //.WhereIF(!string.IsNullOrEmpty(sIsShowWebSim), (t1) => t1.OrgID == i_crm.ORIGID && t1.IsShowWebSim == "Y")
  296. .WhereIF(bTop, (t1) => t1.ExhibitionDateEnd >= DateTime.Now.Date)
  297. .WhereIF(!string.IsNullOrEmpty(sKeyWords), (t1) => (t1.Exhibitioname_TW.Contains(sKeyWords) || t1.Exhibitioname_EN.Contains(sKeyWords)))
  298. .WhereIF(!string.IsNullOrEmpty(sArea), (t1) => sArea.Contains(t1.State))
  299. .WhereIF(!string.IsNullOrEmpty(sDateStart) && string.IsNullOrEmpty(sDateEnd), (t1) => t1.ExhibitionDateEnd >= SqlFunc.ToDate(sDateStart))
  300. .WhereIF(!string.IsNullOrEmpty(sDateEnd) && string.IsNullOrEmpty(sDateStart), (t1) => t1.ExhibitionDateStart <= SqlFunc.ToDate(sDateEnd))
  301. .WhereIF(!string.IsNullOrEmpty(sDateStart) && !string.IsNullOrEmpty(sDateEnd), (t1) => t1.ExhibitionDateStart <= SqlFunc.ToDate(sDateEnd) && t1.ExhibitionDateEnd >= SqlFunc.ToDate(sDateStart))
  302. .WhereIF(!string.IsNullOrEmpty(sCategory), (t1) => sCategory.Contains(t1.Industry))
  303. .WhereIF(!string.IsNullOrEmpty(sCode), (t1) => t1.ExhibitionCode == sCode)
  304. .Select((t1, t2, t3, t4) => new
  305. {
  306. t1.SN,
  307. t1.State,
  308. t1.ExhibitionAddress,
  309. t1.Exhibitioname_TW,
  310. t1.Exhibitioname_EN,
  311. t1.ExhibitionDateStart,
  312. t1.ExhibitionDateEnd,
  313. ExhibitionAddressName = t3.ArgumentValue,
  314. StateName = t4.ArgumentValue,
  315. ExhibitionAddressName_EN = t3.ArgumentValue_EN,
  316. StateName_EN = t4.ArgumentValue_EN,
  317. LogoFilePath = t2.FilePath,
  318. t1.SeaReceiveingDate,
  319. t1.SeaClosingDate,
  320. t1.AirReceiveingDate,
  321. t1.AirClosingDate,
  322. t1.Undertaker,
  323. t1.Telephone,
  324. t1.Email,
  325. t1.WebsiteAdress
  326. }).ToPageList(pml.PageIndex, pml.PageSize, ref iPageCount);
  327. pml.Total = iPageCount;
  328. rm = new SuccessResponseMessage(null, i_crm);
  329. rm.DATA.Add(BLWording.REL, pml);
  330. } while (false);
  331. }
  332. catch (Exception ex)
  333. {
  334. sMsg = Util.GetLastExceptionMsg(ex);
  335. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.WEBSITE.Com.ComService", "", "GetExhibitionPage(獲取展覽資訊分頁資料)", "", "", "");
  336. }
  337. finally
  338. {
  339. if (null != sMsg)
  340. {
  341. rm = new ErrorResponseMessage(sMsg, i_crm);
  342. }
  343. }
  344. return rm;
  345. }
  346. #endregion 獲取展覽資訊分頁資料
  347. #region 獲取最新消息分明細
  348. /// <summary>
  349. /// 獲取最新消息分明細
  350. /// </summary>
  351. /// <param name="i_crm"></param>
  352. /// <returns></returns>
  353. public ResponseMessage GetNewsInfo(RequestMessage i_crm)
  354. {
  355. ResponseMessage rm = null;
  356. string sMsg = null;
  357. var db = SugarBase.GetIntance();
  358. try
  359. {
  360. do
  361. {
  362. var iId = _fetchInt(i_crm, "Id");
  363. var bIncludeFiles = _fetchBool(i_crm, "IncludeFiles");
  364. var saNews = db.Queryable<OTB_WSM_News>().Where(x => x.OrgID == i_crm.ORIGID && x.SN == iId).ToList();
  365. rm = new SuccessResponseMessage(null, i_crm);
  366. rm.DATA.Add(BLWording.REL, saNews);
  367. if (bIncludeFiles && saNews.Count > 0)
  368. {
  369. var saFiles = db.Queryable<OTB_SYS_Files>().Where(x => x.OrgID == i_crm.ORIGID && x.ParentID == saNews[0].PicShowId).ToList();
  370. rm.DATA.Add("files", saFiles);
  371. }
  372. } while (false);
  373. }
  374. catch (Exception ex)
  375. {
  376. sMsg = Util.GetLastExceptionMsg(ex);
  377. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.WEBSITE.Com.ComService", "", "GetNewsInfo(獲取最新消息分明細)", "", "", "");
  378. }
  379. finally
  380. {
  381. if (null != sMsg)
  382. {
  383. rm = new ErrorResponseMessage(sMsg, i_crm);
  384. }
  385. }
  386. return rm;
  387. }
  388. #endregion 獲取最新消息分明細
  389. #region 客戶寄送郵件
  390. /// <summary>
  391. /// 客戶寄送郵件
  392. /// </summary>
  393. /// <param name="i_crm"></param>
  394. /// <returns></returns>
  395. public ResponseMessage SendMail(RequestMessage i_crm)
  396. {
  397. ResponseMessage rm = null;
  398. string sMsg = null;
  399. var bSend = false;
  400. var db = SugarBase.GetIntance();
  401. try
  402. {
  403. do
  404. {
  405. var sFlag = _fetchString(i_crm, "flag");
  406. var sCaptcha = "";
  407. if (HttpContext.Current.Session[BLWording.CAPTCHA + sFlag] != null)
  408. {
  409. sCaptcha = HttpContext.Current.Session[BLWording.CAPTCHA + sFlag].ToString();
  410. }
  411. var sValidcode = _fetchString(i_crm, "validcode");
  412. if (sCaptcha != sValidcode)
  413. {
  414. sMsg = "驗證碼錯誤";
  415. break;
  416. }
  417. var oWebSiteMailLog = new OTB_WSM_WebSiteMailLog
  418. {
  419. OrgID = i_crm.ORIGID,
  420. Type = _fetchString(i_crm, "type"),
  421. Ucomp = _fetchString(i_crm, "ucomp"),
  422. Uname = _fetchString(i_crm, "uname"),
  423. Utel = _fetchString(i_crm, "utel"),
  424. Uemail = _fetchString(i_crm, "uemail"),
  425. Title = _fetchString(i_crm, "utitle"),
  426. Content = _fetchString(i_crm, "umailcontent"),
  427. CreateDate = DateTime.Now,
  428. ModifyDate = DateTime.Now
  429. };
  430. var sCusCommentsEmail = Common.GetSystemSetting(db, i_crm.ORIGID, "CusCommentsEmail");
  431. //獲取Email郵件格式
  432. var oEmailTempl = db.Queryable<OTB_SYS_Email>().Single(it => it.OrgID == i_crm.ORIGID && it.EmailID == "CusComments");
  433. if (oEmailTempl != null)
  434. {
  435. //寄信開始
  436. var sEmailBody = oEmailTempl.BodyHtml.Replace("{{:ucomp}}", oWebSiteMailLog.Ucomp)
  437. .Replace("{{:uname}}", oWebSiteMailLog.Uname)
  438. .Replace("{{:uemail}}", oWebSiteMailLog.Uemail)
  439. .Replace("{{:utel}}", oWebSiteMailLog.Utel)
  440. .Replace("{{:utitle}}", oWebSiteMailLog.Title)
  441. .Replace("{{:umailcontent}}", oWebSiteMailLog.Content);
  442. var oEmail = new Emails();
  443. var saEmailTo = new List<EmailTo>(); //收件人
  444. var oEmailTo = new EmailTo
  445. {
  446. ToUserID = sCusCommentsEmail,
  447. ToUserName = sCusCommentsEmail,
  448. ToEmail = sCusCommentsEmail,
  449. Type = "to"
  450. };
  451. saEmailTo.Add(oEmailTo);
  452. oEmail.FromUserName = "系統郵件";//取fonfig
  453. oEmail.Title = oWebSiteMailLog.Type == null ? oEmailTempl.EmailSubject : (oWebSiteMailLog.Type == "C" ? "一般詢問" : "線上詢價");//取fonfig
  454. oEmail.EmailBody = sEmailBody;
  455. oEmail.IsCCSelf = false;
  456. oEmail.Attachments = null;
  457. oEmail.EmailTo = saEmailTo;
  458. bSend = new MailService(i_crm.ORIGID, true).MailFactory(oEmail, out sMsg);
  459. if (bSend || oWebSiteMailLog.Content.IndexOf("***TEST***") > -1)
  460. {
  461. db.Insertable(oWebSiteMailLog).ExecuteCommand();
  462. }
  463. }
  464. rm = new SuccessResponseMessage(null, i_crm);
  465. rm.DATA.Add(BLWording.REL, bSend);
  466. } while (false);
  467. }
  468. catch (Exception ex)
  469. {
  470. sMsg = Util.GetLastExceptionMsg(ex);
  471. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.WebSite.TE.ComService", "客戶寄送郵件", nameof(SendMail), "", "", "");
  472. }
  473. finally
  474. {
  475. if (null != sMsg)
  476. {
  477. rm = new ErrorResponseMessage(sMsg, i_crm);
  478. }
  479. }
  480. return rm;
  481. }
  482. #endregion 客戶寄送郵件
  483. #region 依據展覽獲取展覽報價規則
  484. /// <summary>
  485. /// 依據展覽獲取展覽報價規則
  486. /// </summary>
  487. /// <param name="i_crm"></param>
  488. /// <returns></returns>
  489. public ResponseMessage GetExhibitionRules(RequestMessage i_crm)
  490. {
  491. ResponseMessage rm = null;
  492. string sMsg = null;
  493. var db = SugarBase.GetIntance();
  494. try
  495. {
  496. do
  497. {
  498. var iId = _fetchInt(i_crm, "Id");
  499. var oRules = db.Queryable<OTB_WSM_ExhibitionRules, OTB_OPM_Exhibition, OTB_SYS_Arguments>((t1, t2, t3) => t1.OrgID == t2.OrgID && t1.Guid == t2.CostRulesId && t1.OrgID == t3.OrgID && t1.Currency == t3.ArgumentID && t3.ArgumentClassID == "Currency")
  500. .Where((t1, t2) => t2.SN == iId)
  501. .Select((t1, t2, t3) => new View_WSM_ExhibitionRules
  502. {
  503. Guid = t1.Guid,
  504. FileId_EN = t1.FileId_EN,
  505. Title = t1.Title,
  506. CostRules = t1.CostRules,
  507. PackingPrice = t1.PackingPrice,
  508. FeedingPrice = t1.FeedingPrice,
  509. StoragePrice = t1.StoragePrice,
  510. FeedingRequiredMinCBM = t1.FeedingRequiredMinCBM,
  511. FeedingMinMode = t1.FeedingMinMode,
  512. PackingRequiredMinCBM = t1.PackingRequiredMinCBM,
  513. PackingMinMode = t1.PackingMinMode,
  514. CostInstruction = t1.CostInstruction,
  515. CostInstruction_EN = t1.CostInstruction_EN,
  516. IsMerge = t1.IsMerge,
  517. Memo = t1.Memo,
  518. ServiceInstruction = t1.ServiceInstruction,
  519. ServiceInstruction_EN = t1.ServiceInstruction_EN,
  520. Currency = t1.Currency,
  521. CurrencyName = t3.ArgumentValue,
  522. CurrencyName_EN = t3.ArgumentValue_EN,
  523. }).Single();
  524. var saFiles = new List<OTB_SYS_Files>();
  525. if (i_crm.LANG == "en")
  526. {
  527. saFiles = db.Queryable<OTB_SYS_Files>().OrderBy(x => x.OrderByValue).Where(x => x.ParentID == oRules.FileId_EN).ToList();
  528. }
  529. else
  530. {
  531. saFiles = db.Queryable<OTB_SYS_Files>().OrderBy(x => x.OrderByValue).Where(x => x.ParentID == oRules.Guid).ToList();
  532. }
  533. oRules.Files = saFiles;
  534. rm = new SuccessResponseMessage(null, i_crm);
  535. rm.DATA.Add(BLWording.REL, oRules);
  536. } while (false);
  537. }
  538. catch (Exception ex)
  539. {
  540. sMsg = Util.GetLastExceptionMsg(ex);
  541. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.WEBSITE.Com.ComService", "", "GetExhibitionRules(依據展覽獲取展覽報價規則)", "", "", "");
  542. }
  543. finally
  544. {
  545. if (null != sMsg)
  546. {
  547. rm = new ErrorResponseMessage(sMsg, i_crm);
  548. }
  549. }
  550. return rm;
  551. }
  552. #endregion 依據展覽獲取展覽報價規則
  553. #region 獲取預約服務展覽資訊
  554. /// <summary>
  555. /// 獲取預約服務展覽資訊
  556. /// </summary>
  557. /// <param name="i_crm"></param>
  558. /// <returns></returns>
  559. public ResponseMessage GetExhibitionAppoint(RequestMessage i_crm)
  560. {
  561. ResponseMessage rm = null;
  562. string sMsg = null;
  563. var db = SugarBase.DB;
  564. try
  565. {
  566. do
  567. {
  568. var pml = new PageModel
  569. {
  570. PageIndex = _fetchInt(i_crm, "pageIndex"),
  571. PageSize = _fetchInt(i_crm, "pageSize")
  572. };
  573. var iPageCount = 0;
  574. var sIsShowWebSim = _fetchString(i_crm, "IsShowWebSim");
  575. var bTop = _fetchBool(i_crm, "Top");
  576. var sKeyWords = _fetchString(i_crm, "KeyWords");
  577. var sArea = _fetchString(i_crm, "Area");
  578. var sDateStart = _fetchString(i_crm, "DateStart");
  579. var sDateEnd = _fetchString(i_crm, "DateEnd");
  580. var sNow = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
  581. pml.DataList = db.Queryable<OTB_OPM_Exhibition>()
  582. .OrderBy(t1 => t1.ExhibitionDateStart, OrderByType.Asc)
  583. .Where(t1 => t1.OrgID == i_crm.ORIGID && t1.IsShowWebSiteAppoint == "Y" && t1.Effective == "Y")
  584. //.WhereIF(!string.IsNullOrEmpty(sIsShowWebSim), (t1) => t1.OrgID == i_crm.ORIGID && t1.IsShowWebSim == "Y")
  585. .WhereIF(bTop, (t1) => t1.ExhibitionDateEnd >= DateTime.Now.Date)
  586. .WhereIF(!string.IsNullOrEmpty(sKeyWords), (t1) => (t1.Exhibitioname_TW.Contains(sKeyWords) || t1.Exhibitioname_EN.Contains(sKeyWords)))
  587. .WhereIF(!string.IsNullOrEmpty(sArea), (t1) => sArea.Contains(t1.State))
  588. .WhereIF(!string.IsNullOrEmpty(sDateStart) && string.IsNullOrEmpty(sDateEnd), (t1) => t1.ExhibitionDateEnd >= SqlFunc.ToDate(sDateStart))
  589. .WhereIF(!string.IsNullOrEmpty(sDateEnd) && string.IsNullOrEmpty(sDateStart), (t1) => t1.ExhibitionDateStart <= SqlFunc.ToDate(sDateEnd))
  590. .WhereIF(!string.IsNullOrEmpty(sDateStart) && !string.IsNullOrEmpty(sDateEnd), (t1) => t1.ExhibitionDateStart <= SqlFunc.ToDate(sDateEnd) && t1.ExhibitionDateEnd >= SqlFunc.ToDate(sDateStart))
  591. .Select(t1 => new
  592. {
  593. t1.SN,
  594. t1.Exhibitioname_TW,
  595. t1.Exhibitioname_EN
  596. }).ToPageList(pml.PageIndex, pml.PageSize, ref iPageCount);
  597. pml.Total = iPageCount;
  598. rm = new SuccessResponseMessage(null, i_crm);
  599. rm.DATA.Add(BLWording.REL, pml);
  600. } while (false);
  601. }
  602. catch (Exception ex)
  603. {
  604. sMsg = Util.GetLastExceptionMsg(ex);
  605. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.WEBSITE.Com.ComService", "", "GetExhibitionAppoint(獲取預約服務展覽資訊)", "", "", "");
  606. }
  607. finally
  608. {
  609. if (null != sMsg)
  610. {
  611. rm = new ErrorResponseMessage(sMsg, i_crm);
  612. }
  613. }
  614. return rm;
  615. }
  616. #endregion 獲取預約服務展覽資訊
  617. }
  618. }