180 lines
6.1 KiB
C#
180 lines
6.1 KiB
C#
using Infrastructure.Attribute;
|
|
using Microsoft.AspNetCore.Http;
|
|
using SqlSugar;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Infrastructure;
|
|
using ARW.Model;
|
|
using ARW.Repository;
|
|
using ARW.Repository.Business.ShopManager.Shops;
|
|
using ARW.Service.Business.IBusinessService.ShopManager.Shops;
|
|
using ARW.Model.Dto.Business.ShopManager.Shops;
|
|
using ARW.Model.Models.Business.ShopManager.Shops;
|
|
using ARW.Model.Vo.Business.ShopManager.Shops;
|
|
using MimeKit;
|
|
using ARW.Model.Models.Business.Custom.Customers;
|
|
using ARW.Repository.Business.Custom.Customers;
|
|
|
|
namespace ARW.Service.Business.BusinessService.ShopManager.Shops
|
|
{
|
|
/// <summary>
|
|
/// 店铺接口实现类
|
|
///
|
|
/// @author 黎文豪
|
|
/// @date 2023-06-09
|
|
/// </summary>
|
|
[AppService(ServiceType = typeof(IShopService), ServiceLifetime = LifeTime.Transient)]
|
|
public class ShopServiceImpl : BaseService<Shop>, IShopService
|
|
{
|
|
private readonly ShopRepository _ShopRepository;
|
|
private readonly CustomerRepository _CustomerRepository;
|
|
|
|
|
|
public ShopServiceImpl(ShopRepository ShopRepository, CustomerRepository customerRepository)
|
|
{
|
|
this._ShopRepository = ShopRepository;
|
|
_CustomerRepository = customerRepository;
|
|
}
|
|
|
|
#region 业务逻辑代码
|
|
|
|
|
|
/// <summary>
|
|
/// 查询店铺分页列表
|
|
/// </summary>
|
|
public async Task<PagedInfo<ShopVo>> GetShopList(ShopQueryDto parm)
|
|
{
|
|
//开始拼装查询条件d
|
|
var predicate = Expressionable.Create<Shop>();
|
|
|
|
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.ShopName), it => it.ShopName.Contains(parm.ShopName));
|
|
predicate = predicate.AndIF(parm.ShopAuditStatus != null, it => it.ShopAuditStatus == parm.ShopAuditStatus);
|
|
var query = _ShopRepository
|
|
.Queryable()
|
|
.Where(predicate.ToExpression())
|
|
.OrderBy(s => s.ShopSort, OrderByType.Asc)
|
|
.Select(s => new ShopVo
|
|
{
|
|
ShopId = s.ShopId,
|
|
ShopGuid = s.ShopGuid,
|
|
ShopUserId = s.ShopUserId,
|
|
ShopCustomerGuid = s.ShopCustomerGuid,
|
|
ShopBusinessCategoryGuid = s.ShopBusinessCategoryGuid,
|
|
ShopLogo = s.ShopLogo,
|
|
ShopBusinessLicense = s.ShopBusinessLicense,
|
|
ShopName = s.ShopName,
|
|
ShopIntro = s.ShopIntro,
|
|
ShopSort = s.ShopSort,
|
|
ShopSalesOrderCount = s.ShopSalesOrderCount,
|
|
ShopAuditStatus = s.ShopAuditStatus,
|
|
ShopAuditUserGuid = s.ShopAuditUserGuid,
|
|
});
|
|
|
|
|
|
return await query.ToPageAsync(parm);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加或修改店铺
|
|
/// </summary>
|
|
public async Task<string> AddOrUpdateShop(Shop model)
|
|
{
|
|
if (model.ShopId != 0)
|
|
{
|
|
var response = await _ShopRepository.UpdateAsync(model);
|
|
return "修改成功!";
|
|
}
|
|
else
|
|
{
|
|
|
|
var response = await _ShopRepository.InsertReturnSnowflakeIdAsync(model);
|
|
return "添加成功!";
|
|
}
|
|
}
|
|
|
|
#region Excel处理
|
|
|
|
|
|
/// <summary>
|
|
/// Excel数据导出处理
|
|
/// </summary>
|
|
public async Task<List<ShopVo>> HandleExportData(List<ShopVo> data)
|
|
{
|
|
return data;
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 获取未绑定的客户列表
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
public async Task<PagedInfo<CustomerWithOutBindVo>> GetCustomerWithOutBindList(CustomerWithOutBindQueryDto parm)
|
|
{
|
|
//开始拼装查询条件d
|
|
var predicate = Expressionable.Create<Customer>();
|
|
|
|
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.CustomerNickname), s => s.CustomerNickname .Contains(parm.CustomerNickname));
|
|
|
|
var query = _CustomerRepository
|
|
.Queryable()
|
|
.Where(predicate.ToExpression())
|
|
.Where(s => SqlFunc.Subqueryable<Shop>().Where(it => it.ShopCustomerGuid == s.CustomerGuid).NotAny())
|
|
.OrderBy(s => s.Update_time, OrderByType.Desc)
|
|
.Select((s) => new CustomerWithOutBindVo
|
|
{
|
|
CustomerGuid = s.CustomerGuid,
|
|
CustomerNickname = s.CustomerNickname,
|
|
});
|
|
|
|
return await query.ToPageAsync(parm);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 审核
|
|
/// </summary>
|
|
public async Task<string> Audit(int id, int status, long userGuid)
|
|
{
|
|
try
|
|
{
|
|
var res = await _ShopRepository.GetFirstAsync(s => s.ShopId == id);
|
|
await UseTranAsync(async () =>
|
|
{
|
|
await _ShopRepository.UpdateAsync(f => new Shop { ShopAuditStatus = status, ShopAuditUserGuid = userGuid, Update_time = DateTime.Now, Update_by = userGuid.ToString() }, s => s.ShopId == id);
|
|
});
|
|
if (res.ShopAuditStatus == 2)
|
|
{
|
|
var errorRes = $"店铺:【{res.ShopName}】<span style='color:red'>已通过审核!</span><br>";
|
|
return errorRes;
|
|
}
|
|
if (res.ShopAuditStatus == 3)
|
|
{
|
|
var errorRes = $"店铺:【{res.ShopName}】<span style='color:red'>已被驳回!</span><br>";
|
|
return errorRes;
|
|
}
|
|
else if (res.ShopAuditStatus == 1)
|
|
{
|
|
var addStr = $"店铺:【{res.ShopName}】<span style='color:#27af49'>审核通过!</span><br>";
|
|
return addStr;
|
|
}
|
|
return "";
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|