micro_mall_api/ARW.Service/Business/BusinessService/LogisticsManage/DeliveryRules/DeliveryRuleService.cs

171 lines
6.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.LogisticsManage.DeliveryRules;
using ARW.Service.Business.IBusinessService.LogisticsManage.DeliveryRules;
using ARW.Model.Dto.Business.LogisticsManage.DeliveryRules;
using ARW.Model.Models.Business.LogisticsManage.DeliveryRules;
using ARW.Model.Vo.Business.LogisticsManage.DeliveryRules;
using Newtonsoft.Json;
using Senparc.Weixin.WxOpen.AdvancedAPIs.Tcb;
using System.Text.RegularExpressions;
using ARW.Model.Models.Business.LogisticsManage.Deliverys;
using ARW.Repository.Business.LogisticsManage.Deliverys;
using ARW.Model.Dto.Business.LogisticsManage.Deliverys;
using ARW.Model.Models.Business.ShopManager.Shops;
using ARW.Model.Vo.Business.LogisticsManage.Deliverys;
using ARW.Model.Models.Business.Custom.Regions;
using ARW.Repository.Business.Custom.Regions;
using ARW.Model.Vo.Business.Custom.Regions;
using Org.BouncyCastle.Crypto.Prng;
namespace ARW.Service.Business.BusinessService.LogisticsManage.DeliveryRules
{
/// <summary>
/// 配送模板区域及运费接口实现类
///
/// @author 黎文豪
/// @date 2023-06-16
/// </summary>
[AppService(ServiceType = typeof(IDeliveryRuleService), ServiceLifetime = LifeTime.Transient)]
public class DeliveryRuleServiceImpl : BaseService<DeliveryRule>, IDeliveryRuleService
{
private readonly DeliveryRuleRepository _DeliveryRuleRepository;
private readonly DeliveryRepository _DeliveryRepository;
private readonly RegionRepository _RegionRepository;
public DeliveryRuleServiceImpl(DeliveryRuleRepository DeliveryRuleRepository, DeliveryRepository deliveryRepository, RegionRepository regionRepository)
{
this._DeliveryRuleRepository = DeliveryRuleRepository;
_DeliveryRepository = deliveryRepository;
_RegionRepository = regionRepository;
}
#region
/// <summary>
/// 通过配送模板guid获取配送模板所关联的配送模板区域及运费列表
/// </summary>
public async Task<List<DeliveryRuleVo>> GetDeliveryRuleList(long deliveryGuid)
{
var query = _DeliveryRuleRepository
.Queryable()
.Where(s => s.DeliveryGuid == deliveryGuid)
.OrderBy(s => s.Create_time, OrderByType.Asc)
.Select(s => new DeliveryRuleVo
{
DeliveryRuleId = s.DeliveryRuleId,
DeliveryGuid = s.DeliveryGuid,
DeliveryRuleRegionName = s.DeliveryRuleRegion,
DeliveryRuleRegion = new List<SecondRegionVo>(),
DeliveryRuleRegionText = s.DeliveryRuleRegionText,
DeliveryRuleFirst = s.DeliveryRuleFirst,
DeliveryRuleFirstFee = s.DeliveryRuleFirstFee,
DeliveryRuleAdditional = s.DeliveryRuleAdditional,
DeliveryRuleAdditionalFee = s.DeliveryRuleAdditionalFee,
});
var list = await query.ToListAsync();
//foreach (var item in list)
//{
// List<int> DeliveryRuleRegionIds = item.DeliveryRuleRegionName.Split(',').Select(int.Parse).ToList();
// var regionList = new List<SecondRegionVo>();
// foreach (var id in DeliveryRuleRegionIds)
// {
// var region = await _RegionRepository.GetFirstAsync(s => s.RegionId == id);
// if (region == null) throw new CustomException($"找不到Id{id}的省市区数据");
// var data = new SecondRegionVo
// {
// Id = region.RegionId,
// Label = region.RegionName,
// Pid = region.RegionPid,
// Code = region.RegionCode
// };
// regionList.Add(data);
// }
// item.DeliveryRuleRegion = regionList;
//}
return list;
}
/// <summary>
/// 通过配送模板guid获取配送模板所关联的配送模板区域及运费guid
/// </summary>
/// <param name="deliveryGuid">配送模板guid</param>
/// <returns></returns>
public async Task<List<long>> GetDeliveryRuleGuidListByDeliveryGuid(long deliveryGuid)
{
var list = await _DeliveryRuleRepository.GetListAsync(f => f.DeliveryGuid == deliveryGuid);
//return list;
return list.Select(x => x.DeliveryRuleGuid).ToList();
}
/// <summary>
/// 通过配送模板guid获取配送模板所关联的配送模板区域及运费名称
/// </summary>
/// <param name="deliveryGuid">配送模板guid</param>
/// <returns></returns>
public async Task<string[]> GetDeliveryRuleNameByDeliveryGuid(long deliveryGuid)
{
var list = await _DeliveryRuleRepository
.Queryable()
.LeftJoin<DeliveryRule>((s, c) => s.DeliveryRuleGuid == c.DeliveryRuleGuid)
.Where((s, c) => s.DeliveryGuid == deliveryGuid)
.Select<DeliveryRule>()
.ToListAsync();
var res = list.Select(x => x.DeliveryRuleRegionText).ToArray();
return res;
//return string.Join(',', list.Select(x => x.DeliveryRuleName));
}
/// <summary>
/// 新增配送模板配送模板区域及运费
/// </summary>
/// <param name="deliveryRuleList">配送模板区域及运费列表</param>
public async Task InsertDeliveryRuleAsync(List<DeliveryRule> deliveryRuleList)
{
await _DeliveryRuleRepository.InsertRangeAsync(deliveryRuleList);
}
/// <summary>
/// 更新配送模板配送模板区域及运费
/// </summary>
/// <param name="deliveryRuleList">配送模板区域及运费列表</param>
/// <param name="deliveryGuid">配送模板guid</param>
/// <returns></returns>
public async Task UpdateDeliveryRuleAsync(List<DeliveryRule> deliveryRuleList, long deliveryGuid)
{
await _DeliveryRuleRepository.DeleteAsync(s => s.DeliveryGuid == deliveryGuid);
await _DeliveryRuleRepository.InsertRangeAsync(deliveryRuleList);
}
#endregion
}
}