97 lines
3.0 KiB
C#
97 lines
3.0 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace Application.Web.Admin.Controllers;
|
|
|
|
public class SendMailController : Controller
|
|
{
|
|
private readonly IMessageService _messageService;
|
|
private readonly IGameGoodsService _goodsService;
|
|
private readonly IUnitUserService _userService;
|
|
public SendMailController(IMessageService messageService,IGameGoodsService goodsService,IUnitUserService userService)
|
|
{
|
|
_messageService = messageService;
|
|
_goodsService = goodsService;
|
|
_userService = userService;
|
|
}
|
|
|
|
// GET
|
|
public IActionResult Index()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> Send(string id, string name, string sign, string awData, int goods, int count, string remark, int type)
|
|
{
|
|
string url = "/SendMail/Index";
|
|
List<TowerGet> award = new List<TowerGet>();
|
|
if (string.IsNullOrEmpty(awData))
|
|
{
|
|
if (goods != 0)
|
|
{
|
|
var goodsInfo = await _goodsService.GetGoodsInfo(goods);
|
|
if (goodsInfo == null)
|
|
{
|
|
TempData["msg"] = "物品不存在!";
|
|
return Redirect(url);
|
|
}
|
|
TowerGet add = new TowerGet();
|
|
add.code = GameEnum.PropCode.Goods.ToString();
|
|
add.name = goodsInfo.goodsName;
|
|
add.parameter = goods.ToString();
|
|
add.count = count;
|
|
award.Add(add);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
award = JsonConvert.DeserializeObject<List<TowerGet>>(awData);
|
|
}
|
|
int index = 0;
|
|
List<string> users = new List<string>();
|
|
if (type == 0)
|
|
{
|
|
string[] ids = id.Split(',');
|
|
foreach (string item in ids)
|
|
{
|
|
var userInfo = await _userService.GetUserInfoByUserNo(item.Trim());
|
|
if (userInfo == null)
|
|
{
|
|
continue;
|
|
}
|
|
index++;
|
|
users.Add(userInfo.userId);
|
|
}
|
|
}
|
|
else if (type == 1)
|
|
{
|
|
DateTime time = TimeAssist.GetDateTimeYMD(0);
|
|
var data = await _userService.GetOnlineUserByTime(TimeExtend.GetTimeStampBySeconds(time));
|
|
foreach (var item in data)
|
|
{
|
|
users.Add(item.userId);
|
|
index++;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var data = await _userService.GetOnlineUserByTime(0);
|
|
foreach (var item in data)
|
|
{
|
|
users.Add(item.userId);
|
|
index++;
|
|
}
|
|
}
|
|
if (await _messageService.SendMaill(users, name, sign, award))
|
|
{
|
|
TempData["msg"] = string.Format("发放成功,共完成{0}个!", index);
|
|
return Redirect(url);
|
|
}
|
|
else
|
|
{
|
|
TempData["msg"] = "发放失败!";
|
|
return Redirect(url);
|
|
}
|
|
}
|
|
} |