2323
This commit is contained in:
parent
74d378ef25
commit
cc790c1bb6
|
|
@ -259,7 +259,7 @@ namespace CoreCms.Net.Web.WebApi.Controllers
|
|||
return jm;
|
||||
}
|
||||
}
|
||||
|
||||
filesStorageOptions.Path = "users";
|
||||
string url = string.Empty;
|
||||
if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.LocalStorage.ToString())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -45,6 +45,9 @@ using NLog;
|
|||
using SKIT.FlurlHttpClient.Wechat.Api;
|
||||
using SKIT.FlurlHttpClient.Wechat.Api.Models;
|
||||
using SqlSugar;
|
||||
using DotLiquid.Util;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
{
|
||||
|
|
@ -85,7 +88,7 @@ namespace CoreCms.Net.Web.WebApi.Controllers
|
|||
private readonly ICoreCmsStoreServices _storeServices;
|
||||
private readonly ICoreCmsCouponServices _couponServices;
|
||||
private readonly ICoreCmsOrderServices _orderServices;
|
||||
|
||||
private readonly IToolsServices _toolsServices;
|
||||
private readonly IWeChatApiHttpClientFactory _weChatApiHttpClientFactory;
|
||||
private readonly WeChatOptions _weChatOptions;
|
||||
|
||||
|
|
@ -120,7 +123,7 @@ namespace CoreCms.Net.Web.WebApi.Controllers
|
|||
, ICoreCmsSettingServices settingServices
|
||||
, ICoreCmsServicesServices servicesServices
|
||||
, IOptions<WeChatOptions> weChatOptions
|
||||
, ICoreCmsUserServicesOrderServices userServicesOrderServices, ICoreCmsUserServicesTicketServices userServicesTicketServices, ICoreCmsStoreServices storeServices, ICoreCmsCouponServices couponServices, ICoreCmsOrderServices orderServices, IWeChatApiHttpClientFactory weChatApiHttpClientFactory)
|
||||
, ICoreCmsUserServicesOrderServices userServicesOrderServices, ICoreCmsUserServicesTicketServices userServicesTicketServices, ICoreCmsStoreServices storeServices, ICoreCmsCouponServices couponServices, ICoreCmsOrderServices orderServices, IWeChatApiHttpClientFactory weChatApiHttpClientFactory, IToolsServices toolsServices)
|
||||
{
|
||||
_user = user;
|
||||
_userWeChatInfoServices = userWeChatInfoServices;
|
||||
|
|
@ -153,7 +156,7 @@ namespace CoreCms.Net.Web.WebApi.Controllers
|
|||
_orderServices = orderServices;
|
||||
_weChatApiHttpClientFactory = weChatApiHttpClientFactory;
|
||||
_weChatOptions = weChatOptions.Value;
|
||||
|
||||
_toolsServices = toolsServices;
|
||||
}
|
||||
/// <summary>
|
||||
/// wx.login登陆成功之后发送的请求
|
||||
|
|
@ -882,16 +885,16 @@ namespace CoreCms.Net.Web.WebApi.Controllers
|
|||
jm.code = 14007;
|
||||
return jm;
|
||||
}
|
||||
//获取用户等级
|
||||
var userGrade = await _userGradeServices.QueryByClauseAsync(p => p.id == user.grade);
|
||||
//获取优惠券
|
||||
var userCouponCount = await _couponServices.GetMyCouponCount(user.id);
|
||||
//订单数量
|
||||
var orderCount = await _orderServices.OrderCount(0, user.id);
|
||||
//足迹
|
||||
var footPrintCount = await _goodsBrowsingServices.GetCountAsync(p => p.userId == user.id);
|
||||
//收藏
|
||||
var collectionCount = await _goodsCollectionServices.GetCountAsync(p => p.userId == user.id);
|
||||
////获取用户等级
|
||||
//var userGrade = await _userGradeServices.QueryByClauseAsync(p => p.id == user.grade);
|
||||
////获取优惠券
|
||||
//var userCouponCount = await _couponServices.GetMyCouponCount(user.id);
|
||||
////订单数量
|
||||
//var orderCount = await _orderServices.OrderCount(0, user.id);
|
||||
////足迹
|
||||
//var footPrintCount = await _goodsBrowsingServices.GetCountAsync(p => p.userId == user.id);
|
||||
////收藏
|
||||
//var collectionCount = await _goodsCollectionServices.GetCountAsync(p => p.userId == user.id);
|
||||
|
||||
|
||||
jm.data = new
|
||||
|
|
@ -900,22 +903,18 @@ namespace CoreCms.Net.Web.WebApi.Controllers
|
|||
user.userName,
|
||||
user.mobile,
|
||||
user.sex,
|
||||
user.birthday,
|
||||
birthday = user.birthday != null ? user.birthday?.ToString("yyyy-MM-dd") : "",
|
||||
user.avatarImage,
|
||||
user.nickName,
|
||||
user.balance,
|
||||
user.point,
|
||||
user.grade,
|
||||
age = 30,
|
||||
user.createTime,
|
||||
user.updataTime,
|
||||
user.status,
|
||||
user.parentId,
|
||||
user.passWord,
|
||||
gradeName = userGrade != null ? userGrade.title : "",
|
||||
userCouponCount,
|
||||
orderCount,
|
||||
footPrintCount,
|
||||
collectionCount
|
||||
|
||||
};
|
||||
return jm;
|
||||
}
|
||||
|
|
@ -1768,6 +1767,127 @@ namespace CoreCms.Net.Web.WebApi.Controllers
|
|||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 编辑用户信息
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> EditUserInfo([FromBody] EditLoginUserInfo entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
if (entity.birthday == null)
|
||||
{
|
||||
jm.msg = GlobalErrorCodeVars.Code11027;
|
||||
return jm;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(entity.nickName))
|
||||
{
|
||||
jm.msg = GlobalErrorCodeVars.Code11028;
|
||||
return jm;
|
||||
}
|
||||
|
||||
if (entity.sex <= 0)
|
||||
{
|
||||
jm.msg = GlobalErrorCodeVars.Code11029;
|
||||
return jm;
|
||||
}
|
||||
if (string.IsNullOrEmpty(entity.avatar))
|
||||
{
|
||||
jm.msg = GlobalErrorCodeVars.Code10003;
|
||||
return jm;
|
||||
}
|
||||
if (entity.avatar.IndexOf("http") == -1)
|
||||
{
|
||||
//entity.avatar # data:image/png;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/4
|
||||
//IFormFile file
|
||||
var filesStorageOptions = await _settingServices.GetFilesStorageOptions();
|
||||
|
||||
//初始化上传参数
|
||||
var maxSize = 1024 * 1024 * filesStorageOptions.MaxSize; //上传大小5M
|
||||
|
||||
Random random = new Random();
|
||||
string fileName = _user.ID + "_" + random.Next(1000, 9999) + ".png";
|
||||
string fileExt = Path.GetExtension(fileName).ToLowerInvariant();
|
||||
|
||||
|
||||
//检查文件扩展名
|
||||
if (string.IsNullOrEmpty(fileExt) ||
|
||||
Array.IndexOf(filesStorageOptions.FileTypes.Split(','), fileExt.Substring(1).ToLower()) == -1)
|
||||
{
|
||||
jm.msg = "上传文件扩展名是不允许的扩展名,请上传后缀名为:" + filesStorageOptions.FileTypes;
|
||||
return jm;
|
||||
}
|
||||
var file = Base64ToFormFile(entity.avatar, fileName);
|
||||
//// 使用StreamReader来读取文件内容
|
||||
//using (var reader = new StreamReader(file.OpenReadStream(), Encoding.UTF8))
|
||||
//{
|
||||
// var content = await reader.ReadToEndAsync(); // 注意:这可能会消耗大量内存对于大文件,所以需要限制上传大小
|
||||
// // 检查内容是否合法
|
||||
// if (CommonHelper.CheckData(content))
|
||||
// {
|
||||
// jm.msg = "请勿提交非法数据。";
|
||||
// return jm;
|
||||
// }
|
||||
//}
|
||||
filesStorageOptions.Path = "users";
|
||||
|
||||
string url = string.Empty;
|
||||
if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.LocalStorage.ToString())
|
||||
{
|
||||
url = await _toolsServices.UpLoadFileForLocalStorage(filesStorageOptions, fileExt, file, (int)GlobalEnumVars.FilesStorageLocation.API);
|
||||
}
|
||||
else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.AliYunOSS.ToString())
|
||||
{
|
||||
url = await _toolsServices.UpLoadFileForAliYunOSS(filesStorageOptions, fileExt, file);
|
||||
}
|
||||
else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.QCloudOSS.ToString())
|
||||
{
|
||||
url = await _toolsServices.UpLoadFileForQCloudOSS(filesStorageOptions, fileExt, file);
|
||||
}
|
||||
else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.QiNiuKoDo.ToString())
|
||||
{
|
||||
url = await _toolsServices.UpLoadFileForQiNiuKoDo(filesStorageOptions, fileExt, file);
|
||||
}
|
||||
entity.avatar = url;
|
||||
}
|
||||
|
||||
|
||||
var up = await _userServices.UpdateAsync(p => new CoreCmsUser()
|
||||
{
|
||||
avatarImage = entity.avatar,
|
||||
birthday = entity.birthday,
|
||||
nickName = entity.nickName,
|
||||
sex = entity.sex
|
||||
},
|
||||
p => p.id == _user.ID);
|
||||
|
||||
jm.status = up;
|
||||
jm.msg = jm.status ? "资料保存成功" : "资料保存失败";
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
private IFormFile Base64ToFormFile(string base64, string fileName)
|
||||
{
|
||||
// 匹配并去除 data:image/png;base64, 前缀
|
||||
var match = Regex.Match(base64, @"data:image/(?<type>.+?);base64,(?<data>.+)");
|
||||
if (!match.Success)
|
||||
throw new ArgumentException("base64格式不正确");
|
||||
|
||||
var base64Data = match.Groups["data"].Value;
|
||||
var bytes = Convert.FromBase64String(base64Data);
|
||||
var stream = new MemoryStream(bytes);
|
||||
|
||||
// 构造 IFormFile
|
||||
return new FormFile(stream, 0, bytes.Length, "file", fileName)
|
||||
{
|
||||
Headers = new HeaderDictionary(),
|
||||
ContentType = $"image/{match.Groups["type"].Value}"
|
||||
};
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 修改用户密码
|
||||
|
|
|
|||
|
|
@ -850,18 +850,32 @@
|
|||
用户操作事件
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:CoreCms.Net.Web.WebApi.Controllers.UserController.#ctor(CoreCms.Net.Auth.HttpContextUser.IHttpContextUser,CoreCms.Net.IServices.ICoreCmsUserWeChatInfoServices,CoreCms.Net.IServices.ICoreCmsUserServices,CoreCms.Net.Auth.Policys.PermissionRequirement,CoreCms.Net.IServices.ICoreCmsSmsServices,CoreCms.Net.IServices.ICoreCmsUserGradeServices,CoreCms.Net.IServices.ICoreCmsUserLogServices,Microsoft.AspNetCore.Http.IHttpContextAccessor,CoreCms.Net.IServices.ICoreCmsGoodsServices,CoreCms.Net.IServices.ICoreCmsGoodsBrowsingServices,CoreCms.Net.IServices.ICoreCmsCartServices,CoreCms.Net.IServices.ICoreCmsGoodsCollectionServices,CoreCms.Net.IServices.ICoreCmsUserShipServices,CoreCms.Net.IServices.ICoreCmsAreaServices,CoreCms.Net.IServices.ICoreCmsBillPaymentsServices,CoreCms.Net.IServices.ICoreCmsGoodsCommentServices,CoreCms.Net.IServices.ICoreCmsUserBankCardServices,CoreCms.Net.IServices.ICoreCmsUserTocashServices,CoreCms.Net.IServices.ICoreCmsUserBalanceServices,CoreCms.Net.IServices.ICoreCmsInvoiceServices,CoreCms.Net.IServices.ICoreCmsUserPointLogServices,CoreCms.Net.IServices.ICoreCmsShareServices,CoreCms.Net.IServices.ICoreCmsSettingServices,CoreCms.Net.IServices.ICoreCmsServicesServices,Microsoft.Extensions.Options.IOptions{CoreCms.Net.WeChat.Service.Options.WeChatOptions},CoreCms.Net.IServices.ICoreCmsUserServicesOrderServices,CoreCms.Net.IServices.ICoreCmsUserServicesTicketServices,CoreCms.Net.IServices.ICoreCmsStoreServices,CoreCms.Net.IServices.ICoreCmsCouponServices,CoreCms.Net.IServices.ICoreCmsOrderServices,CoreCms.Net.WeChat.Service.HttpClients.IWeChatApiHttpClientFactory)">
|
||||
<member name="M:CoreCms.Net.Web.WebApi.Controllers.UserController.#ctor(CoreCms.Net.Auth.HttpContextUser.IHttpContextUser,CoreCms.Net.IServices.ICoreCmsUserWeChatInfoServices,CoreCms.Net.IServices.ICoreCmsUserServices,CoreCms.Net.Auth.Policys.PermissionRequirement,CoreCms.Net.IServices.ICoreCmsSmsServices,CoreCms.Net.IServices.ICoreCmsUserGradeServices,CoreCms.Net.IServices.ICoreCmsUserLogServices,Microsoft.AspNetCore.Http.IHttpContextAccessor,CoreCms.Net.IServices.ICoreCmsGoodsServices,CoreCms.Net.IServices.ICoreCmsGoodsBrowsingServices,CoreCms.Net.IServices.ICoreCmsCartServices,CoreCms.Net.IServices.ICoreCmsGoodsCollectionServices,CoreCms.Net.IServices.ICoreCmsUserShipServices,CoreCms.Net.IServices.ICoreCmsAreaServices,CoreCms.Net.IServices.ICoreCmsBillPaymentsServices,CoreCms.Net.IServices.ICoreCmsGoodsCommentServices,CoreCms.Net.IServices.ICoreCmsUserBankCardServices,CoreCms.Net.IServices.ICoreCmsUserTocashServices,CoreCms.Net.IServices.ICoreCmsUserBalanceServices,CoreCms.Net.IServices.ICoreCmsInvoiceServices,CoreCms.Net.IServices.ICoreCmsUserPointLogServices,CoreCms.Net.IServices.ICoreCmsShareServices,CoreCms.Net.IServices.ICoreCmsSettingServices,CoreCms.Net.IServices.ICoreCmsServicesServices,Microsoft.Extensions.Options.IOptions{CoreCms.Net.WeChat.Service.Options.WeChatOptions},CoreCms.Net.IServices.ICoreCmsUserServicesOrderServices,CoreCms.Net.IServices.ICoreCmsUserServicesTicketServices,CoreCms.Net.IServices.ICoreCmsStoreServices,CoreCms.Net.IServices.ICoreCmsCouponServices,CoreCms.Net.IServices.ICoreCmsOrderServices,CoreCms.Net.WeChat.Service.HttpClients.IWeChatApiHttpClientFactory,CoreCms.Net.IServices.IToolsServices)">
|
||||
<summary>
|
||||
构造函数
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:CoreCms.Net.Web.WebApi.Controllers.UserController.GetWxUserId(CoreCms.Net.Model.FromBody.FMWxPost)">
|
||||
<member name="M:CoreCms.Net.Web.WebApi.Controllers.UserController.UseAnonymousLogin(CoreCms.Net.Model.FromBody.FMWxPost)">
|
||||
<summary>
|
||||
wx.login登陆成功之后发送的请求
|
||||
</summary>
|
||||
<param name="entity"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:CoreCms.Net.Web.WebApi.Controllers.UserController.UseWxPhoneNumberLogin(CoreCms.Net.Model.FromBody.FMWxLoginPhoneNumber)">
|
||||
<summary>
|
||||
微信小程序授权拉取手机号码并登录
|
||||
</summary>
|
||||
<param name="entity"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:CoreCms.Net.Web.WebApi.Controllers.UserController.UseWxAnonymousLogin(CoreCms.Net.Model.FromBody.FMWxLoginPhoneNumber)">
|
||||
<summary>
|
||||
微信小程序匿名转正式登录
|
||||
</summary>
|
||||
<param name="entity"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:CoreCms.Net.Web.WebApi.Controllers.UserController.OnLogin(CoreCms.Net.Model.FromBody.FMWxPost)">
|
||||
<summary>
|
||||
wx.login登陆成功之后发送的请求
|
||||
|
|
@ -1148,6 +1162,13 @@
|
|||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:CoreCms.Net.Web.WebApi.Controllers.UserController.EditUserInfo(CoreCms.Net.Model.FromBody.EditLoginUserInfo)">
|
||||
<summary>
|
||||
编辑用户信息
|
||||
</summary>
|
||||
<param name="entity"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:CoreCms.Net.Web.WebApi.Controllers.UserController.EditPwd(CoreCms.Net.Model.FromBody.EditPwdPost)">
|
||||
<summary>
|
||||
修改用户密码
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user