123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- 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 PosCouponsController : BaseController
- {
- public PosCouponsController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
- {
- }
- #region 创客-首页-客小爽产品-机具管理-机具申请-要兑换的券
- [Authorize]
- public JsonResult ExchangeCoupons(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- Dictionary<string, object> Other = new Dictionary<string, object>();
- List<Dictionary<string, object>> dataList = ExchangeCouponsDo(value, out Other);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Other });
- }
- public List<Dictionary<string, object>> ExchangeCouponsDo(string value, out Dictionary<string, object> Other)
- {
- JsonData data = JsonMapper.ToObject(value);
- int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客
- int Kind = int.Parse(function.CheckInt(data["Kind"].ToString()));//券类型
- 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<PosCoupons> query = maindb.PosCoupons.Where(m => m.UserId == UserId && m.QueryCount == Kind && m.IsUse == 0 && m.IsLock == 0 && m.HelpProfitMerchantId == 0 && m.HelpProfitStatus == 0 && m.HelpProfitFlag == 0);
- 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>();
- int IsLeader = 0;//是否为大盟主机(0-否 1-是)
- if (subdata.LeaderUserId > 0)
- {
- IsLeader = 1;
- }
- else
- {
- IsLeader = 0;
- }
- curData.Add("ExchangeCode", subdata.ExchangeCode); //兑换码
- curData.Add("Id", subdata.Id); //Id
- curData.Add("Kind", subdata.QueryCount); //券类型
- int day = 0;
- if (subdata.UpdateDate != null)
- {
- TimeSpan ts = subdata.UpdateDate.Value - DateTime.Now;
- day = ts.Days;
- }
- curData.Add("RecycDays", day); //循环剩余天数
- curData.Add("EndDate", subdata.UpdateDate == null ? "" : subdata.UpdateDate.Value.ToString("yyyy-MM-dd")); //截止日期
- List<int> ProductType = new List<int>();
- if (subdata.QueryCount == 1)
- {
- ProductType.Add(1);
- ProductType.Add(2);
- ProductType.Add(4);
- ProductType.Add(6);
- ProductType.Add(7);
- ProductType.Add(8);
- ProductType.Add(10);
- }
- else if (subdata.QueryCount == 2)
- {
- ProductType.Add(3);
- ProductType.Add(5);
- ProductType.Add(9);
- ProductType.Add(11);
- }
- curData.Add("ProductType", ProductType);
- curData.Add("IsLeader",IsLeader);
- dataList.Add(curData);
- }
- Other = new Dictionary<string, object>();
- if (PageNum == 1)
- {
- Other.Add("NotUseCount", maindb.PosCoupons.Count(m => m.UserId == UserId && m.IsUse == 0 && m.QueryCount == 1 && m.HelpProfitFlag == 0));
- Other.Add("UsedCount", maindb.PosCoupons.Count(m => m.UserId == UserId && m.IsUse == 1 && m.QueryCount == 1));
- Other.Add("NotUseCount2", maindb.PosCoupons.Count(m => m.UserId == UserId && m.IsUse == 0 && m.QueryCount == 2 && m.HelpProfitFlag == 0));
- Other.Add("UsedCount2", maindb.PosCoupons.Count(m => m.UserId == UserId && m.IsUse == 1 && m.QueryCount == 2));
- }
- return dataList;
- }
- #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
- }
- }
|