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 ARW.Model; using ARW.Repository; using ARW.Repository.Business.ShopManager.Shops; using ARW.Service.Api.IBusinessService.ShopManager.Shops; using ARW.Model.Dto.Api.ShopManager.Shops; using ARW.Model.Models.Business.ShopManager.Shops; using ARW.Model.Vo.Api.ShopManager.Shops; using ARW.Model.Vo.Business.GoodsManager.GoodsCategorys; using ARW.Repository.Business.GoodsManager.GoodsCategorys; using ARW.Repository.Business.Custom.Customers; using ARW.Model.Models.Business.Custom.Customers; using ARW.Repository.Business.LogisticsManage.Deliverys; using ARW.Service.Business.IBusinessService.LogisticsManage.Deliverys; using ARW.Service.Business.IBusinessService.GoodsManager.Goodss; using ARW.Model.Models.Business.LogisticsManage.Deliverys; using ARW.Model.Models.Business.LogisticsManage.DeliveryRules; using ARW.Service.Business.IBusinessService.GoodsManager.GoodsServicess; using ARW.Model.Models.Business.GoodsManager.GoodsServicess; namespace ARW.Service.Api.BusinessService.ShopManager.Shops { /// /// 店铺接口实现类Api /// /// @author lwh /// @date 2023-06-12 /// [AppService(ServiceType = typeof(IShopServiceApi), ServiceLifetime = LifeTime.Transient)] public class ShopServiceImplApi : BaseService, IShopServiceApi { private readonly ShopRepository _ShopRepository; private readonly GoodsCategoryRepository _GoodsCategoryRepository; private readonly CustomerRepository _CustomerRepository; public ShopServiceImplApi(ShopRepository ShopRepository, GoodsCategoryRepository goodsCategoryRepository, CustomerRepository customerRepository) { this._ShopRepository = ShopRepository; _GoodsCategoryRepository = goodsCategoryRepository; _CustomerRepository = customerRepository; } #region Api接口代码 /// /// 获取经营类目列表(一级类目) /// /// /// public async Task> GetFirstGoodsCategoryList() { var query = _GoodsCategoryRepository .Queryable() .OrderBy(s => s.Update_time, OrderByType.Desc) .Select((s) => new GoodsCategoryVoApi { ParentGuid = s.GoodsCategoryParentGuid, Label = s.GoodsCategoryName, Value = s.GoodsCategoryGuid, }); return await query.ToTreeAsync(it => it.Children, it => it.ParentGuid, 0); } /// /// 查询店铺列表(Api) /// /// /// public async Task> GetShopListApi(ShopQueryDtoApi parm) { //开始拼装查询条件d var predicate = Expressionable.Create(); 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.Desc) .Select(s => new ShopVoApi { 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); } /// /// 查询店铺详情(Api) /// /// /// public Task GetShopDetails(ShopDtoApi parm) { var query = _ShopRepository .Queryable() .Where(s => s.ShopGuid == parm.ShopGuid) .Select(s => new ShopApiDetailsVo { 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 AddOrUpdateShop(Shop model) { if (model.ShopId != 0) { var response = await _ShopRepository.UpdateAsync(model); return "修改成功!"; } else { // 判断客户类型是否为商户 var customer = await _CustomerRepository.GetFirstAsync(s => s.CustomerGuid == model.ShopCustomerGuid); if (customer == null) throw new Exception("找不到该客户"); if (customer.CustomerType == 2) { return "您已经是商户"; } model.ShopAuditStatus = 1; model.ShopSort = 100; var response = await _ShopRepository.InsertReturnSnowflakeIdAsync(model); return "申请成功!"; } } #endregion } }