using System; using System.Collections.Generic; using System.Linq; using System.Data; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Microsoft.AspNetCore.Authorization; using System.Web; using MySystem.MainModels; using LitJson; using Library; namespace MySystem.Areas.Api.Controllers.v1.pos { [Area("Api")] [Route("Api/v1/[controller]/[action]")] public class PosCouponOrdersController : BaseController { public PosCouponOrdersController(IHttpContextAccessor accessor, ILogger logger, IOptions setting) : base(accessor, logger, setting) { } #region 创客-首页-客小爽产品-码牌管理-划拨记录 [Authorize] public JsonResult List(string value) { value = DesDecrypt(value); JsonData data = JsonMapper.ToObject(value); Dictionary other = new Dictionary(); List> dataList = ListDo(value, out other); return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = other }); } public List> ListDo(string value, out Dictionary other) { JsonData data = JsonMapper.ToObject(value); int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客Id int ChangeKind = int.Parse(function.CheckInt(data["ChangeKind"].ToString())); // 1-拨入,2-拨出 int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString())); int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString())); List> dataList = new List>(); IQueryable query = maindb.PosCouponOrders; if(ChangeKind == 1) { query = query.Where(m => m.ToUserId == UserId); } else { query = query.Where(m => m.FromUserId == UserId); } query = query.OrderByDescending(m => m.Id); if (PageNum == 1) { query = query.Take(PageSize); } else { int skipNum = PageSize * (PageNum - 1); query = query.Skip(skipNum).Take(PageSize); } foreach (var subdata in query.ToList()) { Dictionary curData = new Dictionary(); curData.Add("Id", subdata.Id); string RealName = ""; string MakerCode = ""; if(ChangeKind == 1) { KxsMainModels.Users user = kxsdb.Users.FirstOrDefault(m => m.Id == subdata.FromUserId) ?? new KxsMainModels.Users(); RealName = function.CheckNull(user.RealName); MakerCode = function.CheckNull(user.MakerCode); if(string.IsNullOrEmpty(RealName)) RealName = "成都总仓"; } else { KxsMainModels.Users user = kxsdb.Users.FirstOrDefault(m => m.Id == subdata.ToUserId) ?? new KxsMainModels.Users(); RealName = function.CheckNull(user.RealName); MakerCode = function.CheckNull(user.MakerCode); } if (RealName.Length > 2 && RealName != "成都总仓") { RealName = RealName.Substring(0, 1) + "*" + RealName.Substring(RealName.Length - 1); } else if(!string.IsNullOrEmpty(RealName) && RealName != "成都总仓") { RealName = RealName.Substring(0, 1) + "*"; } curData.Add("RealName", RealName); //真实姓名 curData.Add("MakerCode", MakerCode); //创客编号 curData.Add("ChangeCount", subdata.ChangeCount); //变更数量 curData.Add("CreateDate", subdata.CreateDate == null ? "" : subdata.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //CreateDate dataList.Add(curData); } other = new Dictionary(); if(PageNum == 1) { DataTable dt = CustomerSqlConn.dtable("select (select count(Id) from PosCouponOrders where FromUserId=" + UserId + "),(select count(Id) from PosCouponOrders where ToUserId=" + UserId + ")", AppConfig.Base.SqlConnStr); if(dt.Rows.Count > 0) { other.Add("FromTotalCount", dt.Rows[0][1].ToString()); other.Add("ToTotalCount", dt.Rows[0][0].ToString()); } } return dataList; } #endregion #region 创客-首页-客小爽产品-码牌管理-划拨记录-详情 [Authorize] public JsonResult Detail(string value) { value = DesDecrypt(value); JsonData data = JsonMapper.ToObject(value); Dictionary Obj = DetailDo(value); return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj }); } public Dictionary DetailDo(string value) { JsonData data = JsonMapper.ToObject(value); Dictionary Obj = new Dictionary(); int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); int Id = int.Parse(function.CheckInt(data["Id"].ToString())); PosCouponOrders query = maindb.PosCouponOrders.FirstOrDefault(m => m.Id == Id) ?? new PosCouponOrders(); string OrderNo = query.OrderNo; Dictionary UserInfo = new Dictionary(); string RealName = ""; string MakerCode = ""; string Mobile = ""; if(query.ToUserId == UserId) { KxsMainModels.Users user = kxsdb.Users.FirstOrDefault(m => m.Id == query.FromUserId) ?? new KxsMainModels.Users(); RealName = function.CheckNull(user.RealName); MakerCode = function.CheckNull(user.MakerCode); Mobile = function.CheckNull(user.Mobile); if(string.IsNullOrEmpty(RealName)) RealName = "成都总仓"; } else { KxsMainModels.Users user = kxsdb.Users.FirstOrDefault(m => m.Id == query.ToUserId) ?? new KxsMainModels.Users(); RealName = function.CheckNull(user.RealName); MakerCode = function.CheckNull(user.MakerCode); Mobile = function.CheckNull(user.Mobile); } if (RealName.Length > 2 && RealName != "成都总仓") { RealName = RealName.Substring(0, 1) + "*" + RealName.Substring(RealName.Length - 1); } else if(!string.IsNullOrEmpty(RealName) && RealName != "成都总仓") { RealName = RealName.Substring(0, 1) + "*"; } Obj.Add("RealName", RealName); //真实姓名 Obj.Add("MakerCode", MakerCode); //创客编号 Obj.Add("Mobile", Mobile); //手机号 Obj.Add("ChangeCount", query.ChangeCount); //变更数量 Obj.Add("ChangeKind", query.ChangeKind); //变更类型 Obj.Add("CreateDate", query.CreateDate); //创建时间 List posids = maindb.PosCouponRecord.Where(m => m.OrderNo == query.OrderNo).ToList().Select(m => m.PosCouponId).ToList(); List list = maindb.PosMachinesTwo.Where(m => posids.Contains(m.Id)).ToList().Select(m => m.PosSn).ToList(); Obj.Add("SnNoList", list); //机具券列表 return Obj; } #endregion #region 检查签名是否合法,合法返回1,不合法返回提示信息 /// /// 检查签名是否合法,合法返回1,不合法返回提示信息 /// /// 请求的参数(json字符串) /// 要签名的字段 /// private string CheckSign(string value, string[] signField) { JsonData json = JsonMapper.ToObject(value); Dictionary dic = new Dictionary(); for (int i = 0; i < signField.Length; i++) { dic.Add(signField[i], json[signField[i]].ToString()); } string sign = json["sign"].ToString(); //客户端签名字符串 return new Sign().sign(dic, sign); } #endregion } }