Browse Source

[WHAT] Upload Remittance API 完成 [WHY] 開發 ShowEasy API

會員My Booking 上傳匯款單
Dev
Janie 2 years ago
parent
commit
c10073c15a
  1. 56
      EuroTran/EasyBL.WEBAPP/ShowEasy/BookingOnlineService.cs
  2. 117
      EuroTran/EasyBL.WEBAPP/ShowEasy/SECommonService.cs
  3. 16
      EuroTran/WebApp/Controllers/BookingOnlineController.cs

56
EuroTran/EasyBL.WEBAPP/ShowEasy/BookingOnlineService.cs

@ -14,6 +14,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
@ -156,6 +157,61 @@ namespace EasyBL.WEBAPP.SYS
}
#endregion My Booking Card
#region Upload 上傳文件
public HttpResponseMessage UploadRemittance(string OrgID, string Account, string BookingID)
{
SuccessResponseMessage srm = null;
string sError = null;
try
{
var c = HttpContext.Current;
var sGUID = Guid.NewGuid().ToString();
SECommonService commonService = new SECommonService();
// 文件上傳
HttpResponseMessage ret = commonService.UploadRemittance(c, OrgID, Account, BookingID);
if (ret.StatusCode == HttpStatusCode.OK)
{
var db = SugarBase.DB;
//SETB_CMS_Member i_crm = new SETB_CMS_Member();
SETB_SAL_Payment i_crm = new SETB_SAL_Payment();
string requestUrl = Common.ConfigGetValue("", "ida:RedirectUri");
var sUser = db.Queryable<SETB_SAL_Payment>()
.Where(x => x.BookingID == BookingID)
.Single();
var sFilePath = db.Queryable<OTB_SYS_Files>()
.Where(x => x.ParentID == sUser.Remittance)
.Single();
sUser.Remittance = requestUrl + "/" + sFilePath.FilePath.Replace("\\", "/");
srm = new SuccessResponseMessage(null, null);
srm.DATA.Add(BLWording.REL, sUser.Remittance);
}
}
catch (Exception ex)
{
sError = Util.GetLastExceptionMsg(ex);
srm = new SuccessResponseMessage(null, null)
{
STATUSCODE = (int)StatusCodeEnum.Error,
MSG = StatusCodeEnum.Error.GetEnumText()
};
srm.DATA.Add(BLWording.REL, "");
}
return HttpResponseExtension.ToJson(JsonConvert.SerializeObject(srm));
}
#endregion Upload 上傳文件
}

117
EuroTran/EasyBL.WEBAPP/ShowEasy/SECommonService.cs

@ -307,6 +307,123 @@ namespace EasyBL.WEBAPP.SYS
#endregion Upload 上傳文件
#region Upload 上傳匯款單
public HttpResponseMessage UploadRemittance(HttpContext c, string OrgID, string Account, string BookingID)
{
SuccessResponseMessage srm = null;
string sError = null;
try
{
//首先先确定请求里夹带的文件数量
var req = c.Request;
var sSource = "MembersBooking";
var sOrgID = OrgID; //要帶token內的資料
var sUserID = Account; //要帶token內的資料
var sParentID = Guid.NewGuid().ToString();
var sServerPath = c.Server.MapPath("/");
var sRoot = sServerPath + "Document\\EurotranFile";
Common.FnCreateDir(sRoot + "\\" + sSource);//如果沒有該目錄就創建目錄
if (req.Files.Count > 0)
{
var saFilesAdd = new List<OTB_SYS_Files>();
for (int index = 0; index < req.Files.Count; index++)
{
var file = req.Files[index];
var sFileSizeName = "";
var sFileID = Guid.NewGuid().ToString();//檔案ID
var sFileName = Path.GetFileName(file.FileName);//檔案名稱+文件格式名稱
var sFileType = file.ContentType; //檔案類型
var iFileSize = file.ContentLength; //檔案大小
var KBSize = Math.Round((decimal)iFileSize / 1024, 1);//單位KB
if (KBSize < 1024)
{
sFileSizeName = KBSize + "KB";
}
else
{
var ComparisonSize = Math.Round((decimal)KBSize / 1024, 1);//單位MB
sFileSizeName = ComparisonSize + "MB";
}
var sfileName = sFileName.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries);
var sSubFileName = sfileName.LastOrDefault(); //副檔名
var sNewFileName = sFileID + '.' + sSubFileName;
var sOutputPath = sRoot + "/" + sSource + "/" + sNewFileName;
sOutputPath = System.Text.RegularExpressions.Regex.Replace(sOutputPath, @"//|/", @"\");
file.SaveAs(sOutputPath);
var oFile = new OTB_SYS_Files
{
OrgID = sOrgID,
FileID = sFileID,
ParentID = sParentID,
SourceFrom = sSource,
FileName = sFileName,
SubFileName = sSubFileName,
FilePath = sOutputPath.Replace(sServerPath, ""),
FileType = sFileType,
FileSize = iFileSize,
FileSizeName = sFileSizeName,
CreateUser = sUserID,
CreateDate = DateTime.Now,
ModifyUser = sUserID,
ModifyDate = DateTime.Now
};
saFilesAdd.Add(oFile);
}
var db = SugarBase.DB;
var iRes = db.Insertable(saFilesAdd).ExecuteCommand();
//var userAccount = db.Queryable<SETB_SAL_BookingOnline>()
// .Where(x => x.BookingID == BookingID && x.Account == Account)
// .Single();
var userPic = db.Updateable<SETB_SAL_Payment>()
.UpdateColumns(x => new SETB_SAL_Payment { Remittance = sParentID })
.Where(x => x.BookingID == BookingID)
.ExecuteCommand();
if (iRes > 0)
{
var rp = c.Response;
var sJsonText = ServiceBase.JsonToString(saFilesAdd);
rp.Write(sJsonText);
rp.End();
}
srm = new SuccessResponseMessage(null, null);
srm.DATA.Add(BLWording.REL, iRes);
}
}
catch (Exception ex)
{
sError = Util.GetLastExceptionMsg(ex);
srm = new SuccessResponseMessage(null, null)
{
STATUSCODE = (int)StatusCodeEnum.Error,
MSG = StatusCodeEnum.Error.GetEnumText()
};
srm.DATA.Add(BLWording.REL, "");
}
return HttpResponseExtension.ToJson(JsonConvert.SerializeObject(srm));
}
#endregion Upload 上傳匯款單
}
}

16
EuroTran/WebApp/Controllers/BookingOnlineController.cs

@ -74,6 +74,22 @@ namespace WebApp.Controllers
return new BookingOnlineService().BookingCardList(SEToken.Account, Lang, rsSubCategoryIDs, rsBookingStatuses, rsPaymentStatuses);
}
/// <summary>
/// 上傳匯款單
/// </summary>
/// <param name="argumentClassID"></param>
/// <returns></returns>
[HttpGet]
[SEApiSecurityFilter]
public HttpResponseMessage UploadRemittance(string BookingID)
{
var SEToken = SETokenUtil.GetToken(this.Request);
return new BookingOnlineService().UploadRemittance(SEToken.OrgID, SEToken.Account, BookingID);
}
}
}
Loading…
Cancel
Save