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.
2234 lines
96 KiB
2234 lines
96 KiB
using CounsellorBL.BLStructure;
|
|
using CounsellorBL.Common;
|
|
using CounsellorBL.Helper;
|
|
using CounsellorBL.ORD;
|
|
using MonumentDefine;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using OT.COM.ArsenalDB;
|
|
using OT.COM.LogisticsUtil;
|
|
using OT.COM.SignalerMessage;
|
|
using SoldierData.EnterprizeV4;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net.Http;
|
|
using static CounsellorBL.Helper.FbRestHelper;
|
|
|
|
namespace CounsellorBL.MEB
|
|
{
|
|
public class MemberListService : SingleDataTableTemplate<tb_meb_member>
|
|
{
|
|
protected class MemberModel : tb_meb_member
|
|
{
|
|
public string age { get; set; }
|
|
public int return_count { get; set; }
|
|
public int amount { get; set; }
|
|
}
|
|
|
|
|
|
public class FbToken
|
|
{
|
|
public string access_token { get; set; }
|
|
public string token_type { get; set; }
|
|
public bool is_valid { get; set; }
|
|
}
|
|
|
|
|
|
public class FbGetGroups
|
|
{
|
|
public List<Groups> data { get; set; }
|
|
public JObject paging { get; set; }
|
|
}
|
|
|
|
|
|
public class Groups
|
|
{
|
|
public string name { get; set; }
|
|
|
|
public string id { get; set; }
|
|
|
|
public string privacy { get; set; }
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
private class CusMemberModel
|
|
{
|
|
public string uid { get; set; }
|
|
public string group_user_id { get; set; }
|
|
public string group_id { get; set; }
|
|
public string fb_pic { get; set; }
|
|
public string user_token { get; set; }
|
|
}
|
|
|
|
private class BatchModel
|
|
{
|
|
public int code { get; set; }
|
|
public string body { get; set; }
|
|
}
|
|
|
|
public class PictureModel
|
|
{
|
|
public Picture picture { get; set; }
|
|
public string id { get; set; }
|
|
|
|
public class Picture
|
|
{
|
|
public PictureData data { get; set; }
|
|
|
|
public class PictureData
|
|
{
|
|
public string url { get; set; }
|
|
}
|
|
}
|
|
}
|
|
|
|
public MemberListService()
|
|
{
|
|
dgReadCommandGenerator = readCommandGenerator;
|
|
dgReadCommandPostDataHandler = readCommandPostDataHandler;
|
|
}
|
|
|
|
|
|
|
|
public bool CheckUserIsInGroup(string group_id,string access_token)
|
|
{
|
|
var IsInGroup = false;
|
|
do
|
|
{
|
|
try
|
|
{
|
|
// 送出資料
|
|
string uri = "https://graph.facebook.com/v8.0/me/groups?limit=10000?";
|
|
var dicData = new Dictionary<string, string>()
|
|
{
|
|
{ "limit", "10000" },
|
|
{ "access_token",access_token}
|
|
};
|
|
APIHelper.BaseGet(uri, null, dicData, out HttpResponseMessage responseMessage);
|
|
if (responseMessage.IsSuccessStatusCode)
|
|
{
|
|
var fb_error = GetFbApiError(responseMessage);
|
|
|
|
if (!string.IsNullOrWhiteSpace(fb_error))
|
|
{
|
|
Logger.Error($"{nameof(CheckUserIsInGroup)} FB API response error message: {fb_error} ");
|
|
break;
|
|
}
|
|
var responseData = JsonConvert.DeserializeObject<FbGetGroups>(responseMessage.Content.ReadAsStringAsync().Result);
|
|
IsInGroup = responseData.data.Any(x => x.id == group_id);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
throw ex;
|
|
}
|
|
} while (false);
|
|
return IsInGroup;
|
|
|
|
}
|
|
|
|
|
|
|
|
[Auth(false)]
|
|
public new CResponseMessage ReadMemberInfo(CRequestMessage i_crmInput)
|
|
{
|
|
string sMsg;
|
|
Command cRes = null;
|
|
CResponseMessage crmRes = null;
|
|
do
|
|
{
|
|
try
|
|
{
|
|
Dictionary<string, string> dicObjCondition = GetQueryMasterFirstWhereData(i_crmInput).ToDictionary(x => x.Key, x => x.Value.ToString());
|
|
List<string> lsMainColumns = EntityBase.GetAllColumnName(typeof(tb_meb_member)); // 取得所有欄位名稱
|
|
|
|
QueryJsonElementCollection lBlocks = new QueryJsonElementCollection();
|
|
QueryJsonElement qjeMember = lBlocks.GetInst();
|
|
qjeMember.table = tb_meb_member.TABLENAME;
|
|
qjeMember.displaycols = lsMainColumns;
|
|
|
|
if (dicObjCondition != null && dicObjCondition.Any())
|
|
{
|
|
qjeMember.dicwherecols = dicObjCondition;
|
|
}
|
|
lBlocks.Add(qjeMember);
|
|
|
|
QueryJsonElement qjeBranch = lBlocks.GetInst();
|
|
qjeBranch.table = tb_grp_branch.TABLENAME;
|
|
qjeBranch.displaycols = new List<string> { tb_grp_branch .CN_BRANCH_NAME};
|
|
qjeBranch.jointable = qjeMember;
|
|
qjeBranch.joincols = new Dictionary<string, string> { { tb_grp_branch.CN_UID, tb_meb_member.CN_DEFAULT_BRANCH } };
|
|
lBlocks.Add(qjeBranch);
|
|
|
|
|
|
|
|
sMsg = MakeSelectJoinByBlocks(lBlocks, out cRes);
|
|
if (sMsg != null)
|
|
{
|
|
break;
|
|
}
|
|
ArsenalInterface ai = ArsenalDBMgr.GetInst(cRes);
|
|
|
|
var qdsMember = ai.RunQueryDataSet(cRes);
|
|
|
|
crmRes = new CSuccessResponseMessage(null, i_crmInput);
|
|
// 多傳一些參數到前端
|
|
crmRes.param.Add("member", new QueryResponse(qdsMember));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sMsg = $"{nameof(ReadMemberInfo)} unknwon exception. i_crmInput={JsonConvert.SerializeObject(i_crmInput)}. ex={ex.Message}";
|
|
#if DEBUG
|
|
System.Diagnostics.Debug.WriteLine(sMsg);
|
|
#endif
|
|
}
|
|
} while (false);
|
|
|
|
if (!string.IsNullOrEmpty(sMsg))
|
|
{
|
|
crmRes = new CErrorResponseMessage(sMsg, i_crmInput);
|
|
Logger.Error(JsonConvert.SerializeObject(i_crmInput));
|
|
Logger.Error(JsonConvert.SerializeObject(crmRes));
|
|
}
|
|
|
|
|
|
return crmRes;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Auth(false)]
|
|
public new CResponseMessage Read(CRequestMessage i_crmInput) => base.Read(i_crmInput);
|
|
protected string readCommandGenerator(CRequestMessage i_crmInput, JArray i_jaData, tb_sys_session i_sSessionUser, out Command o_c,
|
|
[System.Runtime.CompilerServices.CallerLineNumber] int i_nCodeLine = 0,
|
|
[System.Runtime.CompilerServices.CallerMemberName] string i_sMemberName = "",
|
|
[System.Runtime.CompilerServices.CallerFilePath] string i_sSourcePath = "")
|
|
{
|
|
string sMsg;
|
|
Command cRes = null;
|
|
try
|
|
{
|
|
do
|
|
{
|
|
Dictionary<string, object> dicObjCondition = GetQueryMasterFirstWhereData(i_crmInput);
|
|
List<string> lsMainColumns = EntityBase.GetAllColumnName(typeof(tb_meb_member)); // 取得所有欄位名稱
|
|
var lsBranch = ProjectHelper.GetUserGroup(i_crmInput); // 取得可讀取社團資料的社團uid清單
|
|
var lsMember = new List<string>();
|
|
if (dicObjCondition.ContainsKey(tb_meb_member.CN_UID))
|
|
{
|
|
var aMember = dicObjCondition[tb_meb_member.CN_UID] as JArray;
|
|
foreach (var member in aMember)
|
|
{
|
|
lsMember.Add(member.ToString());
|
|
}
|
|
dicObjCondition.Remove(tb_meb_member.CN_UID);
|
|
}
|
|
|
|
Dictionary<string, string> dicCondition = new Dictionary<string, string>();
|
|
foreach (var condition in dicObjCondition)
|
|
{
|
|
dicCondition.Add(condition.Key, condition.Value.ToString());
|
|
}
|
|
|
|
QueryJsonElementCollection lBlocks = new QueryJsonElementCollection();
|
|
QueryJsonElement qjeMember = lBlocks.GetInst();
|
|
qjeMember.table = tb_meb_member.TABLENAME;
|
|
qjeMember.displaycols = lsMainColumns;
|
|
qjeMember.aliascols = new Dictionary<string, List<string>>
|
|
{
|
|
{ "'0'", new List<string>() { "return_count" } }
|
|
};
|
|
if (lsMember.Any())
|
|
{
|
|
qjeMember.wherecols = new WhereNode(tb_meb_member.CN_UID, WhereNode.EColumnOperation.EOT_IN, typeof(tb_meb_member), lsMember.ToArray());
|
|
}
|
|
if (dicCondition != null && dicCondition.Any())
|
|
{
|
|
qjeMember.dicwherecols = dicCondition;
|
|
}
|
|
lBlocks.Add(qjeMember);
|
|
|
|
QueryJsonElement qjeGroup = lBlocks.GetInst();
|
|
qjeGroup.table = tb_grp_group.TABLENAME;
|
|
qjeGroup.jointable = qjeMember;
|
|
qjeGroup.jointype = QueryJsonElement.LEFT_JOIN;
|
|
qjeGroup.joincols = new Dictionary<string, string>() {
|
|
{ tb_grp_group.CN_FB_GROUP_ID,tb_meb_member.CN_GROUP_ID }};
|
|
if (!dicCondition.ContainsKey(tb_meb_member.CN_GROUP_USER_ID))
|
|
{
|
|
qjeGroup.wherecols = new WhereNode(tb_grp_group.CN_UID, WhereNode.EColumnOperation.EOT_IN, typeof(tb_grp_group), lsBranch.ToArray());
|
|
}
|
|
lBlocks.Add(qjeGroup);
|
|
|
|
QueryJsonElement qjePurchase = lBlocks.GetInst();
|
|
qjePurchase.table = tb_ord_purchase.TABLENAME;
|
|
qjePurchase.jointype = QueryJsonElement.LEFT_JOIN;
|
|
qjePurchase.jointable = qjeMember;
|
|
qjePurchase.joincols = new Dictionary<string, string>() {
|
|
{ tb_ord_purchase.CN_MEMBER_UID,tb_meb_member.CN_UID }};
|
|
qjePurchase.aliascols = new Dictionary<string, List<string>>
|
|
{
|
|
{ QueryJsonElement.SUM(tb_ord_purchase.CN_AMOUNT), new List<string>() { "amount" } },
|
|
};
|
|
lBlocks.Add(qjePurchase);
|
|
|
|
qjeMember.groupcols = new List<Tuple<QueryJsonElement, string>>
|
|
{
|
|
Tuple.Create(qjeMember, tb_meb_member.CN_UID),
|
|
Tuple.Create(qjeMember, tb_meb_member.CN_GROUP_ID),
|
|
Tuple.Create(qjeMember, tb_meb_member.CN_GROUP_USER_ID),
|
|
Tuple.Create(qjeMember, tb_meb_member.CN_MESSAGE_USER_ID),
|
|
Tuple.Create(qjeMember, tb_meb_member.CN_EMAIL),
|
|
Tuple.Create(qjeMember, tb_meb_member.CN_RANK),
|
|
Tuple.Create(qjeMember, tb_meb_member.CN_FB_PIC),
|
|
Tuple.Create(qjeMember, tb_meb_member.CN_NAME),
|
|
Tuple.Create(qjeMember, tb_meb_member.CN_NICKNAME),
|
|
Tuple.Create(qjeMember, tb_meb_member.CN_GENDER),
|
|
Tuple.Create(qjeMember, tb_meb_member.CN_JOB),
|
|
Tuple.Create(qjeMember, tb_meb_member.CN_BIRTHDAY),
|
|
Tuple.Create(qjeMember, tb_meb_member.CN_CELLPHONE),
|
|
Tuple.Create(qjeMember, tb_meb_member.CN_PHONE),
|
|
Tuple.Create(qjeMember, tb_meb_member.CN_LAST_CALL_MESSAGE),
|
|
Tuple.Create(qjeMember, tb_meb_member.CN_LINE_ID),
|
|
Tuple.Create(qjeMember, tb_meb_member.CN_AREA),
|
|
Tuple.Create(qjeMember, tb_meb_member.CN_ADDRESS),
|
|
Tuple.Create(qjeMember, tb_meb_member.CN_LINK),
|
|
Tuple.Create(qjeMember, tb_meb_member.CN_SHOPPING_ACCOUNT),
|
|
Tuple.Create(qjeMember, tb_meb_member.CN_STATUS_FLAG),
|
|
Tuple.Create(qjeMember, tb_meb_member.CN_DEFAULT_BRANCH),
|
|
Tuple.Create(qjeMember, tb_meb_member.CN_DELETE_FLAG),
|
|
Tuple.Create(qjeMember, tb_meb_member.CN_WPRICE_PAYMENT),
|
|
Tuple.Create(qjeMember, tb_meb_member.CN_CREATE_DATE),
|
|
Tuple.Create(qjeMember, tb_meb_member.CN_UPDATE_DATE),
|
|
Tuple.Create(qjeMember, tb_meb_member.CN_CREATE_USER_UID),
|
|
Tuple.Create(qjeMember, tb_meb_member.CN_UPDATE_USER_UID),
|
|
Tuple.Create(qjeMember, tb_meb_member.CN_RETURN_COUNT),
|
|
Tuple.Create(qjeMember, tb_meb_member.CN_FIREBASE_TOKEN),
|
|
};
|
|
|
|
sMsg = MakeSelectJoinByBlocks(lBlocks, out cRes);
|
|
if (sMsg != null)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.DBLog(Util.GetLastExceptionMsg(ex), i_nCodeLine, i_sMemberName, i_sSourcePath);
|
|
sMsg = $"{nameof(readCommandGenerator)} unknwon exception. i_crmInput={JsonConvert.SerializeObject(i_crmInput)}. Call from {i_sMemberName} {i_sSourcePath}({i_nCodeLine}).";
|
|
#if DEBUG
|
|
System.Diagnostics.Debug.WriteLine(sMsg);
|
|
#endif
|
|
}
|
|
o_c = cRes;
|
|
return sMsg;
|
|
}
|
|
protected string readCommandPostDataHandler(CRequestMessage i_crmInput, ArsenalInterface i_aiArsenal, Command i_cCmd, JArray i_jaData, tb_sys_session i_sSessionUser, out object o_oReault,
|
|
[System.Runtime.CompilerServices.CallerLineNumber] int i_nCodeLine = 0,
|
|
[System.Runtime.CompilerServices.CallerMemberName] string i_sMemberName = "",
|
|
[System.Runtime.CompilerServices.CallerFilePath] string i_sSourcePath = "")
|
|
{
|
|
string sMsg = null;
|
|
List<MemberModel> oResultData = null;
|
|
try
|
|
{
|
|
do
|
|
{
|
|
Dictionary<string, object> dicCondition = GetQueryMasterFirstWhereData(i_crmInput); // 取得condition
|
|
List<MemberModel> qds = i_aiArsenal.RunQueryList<MemberModel>(i_cCmd);
|
|
|
|
if (!i_cCmd.IsSuccess)
|
|
{
|
|
sMsg = i_cCmd.LastErrorCode;
|
|
break;
|
|
}
|
|
|
|
if (dicCondition.ContainsKey("birthdayMonth"))
|
|
{
|
|
qds = qds.Where(x => x.birthday.HasValue && x.birthday.Value.Month == Convert.ToInt32(dicCondition["birthdayMonth"])).ToList();
|
|
}
|
|
// 不顯示現貨銷售
|
|
if (dicCondition.ContainsKey("hideSpotSale"))
|
|
{
|
|
qds = qds.Where(x => x.name != "現貨銷售").ToList();
|
|
}
|
|
|
|
foreach (var data in qds)
|
|
{
|
|
if (data.birthday.HasValue)
|
|
{
|
|
var age = CalculateAgeCorrect(data.birthday.Value, DateTime.Now);
|
|
data.age = age == 0 ? "" : age.ToString();
|
|
}
|
|
}
|
|
oResultData = qds.OrderByDescending(x => x.create_date).ToList();
|
|
}
|
|
while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.DBLog(Util.GetLastExceptionMsg(ex), i_nCodeLine, i_sMemberName, i_sSourcePath);
|
|
sMsg = $"{nameof(readCommandPostDataHandler)} unknwon exception. i_crmInput={JsonConvert.SerializeObject(i_crmInput)}. Call from {i_sMemberName} {i_sSourcePath}({i_nCodeLine}).";
|
|
#if DEBUG
|
|
System.Diagnostics.Debug.WriteLine(sMsg);
|
|
#endif
|
|
}
|
|
|
|
o_oReault = oResultData;
|
|
return sMsg;
|
|
}
|
|
|
|
public int CalculateAgeCorrect(DateTime birthDate, DateTime now)
|
|
{
|
|
int age = now.Year - birthDate.Year;
|
|
if (now.Month < birthDate.Month || (now.Month == birthDate.Month && now.Day < birthDate.Day)) age--;
|
|
return age;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 取得應用程式權杖
|
|
/// </summary>
|
|
/// <param name="authorizationToken"></param>
|
|
/// <param name="client_id"></param>
|
|
/// <param name="client_secret"></param>
|
|
/// <returns></returns>
|
|
public bool GetAppToken(string APP_ID, string CLIENT_SECRET, out FbToken responseData)
|
|
{
|
|
responseData = new FbToken();
|
|
string uri = string.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&client_secret={1}&grant_type=client_credentials", APP_ID, CLIENT_SECRET);
|
|
APIHelper.BaseGet(uri, null, new Dictionary<string, string>(), out HttpResponseMessage responseMessage);
|
|
if (responseMessage.IsSuccessStatusCode)
|
|
{
|
|
responseData = JsonConvert.DeserializeObject<FbToken>(responseMessage.Content.ReadAsStringAsync().Result);
|
|
}
|
|
return responseMessage.IsSuccessStatusCode;
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool GetFBPagesID(string i_sASID, string PAGE_ID, string i_sToken, out string o_sPSID)
|
|
{
|
|
o_sPSID = null;
|
|
string uri = string.Format("https://graph.facebook.com/{0}/ids_for_pages?page={1}&access_token={2}", i_sASID, PAGE_ID, i_sToken);
|
|
APIHelper.BaseGet(uri, null, new Dictionary<string, string>(), out HttpResponseMessage responseMessage);
|
|
if (responseMessage.IsSuccessStatusCode)
|
|
{
|
|
var sResponse = responseMessage.Content.ReadAsStringAsync().Result;
|
|
Logger.Info(uri + " && " + sResponse);
|
|
var joResult = JsonConvert.DeserializeObject(sResponse) as JObject;
|
|
var oResult = joResult.ToObject<Dictionary<string, object>>();
|
|
var jaData = oResult["data"] as JArray;
|
|
if (jaData.Any())
|
|
{
|
|
var joData = jaData.First() as JObject;
|
|
if (joData != null)
|
|
{
|
|
var objData = joData.ToObject<Dictionary<string, object>>();
|
|
o_sPSID = objData["id"].ToString();
|
|
}
|
|
}
|
|
}
|
|
return responseMessage.IsSuccessStatusCode;
|
|
}
|
|
|
|
|
|
[Auth(false)]
|
|
public CResponseMessage GetQrCode(CRequestMessage i_crmInput)
|
|
{
|
|
string sMsg = null;
|
|
CResponseMessage crmRes = null;
|
|
do
|
|
{
|
|
try
|
|
{
|
|
Dictionary<string, object> dicCondition = GetQueryMasterFirstWhereData(i_crmInput); // 取得condition
|
|
|
|
if (!string.IsNullOrEmpty(sMsg))
|
|
{
|
|
break;
|
|
}
|
|
var group_id = dicCondition[tb_meb_member.CN_GROUP_ID].ToString();
|
|
// 先查詢資料是否存在
|
|
tb_meb_member cMember = new tb_meb_member();
|
|
cMember.SetDirty(tb_meb_member.CN_UID, tb_meb_member.CN_GROUP_USER_ID);
|
|
tb_meb_member cMemberCon = new tb_meb_member() { group_user_id = dicCondition[tb_meb_member.CN_GROUP_USER_ID].ToString(), group_id = group_id };
|
|
Command cMemberSelect = Command.SetupSelectCmd(cMember, cMemberCon);
|
|
ArsenalInterface ai = ArsenalDBMgr.GetInst(cMemberSelect);
|
|
tb_meb_member qdsMember = ai.RunQuerySingleORM<tb_meb_member>(cMemberSelect);
|
|
|
|
crmRes = new CSuccessResponseMessage(null, i_crmInput);
|
|
// 多傳一些參數到前端
|
|
crmRes.param.Add("member", qdsMember);
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sMsg = $"{nameof(PatchMemberInfo)} unknwon exception. i_crmInput={JsonConvert.SerializeObject(i_crmInput)}. ex={ex.Message}";
|
|
#if DEBUG
|
|
System.Diagnostics.Debug.WriteLine(sMsg);
|
|
#endif
|
|
}
|
|
} while (false);
|
|
|
|
if (!string.IsNullOrEmpty(sMsg))
|
|
{
|
|
crmRes = new CErrorResponseMessage(sMsg, i_crmInput);
|
|
Logger.Error(JsonConvert.SerializeObject(i_crmInput));
|
|
Logger.Error(JsonConvert.SerializeObject(crmRes));
|
|
}
|
|
|
|
return crmRes;
|
|
}
|
|
|
|
|
|
[Auth(false)]
|
|
public CResponseMessage CheckTokenValid(CRequestMessage i_crmInput)
|
|
{
|
|
string sMsg = null;
|
|
CResponseMessage crmRes = null;
|
|
do
|
|
{
|
|
try
|
|
{
|
|
Dictionary<string, object> dicCondition = GetQueryMasterFirstWhereData(i_crmInput); // 取得condition
|
|
var fbHelper = new FbRestHelper();
|
|
sMsg = fbHelper.CallFbGetInformation(dicCondition["token"].ToString(), out UserInfo userInfo);
|
|
|
|
if (!string.IsNullOrEmpty(sMsg))
|
|
{
|
|
break;
|
|
}
|
|
|
|
|
|
var group_id = dicCondition[tb_meb_member.CN_GROUP_ID].ToString();
|
|
var groupData = GetGroupSettings(group_id);
|
|
|
|
string sPSID = null;
|
|
if (groupData == null)
|
|
{
|
|
sMsg = "社團資訊錯誤";
|
|
break;
|
|
}
|
|
|
|
#region 取得 pages_user_id <PSID> 到貨通知需要
|
|
var result = GetAppToken(groupData.app_id, groupData.client_secret, out FbToken resData);
|
|
if (result)
|
|
{
|
|
GetFBPagesID(userInfo.id, groupData.page_id, resData.access_token, out sPSID);
|
|
}
|
|
string privacy = null;
|
|
bool isSuccess = getPrivacy(group_id, out privacy);
|
|
|
|
var IsOpen = false;
|
|
if (privacy == "OPEN")
|
|
{
|
|
IsOpen = true;
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
var IsInGroups = CheckUserIsInGroup(group_id, dicCondition["token"].ToString());
|
|
|
|
|
|
|
|
|
|
// 更新會員資料
|
|
List<Command> lCmdUpdate = new List<Command>();
|
|
|
|
// 先查詢資料是否存在
|
|
tb_meb_member cMember = new tb_meb_member();
|
|
cMember.SetFullDirty();
|
|
tb_meb_member cMemberCon = new tb_meb_member() { group_user_id = userInfo.id, group_id = group_id };
|
|
Command cMemberSelect = Command.SetupSelectCmd(cMember, cMemberCon);
|
|
ArsenalInterface ai = ArsenalDBMgr.GetInst(cMemberSelect);
|
|
tb_meb_member qdsMember = ai.RunQuerySingleORM<tb_meb_member>(cMemberSelect);
|
|
string asid = userInfo.id;
|
|
|
|
|
|
if (qdsMember == null)
|
|
{
|
|
|
|
// 新增
|
|
tb_meb_member mNew = new tb_meb_member() { };
|
|
mNew.message_user_id = sPSID;
|
|
mNew.group_user_id = asid;
|
|
mNew.last_call_message = DateTime.Now;
|
|
mNew.gender = userInfo.gender;
|
|
mNew.email = userInfo.email;
|
|
mNew.fb_pic = userInfo.picture.data.url;
|
|
|
|
if (DateTime.TryParse(userInfo.birthday, out DateTime birthday))
|
|
{
|
|
mNew.birthday = birthday;
|
|
}
|
|
|
|
mNew.group_user_id = userInfo.id;
|
|
mNew.group_id = dicCondition["group_id"].ToString();
|
|
lCmdUpdate.Add(Command.SetupInsertCmd(mNew));
|
|
}
|
|
else
|
|
{
|
|
// 更新
|
|
tb_meb_member mUpd = new tb_meb_member();
|
|
mUpd.message_user_id = sPSID;
|
|
if (qdsMember.last_call_message == null) // 紀錄最後傳送時間
|
|
{
|
|
mUpd.last_call_message = DateTime.Now;
|
|
}
|
|
mUpd.message_user_id = sPSID;
|
|
mUpd.group_user_id = asid;
|
|
mUpd.last_call_message = DateTime.Now;
|
|
mUpd.gender = userInfo.gender;
|
|
mUpd.email = userInfo.email;
|
|
mUpd.fb_pic = userInfo.picture.data.url;
|
|
if (DateTime.TryParse(userInfo.birthday, out DateTime birthday))
|
|
{
|
|
mUpd.birthday = birthday;
|
|
}
|
|
|
|
mUpd.group_user_id = userInfo.id;
|
|
|
|
|
|
List<WhereNode> lswnMain = new List<WhereNode>();
|
|
lswnMain.Add(new WhereNode(tb_meb_member.CN_GROUP_USER_ID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_meb_member), asid));
|
|
lswnMain.Add(new WhereNode(tb_meb_member.CN_GROUP_ID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_meb_member), group_id));
|
|
|
|
lCmdUpdate.Add(Command.SetupUpdateCmd(mUpd, new WhereNode(WhereNode.ENodeOperation.ENO_AND, lswnMain.ToArray())));
|
|
}
|
|
ai = ArsenalDBMgr.GetInst(lCmdUpdate[0], GetDefaultSystemColumnInfo());
|
|
ai.RunEditCmds(lCmdUpdate);
|
|
sMsg = GetLastErrorCode(lCmdUpdate);
|
|
|
|
if (sMsg != null)
|
|
{
|
|
if (sMsg == "msg.sqlserver_2627") // 此錯誤為重複 Insert 相同 group_user_id and group_id 改為更新
|
|
{
|
|
List<Command> lCmdUpdateWhenErr = new List<Command>();
|
|
// 更新
|
|
tb_meb_member mUpdErr = new tb_meb_member();
|
|
mUpdErr.message_user_id = sPSID;
|
|
mUpdErr.message_user_id = sPSID;
|
|
mUpdErr.group_user_id = asid;
|
|
mUpdErr.last_call_message = DateTime.Now;
|
|
mUpdErr.gender = userInfo.gender;
|
|
mUpdErr.email = userInfo.email;
|
|
mUpdErr.fb_pic = userInfo.picture.data.url;
|
|
if (DateTime.TryParse(userInfo.birthday, out DateTime birthday))
|
|
{
|
|
mUpdErr.birthday = birthday;
|
|
}
|
|
mUpdErr.group_user_id = userInfo.id;
|
|
List<WhereNode> lswnMainErr = new List<WhereNode>();
|
|
lswnMainErr.Add(new WhereNode(tb_meb_member.CN_GROUP_USER_ID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_meb_member), asid));
|
|
lswnMainErr.Add(new WhereNode(tb_meb_member.CN_GROUP_ID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_meb_member), group_id));
|
|
|
|
lCmdUpdateWhenErr.Add(Command.SetupUpdateCmd(mUpdErr, new WhereNode(WhereNode.ENodeOperation.ENO_AND, lswnMainErr.ToArray())));
|
|
|
|
ArsenalInterface ai2 = ArsenalDBMgr.GetInst(lCmdUpdateWhenErr[0], GetDefaultSystemColumnInfo());
|
|
ai2.RunEditCmds(lCmdUpdateWhenErr);
|
|
sMsg = GetLastErrorCode(lCmdUpdateWhenErr);
|
|
// 傳必要參數至前端
|
|
crmRes.param.Add("psid", sPSID);
|
|
crmRes.param.Add("branch_status", 1);
|
|
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
crmRes = new CSuccessResponseMessage(null, i_crmInput);
|
|
// 多傳一些參數到前端
|
|
crmRes.param.Add("psid", sPSID);
|
|
|
|
if (IsOpen == true)
|
|
{
|
|
crmRes.param.Add("joinGroups", "Y");
|
|
}
|
|
else
|
|
{
|
|
crmRes.param.Add("joinGroups", IsInGroups == true ? "Y" : "N");
|
|
}
|
|
|
|
|
|
crmRes.param.Add("fbid", userInfo.id);
|
|
|
|
// 只顯示公開的分店
|
|
List<tb_grp_branch> branches = GetBranches(group_id);
|
|
var enabledBranches = branches.Where(x => x.public_status == (int)Enums.Flag.Enable).Select(x => new { value = x.uid, display = x.branch_name });
|
|
|
|
// 沒有預設分店
|
|
string default_branch = qdsMember?.default_branch;
|
|
int branch_status = 0; // 0:未填寫 1:已填寫 -1:已填寫但分店消失
|
|
if (!string.IsNullOrEmpty(default_branch))
|
|
{
|
|
branch_status = enabledBranches.Any(x => x.value == default_branch) ? 1 : -1;
|
|
crmRes.param.Add("default_branch", enabledBranches.Where(x => x.value == default_branch).FirstOrDefault().display);
|
|
}
|
|
if (branch_status != 1)
|
|
{
|
|
crmRes.param.Add("branch_data", enabledBranches);
|
|
}
|
|
crmRes.param.Add("branch_status", branch_status);
|
|
Logger.Info($"group_id: {group_id} group_user_id: {asid} branch_status: {branch_status} enabledBranches: {enabledBranches.Count()}");
|
|
|
|
// 紀錄是否第一次登入
|
|
if (qdsMember == null)
|
|
{
|
|
crmRes.param.Add("first_login", true);
|
|
}
|
|
|
|
//在查一次傳uid
|
|
cMember = new tb_meb_member();
|
|
cMember.SetFullDirty();
|
|
cMemberCon = new tb_meb_member() { group_user_id = userInfo.id, group_id = group_id };
|
|
cMemberSelect = Command.SetupSelectCmd(cMember, cMemberCon);
|
|
ai = ArsenalDBMgr.GetInst(cMemberSelect);
|
|
qdsMember = ai.RunQuerySingleORM<tb_meb_member>(cMemberSelect);
|
|
if (qdsMember == null)
|
|
{
|
|
crmRes.param.Add("uid", tb_meb_member.CN_UID);
|
|
}
|
|
crmRes.param.Add("token", Guid.NewGuid().ToString());
|
|
|
|
|
|
// 如果超過指定天數沒有按,提醒使用者
|
|
bool sendMessageAgain = qdsMember?.message_user_id != null && qdsMember?.last_call_message <= DateTime.Now.AddMonths(-1);
|
|
crmRes.param.Add("send_msg_again", sendMessageAgain);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sMsg = $"{nameof(PatchMemberInfo)} unknwon exception. i_crmInput={JsonConvert.SerializeObject(i_crmInput)}. ex={ex.Message}";
|
|
#if DEBUG
|
|
System.Diagnostics.Debug.WriteLine(sMsg);
|
|
#endif
|
|
}
|
|
} while (false);
|
|
|
|
if (!string.IsNullOrEmpty(sMsg))
|
|
{
|
|
crmRes = new CErrorResponseMessage(sMsg, i_crmInput);
|
|
Logger.Error(JsonConvert.SerializeObject(i_crmInput));
|
|
Logger.Error(JsonConvert.SerializeObject(crmRes));
|
|
}
|
|
|
|
return crmRes;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Auth(false)]
|
|
public CResponseMessage PatchMemberInfo(CRequestMessage i_crmInput)
|
|
{
|
|
string sMsg = null;
|
|
CResponseMessage crmRes = null;
|
|
try
|
|
{
|
|
do
|
|
{
|
|
|
|
|
|
sMsg = getCommonParameter(i_crmInput, BLWording.ADD_MASTER, out JArray jaDataArray, out tb_sys_session sUserSession);
|
|
if (sMsg != null)
|
|
{
|
|
break;
|
|
}
|
|
if (jaDataArray.Count != 1 || jaDataArray[0] == null)
|
|
{
|
|
sMsg = MessageWording.PARAM_NOT_EXPECTED;
|
|
break;
|
|
}
|
|
|
|
JObject joData = jaDataArray[0] as JObject;
|
|
Dictionary<string, object> dicData = new Dictionary<string, object>();
|
|
|
|
if (joData != null)
|
|
{
|
|
dicData = joData.ToObject<Dictionary<string, object>>();
|
|
}
|
|
string sPSID = null;
|
|
|
|
var group_id = dicData[tb_meb_member.CN_GROUP_ID].ToString();
|
|
var groupData = GetGroupSettings(group_id);
|
|
|
|
if (groupData == null)
|
|
{
|
|
sMsg = "社團資訊錯誤";
|
|
break;
|
|
}
|
|
|
|
#region 取得 pages_user_id <PSID> 到貨通知需要
|
|
var result = GetAppToken(groupData.app_id, groupData.client_secret, out FbToken resData);
|
|
if (result)
|
|
{
|
|
GetFBPagesID(dicData[BLWording.ASID].ToString(), groupData.page_id, resData.access_token, out sPSID);
|
|
}
|
|
#endregion
|
|
|
|
// 更新會員資料
|
|
List<Command> lCmdUpdate = new List<Command>();
|
|
|
|
// 先查詢資料是否存在
|
|
tb_meb_member cMember = new tb_meb_member();
|
|
cMember.SetFullDirty();
|
|
tb_meb_member cMemberCon = new tb_meb_member() { group_user_id = dicData[BLWording.ASID].ToString(), group_id = group_id };
|
|
Command cMemberSelect = Command.SetupSelectCmd(cMember, cMemberCon);
|
|
ArsenalInterface ai = ArsenalDBMgr.GetInst(cMemberSelect);
|
|
tb_meb_member qdsMember = ai.RunQuerySingleORM<tb_meb_member>(cMemberSelect);
|
|
string asid = dicData[BLWording.ASID].ToString();
|
|
|
|
if (qdsMember == null)
|
|
{
|
|
// 新增
|
|
tb_meb_member mNew = new tb_meb_member() { };
|
|
mNew.message_user_id = sPSID;
|
|
mNew.group_user_id = asid;
|
|
mNew.last_call_message = DateTime.Now;
|
|
mNew.FillData(dicData);
|
|
lCmdUpdate.Add(Command.SetupInsertCmd(mNew));
|
|
}
|
|
else
|
|
{
|
|
// 更新
|
|
dicData.Remove("group_id");
|
|
tb_meb_member mUpd = new tb_meb_member();
|
|
mUpd.message_user_id = sPSID;
|
|
if (qdsMember.last_call_message == null) // 紀錄最後傳送時間
|
|
{
|
|
mUpd.last_call_message = DateTime.Now;
|
|
}
|
|
mUpd.FillData(dicData);
|
|
List<WhereNode> lswnMain = new List<WhereNode>();
|
|
lswnMain.Add(new WhereNode(tb_meb_member.CN_GROUP_USER_ID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_meb_member), asid));
|
|
lswnMain.Add(new WhereNode(tb_meb_member.CN_GROUP_ID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_meb_member), group_id));
|
|
|
|
lCmdUpdate.Add(Command.SetupUpdateCmd(mUpd, new WhereNode(WhereNode.ENodeOperation.ENO_AND, lswnMain.ToArray())));
|
|
}
|
|
ai = ArsenalDBMgr.GetInst(lCmdUpdate[0], GetDefaultSystemColumnInfo());
|
|
ai.RunEditCmds(lCmdUpdate);
|
|
sMsg = GetLastErrorCode(lCmdUpdate);
|
|
|
|
if (sMsg != null)
|
|
{
|
|
if (sMsg == "msg.sqlserver_2627") // 此錯誤為重複 Insert 相同 group_user_id and group_id 改為更新
|
|
{
|
|
List<Command> lCmdUpdateWhenErr = new List<Command>();
|
|
// 更新
|
|
dicData.Remove("group_id");
|
|
tb_meb_member mUpdErr = new tb_meb_member();
|
|
mUpdErr.message_user_id = sPSID;
|
|
mUpdErr.FillData(dicData);
|
|
List<WhereNode> lswnMainErr = new List<WhereNode>();
|
|
lswnMainErr.Add(new WhereNode(tb_meb_member.CN_GROUP_USER_ID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_meb_member), asid));
|
|
lswnMainErr.Add(new WhereNode(tb_meb_member.CN_GROUP_ID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_meb_member), group_id));
|
|
|
|
lCmdUpdateWhenErr.Add(Command.SetupUpdateCmd(mUpdErr, new WhereNode(WhereNode.ENodeOperation.ENO_AND, lswnMainErr.ToArray())));
|
|
|
|
ArsenalInterface ai2 = ArsenalDBMgr.GetInst(lCmdUpdateWhenErr[0], GetDefaultSystemColumnInfo());
|
|
ai2.RunEditCmds(lCmdUpdateWhenErr);
|
|
sMsg = GetLastErrorCode(lCmdUpdateWhenErr);
|
|
// 傳必要參數至前端
|
|
crmRes.param.Add("psid", sPSID);
|
|
crmRes.param.Add("branch_status", 1);
|
|
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
crmRes = new CSuccessResponseMessage(null, i_crmInput);
|
|
// 多傳一些參數到前端
|
|
crmRes.param.Add("psid", sPSID);
|
|
|
|
// 只顯示公開的分店
|
|
List<tb_grp_branch> branches = GetBranches(group_id);
|
|
var enabledBranches = branches.Where(x => x.public_status == (int)Enums.Flag.Enable).Select(x => new { value = x.uid, display = $"{x.branch_name} - {x.address = x.address }" });
|
|
|
|
// 沒有預設分店
|
|
string default_branch = qdsMember?.default_branch;
|
|
int branch_status = 0; // 0:未填寫 1:已填寫 -1:已填寫但分店消失
|
|
if (!string.IsNullOrEmpty(default_branch))
|
|
{
|
|
branch_status = enabledBranches.Any(x => x.value == default_branch) ? 1 : -1;
|
|
crmRes.param.Add("default_branch", enabledBranches.Where(x => x.value == default_branch).FirstOrDefault().display);
|
|
}
|
|
if (branch_status != 1)
|
|
{
|
|
crmRes.param.Add("branch_data", enabledBranches);
|
|
}
|
|
crmRes.param.Add("branch_status", branch_status);
|
|
Logger.Info($"group_id: {group_id} group_user_id: {asid} branch_status: {branch_status} enabledBranches: {enabledBranches.Count()}");
|
|
|
|
// 紀錄是否第一次登入
|
|
if (qdsMember == null)
|
|
{
|
|
crmRes.param.Add("first_login", true);
|
|
}
|
|
|
|
// 如果超過指定天數沒有按,提醒使用者
|
|
bool sendMessageAgain = qdsMember?.message_user_id != null && qdsMember?.last_call_message <= DateTime.Now.AddMonths(-1);
|
|
crmRes.param.Add("send_msg_again", sendMessageAgain);
|
|
}
|
|
while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sMsg = $"{nameof(PatchMemberInfo)} unknwon exception. i_crmInput={JsonConvert.SerializeObject(i_crmInput)}. ex={ex.Message}";
|
|
#if DEBUG
|
|
System.Diagnostics.Debug.WriteLine(sMsg);
|
|
#endif
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(sMsg))
|
|
{
|
|
//Logger.Info(JsonConvert.SerializeObject(i_crmInput));
|
|
//Logger.Info(JsonConvert.SerializeObject(crmRes));
|
|
}
|
|
else
|
|
{
|
|
crmRes = new CErrorResponseMessage(sMsg, i_crmInput);
|
|
Logger.Error(JsonConvert.SerializeObject(i_crmInput));
|
|
Logger.Error(JsonConvert.SerializeObject(crmRes));
|
|
}
|
|
return crmRes;
|
|
}
|
|
|
|
private List<tb_grp_branch> GetBranches(string group_id)
|
|
{
|
|
// 從group_id找到uid,再用uid去撈分店名稱跟分店uid
|
|
QueryJsonElementCollection lBlocks = new QueryJsonElementCollection();
|
|
QueryJsonElement qjeOrigin = lBlocks.GetInst();
|
|
qjeOrigin.table = tb_grp_group.TABLENAME;
|
|
qjeOrigin.displaycols = new List<string>() { tb_grp_group.CN_UID };
|
|
qjeOrigin.wherecols = new WhereNode(tb_grp_group.CN_FB_GROUP_ID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_grp_group), group_id);
|
|
lBlocks.Add(qjeOrigin);
|
|
string sMsg = MakeSelectJoinByBlocks(lBlocks, out Command cRes);
|
|
var ai = ArsenalDBMgr.GetInst(cRes);
|
|
var group = ai.RunQuerySingleORM<tb_grp_group>(cRes);
|
|
|
|
if (group == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
lBlocks = new QueryJsonElementCollection();
|
|
qjeOrigin = lBlocks.GetInst();
|
|
qjeOrigin.table = tb_grp_branch.TABLENAME;
|
|
qjeOrigin.displaycols = new List<string>() { tb_grp_branch.CN_UID, tb_grp_branch.CN_BRANCH_NAME, tb_grp_branch.CN_PUBLIC_STATUS, tb_grp_branch.CN_ADDRESS };
|
|
qjeOrigin.wherecols = new WhereNode(tb_grp_branch.CN_GROUP_UID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_grp_branch), group.uid);
|
|
lBlocks.Add(qjeOrigin);
|
|
sMsg = MakeSelectJoinByBlocks(lBlocks, out cRes);
|
|
ai = ArsenalDBMgr.GetInst(cRes);
|
|
var data = ai.RunQueryList<tb_grp_branch>(cRes);
|
|
|
|
return data;
|
|
}
|
|
|
|
public CResponseMessage GetMatchedMember(CRequestMessage i_crmInput)
|
|
{
|
|
CResponseMessage crmRes = null;
|
|
string sMsg = null;
|
|
|
|
try
|
|
{
|
|
do
|
|
{
|
|
tb_meb_member sDisplay = new tb_meb_member();
|
|
sDisplay.SetFullDirtyEx(EntityBaseExtension.EColumnFilter.ES_NO_SYSTEMCOLUMN);
|
|
Command cAllSetting = Command.SetupSelectCmd(sDisplay);
|
|
|
|
crmRes = this.simpleQuery(i_crmInput, BLWording.QRY_MASTER, null, cAllSetting);
|
|
|
|
}
|
|
while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.DBLog(Util.GetLastExceptionMsg(ex));
|
|
sMsg = $"{nameof(GetMatchedMember)} unknwon exception. Call from).";
|
|
|
|
#if DEBUG
|
|
System.Diagnostics.Debug.WriteLine(sMsg);
|
|
#endif
|
|
|
|
}
|
|
|
|
if (sMsg != null)
|
|
{
|
|
crmRes = new CErrorResponseMessage(sMsg);
|
|
Logger.Error(JsonConvert.SerializeObject(i_crmInput));
|
|
Logger.Error(JsonConvert.SerializeObject(crmRes));
|
|
}
|
|
else
|
|
{
|
|
//Logger.Info(JsonConvert.SerializeObject(i_crmInput));
|
|
//Logger.Info(JsonConvert.SerializeObject(crmRes));
|
|
}
|
|
|
|
return crmRes;
|
|
}
|
|
public CResponseMessage GetMemberProfile(CRequestMessage i_crmInput)
|
|
{
|
|
CResponseMessage crmRes = null;
|
|
string sMsg = null;
|
|
Command cRes = null;
|
|
|
|
try
|
|
{
|
|
do
|
|
{
|
|
Dictionary<string, string> dicCondition = GetQueryMasterFirstQJEDicwherecols(i_crmInput);
|
|
|
|
var lsBranch = ProjectHelper.GetUserGroup(i_crmInput);
|
|
|
|
QueryJsonElementCollection lBlocks = new QueryJsonElementCollection();
|
|
QueryJsonElement qjeMember = lBlocks.GetInst();
|
|
qjeMember.table = tb_meb_member.TABLENAME;
|
|
qjeMember.dicwherecols = dicCondition;
|
|
lBlocks.Add(qjeMember);
|
|
|
|
QueryJsonElement qjeGroup = lBlocks.GetInst();
|
|
qjeGroup.table = tb_grp_group.TABLENAME;
|
|
qjeGroup.jointable = qjeMember;
|
|
qjeGroup.jointype = QueryJsonElement.LEFT_JOIN;
|
|
qjeGroup.joincols = new Dictionary<string, string>() {
|
|
{ tb_grp_group.CN_FB_GROUP_ID,tb_meb_member.CN_GROUP_ID }};
|
|
if (!dicCondition.ContainsKey(tb_meb_member.CN_GROUP_USER_ID))
|
|
{
|
|
qjeGroup.wherecols = new WhereNode(tb_grp_group.CN_UID, WhereNode.EColumnOperation.EOT_IN, typeof(tb_grp_group), lsBranch.ToArray());
|
|
}
|
|
lBlocks.Add(qjeGroup);
|
|
|
|
QueryJsonElement qjeGroupUser = lBlocks.GetInst();
|
|
qjeGroupUser.table = tb_grp_group2user.TABLENAME;
|
|
qjeGroupUser.jointable = qjeGroup;
|
|
qjeGroupUser.jointype = QueryJsonElement.LEFT_JOIN;
|
|
qjeGroupUser.joincols = new Dictionary<string, string> { { tb_grp_group2user.CN_GROUP_UID, tb_grp_group.CN_UID } };
|
|
qjeGroupUser.displaycols = new List<string>()
|
|
{
|
|
tb_grp_group2user.CN_USER_TOKEN
|
|
};
|
|
lBlocks.Add(qjeGroupUser);
|
|
|
|
sMsg = MakeSelectJoinByBlocks(lBlocks, out cRes);
|
|
ArsenalInterface ai = ArsenalDBMgr.GetInst(cRes);
|
|
List<tb_grp_group> qds = ai.RunQueryList<tb_grp_group>(cRes);
|
|
var user_token = "";
|
|
foreach (var data in qds)
|
|
{
|
|
user_token = data.GetValue("user_token").ToString();
|
|
}
|
|
string uri = "";
|
|
if (dicCondition.ContainsKey(tb_meb_member.CN_GROUP_USER_ID))
|
|
{
|
|
uri = string.Format("https://graph.facebook.com/{0}?fields={1}&access_token={2}", dicCondition[tb_meb_member.CN_GROUP_USER_ID], "picture.type(normal)", user_token);
|
|
}
|
|
APIHelper.BaseGet(uri, null, new Dictionary<string, string>(), out HttpResponseMessage responseMessage);
|
|
|
|
if (responseMessage.IsSuccessStatusCode)
|
|
{
|
|
var joResult = JsonConvert.DeserializeObject(responseMessage.Content.ReadAsStringAsync().Result) as JObject;
|
|
var oResult = joResult.ToObject<Dictionary<string, object>>();
|
|
if (oResult.Any())
|
|
{
|
|
crmRes = new CSuccessResponseMessage(null, i_crmInput);
|
|
crmRes.param.Add("data", oResult);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
LogHelper.DBLog("url獲取picture失敗:" + uri);
|
|
crmRes = new CErrorResponseMessage("獲取picture失敗");
|
|
}
|
|
|
|
}
|
|
while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.DBLog(Util.GetLastExceptionMsg(ex));
|
|
sMsg = $"{nameof(GetMemberProfile)} unknwon exception. Call from).";
|
|
|
|
#if DEBUG
|
|
System.Diagnostics.Debug.WriteLine(sMsg);
|
|
#endif
|
|
|
|
}
|
|
|
|
if (sMsg != null)
|
|
{
|
|
crmRes = new CErrorResponseMessage(sMsg);
|
|
Logger.Error(JsonConvert.SerializeObject(i_crmInput));
|
|
Logger.Error(JsonConvert.SerializeObject(crmRes));
|
|
}
|
|
else
|
|
{
|
|
//Logger.Info(JsonConvert.SerializeObject(i_crmInput));
|
|
//Logger.Info(JsonConvert.SerializeObject(crmRes));
|
|
}
|
|
|
|
return crmRes;
|
|
}
|
|
|
|
|
|
public CResponseMessage RefreshAllMemberInfo(CRequestMessage i_crmInput)
|
|
{
|
|
CResponseMessage crmRes = null;
|
|
string sMsg = null;
|
|
Command cRes = null;
|
|
try
|
|
{
|
|
do
|
|
{
|
|
Dictionary<string, object> dicCondition = GetQueryMasterFirstWhereData(i_crmInput);
|
|
string[] aMemberUID = new string[0];
|
|
if (dicCondition.ContainsKey(tb_meb_member.CN_UID))
|
|
{
|
|
if (dicCondition[tb_meb_member.CN_UID] != null)
|
|
{
|
|
var jaMemberUID = dicCondition[tb_meb_member.CN_UID] as JArray;
|
|
aMemberUID = jaMemberUID.Select(x => x.ToString()).ToArray();
|
|
}
|
|
}
|
|
QueryJsonElementCollection lBlocks = new QueryJsonElementCollection();
|
|
QueryJsonElement qjeMember = lBlocks.GetInst();
|
|
qjeMember.table = tb_meb_member.TABLENAME;
|
|
qjeMember.displaycols = new List<string>()
|
|
{ tb_meb_member.CN_UID,
|
|
tb_meb_member.CN_GROUP_USER_ID,
|
|
tb_meb_member.CN_GROUP_ID,
|
|
tb_meb_member.CN_FB_PIC
|
|
};
|
|
qjeMember.wherecols = new WhereNode(tb_meb_member.CN_UID, WhereNode.EColumnOperation.EOT_IN, typeof(tb_meb_member), aMemberUID.ToArray());
|
|
lBlocks.Add(qjeMember);
|
|
|
|
QueryJsonElement qjeGroup = lBlocks.GetInst();
|
|
qjeGroup.table = tb_grp_group.TABLENAME;
|
|
qjeGroup.jointable = qjeMember;
|
|
qjeGroup.jointype = QueryJsonElement.LEFT_JOIN;
|
|
qjeGroup.joincols = new Dictionary<string, string>() {
|
|
{ tb_grp_group.CN_FB_GROUP_ID,tb_meb_member.CN_GROUP_ID }};
|
|
lBlocks.Add(qjeGroup);
|
|
|
|
QueryJsonElement qjeGroupUser = lBlocks.GetInst();
|
|
qjeGroupUser.table = tb_grp_group2user.TABLENAME;
|
|
qjeGroupUser.jointable = qjeGroup;
|
|
qjeGroupUser.jointype = QueryJsonElement.LEFT_JOIN;
|
|
qjeGroupUser.joincols = new Dictionary<string, string> { { tb_grp_group2user.CN_GROUP_UID, tb_grp_group.CN_UID } };
|
|
qjeGroupUser.displaycols = new List<string>()
|
|
{
|
|
tb_grp_group2user.CN_USER_TOKEN
|
|
};
|
|
lBlocks.Add(qjeGroupUser);
|
|
|
|
sMsg = MakeSelectJoinByBlocks(lBlocks, out cRes);
|
|
ArsenalInterface ai = ArsenalDBMgr.GetInst(cRes);
|
|
List<CusMemberModel> qds = ai.RunQueryList<CusMemberModel>(cRes);
|
|
|
|
List<Command> lCmdUpdate = new List<Command>();
|
|
List<WhereNode> lswnMain = new List<WhereNode>();
|
|
var user_token = "";
|
|
if(qds.Count()>0)
|
|
{
|
|
user_token = qds[0].user_token.ToString();
|
|
}
|
|
|
|
string strPostUrl = "https://graph.facebook.com/me";
|
|
var lsData = new List<APIHelper.DataContent>()
|
|
{
|
|
new APIHelper.DataContent { Key = "access_token" , Type = typeof(StringContent) , Content = user_token },
|
|
new APIHelper.DataContent { Key = "include_headers", Type = typeof(StringContent), Content = "false" }
|
|
};
|
|
var listBacth = new List<Dictionary<string, string>>();
|
|
var dicBacth = new Dictionary<string, string>();
|
|
var iRowNO = 0;
|
|
foreach (CusMemberModel MemberData in qds)
|
|
{
|
|
iRowNO++;
|
|
dicBacth = new Dictionary<string, string>();
|
|
dicBacth.Add("method", "GET");
|
|
dicBacth.Add("relative_url", string.Format("{0}?fields={1}", MemberData.group_user_id, "picture.type(normal)"));
|
|
listBacth.Add(dicBacth);
|
|
try
|
|
{
|
|
//每50執行一次批次
|
|
if (iRowNO % 50 == 0 || iRowNO == qds.Count())
|
|
{
|
|
lsData.Add(new APIHelper.DataContent { Key = "batch", Type = typeof(StringContent), Content = JsonConvert.SerializeObject(listBacth) });
|
|
listBacth = new List<Dictionary<string, string>>();
|
|
APIHelper.BasePost(strPostUrl, null, lsData, out HttpResponseMessage responseMessage);
|
|
if (responseMessage.IsSuccessStatusCode)
|
|
{
|
|
string sContent = responseMessage.Content.ReadAsStringAsync().Result;
|
|
var lstReturn = JsonConvert.DeserializeObject<List<BatchModel>>(sContent);
|
|
foreach (BatchModel BatchModel in lstReturn)
|
|
{
|
|
if (BatchModel.code == 200)
|
|
{
|
|
var PictureModel = JsonConvert.DeserializeObject<PictureModel>(BatchModel.body);
|
|
var strPicurl = PictureModel.picture.data.url;
|
|
if (!string.IsNullOrEmpty(strPicurl))
|
|
{
|
|
//更新
|
|
tb_meb_member mUpd = new tb_meb_member();
|
|
mUpd.fb_pic = strPicurl;
|
|
mUpd.update_date = DateTime.Now;
|
|
lswnMain = new List<WhereNode>();
|
|
lswnMain.Add(new WhereNode(tb_meb_member.CN_GROUP_USER_ID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_meb_member), PictureModel.id));
|
|
lCmdUpdate.Add(Command.SetupUpdateCmd(mUpd, new WhereNode(WhereNode.ENodeOperation.ENO_AND, lswnMain.ToArray())));
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
Logger.Error($"CallFbPostPushAPI f7");
|
|
sMsg = JsonConvert.SerializeObject(responseMessage);
|
|
Logger.Error($"CallFbPostPushAPI sMsg={sMsg}");
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.DBLog(Util.GetLastExceptionMsg(ex));
|
|
Logger.Error(MemberData.uid + "error");
|
|
sMsg = MemberData.uid + "error";
|
|
|
|
#if DEBUG
|
|
System.Diagnostics.Debug.WriteLine(sMsg);
|
|
#endif
|
|
}
|
|
}
|
|
// 更新fb_pic資料
|
|
if (lCmdUpdate.Count() > 0)
|
|
{
|
|
ai = ArsenalDBMgr.GetInst(lCmdUpdate[0], GetDefaultSystemColumnInfo());
|
|
ai.RunEditCmds(lCmdUpdate);
|
|
sMsg = GetLastErrorCode(lCmdUpdate);
|
|
|
|
if (sMsg != null)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
//查詢最新的fb_pic
|
|
lBlocks = new QueryJsonElementCollection();
|
|
qjeMember = lBlocks.GetInst();
|
|
qjeMember.table = tb_meb_member.TABLENAME;
|
|
qjeMember.displaycols = new List<string>()
|
|
{ tb_meb_member.CN_UID,
|
|
tb_meb_member.CN_GROUP_USER_ID,
|
|
tb_meb_member.CN_GROUP_ID,
|
|
tb_meb_member.CN_FB_PIC
|
|
};
|
|
qjeMember.wherecols = new WhereNode(tb_meb_member.CN_UID, WhereNode.EColumnOperation.EOT_IN, typeof(tb_meb_member), aMemberUID.ToArray());
|
|
lBlocks.Add(qjeMember);
|
|
sMsg = MakeSelectJoinByBlocks(lBlocks, out cRes);
|
|
ai = ArsenalDBMgr.GetInst(cRes);
|
|
qds = ai.RunQueryList<CusMemberModel>(cRes);
|
|
crmRes = new CSuccessResponseMessage(null, i_crmInput);
|
|
crmRes.param.Add(BLWording.DATA, qds);
|
|
}
|
|
while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.DBLog(Util.GetLastExceptionMsg(ex));
|
|
sMsg = $"{nameof(GetMemberProfile)} unknwon exception. Call from).";
|
|
|
|
#if DEBUG
|
|
System.Diagnostics.Debug.WriteLine(sMsg);
|
|
#endif
|
|
|
|
}
|
|
|
|
if (sMsg != null)
|
|
{
|
|
crmRes = new CErrorResponseMessage(sMsg);
|
|
Logger.Error(JsonConvert.SerializeObject(i_crmInput));
|
|
Logger.Error(JsonConvert.SerializeObject(crmRes));
|
|
}
|
|
return crmRes;
|
|
}
|
|
|
|
[Auth(false)]
|
|
public CResponseMessage SetDefaultBranch(CRequestMessage i_crmInput)
|
|
{
|
|
return UpdateCommand(i_crmInput, (dicData) =>
|
|
{
|
|
var defaultBranch = dicData[tb_meb_member.CN_DEFAULT_BRANCH] as string;
|
|
var group_user_id = dicData[tb_meb_member.CN_GROUP_USER_ID] as string;
|
|
var group_id = dicData[tb_meb_member.CN_GROUP_ID] as string;
|
|
|
|
// 更新預設分店
|
|
tb_meb_member updateEntity = new tb_meb_member { default_branch = defaultBranch };
|
|
tb_meb_member updateEntityCond = new tb_meb_member { group_user_id = group_user_id, group_id = group_id };
|
|
return Command.SetupUpdateCmd(updateEntity, updateEntityCond);
|
|
});
|
|
}
|
|
|
|
[Auth(false)]
|
|
public CResponseMessage CallSendMessage(CRequestMessage i_crmInput)
|
|
{
|
|
return UpdateCommand(i_crmInput, (dicData) =>
|
|
{
|
|
var group_user_id = dicData[tb_meb_member.CN_GROUP_USER_ID] as string;
|
|
var group_id = dicData[tb_meb_member.CN_GROUP_ID] as string;
|
|
|
|
// 更新最後傳遞訊息時間
|
|
tb_meb_member updateEntity = new tb_meb_member { last_call_message = DateTime.Now };
|
|
tb_meb_member updateEntityCond = new tb_meb_member { group_user_id = group_user_id, group_id = group_id };
|
|
return Command.SetupUpdateCmd(updateEntity, updateEntityCond);
|
|
});
|
|
}
|
|
|
|
private CResponseMessage UpdateCommand(CRequestMessage i_crmInput, Func<Dictionary<string, object>, Command> func)
|
|
{
|
|
CResponseMessage crmRes = null;
|
|
string sMsg = null;
|
|
Dictionary<string, object> dicData = (i_crmInput.param[BLWording.UPD_MASTER] as JObject).ToObject<Dictionary<string, object>>();
|
|
|
|
try
|
|
{
|
|
do
|
|
{
|
|
Command cmd = func(dicData);
|
|
|
|
var ai = ArsenalDBMgr.GetInst(cmd, GetDefaultSystemColumnInfo());
|
|
ai.RunEditSingleCmd(cmd);
|
|
sMsg = GetLastErrorCode(cmd);
|
|
}
|
|
while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.DBLog(Util.GetLastExceptionMsg(ex));
|
|
sMsg = $"{nameof(UpdateCommand)} unknwon exception. Call from).";
|
|
|
|
#if DEBUG
|
|
System.Diagnostics.Debug.WriteLine(sMsg);
|
|
#endif
|
|
|
|
}
|
|
|
|
if (sMsg != null)
|
|
{
|
|
crmRes = new CErrorResponseMessage(sMsg);
|
|
Logger.Error(JsonConvert.SerializeObject(i_crmInput));
|
|
Logger.Error(JsonConvert.SerializeObject(crmRes));
|
|
}
|
|
else
|
|
{
|
|
crmRes = new CSuccessResponseMessage(null, i_crmInput);
|
|
//Logger.Info(JsonConvert.SerializeObject(i_crmInput));
|
|
//Logger.Info(JsonConvert.SerializeObject(crmRes));
|
|
}
|
|
|
|
return crmRes;
|
|
}
|
|
public CResponseMessage RefreshMemberInfo(CRequestMessage i_crmInput)
|
|
{
|
|
string sMsg = null;
|
|
CResponseMessage crmRes = null;
|
|
try
|
|
{
|
|
do
|
|
{
|
|
sMsg = getCommonParameter(i_crmInput, BLWording.ADD_MASTER, out JArray jaDataArray, out tb_sys_session sUserSession);
|
|
if (sMsg != null)
|
|
{
|
|
break;
|
|
}
|
|
if (jaDataArray.Count != 1 || jaDataArray[0] == null)
|
|
{
|
|
sMsg = MessageWording.PARAM_NOT_EXPECTED;
|
|
break;
|
|
}
|
|
|
|
JObject joData = jaDataArray[0] as JObject;
|
|
Dictionary<string, object> dicData = new Dictionary<string, object>();
|
|
|
|
if (joData != null)
|
|
{
|
|
dicData = joData.ToObject<Dictionary<string, object>>();
|
|
}
|
|
string sPSID = null;
|
|
string fbGroupId = null;
|
|
if (dicData.ContainsKey(tb_meb_member.CN_GROUP_ID))
|
|
{
|
|
fbGroupId = dicData[tb_meb_member.CN_GROUP_ID].ToString();
|
|
}
|
|
|
|
var groupData = GetGroupSettings(fbGroupId);
|
|
|
|
var result = GetAppToken(groupData.app_id, groupData.client_secret, out FbToken resData);
|
|
if (result)
|
|
{
|
|
GetFBPagesID(dicData[BLWording.ASID].ToString(), groupData.page_id, resData.access_token, out sPSID);
|
|
}
|
|
|
|
// 更新會員資料
|
|
List<Command> lCmdUpdate = new List<Command>();
|
|
|
|
// 先查詢資料是否存在
|
|
tb_meb_member cMember = new tb_meb_member();
|
|
cMember.SetFullDirty();
|
|
tb_meb_member cMemberCon = new tb_meb_member() { group_user_id = dicData[BLWording.ASID].ToString(), group_id = fbGroupId };
|
|
Command cMemberSelect = Command.SetupSelectCmd(cMember, cMemberCon);
|
|
ArsenalInterface ai = ArsenalDBMgr.GetInst(cMemberSelect);
|
|
tb_meb_member qdsMember = ai.RunQuerySingleORM<tb_meb_member>(cMemberSelect);
|
|
string asid = dicData[BLWording.ASID].ToString();
|
|
var group_id = fbGroupId;
|
|
|
|
// 更新
|
|
dicData.Remove(tb_grp_article.CN_GROUP_UID);
|
|
tb_meb_member mUpd = new tb_meb_member();
|
|
mUpd.message_user_id = sPSID;
|
|
mUpd.fb_pic = dicData[tb_meb_member.CN_FB_PIC].ToString();
|
|
List<WhereNode> lswnMain = new List<WhereNode>();
|
|
lswnMain.Add(new WhereNode(tb_meb_member.CN_GROUP_USER_ID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_meb_member), asid));
|
|
lswnMain.Add(new WhereNode(tb_meb_member.CN_GROUP_ID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_meb_member), group_id));
|
|
|
|
lCmdUpdate.Add(Command.SetupUpdateCmd(mUpd, new WhereNode(WhereNode.ENodeOperation.ENO_AND, lswnMain.ToArray())));
|
|
|
|
ai = ArsenalDBMgr.GetInst(lCmdUpdate[0], GetDefaultSystemColumnInfo());
|
|
ai.RunEditCmds(lCmdUpdate);
|
|
sMsg = GetLastErrorCode(lCmdUpdate);
|
|
|
|
if (sMsg != null)
|
|
{
|
|
break;
|
|
}
|
|
|
|
crmRes = new CSuccessResponseMessage(null, i_crmInput);
|
|
crmRes.param.Add("psid", sPSID);
|
|
}
|
|
while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sMsg = $"{nameof(RefreshMemberInfo)} unknwon exception. i_crmInput={JsonConvert.SerializeObject(i_crmInput)}. ex={ex.Message}";
|
|
#if DEBUG
|
|
System.Diagnostics.Debug.WriteLine(sMsg);
|
|
#endif
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(sMsg))
|
|
{
|
|
//Logger.Info(JsonConvert.SerializeObject(i_crmInput));
|
|
//Logger.Info(JsonConvert.SerializeObject(crmRes));
|
|
}
|
|
else
|
|
{
|
|
crmRes = new CErrorResponseMessage(sMsg, i_crmInput);
|
|
Logger.Error(JsonConvert.SerializeObject(i_crmInput));
|
|
Logger.Error(JsonConvert.SerializeObject(crmRes));
|
|
}
|
|
return crmRes;
|
|
}
|
|
public CResponseMessage GetAllMembers(CRequestMessage i_crmInput)
|
|
{
|
|
string sMsg;
|
|
Command cRes = null;
|
|
CResponseMessage crmRes = null;
|
|
try
|
|
{
|
|
do
|
|
{
|
|
Dictionary<string, object> dicObjCondition = GetQueryMasterFirstWhereData(i_crmInput);
|
|
List<string> lsMainColumns = EntityBase.GetAllColumnName(typeof(tb_meb_member)); // 取得所有欄位名稱
|
|
var lsBranch = ProjectHelper.GetUserGroup(i_crmInput); // 取得可讀取社團資料的社團uid清單
|
|
var lsMember = new List<string>();
|
|
if (dicObjCondition.ContainsKey(tb_meb_member.CN_UID))
|
|
{
|
|
var aMember = dicObjCondition[tb_meb_member.CN_UID] as JArray;
|
|
foreach (var member in aMember)
|
|
{
|
|
lsMember.Add(member.ToString());
|
|
}
|
|
dicObjCondition.Remove(tb_meb_member.CN_UID);
|
|
}
|
|
|
|
Dictionary<string, string> dicCondition = new Dictionary<string, string>();
|
|
foreach (var condition in dicObjCondition)
|
|
{
|
|
dicCondition.Add(condition.Key, condition.Value.ToString());
|
|
}
|
|
|
|
QueryJsonElementCollection lBlocks = new QueryJsonElementCollection();
|
|
QueryJsonElement qjeMember = lBlocks.GetInst();
|
|
qjeMember.table = tb_meb_member.TABLENAME;
|
|
qjeMember.displaycols = lsMainColumns;
|
|
List<WhereNode> lswnMain = new List<WhereNode>();
|
|
if (lsMember.Any())
|
|
{
|
|
qjeMember.wherecols = new WhereNode(tb_meb_member.CN_UID, WhereNode.EColumnOperation.EOT_IN, typeof(tb_meb_member), lsMember.ToArray());
|
|
}
|
|
lBlocks.Add(qjeMember);
|
|
|
|
QueryJsonElement qjeGroup = lBlocks.GetInst();
|
|
qjeGroup.table = tb_grp_group.TABLENAME;
|
|
qjeGroup.jointable = qjeMember;
|
|
qjeGroup.jointype = QueryJsonElement.LEFT_JOIN;
|
|
qjeGroup.joincols = new Dictionary<string, string>() {
|
|
{ tb_grp_group.CN_FB_GROUP_ID,tb_meb_member.CN_GROUP_ID }};
|
|
if (dicObjCondition.ContainsKey(tb_meb_member.CN_GROUP_ID))
|
|
{
|
|
qjeGroup.wherecols = new WhereNode(tb_grp_group.CN_UID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_grp_group), dicObjCondition[tb_meb_member.CN_GROUP_ID].ToString());
|
|
}
|
|
else
|
|
{
|
|
qjeGroup.wherecols = new WhereNode(tb_grp_group.CN_UID, WhereNode.EColumnOperation.EOT_IN, typeof(tb_grp_group), lsBranch.ToArray());
|
|
}
|
|
lBlocks.Add(qjeGroup);
|
|
|
|
sMsg = MakeSelectJoinByBlocks(lBlocks, out cRes);
|
|
ArsenalInterface ai = ArsenalDBMgr.GetInst(cRes, GetDefaultSystemColumnInfo());
|
|
List<tb_meb_member> qds = ai.RunQueryList<tb_meb_member>(cRes);
|
|
sMsg = GetLastErrorCode(cRes);
|
|
|
|
if (sMsg != null)
|
|
{
|
|
break;
|
|
}
|
|
crmRes = new CSuccessResponseMessage(null, i_crmInput);
|
|
crmRes.param.Add("data", qds);
|
|
}
|
|
while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sMsg = $"{nameof(GetAllMembers)} unknwon exception. i_crmInput={JsonConvert.SerializeObject(i_crmInput)}. ex={ex.Message}";
|
|
#if DEBUG
|
|
System.Diagnostics.Debug.WriteLine(sMsg);
|
|
#endif
|
|
}
|
|
return crmRes;
|
|
}
|
|
[Auth(false)]
|
|
public CResponseMessage SetShoppingPoints(CRequestMessage i_crmInput)
|
|
{
|
|
CResponseMessage crmRes = null;
|
|
string sMsg = null;
|
|
Command cRes = null;
|
|
|
|
try
|
|
{
|
|
do
|
|
{
|
|
sMsg = getCommonParameter(i_crmInput, BLWording.UPD_MASTER, out JArray jaDataArray, out tb_sys_session sUserSession);
|
|
if (sMsg != null)
|
|
{
|
|
break;
|
|
}
|
|
if (jaDataArray.Count != 1 || jaDataArray[0] == null)
|
|
{
|
|
sMsg = MessageWording.PARAM_NOT_EXPECTED;
|
|
break;
|
|
}
|
|
JObject joData = jaDataArray[0] as JObject;
|
|
|
|
Dictionary<string, object> dicData = joData[BLWording.WHEREDATA].ToObject<Dictionary<string, object>>();
|
|
|
|
|
|
tb_meb_member cMember = new tb_meb_member();
|
|
cMember.SetDirty(tb_meb_member.CN_UID);
|
|
tb_meb_member cCon = new tb_meb_member()
|
|
{
|
|
group_user_id = dicData[tb_meb_member.CN_GROUP_USER_ID].ToString(),
|
|
group_id = dicData[tb_meb_member.CN_GROUP_ID].ToString()
|
|
};
|
|
Command cSelect = Command.SetupSelectCmd(cMember, cCon);
|
|
ArsenalInterface ai = ArsenalDBMgr.GetInst(cSelect);
|
|
List<tb_meb_member> qdsMember = ai.RunQueryList<tb_meb_member>(cSelect);
|
|
|
|
List<Command> lCmdUpdate = new List<Command>();
|
|
string sNewArticleUid = Guid.NewGuid().ToString();
|
|
|
|
tb_meb_shopping_points_record mNew = new tb_meb_shopping_points_record() { };
|
|
mNew.uid = sNewArticleUid;
|
|
mNew.member_uid = qdsMember[0].uid;
|
|
mNew.amount = 30;
|
|
mNew.memo = "首登";
|
|
lCmdUpdate.Add(Command.SetupInsertCmd(mNew));
|
|
|
|
lCmdUpdate.Add(Command.SetupUpdateCmd(new tb_meb_member()
|
|
{
|
|
shopping_account = 30
|
|
}
|
|
, new tb_meb_member() { uid = qdsMember[0].uid }));
|
|
|
|
ai = ArsenalDBMgr.GetInst(lCmdUpdate[0], GetDefaultSystemColumnInfo());
|
|
ai.RunEditCmds(lCmdUpdate);
|
|
sMsg = GetLastErrorCode(lCmdUpdate);
|
|
|
|
if (sMsg != null)
|
|
{
|
|
break;
|
|
}
|
|
crmRes = new CSuccessResponseMessage(null, i_crmInput);
|
|
}
|
|
while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.DBLog(Util.GetLastExceptionMsg(ex));
|
|
sMsg = $"{nameof(SetShoppingPoints)} unknwon exception. Call from).";
|
|
|
|
#if DEBUG
|
|
System.Diagnostics.Debug.WriteLine(sMsg);
|
|
#endif
|
|
|
|
}
|
|
|
|
if (sMsg != null)
|
|
{
|
|
crmRes = new CErrorResponseMessage(sMsg);
|
|
Logger.Error(JsonConvert.SerializeObject(i_crmInput));
|
|
Logger.Error(JsonConvert.SerializeObject(crmRes));
|
|
}
|
|
else
|
|
{
|
|
//Logger.Info(JsonConvert.SerializeObject(i_crmInput));
|
|
//Logger.Info(JsonConvert.SerializeObject(crmRes));
|
|
}
|
|
|
|
return crmRes;
|
|
}
|
|
class ShoppingPointsModel : tb_meb_shopping_points_record
|
|
{
|
|
public string name { get; set; }
|
|
}
|
|
[Auth(false)]
|
|
public CResponseMessage GetShoppingPoints(CRequestMessage i_crmInput)
|
|
{
|
|
CResponseMessage crmRes = null;
|
|
string sMsg = null;
|
|
Command cRes = null;
|
|
|
|
try
|
|
{
|
|
do
|
|
{
|
|
Dictionary<string, object> dicObjCondition = GetQueryMasterFirstWhereData(i_crmInput);
|
|
string[] aMember = null;
|
|
string group_user_id = null;
|
|
string group_id = null;
|
|
if (dicObjCondition.ContainsKey(tb_meb_shopping_points_record.CN_MEMBER_UID))
|
|
{
|
|
var jaMember = dicObjCondition[tb_meb_shopping_points_record.CN_MEMBER_UID] as JArray;
|
|
aMember = jaMember.Select(x => x.ToString()).ToArray();
|
|
}
|
|
else if (dicObjCondition.ContainsKey(tb_meb_member.CN_GROUP_USER_ID))
|
|
{
|
|
group_user_id = dicObjCondition[tb_meb_member.CN_GROUP_USER_ID].ToString();
|
|
group_id = dicObjCondition[tb_meb_member.CN_GROUP_ID].ToString();
|
|
}
|
|
else
|
|
{
|
|
sMsg = "參數錯誤";
|
|
break;
|
|
}
|
|
QueryJsonElementCollection lBlocks = new QueryJsonElementCollection();
|
|
QueryJsonElement qjeMember = lBlocks.GetInst();
|
|
qjeMember.table = tb_meb_member.TABLENAME;
|
|
qjeMember.displaycols = new List<string>() {
|
|
tb_meb_member.CN_UID,
|
|
tb_meb_member.CN_NAME,
|
|
tb_meb_member.CN_SHOPPING_ACCOUNT,
|
|
};
|
|
if (aMember != null)
|
|
{
|
|
qjeMember.wherecols = new WhereNode(tb_meb_member.CN_UID, WhereNode.EColumnOperation.EOT_IN, typeof(tb_meb_member), aMember);
|
|
}
|
|
else if (group_user_id != null && group_id != null)
|
|
{
|
|
List<WhereNode> lswnMember = new List<WhereNode>();
|
|
lswnMember.Add(new WhereNode(tb_meb_member.CN_GROUP_USER_ID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_meb_member), group_user_id));
|
|
lswnMember.Add(new WhereNode(tb_meb_member.CN_GROUP_ID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_meb_member), group_id));
|
|
qjeMember.wherecols = new WhereNode(WhereNode.ENodeOperation.ENO_AND, lswnMember.ToArray());
|
|
}
|
|
lBlocks.Add(qjeMember);
|
|
|
|
sMsg = MakeSelectJoinByBlocks(lBlocks, out cRes);
|
|
ArsenalInterface ai = ArsenalDBMgr.GetInst(cRes, GetDefaultSystemColumnInfo());
|
|
List<tb_meb_member> qds = ai.RunQueryList<tb_meb_member>(cRes);
|
|
|
|
sMsg = GetLastErrorCode(cRes);
|
|
|
|
if (sMsg != null)
|
|
{
|
|
break;
|
|
}
|
|
crmRes = new CSuccessResponseMessage(null, i_crmInput);
|
|
crmRes.param.Add("data", qds);
|
|
}
|
|
while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.DBLog(Util.GetLastExceptionMsg(ex));
|
|
sMsg = $"{nameof(GetShoppingPoints)} unknwon exception. Call from).";
|
|
#if DEBUG
|
|
System.Diagnostics.Debug.WriteLine(sMsg);
|
|
#endif
|
|
}
|
|
|
|
if (sMsg != null)
|
|
{
|
|
crmRes = new CErrorResponseMessage(sMsg);
|
|
Logger.Error(JsonConvert.SerializeObject(i_crmInput));
|
|
Logger.Error(JsonConvert.SerializeObject(crmRes));
|
|
}
|
|
else
|
|
{
|
|
//Logger.Info(JsonConvert.SerializeObject(i_crmInput));
|
|
//Logger.Info(JsonConvert.SerializeObject(crmRes));
|
|
}
|
|
|
|
return crmRes;
|
|
}
|
|
public CResponseMessage UpdateShoppingPoints(CRequestMessage i_crmInput)
|
|
{
|
|
CResponseMessage crmRes = null;
|
|
string sMsg = null;
|
|
Command cRes = null;
|
|
|
|
try
|
|
{
|
|
do
|
|
{
|
|
sMsg = getCommonParameter(i_crmInput, BLWording.UPD_MASTER, out JArray jaDataArray, out tb_sys_session sUserSession);
|
|
if (sMsg != null)
|
|
{
|
|
break;
|
|
}
|
|
if (jaDataArray.Count != 1 || jaDataArray[0] == null)
|
|
{
|
|
sMsg = MessageWording.PARAM_NOT_EXPECTED;
|
|
break;
|
|
}
|
|
JObject joData = jaDataArray[0] as JObject;
|
|
|
|
Dictionary<string, object> dicData = joData[BLWording.WHEREDATA].ToObject<Dictionary<string, object>>();
|
|
string memberUid = dicData[tb_meb_member.CN_UID].ToString();
|
|
int type = Convert.ToInt32(dicData["type"]);
|
|
int amount = type == 0 ? Convert.ToInt32(dicData[tb_meb_shopping_points_record.CN_AMOUNT]) : -Convert.ToInt32(dicData[tb_meb_shopping_points_record.CN_AMOUNT]);
|
|
string memo = dicData[tb_meb_shopping_points_record.CN_MEMO].ToString();
|
|
|
|
tb_meb_member cMember = new tb_meb_member();
|
|
cMember.SetDirty(tb_meb_member.CN_SHOPPING_ACCOUNT);
|
|
tb_meb_member cCon = new tb_meb_member()
|
|
{
|
|
uid = memberUid
|
|
};
|
|
Command cSelect = Command.SetupSelectCmd(cMember, cCon);
|
|
ArsenalInterface ai = ArsenalDBMgr.GetInst(cSelect);
|
|
List<tb_meb_member> qdsMember = ai.RunQueryList<tb_meb_member>(cSelect);
|
|
|
|
List<Command> lCmdUpdate = new List<Command>();
|
|
string sNewArticleUid = Guid.NewGuid().ToString();
|
|
|
|
tb_meb_shopping_points_record mNew = new tb_meb_shopping_points_record() { };
|
|
mNew.uid = sNewArticleUid;
|
|
mNew.member_uid = memberUid;
|
|
mNew.amount = amount;
|
|
mNew.memo = string.IsNullOrEmpty(memo) ? null : memo;
|
|
lCmdUpdate.Add(Command.SetupInsertCmd(mNew));
|
|
// 更新member shopping_account
|
|
if (qdsMember[0].shopping_account + amount < 0)
|
|
{
|
|
sMsg = "購物金不得小於0";
|
|
break;
|
|
}
|
|
lCmdUpdate.Add(Command.SetupUpdateCmd(new tb_meb_member()
|
|
{
|
|
shopping_account = qdsMember[0].shopping_account + amount
|
|
}
|
|
, new tb_meb_member() { uid = memberUid }));
|
|
|
|
ai = ArsenalDBMgr.GetInst(lCmdUpdate[0], GetDefaultSystemColumnInfo());
|
|
ai.RunEditCmds(lCmdUpdate);
|
|
sMsg = GetLastErrorCode(lCmdUpdate);
|
|
|
|
if (sMsg != null)
|
|
{
|
|
break;
|
|
}
|
|
crmRes = new CSuccessResponseMessage(null, i_crmInput);
|
|
}
|
|
while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.DBLog(Util.GetLastExceptionMsg(ex));
|
|
sMsg = $"{nameof(UpdateShoppingPoints)} unknwon exception. Call from).";
|
|
#if DEBUG
|
|
System.Diagnostics.Debug.WriteLine(sMsg);
|
|
#endif
|
|
}
|
|
|
|
if (sMsg != null)
|
|
{
|
|
crmRes = new CErrorResponseMessage(sMsg);
|
|
Logger.Error(JsonConvert.SerializeObject(i_crmInput));
|
|
Logger.Error(JsonConvert.SerializeObject(crmRes));
|
|
}
|
|
else
|
|
{
|
|
//Logger.Info(JsonConvert.SerializeObject(i_crmInput));
|
|
//Logger.Info(JsonConvert.SerializeObject(crmRes));
|
|
}
|
|
|
|
return crmRes;
|
|
}
|
|
public CResponseMessage ResetReturnCount(CRequestMessage i_crmInput)
|
|
{
|
|
CResponseMessage crmRes = null;
|
|
string sMsg = null;
|
|
try
|
|
{
|
|
do
|
|
{
|
|
tb_meb_member dicData = new tb_meb_member();
|
|
|
|
if (i_crmInput != null && i_crmInput.param != null && i_crmInput.param.ContainsKey(BLWording.UPD_MASTER))
|
|
{
|
|
JArray joData = i_crmInput.param[BLWording.UPD_MASTER] as JArray;
|
|
|
|
if (joData.Any())
|
|
{
|
|
dicData = joData[0][BLWording.WHEREDATA].ToObject<tb_meb_member>();
|
|
}
|
|
}
|
|
|
|
|
|
Command cCmd = Command.SetupUpdateCmd(new tb_meb_member()
|
|
{
|
|
return_count = 0
|
|
}
|
|
, new tb_meb_member() { uid = dicData.uid });
|
|
|
|
ArsenalInterface ai = ArsenalDBMgr.GetInst(cCmd, GetDefaultSystemColumnInfo());
|
|
ai.RunEditSingleCmd(cCmd);
|
|
string sErrorCode = GetLastErrorCode(cCmd);
|
|
|
|
if (sErrorCode != null)
|
|
{
|
|
sMsg = sErrorCode;
|
|
}
|
|
|
|
if (sMsg != null)
|
|
{
|
|
break;
|
|
}
|
|
crmRes = new CSuccessResponseMessage(null, i_crmInput);
|
|
}
|
|
while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.DBLog(Util.GetLastExceptionMsg(ex));
|
|
sMsg = $"{nameof(ResetReturnCount)} unknwon exception. Call from).";
|
|
|
|
#if DEBUG
|
|
System.Diagnostics.Debug.WriteLine(sMsg);
|
|
#endif
|
|
|
|
}
|
|
|
|
if (sMsg != null)
|
|
{
|
|
crmRes = new CErrorResponseMessage(sMsg);
|
|
Logger.Error(JsonConvert.SerializeObject(i_crmInput));
|
|
Logger.Error(JsonConvert.SerializeObject(crmRes));
|
|
}
|
|
else
|
|
{
|
|
//Logger.Info(JsonConvert.SerializeObject(i_crmInput));
|
|
//Logger.Info(JsonConvert.SerializeObject(crmRes));
|
|
}
|
|
|
|
return crmRes;
|
|
}
|
|
[Auth(false)]
|
|
public CResponseMessage VerifyFirebaseToken(CRequestMessage i_crmInput)
|
|
{
|
|
string sMsg = null;
|
|
CResponseMessage crmRes = null;
|
|
try
|
|
{
|
|
do
|
|
{
|
|
sMsg = getCommonParameter(i_crmInput, BLWording.QRY_MASTER, out JArray jaDataArray, out tb_sys_session sUserSession);
|
|
if (sMsg != null)
|
|
{
|
|
break;
|
|
}
|
|
if (jaDataArray.Count != 1 || jaDataArray[0] == null)
|
|
{
|
|
sMsg = MessageWording.PARAM_NOT_EXPECTED;
|
|
break;
|
|
}
|
|
|
|
JObject joData = jaDataArray[0][BLWording.WHEREDATA] as JObject;
|
|
Dictionary<string, object> dicData = new Dictionary<string, object>();
|
|
|
|
if (joData != null)
|
|
{
|
|
dicData = joData.ToObject<Dictionary<string, object>>();
|
|
}
|
|
string firebaseToken = dicData[tb_meb_member.CN_FIREBASE_TOKEN].ToString();
|
|
string group_id = dicData[tb_meb_member.CN_GROUP_ID].ToString();
|
|
string asid = dicData[tb_meb_member.CN_GROUP_USER_ID].ToString();
|
|
|
|
// 查詢Token
|
|
tb_meb_member cMember = new tb_meb_member();
|
|
cMember.SetFullDirty();
|
|
tb_meb_member cMemberCon = new tb_meb_member() { group_user_id = asid, group_id = group_id };
|
|
Command cMemberSelect = Command.SetupSelectCmd(cMember, cMemberCon);
|
|
ArsenalInterface ai = ArsenalDBMgr.GetInst(cMemberSelect);
|
|
tb_meb_member qdsMember = ai.RunQuerySingleORM<tb_meb_member>(cMemberSelect);
|
|
|
|
// 更新會員資料
|
|
List<Command> lCmdUpdate = new List<Command>();
|
|
|
|
if (qdsMember.firebase_token == null || firebaseToken != qdsMember.firebase_token)
|
|
{
|
|
// 更新
|
|
tb_meb_member mUpd = new tb_meb_member();
|
|
mUpd.firebase_token = firebaseToken;
|
|
List<WhereNode> lswnMain = new List<WhereNode>();
|
|
lswnMain.Add(new WhereNode(tb_meb_member.CN_GROUP_USER_ID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_meb_member), asid));
|
|
lswnMain.Add(new WhereNode(tb_meb_member.CN_GROUP_ID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_meb_member), group_id));
|
|
|
|
lCmdUpdate.Add(Command.SetupUpdateCmd(mUpd, new WhereNode(WhereNode.ENodeOperation.ENO_AND, lswnMain.ToArray())));
|
|
ai = ArsenalDBMgr.GetInst(lCmdUpdate[0], GetDefaultSystemColumnInfo());
|
|
ai.RunEditCmds(lCmdUpdate);
|
|
string sErrorCode = GetLastErrorCode(lCmdUpdate);
|
|
|
|
if (sErrorCode != null)
|
|
{
|
|
sMsg = sErrorCode;
|
|
}
|
|
|
|
if (sMsg != null)
|
|
{
|
|
sMsg = "已偵測裝置變更";
|
|
}
|
|
}
|
|
|
|
|
|
|
|
crmRes = new CSuccessResponseMessage(sMsg, i_crmInput);
|
|
}
|
|
while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sMsg = $"{nameof(VerifyFirebaseToken)} unknwon exception. i_crmInput={JsonConvert.SerializeObject(i_crmInput)}. ex={ex.Message}";
|
|
#if DEBUG
|
|
System.Diagnostics.Debug.WriteLine(sMsg);
|
|
#endif
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(sMsg))
|
|
{
|
|
//Logger.Info(JsonConvert.SerializeObject(i_crmInput));
|
|
//Logger.Info(JsonConvert.SerializeObject(crmRes));
|
|
}
|
|
else
|
|
{
|
|
crmRes = new CErrorResponseMessage(sMsg, i_crmInput);
|
|
Logger.Error(JsonConvert.SerializeObject(i_crmInput));
|
|
Logger.Error(JsonConvert.SerializeObject(crmRes));
|
|
}
|
|
return crmRes;
|
|
}
|
|
protected class tokenModel
|
|
{
|
|
public string group_id { get; set; }
|
|
public string code { get; set; }
|
|
public string redirect_uri { get; set; }
|
|
public string access_token { get; set; }
|
|
}
|
|
[Auth(false)]
|
|
public CResponseMessage GetAccessToken(CRequestMessage i_crmInput)
|
|
{
|
|
CResponseMessage crmRes = null;
|
|
string sMsg = null;
|
|
try
|
|
{
|
|
do
|
|
{
|
|
tokenModel dicData = new tokenModel();
|
|
tokenModel rawResult = null;
|
|
if (i_crmInput != null && i_crmInput.param != null && i_crmInput.param.ContainsKey(BLWording.UPD_MASTER))
|
|
{
|
|
JArray joData = i_crmInput.param[BLWording.UPD_MASTER] as JArray;
|
|
|
|
if (joData.Any())
|
|
{
|
|
dicData = joData[0][BLWording.WHEREDATA].ToObject<tokenModel>();
|
|
}
|
|
}
|
|
|
|
var groupData = GetGroupSettings(dicData.group_id);
|
|
|
|
string uri = string.Format("https://graph.facebook.com/v3.2/oauth/access_token?client_id={0}&redirect_uri={1}&code={2}&client_secret={3}", groupData.app_id, dicData.redirect_uri, dicData.code, groupData.client_secret);
|
|
APIHelper.BaseGet(uri, null, new Dictionary<string, string>(), out HttpResponseMessage responseMessage);
|
|
if (responseMessage.IsSuccessStatusCode)
|
|
{
|
|
rawResult = JsonConvert.DeserializeObject<tokenModel>(responseMessage.Content.ReadAsStringAsync().Result);
|
|
if (string.IsNullOrEmpty(rawResult.access_token))
|
|
{
|
|
sMsg = "獲取token失敗";
|
|
}
|
|
}
|
|
|
|
if (sMsg != null)
|
|
{
|
|
break;
|
|
}
|
|
crmRes = new CSuccessResponseMessage(null, i_crmInput);
|
|
crmRes.param.Add("access_token", rawResult.access_token);
|
|
}
|
|
while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.DBLog(Util.GetLastExceptionMsg(ex));
|
|
sMsg = $"{nameof(GetAccessToken)} unknwon exception. Call from).";
|
|
|
|
#if DEBUG
|
|
System.Diagnostics.Debug.WriteLine(sMsg);
|
|
#endif
|
|
|
|
}
|
|
|
|
if (sMsg != null)
|
|
{
|
|
crmRes = new CErrorResponseMessage(sMsg);
|
|
Logger.Error(JsonConvert.SerializeObject(i_crmInput));
|
|
Logger.Error(JsonConvert.SerializeObject(crmRes));
|
|
}
|
|
else
|
|
{
|
|
//Logger.Info(JsonConvert.SerializeObject(i_crmInput));
|
|
//Logger.Info(JsonConvert.SerializeObject(crmRes));
|
|
}
|
|
|
|
return crmRes;
|
|
}
|
|
protected class checkedTokenModel
|
|
{
|
|
public Data data { get; set; }
|
|
public class Data
|
|
{
|
|
public string user_id { get; set; }
|
|
public string app_id { get; set; }
|
|
public bool is_valid { get; set; }
|
|
}
|
|
}
|
|
[Auth(false)]
|
|
public CResponseMessage CheckAccessToken(CRequestMessage i_crmInput)
|
|
{
|
|
CResponseMessage crmRes = null;
|
|
string sMsg = null;
|
|
try
|
|
{
|
|
do
|
|
{
|
|
tokenModel dicData = new tokenModel();
|
|
checkedTokenModel rawResult = null;
|
|
if (i_crmInput != null && i_crmInput.param != null && i_crmInput.param.ContainsKey(BLWording.UPD_MASTER))
|
|
{
|
|
JArray joData = i_crmInput.param[BLWording.UPD_MASTER] as JArray;
|
|
|
|
if (joData.Any())
|
|
{
|
|
dicData = joData[0][BLWording.WHEREDATA].ToObject<tokenModel>();
|
|
}
|
|
}
|
|
var groupData = GetGroupSettings(dicData.group_id);
|
|
var result = GetAppToken(groupData.app_id, groupData.client_secret, out FbToken responseData);
|
|
|
|
string uri = string.Format("https://graph.facebook.com/debug_token?input_token={0}&access_token={1}", dicData.access_token, responseData.access_token);
|
|
APIHelper.BaseGet(uri, null, new Dictionary<string, string>(), out HttpResponseMessage responseMessage);
|
|
if (responseMessage.IsSuccessStatusCode)
|
|
{
|
|
rawResult = JsonConvert.DeserializeObject<checkedTokenModel>(responseMessage.Content.ReadAsStringAsync().Result);
|
|
if (!rawResult.data.is_valid)
|
|
{
|
|
sMsg = "驗證token失敗";
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
sMsg = "驗證token失敗";
|
|
break;
|
|
}
|
|
|
|
if (sMsg != null)
|
|
{
|
|
break;
|
|
}
|
|
crmRes = new CSuccessResponseMessage(null, i_crmInput);
|
|
}
|
|
while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.DBLog(Util.GetLastExceptionMsg(ex));
|
|
sMsg = $"{nameof(GetAccessToken)} unknwon exception. Call from).";
|
|
|
|
#if DEBUG
|
|
System.Diagnostics.Debug.WriteLine(sMsg);
|
|
#endif
|
|
|
|
}
|
|
|
|
if (sMsg != null)
|
|
{
|
|
crmRes = new CErrorResponseMessage(sMsg);
|
|
Logger.Error(JsonConvert.SerializeObject(i_crmInput));
|
|
Logger.Error(JsonConvert.SerializeObject(crmRes));
|
|
}
|
|
else
|
|
{
|
|
//Logger.Info(JsonConvert.SerializeObject(i_crmInput));
|
|
//Logger.Info(JsonConvert.SerializeObject(crmRes));
|
|
}
|
|
|
|
return crmRes;
|
|
}
|
|
|
|
public bool getPrivacy(string group_id,out string privacy)
|
|
{
|
|
var result = false;
|
|
|
|
privacy = null;
|
|
string sMsg = null;
|
|
|
|
QueryJsonElementCollection lBlocks = new QueryJsonElementCollection();
|
|
QueryJsonElement qjeGroups = lBlocks.GetInst();
|
|
qjeGroups.table = tb_grp_group.TABLENAME;
|
|
qjeGroups.wherecols = new WhereNode(tb_grp_group.CN_FB_GROUP_ID, WhereNode.EColumnOperation.EOT_EQ, typeof(tb_grp_group2user), group_id);
|
|
lBlocks.Add(qjeGroups);
|
|
|
|
QueryJsonElement qjeGroupUser = lBlocks.GetInst();
|
|
qjeGroupUser.table = tb_grp_group2user.TABLENAME;
|
|
qjeGroupUser.jointable = qjeGroups;
|
|
qjeGroupUser.displaycols = new List<string>() { tb_grp_group2user.CN_USER_TOKEN };
|
|
qjeGroupUser.jointype = QueryJsonElement.LEFT_JOIN;
|
|
qjeGroupUser.joincols = new Dictionary<string, string>() {
|
|
{ tb_grp_group2user.CN_GROUP_UID,tb_grp_group.CN_UID }};
|
|
|
|
|
|
lBlocks.Add(qjeGroupUser);
|
|
|
|
Command cRes = null;
|
|
sMsg = MakeSelectJoinByBlocks(lBlocks, out cRes);
|
|
ArsenalInterface ai = ArsenalDBMgr.GetInst(cRes);
|
|
tb_grp_group2user qdsGroups = ai.RunQuerySingleORM<tb_grp_group2user>(cRes);
|
|
|
|
if (qdsGroups != null)
|
|
{
|
|
|
|
var groupsInfo = GetPrivacy(group_id, qdsGroups.user_token);
|
|
privacy = groupsInfo.privacy;
|
|
result = true;
|
|
}
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
public Groups GetPrivacy(string group_id, string access_token)
|
|
{
|
|
Groups GroupInfo = null;
|
|
do
|
|
{
|
|
try
|
|
{
|
|
// 送出資料
|
|
string uri = $"https://graph.facebook.com/v8.0/{group_id}?";
|
|
var dicData = new Dictionary<string, string>()
|
|
{
|
|
{ "access_token",access_token},
|
|
{ "fields","privacy"}
|
|
};
|
|
APIHelper.BaseGet(uri, null, dicData, out HttpResponseMessage responseMessage);
|
|
if (responseMessage.IsSuccessStatusCode)
|
|
{
|
|
var fb_error = GetFbApiError(responseMessage);
|
|
|
|
if (!string.IsNullOrWhiteSpace(fb_error))
|
|
{
|
|
Logger.Error($"{nameof(GetPrivacy)} FB API response error message: {fb_error} ");
|
|
break;
|
|
}
|
|
GroupInfo = JsonConvert.DeserializeObject<Groups>(responseMessage.Content.ReadAsStringAsync().Result);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
throw ex;
|
|
}
|
|
} while (false);
|
|
return GroupInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private tb_grp_group GetGroupSettings(string group_id)
|
|
{
|
|
// 獲得該社團的token, app id, client secret
|
|
tb_grp_group cGroup = new tb_grp_group();
|
|
cGroup.SetDirty(tb_grp_group.CN_APP_ID, tb_grp_group.CN_PAGE_ID, tb_grp_group.CN_CLIENT_SECRET);
|
|
tb_grp_group cCon = new tb_grp_group() { fb_group_id = group_id };
|
|
Command cSelect = Command.SetupSelectCmd(cGroup, cCon);
|
|
ArsenalInterface ai2 = ArsenalDBMgr.GetInst(cSelect);
|
|
tb_grp_group qds2 = ai2.RunQuerySingleORM<tb_grp_group>(cSelect);
|
|
|
|
return qds2;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|