| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- /*
- * 电签券兑换记录
- */
- 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 PosCouponExchangeRecordController : BaseController
- {
- public PosCouponExchangeRecordController(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(PosCouponExchangeRecord data, string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- #endregion
- #region 根据条件查询电签券兑换记录列表
- /// <summary>
- /// 电签券兑换记录列表
- /// </summary>
- /// <returns></returns>
- public JsonResult IndexData(PosCouponExchangeRecord data, string UserIdMakerCode, string CreateDateData, int page = 1, int limit = 30)
- {
- Dictionary<string, string> Fields = new Dictionary<string, string>();
- string condition = "";
- //来源创客编号
- if (!string.IsNullOrEmpty(UserIdMakerCode))
- {
- condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
- }
- 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'";
- }
- //来源券码
- if (!string.IsNullOrEmpty(data.SourceCoupons))
- {
- condition += " and SourceCoupons like '%" + data.SourceCoupons + "%'";
- }
- //兑换券码
- if (!string.IsNullOrEmpty(data.ToCoupons))
- {
- condition += " and ToCoupons like '%" + data.ToCoupons + "%'";
- }
- Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("PosCouponExchangeRecord", 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 Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
- dic["UserIdMakerCode"] = Users.MakerCode;
- dic["UserIdRealName"] = Users.RealName;
- dic.Remove("UserId");
- }
- return Json(obj);
- }
- #endregion
- #region 导出Excel
- /// <summary>
- /// 导出Excel
- /// </summary>
- /// <returns></returns>
- public JsonResult ExportExcel(PosCouponExchangeRecord data, string UserIdMakerCode, string CreateDateData)
- {
- Dictionary<string, string> Fields = new Dictionary<string, string>();
- string condition = "";
- //来源创客编号
- if (!string.IsNullOrEmpty(UserIdMakerCode))
- {
- condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
- }
- 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'";
- }
- //来源券码
- if (!string.IsNullOrEmpty(data.SourceCoupons))
- {
- condition += " and SourceCoupons like '%" + data.SourceCoupons + "%'";
- }
- //兑换券码
- if (!string.IsNullOrEmpty(data.ToCoupons))
- {
- condition += " and ToCoupons like '%" + data.ToCoupons + "%'";
- }
- Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("PosCouponExchangeRecord", Fields, "Id desc", "0", 1, 20000, condition, "FromUserId,ToUserId,OrderNo,BeforeStock,BeforeTotal,BeforeOut,AfterStock,AfterTotal,AfterOut,ChangeCount,ChangeKind", 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 Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
- dic["UserIdMakerCode"] = Users.MakerCode;
- dic["UserIdRealName"] = Users.RealName;
- dic.Remove("UserId");
- }
- 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("SourceCount", "来源券数量");
- ReturnFields.Add("ToCount", "兑换券数量");
- ReturnFields.Add("SourceCoupons", "来源券");
- ReturnFields.Add("ToCoupons", "兑换券");
- result.Add("Fields", ReturnFields);
- AddSysLog("0", "PosCouponExchangeRecord", "ExportExcel");
- return Json(result);
- }
- #endregion
- }
- }
|