diff --git a/Controllers/ApiController.cs b/Controllers/ApiController.cs index 4d86580..c96a0d6 100644 --- a/Controllers/ApiController.cs +++ b/Controllers/ApiController.cs @@ -56,6 +56,33 @@ namespace Journeys_WantHome.Controllers this._httpContextAccessor = httpContextAccessor; } + [Route("kolList")] + public ActionResult KolList(IFormCollection obj) { + kolListResult ret = new kolListResult(); + + 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"); + } + + List kols = conn.Query("select * from kol order by kol_modifydate desc").ToList(); + + foreach (kol kolItem in kols) + { + kolDetial objItem = new kolDetial(kolItem); + + ret.kolList.Add(objItem); + } + + ret.ret = "yes"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + [Route("kolAddEditDelGet")] public ActionResult kolAddEditDelGet(IFormCollection obj) { kolResult ret = new kolResult(); @@ -72,6 +99,37 @@ namespace Journeys_WantHome.Controllers string method = obj["method"].ToString(); 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 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 }); + conn.Execute("delete kolCooperateType where kol_uid = @kol_uid", new { kol_uid = kol_uid }); + + ret.ret = "yes"; + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + if (method == "get") + { + kol kolData = conn.QueryFirstOrDefault("select * from kol where kol_uid = @kol_uid", new { kol_uid = kol_uid }); + + if (kolData == null) + { + ret.ret = "no"; + ret.message = "找不到此kol_uid資料!"; + ret.err_code = "0003"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + ret.kol = new kolDetial(kolData); + ret.ret = "yes"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + string kol_name = obj["kol_name"].ToString(); string kol_descript = obj["kol_descript"].ToString(); string kol_contact1 = obj["kol_contact1"].ToString(); @@ -99,6 +157,163 @@ namespace Journeys_WantHome.Controllers return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); } + if (method == "edit") { + string err_msg = ""; + + if (kol_name == "") + { + err_msg = "請輸入KOL頻道名稱!\n"; + } + + if (kol_photo == "") + { + err_msg += "請選擇KOL的照片!\n"; + } + + if (err_msg != "") + { + ret.ret = "no"; + ret.err_code = "0002"; + ret.message = err_msg; + 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}); + + //newKol.kol_uid = kol_uid; + newKol.kol_name = kol_name; + newKol.kol_descript = kol_descript; + newKol.kol_photo = kol_photo; + newKol.kol_contact1 = kol_contact1; + newKol.kol_contact2 = kol_contact2; + newKol.kol_men_ratio = kol_men_ratio; + newKol.kol_women_ratio = kol_women_ratio; + newKol.kol_13_17 = kol_13_17; + newKol.kol_18_24 = kol_18_24; + newKol.kol_25_34 = kol_25_34; + newKol.kol_35_44 = kol_35_44; + newKol.kol_45_54 = kol_45_54; + newKol.kol_55_64 = kol_55_64; + newKol.kol_65 = kol_65; + newKol.kol_modifydate = DateTime.Now; + newKol.kol_modify_userId = token.user_id; + + string[] kolMakeupArr = kolMakeupStr.Split(','); + + List kolMakeups = new List(); + foreach (string makeup in kolMakeupArr) + { + optionItem item = conn.QueryFirstOrDefault("select * from optionItem where optionItem_ishide = 'N' and optionItem_uid = @optionItem_uid", new { optionItem_uid = makeup }); + + if (item != null) + { + kolMakeup makeupObj = new kolMakeup(); + makeupObj.kolMakeup_uid = "kmk_" + GlobalClass.CreateRandomCode(12); + makeupObj.kol_uid = kol_uid; + makeupObj.option_uid = item.option_uid; + makeupObj.optionItem_uid = item.optionItem_uid; + kolMakeups.Add(makeupObj); + } + } + + string[] kolStyleArr = kolStyleStr.Split(","); + + List kolStyles = new List(); + foreach (string style in kolStyleArr) + { + optionItem item = conn.QueryFirstOrDefault("select * from optionItem where optionItem_ishide = 'N' and optionItem_uid = @optionItem_uid", new { optionItem_uid = style }); + + if (item != null) + { + kolStyle styleObj = new kolStyle(); + styleObj.kolStyle_uid = "ks_" + GlobalClass.CreateRandomCode(12); + styleObj.kol_uid = kol_uid; + styleObj.option_uid = item.option_uid; + styleObj.optionItem_uid = item.optionItem_uid; + kolStyles.Add(styleObj); + } + + } + + string[] kolFansTypeArr = kolFansTypeStr.Split(","); + + List kolFansTypes = new List(); + 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 }); + + if (item != null) + { + kolFansType fansObj = new kolFansType(); + fansObj.kolFansType_uid = "kft_" + GlobalClass.CreateRandomCode(12); + fansObj.kol_uid = kol_uid; + fansObj.option_uid = item.option_uid; + fansObj.optionItem_uid = item.optionItem_uid; + kolFansTypes.Add(fansObj); + } + } + + dynamic mediaJsonObj; + + try + { + mediaJsonObj = JsonConvert.DeserializeObject(mediaArrayJson); + } + catch (Exception ex) + { + ret.ret = "no"; + ret.err_code = "0003"; + ret.message = "media json error" + ex.Message; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + List medias = new List(); + + foreach (dynamic item in mediaJsonObj) + { + kolMedia mediaObj = new kolMedia(); + + mediaObj.kolMedia_uid = "km_" + GlobalClass.CreateRandomCode(12); + mediaObj.kol_uid = kol_uid; + mediaObj.option_uid = item.option_uid; + mediaObj.optionItem_uid = item.optionItem_uid; + mediaObj.kolMedia_fansNum = int.Parse(item.kolMedia_fansNum.ToString()); + mediaObj.kolMedia_accountName = item.kolMedia_accountName; + mediaObj.kolMedia_displayName = item.kolMedia_displayName; + mediaObj.kolMedia_url = item.kolMedia_url; + + medias.Add(mediaObj); + } + + 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 }); + + conn.Insert(kolMakeups); + conn.Insert(kolStyles); + conn.Insert(kolFansTypes); + conn.Insert(medias); + + try + { + conn.Update(newKol); + conn.Close(); + + ret.kol = new kolDetial(kol_uid); + } + catch (Exception ex) + { + ret.ret = "no"; + ret.err_code = "1001"; + 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"); + } + if (method == "add") { string err_msg = ""; @@ -250,6 +465,8 @@ namespace Journeys_WantHome.Controllers return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); } + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); } @@ -364,6 +581,13 @@ namespace Journeys_WantHome.Controllers } + public class kolListResult { + public string ret { get; set; } = ""; + public string err_code { get; set; } = ""; + public string message { get; set; } = ""; + + public List kolList { get; set; } = new List(); + } public class kolResult { public string ret { get; set; } = ""; public string err_code { get; set; } = ""; diff --git a/Views/Home/KolList.cshtml b/Views/Home/KolList.cshtml index 39a3da7..597ff3c 100644 --- a/Views/Home/KolList.cshtml +++ b/Views/Home/KolList.cshtml @@ -38,9 +38,12 @@ + - + + + diff --git a/wwwroot/assets/javascript/custom/kollist.js b/wwwroot/assets/javascript/custom/kollist.js index 0ace63c..f169da1 100644 --- a/wwwroot/assets/javascript/custom/kollist.js +++ b/wwwroot/assets/javascript/custom/kollist.js @@ -1,7 +1,9 @@  var mediaTr; var delMedia; - +var mainTable; +var mainRowID; +var mainPos; $(document).ready(function () { delMedia = ''; @@ -9,7 +11,7 @@ $(document).ready(function () { loadKolMakeupCheckboxItem(); loadKolStyleCheckboxItem(); loadKolFansTypeCheckboxItem(); - + loadDataTable(); $('#kolSaveBtn').on('click', function () { var method = $('#method').val(); var kol_uid = $('#kol_uid').val(); @@ -91,6 +93,8 @@ $(document).ready(function () { return; } + mainTable = $('#dt-responsive').dataTable(); + var formData = { method: method, kol_uid: kol_uid, @@ -119,9 +123,18 @@ $(document).ready(function () { type: "post", data: formData, success: function (data, textStatus, jqXHR) { + var obj = data.kol; if (data.ret == "yes") { - + if (method == "add") { + mainTable.fnAddData(obj); + } + + if (method == "edit") { + mainTable.fnUpdate(obj, mainPos); + } + + $('#clientNewModal').modal('toggle'); } else { alert(data.message); @@ -225,6 +238,211 @@ $(document).ready(function () { $('#clientNewModal').modal('toggle'); }); + function loadDataTable() { + var dataTables = { + init: function init() { + + this.bindUIActions(); + }, + bindUIActions: function bindUIActions() { + + // event handlers + this.table = this.handleDataTables(); + + // add buttons + //this.table.buttons().container().appendTo('#dt-buttons').unwrap(); + }, + handleDataTables: function handleDataTables() { + //$('#myTable').append(""); + return $('#dt-responsive').DataTable({ + dom: '<\'text-muted\'Bif>\n <\'table-responsive\'trl>\n <\'mt-4\'p>', + lengthChange: true, + lengthMenu: [[25, 50, 100, -1], [25, 50, 100, "All"]], + pageLength: 25, + buttons: [ + //{ + // text: '休假設定', + // action: function (e, dt, node, config) { + // vacationBtnFun(); + + // } + //}, + //'excelHtml5' + ], + language: { + paginate: { + previous: '', + next: '' + }, + buttons: { + copyTitle: 'Data copied', + copyKeys: 'Use your keyboard or menu to select the copy command' + } + }, + autoWidth: false, + ajax: { + url: '/Api/kolList', + type: 'POST', + data: function (d) { + Object.assign(d, { + bar_area: $('#bar_area').val(), + is_lottery: $('#isLottery').val() + }); + + return d; + }, + dataSrc: 'kolList' + }, + rowId: 'kol_uid', + deferRender: true, + initComplete: function () { + $('#dt-responsive').on('click', 'a', function () { + buttonClick2(this); + }); + + $('#dt-responsive').on('click', 'button', function () { + buttonClick2(this); + }); + + $('#dt-responsive').on('click', 'input[name="selectedRow[]"]', function () { + checkboxClick(this); + }); + }, + order: [[5, 'desc']], + info: true, + search: "搜尋:", + searching: true, + columns: [{ data: 'kol_photo', className: 'align-middle', orderable: false, searchable: false }, + { data: 'kol_name', className: 'align-middle text-left', orderable: true, searchable: true }, + { data: 'kol_descript', className: 'align-middle text-left', orderable: true, searchable: true }, + { data: 'kol_contact1', className: 'align-middle text-left', orderable: false, searchable: true }, + { data: 'kol_contact2', className: 'align-middle text-left', orderable: false, searchable: true }, + { data: 'kol_modifydate', className: 'align-middle text-left', orderable: false, searchable: true }, + { data: 'kol_uid', className: 'align-middle text-center', orderable: false, searchable: false }], + columnDefs: [ + { + targets: 0, + className: 'align-middle text-center', + orderable: false, + searchable: false, + render: function render(data, type, row, meta) { + var ret = ''; + ret += '
'; + ret += ' '; + ret += '
'; + return ret; + //return row.gift_city + row.gift_area + row.gift_address; + //var editRet = ''; + + //if (row.quotationUser_perm == "A" || row.quotationUser_perm == "D" || row.quotationUser_perm == "admin" || row.quotationUser_perm == "pro") { + // editRet = editRet + ' '; + //} + //return editRet; + } + } + , { + targets: 2, + orderable: false, + searchable: false, + render: function render(data, type, row, meta) { + var ret = ''; + + $.each(row.makeups, function (key, value) { + ret += value.optionItem_name + '/'; + }); + + ret = ret.replace(/^\/+|\/+$/g, ''); + + return ret; + + //return '' + row.company_name + ''; + } + } + , { + targets: 5, + orderable: false, + searchable: false, + render: function render(data, type, row, meta) { + return (new Date(row.kol_modifydate)).format("yyyy/MM/dd hh:mm:ss"); + } + } + , { + targets: 6, + orderable: false, + searchable: false, + render: function render(data, type, row, meta) { + var ret = ''; + + ret += ''; + ret += ''; + return ret; + } + } + //, { + // targets: 2, + // orderable: false, + // searchable: false, + // render: function render(data, type, row, meta) { + // return row.company_serial; + // } + //}, { + // targets: 3, + // orderable: false, + // searchable: false, + // render: function render(data, type, row, meta) { + + // if (row.company_enabled == "Y") { + // return ''; + // } else { + // return ''; + // } + // } + //}, { + // targets: 4, + // orderable: false, + // searchable: false, + // render: function render(data, type, row, meta) { + // return (new Date(row.company_createdate)).format("yyyy/MM/dd hh:mm:ss"); + // } + //}, { + // targets: 5, + // orderable: false, + // searchable: false, + // render: function render(data, type, row, meta) { + // var editRet = ''; + + + // return editRet; + // } + //} + + ], + + }); + }, + handleSearchRecords: function handleSearchRecords() { + var self = this; + + $('#table-search, #filterBy').on('keyup change focus', function (e) { + var filterBy = $('#filterBy').val(); + var hasFilter = filterBy !== ''; + var value = $('#table-search').val(); + + self.table.search('').columns().search('').draw(); + + if (hasFilter) { + self.table.columns(filterBy).search(value).draw(); + } else { + self.table.search(value).draw(); + } + + }); + } + } + + dataTables.init(); + } + var url = "/Api/KolPhotoUpload"; @@ -262,8 +480,130 @@ $(document).ready(function () { $('#progress-avatar').removeClass('show').children().css('width', 0); }); // File upload using button // ============================================================= + + }); + +function buttonClick2(obj) { + var type = obj.getAttribute('data-method'); + var uid = obj.getAttribute('data-uid'); + + mainTable = $('#dt-responsive').dataTable(); + mainRowID = $('#' + uid); + + mainPos = mainTable.fnGetPosition($('#' + uid)[0]); + + if (type == "del") { + if (confirm('確定刪除此筆資料? 刪除後將無任何方法回復!')) { + var formData = { + method: "del", + kol_uid: uid + } + + $.ajax({ + url: "/Api/kolAddEditDelGet", + type: "post", + data: formData, + success: function (data, textStatus, jqXHR) { + if (data.ret == "yes") { + var row = mainTable.api().row(mainRowID).remove().draw(false); + alert('刪除完成!'); + + } else { + alert(data.message); + + if (data.err_code == "9999") { + location.href = "/Home/Index"; + } + } + }, + error: function (jqXHR, textStatus, errorThrown) { + alert('網路或伺服器發生錯誤,請稍後重試!'); + } + }); + } + } + + if (type == "edit") { + $('#method').val('edit'); + $('#kol_uid').val(uid); + + var formData = { + method: "get", + kol_uid: uid + } + + $.ajax({ + url: "/Api/kolAddEditDelGet", + type: "post", + data: formData, + success: function (data, textStatus, jqXHR) { + if (data.ret == "yes") { + cleanModalData(); + + var obj = data.kol; + $('#method').val('edit'); + $('#kol_uid').val(uid); + $('#kol_name').val(obj.kol_name).trigger('change'); + $('#kol_descript').val(obj.kol_descript).trigger('change'); + $('#kol_contact1').val(obj.kol_contact1).trigger('change'); + $('#kol_contact2').val(obj.kol_contact2).trigger('change'); + $('#kol_men_ratio').val(obj.kol_men_ratio).trigger('change'); + $('#kol_women_ratio').val(obj.kol_women_ratio).trigger('change'); + $('#kol_13_17').val(obj.kol_13_17).trigger('change'); + $('#kol_18_24').val(obj.kol_18_24).trigger('change'); + $('#kol_25_34').val(obj.kol_25_34).trigger('change'); + $('#kol_35_44').val(obj.kol_35_44).trigger('change'); + $('#kol_45_54').val(obj.kol_45_54).trigger('change'); + $('#kol_55_64').val(obj.kol_55_64).trigger('change'); + $('#kol_65').val(obj.kol_65).trigger('change'); + $('#fileupload-avatar').parent().children('img').prop('src', obj.kol_photo); + + $.each(obj.makeups, function (key, value) { + $("input:checkbox[value='" + value.optionItem_uid + "']").prop('checked', true); + }); + + $.each(obj.styles, function (key, value) { + $("input:checkbox[value='" + value.optionItem_uid + "']").prop('checked', true); + }); + + $.each(obj.fansTypes, function (key, value) { + $("input:checkbox[value='" + value.optionItem_uid + "']").prop('checked', true); + }); + $.each(obj.medias, function (key, value) { + var trHtml = ""; + trHtml += ''; + trHtml += ' '; + trHtml += ' '; + trHtml += ' '; + trHtml += ' '; + trHtml += ' '; + trHtml += ' '; + trHtml += ''; + + $('#media_table tbody').append(trHtml); + //$("input:checkbox[value='" + value.optionItem_uid + "']").prop('checked', true); + }); + + $('#clientNewModal').modal('toggle'); + } else { + alert(data.message); + + if (data.err_code == "9999") { + location.href = "/Home/Index"; + } + } + }, + error: function (jqXHR, textStatus, errorThrown) { + alert('網路或伺服器發生錯誤,請稍後重試!'); + } + }); + } +} function buttonClick(obj) { mediaTr = $(obj).closest('tr'); diff --git a/wwwroot/images/avatar/avatar_0LKA5P5X.jpg b/wwwroot/images/avatar/avatar_0LKA5P5X.jpg new file mode 100644 index 0000000..9c7b7e0 Binary files /dev/null and b/wwwroot/images/avatar/avatar_0LKA5P5X.jpg differ diff --git a/wwwroot/images/avatar/avatar_3EI0SFA9.jpg b/wwwroot/images/avatar/avatar_3EI0SFA9.jpg new file mode 100644 index 0000000..6412351 Binary files /dev/null and b/wwwroot/images/avatar/avatar_3EI0SFA9.jpg differ diff --git a/wwwroot/images/avatar/avatar_U2RSNV05.jpg b/wwwroot/images/avatar/avatar_U2RSNV05.jpg new file mode 100644 index 0000000..4f62819 Binary files /dev/null and b/wwwroot/images/avatar/avatar_U2RSNV05.jpg differ diff --git a/wwwroot/images/avatar/avatar_WI2ZDV9E.jpg b/wwwroot/images/avatar/avatar_WI2ZDV9E.jpg new file mode 100644 index 0000000..7a4ab05 Binary files /dev/null and b/wwwroot/images/avatar/avatar_WI2ZDV9E.jpg differ diff --git a/wwwroot/images/avataravatar_S88S6KEP..png b/wwwroot/images/avataravatar_S88S6KEP..png deleted file mode 100644 index ec93d5d..0000000 Binary files a/wwwroot/images/avataravatar_S88S6KEP..png and /dev/null differ
相片 名稱 組成類型 KOL類型 聯絡方式1 聯絡方式2 最後修改時間
' + value.optionItem_name + ' ' + value.kolMedia_url + ' ' + value.kolMedia_accountName + ' ' + value.kolMedia_displayName + ' ' + value.kolMedia_fansNum + ' '; + trHtml += ' '; + trHtml += ' '; + trHtml += '