| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- /*
- * 盟主兑换机具券
- */
- using System;
- using System.Web;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Threading.Tasks;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Http;
- using Microsoft.Extensions.Logging;
- using Microsoft.Extensions.Options;
- using MySystem.Models;
- using Library;
- using LitJson;
- using MySystemLib;
- namespace MySystem.Areas.Admin.Controllers
- {
- [Area("Admin")]
- [Route("Admin/[controller]/[action]")]
- public class LeaderReserveRecordController : BaseController
- {
- public LeaderReserveRecordController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
- {
- OtherMySqlConn.connstr = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
- }
- #region 盟主兑换机具券列表
- /// <summary>
- /// 根据条件查询盟主兑换机具券列表
- /// </summary>
- /// <returns></returns>
- public IActionResult Index(LeaderReserveRecord data, string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- #endregion
- #region 根据条件查询盟主兑换机具券列表
- /// <summary>
- /// 根据条件查询盟主兑换机具券列表
- /// </summary>
- /// <returns></returns>
- public JsonResult IndexData(LeaderReserveRecord data, string UserIdMakerCode, string SourceMakerCode, string RemarkSelect, string CreateDateData, int page = 1, int limit = 30)
- {
- Dictionary<string, string> Fields = new Dictionary<string, string>();
- Fields.Add("SeoKeyword", "1"); //订单编号
- string condition = " and Status>-1";
- //创客编号
- if (!string.IsNullOrEmpty(UserIdMakerCode))
- {
- condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
- }
- //购券创客
- if (!string.IsNullOrEmpty(SourceMakerCode))
- {
- condition += " and SourceUserId in (select UserId from UserForMakerCode where MakerCode='" + SourceMakerCode + "')";
- }
- //变动类型
- if (!string.IsNullOrEmpty(RemarkSelect))
- {
- condition += " and Remark='" + RemarkSelect + "'";
- }
- //创建时间
- if (!string.IsNullOrEmpty(CreateDateData))
- {
- string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
- string start = datelist[0];
- string end = datelist[1];
- condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
- }
- Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("LeaderReserveRecord", Fields, "Id desc", "0", page, limit, condition);
- List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
- foreach (Dictionary<string, object> dic in diclist)
- {
- //创客
- int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
- Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
- UserAccount userAccount = db.UserAccount.FirstOrDefault(m => m.Id == UserId) ?? new UserAccount();
- dic["LeaderBalanceAmount"] = userAccount.LeaderBalanceAmount;
- dic["UserIdMakerCode"] = userid_Users.MakerCode;
- dic["UserIdRealName"] = userid_Users.RealName;
- dic.Remove("UserId");
- //购券创客
- int SourceUserId = int.Parse(function.CheckInt(dic["SourceUserId"].ToString()));
- if (SourceUserId > 0)
- {
- Users sourceUser = db.Users.FirstOrDefault(m => m.Id == SourceUserId) ?? new Users();
- dic["SourceMakerCode"] = sourceUser.MakerCode;
- dic.Remove("SourceUserId");
- }
- // else
- // {
- // int OrderId = int.Parse(function.CheckInt(dic["OrderId"].ToString()));
- // var order = db.Orders.FirstOrDefault(m => m.Id == OrderId) ?? new Orders();
- // Users sourceUser = db.Users.FirstOrDefault(m => m.Id == order.UserId) ?? new Users();
- // dic["SourceMakerCode"] = sourceUser.MakerCode;
- // dic.Remove("OrderId");
- // }
- // //购券创客
- // int SourceUserId = int.Parse(function.CheckInt(dic["SourceUserId"].ToString()));
- // Users sourceUser = db.Users.FirstOrDefault(m => m.Id == SourceUserId) ?? new Users();
- // dic["SourceMakerCode"] = sourceUser.MakerCode;
- // dic.Remove("SourceUserId");
- // //订单来源创客
- // int OrderId = int.Parse(function.CheckInt(dic["OrderId"].ToString()));
- // var order = db.Orders.FirstOrDefault(m => m.Id == OrderId) ?? new Orders();
- // Users sourceOrderUser = db.Users.FirstOrDefault(m => m.Id == order.UserId) ?? new Users();
- // dic["SourceOrderMakerCode"] = sourceOrderUser.MakerCode;
- // dic.Remove("OrderId");
- //订单信息
- JsonData ApplyList = JsonMapper.ToObject(dic["SeoTitle"].ToString());//申请数据
- dic["dPosCoupons"] = "";
- dic["bPosCoupons"] = "";
- if (!string.IsNullOrEmpty(dic["SeoTitle"].ToString()))
- {
- for (int i = 0; i < ApplyList.Count; i++)
- {
- int num = Convert.ToInt32(ApplyList[i]["Num"].ToString());
- int type = Convert.ToInt32(ApplyList[i]["Type"].ToString());
- if (type == 1)
- {
- dic["dPosCoupons"] = num + "张";
- }
- else
- {
- dic["bPosCoupons"] = num + "张";
- }
- }
- }
- //券码
- int OrderId = int.Parse(function.CheckInt(dic["Id"].ToString()));
- if (OrderId >= 2300)
- {
- var info = db.UserSnDelayChange.Where(m => m.QueryCount == OrderId).ToList();
- var PosCoupons = "";
- foreach (var item in info)
- {
- PosCoupons += item.SnNo + ",";
- }
- dic["PosCoupons"] = PosCoupons;
- }
- else
- {
- dic["PosCoupons"] = dic["SeoDescription"].ToString();
- }
- }
- return Json(obj);
- }
- #endregion
- #region 快捷导出Excel
- public JsonResult QuickExportExcel(LeaderReserveRecord data, string UserIdMakerCode, string SourceMakerCode, string RemarkSelect, string CreateDateData, string SeoKeyword)
- {
- string SqlString = " and Status>-1";
- //创客编号
- if (!string.IsNullOrEmpty(UserIdMakerCode))
- {
- SqlString += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
- }
- //购券创客
- if (!string.IsNullOrEmpty(SourceMakerCode))
- {
- SqlString += " and SourceUserId in (select UserId from UserForMakerCode where MakerCode='" + SourceMakerCode + "')";
- }
- //变动类型
- if (!string.IsNullOrEmpty(RemarkSelect))
- {
- SqlString += " and Remark='" + RemarkSelect + "'";
- }
- //创建时间
- if (!string.IsNullOrEmpty(CreateDateData))
- {
- string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
- string start = datelist[0];
- string end = datelist[1];
- SqlString += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
- }
- //订单编号
- if (!string.IsNullOrEmpty(SeoKeyword))
- {
- SqlString += " and SeoKeyword=" + SeoKeyword;
- }
- // 创客姓名、创客编号、创建时间、变动类型、电签兑换券张数、大POS兑换券张数、可提现余额、使用前剩余额度、使用后剩余额度
- var sysAdmin = bsdb.SysAdmin.FirstOrDefault(m => m.AdminName == SysUserName && m.Status > -1);
- var FileName = "盟主储蓄金变动记录";
- string SendData = "{\"Operater\":\"" + sysAdmin.Id + "\",\"SqlString\":\"" + SqlString + "\",\"FileName\":\"" + FileName + "\",\"MaxCount\":\"0\"}";
- RedisDbconn.Instance.AddList("ExportQueue", SendData);
- return Json("result");
- }
- #endregion
- #region 导出Excel
- /// <summary>
- /// 导出Excel
- /// </summary>
- /// <returns></returns>
- public JsonResult ExportExcel(LeaderReserveRecord data, string UserIdMakerCode, string CreateDateData, string LeaderLevelSelect)
- {
- Dictionary<string, string> Fields = new Dictionary<string, string>();
- string condition = " and Status>-1";
- //创客创客编号
- if (!string.IsNullOrEmpty(UserIdMakerCode))
- {
- condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
- }
- //盟主等级
- if (!string.IsNullOrEmpty(LeaderLevelSelect))
- {
- condition += " and LeaderLevel=" + LeaderLevelSelect;
- }
- //创建时间
- if (!string.IsNullOrEmpty(CreateDateData))
- {
- string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
- string start = datelist[0];
- string end = datelist[1];
- condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
- }
- Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("Leaders", Fields, "Id desc", "0", 1, 20000, condition, "UserId,LeaderLevel,CreateDate", false);
- List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
- foreach (Dictionary<string, object> dic in diclist)
- {
- //创客
- int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
- Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
- dic["UserIdMakerCode"] = userid_Users.MakerCode;
- dic["UserIdRealName"] = userid_Users.RealName;
- dic.Remove("UserId");
- //盟主等级
- int LeaderLevel = int.Parse(dic["LeaderLevel"].ToString());
- if (LeaderLevel == 1) dic["LeaderLevel"] = "小盟主";
- if (LeaderLevel == 2) dic["LeaderLevel"] = "大盟主";
- if (LeaderLevel == 0) dic["LeaderLevel"] = "";
- }
- Dictionary<string, object> result = new Dictionary<string, object>();
- result.Add("Status", "1");
- result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
- result.Add("Obj", diclist);
- Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
- ReturnFields.Add("UserIdMakerCode", "创客创客编号");
- ReturnFields.Add("UserIdRealName", "创客真实姓名");
- ReturnFields.Add("LeaderLevel", "盟主等级");
- ReturnFields.Add("CreateDate", "创建时间");
- result.Add("Fields", ReturnFields);
- AddSysLog("0", "Leaders", "ExportExcel");
- return Json(result);
- }
- #endregion
- }
- }
|