81 lines
4.0 KiB
C#
81 lines
4.0 KiB
C#
using Exceptionless.Models;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using Microsoft.Extensions.Configuration;
|
||
using System.Text;
|
||
using Zxd.Core.Shared;
|
||
using Zxd.Crm.Domain.Dto;
|
||
using Zxd.Crm.Domain.Impl;
|
||
using Zxd.Entity.CompanyBaseConf;
|
||
|
||
//using WX.CRM.Common;
|
||
|
||
namespace Zxd.Crm.WebApi.Controllers
|
||
{
|
||
[ApiSignatureFilterForbid]
|
||
public class ProductController : BaseController
|
||
{
|
||
private readonly IConfiguration _configuration;
|
||
private readonly IBaseRepository<ZxdDbContext> _zxdRepository;
|
||
|
||
public ProductController(IConfiguration configuration, IBaseRepository<ZxdDbContext> zxdRepository)
|
||
{
|
||
_configuration = configuration;
|
||
_zxdRepository = zxdRepository;
|
||
}
|
||
|
||
//根据坐席id获取对应可授权产品数据
|
||
[HttpGet("GetProductByAppid")]
|
||
public PageResult<WxSzzySubproduct> GetProductByAppid([FromQuery] GetProductByAppidDto dto)
|
||
{
|
||
try
|
||
{
|
||
List<WxSzzySubproduct> res = new List<WxSzzySubproduct>();
|
||
//List<Domain.Dto.DeptmentDto> departmentList = new List<Domain.Dto.DeptmentDto>();
|
||
// 1 拿到所有本事业部的所有部门数据
|
||
var systemConfig = _configuration.GetSection("SystemConfig").Get<SystemConfig>();
|
||
var url = systemConfig.GetDeptsUrl();
|
||
var req = HttpHelper.GetData(url, "", Encoding.UTF8);
|
||
var resModel = JsonHelper.FromJson<CommonApiResult<List<Domain.Dto.DeptmentDto>>>(req);
|
||
if (resModel.code == 0)
|
||
{
|
||
var departmentList = resModel.data.Where(d => d.appid == dto.appid).ToList();
|
||
var CompanyCodeList = departmentList.Select(d => d.companyCode).ToList();
|
||
// 2 根据部门code,找出所有相关的产品
|
||
//var channelList = _zxdRepository.GetRepository<WxSzzySubproductCh>().Query();
|
||
var productList = _zxdRepository.GetRepository<WxSzzySubproduct>().Query();
|
||
var channelQ = _zxdRepository.GetRepository<WxSzzySubproductCh>().Query().Where(c => c.isEmpower == 1 && (CompanyCodeList.Contains(c.companycode)));
|
||
var channelList = channelQ.Skip((dto.PageIndex - 1) * dto.PageSize)
|
||
.Take(dto.PageSize)
|
||
.ToList();
|
||
var count = channelQ.Count();
|
||
var productListByCh = channelList.Select(ch => new WxSzzySubproduct
|
||
{
|
||
subproductid = ch.subproductid,
|
||
subproductname = ch.subproductname,
|
||
isEmpower = ch.isEmpower,
|
||
productcode = productList.FirstOrDefault(p => p.subproductid == ch.subproductid)?.productcode,
|
||
price = productList.FirstOrDefault(p => p.subproductid == ch.subproductid)?.price,
|
||
producttype = productList.FirstOrDefault(p => p.subproductid == ch.subproductid)?.producttype,
|
||
mid = productList.FirstOrDefault(p => p.subproductid == ch.subproductid)?.mid
|
||
})?.ToList();
|
||
|
||
//List<WxSzzySubproduct> data = productListByCh.Skip((dto.PageIndex - 1) * dto.PageSize)
|
||
// .Take(dto.PageSize)
|
||
// .ToList();
|
||
Log.Information("获取可赋权产品数据:" + productListByCh);
|
||
return new PageResult<WxSzzySubproduct>(dto.PageIndex, dto.PageSize, count, productListByCh);
|
||
}
|
||
else
|
||
{
|
||
Log.Error("获取部门数据失败");
|
||
return new PageResult<WxSzzySubproduct>(dto.PageIndex, dto.PageSize, 0, new List<WxSzzySubproduct>());
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Log.Error("获取可赋权产品数据失败:" + ex.ToString());
|
||
return new PageResult<WxSzzySubproduct>(dto.PageIndex, dto.PageSize, 0, new List<WxSzzySubproduct>());
|
||
}
|
||
}
|
||
}
|
||
} |