129 lines
5.6 KiB
C#
129 lines
5.6 KiB
C#
using Infrastructure.Attribute;
|
|
using SqlSugar;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using ARW.Model;
|
|
using ARW.Repository;
|
|
using ARW.Service.Api.IBusinessService.Custom.Customers;
|
|
using ARW.Model.Dto.Api.Custom.Customers;
|
|
using ARW.Model.Vo.Api.Custom.Customers;
|
|
using ARW.Model.Models.Business.Custom.Customers;
|
|
using ARW.Repository.Business.Custom.Customers;
|
|
using ARW.Repository.Business.Custom.GoodsCollections;
|
|
using ARW.Repository.Business.Custom.GoodsBrowsingHistorys;
|
|
using ARW.Repository.Business.OrderManage.Orders;
|
|
using ARW.Model.Vo.Api.GoodsManager.Goodss;
|
|
using Newtonsoft.Json;
|
|
using Senparc.CO2NET.Extensions;
|
|
using ARW.Repository.Business.OrderManage.OrderRefunds;
|
|
|
|
namespace ARW.Service.Api.BusinessService.Custom.Customers
|
|
{
|
|
/// <summary>
|
|
/// 小程序客户接口实现类Api
|
|
///
|
|
/// @author lwh
|
|
/// @date 2023-06-07
|
|
/// </summary>
|
|
[AppService(ServiceType = typeof(ICustomerServiceApi), ServiceLifetime = LifeTime.Transient)]
|
|
public class CustomerServiceImplApi : BaseService<Customer>, ICustomerServiceApi
|
|
{
|
|
private readonly CustomerRepository _CustomerRepository;
|
|
private readonly GoodsCollectionRepository _GoodsCollectionRepository;
|
|
private readonly GoodsBrowsingHistoryRepository _GoodsBrowsingHistoryRepository;
|
|
private readonly OrderRepository _OrderRepository;
|
|
private readonly OrderRefundRepository _OrderRefundRepository;
|
|
|
|
public CustomerServiceImplApi(CustomerRepository CustomerRepository, GoodsCollectionRepository goodsCollectionRepository, GoodsBrowsingHistoryRepository goodsBrowsingHistoryRepository, OrderRepository orderRepository, OrderRefundRepository orderRefundRepository)
|
|
{
|
|
this._CustomerRepository = CustomerRepository;
|
|
_GoodsCollectionRepository = goodsCollectionRepository;
|
|
_GoodsBrowsingHistoryRepository = goodsBrowsingHistoryRepository;
|
|
_OrderRepository = orderRepository;
|
|
_OrderRefundRepository = orderRefundRepository;
|
|
}
|
|
|
|
#region Api接口代码
|
|
|
|
|
|
/// <summary>
|
|
/// 查询小程序客户详情(Api)
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
public async Task<string> GetCustomerDetails(CustomerQueryDtoApi parm)
|
|
{
|
|
|
|
var query = _CustomerRepository
|
|
.Queryable()
|
|
.Where(s => s.CustomerGuid == parm.CustomerGuid)
|
|
.Select(s => new CustomerApiDetailsVo
|
|
{
|
|
CustomerId = s.CustomerId,
|
|
CustomerGuid = s.CustomerGuid,
|
|
CustomerXcxOpenid = s.CustomerXcxOpenid,
|
|
CustomerNickname = s.CustomerNickname,
|
|
CustomerMobilePhoneNumber = s.CustomerMobilePhoneNumber,
|
|
CustomerAvatar = s.CustomerAvatar,
|
|
CustomerGender = s.CustomerGender,
|
|
CustomerType = s.CustomerType
|
|
}).Take(1);
|
|
|
|
|
|
var json = await query.ToJsonAsync();
|
|
|
|
if (json != "[]")
|
|
{
|
|
json = json.Remove(0, 1);
|
|
json = json.Substring(0, json.Length - 1);
|
|
var data = JsonConvert.DeserializeObject<CustomerApiDetailsVo>(json);
|
|
|
|
// 获取收藏数量
|
|
data.CollectCount = await _GoodsCollectionRepository.CountAsync(s => s.CustomerGuid == data.CustomerGuid);
|
|
// 获取历史搜索数量
|
|
data.HistoryCount = await _GoodsBrowsingHistoryRepository.CountAsync(s => s.CustomerGuid == data.CustomerGuid);
|
|
// 获取待付款数量
|
|
data.WaitPayCount = await _OrderRepository.CountAsync(s => s.CustomerGuid == data.CustomerGuid
|
|
&& s.PayStatus == 1 && s.OrderStatus == 1);
|
|
// 获取待发货数量
|
|
data.DeliverCount = await _OrderRepository.CountAsync(s => s.CustomerGuid == data.CustomerGuid
|
|
&& s.DeliveryStatus == 1 && s.PayStatus == 2 && s.OrderStatus == 1);
|
|
// 获取待收货数量
|
|
data.PackageCount = await _OrderRepository.CountAsync(s => s.CustomerGuid == data.CustomerGuid
|
|
&& s.ReceiptStatus == 1 && s.DeliveryStatus == 2
|
|
&& s.PayStatus == 2 && s.OrderStatus == 1);
|
|
// 获取待评价数量
|
|
data.CommentCount = await _OrderRepository.CountAsync(s => s.CustomerGuid == data.CustomerGuid
|
|
&& s.IsComment == 1 && s.PayStatus == 2 && s.OrderStatus == 4);
|
|
// 获取退款/售后数量
|
|
data.ExchangCount = await _OrderRefundRepository.CountAsync(s => s.CustomerGuid == data.CustomerGuid && s.OrderRefundStatus == 1);
|
|
|
|
json = data.ToJson();
|
|
}
|
|
|
|
return json;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 编辑客户信息
|
|
/// </summary>
|
|
public async Task<string> UpdateCustomer(Customer model)
|
|
{
|
|
var response = await _CustomerRepository.UpdateAsync(f => new Customer
|
|
{
|
|
CustomerAvatar = model.CustomerAvatar,
|
|
CustomerNickname = model.CustomerNickname,
|
|
CustomerGender = model.CustomerGender,
|
|
}, s => s.CustomerGuid == model.CustomerGuid);
|
|
return "修改成功!";
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|