You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

192 lines
7.2 KiB

  1. using EasyBL.WebApi.Message;
  2. using EasyNet;
  3. using Entity.Sugar;
  4. using Entity.ViewModels;
  5. using SqlSugar;
  6. using SqlSugar.Base;
  7. using System;
  8. using System.Collections.Generic;
  9. namespace EasyBL.WEBAPP.WSM
  10. {
  11. public class MemberMaintain_UpdService : ServiceBase
  12. {
  13. #region 會員類別管理(單筆查詢)
  14. /// <summary>
  15. /// 會員類別管理(單筆查詢)
  16. /// </summary>
  17. /// <param name="i_crm"></param>
  18. /// <returns></returns>
  19. public ResponseMessage QueryOne(RequestMessage i_crm)
  20. {
  21. ResponseMessage rm = null;
  22. string sMsg = null;
  23. var db = SugarBase.GetIntance();
  24. try
  25. {
  26. do
  27. {
  28. var sMemberID = _fetchString(i_crm, @"MemberID");
  29. var sCountryID = _fetchString(i_crm, @"CountryID");
  30. var sArgumentID = _fetchString(i_crm, @"ArgumentID");
  31. var oEntity = db.Queryable<SETB_CMS_Member, SETB_SYS_Country, OTB_SYS_Arguments>
  32. ((t1, t2, t3) =>
  33. new object[]{
  34. JoinType.Left, t1.OrgID == t2.OrgID && t1.CountryID == t2.CountryID,
  35. JoinType.Left,t1.OrgID == t3.OrgID && t1.ArgumentID == t3.ArgumentID
  36. })
  37. .Where((t1, t2, t3) => t1.OrgID == i_crm.ORIGID && t1.MemberID == sMemberID)
  38. .Select((t1, t2, t3) => new View_CMS_Member
  39. {
  40. MemberID = SqlFunc.GetSelfAndAutoFill(t1.MemberID),
  41. CountryID = SqlFunc.GetSelfAndAutoFill(t2.CountryID),
  42. ArgumentID = t3.ArgumentID,
  43. ArgumentValue = t3.ArgumentValue
  44. })
  45. .Single();
  46. rm = new SuccessResponseMessage(null, i_crm);
  47. rm.DATA.Add(BLWording.REL, oEntity);
  48. } while (false);
  49. }
  50. catch (Exception ex)
  51. {
  52. sMsg = Util.GetLastExceptionMsg(ex);
  53. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(MemberMaintain_UpdService), "", "QueryOne(會員類別管理(單筆查詢))", "", "", "");
  54. }
  55. finally
  56. {
  57. if (null != sMsg)
  58. {
  59. rm = new ErrorResponseMessage(sMsg, i_crm);
  60. }
  61. }
  62. return rm;
  63. }
  64. #endregion 會員類別管理(單筆查詢)
  65. #region 密碼加密
  66. /// <summary>
  67. /// 帳號管理(新增)
  68. /// </summary>
  69. /// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
  70. /// <returns></returns>
  71. public ResponseMessage ResetPassword(RequestMessage i_crm)
  72. {
  73. ResponseMessage rm = null;
  74. string sMsg = null;
  75. try
  76. {
  77. rm = SugarBase.ExecTran(db =>
  78. {
  79. do
  80. {
  81. var sMemberID = _fetchString(i_crm, @"MemberID");
  82. var MemberValue = db.Queryable<SETB_CMS_Member>().Single(x => x.OrgID == i_crm.ORIGID && x.MemberID == sMemberID);
  83. MemberValue.Password = SecurityUtil.Encrypt("123456");
  84. var iRel = db.Updateable(MemberValue).ExecuteCommand();
  85. rm = new SuccessResponseMessage(null, i_crm);
  86. rm.DATA.Add(BLWording.REL, iRel);
  87. } while (false);
  88. return rm;
  89. });
  90. }
  91. catch (Exception ex)
  92. {
  93. sMsg = Util.GetLastExceptionMsg(ex);
  94. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(MemberMaintain_UpdService), @"帳號管理", @"ResetPassword", @"", @"", @"");
  95. }
  96. finally
  97. {
  98. if (null != sMsg)
  99. {
  100. rm = new ErrorResponseMessage(sMsg, i_crm);
  101. }
  102. }
  103. return rm;
  104. }
  105. #endregion 密碼加密
  106. #region 寄送新密碼至信箱
  107. /// <summary>
  108. /// 帳號管理(新增)
  109. /// </summary>
  110. /// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
  111. /// <returns></returns>
  112. public ResponseMessage Insert(RequestMessage i_crm)
  113. {
  114. ResponseMessage rm = null;
  115. string sMsg = null;
  116. try
  117. {
  118. rm = SugarBase.ExecTran(db =>
  119. {
  120. do
  121. {
  122. var sMemberID = _fetchString(i_crm, @"MemberID");
  123. var sOrgID = _fetchString(i_crm, @"OrgID");
  124. string sError = null;
  125. var sEmail = db.Queryable<SETB_CMS_Member>().Single(x => x.OrgID == i_crm.ORIGID && x.MemberID == sMemberID); //取得Email
  126. if (sEmail == null)
  127. {
  128. sEmail = new SETB_CMS_Member();
  129. }
  130. var oEmail = new Emails(); //寄件人
  131. var toEmail = new List<EmailTo>(); //收件人
  132. var oEmailTo = new EmailTo //收件人資訊
  133. {
  134. ToUserID = sEmail.MemberID,
  135. ToUserName = sEmail.LastName,
  136. ToEmail = sEmail.Email,
  137. Type = "to"
  138. };
  139. toEmail.Add(oEmailTo);
  140. oEmail.FromUserName = "系統自動發送";//取fonfig
  141. oEmail.Title = "ShowEasy 密碼已重設";//取fonfig
  142. oEmail.EmailBody = "感謝您與ShowEasy客服聯繫,您的新密碼為:123456";
  143. oEmail.IsCCSelf = false;
  144. oEmail.Attachments = null;
  145. oEmail.EmailTo = toEmail;
  146. var bSend = new MailService(sOrgID, true).MailFactory(oEmail, out sError);
  147. if (sError != null)
  148. {
  149. break;
  150. }
  151. rm = new SuccessResponseMessage(null, i_crm);
  152. rm.DATA.Add(BLWording.REL, sError);
  153. } while (false);
  154. return rm;
  155. });
  156. }
  157. catch (Exception ex)
  158. {
  159. sMsg = Util.GetLastExceptionMsg(ex);
  160. LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(MemberMaintain_UpdService), @"帳號管理", @"Add", @"", @"", @"");
  161. }
  162. finally
  163. {
  164. if (null != sMsg)
  165. {
  166. rm = new ErrorResponseMessage(sMsg, i_crm);
  167. }
  168. }
  169. return rm;
  170. }
  171. #endregion 寄送新密碼至信箱
  172. }
  173. }