| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304 |
- using System;
- using System.Collections.Generic;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Configuration;
- using SuperCms.Extensions;
- using SuperAdmin.Source;
- using Microsoft.AspNetCore.Http;
- using System.IO;
- using ReportWeb.Models;
- using ReportWeb;
- using System.Data;
- using Newtonsoft.Json;
- using ReportWeb.Source;
- using OfficeOpenXml;
- using ClosedXML.Excel;
- using ReportWebCore.Models.Http;
- namespace SuperAdmin.Controllers
- {
- public class LuckySpinController : BaseController
- {
- private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program));
- DbConnector db = new DbConnector();
- List<Services> listService;
- String sdf = "dd/MM/yyyy HH:mm";
- String df = "dd/MM/yyyy";
- public LuckySpinController(IConfiguration _configuration, IWebHostEnvironment hostEnvironment) : base(_configuration, hostEnvironment)
- {
- // init
- }
- // SPIN
- public ActionResult PrizeWinner()
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null || (user.role <= 0))
- {
- return Redirect(subDomain + "/Home/Login");
- }
- else
- {
- return View();
- }
- }
- [HttpPost]
- public JsonResult PrizeWinnerSearch(String msisdn, String period, String fromDate, String toDate)
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null || user.role <= 0)
- {
- ViewBag.username = "Welcome!";
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- msisdn = validateMsisdn(msisdn);
- //if (msisdn == null || msisdn == "")
- //{
- // return Json(new
- // {
- // error = "1",
- // content = "Enter msisdn"
- // });
- //}
- DateTime startTime = DateTime.ParseExact(fromDate, df, null);
- DateTime endTime = DateTime.ParseExact(toDate, df, null);
- List<PrizeObj> listPrize = db.GetListPrizeWinner(msisdn, period, startTime, endTime);
- return Json(new
- {
- error = "0",
- listPrize = listPrize
- });
- }
- [HttpPost]
- public IActionResult PrizeWinnerExport(String msisdn, String period, String fromDate, String toDate)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Not allow"
- });
- }
- return ExportPrizeWinner(msisdn, period, fromDate, toDate);
- }
- private FileContentResult ExportPrizeWinner(String msisdn, String period, String fromDate, String toDate)
- {
- try
- {
- ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
- msisdn = validateMsisdn(msisdn);
- DateTime startTime = DateTime.ParseExact(fromDate, df, null);
- DateTime endTime = DateTime.ParseExact(toDate, df, null);
- List<PrizeObj> list = db.GetListPrizeWinner(msisdn, period, startTime, endTime);
- string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
- string fileName = "report_prize_winner.xlsx";
- using (var workbook = new XLWorkbook())
- {
- int i = 1;
- IXLWorksheet worksheet = workbook.Worksheets.Add("Report Prize Winner");
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "No.";
- worksheet.Column(i).Width = 20;
- worksheet.Cell(1, i++).Value = "Phone number";
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "Period";
- worksheet.Column(i).Width = 25;
- worksheet.Cell(1, i++).Value = "Prize";
- worksheet.Column(i).Width = 25;
- worksheet.Cell(1, i++).Value = "Spin Time";
- worksheet.Column(i).Width = 25;
- worksheet.Cell(1, i++).Value = "Process Time";
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "Status";
- // make color
- worksheet.Row(1).Style.Font.Bold = true;
- worksheet.Row(1).Style.Fill.BackgroundColor = XLColor.Yellow;
- //worksheet.Cell(1, i++).Value = "BetId";
- if (list != null && list.Count > 0)
- {
- for (int index = 1; index <= list.Count; index++)
- {
- i = 1;
- var news = list[index - 1];
- worksheet.Cell(index + 1, i++).Value = index;
- worksheet.Cell(index + 1, i++).SetValue(news.msisdn);
- worksheet.Cell(index + 1, i++).SetValue(news.period == 1 ? "DAILY" : news.period == 2 ? "WEEKLY" : news.period == 3 ? "MONTHLY" : "PROMOTION");
- worksheet.Cell(index + 1, i++).SetValue(news.prize_name2);
- worksheet.Cell(index + 1, i++).SetValue(news.code_time.Value.ToString("dd/MM/yyyy HH:mm:ss"));
- worksheet.Cell(index + 1, i++).SetValue(news.process_time == null ? "" : news.process_time.Value.ToString("dd/MM/yyyy HH:mm:ss"));
- worksheet.Cell(index + 1, i++).SetValue(news.status == 0 ? "Success" : "Failure");
- }
- }
- using (var stream = new MemoryStream())
- {
- workbook.SaveAs(stream);
- var content = stream.ToArray();
- return File(content, contentType, fileName);
- }
- }
- }
- catch (Exception ex)
- {
- return null;
- }
- }
- // SPIN
- public ActionResult Ranking()
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null || (user.role <= 0))
- {
- return Redirect(subDomain + "/Home/Login");
- }
- else
- {
- return View();
- }
- }
- [HttpPost]
- public JsonResult GetRanking(String msisdn, String month)
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null || user.role <= 0)
- {
- ViewBag.username = "Welcome!";
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- msisdn = validateMsisdn(msisdn);
- List<UserCoin> rankingCoin = db.GetRankingCoin(msisdn, month, 100);
- SearchModel model = new SearchModel();
- model.rankingCoin = rankingCoin;
- return Json(new
- {
- error = "0",
- model = model
- });
- }
- [HttpPost]
- public IActionResult RankingExport(String msisdn, String month)
- {
- if (!CheckAuthToken())
- {
- return Json(new
- {
- error = "-1",
- content = "Not allow"
- });
- }
- return ExportRanking(msisdn, month);
- }
- private FileContentResult ExportRanking(String msisdn, String month)
- {
- try
- {
- ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
- msisdn = validateMsisdn(msisdn);
- msisdn = validateMsisdn(msisdn);
- List<UserCoin> list = db.GetRankingCoin(msisdn, month, 0);
- string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
- string fileName = "ranking.xlsx";
- using (var workbook = new XLWorkbook())
- {
- int i = 1;
- IXLWorksheet worksheet = workbook.Worksheets.Add("Ranking");
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "No.";
- worksheet.Column(i).Width = 20;
- worksheet.Cell(1, i++).Value = "Phone number";
- worksheet.Column(i).Width = 15;
- worksheet.Cell(1, i++).Value = "Total coin";
- worksheet.Column(i).Width = 20;
- worksheet.Cell(1, i++).Value = "Month";
- worksheet.Column(i).Width = 20;
- worksheet.Cell(1, i++).Value = "Package";
- worksheet.Column(i).Width = 25;
- worksheet.Cell(1, i++).Value = "Last Update";
- // make color
- worksheet.Row(1).Style.Font.Bold = true;
- worksheet.Row(1).Style.Fill.BackgroundColor = XLColor.Yellow;
- //worksheet.Cell(1, i++).Value = "BetId";
- if (list != null && list.Count > 0)
- {
- for (int index = 1; index <= list.Count; index++)
- {
- i = 1;
- var news = list[index - 1];
- worksheet.Cell(index + 1, i++).SetValue(news.rank);
- worksheet.Cell(index + 1, i++).SetValue(news.msisdn);
- worksheet.Cell(index + 1, i++).SetValue(news.total_coin);
- worksheet.Cell(index + 1, i++).SetValue(month);
- worksheet.Cell(index + 1, i++).SetValue(news.product_name);
- worksheet.Cell(index + 1, i++).SetValue(news.last_update.Value.ToString("dd/MM/yyyy HH:mm:ss"));
- }
- }
- using (var stream = new MemoryStream())
- {
- workbook.SaveAs(stream);
- var content = stream.ToArray();
- return File(content, contentType, fileName);
- }
- }
- }
- catch (Exception ex)
- {
- return null;
- }
- }
- [HttpPost]
- public JsonResult AddMoneyRanking(String id)
- {
- Users user = HttpContext.Session.GetComplexData<Users>("user");
- if (user == null || user.role <= 0)
- {
- ViewBag.username = "Welcome!";
- return Json(new
- {
- error = "10",
- content = "Timeout"
- });
- }
- ErrResponse dbRes = db.ProcessPrizeTop(long.Parse(id));
- return Json(new
- {
- error = dbRes.error,
- content = dbRes.message
- });
- }
- }
- }
|