diff --git a/Controllers/ApiController.cs b/Controllers/ApiController.cs index 4bb35f6..8dde8cd 100644 --- a/Controllers/ApiController.cs +++ b/Controllers/ApiController.cs @@ -17,7 +17,6 @@ using System.Net.Http; using System.Net.Http.Headers; using Dapper.Contrib.Extensions; using System.IO; - using System.IO.Compression; using System.Threading; using System.Dynamic; @@ -39,6 +38,13 @@ using System.Diagnostics.Eventing.Reader; using static Journeys_WantHome.Controllers.AuthApiController; using SixLabors.ImageSharp.Memory; using Org.BouncyCastle.Utilities; +using Org.BouncyCastle.Bcpg.OpenPgp; +using NPOI.OpenXmlFormats.Dml.Chart; +using System.Collections; +using System.Formats.Asn1; +using Org.BouncyCastle.Ocsp; +using System.Drawing; +using System.Drawing.Imaging; namespace Journeys_WantHome.Controllers @@ -48,7 +54,7 @@ namespace Journeys_WantHome.Controllers public class ApiController : ControllerBase { private readonly IHttpContextAccessor _httpContextAccessor; - + DbConn dbConn = new DbConn(); SqlConnection conn = new SqlConnection(GlobalClass.appsettings("ConnectionStrings:SQLConnectionString")); SqlConnection elabConn = new SqlConnection(GlobalClass.appsettings("ConnectionStrings:ElabConnectionString")); @@ -59,6 +65,602 @@ namespace Journeys_WantHome.Controllers this._httpContextAccessor = httpContextAccessor; } + [Route("instagramData")] + public ActionResult InstagramPostData(IFormCollection obj) { + igDataResult ret = new igDataResult(); + + authToken token = new authToken(this._httpContextAccessor); + if (token.user_isLogin == false) + { + HttpContext.Response.Cookies.Delete("token_key"); + ret.ret = "no"; + ret.err_code = "99999"; + ret.message = "非登入狀態!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + string method = obj["method"].ToString(); + string instagram_uid = obj["instagram_uid"].ToString(); + + if (method == "post") + { + ret.list = conn.Query("select * from instagramDetail where instagramDetail_type='post' and instagram_uid = @instagram_uid", new { instagram_uid = instagram_uid }).ToList(); + } + else { + ret.list = conn.Query("select * from instagramDetail where instagramDetail_type='reels' and instagram_uid = @instagram_uid", new { instagram_uid = instagram_uid }).ToList(); + } + + ret.ret = "yes"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + [Route("instagramList")] + public ActionResult InstagramList(IFormCollection obj) { + igRankListResult ret = new igRankListResult(); + + authToken token = new authToken(this._httpContextAccessor); + if (token.user_isLogin == false) + { + HttpContext.Response.Cookies.Delete("token_key"); + ret.ret = "no"; + ret.err_code = "99999"; + ret.message = "非登入狀態!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + ret.list = conn.Query("select top 15 * from instagramKolView where instagram_revoke = 'N' order by instagram_fansNum desc ").ToList(); + ret.ret = "yes"; + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + [Route("igUpdateData")] + public ActionResult IgUpdateData(IFormCollection obj) { + normalResult ret = new normalResult(); + + string json_data = obj["json_data"].ToString(); + //json_data = json_data.Replace("\uFEFF", "").Replace("False","false"); + if (json_data == "") { + ret.ret = "no"; + ret.err_code = "0001"; + ret.message = "json_data沒有資料"; + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + dynamic igObject; + + try { + igObject = JsonConvert.DeserializeObject(json_data); + } catch (Exception e) + { + updateLog successLog = new updateLog(); + successLog.updateLog_text = "此Instagram 資料更新失敗 " + e.Message; + successLog.updateLog_kolMedia_uid = ""; + successLog.updateLog_kolMedia_accountName = ""; + successLog.updateLog_kolMedia_displayName = ""; + successLog.updateLog_kol_uid = ""; + successLog.updateLog_type = "Instagram"; + successLog.updateLog_result = "failed"; + successLog.updateLog_uid = ""; + + conn.Insert(successLog); + + ret.ret = "no"; + ret.err_code = "0002"; + ret.message = "json parse error : " + e.Message; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + string kolMedia_uid = igObject.kolMedia_uid; + string kol_uid = igObject.kol_uid; + + kolMedia objMedia = conn.QueryFirstOrDefault("select * from kolMedia where kolMedia_uid = @kolMedia_uid", new { kolMedia_uid = kolMedia_uid }); + + if (objMedia == null) + { + updateLog successLog = new updateLog(); + successLog.updateLog_text = "此Instagram (" + kolMedia_uid + ") 資料更新失敗,無此kolMedia_uid資料"; + successLog.updateLog_kolMedia_uid = kolMedia_uid; + successLog.updateLog_kolMedia_accountName = ""; + successLog.updateLog_kolMedia_displayName = "kol_uid = " + kol_uid; + successLog.updateLog_kol_uid = kol_uid; + successLog.updateLog_type = "Instagram"; + successLog.updateLog_result = "failed"; + successLog.updateLog_uid = ""; + + conn.Insert(successLog); + + ret.ret = "no"; + ret.err_code = "0001"; + ret.message = "無此kolMedia_uid資料! // " + json_data; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + conn.Execute("insert into schedule (schedule_type, schedule_log) values ('Instagram', '開始執行igUpdateData,執行對象kolMedia_uid=" + kolMedia_uid + "')", new { kolMedia_uid = kolMedia_uid }); + + try + { + objMedia.kolMedia_fansNum = (int)igObject.fans_count; + string pic_url = igObject.ig_pic; + instagram igClass = new instagram(); + List igList = new List(); + + string kolIgFileName = "igKol_" + DateTime.Now.ToString("yyyyMMdd") + "_" + GlobalClass.CreateRandomCode(16) + ".jpg"; + //string newFileName = "uid_" + GlobalClass.CreateRandomCode(16) + Path.GetExtension(originFileName); + string fullPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images/instagram/" + kolIgFileName); + + WebRequest wreq = WebRequest.Create(pic_url); + + HttpWebResponse wresp = (HttpWebResponse)wreq.GetResponse(); + Stream s = wresp.GetResponseStream(); + System.Drawing.Image img; + img = System.Drawing.Image.FromStream(s); + img.Save(fullPath, ImageFormat.Jpeg); + MemoryStream ms = new MemoryStream(); + img.Save(ms, ImageFormat.Jpeg); + img.Dispose(); + + + + igClass.instagram_uid = "ig_" + GlobalClass.CreateRandomCode(16); + igClass.instagram_name = igObject.ig_fullname; + igClass.kolMedia_uid = kolMedia_uid; + igClass.kol_uid = kol_uid; + igClass.instagram_pic = kolIgFileName; + igClass.instagram_fansNum = (int)igObject.fans_count; + igClass.instagram_followNum = (int)igObject.following_count; + + int postLikeNum = 0; + int postCommentNum = 0; + int reelViewCount = 0; + + foreach (var igObj in igObject.posts) { + + string postIgFileName = "igPost_" + kol_uid + "_" + DateTime.Now.ToString("yyyyMMdd") + "_" + GlobalClass.CreateRandomCode(16) + ".jpg"; + //string newFileName = "uid_" + GlobalClass.CreateRandomCode(16) + Path.GetExtension(originFileName); + string postfullPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images/instagram/" + postIgFileName); + string post_img_url = igObj.url; + WebRequest iwreq = WebRequest.Create(post_img_url); + + HttpWebResponse iwresp = (HttpWebResponse)iwreq.GetResponse(); + Stream s1 = iwresp.GetResponseStream(); + System.Drawing.Image img1; + img1 = System.Drawing.Image.FromStream(s1); + img1.Save(postfullPath, ImageFormat.Jpeg); + MemoryStream ms1 = new MemoryStream(); + img1.Save(ms1, ImageFormat.Jpeg); + img1.Dispose(); + + postLikeNum += (int)igObj.likes; + postCommentNum += (int)igObj.comments; + + instagramDetail newIg = new instagramDetail(); + newIg.instagram_uid = igClass.instagram_uid; + newIg.instagramDetail_type = "post"; + newIg.instagramDetail_title = igObj.title; + newIg.instagramDetail_photo = postIgFileName; + newIg.instagramDetail_shortcode = igObj.shortcode; + newIg.instagramDetail_date = igObj.date; + newIg.instagramDetail_likeNum = (int)igObj.likes; + newIg.instagramDetail_commentNum = (int)igObj.comments; + + if ((Boolean)igObj.is_pinned) + { + newIg.instagramDetail_ispinned = "Y"; + } + else + { + newIg.instagramDetail_ispinned = "N"; + } + + igList.Add(newIg); + } + + int reelsCount = 0; + foreach (var igObj in igObject.reels) + { + string postIgFileName = "igReels_" + kol_uid + "_" + DateTime.Now.ToString("yyyyMMdd") + "_" + GlobalClass.CreateRandomCode(16) + ".jpg"; + //string newFileName = "uid_" + GlobalClass.CreateRandomCode(16) + Path.GetExtension(originFileName); + string postfullPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images/instagram/" + postIgFileName); + string post_img_url = igObj.url; + WebRequest iwreq = WebRequest.Create(post_img_url); + + HttpWebResponse iwresp = (HttpWebResponse)iwreq.GetResponse(); + Stream s1 = iwresp.GetResponseStream(); + System.Drawing.Image img1; + img1 = System.Drawing.Image.FromStream(s1); + img1.Save(postfullPath, ImageFormat.Jpeg); + MemoryStream ms1 = new MemoryStream(); + img1.Save(ms1, ImageFormat.Jpeg); + img1.Dispose(); + + + reelViewCount += (int)igObj.video_view_count; + reelsCount++; + + instagramDetail newIg = new instagramDetail(); + newIg.instagram_uid = igClass.instagram_uid; + newIg.instagramDetail_type = "reels"; + newIg.instagramDetail_title = igObj.title; + newIg.instagramDetail_photo = postIgFileName; + newIg.instagramDetail_shortcode = igObj.shortcode; + newIg.instagramDetail_date = igObj.date; + newIg.instagramDetail_likeNum = (int)igObj.likes; + newIg.instagramDetail_commentNum = (int)igObj.comments; + newIg.instagramDetail_viewNum = (int)igObj.video_view_count; + + if ((Boolean)igObj.is_pinned) + { + newIg.instagramDetail_ispinned = "Y"; + } + else + { + newIg.instagramDetail_ispinned = "N"; + } + + igList.Add(newIg); + } + + if (postLikeNum < 0) + { + igClass.instagram_postActive = -1; + } + else { + igClass.instagram_postActive = (double)(postLikeNum + postCommentNum) / (double)igClass.instagram_fansNum; + } + + if (reelsCount > 0) + { + igClass.instagram_reelsActive = (double)reelViewCount / (double)reelsCount; + } + else { + igClass.instagram_reelsActive = -1; + } + + igClass.instagram_revoke = "N"; + + conn.Execute("update instagram set instagram_revoke = 'Y' where kol_uid = @kol_uid and kolMedia_uid = @kolMedia_uid", new { kol_uid = kol_uid, kolMedia_uid = kolMedia_uid }); + + + conn.Update(objMedia); + conn.Insert(igList); + conn.Insert(igClass); + + conn.Execute("insert into schedule (schedule_type, schedule_log) values ('Instagram', '執行完成,執行對象kolMedia_uid=" + kolMedia_uid + "')"); + + updateLog successLog = new updateLog(); + successLog.updateLog_text = "此Instagram (" + igClass.instagram_name + ") 資料更新成功"; + successLog.updateLog_kolMedia_uid = kolMedia_uid; + successLog.updateLog_kolMedia_accountName = ""; + successLog.updateLog_kolMedia_displayName = igClass.instagram_name; + successLog.updateLog_kol_uid = kol_uid; + successLog.updateLog_type = "Instagram"; + successLog.updateLog_result = "success"; + successLog.updateLog_uid = ""; + + conn.Insert(successLog); + + ret.ret = "yes"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + catch (Exception ex) { + + updateLog successLog = new updateLog(); + successLog.updateLog_text = "此Instagram (" + kolMedia_uid + ") 資料更新失敗 " + ex.Message; + successLog.updateLog_kolMedia_uid = kolMedia_uid; + successLog.updateLog_kolMedia_accountName = ""; + successLog.updateLog_kolMedia_displayName = "kol_uid = " + kol_uid; + successLog.updateLog_kol_uid = kol_uid; + successLog.updateLog_type = "Instagram"; + successLog.updateLog_result = "failed"; + successLog.updateLog_uid = ""; + + conn.Insert(successLog); + + ret.ret = "no"; + ret.err_code = "0003"; + ret.message = "資料更新錯誤 : " + ex.Message; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + + + ret.ret = "yes"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + [Route("igUpdateList")] + public ActionResult IgUpdateList(IFormCollection obj) + { + fbUpdateListResult ret = new fbUpdateListResult(); + + //撈出FB頻道清單 + List kolMedias = conn.Query("select A.* from kolMedia A, kol B where A.kol_uid = B.kol_uid and A.option_uid = 'media' and A.optionItem_uid = 'media002' order by A.kolMedia_sn desc ").ToList(); + + foreach (kolMedia media in kolMedias) + { + string overDate = DateTime.Now.AddDays(int.Parse(GlobalClass.appsettings("UpdateByDay")) * -1).ToString("yyyy/MM/dd HH:mm:ss"); + + updateLog objLog = conn.QueryFirstOrDefault("select * from updateLog where updateLog_type = 'Instagram' and updateLog_result = 'success' and updateLog_kol_uid = @kol_uid and updateLog_kolMedia_uid = @kolMedia_uid and updateLog_updateTime >= @overDate ", new { kol_uid = media.kol_uid, kolMedia_uid = media.kolMedia_uid, overDate = overDate }); + + if (objLog == null) + { + fbClass objNew = new fbClass(); + objNew.kolMedia_accountName = media.kolMedia_accountName; + objNew.kolMedia_uid = media.kolMedia_uid; + objNew.kolMedia_url = media.kolMedia_url; + objNew.kol_uid = media.kol_uid; + objNew.optionItem_uid = media.optionItem_uid; + ret.list.Add(objNew); + } + + } + + conn.Execute("insert into schedule (schedule_type, schedule_log) values ('Instagram', 'Server撈取清單')"); + + + ret.ret = "yes"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + [Route("facebookData")] + public ActionResult FacebookData(IFormCollection obj) + { + facebookDataResult ret = new facebookDataResult(); + authToken token = new authToken(this._httpContextAccessor); + if (token.user_isLogin == false) + { + HttpContext.Response.Cookies.Delete("token_key"); + ret.ret = "no"; + ret.err_code = "99999"; + ret.message = "非登入狀態!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + string facebook_uid = obj["facebook_uid"].ToString(); + + ret.list = conn.Query("select * from facebookDetail where facebook_uid = @facebook_uid", new { facebook_uid = facebook_uid }).ToList(); + ret.ret = "yes"; + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + [Route("facebookList")] + public ActionResult FacebookList() { + fbRankListResult ret = new fbRankListResult(); + + authToken token = new authToken(this._httpContextAccessor); + if (token.user_isLogin == false) + { + HttpContext.Response.Cookies.Delete("token_key"); + ret.ret = "no"; + ret.err_code = "99999"; + ret.message = "非登入狀態!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + ret.list = conn.Query("select top 15 * from facebookKolView where facebook_revoke = 'N' order by facebook_fansNum desc ").ToList(); + ret.ret = "yes"; + + ret.ret = "yes"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + [HttpGet] + [Route("fbUpdateData")] + public ActionResult FbUpdateData(string kol_uid, string kolMedia_uid, string fb_title, string fans_num, string json_data) { + normalResult ret = new normalResult(); + + kolMedia objMedia = conn.QueryFirstOrDefault("select * from kolMedia where kolMedia_uid = @kolMedia_uid", new { kolMedia_uid = kolMedia_uid }); + + if (objMedia == null) + { + ret.ret = "no"; + ret.err_code = "0001"; + ret.message = "無此kolMedia_uid資料!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + conn.Execute("insert into schedule (schedule_type, schedule_log) values ('Facebook', '開始執行fbUpdateData,執行對象kolMedia_uid=" + kolMedia_uid + "')", new { kolMedia_uid = kolMedia_uid }); + + try + { + int intFansNum = 0; + + fans_num = fans_num.Replace(",", "").Trim(); + + if (fans_num.IndexOf("萬") >= 0) + { + fans_num = fans_num.Replace("萬", ""); + + double fans_numf = double.Parse(fans_num); + + fans_num = (fans_numf * 10000).ToString(); + } + + + + try + { + intFansNum = int.Parse(fans_num); + } + catch (Exception ex) + { + conn.Execute("insert into schedule (schedule_type, schedule_log) values ('Facebook', '執行fbUpdateData facebookArray Json化發生錯誤,執行對象kolMedia_uid=" + kolMedia_uid + ", 錯誤訊息:" + ex.Message.Replace("'", "").Replace("\"", "") + "')", new { kolMedia_uid = kolMedia_uid, msg = ex.Message }); + + + updateLog failedLog = new updateLog(); + failedLog.updateLog_text = "此Facebook (" + fb_title + ") 資料更新失敗 (" + ex.Message + ")"; + failedLog.updateLog_kolMedia_uid = kolMedia_uid; + failedLog.updateLog_kolMedia_accountName = ""; + failedLog.updateLog_kolMedia_displayName = fb_title; + failedLog.updateLog_kol_uid = kol_uid; + failedLog.updateLog_type = "Facebook"; + failedLog.updateLog_result = "failed"; + failedLog.updateLog_uid = ""; + + conn.Insert(failedLog); + + ret.ret = "no"; + ret.err_code = "0002"; + ret.message = ex.Message; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + dynamic facebookArray; + + try + { + facebookArray = JsonConvert.DeserializeObject(json_data); + } + catch (Exception ex) + { + conn.Execute("insert into schedule (schedule_type, schedule_log) values ('Facebook', '執行fbUpdateData facebookArray Json化發生錯誤,執行對象kolMedia_uid=" + kolMedia_uid + ", 錯誤訊息:" + ex.Message.Replace("'", "").Replace("\"", "") + "')", new { kolMedia_uid = kolMedia_uid, msg = ex.Message }); + + updateLog failedLog = new updateLog(); + failedLog.updateLog_text = "此Facebook (" + fb_title + ") 資料更新失敗 (" + ex.Message + ")"; + failedLog.updateLog_kolMedia_uid = kolMedia_uid; + failedLog.updateLog_kolMedia_accountName = ""; + failedLog.updateLog_kolMedia_displayName = fb_title; + failedLog.updateLog_kol_uid = kol_uid; + failedLog.updateLog_type = "Facebook"; + failedLog.updateLog_result = "failed"; + failedLog.updateLog_uid = ""; + + conn.Insert(failedLog); + + ret.ret = "no"; + ret.err_code = "0003"; + ret.message = "json_data error : " + ex.Message; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + objMedia.kolMedia_fansNum = intFansNum; + + int totalLikeNum = 0; + int totalMsgNum = 0; + int totalShareNum = 0; + int totalCount = 0; + List fbList = new List(); + facebook fb = new facebook(); + fb.facebook_uid = "fb_" + GlobalClass.CreateRandomCode(24); + fb.facebook_fansNum = intFansNum; + fb.facebook_name = fb_title; + fb.kol_uid = kol_uid; + fb.kolMedia_uid = kolMedia_uid; + + foreach (var fbObj in facebookArray) + { + string like_num = fbObj.like_num; + string msg_num = fbObj.like_num; + string share_num = fbObj.share_num; + like_num = like_num.Replace(",", ""); + msg_num = msg_num.Replace(",", ""); + share_num = share_num.Replace(",", ""); + + totalLikeNum += int.Parse(like_num); + totalMsgNum += int.Parse(msg_num); + totalShareNum += int.Parse(share_num); + totalCount += totalLikeNum + totalMsgNum + totalShareNum; + + facebookDetail item = new facebookDetail(); + item.facebook_uid = fb.facebook_uid; + item.facebookDetail_publishedAt = (string)fbObj.fb_date; + item.facebookDetail_likeCount = int.Parse(like_num); + item.facebookDetail_msgCount = int.Parse(msg_num); + item.facebookDetail_shareCount = int.Parse(share_num); + + fbList.Add(item); + } + + double actionNum = (double)totalCount / (double)intFansNum; + fb.facebook_active = actionNum; + fb.facebook_5_likesNum = totalLikeNum; + fb.facebook_5_msgNum = totalMsgNum; + fb.facebook_5_shareNum = totalShareNum; + fb.facebook_revoke = "N"; + + conn.Execute("update facebook set facebook_revoke = 'Y' where kol_uid = @kol_uid and kolMedia_uid = @kolMedia_uid", new { kol_uid = kol_uid, kolMedia_uid = kolMedia_uid }); + + + conn.Update(objMedia); + conn.Insert(fbList); + conn.Insert(fb); + + conn.Execute("insert into schedule (schedule_type, schedule_log) values ('Facebook', '執行完成,執行對象kolMedia_uid=@kolMedia_uid')", new { kolMedia_uid = kolMedia_uid }); + + updateLog successLog = new updateLog(); + successLog.updateLog_text = "此Facebook (" + fb_title + ") 資料更新成功"; + successLog.updateLog_kolMedia_uid = kolMedia_uid; + successLog.updateLog_kolMedia_accountName = ""; + successLog.updateLog_kolMedia_displayName = fb_title; + successLog.updateLog_kol_uid = kol_uid; + successLog.updateLog_type = "Facebook"; + successLog.updateLog_result = "success"; + successLog.updateLog_uid = ""; + + conn.Insert(successLog); + + ret.ret = "yes"; + } + catch (Exception ex) { + conn.Execute("insert into schedule (schedule_type, schedule_log) values ('Facebook', '執行fbUpdateData facebookArray Json化發生錯誤,執行對象kolMedia_uid=" + kolMedia_uid + ", 錯誤訊息:" + ex.Message.Replace("'", "").Replace("\"", "") + "')", new { kolMedia_uid = kolMedia_uid, msg = ex.Message }); + + updateLog failedLog = new updateLog(); + failedLog.updateLog_text = "此Facebook (" + fb_title + ") 資料更新失敗 (" + ex.Message + ")"; + failedLog.updateLog_kolMedia_uid = kolMedia_uid; + failedLog.updateLog_kolMedia_accountName = ""; + failedLog.updateLog_kolMedia_displayName = fb_title; + failedLog.updateLog_kol_uid = kol_uid; + failedLog.updateLog_type = "Facebook"; + failedLog.updateLog_result = "failed"; + failedLog.updateLog_uid = ""; + + conn.Insert(failedLog); + + ret.ret = "no"; + ret.err_code = "0003"; + ret.message = "json_data error : " + ex.Message; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + [Route("fbUpdateList")] + public ActionResult FbUpdateList(IFormCollection obj) { + fbUpdateListResult ret = new fbUpdateListResult(); + + //撈出FB頻道清單 + List kolMedias = conn.Query("select A.* from kolMedia A, kol B where A.kol_uid = B.kol_uid and A.option_uid = 'media' and A.optionItem_uid = 'media001' ").ToList(); + + foreach (kolMedia media in kolMedias) { + string overDate = DateTime.Now.AddDays(int.Parse(GlobalClass.appsettings("UpdateByDay")) * -1).ToString("yyyy/MM/dd HH:mm:ss"); + + updateLog objLog = conn.QueryFirstOrDefault("select * from updateLog where updateLog_type = 'Facebook' and updateLog_result = 'success' and updateLog_kol_uid = @kol_uid and updateLog_kolMedia_uid = @kolMedia_uid and updateLog_updateTime >= @overDate ", new { kol_uid = media.kol_uid, kolMedia_uid = media.kolMedia_uid, overDate = overDate }); + + if (objLog == null) { + fbClass objNew = new fbClass(); + objNew.kolMedia_accountName = media.kolMedia_accountName; + objNew.kolMedia_uid = media.kolMedia_uid; + objNew.kolMedia_url = media.kolMedia_url; + objNew.kol_uid = media.kol_uid; + objNew.optionItem_uid = media.optionItem_uid; + ret.list.Add(objNew); + } + + } + + conn.Execute("insert into schedule (schedule_type, schedule_log) values ('Facebook', 'Server撈取清單')"); + + + ret.ret = "yes"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + [Route("youtubeData")] public ActionResult YoutubeData(IFormCollection obj) { youtubeDataResult ret = new youtubeDataResult(); @@ -137,7 +739,7 @@ namespace Journeys_WantHome.Controllers string project_uid = obj["project_uid"].ToString(); - project objProj = conn.QueryFirstOrDefault("select * from project where project_uid = @project_uid", new { project_uid = project_uid}); + project objProj = conn.QueryFirstOrDefault("select * from project where project_uid = @project_uid", new { project_uid = project_uid }); if (objProj != null) { @@ -148,7 +750,7 @@ namespace Journeys_WantHome.Controllers ret.ret = "no"; ret.err_code = "00001"; ret.message = "無此project_uid資料!"; - + } return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); } @@ -170,7 +772,7 @@ namespace Journeys_WantHome.Controllers List kolProjectViews = conn.Query("select * from kolProjectView where project_uid = @project_uid order by kol_uid, optionItem_order", new { project_uid = project_uid }).ToList(); - foreach (kolProjectView objView in kolProjectViews) + foreach (kolProjectView objView in kolProjectViews) { ret.detail.Add(new kolProjectViewDetail(objView)); } @@ -235,7 +837,7 @@ namespace Journeys_WantHome.Controllers ret.datas.Add(objItem); } - + ret.ret = "yes"; return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); } @@ -285,7 +887,7 @@ namespace Journeys_WantHome.Controllers conn.Execute("delete kolProjectImage where kolProject_uid = @kolProject_uid", new { kolProject_uid = kolProject_uid }); conn.Execute("delete kolProjectFile where kolProject_uid = @kolProject_uid", new { kolProject_uid = kolProject_uid }); conn.Execute("delete kolProject where kolProject_uid = @kolProject_uid", new { kolProject_uid = kolProject_uid }); - + ret.ret = "yes"; return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); @@ -424,7 +1026,7 @@ namespace Journeys_WantHome.Controllers dynamic kolProjectFileJsonObj; - try { + try { kolProjectFileJsonObj = JsonConvert.DeserializeObject(kolProjectFileArrayJson); } catch (Exception ex) @@ -434,7 +1036,7 @@ namespace Journeys_WantHome.Controllers ret.message = "kolProjectFile json error" + ex.Message; return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); } - + List kolProjectFiles = new List(); foreach (dynamic item in kolProjectFileJsonObj) @@ -543,7 +1145,7 @@ namespace Journeys_WantHome.Controllers kolCooperateTypes.Add(kct); } - foreach (string evaluate in kolProjectEvaluateArr) + foreach (string evaluate in kolProjectEvaluateArr) { if (evaluate != "") { kolProjectEvaluate kpe = new kolProjectEvaluate(); @@ -553,7 +1155,7 @@ namespace Journeys_WantHome.Controllers kpe.kolProjectEvaluate_text = evaluate; kolProjectEvaluates.Add(kpe); - } + } } dynamic kolProjectFileJsonObj; @@ -601,7 +1203,7 @@ namespace Journeys_WantHome.Controllers List kolProjectPrices = new List(); - foreach (dynamic item in kolProjectPriceJsonObj) { + foreach (dynamic item in kolProjectPriceJsonObj) { kolProjectPrice kpp = new kolProjectPrice(); kpp.kolProjectPrice_uid = "kpp_" + GlobalClass.CreateRandomCode(16); kpp.kolProject_uid = kolProject_uid; @@ -633,7 +1235,7 @@ namespace Journeys_WantHome.Controllers List kolProjectLinks = new List(); - foreach (dynamic item in kolProjectLinkJsonObj) { + foreach (dynamic item in kolProjectLinkJsonObj) { kolProjectLink kpl = new kolProjectLink(); kpl.kolProjectLink_uid = "kpl_" + GlobalClass.CreateRandomCode(16); kpl.kolProject_uid = kolProject_uid; @@ -660,7 +1262,7 @@ namespace Journeys_WantHome.Controllers List kolProjectImages = new List(); - foreach (dynamic item in kolProjectImageJsonObj) { + foreach (dynamic item in kolProjectImageJsonObj) { kolProjectImage kpi = new kolProjectImage(); kpi.kolProjectImage_uid = "kpi_" + GlobalClass.CreateRandomCode(16); kpi.kolProjectImage_photo = item.kolProjectImage_photo; @@ -678,7 +1280,7 @@ namespace Journeys_WantHome.Controllers conn.Insert(kolProjectLinks); conn.Insert(kolProjectImages); conn.Insert(kolProjectFiles); - + ret.data.kolProject = kp; ret.data.kolProjectEvaluates = kolProjectEvaluates; @@ -752,7 +1354,7 @@ namespace Journeys_WantHome.Controllers objFile.file_mimeType = file.ContentType; objFile.file_createdate = DateTime.Now; - + try { @@ -974,7 +1576,7 @@ namespace Journeys_WantHome.Controllers string quotation_serial = obj["quotation_serial"].ToString(); - files fil = prmConn.QueryFirstOrDefault("select * from files where file_target_uid = @quotation_serial and file_del = 'N'", new { quotation_serial = quotation_serial}); + files fil = prmConn.QueryFirstOrDefault("select * from files where file_target_uid = @quotation_serial and file_del = 'N'", new { quotation_serial = quotation_serial }); if (fil == null) { @@ -1004,7 +1606,7 @@ namespace Journeys_WantHome.Controllers if (token.user_isLogin == false) { HttpContext.Response.Cookies.Delete("token_key"); - + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); } @@ -1029,7 +1631,7 @@ namespace Journeys_WantHome.Controllers return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); } - [Route("projectAddEditDelGet")] + [Route("projectAddEditDelGet")] public ActionResult ProjectAddEditDelGet(IFormCollection obj) { projectResult ret = new projectResult(); @@ -1138,7 +1740,7 @@ namespace Journeys_WantHome.Controllers } project newProj = new project(); - + newProj.project_uid = project_uid; newProj.project_name = project_name; newProj.project_isPrm = project_isPrm; @@ -1159,7 +1761,7 @@ namespace Journeys_WantHome.Controllers } [Route("projectList")] - public ActionResult ProjectList(IFormCollection obj) { + public ActionResult ProjectList(IFormCollection obj) { projectListResult ret = new projectListResult(); authToken token = new authToken(this._httpContextAccessor); @@ -1229,10 +1831,10 @@ namespace Journeys_WantHome.Controllers //ret.projectList = projects; } - + ret.ret = "yes"; - + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); } @@ -1448,7 +2050,7 @@ namespace Journeys_WantHome.Controllers string kol_uid = obj["kol_uid"].ToString(); if (method == "del") { - conn.Execute("delete kol where kol_uid = @kol_uid", new { kol_uid = kol_uid}); + conn.Execute("delete kol where kol_uid = @kol_uid", new { kol_uid = kol_uid }); conn.Execute("delete kolMakeup where kol_uid = @kol_uid", new { kol_uid = kol_uid }); conn.Execute("delete kolStyle where kol_uid = @kol_uid", new { kol_uid = kol_uid }); conn.Execute("delete kolFansType where kol_uid = @kol_uid", new { kol_uid = kol_uid }); @@ -1527,7 +2129,7 @@ namespace Journeys_WantHome.Controllers return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); } - kol newKol = conn.QueryFirstOrDefault("select * from kol where kol_uid = @kol_uid", new { kol_uid = kol_uid}); + kol newKol = conn.QueryFirstOrDefault("select * from kol where kol_uid = @kol_uid", new { kol_uid = kol_uid }); //newKol.kol_uid = kol_uid; newKol.kol_name = kol_name; @@ -1607,8 +2209,8 @@ namespace Journeys_WantHome.Controllers foreach (string tag in kolTagArr) { tags tagData = conn.QueryFirstOrDefault("select * from tags where tag_uid = @tag_uid", new { tag_uid = tag }); - if (tagData != null) { - kolTag newKolTag = new kolTag(); + if (tagData != null) { + kolTag newKolTag = new kolTag(); newKolTag.kolTag_uid = "kt_" + GlobalClass.CreateRandomCode(12); newKolTag.kol_uid = kol_uid; newKolTag.tag_uid = tag; @@ -1648,7 +2250,7 @@ namespace Journeys_WantHome.Controllers medias.Add(mediaObj); } - conn.Execute("delete kolMakeup where kol_uid = @kol_uid", new { kol_uid = kol_uid}); + conn.Execute("delete kolMakeup where kol_uid = @kol_uid", new { kol_uid = kol_uid }); conn.Execute("delete kolStyle where kol_uid = @kol_uid", new { kol_uid = kol_uid }); conn.Execute("delete kolFansType where kol_uid = @kol_uid", new { kol_uid = kol_uid }); conn.Execute("delete kolMedia where kol_uid = @kol_uid", new { kol_uid = kol_uid }); @@ -1681,7 +2283,7 @@ namespace Journeys_WantHome.Controllers if (method == "add") { string err_msg = ""; - + if (kol_name == "") { err_msg = "請輸入KOL頻道名稱!\n"; } @@ -1700,7 +2302,7 @@ namespace Journeys_WantHome.Controllers kol newKol = new kol(); kol_uid = "kol_" + GlobalClass.CreateRandomCode(12); - + newKol.kol_uid = kol_uid; newKol.kol_name = kol_name; newKol.kol_descript = kol_descript; @@ -1748,18 +2350,18 @@ namespace Journeys_WantHome.Controllers { kolStyle styleObj = new kolStyle(); styleObj.kolStyle_uid = "ks_" + GlobalClass.CreateRandomCode(12); - styleObj.kol_uid= kol_uid; + styleObj.kol_uid = kol_uid; styleObj.option_uid = item.option_uid; - styleObj.optionItem_uid= item.optionItem_uid; + styleObj.optionItem_uid = item.optionItem_uid; kolStyles.Add(styleObj); } - + } string[] kolFansTypeArr = kolFansTypeStr.Split(","); List kolFansTypes = new List(); - foreach(string fansType in kolFansTypeArr) + foreach (string fansType in kolFansTypeArr) { optionItem item = conn.QueryFirstOrDefault("select * from optionItem where optionItem_ishide = 'N' and optionItem_uid = @optionItem_uid", new { optionItem_uid = fansType }); @@ -1792,7 +2394,7 @@ namespace Journeys_WantHome.Controllers dynamic mediaJsonObj; - try { + try { mediaJsonObj = JsonConvert.DeserializeObject(mediaArrayJson); } catch (Exception ex) { @@ -1838,16 +2440,16 @@ namespace Journeys_WantHome.Controllers ret.message = ex.Message; return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); } - - + + ret.ret = "yes"; return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); } - + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); } @@ -1877,11 +2479,11 @@ namespace Journeys_WantHome.Controllers string originFileName = file.FileName; - string newFileName = "avatar_" + GlobalClass.CreateRandomCode(8) + Path.GetExtension(originFileName); + string newFileName = "avatar_" + GlobalClass.CreateRandomCode(8) + Path.GetExtension(originFileName); string fullPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images/avatar/" + newFileName); try { - using (var stream = new FileStream(fullPath, FileMode.Create)) { + using (var stream = new FileStream(fullPath, FileMode.Create)) { file.CopyTo(stream); } @@ -1895,17 +2497,17 @@ namespace Journeys_WantHome.Controllers newFile.thumbnailUrl = "/images/avatar/" + newFileName; newFile.deleteUrl = "/images/avatar/" + newFileName; - + files.Add(newFile); fileResult obj = new fileResult(); obj.files = files; - - - + + + return Content(JsonConvert.SerializeObject(obj), "application/json;charset=utf-8"); } @@ -1943,7 +2545,7 @@ namespace Journeys_WantHome.Controllers return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); } - + string option_uid = obj["option_uid"].ToString(); @@ -1960,7 +2562,55 @@ namespace Journeys_WantHome.Controllers return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); } - + + } + + public class igDataResult { + public string ret { get; set; } = "no"; + public string err_code { get; set; } = "0000"; + public string message { get; set; } = ""; + + public List list = new List(); + } + + public class igRankListResult { + public string ret { get; set; } = "no"; + public string err_code { get; set; } = "0000"; + public string message { get; set; } = ""; + + public List list { get; set; } = new List(); + } + + public class facebookDataResult { + public string ret { get; set; } = "no"; + public string err_code { get; set; } = "0000"; + public string message { get; set; } = ""; + public List list = new List(); + } + public class fbRankListResult { + public string ret { get; set; } = "no"; + public string err_code { get; set; } = "0000"; + public string message { get; set; } = ""; + + public List list { get; set; } = new List(); + } + + public class fbUpdateListResult { + public string ret { get; set; } = "no"; + public string err_code { get; set; } = "0000"; + public string message { get; set; } = ""; + + public List list { get; set; } = new List(); + } + + public class fbClass + { + public string kol_uid { get; set; } = ""; + public string kolMedia_uid { get; set; } = ""; + public string optionItem_uid { get; set; } = ""; + public string kolMedia_url { get; set; } = ""; + public string kolMedia_accountName { get; set; } = ""; + } public class youtubeDataResult @@ -2097,4 +2747,11 @@ namespace Journeys_WantHome.Controllers public long size { get; set; } = 0; public string error { get; set; } = ""; } + + public class normalResult { + public string ret { get; set; } = ""; + public string err_code { get; set; } = ""; + public string message { get; set; } = ""; + } } + diff --git a/Journeys_WantHome.csproj b/Journeys_WantHome.csproj index bcef7d6..0682de2 100644 --- a/Journeys_WantHome.csproj +++ b/Journeys_WantHome.csproj @@ -43,6 +43,7 @@ + diff --git a/Models/DbTableClass.cs b/Models/DbTableClass.cs index c68ff55..f5be718 100644 --- a/Models/DbTableClass.cs +++ b/Models/DbTableClass.cs @@ -8,6 +8,130 @@ using Newtonsoft.Json.Linq; public class DbTableClass { + [Table("instagramKolView")] + public class instagramKolView + { + [JsonIgnore] + [Key] + public int instagram_sn { get; set; } + public string instagram_uid { get; set; } + public string kol_uid { get; set; } + public string kolMedia_uid { get; set; } + public string instagram_name { get; set; } + public string instagram_pic { get; set; } + public string instagram_revoke { get; set; } + public int instagram_fansNum { get; set; } + public int instagram_followNum { get; set; } + public double instagram_postActive { get; set; } + public double instagram_reelsActive { get; set; } + public DateTime instagram_updatedate { get; set; } + public string kolMedia_url { get; set; } + public string kol_photo { get; set; } + + } + + + + [Table("instagramDetail")] + public class instagramDetail + { + [JsonIgnore] + [Key] + public int instagramDetail_sn { get; set; } + public string instagram_uid { get; set; } = ""; + public string instagramDetail_type { get; set; } = ""; + public string instagramDetail_title { get; set; } = ""; + public string instagramDetail_photo { get; set; } = ""; + public string instagramDetail_shortcode { get; set; } = ""; + public string instagramDetail_date { get; set; } = ""; + public int instagramDetail_viewNum { get; set; } = 0; + public int instagramDetail_likeNum { get; set; } = 0; + public int instagramDetail_commentNum { get; set; } = 0; + public string instagramDetail_ispinned { get; set; } = "N"; + public DateTime instagramDetail_createdate { get; set; } = DateTime.Now; + } + + + + [Table("instagram")] + public class instagram + { + [JsonIgnore] + [Key] + public int instagram_sn { get; set; } + public string instagram_uid { get; set; } = ""; + public string kol_uid { get; set; } = ""; + public string kolMedia_uid { get; set; } = ""; + public string instagram_name { get; set; } = ""; + public string instagram_pic { get; set; } = ""; + public string instagram_revoke { get; set; } = "N"; + public int instagram_fansNum { get; set; } = 0; + public int instagram_followNum { get; set; } = 0; + public double instagram_postActive { get; set; } = 0.0; + public double instagram_reelsActive { get; set; } = 0.0; + public DateTime instagram_updatedate { get; set; } = DateTime.Now; + } + + + [Table("facebookKolView")] + public class facebookKolView + { + [JsonIgnore] + [Key] + public int facebook_sn { get; set; } + public string facebook_uid { get; set; } = ""; + public string kol_uid { get; set; } = ""; + public string kolMedia_uid { get; set; } = ""; + public string facebook_name { get; set; } = ""; + public string facebook_revoke { get; set; } = "N"; + public int facebook_fansNum { get; set; } = 0; + public int facebook_5_likesNum { get; set; } = 0; + public int facebook_5_msgNum { get; set; } = 0; + public int facebook_5_shareNum { get; set; } = 0; + public double facebook_active { get; set; } = 0.0; + public DateTime facebook_updatedate { get; set; } = DateTime.Now; + public string kol_name { get; set; } = ""; + public string kol_photo { get; set; } = ""; + public string kolMedia_url { get; set; } = ""; + } + + + + [Table("facebookDetail")] + public class facebookDetail + { + [JsonIgnore] + [Key] + public int facebookDetail_sn { get; set; } + public string facebook_uid { get; set; } = ""; + public string facebookDetail_publishedAt { get; set; } = ""; + public int facebookDetail_likeCount { get; set; } = 0; + public int facebookDetail_msgCount { get; set; } = 0; + public int facebookDetail_shareCount { get; set; } = 0; + public DateTime facebookDetail_createdate { get; set; } =DateTime.Now; + } + + [Table("facebook")] + public class facebook + { + [JsonIgnore] + [Key] + public int facebook_sn { get; set; } + public string facebook_uid { get; set; } = ""; + public string kol_uid { get; set; } = ""; + public string kolMedia_uid { get; set; } = ""; + public string facebook_name { get; set; } = ""; + public string facebook_revoke { get; set; } = "N"; + public int facebook_fansNum { get; set; } = 0; + public int facebook_5_likesNum { get; set; } = 0; + public int facebook_5_msgNum { get; set; } = 0; + public int facebook_5_shareNum { get; set; } = 0; + public double facebook_active { get; set; } = 0.0; + public DateTime facebook_updatedate { get; set; } = DateTime.Now; + } + + + [Table("youtubeDetail")] public class youtubeDetail { diff --git a/Models/youtubeUpdateClass.cs b/Models/youtubeUpdateClass.cs index 397aae9..76c3fed 100644 --- a/Models/youtubeUpdateClass.cs +++ b/Models/youtubeUpdateClass.cs @@ -29,7 +29,7 @@ public class youtubeUpdateClass : IHostedService, IDisposable { _timer = new Timer(DoWork, null, TimeSpan.Zero, - TimeSpan.FromSeconds(5 * 60)); + TimeSpan.FromSeconds(15 * 60)); return Task.CompletedTask; } diff --git a/Views/Home/Dashboard.cshtml b/Views/Home/Dashboard.cshtml index cebb543..5a0cd08 100644 --- a/Views/Home/Dashboard.cshtml +++ b/Views/Home/Dashboard.cshtml @@ -46,6 +46,9 @@
+ +
+
@@ -80,4 +83,64 @@ - \ No newline at end of file + + +
+ +
+ +
+ +
diff --git a/Views/Home/KolList.cshtml b/Views/Home/KolList.cshtml index 6104de1..53fd2a7 100644 --- a/Views/Home/KolList.cshtml +++ b/Views/Home/KolList.cshtml @@ -338,7 +338,7 @@
- +
diff --git a/Views/Home/ProjectList.cshtml b/Views/Home/ProjectList.cshtml index d9494cf..03d053a 100644 --- a/Views/Home/ProjectList.cshtml +++ b/Views/Home/ProjectList.cshtml @@ -106,13 +106,13 @@
- +
- +
- +
diff --git a/wwwroot/assets/javascript/custom/dashboard.js b/wwwroot/assets/javascript/custom/dashboard.js index 019eda1..69b0cac 100644 --- a/wwwroot/assets/javascript/custom/dashboard.js +++ b/wwwroot/assets/javascript/custom/dashboard.js @@ -2,8 +2,217 @@ $(document).ready(function () { loadYoutubeCard(); + loadFacebookCard(); + loadInstagramCard(); }); +function loadInstagramCard() { + $.ajax({ + url: "/Api/instagramList", + type: "post", + data: null, + success: function (data, textStatus, jqXHR) { + if (data.ret == "yes") { + var obj = data.list; + $('#card_group2').append(instagramCardHtml(obj)); + + + + + } else { + alert(data.message); + + if (data.err_code == "99999") { + location.href = "/Root/Login"; + } + } + }, + error: function (jqXHR, textStatus, errorThrown) { + alert('網路或伺服器發生錯誤,請稍後重試!'); + } + }); +} + +function instagramCardHtml(objItem) { + var html = ""; + html += ""; + html += "
"; + html += " "; + html += "
"; + html += " "; + html += "
"; + html += " "; + html += "
"; + html += " Instagram 排行 "; + html += "
"; + html += "
"; + html += "
"; + html += "
"; + html += " "; + html += "
"; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + + $.each(objItem, function (index, item) { + html += instagramSubHtml(item); + }); + + html += " "; + html += "
名稱 粉絲數 貼文互動數(近6) Reels預估觀看數 更新日期
"; + html += "
"; + html += " "; + html += "
"; + html += "
"; + html += "
"; + html += "
"; + + return html; +} + +function instagramSubHtml(item) { + var html = ""; + + var decimal = item.instagram_postActive; + var postPercent = (decimal * 100).toFixed(2) + "%"; + + var avgView = item.instagram_reelsActive.toFixed(0); + + var publishdate = new Date(item.instagram_updatedate); + + html += " "; + html += " "; + html += " "; + html += "  "; + html += " " + item.instagram_name + ""; + html += " "; + html += " " + AppendComma(item.instagram_fansNum) + " "; + html += " " + postPercent + " "; + html += " " + AppendComma(avgView) + " "; + html += " " + formatDate(publishdate, 'yyyy/MM/dd HH:mm:ss') + " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + + return html; +} + +function loadFacebookCard() { + $.ajax({ + url: "/Api/facebookList", + type: "post", + data: null, + success: function (data, textStatus, jqXHR) { + if (data.ret == "yes") { + var obj = data.list; + $('#card_group').append(facebookCardHtml(obj)); + + + + + } else { + alert(data.message); + + if (data.err_code == "99999") { + location.href = "/Root/Login"; + } + } + }, + error: function (jqXHR, textStatus, errorThrown) { + alert('網路或伺服器發生錯誤,請稍後重試!'); + } + }); +} + +function facebookCardHtml(objItem) { + var html = ""; + html += ""; + html += "
"; + html += " "; + html += "
"; + html += " "; + html += "
"; + html += " "; + html += "
"; + html += " Facebook 排行 "; + html += "
"; + html += "
"; + html += "
"; + html += "
"; + html += " "; + html += "
"; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + html += " "; + + $.each(objItem, function (index, item) { + html += facebookSubHtml(item); + }); + + html += " "; + html += "
名稱 追蹤者數 互動數(近5) 資料更新日期
"; + html += "
"; + html += " "; + html += "
"; + html += "
"; + html += "
"; + html += "
"; + + return html; +} + +function facebookSubHtml(item) { + var html = ""; + + var decimal = item.facebook_active; + var percent = (decimal * 100).toFixed(2) + "%"; + var publishdate = new Date(item.facebook_updatedate); + + html += " "; + html += " "; + html += " "; + html += "  "; + html += " " + item.facebook_name + ""; + html += " "; + html += " " + AppendComma(item.facebook_fansNum) + " "; + html += " " + percent + " "; + html += " " + formatDate(publishdate, 'yyyy/MM/dd HH:mm:ss') + " "; + html += " "; + html += " "; + html += " "; + html += " "; + + return html; +} + + function loadYoutubeCard() { $.ajax({ url: "/Api/youtubeList", @@ -54,9 +263,10 @@ function youtubeCardHtml(objItem) { html += " "; html += " "; html += " 頻道名稱 "; - html += " 帳號 "; + html += " 訂閱數 "; html += " 平均觀看數(近5) "; + html += " 資料更新日期 "; html += " "; html += " "; html += " "; @@ -89,9 +299,10 @@ function youtubeSubHtml(item) { html += "  "; html += " " + item.youtube_name + ""; html += " "; - html += " " + item.youtube_account + " "; + html += " " + AppendComma(item.youtube_subscriberCount) + " "; html += " " + AppendComma(item.youtube_avgViewCount) + " "; + html += " " + (new Date(item.youtube_updateTime)).format("yyyy/MM/dd hh:mm:ss") + " "; html += " "; html += " "; html += " "; @@ -100,6 +311,312 @@ function youtubeSubHtml(item) { return html; } +function instagramBtnClick(obj) { + var dataUid = obj.getAttribute('data-uid'); + var dataType = obj.getAttribute('data-method'); + + if (dataType == 'post') { + var trList = $("#instagramPost_layout").find(".masonry-item"); + $.each(trList, function (index, item) { + $(item).remove(); + }); + + var formData = { + instagram_uid: dataUid, + method: 'post' + } + + $.ajax({ + url: "/Api/instagramData", + type: "post", + data: formData, + success: function (data, textStatus, jqXHR) { + if (data.ret == "yes") { + var obj = data.list; + + var html = ""; + + $.each(obj, function (index, item) { + html += instagramPostModalHtml(item); + }); + + $('#instagramPost_layout').append(html); + + $('#InstagramPostModal').modal('toggle'); + + + } else { + alert(data.message); + + if (data.err_code == "99999") { + location.href = "/Root/Login"; + } + } + }, + error: function (jqXHR, textStatus, errorThrown) { + alert('網路或伺服器發生錯誤,請稍後重試!'); + } + }); + } + + if (dataType == 'reels') { + var trList = $("#instagramPost_layout").find(".masonry-item"); + $.each(trList, function (index, item) { + $(item).remove(); + }); + + var formData = { + instagram_uid: dataUid, + method: 'reels' + } + + $.ajax({ + url: "/Api/instagramData", + type: "reels", + data: formData, + success: function (data, textStatus, jqXHR) { + if (data.ret == "yes") { + var obj = data.list; + + var html = ""; + + $.each(obj, function (index, item) { + html += instagramReelsModalHtml(item); + }); + + $('#instagramPost_layout').append(html); + + $('#InstagramPostModal').modal('toggle'); + + + } else { + alert(data.message); + + if (data.err_code == "99999") { + location.href = "/Root/Login"; + } + } + }, + error: function (jqXHR, textStatus, errorThrown) { + alert('網路或伺服器發生錯誤,請稍後重試!'); + } + }); + } +} + +function instagramReelsModalHtml(obj) { + + + + var html = ""; + html += ""; + html += "
"; + html += " "; + html += "
"; + html += " "; + html += " "; + html += " "; + html += "
"; + html += " "; + html += "
"; + html += " "; + html += "
"; + html += "
"; + html += " " + obj.instagramDetail_title + ""; + html += "
"; + html += "
" + obj.instagramDetail_date + "
"; + html += "
"; + html += " "; + html += "
"; + html += " "; + html += "
"; + + html += " "; + html += "
"; + html += " "; + html += "
"; + html += "
" + AppendComma(obj.instagramDetail_viewNum) + "
"; + html += "

觀看數

"; + html += "
"; + html += "
"; + html += " "; + html += "
"; + html += " "; + html += "
"; + html += "
" + AppendComma(obj.instagramDetail_commentNum) + "
"; + html += "

留言數

"; + html += "
"; + html += "
"; + html += "
"; + html += "
"; + html += "
"; + html += "
"; + + return html; +} + +function instagramPostModalHtml(obj) { + + + + var html = ""; + html += ""; + html += "
"; + html += " "; + html += "
"; + html += " "; + html += " "; + html += " "; + html += "
"; + html += " "; + html += "
"; + html += " "; + html += "
"; + html += "
"; + html += " " + obj.instagramDetail_title + ""; + html += "
"; + html += "
" + obj.instagramDetail_date + "
"; + html += "
"; + html += " "; + html += "
"; + html += " "; + html += "
"; + + html += " "; + html += "
"; + html += " "; + html += "
"; + html += "
" + AppendComma(obj.instagramDetail_likeNum) + "
"; + html += "

喜歡數

"; + html += "
"; + html += "
"; + html += " "; + html += "
"; + html += " "; + html += "
"; + html += "
" + AppendComma(obj.instagramDetail_commentNum) + "
"; + html += "

留言數

"; + html += "
"; + html += "
"; + html += "
"; + html += "
"; + html += "
"; + html += "
"; + + return html; +} +function facebookBtnClick(obj) { + var dataUid = obj.getAttribute('data-uid'); + + + var trList = $("#facebook_layout").find(".masonry-item"); + $.each(trList, function (index, item) { + $(item).remove(); + }); + + var formData = { + facebook_uid: dataUid + } + + $.ajax({ + url: "/Api/facebookData", + type: "post", + data: formData, + success: function (data, textStatus, jqXHR) { + if (data.ret == "yes") { + var obj = data.list; + + var html = ""; + + $.each(obj, function (index, item) { + html += facebookModalHtml(item); + }); + + $('#facebook_layout').append(html); + + $('#FacebookModal').modal('toggle'); + + + } else { + alert(data.message); + + if (data.err_code == "99999") { + location.href = "/Root/Login"; + } + } + }, + error: function (jqXHR, textStatus, errorThrown) { + alert('網路或伺服器發生錯誤,請稍後重試!'); + } + }); +} + +function facebookModalHtml(obj) { + + //var publishdate = new Date(obj.youtubeDetail_publishedAt); + + var html = ""; + html += ""; + html += "
"; + html += " "; + html += "
"; + //html += " "; + //html += " "; + //html += " "; + html += "
"; + html += " "; + html += "
"; + html += " "; + html += "
"; + // html += "
"; + //html += " " + obj.youtubeDetail_title + ""; + //html += "
"; + //html += "
" + obj.+ "
"; + html += "
"; + html += " "; + html += "
"; + html += " "; + html += "
"; + html += " "; + html += "
"; + html += " "; + html += "
"; + html += " " + obj.facebookDetail_publishedAt + " "; + html += "

貼文發布時間

"; + + html += "
"; + html += "
"; + html += " "; + html += "
"; + html += " "; + html += "
"; + html += "
" + AppendComma(obj.facebookDetail_likeCount) + "
"; + html += "

按讚數

"; + html += "
"; + html += "
"; + html += " "; + html += "
"; + html += " "; + html += "
"; + html += "
" + AppendComma(obj.facebookDetail_msgCount) + "
"; + html += "

留言數

"; + html += "
"; + html += "
"; + html += " "; + html += "
"; + html += " "; + html += "
"; + html += "
" + AppendComma(obj.facebookDetail_shareCount) + "
"; + html += "

分享數

"; + html += "
"; + html += "
"; + html += "
"; + html += "
"; + html += "
"; + html += "
"; + + return html; +} function youtubeBtnClick(obj) { var dataUid = obj.getAttribute('data-uid'); diff --git a/wwwroot/images/instagram/igKol_20240516_CSTI980X1H99GYLZ.jpg b/wwwroot/images/instagram/igKol_20240516_CSTI980X1H99GYLZ.jpg new file mode 100644 index 0000000..f1432df Binary files /dev/null and b/wwwroot/images/instagram/igKol_20240516_CSTI980X1H99GYLZ.jpg differ