123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502 |
- 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 PosMachinesController : BaseController
- {
- public PosMachinesController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
- {
- }
- #region 首页-客小爽产品-机具管理-已绑定机具列表
- [Authorize]
- public JsonResult MyMachinesForBind(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- Dictionary<string, object> Other = new Dictionary<string, object>();
- List<Dictionary<string, object>> dataList = MyMachinesForBindDo(value, out Other);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Other });
- }
- public List<Dictionary<string, object>> MyMachinesForBindDo(string value, out Dictionary<string, object> Other)
- {
- JsonData data = JsonMapper.ToObject(value);
- int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //所属创客
- int BrandId = int.Parse(function.CheckInt(data["BrandId"].ToString())); //产品类型
- string SnNo = data["SnNo"].ToString(); //SN号
- 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>>();
- if (!string.IsNullOrEmpty(SnNo))
- {
- PageSize = 100000;
- }
- IQueryable<PosMachinesTwo> query = maindb.PosMachinesTwo.Where(m => m.Status > -1 && m.BuyUserId == UserId && m.BrandId == BrandId && m.BindingState == 1);
- if (!string.IsNullOrEmpty(SnNo))
- {
- query = query.Where(m => m.PosSn == SnNo);
- }
- Other = new Dictionary<string, object>();
- if (PageNum == 1)
- {
- Other.Add("count", query.Count());
- 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("ActivationState", subdata.ActivationState == 1 ? "已激活" : "未激活"); //激活状态
- curData.Add("PosSn", subdata.PosSn); //SN编号
- curData.Add("PosSnType", RelationClass.GetPosSnTypeInfo(subdata.PosSnType)); //机具类型
- curData.Add("Id", subdata.Id); //Id
- decimal Deposit = 299;
- if (BrandId == 6)
- {
- Deposit = 249;
- }
- if (!string.IsNullOrEmpty(subdata.PrizeParams))
- {
- Deposit = decimal.Parse(function.CheckNum(subdata.PrizeParams));
- }
- curData.Add("Deposit", Deposit);
- curData.Add("BindedMerchant", subdata.BuyUserId != subdata.UserId ? 1 : 0); //是否已绑定商户型创客
- curData.Add("IsLeader",IsLeader);
- dataList.Add(curData);
- }
- return dataList;
- }
- #endregion
- #region 首页-客小爽产品-机具管理-总机具列表
- [Authorize]
- public JsonResult MyMachines(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- Dictionary<string, object> Other = new Dictionary<string, object>();
- List<Dictionary<string, object>> dataList = MyMachinesDo(value, out Other);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Other });
- }
- public List<Dictionary<string, object>> MyMachinesDo(string value, out Dictionary<string, object> Other)
- {
- JsonData data = JsonMapper.ToObject(value);
- int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //所属创客
- int BrandId = int.Parse(function.CheckInt(data["BrandId"].ToString())); //产品类型
- string SnNo = data["SnNo"].ToString(); //SN号
- 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>>();
- if (!string.IsNullOrEmpty(SnNo))
- {
- PageSize = 100000;
- }
- IQueryable<PosMachinesTwo> query = maindb.PosMachinesTwo.Where(m => m.Status > -1 && m.BuyUserId == UserId && m.BrandId == BrandId);
- if (!string.IsNullOrEmpty(SnNo))
- {
- query = query.Where(m => m.PosSn == SnNo);
- }
- Other = new Dictionary<string, object>();
- if (PageNum == 1)
- {
- Other.Add("count", query.Count());
- 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("PosSn", subdata.PosSn); //SN编号
- curData.Add("PosSnType", RelationClass.GetPosSnTypeInfo(subdata.PosSnType)); //机具类型
- curData.Add("Id", subdata.Id); //Id
- curData.Add("CreateDate", subdata.TransferTime == null ? "" : subdata.TransferTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); //CreateDate
- StoreHouse store = StoreHouseDbconn.Instance.Get(subdata.StoreId) ?? new StoreHouse();
- curData.Add("FromStore", store.StoreName); //来自仓库
- decimal Deposit = 299;
- if (BrandId == 6)
- {
- Deposit = 249;
- }
- if (!string.IsNullOrEmpty(subdata.PrizeParams))
- {
- Deposit = decimal.Parse(function.CheckNum(subdata.PrizeParams));
- }
- curData.Add("Deposit", Deposit);
- curData.Add("IsLeader",IsLeader);
- dataList.Add(curData);
- }
- return dataList;
- }
- #endregion
- #region 首页-客小爽产品-机具管理-未绑定机具列表
- [Authorize]
- public JsonResult MyMachinesForUnBind(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- Dictionary<string, object> Other = new Dictionary<string, object>();
- List<Dictionary<string, object>> dataList = MyMachinesForUnBindDo(value, out Other);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Other });
- }
- public List<Dictionary<string, object>> MyMachinesForUnBindDo(string value, out Dictionary<string, object> Other)
- {
- JsonData data = JsonMapper.ToObject(value);
- int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //所属创客
- int BrandId = int.Parse(function.CheckInt(data["BrandId"].ToString())); //产品类型
- string SnNo = data["SnNo"].ToString(); //SN号
- 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>>();
- if (!string.IsNullOrEmpty(SnNo))
- {
- PageSize = 100000;
- }
- IQueryable<PosMachinesTwo> query = maindb.PosMachinesTwo.Where(m => m.Status > -1 && m.BuyUserId == UserId && m.BrandId == BrandId && m.BindingState == 0);
- if (!string.IsNullOrEmpty(SnNo))
- {
- query = query.Where(m => m.PosSn == SnNo && m.PosSnType == 0);
- }
- Other = new Dictionary<string, object>();
- if (PageNum == 1)
- {
- Other.Add("count", query.Count());
- 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("PosSn", subdata.PosSn); //SN编号
- curData.Add("PosSnType", RelationClass.GetPosSnTypeInfo(subdata.PosSnType)); //机具类型
- curData.Add("Id", subdata.Id); //Id
- if (subdata.RecycEndDate != null)
- {
- TimeSpan ts = subdata.RecycEndDate.Value - DateTime.Now;
- curData.Add("ActDays", ts.TotalDays.ToString("f0")); //活动剩余天数
- }
- else
- {
- curData.Add("ActDays", 0); //活动剩余天数
- }
- curData.Add("CreateDate", subdata.CreateDate.Value.ToString("yyyy-MM-dd")); //机具初始日期
- curData.Add("EndDate", subdata.RecycEndDate == null ? "" : subdata.RecycEndDate.Value.ToString("yyyy-MM-dd")); //截止日期
- decimal Deposit = 299;
- if (BrandId == 6)
- {
- Deposit = 249;
- }
- if (!string.IsNullOrEmpty(subdata.PrizeParams))
- {
- Deposit = decimal.Parse(function.CheckNum(subdata.PrizeParams));
- }
- curData.Add("Deposit", Deposit);
- curData.Add("IsLeader",IsLeader);
- dataList.Add(curData);
- }
- return dataList;
- }
- #endregion
- #region 首页-客小爽产品-机具管理-已绑定机具列表-设置商户型创客(立刷)
- [Authorize]
- public JsonResult SetMerchantMaker(string value)
- {
- //TODO: 要做一下判断机具是否是当前操作人本人
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- int SnId = int.Parse(function.CheckInt(data["SnId"].ToString()));
- int UserId = int.Parse(function.CheckInt(data["UserId"].ToString()));
- Users user = maindb.Users.FirstOrDefault(m => m.Id == UserId);
- if (user != null)
- {
- if (user.MerchantType == 1)
- {
- return Json(new AppResultJson() { Status = "-1", Info = "创客" + user.MakerCode + "已是商户型创客,请勿重复设置" });
- }
- if (user.AuthFlag != 1)
- {
- return Json(new AppResultJson() { Status = "-1", Info = "创客" + user.MakerCode + "未实名认证" });
- }
- bool checkPos = maindb.PosMachinesTwo.Any(m => m.Status > -1 && m.UserId == user.Id);
- if (checkPos)
- {
- return Json(new AppResultJson() { Status = "-1", Info = "创客" + user.MakerCode + "已拥有机具" });
- }
- PosMachinesTwo pos = maindb.PosMachinesTwo.FirstOrDefault(m => m.Status > -1 && m.Id == SnId);
- if (pos != null)
- {
- if (!function.CheckNull(user.ParentNav).Contains("," + pos.BuyUserId + ","))
- {
- return Json(new AppResultJson() { Status = "-1", Info = "创客" + user.MakerCode + "不在您可操作的系统内" });
- }
- pos.UserId = user.Id;
- user.MerchantType = 1;
- string MerNo = "";
- PosMerchantInfo merchant = maindb.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
- if (merchant != null)
- {
- merchant.UserId = user.Id;
- merchant.MerUserType = 1;
- MerNo = merchant.MerchantName;
- }
- pos.SeoTitle = user.Id.ToString(); // 记录商户型创客的Id
- maindb.SetMerchantTypeRecord.Add(new SetMerchantTypeRecord()
- {
- CreateDate = DateTime.Now,
- IsRecyc = (ulong)pos.IsPurchase,
- CreditAmount = pos.CreditTrade,
- PosSnType = pos.PosSnType,
- ActDate = pos.ActivationTime,
- BindDate = pos.BindingTime,
- ActStatus = (ulong)pos.ActivationState,
- BindStatus = (ulong)pos.BindingState,
- MerNo = MerNo,
- PosSn = pos.PosSn,
- Note = "设置商户型创客",
- ToUserId = user.Id,
- FromUserId = pos.BuyUserId,
- });
- maindb.SaveChanges();
- }
- }
- return Json(new AppResultJson() { Status = "1", Info = "" });
- }
- #endregion
- #region 首页-客小爽产品-机具管理-已绑定机具列表-设置商户型创客(无创客编号)
- [Authorize]
- public JsonResult SetMerchantMakerWithoutUser(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- int SnId = int.Parse(function.CheckInt(data["SnId"].ToString()));
- int UserId = int.Parse(function.CheckInt(data["UserId"].ToString()));
- string path = function.CreateQRCode2(SourceHost + "/p/user-inviteregist-1?Id=" + UserId + "&SnId=" + SnId, function.MD5_16(SnId.ToString()), "/static/MerQrCode/");
- path = path.Replace("//", "/");
- return Json(new AppResultJson() { Status = "1", Info = "", Data = SourceHost + path });
- }
- #endregion
- #region 首页-客小爽产品-机具管理-整箱划拨搜索
- [Authorize]
- public JsonResult WholeSearchByUser(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- List<Dictionary<string, object>> dataList = WholeSearchByUserDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
- }
- public List<Dictionary<string, object>> WholeSearchByUserDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //所在仓库
- int BrandId = int.Parse(function.CheckInt(data["BrandId"].ToString()));
- int BrandSubId = int.Parse(function.CheckInt(data["BrandSubId"].ToString()));
- string SnNo = data["SnNo"].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>>();
- if (string.IsNullOrEmpty(SnNo))
- {
- return dataList;
- }
- List<MachineForSnNo> MachineSnNos = maindb.MachineForSnNo.Where(m => m.SnNo.Contains(SnNo)).ToList();
- List<int> SnIds = MachineSnNos.Select(m => m.SnId).ToList();
- List<PosMachinesTwo> query = maindb.PosMachinesTwo.Where(m => SnIds.Contains(m.Id) && m.Status > -1 && m.BuyUserId == UserId && m.BrandId == BrandId && m.BindingState == 0 && m.ActivationState == 0 && m.PreUserId == 0).OrderBy(m => m.PosSn).ToList();
- foreach (var subdata in query)
- {
- Dictionary<string, object> curData = new Dictionary<string, object>();
- curData.Add("PosSn", subdata.PosSn); //SN编号
- curData.Add("Id", subdata.Id); //Id
- curData.Add("ProductType", RelationClass.GetKqProductBrandInfo(subdata.BrandId)); //产品类型
- int day = 0;
- if (subdata.RecycEndDate != null)
- {
- TimeSpan ts = subdata.RecycEndDate.Value - DateTime.Now;
- day = ts.Days;
- }
- curData.Add("ActDays", day);
- curData.Add("EndDate", subdata.RecycEndDate == null ? "" : subdata.RecycEndDate.Value.ToString("yyyy-MM-dd"));
- dataList.Add(curData);
- }
- return dataList;
- }
- #endregion
- #region 首页-仓库管理-整箱划拨搜索
- [Authorize]
- public JsonResult WholeSearch(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- List<Dictionary<string, object>> dataList = WholeSearchDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
- }
- public List<Dictionary<string, object>> WholeSearchDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- int StoreId = int.Parse(function.CheckInt(data["StoreId"].ToString())); //所在仓库
- int BrandId = int.Parse(function.CheckInt(data["BrandId"].ToString()));
- string SearchKey = data["SearchKey"].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>>();
- if (string.IsNullOrEmpty(SearchKey))
- {
- return dataList;
- }
- List<string> SnNos = new List<string>();
- int start = int.Parse(SearchKey.Substring(SearchKey.Length - 4));
- for (int i = start; i < start + 100; i++)
- {
- string EndNo = i.ToString();
- for (int j = 0; j < 4 - i.ToString().Length; j++)
- {
- EndNo = "0" + EndNo;
- }
- string SnNo = SearchKey.Substring(0, SearchKey.Length - 4) + EndNo;
- SnNos.Add(SnNo);
- }
- List<MachineForSnNo> MachineSnNos = maindb.MachineForSnNo.Where(m => SnNos.Contains(m.SnNo)).ToList();
- List<int> SnIds = MachineSnNos.Select(m => m.SnId).ToList();
- List<PosMachinesTwo> query = maindb.PosMachinesTwo.Where(m => SnIds.Contains(m.Id) && m.Status > -1 && m.StoreId == StoreId && m.BrandId == BrandId && m.UserId == 0 && m.PosSnType == 0 && m.BindingState == 0 && m.ActivationState == 0 && m.PreUserId == 0).OrderBy(m => m.PosSn).ToList();
- foreach (var subdata in query)
- {
- Dictionary<string, object> curData = new Dictionary<string, object>();
- curData.Add("PosSn", subdata.PosSn); //SN编号
- curData.Add("Id", subdata.Id); //Id
- curData.Add("ProductType", RelationClass.GetKqProductBrandInfo(subdata.BrandId)); //产品类型
- dataList.Add(curData);
- }
- return dataList;
- }
- #endregion
- #region 首页-仓库管理-逐台划拨搜索
- [Authorize]
- public JsonResult OneSearch(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- List<Dictionary<string, object>> dataList = OneSearchDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
- }
- public List<Dictionary<string, object>> OneSearchDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- int StoreId = int.Parse(function.CheckInt(data["StoreId"].ToString())); //所在仓库
- int BrandId = int.Parse(function.CheckInt(data["BrandId"].ToString()));
- string SearchKey = data["SearchKey"].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>>();
- List<PosMachinesTwo> query = maindb.PosMachinesTwo.Where(m => m.Status > -1 && m.StoreId == StoreId && m.BrandId == BrandId && m.UserId == 0 && m.PreUserId == 0).OrderBy(m => m.PosSn).ToList();
- if (!string.IsNullOrEmpty(SearchKey))
- {
- query = query.Where(m => m.PosSn.EndsWith(SearchKey)).ToList();
- }
- if (PageNum == 1)
- {
- query = query.Take(PageSize).ToList();
- }
- else
- {
- int skipNum = PageSize * (PageNum - 1);
- query = query.Skip(skipNum).Take(PageSize).ToList();
- }
- foreach (var subdata in query)
- {
- Dictionary<string, object> curData = new Dictionary<string, object>();
- curData.Add("PosSn", subdata.PosSn); //SN编号
- curData.Add("Id", subdata.Id); //Id
- curData.Add("ProductType", RelationClass.GetKqProductBrandInfo(subdata.BrandId)); //产品类型
- dataList.Add(curData);
- }
- 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
- }
- }
|