403 lines
18 KiB
C#
403 lines
18 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;
|
|
using ARW.Model.System;
|
|
using ARW.Repository.System;
|
|
using ARW.Model.Vo.Business.GoodsManager.GoodsCategorys;
|
|
using ARW.Repository.Business.GoodsManager.GoodsCategorys;
|
|
using ARW.Model.Models.Business.GoodsManager.GoodsCategorys;
|
|
using ARW.Service.System.IService;
|
|
using ARW.Service.System;
|
|
using MimeKit.Encodings;
|
|
using ARW.Model.Dto.Api.ShopManager.Shops;
|
|
using ARW.Model.Vo.Api.ShopManager.Shops;
|
|
using ARW.Model.Models.Business.GoodsManager.GoodsServicess;
|
|
using ARW.Model.Models.Business.LogisticsManage.DeliveryRules;
|
|
using ARW.Model.Models.Business.LogisticsManage.Deliverys;
|
|
using ARW.Service.Business.IBusinessService.GoodsManager.GoodsServicess;
|
|
using ARW.Service.Business.IBusinessService.LogisticsManage.Deliverys;
|
|
using Aliyun.OSS;
|
|
|
|
namespace ARW.Service.Business.BusinessService.ShopManager.Shops
|
|
{
|
|
/// <summary>
|
|
/// 店铺接口实现类
|
|
///
|
|
/// @author lwh
|
|
/// @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;
|
|
private readonly SysUserRepository _SysUserRepository;
|
|
private readonly GoodsCategoryRepository _GoodsCategoryRepository;
|
|
|
|
private readonly ISysUserService UserService;
|
|
private readonly ISysConfigService _SysConfigService;
|
|
private readonly IDeliveryService _DeliveryService;
|
|
private readonly IGoodsServicesService _GoodsServicesService;
|
|
|
|
public ShopServiceImpl(ShopRepository ShopRepository, CustomerRepository customerRepository, SysUserRepository sysUserRepository, GoodsCategoryRepository goodsCategoryRepository, ISysUserService userService, ISysConfigService sysConfigService, IDeliveryService deliveryService, IGoodsServicesService goodsServicesService)
|
|
{
|
|
this._ShopRepository = ShopRepository;
|
|
_CustomerRepository = customerRepository;
|
|
_SysUserRepository = sysUserRepository;
|
|
_GoodsCategoryRepository = goodsCategoryRepository;
|
|
UserService = userService;
|
|
_SysConfigService = sysConfigService;
|
|
_DeliveryService = deliveryService;
|
|
_GoodsServicesService = goodsServicesService;
|
|
}
|
|
|
|
#region 业务逻辑代码
|
|
|
|
|
|
/// <summary>
|
|
/// 查询店铺分页列表
|
|
/// </summary>
|
|
public async Task<PagedInfo<ShopVo>> GetShopList(ShopQueryDto parm)
|
|
{
|
|
//开始拼装查询条件d
|
|
var predicate = Expressionable.Create<Shop>();
|
|
|
|
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.ShopName), s => s.ShopName.Contains(parm.ShopName));
|
|
predicate = predicate.AndIF(parm.ShopAuditStatus != null, s => s.ShopAuditStatus == parm.ShopAuditStatus);
|
|
var query = _ShopRepository
|
|
.Queryable()
|
|
//.LeftJoin<SysUser>((s, c) => s.ShopUserId == c.UserId)
|
|
.LeftJoin<Customer>((s, d) => s.ShopCustomerGuid == d.CustomerGuid)
|
|
.LeftJoin<GoodsCategory>((s, d, f) => s.ShopBusinessCategoryGuid == f.GoodsCategoryGuid)
|
|
.Where(predicate.ToExpression())
|
|
.OrderBy(s => s.ShopSort, OrderByType.Asc)
|
|
.Select((s, d, f) => new ShopVo
|
|
{
|
|
CustomerNickname = d.CustomerNickname,
|
|
ShopBusinessCategoryName = f.GoodsCategoryName,
|
|
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,
|
|
CreateTime = s.Create_time.ToString("yyyy-MM-dd HH:mm")
|
|
});
|
|
|
|
|
|
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 isRepeat = await CheckRepeatShopName(model.ShopName);
|
|
if (isRepeat) throw new CustomException("商铺名称已存在");
|
|
model.ShopAuditStatus = 2;
|
|
model.ShopAuditUserGuid = 1;
|
|
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>
|
|
public async Task<List<GoodsCategoryVo>> GetFirstGoodsCategoryList()
|
|
{
|
|
var query = _GoodsCategoryRepository
|
|
.Queryable()
|
|
.Where(s => s.GoodsCategoryParentGuid == 0)
|
|
.OrderBy(s => s.Update_time, OrderByType.Desc)
|
|
.Select((s) => new GoodsCategoryVo
|
|
{
|
|
GoodsCategoryId = s.GoodsCategoryId,
|
|
GoodsCategoryGuid = s.GoodsCategoryGuid,
|
|
GoodsCategoryParentGuid = s.GoodsCategoryParentGuid,
|
|
GoodsCategoryAncestralGuid = s.GoodsCategoryAncestralGuid,
|
|
GoodsCategoryName = s.GoodsCategoryName,
|
|
GoodsCategoryImg = s.GoodsCategoryImg,
|
|
GoodsCategoryDisplayStatus = s.GoodsCategoryDisplayStatus,
|
|
GoodsCategoryIsPopular = s.GoodsCategoryIsPopular,
|
|
ProductCategorySort = s.ProductCategorySort,
|
|
});
|
|
|
|
return await query.ToListAsync();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取未绑定的用户列表
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
public async Task<PagedInfo<UserWithOutBindVo>> GetUserWithOutBindList(UserWithOutBindQueryDto parm)
|
|
{
|
|
//开始拼装查询条件d
|
|
var predicate = Expressionable.Create<SysUser>();
|
|
|
|
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.UserName), s => s.UserName.Contains(parm.UserName));
|
|
|
|
var query = _SysUserRepository
|
|
.Queryable()
|
|
.Where(predicate.ToExpression())
|
|
.Where(s => SqlFunc.Subqueryable<Shop>().Where(it => it.ShopUserId == s.UserId).NotAny())
|
|
.Where(s => s.UserId != 1)
|
|
.OrderBy(s => s.Update_time, OrderByType.Desc)
|
|
.Select((s) => new UserWithOutBindVo
|
|
{
|
|
UserId = s.UserId,
|
|
UserName = s.UserName,
|
|
});
|
|
|
|
return await query.ToPageAsync(parm);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取未绑定的客户列表
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
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>";
|
|
|
|
// 分发后台用户账户
|
|
var customer = await _CustomerRepository.GetFirstAsync(s => s.CustomerGuid == res.ShopCustomerGuid);
|
|
long[] roleId = new long[] { 3 };
|
|
int[] postId = Array.Empty<int>();
|
|
if (UserConstants.NOT_UNIQUE.Equals(UserService.CheckUserNameUnique(customer.CustomerMobilePhoneNumber)))
|
|
{
|
|
throw new Exception($"新增用户 '{customer.CustomerMobilePhoneNumber}'失败,登录账号已存在");
|
|
}
|
|
|
|
var initPassword = _SysConfigService.Queryable().First(f => f.ConfigKey == "sys.user.initPassword");
|
|
var password = NETCore.Encrypt.EncryptProvider.Md5(initPassword.ConfigValue);
|
|
var user = new SysUser
|
|
{
|
|
UserName = customer.CustomerMobilePhoneNumber,
|
|
NickName = customer.CustomerNickname,
|
|
Password = password,
|
|
Avatar = customer.CustomerAvatar,
|
|
Phonenumber = customer.CustomerMobilePhoneNumber,
|
|
Sex = customer.CustomerGender.ToString(),
|
|
Status = "0",
|
|
RoleIds = roleId,
|
|
PostIds = postId
|
|
};
|
|
var userId = UserService.InsertUser(user);
|
|
if (userId == 0) throw new Exception($"新增用户 '{customer.CustomerMobilePhoneNumber}'失败");
|
|
await _ShopRepository.UpdateAsync(f => new Shop
|
|
{
|
|
ShopUserId = (int?)userId,
|
|
}, s => s.ShopId == id);
|
|
|
|
// 给该用户的店铺添加默认数据
|
|
// 添加配送模板(全国包邮)
|
|
await HadnleAddDelivery(res.ShopGuid);
|
|
// 添加服务与承诺(七天无理由退货)
|
|
await HadnleAddGoodsService(res.ShopGuid);
|
|
|
|
// 修改客户类型为 商户(2)
|
|
await _CustomerRepository.UpdateAsync(f => new Customer
|
|
{
|
|
CustomerType = 2
|
|
}, s => s.CustomerGuid == res.ShopCustomerGuid);
|
|
|
|
|
|
return addStr;
|
|
}
|
|
return "";
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取商户店铺详情
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
public Task<string> GetShopOperatorDetail(ShopOperatorQueryDto parm)
|
|
{
|
|
|
|
var query = _ShopRepository
|
|
.Queryable()
|
|
.Where(s => s.ShopGuid == parm.ShopGuid)
|
|
.Select(s => new ShopDetailVo
|
|
{
|
|
ShopId = s.ShopId,
|
|
ShopGuid = s.ShopGuid,
|
|
ShopBusinessCategoryGuid = s.ShopBusinessCategoryGuid,
|
|
ShopLogo = s.ShopLogo,
|
|
ShopBusinessLicense = s.ShopBusinessLicense,
|
|
ShopName = s.ShopName,
|
|
ShopIntro = s.ShopIntro,
|
|
ShopSalesOrderCount = s.ShopSalesOrderCount,
|
|
}).Take(1);
|
|
|
|
|
|
return query.ToJsonAsync();
|
|
}
|
|
|
|
|
|
public async Task<bool> CheckRepeatShopName(string shopName)
|
|
{
|
|
var query = await _ShopRepository.GetFirstAsync(s => s.ShopName == shopName);
|
|
return query != null;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 添加配送模板(全国包邮)
|
|
/// </summary>
|
|
/// <param name="shopGuid">店铺guid</param>
|
|
/// <returns></returns>
|
|
public async Task HadnleAddDelivery(long shopGuid)
|
|
{
|
|
var deliveryRuleList = new List<DeliveryRule>();
|
|
var deliveryRule = new DeliveryRule
|
|
{
|
|
DeliveryRuleRegion = "2,20,38,61,76,84,103,123,148,165,177,194,205,218,229,240,246,259,266,273,285,299,314,332,347,357,367,371,384,393,403,418,426,438,445,458,463,477,488,496,504,511,518,526,533,541,549,554,562,570,578,589,599,606,611,619,626,632,638,648,667,684,694,703,712,722,733,744,749,760,767,778,783,801,813,821,832,839,849,858,865,873,883,890,897,904,911,925,936,949,957,963,970,980,987,992,1002,1013,1023,1032,1040,1048,1055,1060,1065,1076,1084,1093,1102,1108,1116,1121,1126,1135,1149,1156,1162,1175,1188,1200,1211,1219,1230,1240,1245,1251,1265,1268,1272,1291,1305,1316,1328,1342,1355,1366,1375,1382,1388,1401,1414,1426,1433,1438,1443,1456,1468,1477,1485,1496,1509,1519,1535,1546,1556,1562,1575,1586,1593,1600,1606,1613,1627,1637,1648,1659,1672,1686,1693,1702,1716,1726,1730,1736,1744,1753,1764,1771,1775,1789,1799,1809,1815,1828,1841,1851,1861,1866,1873,1885,1897,1910,1916,1926,1938,1949,1959,1963,1971,1977,1985,1995,2001,2010,2016,2025,2030,2037,2042,2051,2052,2053,2057,2063,2070,2083,2094,2112,2120,2125,2130,2135,2141,2149,2162,2168,2180,2187,2196,2201,2206,2207,2224,2264,2285,2292,2298,2306,2313,2323,2331,2337,2343,2355,2365,2372,2383,2390,2398,2407,2413,2417,2431,2450,2469,2480,2485,2500,2507,2516,2527,2536,2553,2567,2582,2592,2602,2608,2620,2626,2637,2646,2657,2671,2680,2684,2697,2703,2708,2713,2722,2741,2753,2761,2774,2786,2795,2809,2814,2827,2842,2854,2868,2880,2893,2904,2913,2922,2923,2926,2932,2940,2945,2952,2960,2968,2977,2985,2995,3004,3014,3022,3029,3034,3039,3045,3052,3059,3067,3074,3078,3084,3090,3095,3104,3109,3113,3117,3125,3130,3140,3150,3155,3168,3177,3189,3197,3216,3229,3268,3306,3336,3350,3358,3362,3365,3395,3408,3422,3436,3455,3482,3501,3522,3556,3573,3587,3595,3615",
|
|
DeliveryRuleRegionText = "北京,天津,河北省,山西省,内蒙古自治区,辽宁省,吉林省,黑龙江省,上海,江苏省,浙江省,安徽省,福建省,江西省,山东省,河南省,湖北省,湖南省,广东省,广西壮族自治区,海南省,重庆,四川省,贵州省,云南省,西藏自治区,陕西省,甘肃省,青海省,宁夏回族自治区,新疆维吾尔自治区,台湾省,香港特别行政区,澳门特别行政区",
|
|
DeliveryRuleFirst = 0,
|
|
DeliveryRuleFirstFee = 0,
|
|
DeliveryRuleAdditional = 0,
|
|
DeliveryRuleAdditionalFee = 0,
|
|
};
|
|
deliveryRuleList.Add(deliveryRule);
|
|
var delivery = new Delivery
|
|
{
|
|
ShopGuid = shopGuid,
|
|
DeliveryName = "全国包邮",
|
|
DeliveryBillingMethod = 1,
|
|
DeliverySort = 100,
|
|
DeliveryRuleDataList = deliveryRuleList
|
|
};
|
|
await _DeliveryService.AddOrUpdateDelivery(delivery);
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 添加服务与承诺(七天无理由退货)
|
|
/// </summary>
|
|
/// <param name="shopGuid">店铺guid</param>
|
|
/// <returns></returns>
|
|
public async Task HadnleAddGoodsService(long shopGuid)
|
|
{
|
|
var goodsService = new GoodsServices
|
|
{
|
|
ShopGuid = shopGuid,
|
|
GoodsServicesName = "七天无理由退货",
|
|
GoodsServicesSummary = "请确保商品完好,包邮商品买家承担退货运费,非包邮商品买家承担来回运费。",
|
|
GoodsServicesIsDefault = 1,
|
|
GoodsServicesDisplayStatus = 1,
|
|
GoodsServicesSort = 100
|
|
};
|
|
await _GoodsServicesService.AddOrUpdateGoodsServices(goodsService);
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|