123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- 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/pos/[controller]/[action]")]
- public class PosCouponOrdersController : BaseController
- {
- public PosCouponOrdersController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
- {
- }
- #region 创客-首页-客小爽产品-机具管理-券划拨记录
- [Authorize]
- public JsonResult List(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- List<Dictionary<string, object>> dataList = ListDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
- }
- public List<Dictionary<string, object>> ListDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客Id
- int Kind = int.Parse(function.CheckInt(data["Kind"].ToString()));
- 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<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
- IQueryable<PosCouponOrders> query = maindb.PosCouponOrders.Where(m => m.QueryCount == Kind && m.ChangeKind == ChangeKind && m.FromUserId == UserId).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<string, object> curData = new Dictionary<string, object>();
- curData.Add("Id", subdata.Id);
- curData.Add("ToUserId", subdata.ToUserId); //目标创客
- Dictionary<string, object> UserInfo = new Dictionary<string, object>();
- Users UsersData = maindb.Users.FirstOrDefault(m => m.Id == subdata.ToUserId) ?? new Users();
- string RealName = UsersData.RealName;
- if (RealName.Length > 2)
- {
- RealName = RealName.Substring(0, 1) + "*" + RealName.Substring(RealName.Length - 1);
- }
- else
- {
- RealName = RealName.Substring(0, 1) + "*";
- }
- UserInfo.Add("RealName", RealName); //真实姓名
- UserInfo.Add("MakerCode", UsersData.MakerCode); //创客编号
- curData.Add("UserInfo", UserInfo);
- curData.Add("ChangeCount", subdata.ChangeCount); //变更数量
- curData.Add("ChangeKind", subdata.ChangeKind); //变更类型
- curData.Add("CreateDate", subdata.CreateDate == null ? "" : subdata.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //CreateDate
- dataList.Add(curData);
- }
- return dataList;
- }
- #endregion
- #region 创客-首页-客小爽产品-机具管理-券划拨记录-详情
- [Authorize]
- public JsonResult Detail(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- Dictionary<string, object> Obj = DetailDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
- }
- public Dictionary<string, object> DetailDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- Dictionary<string, object> Obj = new Dictionary<string, object>();
- int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
- PosCouponOrders query = maindb.PosCouponOrders.FirstOrDefault(m => m.Id == Id) ?? new PosCouponOrders();
- string OrderNo = query.OrderNo;
- Obj.Add("ToUserId", query.ToUserId); //目标创客
- Dictionary<string, object> UserInfo = new Dictionary<string, object>();
- Users UsersData = maindb.Users.FirstOrDefault(m => m.Id == query.ToUserId) ?? new Users();
- UserInfo.Add("RealName", UsersData.RealName); //真实姓名
- UserInfo.Add("MakerCode", UsersData.MakerCode); //创客编号
- UserInfo.Add("Mobile", UsersData.Mobile); //手机号
- Obj.Add("UserInfo", UserInfo);
- Obj.Add("ChangeCount", query.ChangeCount); //变更数量
- Obj.Add("ChangeKind", query.ChangeKind); //变更类型
- Obj.Add("CreateDate", query.CreateDate); //创建时间
- List<PosCouponRecord> list = maindb.PosCouponRecord.Where(m => m.OrderNo == OrderNo).ToList();
- List<string> codes = new List<string>();
- string CodeType = "";
- foreach (PosCouponRecord sub in list)
- {
- int PosCouponId = sub.PosCouponId;
- PosCoupons coupon = maindb.PosCoupons.FirstOrDefault(m => m.Id == PosCouponId);
- if (coupon != null)
- {
- codes.Add(coupon.ExchangeCode);
- if (coupon.ExchangeCode.StartsWith("02")) CodeType = "电签兑换券";
- if (coupon.ExchangeCode.StartsWith("03")) CodeType = "大机兑换券";
- }
- }
- Obj.Add("Codes", codes); //机具券列表
- Obj.Add("CodeType", CodeType); //券类型
- return Obj;
- }
- #endregion
- #region 检查签名是否合法,合法返回1,不合法返回提示信息
- /// <summary>
- /// 检查签名是否合法,合法返回1,不合法返回提示信息
- /// </summary>
- /// <param name="value">请求的参数(json字符串)</param>
- /// <param name="signField">要签名的字段</param>
- /// <returns></returns>
- private string CheckSign(string value, string[] signField)
- {
- JsonData json = JsonMapper.ToObject(value);
- Dictionary<string, string> dic = new Dictionary<string, string>();
- 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
- }
- }
|