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.
 
 
 
 
 

193 lines
7.2 KiB

using EasyBL.WebApi.Message;
using EasyNet;
using Entity.Sugar;
using Entity.ViewModels;
using SqlSugar;
using SqlSugar.Base;
using System;
using System.Collections.Generic;
namespace EasyBL.WEBAPP.WSM
{
public class MemberMaintain_UpdService : ServiceBase
{
#region 會員類別管理(單筆查詢)
/// <summary>
/// 會員類別管理(單筆查詢)
/// </summary>
/// <param name="i_crm"></param>
/// <returns></returns>
public ResponseMessage QueryOne(RequestMessage i_crm)
{
ResponseMessage rm = null;
string sMsg = null;
var db = SugarBase.GetIntance();
try
{
do
{
var sMemberID = _fetchString(i_crm, @"MemberID");
var sCountryID = _fetchString(i_crm, @"CountryID");
var sArgumentID = _fetchString(i_crm, @"ArgumentID");
var oEntity = db.Queryable<SETB_CMS_Member, SETB_SYS_Country, OTB_SYS_Arguments>
((t1, t2, t3) =>
new object[]{
JoinType.Left, t1.OrgID == t2.OrgID && t1.CountryID == t2.CountryID,
JoinType.Left,t1.OrgID == t3.OrgID && t1.ArgumentID == t3.ArgumentID
})
.Where((t1, t2, t3) => t1.OrgID == i_crm.ORIGID && t1.MemberID == sMemberID)
.Select((t1, t2, t3) => new View_CMS_Member
{
MemberID = SqlFunc.GetSelfAndAutoFill(t1.MemberID),
CountryID = SqlFunc.GetSelfAndAutoFill(t2.CountryID),
ArgumentID = t3.ArgumentID,
ArgumentValue = t3.ArgumentValue
})
.Single();
rm = new SuccessResponseMessage(null, i_crm);
rm.DATA.Add(BLWording.REL, oEntity);
} while (false);
}
catch (Exception ex)
{
sMsg = Util.GetLastExceptionMsg(ex);
LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(MemberMaintain_UpdService), "", "QueryOne(會員類別管理(單筆查詢))", "", "", "");
}
finally
{
if (null != sMsg)
{
rm = new ErrorResponseMessage(sMsg, i_crm);
}
}
return rm;
}
#endregion 會員類別管理(單筆查詢)
#region 密碼加密
/// <summary>
/// 帳號管理(新增)
/// </summary>
/// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
/// <returns></returns>
public ResponseMessage ResetPassword(RequestMessage i_crm)
{
ResponseMessage rm = null;
string sMsg = null;
try
{
rm = SugarBase.ExecTran(db =>
{
do
{
var sMemberID = _fetchString(i_crm, @"MemberID");
var MemberValue = db.Queryable<SETB_CMS_Member>().Single(x => x.OrgID == i_crm.ORIGID && x.MemberID == sMemberID);
MemberValue.Password = SecurityUtil.Encrypt("123456");
var iRel = db.Updateable(MemberValue).ExecuteCommand();
rm = new SuccessResponseMessage(null, i_crm);
rm.DATA.Add(BLWording.REL, iRel);
} while (false);
return rm;
});
}
catch (Exception ex)
{
sMsg = Util.GetLastExceptionMsg(ex);
LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(MemberMaintain_UpdService), @"帳號管理", @"ResetPassword", @"", @"", @"");
}
finally
{
if (null != sMsg)
{
rm = new ErrorResponseMessage(sMsg, i_crm);
}
}
return rm;
}
#endregion 密碼加密
#region 寄送新密碼至信箱
/// <summary>
/// 帳號管理(新增)
/// </summary>
/// <param name="i_crm">todo: describe i_crm parameter on UpdImportCustomers</param>
/// <returns></returns>
public ResponseMessage Insert(RequestMessage i_crm)
{
ResponseMessage rm = null;
string sMsg = null;
try
{
rm = SugarBase.ExecTran(db =>
{
do
{
var sMemberID = _fetchString(i_crm, @"MemberID");
var sOrgID = _fetchString(i_crm, @"OrgID");
string sError = null;
var sEmail = db.Queryable<SETB_CMS_Member>().Single(x => x.OrgID == i_crm.ORIGID && x.MemberID == sMemberID); //取得Email
if (sEmail == null)
{
sEmail = new SETB_CMS_Member();
}
var oEmail = new Emails(); //寄件人
var toEmail = new List<EmailTo>(); //收件人
var oEmailTo = new EmailTo //收件人資訊
{
ToUserID = sEmail.MemberID,
ToUserName = sEmail.LastName,
ToEmail = sEmail.Email,
Type = "to"
};
toEmail.Add(oEmailTo);
oEmail.FromUserName = "系統自動發送";//取fonfig
oEmail.Title = "ShowEasy 密碼已重設";//取fonfig
oEmail.EmailBody = "感謝您與ShowEasy客服聯繫,您的新密碼為:123456";
oEmail.IsCCSelf = false;
oEmail.Attachments = null;
oEmail.EmailTo = toEmail;
var bSend = new MailService(sOrgID, true).MailFactory(oEmail, out sError);
if (sError != null)
{
break;
}
rm = new SuccessResponseMessage(null, i_crm);
rm.DATA.Add(BLWording.REL, sError);
} while (false);
return rm;
});
}
catch (Exception ex)
{
sMsg = Util.GetLastExceptionMsg(ex);
LogAndSendEmail(sMsg + @"Param:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(MemberMaintain_UpdService), @"帳號管理", @"Add", @"", @"", @"");
}
finally
{
if (null != sMsg)
{
rm = new ErrorResponseMessage(sMsg, i_crm);
}
}
return rm;
}
#endregion 寄送新密碼至信箱
}
}