You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
3.2 KiB
75 lines
3.2 KiB
2 years ago
|
using Znyc.CloudCar.IRepository.Currency;
|
||
|
using Znyc.CloudCar.IRepository.User;
|
||
|
using Znyc.CloudCar.IServices.CaChe;
|
||
|
using Znyc.CloudCar.IServices.User;
|
||
|
using Znyc.CloudCar.Model.Dtos.User;
|
||
|
using Znyc.CloudCar.Model.Entities;
|
||
|
using Znyc.CloudCar.Utility.Extensions;
|
||
|
using Znyc.CloudCar.Utility.Helper;
|
||
|
|
||
|
namespace Znyc.CloudCar.Services.User
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 用户服务
|
||
|
/// </summary>
|
||
|
public class WxUnifyUserService : IWxUnifyUserService
|
||
|
{
|
||
|
private readonly IWxUnifyUserRepository _wxUnifyUserRepository;
|
||
|
private readonly ICurrencyRecordRepository _currencyRecordRepository;
|
||
|
private readonly IUserRepository _userRepository;
|
||
|
private readonly ICacheService _cacheService;
|
||
|
|
||
|
public WxUnifyUserService(
|
||
|
IWxUnifyUserRepository wxUnifyUserRepository,
|
||
|
ICurrencyRecordRepository currencyRecordRepository,
|
||
|
IUserRepository userRepository,
|
||
|
ICacheService cacheService
|
||
|
)
|
||
|
{
|
||
|
_wxUnifyUserRepository = wxUnifyUserRepository;
|
||
|
_currencyRecordRepository = currencyRecordRepository;
|
||
|
_userRepository = userRepository;
|
||
|
_cacheService = cacheService;
|
||
|
}
|
||
|
|
||
|
public async Task AddOrUpdateAsync(WxUnifyUserAddInput wxUnifyUser, string unionId)
|
||
|
{
|
||
|
var wxUser = await _wxUnifyUserRepository.GetAsync(x => x.UnionId == unionId && x.IsDeleted == false); ;
|
||
|
if (wxUser == null)
|
||
|
{
|
||
|
WxUnifyUserEntity entity = new WxUnifyUserEntity
|
||
|
{
|
||
|
UnionId = unionId,
|
||
|
NickName = wxUnifyUser.NickName,
|
||
|
AvatarUrl = wxUnifyUser.AvatarUrl,
|
||
|
Phone = wxUnifyUser.Phone.NotNull() ? wxUnifyUser.Phone : "",
|
||
|
Gender = wxUnifyUser.Gender,
|
||
|
Country = wxUnifyUser.City.NotNull() ? wxUnifyUser.City : "",
|
||
|
Province = wxUnifyUser.Province.NotNull() ? wxUnifyUser.Province : "",
|
||
|
City = wxUnifyUser.City.NotNull() ? wxUnifyUser.City : "",
|
||
|
Language = wxUnifyUser.Language
|
||
|
};
|
||
|
await _wxUnifyUserRepository.InsertAsync(entity);
|
||
|
WxUnifyUserOutput wxUnifyUserOutput = new WxUnifyUserOutput()
|
||
|
{
|
||
|
UnionId = unionId,
|
||
|
NickName = wxUnifyUser.NickName,
|
||
|
CreatedTime = DateTime.Now
|
||
|
};
|
||
|
//新用户信息添加进Redis缓存
|
||
|
await _cacheService.SetRegistUserListAsync(wxUnifyUser.NickName, DateTime.Now.ToTimestamp());
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
wxUser.NickName = wxUnifyUser.NickName;
|
||
|
wxUser.AvatarUrl = wxUnifyUser.AvatarUrl;
|
||
|
wxUser.Phone = wxUnifyUser.Phone.NotNull() ? wxUnifyUser.Phone : "";
|
||
|
wxUser.Gender = wxUnifyUser.Gender;
|
||
|
wxUser.Country = wxUnifyUser.City.NotNull() ? wxUnifyUser.City : "";
|
||
|
wxUser.Province = wxUnifyUser.Province.NotNull() ? wxUnifyUser.Province : "";
|
||
|
wxUser.City = wxUnifyUser.City.NotNull() ? wxUnifyUser.City : "";
|
||
|
await _wxUnifyUserRepository.UpdateAsync(wxUser);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|