1034 lines
41 KiB
C#
1034 lines
41 KiB
C#
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using Microsoft.AspNetCore.Cors;
|
|
using Dapper;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Web;
|
|
using System.Text;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Net.Http.Headers;
|
|
using Dapper.Contrib.Extensions;
|
|
|
|
using System.IO;
|
|
using System.Threading;
|
|
using System.Dynamic;
|
|
using NPOI;
|
|
using NPOI.HPSF;
|
|
using NPOI.HSSF;
|
|
using NPOI.HSSF.UserModel;
|
|
using NPOI.XSSF;
|
|
using NPOI.XSSF.UserModel;
|
|
using NPOI.POIFS;
|
|
using NPOI.Util;
|
|
using Microsoft.Extensions.Configuration;
|
|
using System.Security.Policy;
|
|
using NPOI.SS.Formula.Functions;
|
|
using static DbTableClass;
|
|
using System.Runtime.InteropServices.ObjectiveC;
|
|
using static System.Net.WebRequestMethods;
|
|
using System.Diagnostics.Eventing.Reader;
|
|
using static Journeys_WantHome.Controllers.AuthApiController;
|
|
|
|
|
|
namespace Journeys_WantHome.Controllers
|
|
{
|
|
[Route("Api")]
|
|
|
|
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"));
|
|
SqlConnection prmConn = new SqlConnection(GlobalClass.appsettings("ConnectionStrings:DBConnectionString"));
|
|
|
|
public ApiController(IHttpContextAccessor httpContextAccessor)
|
|
{
|
|
this._httpContextAccessor = httpContextAccessor;
|
|
}
|
|
|
|
[Route("mediaSpecList")]
|
|
public ActionResult MediaSpecList(IFormCollection obj) {
|
|
mediaSpecListResult ret = new mediaSpecListResult();
|
|
authToken token = new authToken(this._httpContextAccessor);
|
|
if (token.user_isLogin == false)
|
|
{
|
|
HttpContext.Response.Cookies.Delete("token_key");
|
|
|
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
|
}
|
|
|
|
string optionItem_uid = obj["optionItem_uid"].ToString();
|
|
|
|
ret.mediaSpecList = conn.Query<mediaItem>("select * from mediaItem where mediaItem_ishide = 'N' and optionItem_uid = @optionItem_uid order by mediaItem_order", new { optionItem_uid = optionItem_uid }).ToList();
|
|
|
|
ret.ret = "yes";
|
|
|
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
|
}
|
|
|
|
[Route("updateTags")]
|
|
public ActionResult UpdateTags(IFormCollection obj) {
|
|
updatTagResult ret = new updatTagResult();
|
|
|
|
authToken token = new authToken(this._httpContextAccessor);
|
|
if (token.user_isLogin == false)
|
|
{
|
|
HttpContext.Response.Cookies.Delete("token_key");
|
|
|
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
|
}
|
|
|
|
string search = obj["search"].ToString();
|
|
|
|
if (search.Length < 2) {
|
|
ret.ret = "no";
|
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
|
}
|
|
|
|
tags tag = conn.QueryFirstOrDefault<tags>("select * from tags where tag_text = @tag_text", new { tag_text = search });
|
|
|
|
|
|
|
|
if (tag == null)
|
|
{
|
|
tags newTag = new tags();
|
|
newTag.tag_uid = "tag_" + GlobalClass.CreateRandomCode(12);
|
|
newTag.tag_text = search;
|
|
|
|
conn.Insert<tags>(newTag);
|
|
|
|
ret.data.id = newTag.tag_uid;
|
|
ret.data.text = search;
|
|
ret.ret = "yes";
|
|
}
|
|
else {
|
|
ret.data.id = tag.tag_uid;
|
|
ret.data.text = search;
|
|
ret.ret = "yes";
|
|
}
|
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
|
}
|
|
|
|
[Route("queryTags")]
|
|
public ActionResult QueryTags(IFormCollection obj) {
|
|
tagListResult ret = new tagListResult();
|
|
|
|
authToken token = new authToken(this._httpContextAccessor);
|
|
if (token.user_isLogin == false)
|
|
{
|
|
HttpContext.Response.Cookies.Delete("token_key");
|
|
|
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
|
}
|
|
|
|
string search = obj["search"].ToString();
|
|
|
|
search = "%" + search + "%";
|
|
|
|
List<tags> tagList = conn.Query<tags>("select * from tags where tag_text like @tag_text", new { tag_text = search }).ToList();
|
|
|
|
foreach (tags tag in tagList)
|
|
{
|
|
optionData item = new optionData();
|
|
|
|
item.id = tag.tag_uid;
|
|
item.text = tag.tag_text;
|
|
|
|
ret.data.Add(item);
|
|
}
|
|
|
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
|
}
|
|
|
|
[Route("queryPrmFile")]
|
|
public ActionResult QueryPrmFile(IFormCollection obj) {
|
|
prmFileResult ret = new prmFileResult();
|
|
|
|
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 quotation_serial = obj["quotation_serial"].ToString();
|
|
|
|
files fil = prmConn.QueryFirstOrDefault<files>("select * from files where file_target_uid = @quotation_serial and file_del = 'N'", new { quotation_serial = quotation_serial});
|
|
|
|
if (fil == null)
|
|
{
|
|
ret.ret = "yes";
|
|
ret.hasFile = "N";
|
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
|
}
|
|
else {
|
|
ret.ret = "yes";
|
|
ret.hasFile = "Y";
|
|
ret.fileName = fil.file_filename;
|
|
ret.fileUrl = "https://prm.bremennetwork.tw/api/fileService4Journeys.ashx?id=" + fil.file_uid;
|
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
|
|
|
}
|
|
|
|
|
|
|
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
|
}
|
|
|
|
[Route("queryPrm")]
|
|
public ActionResult QueryPrm(IFormCollection obj) {
|
|
prmResult ret = new prmResult();
|
|
|
|
authToken token = new authToken(this._httpContextAccessor);
|
|
if (token.user_isLogin == false)
|
|
{
|
|
HttpContext.Response.Cookies.Delete("token_key");
|
|
|
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
|
}
|
|
|
|
string search = obj["search"].ToString();
|
|
|
|
string quotation_serial = search + "%";
|
|
string quotation_name = "%" + search + "%";
|
|
|
|
List<quotation> quotations = prmConn.Query<quotation>("select * from quotation where dept_uid in ('bremen', 'journeys') and quotation_del = 'N' and quotation_invalid = 'N' and (quotation_serial like @quotation_serial or quotation_name like @quotation_name) order by quotation_serial desc ", new { quotation_serial = quotation_serial, quotation_name = quotation_name }).ToList();
|
|
|
|
foreach (quotation proj in quotations)
|
|
{
|
|
optionData item = new optionData();
|
|
|
|
item.id = proj.quotation_serial;
|
|
item.text = "(" + proj.quotation_serial + ") " + proj.quotation_name;
|
|
|
|
ret.data.Add(item);
|
|
}
|
|
|
|
|
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
|
}
|
|
|
|
[Route("projectAddEditDelGet")]
|
|
public ActionResult ProjectAddEditDelGet(IFormCollection obj)
|
|
{
|
|
projectResult ret = new projectResult();
|
|
|
|
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 project_uid = obj["project_uid"].ToString();
|
|
|
|
string project_isPrm = obj["project_isPrm"].ToString();
|
|
string project_prmSerial = obj["project_prmSerial"].ToString();
|
|
string project_name = obj["project_name"].ToString();
|
|
string project_year = obj["project_year"].ToString();
|
|
string project_month = obj["project_month"].ToString();
|
|
string project_isExec = project_isPrm;
|
|
|
|
if (method == "del") {
|
|
project newProj = conn.QueryFirstOrDefault<project>("select * from project where project_uid = @project_uid", new { project_uid = project_uid });
|
|
|
|
if (newProj == null)
|
|
{
|
|
ret.ret = "no";
|
|
ret.err_code = "2001";
|
|
ret.message = "找不到此專案資料!";
|
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
|
}
|
|
|
|
conn.Delete<project>(newProj);
|
|
ret.ret = "yes";
|
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
|
}
|
|
|
|
if (method == "get") {
|
|
project newProj = conn.QueryFirstOrDefault<project>("select * from project where project_uid = @project_uid", new { project_uid = project_uid });
|
|
|
|
if (newProj == null)
|
|
{
|
|
ret.ret = "no";
|
|
ret.err_code = "2001";
|
|
ret.message = "找不到此專案資料!";
|
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
|
}
|
|
|
|
ret.ret = "yes";
|
|
ret.data = newProj;
|
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
|
}
|
|
|
|
if (method == "edit") {
|
|
project newProj = conn.QueryFirstOrDefault<project>("select * from project where project_uid = @project_uid", new { project_uid = project_uid });
|
|
|
|
if (newProj == null) {
|
|
ret.ret = "no";
|
|
ret.err_code = "2001";
|
|
ret.message = "找不到此專案資料!";
|
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
|
}
|
|
|
|
newProj.project_name = project_name;
|
|
newProj.project_isPrm = project_isPrm;
|
|
newProj.project_year = int.Parse(project_year);
|
|
newProj.project_month = int.Parse(project_month);
|
|
newProj.project_modifydate = DateTime.Now;
|
|
newProj.project_modify_id = token.user_id;
|
|
newProj.project_prmSerial = project_prmSerial;
|
|
newProj.project_isExec = project_isExec;
|
|
|
|
conn.Update<project>(newProj);
|
|
ret.ret = "yes";
|
|
ret.data = newProj;
|
|
|
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
|
}
|
|
|
|
if (method == "add") {
|
|
project_uid = GlobalClass.CreateRandomCode(12);
|
|
|
|
if (project_isPrm == "Y")
|
|
{
|
|
project findProje = conn.QueryFirstOrDefault<project>("select * from project where project_prmSerial = @project_prmSerial", new { project_prmSerial = project_prmSerial });
|
|
if (findProje != null)
|
|
{
|
|
ret.ret = "no";
|
|
ret.err_code = "1001";
|
|
ret.message = "此PRM專案已經存在於KOL系統之中!";
|
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
|
}
|
|
}
|
|
else {
|
|
project findProje = conn.QueryFirstOrDefault<project>("select * from project where project_name = @project_name and project_year = @project_year and project_month = @project_month ", new { project_name = project_name, project_year = project_year, project_month = project_month });
|
|
if (findProje != null)
|
|
{
|
|
ret.ret = "no";
|
|
ret.err_code = "1002";
|
|
ret.message = "此專案名稱已經存在於KOL系統之中!";
|
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
|
}
|
|
}
|
|
|
|
project newProj = new project();
|
|
|
|
newProj.project_uid = project_uid;
|
|
newProj.project_name = project_name;
|
|
newProj.project_isPrm = project_isPrm;
|
|
newProj.project_year = int.Parse(project_year);
|
|
newProj.project_month = int.Parse(project_month);
|
|
newProj.project_create_id = token.user_id;
|
|
newProj.project_modify_id = token.user_id;
|
|
newProj.project_prmSerial = project_prmSerial;
|
|
newProj.project_isExec = project_isExec;
|
|
|
|
conn.Insert(newProj);
|
|
ret.ret = "yes";
|
|
ret.data = newProj;
|
|
|
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
|
}
|
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
|
}
|
|
|
|
[Route("projectList")]
|
|
public ActionResult ProjectList(IFormCollection obj) {
|
|
projectListResult ret = new projectListResult();
|
|
|
|
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 project_year = obj["year"].ToString();
|
|
string project_month = obj["month"].ToString();
|
|
|
|
if (project_year == "")
|
|
{
|
|
List<project> projects = conn.Query<project>("select * from project order by project_modifydate desc ").ToList();
|
|
ret.projectList = projects;
|
|
}
|
|
else {
|
|
List<project> projects = conn.Query<project>("select * from project where project_year = @project_year and project_month = @project_month order by project_modifydate desc ", new { project_year = project_year, project_month = project_month }).ToList();
|
|
ret.projectList = projects;
|
|
}
|
|
|
|
|
|
|
|
ret.ret = "yes";
|
|
|
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
|
}
|
|
|
|
[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<kol> kols = conn.Query<kol>("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();
|
|
|
|
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 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 });
|
|
conn.Execute("delete kolTag 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<kol>("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();
|
|
string kol_contact2 = obj["kol_contact2"].ToString();
|
|
double kol_men_ratio = double.Parse(obj["kol_men_ratio"].ToString());
|
|
double kol_women_ratio = double.Parse(obj["kol_women_ratio"].ToString());
|
|
double kol_13_17 = double.Parse(obj["kol_13_17"].ToString());
|
|
double kol_18_24 = double.Parse(obj["kol_18_24"].ToString());
|
|
double kol_25_34 = double.Parse(obj["kol_25_34"].ToString());
|
|
double kol_35_44 = double.Parse(obj["kol_35_44"].ToString());
|
|
double kol_45_54 = double.Parse(obj["kol_45_54"].ToString());
|
|
double kol_55_64 = double.Parse(obj["kol_55_64"].ToString());
|
|
double kol_65 = double.Parse(obj["kol_65"].ToString());
|
|
string kol_photo = obj["kol_photo"].ToString();
|
|
|
|
string kolMakeupStr = obj["kolMakeupStr"].ToString().TrimEnd(',');
|
|
string kolStyleStr = obj["kolStyleStr"].ToString().TrimEnd(',');
|
|
string kolFansTypeStr = obj["kolFansType"].ToString().TrimEnd(',');
|
|
string kolTagsStr = obj["kolTags"].ToString().TrimEnd(',');
|
|
string mediaArrayJson = obj["mediaArrayJson"].ToString().TrimEnd(',');
|
|
|
|
if (method == "") {
|
|
ret.ret = "no";
|
|
ret.err_code = "0001";
|
|
ret.message = "無method參數!";
|
|
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<kol>("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<kolMakeup> kolMakeups = new List<kolMakeup>();
|
|
foreach (string makeup in kolMakeupArr)
|
|
{
|
|
optionItem item = conn.QueryFirstOrDefault<optionItem>("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<kolStyle> kolStyles = new List<kolStyle>();
|
|
foreach (string style in kolStyleArr)
|
|
{
|
|
optionItem item = conn.QueryFirstOrDefault<optionItem>("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<kolFansType> kolFansTypes = new List<kolFansType>();
|
|
foreach (string fansType in kolFansTypeArr)
|
|
{
|
|
optionItem item = conn.QueryFirstOrDefault<optionItem>("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);
|
|
}
|
|
}
|
|
|
|
string[] kolTagArr = kolTagsStr.Split(",");
|
|
List<kolTag> kolTags = new List<kolTag>();
|
|
foreach (string tag in kolTagArr) {
|
|
tags tagData = conn.QueryFirstOrDefault<tags>("select * from tags where tag_uid = @tag_uid", new { tag_uid = tag });
|
|
|
|
if (tagData != null) {
|
|
kolTag newKolTag = new kolTag();
|
|
newKolTag.kolTag_uid = "kt_" + GlobalClass.CreateRandomCode(12);
|
|
newKolTag.kol_uid = kol_uid;
|
|
newKolTag.tag_uid = tag;
|
|
kolTags.Add(newKolTag);
|
|
}
|
|
}
|
|
|
|
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<kolMedia> medias = new List<kolMedia>();
|
|
|
|
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.Execute("delete kolTag where kol_uid = @kol_uid", new { kol_uid = kol_uid });
|
|
|
|
conn.Insert(kolMakeups);
|
|
conn.Insert(kolStyles);
|
|
conn.Insert(kolFansTypes);
|
|
conn.Insert(medias);
|
|
conn.Insert(kolTags);
|
|
|
|
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 = "";
|
|
|
|
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 = new kol();
|
|
|
|
kol_uid = "kol_" + GlobalClass.CreateRandomCode(12);
|
|
|
|
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_create_userId = token.user_id;
|
|
newKol.kol_modify_userId = token.user_id;
|
|
|
|
string[] kolMakeupArr = kolMakeupStr.Split(',');
|
|
|
|
List<kolMakeup> kolMakeups = new List<kolMakeup>();
|
|
foreach (string makeup in kolMakeupArr)
|
|
{
|
|
optionItem item = conn.QueryFirstOrDefault<optionItem>("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<kolStyle> kolStyles = new List<kolStyle>();
|
|
foreach (string style in kolStyleArr)
|
|
{
|
|
optionItem item = conn.QueryFirstOrDefault<optionItem>("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<kolFansType> kolFansTypes = new List<kolFansType>();
|
|
foreach(string fansType in kolFansTypeArr)
|
|
{
|
|
optionItem item = conn.QueryFirstOrDefault<optionItem>("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);
|
|
}
|
|
}
|
|
|
|
string[] kolTagArr = kolTagsStr.Split(",");
|
|
List<kolTag> kolTags = new List<kolTag>();
|
|
foreach (string tag in kolTagArr)
|
|
{
|
|
tags tagData = conn.QueryFirstOrDefault<tags>("select * from tags where tag_uid = @tag_uid", new { tag_uid = tag });
|
|
|
|
if (tagData != null)
|
|
{
|
|
kolTag newKolTag = new kolTag();
|
|
newKolTag.kolTag_uid = "kt_" + GlobalClass.CreateRandomCode(12);
|
|
newKolTag.kol_uid = kol_uid;
|
|
newKolTag.tag_uid = tag;
|
|
kolTags.Add(newKolTag);
|
|
}
|
|
}
|
|
|
|
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<kolMedia> medias = new List<kolMedia>();
|
|
|
|
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.Insert(kolMakeups);
|
|
conn.Insert(kolStyles);
|
|
conn.Insert(kolFansTypes);
|
|
conn.Insert(medias);
|
|
conn.Insert(kolTags);
|
|
|
|
try
|
|
{
|
|
conn.Insert(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");
|
|
}
|
|
|
|
|
|
|
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
|
}
|
|
|
|
[Route("kolPhotoUpload")]
|
|
[RequestFormLimits(MultipartBodyLengthLimit = int.MaxValue)]
|
|
[RequestSizeLimit(int.MaxValue)]
|
|
public ActionResult KolPhotoUpload([FromForm(Name = "avatar")] IFormFile file) {
|
|
authToken token = new authToken(this._httpContextAccessor);
|
|
if (token.user_isLogin == false)
|
|
{
|
|
List<errFile> files = new List<errFile>();
|
|
|
|
errFile newFile = new errFile();
|
|
newFile.name = "";
|
|
newFile.size = 0;
|
|
newFile.error = "尚未登入";
|
|
|
|
files.Add(newFile);
|
|
|
|
fileResult obj = new fileResult();
|
|
|
|
obj.files = files;
|
|
|
|
return Content(JsonConvert.SerializeObject(files), "application/json;charset=utf-8");
|
|
}
|
|
|
|
|
|
string originFileName = file.FileName;
|
|
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)) {
|
|
file.CopyTo(stream);
|
|
}
|
|
|
|
List<uploadFile> files = new List<uploadFile>();
|
|
|
|
uploadFile newFile = new uploadFile();
|
|
|
|
newFile.name = originFileName;
|
|
newFile.url = "/images/avatar/" + newFileName;
|
|
newFile.size = file.Length;
|
|
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");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
List<errFile> files = new List<errFile>();
|
|
|
|
errFile newFile = new errFile();
|
|
newFile.name = originFileName;
|
|
newFile.size = file.Length;
|
|
newFile.error = ex.Message;
|
|
|
|
files.Add(newFile);
|
|
|
|
fileResult obj = new fileResult();
|
|
|
|
obj.files = files;
|
|
|
|
return Content(JsonConvert.SerializeObject(files), "application/json;charset=utf-8");
|
|
}
|
|
}
|
|
|
|
[Route("optionItemList")]
|
|
public ActionResult OptionItemList(IFormCollection obj)
|
|
{
|
|
optionListResult ret = new optionListResult();
|
|
|
|
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 option_uid = obj["option_uid"].ToString();
|
|
|
|
if (option_uid == "")
|
|
{
|
|
ret.ret = "no";
|
|
ret.err_code = "00001";
|
|
ret.message = "無option_uid資料!";
|
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
|
}
|
|
|
|
ret.optionItems = conn.Query<optionItem>("select * from optionItem where optionItem_ishide = 'N' and option_uid = @option_uid order by optionItem_order ", new { option_uid = option_uid }).ToList();
|
|
ret.ret = "yes";
|
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public class mediaSpecListResult {
|
|
public string ret { get; set; } = "no";
|
|
public string err_code { get; set; } = "0000";
|
|
public string message { get; set; } = "";
|
|
|
|
public List<mediaItem> mediaSpecList = new List<mediaItem>();
|
|
}
|
|
|
|
public class updatTagResult {
|
|
public string ret { get; set; } = "no";
|
|
public string err_code { get; set; } = "0000";
|
|
public string message { get; set; } = "";
|
|
|
|
public optionData data = new optionData();
|
|
}
|
|
public class tagListResult {
|
|
public List<optionData> data = new List<optionData>();
|
|
}
|
|
public class prmFileResult {
|
|
public string ret { get; set; } = "no";
|
|
public string err_code { get; set; } = "0000";
|
|
public string message { get; set; } = "";
|
|
|
|
public string hasFile { get; set; } = "N";
|
|
public string fileName { get; set; } = "";
|
|
public string fileUrl { get; set; } = "";
|
|
|
|
}
|
|
public class prmResult {
|
|
public List<optionData> data = new List<optionData>();
|
|
}
|
|
|
|
public class optionData {
|
|
public string id { get; set; } = "";
|
|
public string text { get; set; } = "";
|
|
}
|
|
|
|
public class projectResult {
|
|
public string ret { get; set; } = "no";
|
|
public string err_code { get; set; } = "0000";
|
|
public string message { get; set; } = "";
|
|
|
|
public project data { get; set; } = new project();
|
|
}
|
|
|
|
public class projectListResult {
|
|
public string ret { get; set; } = "no";
|
|
public string err_code { get; set; } = "0000";
|
|
public string message { get; set; } = "";
|
|
|
|
public List<project> projectList { get; set; } = new List<project>();
|
|
}
|
|
|
|
public class kolListResult {
|
|
public string ret { get; set; } = "";
|
|
public string err_code { get; set; } = "";
|
|
public string message { get; set; } = "";
|
|
|
|
public List<kolDetial> kolList { get; set; } = new List<kolDetial>();
|
|
}
|
|
public class kolResult {
|
|
public string ret { get; set; } = "";
|
|
public string err_code { get; set; } = "";
|
|
public string message { get; set; } = "";
|
|
public kolDetial kol { get; set; } = new kolDetial();
|
|
|
|
}
|
|
|
|
public class fileResult {
|
|
public object files = new object();
|
|
}
|
|
|
|
public class uploadFile {
|
|
public string name { get; set; } = "";
|
|
public long size { get; set; } = 0;
|
|
public string url { get; set; } = "";
|
|
public string thumbnailUrl { get; set; } = "";
|
|
public string deleteUrl { get; set; } = "";
|
|
public string deleteType { get; set; } = "DELETE";
|
|
}
|
|
|
|
public class errFile {
|
|
public string name { get; set; } = "";
|
|
public long size { get; set; } = 0;
|
|
public string error { get; set; } = "";
|
|
}
|
|
}
|