NewGaoKaoApi/New_College.Api/Controllers/Back/VipCardController.cs

202 lines
7.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using New_College.IServices;
using New_College.Model;
using New_College.Model.Models;
using New_College.Model.ViewModels;
using New_College.Model.ViewModels.Query;
namespace New_College.Api.Controllers.Back
{
[Route("api/back/[controller]/[action]")]
[ApiController]
public class VipCardController : ControllerBase
{
private readonly IV_VipCardInfoServices iV_VipCardInfoServices;
private readonly IV_VipCardTypeServices iV_VipCardTypeServices;
private readonly IV_OrderInfoServices iV_OrderInfoServices;
private readonly IV_CustomerInfoServices _CustomerInfoServices;
private readonly ID_UserSettingBaseServices d_UserSettingBase;
public VipCardController(IV_VipCardInfoServices IV_VipCardInfoServices, IV_VipCardTypeServices IV_VipCardTypeServices, IV_OrderInfoServices IV_OrderInfoServices, IV_CustomerInfoServices customerInfoServices, ID_UserSettingBaseServices userSettingBaseServices)
{
iV_VipCardInfoServices = IV_VipCardInfoServices;
iV_VipCardTypeServices = IV_VipCardTypeServices;
iV_OrderInfoServices = IV_OrderInfoServices;
_CustomerInfoServices = customerInfoServices;
d_UserSettingBase = userSettingBaseServices;
}
/// <summary>
/// 生成卡信息
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
[HttpPost]
public async Task<MessageModel<List<string>>> AutoVipCardInfo([FromBody] AutoVipInfoQuery query)
{
return await iV_VipCardInfoServices.AutoVipCardInfo(query);
}
/// <summary>
/// 获取分页
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
[HttpGet]
public async Task<MessageModel<PageModel<VipCardInfoResult>>> GetVipCardInfoByPage([FromQuery] VipCardInfoSearchQuery query)
{
return await iV_VipCardInfoServices.GetVipCardInfoByPage(query);
}
/// <summary>
/// 获取单个
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
[HttpGet]
public async Task<MessageModel<VipCardInfoResultOne>> GetVipCardInfoOne([FromQuery] IdQuery query)
{
return await iV_VipCardInfoServices.GetVipCardInfoOne(query);
}
/// <summary>
/// 添加
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
[HttpPost]
public async Task<MessageModel<bool>> AddVipCardInfo([FromBody] VipCardInfoQuery query)
{
return await iV_VipCardInfoServices.AddVipCardInfo(query);
}
/// <summary>
/// 修改
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
[HttpPut]
public async Task<MessageModel<bool>> UpdateVipCardInfo(VipCardInfoQuery query)
{
return await iV_VipCardInfoServices.UpdateVipCardInfo(query);
}
/// <summary>
/// 删除
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
[HttpPost]
public async Task<MessageModel<bool>> DeleteVipCardInfo([FromBody] IdQuery query)
{
return await iV_VipCardInfoServices.DeleteVipCardInfo(query);
}
/// <summary>
/// 获取vipcardTypeList
/// </summary>
/// <returns></returns>
[HttpPost]
public async Task<List<VipCardTypeQuery>> GetVipCardType()
{
return await iV_VipCardTypeServices.GetVipCardType();
}
/// <summary>
///
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
[HttpGet]
[AllowAnonymous]
public async Task<bool> Init([FromQuery] string key)
{
if (key == "brapuk6fon0wachiMlth2t3lb4a0h7ji")
{
await d_UserSettingBase.UpdateBaseInit();
return true;
}
else
return false;
}
/// <summary>
/// 根据用户是否为Vip获取相应权限
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
[HttpGet]
public async Task<VipPowerRolesViewsDTO> CheckRoles([FromQuery] IdQuery query)
{
var response = new VipPowerRolesViewsDTO();
var custom = await _CustomerInfoServices.Query(c => c.Id == query.CustomerId);
if (custom.Any())
{
var tellist = SHanDongTel.Tel.Split("|").ToList();
if (tellist.Contains(custom.FirstOrDefault().Phone))
{
return new VipPowerRolesViewsDTO()
{
IsVip = true,
minProRole = new MinProRole()
{
ScoreCount = 99,
SearchCount = 99,
ShowCount = 99
},
pcRole = new PCRole()
{
ScoreCount = 99,
SearchCount = 99,
ShowCount = 99
}
};
}
var isverfiy = await d_UserSettingBase.Query(c => c.CustomerId == query.CustomerId);
if (!isverfiy.Any())
{
await d_UserSettingBase.SyncBaseInfo(new UserSettingBaseRequest() { CustomerId = query.CustomerId.Value });
}
response.IsVip = custom.FirstOrDefault().IsVIP;
var list = await d_UserSettingBase.GetUserBaseSettings(new UserSettingBaseRequest() { CustomerId = query.CustomerId.Value });
response.pcRole = list.Where(e => e.PType == 0).Select(c => new PCRole()
{
ScoreCount = c.ScoreCount,
SearchCount = c.SearchCount,
ShowCount = c.ShowCount
}).FirstOrDefault();
response.minProRole = list.Where(e => e.PType == 1).Select(c => new MinProRole()
{
ScoreCount = response.IsVip ? 999 : c.ScoreCount,
SearchCount = response.IsVip ? 999 : c.SearchCount,
ShowCount = response.IsVip ? 999 : c.ShowCount
}).FirstOrDefault();
}
else
{
response.IsVip = true;
response.pcRole = new PCRole()
{
ScoreCount = 3,
SearchCount = 10,
ShowCount = 10
};
response.minProRole = new MinProRole()
{
ScoreCount = 3,
SearchCount = 10,
ShowCount = 10
};
}
return response;
}
}
}