@@ -128,7 +128,7 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Applet | |||
[HttpPost("/api/AppletService/MaterialAdd")] | |||
public async Task MaterialAdd(AddMiniStorePageMaterialInput input) | |||
{ | |||
var res = await db.Queryable<MiniStorePageConfig>().FirstAsync(x => x.MaterialCode == input.MaterialCode ); | |||
var res = await db.Queryable<MiniStorePageConfig>().FirstAsync(x => x.MaterialCode == input.MaterialCode && x.PageId == input.PageId); | |||
if (res != null) | |||
{ | |||
throw Oops.Bah("素材编码重复"); | |||
@@ -209,7 +209,7 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Applet | |||
throw Oops.Bah("没有找到数据"); | |||
} | |||
//判断编码重复 | |||
var data1 = await db.Queryable<MiniStorePageConfig>().FirstAsync(x => x.Id != input.Id && x.MaterialCode == input.MaterialCode ); | |||
var data1 = await db.Queryable<MiniStorePageConfig>().FirstAsync(x => x.Id != input.Id && x.MaterialCode == input.MaterialCode && x.PageId == input.PageId); | |||
if (data1 != null) | |||
{ | |||
throw Oops.Bah("编码重复"); | |||
@@ -228,17 +228,25 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Applet | |||
/// <returns></returns> | |||
[HttpPost("/api/AppletService/MiniStoreMaterial")] | |||
[AllowAnonymous] | |||
public async Task<List<MiniStorePageConfigOutput>> MiniStoreMaterial(QueryMiniStorePageInput input) | |||
public async Task<SqlSugarPagedList<MiniStorePageConfigOutput>> MiniStoreMaterial(QueryMiniStorePageInput input) | |||
{ | |||
List<MiniStorePageConfigOutput> outputs = new(); | |||
var datas = await db.Queryable<MiniStorePage>().Where(x => x.StoreId == input.StoreId).ToListAsync(); | |||
foreach (var item in datas) | |||
var datas = await db.Queryable<MiniStorePage>().Where(x => x.StoreId == input.StoreId && x.Id == input.PageId).ToListAsync(); | |||
if (datas.Count > 0) | |||
{ | |||
var ids = datas.Select(x => x.Id); | |||
var pageList = await db.Queryable<MiniStorePageConfig>().Where(x => ids.Contains(x.PageId)) | |||
.OrderBy(x => x.Id) | |||
.ToPagedListAsync(input.Current, input.PageSize); | |||
MiniStorePageConfigOutput output = new(); | |||
output.PageName = item.PageName; | |||
output.PageRoute = item.PageRoute; | |||
var lists = await db.Queryable<MiniStorePageConfig>().Where(x => x.PageId == item.Id).ToListAsync(); | |||
foreach (var materialItem in lists) | |||
output.PageName = datas[0]?.PageName ?? ""; | |||
output.PageRoute = datas[0]?.PageRoute ?? ""; | |||
foreach (var materialItem in pageList.Items) | |||
{ | |||
MiniStorePageMaterialOutput material = new(); | |||
material.MaterialName = materialItem.MaterialName; | |||
@@ -249,9 +257,23 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Applet | |||
output.List.Add(material); | |||
} | |||
outputs.Add(output); | |||
return new SqlSugarPagedList<MiniStorePageConfigOutput>() | |||
{ | |||
Items = outputs, | |||
PageIndex = pageList.PageIndex, | |||
PageSize = pageList.PageSize, | |||
TotalCount = pageList.TotalCount, | |||
TotalPages = pageList.TotalPages, | |||
}; | |||
} | |||
return outputs; | |||
return new SqlSugarPagedList<MiniStorePageConfigOutput>() | |||
{ | |||
Items = new List<MiniStorePageConfigOutput>() | |||
}; | |||
} | |||
#endregion | |||
@@ -264,7 +286,12 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Applet | |||
{ | |||
db.Ado.BeginTran(); | |||
var payTemplate = await db.Insertable(new BPA_PayTemplate() | |||
var payTemplate = db.Queryable<BPA_PayTemplate>().First(x => x.IsDeleted == 0 && x.Name == inputDto.Name); | |||
if (payTemplate != null) | |||
{ | |||
throw Oops.Bah("名称重复"); | |||
} | |||
payTemplate = await db.Insertable(new BPA_PayTemplate() | |||
{ | |||
Name = inputDto.Name, | |||
}).CallEntityMethod(t => t.Create()).ExecuteReturnEntityAsync(); | |||
@@ -300,9 +327,10 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Applet | |||
db.Ado.CommitTran(); | |||
return result; | |||
} | |||
catch (Exception) | |||
catch (Exception e) | |||
{ | |||
db.Ado.RollbackTran(); | |||
throw Oops.Bah(e.Message); | |||
return false; | |||
} | |||
} | |||
@@ -345,6 +373,7 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Applet | |||
int total = 0; | |||
var res = db.Queryable<BPA_PayTemplate>() | |||
.Where(x => x.IsDeleted == 0) | |||
.WhereIF(!string.IsNullOrEmpty(inputDto.Name), x => x.Name.Contains(inputDto.Name)) | |||
.Select(t => new PayTemplateOutDto | |||
{ | |||
Id = t.Id.SelectAll(), | |||
@@ -384,10 +413,17 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Applet | |||
[HttpPost("/api/paytemplate/update")] | |||
public async Task<bool> Update(PayTemplateCreateOrUpdateInputDto inputDto) | |||
{ | |||
var payTemplate = db.Queryable<BPA_PayTemplate>().First(x => x.Id == inputDto.Id && x.IsDeleted == 0); | |||
var payTemplate = db.Queryable<BPA_PayTemplate>().First(x => x.Id != inputDto.Id && x.IsDeleted == 0 && x.Name == inputDto.Name); | |||
if (payTemplate != null) | |||
{ | |||
throw Oops.Bah("名称重复"); | |||
} | |||
payTemplate = db.Queryable<BPA_PayTemplate>().First(x => x.Id == inputDto.Id && x.IsDeleted == 0); | |||
if (payTemplate == null) return false; | |||
payTemplate.Name = inputDto.Name; | |||
var payTemplateInfo = db.Queryable<BPA_PayTemplateInfo>().Where(x => x.PayTemplateId == inputDto.Id).ToList(); | |||
foreach (var item in payTemplateInfo) | |||
{ | |||
@@ -431,6 +467,12 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Applet | |||
[HttpPost("/api/appid/add")] | |||
public async Task<bool> AppidAdd(BPA_AppIdConfig inputDto) | |||
{ | |||
var data = db.Queryable<BPA_AppIdConfig>().First(x => x.IsDeleted == 0 && x.AppId == inputDto.AppId); | |||
if (data != null) | |||
{ | |||
throw Oops.Bah("AppId重复"); | |||
} | |||
try | |||
{ | |||
var result = await db.Insertable(inputDto).CallEntityMethod(t => t.Create()).ExecuteCommandAsync() > 0; | |||
@@ -488,7 +530,12 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Applet | |||
[HttpPost("/api/appid/update")] | |||
public async Task<bool> AppidUpdate(BPA_AppIdConfig inputDto) | |||
{ | |||
var data = db.Queryable<BPA_AppIdConfig>().First(x => x.Id == inputDto.Id && x.IsDeleted == 0); | |||
var data = db.Queryable<BPA_AppIdConfig>().First(x => x.Id != inputDto.Id && x.IsDeleted == 0 && x.AppId == inputDto.AppId); | |||
if (data != null) | |||
{ | |||
throw Oops.Bah("AppId重复"); | |||
} | |||
data = db.Queryable<BPA_AppIdConfig>().First(x => x.Id == inputDto.Id && x.IsDeleted == 0); | |||
if (data == null) return false; | |||
data.AppId = inputDto.AppId; | |||
try | |||
@@ -65,6 +65,8 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Applet.Dtos | |||
/// 主键 | |||
/// </summary> | |||
public string StoreId { get; set; } | |||
public string PageId { get; set; } | |||
} | |||
#endregion | |||
@@ -10,5 +10,6 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Applet.Dtos | |||
{ | |||
public class PayTemplatePageInputDto: PageInputBase | |||
{ | |||
public string Name { get; set; } | |||
} | |||
} |
@@ -45,7 +45,7 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.FoodMenu.Dt | |||
public string goodsTypeName { get; set; } | |||
public string remark { get; set; } | |||
public string descritption { get; set; } | |||
public int isDeleted { get; set; } | |||
@@ -55,11 +55,42 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.FoodMenu.Dt | |||
public string design { get; set; } | |||
public int isWeigh { get; set; } | |||
public string isWeigh { get; set; } | |||
public string defaultMate { get; set; } | |||
public string isAttrubute { get; set; } | |||
public List<GoodstechnologyItem> goodstechnology { get; set; } | |||
} | |||
public class GoodstechnologyItem | |||
{ | |||
public string stepName { get; set; } | |||
public string actionJson { get; set; } | |||
public string goodsAttributeId { get; set; } | |||
public string isBatch { get; set; } | |||
public string chnologyId { get; set; } | |||
public string groupId { get; set; } | |||
public int sort { get; set; } | |||
public string goodsId { get; set; } | |||
public string deviceId { get; set; } | |||
public string id { get; set; } | |||
public string createAt { get; set; } | |||
public string createBy { get; set; } | |||
public int isDeleted { get; set; } | |||
} | |||
public class BaseResultDto2 | |||
@@ -24,5 +24,6 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.FoodMenu.Dt | |||
{ | |||
public string GoodsId { get; set;} | |||
public string GoodsName { get; set; } | |||
public decimal Price { get; set;} | |||
} | |||
} |
@@ -37,6 +37,7 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.FoodMenu.Dt | |||
{ | |||
public string Id { get; set; } | |||
public string Name { get; set; } | |||
public decimal Price { get; set; } | |||
public bool Check { get; set; } | |||
} | |||
} |
@@ -73,6 +73,37 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.FoodMenu | |||
}; | |||
} | |||
/// <summary> | |||
/// 删除菜谱 | |||
/// </summary> | |||
/// <param name="id"></param> | |||
/// <returns></returns> | |||
[HttpPost("/api/FoodMenu/DelShopFoodMenu")] | |||
public async Task<bool> DelShopFoodMenu(string id) | |||
{ | |||
try | |||
{ | |||
db.Ado.BeginTran(); | |||
var data = db.Queryable<BPA_FoodMenuInfo>().Where(a => a.Id == id).ToList(); | |||
var res = await db.Deleteable<BPA_FoodMenuInfo>(data).ExecuteCommandAsync(); | |||
var data2 = db.Queryable<BPA_StoreFoodMenu>().Where(a => a.FoodMenuId == id).ToList(); | |||
await db.Deleteable<BPA_StoreFoodMenu>(data2).ExecuteCommandAsync(); | |||
db.Ado.CommitTran(); | |||
return true; | |||
} | |||
catch (Exception ex) | |||
{ | |||
return false; | |||
} | |||
} | |||
/// <summary> | |||
@@ -92,7 +123,7 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.FoodMenu | |||
if (obj1 != null && data.Id != obj1.Id) | |||
{ | |||
throw new Exception("名称或编码重复"); | |||
throw new Exception("名称重复"); | |||
} | |||
if (data != null) | |||
@@ -178,7 +209,7 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.FoodMenu | |||
//var url1 = App.Configuration["SAAS_Manage"] + "/api/goods/getgoodslist"; | |||
//var json1 = HttpHelper.HttpGet(url1, "", dic, ""); | |||
var url = App.Configuration["SAAS_Manage"] + "/api/goods/page"; | |||
var url = App.Configuration["SAAS_Manage"] + "api/goods/page"; | |||
var json2 = HttpHelper.PostData(url, JsonConvert.SerializeObject(new | |||
{ | |||
current = inputDto.Current, | |||
@@ -204,6 +235,7 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.FoodMenu | |||
{ | |||
Id = item.id, | |||
Name = item.name, | |||
Price = item.price, | |||
Check = check | |||
}); | |||
} | |||
@@ -260,7 +292,7 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.FoodMenu | |||
Dictionary<string, string> dic = new Dictionary<string, string>(); | |||
dic.Add("Authorization", authorization); | |||
var url1 = App.Configuration["SAAS_Manage"] + "/api/goods/getgoodslist"; | |||
var url1 = App.Configuration["SAAS_Manage"] + "api/goods/getgoodslist"; | |||
var json1 = HttpHelper.HttpGet(url1, "", dic, ""); | |||
var data2 = JsonConvert.DeserializeObject<BaseResultDto2>(json1); | |||
@@ -275,6 +307,7 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.FoodMenu | |||
FoodMenuId = inputDto.FoodMenuId, | |||
GoodsName = data2?.data?.First(c => c.id == x.GoodsId)?.name, | |||
GoodsId = x.GoodsId, | |||
Price= data2?.data?.First(c => c.id == x.GoodsId)?.price??0, | |||
}).ToList(); | |||
if (data.Count > 0) | |||
{ | |||
@@ -294,6 +327,7 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.FoodMenu | |||
{ | |||
var tihsAdd = thisData.Where(x => x.FoodId == item2.GoodsId).FirstOrDefault(); | |||
var price = data2?.data?.First(c => c.id == (tihsAdd?.FoodId ?? item2.GoodsId))?.price ?? 0; | |||
await db.Insertable(new BPA_StoreFoodMenu() | |||
{ | |||
CookingWorkId = tihsAdd?.CookingWorkId ?? "", | |||
@@ -302,11 +336,11 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.FoodMenu | |||
FoodId = tihsAdd?.FoodId ?? item2.GoodsId, | |||
FoodMenuId = inputDto.FoodMenuId, | |||
FoodName = item?.First()?.FoodName, | |||
Price = tihsAdd?.Price ?? 0, | |||
Price = price, | |||
StopSales = tihsAdd?.StopSales ?? 0, | |||
StoreId = item.First().StoreId, | |||
Vip2Price = tihsAdd?.Vip2Price ?? 0, | |||
VipPrice = tihsAdd?.VipPrice ?? 0, | |||
Vip2Price = price, | |||
VipPrice = price, | |||
}).CallEntityMethod(m => m.Create()).ExecuteCommandAsync(); | |||
} | |||
@@ -318,8 +352,8 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.FoodMenu | |||
StoreId = inputDto.StoreId, | |||
FoodMenuIds = new List<string> | |||
{ | |||
inputDto.FoodMenuId | |||
} | |||
inputDto.FoodMenuId, | |||
}, | |||
}); | |||
db.Ado.CommitTran(); | |||
@@ -379,8 +413,8 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.FoodMenu | |||
Id = a.Id, | |||
goodsId = a.Id, | |||
goodsName=a.GoodsName, | |||
Price = 0, | |||
vipPrice = 0, | |||
Price = a.Price, | |||
vipPrice = a.Price, | |||
a.FoodMenuId | |||
}).ToList(); | |||
@@ -24,6 +24,7 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Printer | |||
/// 核心对象:拥有完整的SqlSugar全部功能 | |||
/// </summary> | |||
private readonly SqlSugarScope db; | |||
/// <summary> | |||
/// construct | |||
/// </summary> | |||
@@ -326,9 +327,19 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Printer | |||
/// <param name="inputDto"></param> | |||
/// <returns></returns> | |||
[HttpPut("/api/Printer/UpdatePrinterTemplate")] | |||
public bool UpdatePrinterTemplate(PrinterTemplateCreateOrUpdateInputDto inputDto) | |||
public async Task<bool> UpdatePrinterTemplate(PrinterTemplateCreateOrUpdateInputDto inputDto) | |||
{ | |||
var res = db.Updateable(inputDto.Adapt<BPA_PrinterTemplate>()) | |||
var data =await db.Queryable<BPA_PrinterTemplate>().FirstAsync(x => x.Id == inputDto.Id); | |||
data.Title = inputDto.Title; | |||
data.Explain = inputDto.Explain; | |||
data.Footer = inputDto.Footer; | |||
data.IsShowNumber = inputDto.IsShowNumber; | |||
data.IsShowPrintTime = inputDto.IsShowPrintTime; | |||
data.Subtitle = inputDto.Subtitle; | |||
data.Title = inputDto.Title; | |||
var res = db.Updateable(data) | |||
.CallEntityMethod(m => m.Modify()).ExecuteCommand(); | |||
return res > 0; | |||
} | |||
@@ -1,6 +1,7 @@ | |||
using BPA.KitChen.StoreManagement.Application.BaseDto; | |||
using BPA.KitChen.StoreManagement.Application.Service.ShopManage.StoreAdvertisement.Dtos; | |||
using BPA.KitChen.StoreManagement.Application.Service.ShopManage.StoreDesktopNumber; | |||
using BPA.KitChen.StoreManagement.Application.Service.SysService; | |||
using BPA.KitChen.StoreManagement.Core.Common; | |||
using BPA.KitChen.StoreManagement.Core.Common.Const; | |||
using BPA.KitChen.StoreManagement.Core.Entity; | |||
@@ -24,12 +25,14 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.StoreAdvert | |||
{ | |||
private readonly SqlSugarScope db; | |||
private readonly IWebHostEnvironment _webHostEnvironment; | |||
private readonly ISysService _sysService; | |||
private readonly string host = "";//App.Configuration["HostPort"]; | |||
public StoreAdvertisementService(IWebHostEnvironment webHostEnvironment) | |||
public StoreAdvertisementService(IWebHostEnvironment webHostEnvironment, ISysService sysService) | |||
{ | |||
db = SqlSugarDb.Db; | |||
_webHostEnvironment= webHostEnvironment; | |||
_sysService = sysService; | |||
} | |||
/// <summary> | |||
@@ -68,17 +71,17 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.StoreAdvert | |||
if (inputDto.UploadType == 1) //校验:0自定义上传,1网络路径 | |||
videoUrls = inputDto.NetWorkUrl; | |||
else | |||
videoUrls = inputDto.VideoUrl; | |||
videoUrls = inputDto.ImageUrl[0].Name;/*; inputDto.VideoUrl;*/ | |||
} | |||
BPA_StoreAdvertisement info = new BPA_StoreAdvertisement() | |||
{ | |||
ImageUrl = imageUrls.TrimEnd('|'), | |||
Content = inputDto.Content??"", | |||
VideoUrl = videoUrls, | |||
VideoUrl = string.IsNullOrEmpty(videoUrls)?"": videoUrls, | |||
UploadType = inputDto.UploadType, | |||
StartTime = inputDto.StartTime, | |||
EndTime = inputDto.EndTime, | |||
StartTime = inputDto.StartTime??DateTime.Now.ToString(), | |||
EndTime = inputDto.EndTime ?? DateTime.Now.ToString(), | |||
Type = inputDto.Type, | |||
Step = inputDto.Step, | |||
Title = inputDto.Title, | |||
@@ -191,6 +194,7 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.StoreAdvert | |||
[HttpPut("/api/StoreAdvertisement/UpdateStoreAdvertisement")] | |||
public bool UpdateStoreAdvertisementAsync(StoreAdvertisementEntityDto inputDto) | |||
{ | |||
inputDto.ImageUrl= inputDto.ImageUrl.Where(x=>x!=null).ToList(); | |||
string imageUrls = string.Empty; | |||
string videoUrls = string.Empty; | |||
//广告类型 0图片 1 视频 | |||
@@ -207,7 +211,7 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.StoreAdvert | |||
{ | |||
foreach (var item in inputDto.ImageUrl) | |||
{ | |||
imageUrls += item.Name??"" + "|"; | |||
imageUrls += (item.Name??"") + "|"; | |||
} | |||
} | |||
} | |||
@@ -218,12 +222,12 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.StoreAdvert | |||
if (inputDto.UploadType == 1) //校验:0自定义上传,1网络路径 | |||
videoUrls = inputDto.NetWorkUrl; | |||
else | |||
videoUrls = inputDto.VideoUrl; | |||
videoUrls = inputDto.ImageUrl[0].Name;/*; inputDto.VideoUrl;*/ | |||
} | |||
var data = db.Queryable<BPA_StoreAdvertisement>().Where(x => x.Id == inputDto.Id).First(); | |||
data.UploadType = inputDto.UploadType; | |||
data.StartTime = inputDto.StartTime; | |||
data.EndTime = inputDto.EndTime; | |||
data.StartTime = inputDto.StartTime??DateTime.Now.ToString(); | |||
data.EndTime = inputDto.EndTime ?? DateTime.Now.ToString(); | |||
data.Content = inputDto.Content; | |||
data.Title = inputDto.Title; | |||
data.Step = inputDto.Step; | |||
@@ -276,7 +280,7 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.StoreAdvert | |||
/// <returns></returns> | |||
[Route("/api/Upload/FormImg")] | |||
[HttpPost, AllowAnonymous, NonUnify] | |||
public ResultEntity UploadImg(IFormFile file, string storeId) | |||
public async Task<ResultEntity> UploadImg(IFormFile file, string storeId) | |||
{ | |||
if (file == null) | |||
return new ResultEntity() | |||
@@ -330,7 +334,14 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.StoreAdvert | |||
IsSuccess = false, | |||
Msg = "该店铺不存在" | |||
}; | |||
var res = await _sysService.GetCosImgesURL(file); | |||
return new ResultEntity() | |||
{ | |||
Data =new List<string>(){ res }, | |||
IsSuccess = true, | |||
}; | |||
//返回的文件地址 | |||
List<string> filenames = new List<string>(); | |||
try | |||
@@ -1,4 +1,5 @@ | |||
using System; | |||
using Microsoft.AspNetCore.Http; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
@@ -8,5 +9,6 @@ namespace BPA.KitChen.StoreManagement.Application.Service.SysService | |||
{ | |||
public interface ISysService | |||
{ | |||
Task<string> GetCosImgesURL(IFormFile file); | |||
} | |||
} |
@@ -7,6 +7,8 @@ using COSXML.Model.Tag; | |||
using Furion; | |||
using Furion.DependencyInjection; | |||
using Furion.DynamicApiController; | |||
using Microsoft.AspNetCore.Authorization; | |||
using Microsoft.AspNetCore.Http; | |||
using Microsoft.AspNetCore.Mvc; | |||
using SqlSugar; | |||
using System.Text.RegularExpressions; | |||
@@ -85,5 +87,27 @@ namespace BPA.KitChen.StoreManagement.Application.Service.SysService | |||
} | |||
return null; | |||
} | |||
[HttpPost("/api/systemconfig/GetCosFileURL"), ApiDescriptionSettings(SplitCamelCase = false), AllowAnonymous, NonUnify] | |||
public async Task<string> GetCosImgesURL(IFormFile file) | |||
{ | |||
byte[] pReadByte = new byte[0]; | |||
var pFileStream = file.OpenReadStream(); | |||
BinaryReader r = new BinaryReader(pFileStream); | |||
r.BaseStream.Seek(0, SeekOrigin.Begin); //将文件指针设置到文件开 | |||
pReadByte = r.ReadBytes((int)r.BaseStream.Length); | |||
TransferUploadObjectModel m = new TransferUploadObjectModel(); | |||
/// 高级接口上传对象 | |||
var result = await m.TransferUploadFile(new FileInputInfoDto() | |||
{ | |||
Directory = "goods", | |||
FileExtension = Path.GetExtension(file.FileName).Replace(".", ""), | |||
Method = "PUT", | |||
}, pReadByte); | |||
return result; | |||
} | |||
} | |||
} |
@@ -0,0 +1,100 @@ | |||
using COSXML.Model.Object; | |||
using COSXML.Auth; | |||
using COSXML.Transfer; | |||
using System; | |||
using COSXML; | |||
using System.Threading.Tasks; | |||
using BPA.Kitchen.Core.Common; | |||
using Furion.DatabaseAccessor; | |||
using Furion; | |||
using Microsoft.AspNetCore.Components.Forms; | |||
using SqlSugar; | |||
using COSXML.Model.Bucket; | |||
using COSXML.Utils; | |||
using BPA.KitChen.StoreManagement.Core.Common; | |||
using BPA.KitChen.StoreManagement.Application.Service.SysService.Dtos; | |||
using BPA.KitChen.StoreManagement.Core.Common.Const; | |||
namespace BPA.KitChen.StoreManagement.Application.Service.SysService | |||
{ | |||
public class TransferUploadObjectModel | |||
{ | |||
private readonly ISqlSugarRepository repository; | |||
private readonly SqlSugarClient db; | |||
private CosXml cosXml; | |||
public TransferUploadObjectModel() | |||
{ | |||
var cosConfig = CosConfig.cosInfoOptions; | |||
// repository = sqlSugarRepository; | |||
//db = NewSqlSugar.GetInstance(repository.Context); // 推荐操作 | |||
CosXmlConfig config = new CosXmlConfig.Builder() | |||
.SetRegion(cosConfig.Region) // 设置默认的区域, COS 地域的简称请参照 https://cloud.tencent.com/document/product/436/6224 | |||
.Build(); | |||
string secretId = cosConfig.SecretId; // 云 API 密钥 SecretId, 获取 API 密钥请参照 https://console.cloud.tencent.com/cam/capi | |||
string secretKey = cosConfig.SecretKey; // 云 API 密钥 SecretKey, 获取 API 密钥请参照 https://console.cloud.tencent.com/cam/capi | |||
long durationSecond = 6000; //每次请求签名有效时长,单位为秒 | |||
QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId, | |||
secretKey, durationSecond); | |||
this.cosXml = new CosXmlServer(config, qCloudCredentialProvider); | |||
} | |||
/// 高级接口上传文件 | |||
public async Task<string> TransferUploadFile(FileInputInfoDto inputDto, byte[] data) | |||
{ | |||
var cosConfig = CosConfig.cosInfoOptions; | |||
// 初始化 TransferConfig | |||
TransferConfig transferConfig = new TransferConfig(); | |||
// 手动设置开始分块上传的大小阈值为10MB,默认值为5MB | |||
transferConfig.DivisionForUpload = 10 * 1024 * 1024; | |||
// 手动设置分块上传中每个分块的大小为2MB,默认值为1MB | |||
transferConfig.SliceSizeForUpload = 2 * 1024 * 1024; | |||
string GroupId = App.User.FindFirst(ClaimConst.GroupId)?.Value; | |||
string baseUrl = "/Franchisee/"; | |||
//if (!string.IsNullOrWhiteSpace(GroupId)) | |||
//{ | |||
// var Companycheck = db.Queryable<BPA_Company>().Where(x => x.Id == GroupId).First(); | |||
// baseUrl = baseUrl + Companycheck.Code + "/"; | |||
//} | |||
DateTime dt = DateTime.Now; | |||
baseUrl = baseUrl + inputDto.Directory + "/" + dt.ToFileTime().ToString() + "." + inputDto.FileExtension; | |||
try | |||
{ | |||
// 存储桶名称,此处填入格式必须为 bucketname-APPID, 其中 APPID 获取参考 https://console.cloud.tencent.com/developer | |||
String bucket = cosConfig.Bucket; | |||
String cosPath = baseUrl; //对象在存储桶中的位置标识符,即称对象键 | |||
// byte[] data = new byte[1024]; // 二进制数据 | |||
PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, cosPath, data); | |||
// 发起上传 | |||
PutObjectResult result = cosXml.PutObject(putObjectRequest); | |||
Console.WriteLine(result.GetResultInfo()); | |||
return @"https://" + cosConfig.Bucket + ".cos.ap-chengdu.myqcloud.com/" + cosPath; | |||
} | |||
catch (COSXML.CosException.CosClientException clientEx) | |||
{ | |||
//请求失败 | |||
Console.WriteLine("CosClientException: " + clientEx); | |||
} | |||
catch (COSXML.CosException.CosServerException serverEx) | |||
{ | |||
//请求失败 | |||
Console.WriteLine("CosServerException: " + serverEx.GetInfo()); | |||
} | |||
return ""; | |||
} | |||
} | |||
} |
@@ -25,6 +25,8 @@ namespace BPA.KitChen.StoreManagement.Core.Entity | |||
[SugarColumn(ColumnDataType = "Nvarchar(64)", IsNullable = true)] | |||
public string GoodsName { get; set; } | |||
[SugarColumn(ColumnDataType = "decimal(18,2)", IsNullable = false)] | |||
public decimal Price { get; set; } | |||
/// <summary> | |||
/// 菜谱信息表 | |||
/// </summary> | |||
@@ -37,6 +37,7 @@ namespace BPA.KitChen.StoreManagement.Core.Entity | |||
/// <summary> | |||
/// 图片存储路径 | |||
/// </summary> | |||
[SugarColumn(ColumnDataType = "Nvarchar(2000)", IsNullable = true)] | |||
public string ImageUrl { get; set; } | |||
/// <summary> | |||
/// 视频存储路径 | |||
@@ -14,7 +14,7 @@ | |||
"dotnetRunMessages": true, | |||
"launchBrowser": true, | |||
"launchUrl": "api/index.html", | |||
"applicationUrl": "http://localhost:5298", | |||
"applicationUrl": "http://localhost:5002", | |||
"environmentVariables": { | |||
"ASPNETCORE_ENVIRONMENT": "Development" | |||
} | |||
@@ -21,7 +21,7 @@ | |||
"UserName": "emqx_u_block", | |||
"Password": "emqx_p_admin8765490789" | |||
}, | |||
"SAAS_Manage": "http://10.2.1.26:21995/saasbase/", | |||
"SAAS_Manage": "http://localhost:5001/", | |||
"DBConnectionStr": "server=10.2.1.21;Port=3306;Database=bpa_kitchen_storemanage;Uid=root;Pwd=cygadmin;", | |||
"AllowedHosts": "*" |