123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533 |
- 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;
- using System.Text;
- /// <summary>
- /// 分仓向总仓申请机具接口
- /// </summary>
- namespace MySystem.Areas.Api.Controllers.v1
- {
- [Area("Api")]
- [Route("/Api/v1/[controller]/[action]")]
- public class ApplyMachineController : BaseController
- {
- public ApplyMachineController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
- {
- }
- // #region 创客-首页-仓库管理-仓库列表
- // /// <summary>
- // /// 创客仓库列表
- // /// </summary>
- // /// <param name="value"></param>
- // /// <returns></returns>
- // [Authorize]
- // public JsonResult StoreHouseList(string value)
- // {
- // value = DesDecrypt(value);
- // JsonData data = JsonMapper.ToObject(value);
- // List<Dictionary<string, object>> dataList = StoreHouseListDo(value);
- // return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
- // }
- // public List<Dictionary<string, object>> StoreHouseListDo(string value)
- // {
- // JsonData data = JsonMapper.ToObject(value);
- // int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客Id
- // 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<int> query = ApplyMachineDbconn.Instance.GetList(UserId, PageNum, PageSize);
- // foreach (int StoreId in query)
- // {
- // StoreHouse subdata = ApplyMachineDbconn.Instance.Get(StoreId) ?? new StoreHouse();
- // Dictionary<string, object> curData = new Dictionary<string, object>();
- // curData.Add("Id", subdata.Id); //Id
- // curData.Add("Name", subdata.ProductName); //产品仓库名称
- // curData.Add("LaveNum", subdata.LaveNum); //剩余数量
- // dataList.Add(curData);
- // }
- // return dataList;
- // }
- // #endregion
- #region 创客-首页-仓库管理-机具申请-返回可申请机具数量
- [Authorize]
- public JsonResult StoreApply(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- AppResultJson result = StoreApplyDo(value);
- return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
- }
- public AppResultJson StoreApplyDo(string value)
- {
- // value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客Id
- int StoreId = int.Parse(function.CheckInt(data["StoreId"].ToString())); //仓库Id
- int BrandId = int.Parse(function.CheckInt(data["BrandId"].ToString())); //产品类型
- DateTime LastTime = DateTime.Parse(DateTime.Now.AddMonths(-1).AddDays(1 - DateTime.Now.Day).ToString("yyyy-MM-dd 00:00:00"));
- DateTime ThisTime = DateTime.Parse(DateTime.Now.AddDays(1 - DateTime.Now.Day).AddDays(-1).ToString("yyyy-MM-dd 23:59:59"));
- //剩余库存量
- var storeHousesLaveNum = maindb.StoreHouse.FirstOrDefault(m => m.UserId == UserId && m.Id == StoreId).LaveNum;
- //上月出货总量
- int applyDeviceNum = 0;
- bool check = maindb.MachineApply.Any(m => m.UserId == UserId && m.StoreId == StoreId && m.ApplyTime >= LastTime && m.ApplyTime <= ThisTime);
- if (check)
- {
- applyDeviceNum = maindb.MachineApply.Where(m => m.UserId == UserId && m.StoreId == StoreId && m.ApplyTime >= LastTime && m.ApplyTime <= ThisTime).Sum(m => m.ApplyDeviceNum);
- }
- //上月出货量两倍
- int LastApplyTwo = applyDeviceNum * 2;
- //最低库存数 固定
- int minInventory = 0;
- //电签
- if (BrandId == 1 || BrandId == 2 || BrandId == 4 || BrandId == 6)
- {
- minInventory = 60;
- }
- //大Pos
- else if (BrandId == 3 || BrandId == 5)
- {
- minInventory = 25;
- }
- // //金控电签
- // if (BrandId == 1)
- // {
- // minInventory = 60;
- // }
- // //开店宝电签
- // else if (BrandId == 2)
- // {
- // minInventory = 60;
- // }
- // //金控大POS
- // else if (BrandId == 3)
- // {
- // minInventory = 25;
- // }
- // //乐刷电签
- // else if (BrandId == 4)
- // {
- // minInventory = 60;
- // }
- //申请数量上限(上月出库量的2倍或最低库存量)
- int findInventory = 0;
- if (LastApplyTwo > minInventory)
- {
- findInventory = (LastApplyTwo - storeHousesLaveNum) < 0 ? 0 : (LastApplyTwo - storeHousesLaveNum);
- }
- else
- {
- findInventory = minInventory - storeHousesLaveNum < 0 ? 0 : minInventory - storeHousesLaveNum;
- }
- //箱数
- int boxes = 0;
- //电签
- if (BrandId == 1 || BrandId == 2 || BrandId == 4 || BrandId == 6)
- {
- boxes = findInventory / 50;
- }
- //大Pos
- else if (BrandId == 3 || BrandId == 5)
- {
- boxes = findInventory / 10;
- }
- // //电签
- // if (BrandId == 1 || BrandId == 1 || BrandId == 1 || BrandId == 1)
- // {
- // boxes = findInventory / 50;
- // }
- // //开店宝电签
- // else if (BrandId == 2)
- // {
- // boxes = findInventory / 50;
- // }
- // //金控大POS
- // else if (BrandId == 3)
- // {
- // boxes = findInventory / 10;
- // }
- // //乐刷电签
- // else if (BrandId == 4)
- // {
- // boxes = findInventory / 50;
- // }
- // //乐刷大POS
- // else if (BrandId == 5)
- // {
- // boxes = findInventory / 10;
- // }
- // //立刷电签
- // else if (BrandId == 6)
- // {
- // boxes = findInventory / 50;
- // }
- //每箱台数
- int boxNum = 0;
- if (BrandId == 1 || BrandId == 2 || BrandId == 4 || BrandId == 6)
- {
- boxNum = 50;
- }
- else if (BrandId == 3 || BrandId == 5)
- {
- boxNum = 10;
- }
- Machines machines = new Machines();
- machines.findInventory = findInventory;
- machines.boxes = boxes;
- machines.boxeNum = boxNum;
- return new AppResultJson() { Status = "1", Info = "", Data = machines };
- }
- #endregion
- // #region 创客-首页-仓库管理-机具申请--确认申请
- // [Authorize]
- // public JsonResult ConfirmApply(string value)
- // {
- // value = DesDecrypt(value);
- // JsonData data = JsonMapper.ToObject(value);
- // AppResultJson result = ConfirmApplyDo(value);
- // return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
- // }
- // public AppResultJson ConfirmApplyDo(string value)
- // {
- // JsonData data = JsonMapper.ToObject(value);
- // int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客Id
- // int StoreId = int.Parse(function.CheckInt(data["StoreId"].ToString())); //仓库Id
- // int BrandId = int.Parse(function.CheckInt(data["BrandId"].ToString())); //产品类型
- // int ApplyNum = int.Parse(function.CheckInt(data["ApplyNum"].ToString())); //申请箱数
- // DateTime LastTime = DateTime.Parse(DateTime.Now.AddMonths(-1).AddDays(1 - DateTime.Now.Day).ToString("yyyy-MM-dd 00:00:00"));
- // DateTime ThisTime = DateTime.Parse(DateTime.Now.AddDays(1 - DateTime.Now.Day).AddDays(-1).ToString("yyyy-MM-dd 23:59:59"));
- // //剩余库存量
- // var storeHousesLaveNum = maindb.StoreHouse.FirstOrDefault(m => m.UserId == UserId && m.Id == StoreId).LaveNum;
- // //上月出货总量
- // int applyDeviceNum = 0;
- // bool check = maindb.MachineApply.Any(m => m.UserId == UserId && m.StoreId == StoreId && m.ApplyTime >= LastTime && m.ApplyTime <= ThisTime);
- // if (check)
- // {
- // applyDeviceNum = maindb.MachineApply.Where(m => m.UserId == UserId && m.StoreId == StoreId && m.ApplyTime >= LastTime && m.ApplyTime <= ThisTime).Sum(m => m.ApplyDeviceNum);
- // }
- // //上月出货量两倍
- // int LastApplyTwo = applyDeviceNum * 2;
- // //最低库存数
- // int minInventory = 0;
- // //电签
- // if (BrandId == 1 || BrandId == 2 || BrandId == 4 || BrandId == 6)
- // {
- // minInventory = 60;
- // }
- // //大Pos
- // else if (BrandId == 3 || BrandId == 5)
- // {
- // minInventory = 25;
- // }
- // //申请数量上限(上月出库量的2倍或最低库存量)
- // int findInventory = 0;
- // if (LastApplyTwo > minInventory)
- // {
- // findInventory = (LastApplyTwo - storeHousesLaveNum) < 0 ? 0 : (LastApplyTwo - storeHousesLaveNum);
- // }
- // else
- // {
- // findInventory = minInventory - storeHousesLaveNum < 0 ? 0 : minInventory - storeHousesLaveNum;
- // }
- // //每箱台数
- // int boxNum = 0;
- // if (BrandId == 1 || BrandId == 2 || BrandId == 4 || BrandId == 6)
- // {
- // boxNum = 50;
- // }
- // else if (BrandId == 3 || BrandId == 5)
- // {
- // boxNum = 10;
- // }
- // bool checks = maindb.StoreMachineApply.Any(m => m.UserId == UserId && m.StoreId == StoreId && m.BrandId == BrandId && m.Status == 0);
- // if (checks)
- // {
- // return new AppResultJson() { Status = "-1", Info = "您有相同机具类型的申请正在进行中,请等待完成后再次申请" };
- // }
- // if (!checks)
- // {
- // if (findInventory < boxNum)
- // {
- // return new AppResultJson() { Status = "-1", Info = "可申请机具数量低于机具整箱数量,不可申请" };
- // }
- // if (storeHousesLaveNum <= applyDeviceNum || storeHousesLaveNum <= minInventory)
- // {
- // Users users = maindb.Users.Find(UserId);
- // StoreHouse storehouse = maindb.StoreHouse.Find(StoreId);
- // Orders orders = new Orders();
- // orders.Status = 0;
- // orders.CreateDate = DateTime.Now;
- // orders.StoreId = StoreId;
- // orders.Areas = storehouse.Areas;
- // orders.Address = storehouse.Address;
- // orders.Mobile = users.Mobile;
- // orders.StoreContactMobile = storehouse.ManageMobile;
- // orders.RealName = users.RealName;
- // orders.UserId = storehouse.UserId;
- // maindb.Orders.Add(orders);
- // maindb.SaveChanges();
- // StoreMachineApply storeMachineApply = new StoreMachineApply();
- // storeMachineApply.Version = 0;
- // storeMachineApply.CreateDate = DateTime.Now;
- // storeMachineApply.ApplyTime = DateTime.Now;
- // storeMachineApply.ApplyNo = "AS" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
- // storeMachineApply.BrandId = BrandId;
- // storeMachineApply.ApplyNum = ApplyNum;
- // storeMachineApply.BoxNum = boxNum;
- // storeMachineApply.LastApply = applyDeviceNum;
- // storeMachineApply.MaxApply = findInventory;
- // storeMachineApply.ActualApply = ApplyNum * boxNum;
- // storeMachineApply.UserId = UserId;
- // storeMachineApply.StoreId = StoreId;
- // maindb.StoreMachineApply.Add(storeMachineApply);
- // maindb.SaveChanges();
- // storeMachineApply.OrderId = orders.Id;
- // orders.Sort = storeMachineApply.Id;
- // maindb.SaveChanges();
- // }
- // }
- // return new AppResultJson() { Status = "1", Info = "申请成功", Data = "" };
- // }
- // #endregion
- // #region 创客-首页-仓库管理-机具申请-申请记录列表
- // /// <summary>
- // /// 机具申请记录列表
- // /// </summary>
- // /// <param name="value"></param>
- // /// <returns></returns>
- // [Authorize]
- // public JsonResult StoreApplyRecordList(string value)
- // {
- // value = DesDecrypt(value);
- // JsonData data = JsonMapper.ToObject(value);
- // List<Dictionary<string, object>> dataList = StoreApplyRecordListDo(value);
- // return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
- // }
- // public List<Dictionary<string, object>> StoreApplyRecordListDo(string value)
- // {
- // JsonData data = JsonMapper.ToObject(value);
- // int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客Id
- // int BrandId = int.Parse(function.CheckInt(data["BrandId"].ToString()));//产品类型
- // int StoreId = int.Parse(function.CheckInt(data["StoreId"].ToString()));//仓库Id
- // 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<int> query = ApplyMachineDbconn.Instance.GetApplyList(UserId, StoreId, PageNum, PageSize);
- // foreach (int Id in query)
- // {
- // StoreMachineApply subdata = ApplyMachineDbconn.Instance.GetApply(Id) ?? new StoreMachineApply();
- // Dictionary<string, object> curData = new Dictionary<string, object>();
- // curData.Add("Id", subdata.Id); //Id
- // curData.Add("ApplyTime", Convert.ToDateTime(subdata.ApplyTime).ToString("yyyy-MM-dd HH:mm:ss")); //申请时间
- // curData.Add("BrandId", subdata.BrandId); //机具类型
- // curData.Add("ApplyNum", subdata.ApplyNum); //申请箱数
- // curData.Add("Status", subdata.Status); //申请状态
- // dataList.Add(curData);
- // }
- // return dataList;
- // }
- // #endregion
- // #region 创客-首页-仓库管理-机具申请-申请记录详情
- // /// <summary>
- // /// 机具申请列表详情
- // /// </summary>
- // /// <param name="value"></param>
- // /// <returns></returns>
- // [Authorize]
- // public JsonResult StoreApplyDetail(string value)
- // {
- // value = DesDecrypt(value);
- // JsonData data = JsonMapper.ToObject(value);
- // List<Dictionary<string, object>> dataList = StoreApplyDetailDo(value);
- // return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
- // }
- // public List<Dictionary<string, object>> StoreApplyDetailDo(string value)
- // {
- // JsonData data = JsonMapper.ToObject(value);
- // int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客Id
- // int StoreId = int.Parse(function.CheckInt(data["StoreId"].ToString()));//仓库Id
- // int StoreApplyId = int.Parse(function.CheckInt(data["StoreApplyId"].ToString()));//申请记录Id
- // List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
- // List<int> query = ApplyMachineDbconn.Instance.GetApplyDetailList(UserId, StoreId, StoreApplyId);
- // foreach (int Id in query)
- // {
- // StoreMachineApply subdata = ApplyMachineDbconn.Instance.GetApply(Id) ?? new StoreMachineApply();
- // var temp = subdata.SwapSnExpand;
- // temp = temp.Substring(1);
- // temp = temp.Substring(0, temp.Length - 1);
- // var SwapSnExpand = temp.Split(",,");
- // Orders orders = OrdersDbconn.Instance.Get(subdata.OrderId.Value) ?? new Orders();
- // Dictionary<string, object> curData = new Dictionary<string, object>();
- // curData.Add("Id", subdata.Id); //Id
- // curData.Add("ApplyTime", Convert.ToDateTime(subdata.ApplyTime).ToString("yyyy-MM-dd HH:mm:ss")); //申请时间
- // curData.Add("BrandId", subdata.BrandId); //快递单号
- // curData.Add("ApplyNum", subdata.ApplyNum); //申请箱数
- // curData.Add("SendNum", subdata.SendNum); //发货箱数
- // curData.Add("BoxNum", subdata.BoxNum); //每箱台数
- // curData.Add("ErpMode", orders.ErpMode); //配送方式
- // curData.Add("OrderNo", orders.OrderNo); //快递单号
- // curData.Add("SwapSnExpand", SwapSnExpand); //机具SN号
- // dataList.Add(curData);
- // }
- // return dataList;
- // }
- // #endregion
- #region 创客-首页-仓库管理-订单列表-库存
- [Authorize]
- public JsonResult StoreStockList(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- List<Dictionary<string, object>> dataList = StoreStockListDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
- }
- public List<Dictionary<string, object>> StoreStockListDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- int StoreId = int.Parse(function.CheckInt(data["StoreId"].ToString())); //仓库Id
- 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<PosMachinesTwo> query = maindb.PosMachinesTwo.Where(m => m.StoreId == StoreId && m.UserId == 0 && m.BuyUserId == 0 && m.PreUserId == 0 && m.Status > -1);//库存和预发机分离
- int skipNum = PageSize * (PageNum - 1);
- query = query.Skip(skipNum).Take(PageSize);
- foreach (var item in query.ToList())
- {
- PosMachinesTwo subdata = PosMachinesTwoDbconn.Instance.Get(item.Id) ?? new PosMachinesTwo();
- Dictionary<string, object> curData = new Dictionary<string, object>();
- curData.Add("PosSn", subdata.PosSn);
- curData.Add("CreateDate", subdata.CreateDate);
- curData.Add("PreUserId", subdata.PreUserId);
- dataList.Add(curData);
- }
- return dataList;
- }
- #endregion
- #region 创客-首页-仓库管理-订单列表-预发机
- [Authorize]
- public JsonResult PreStoreStockList(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- List<Dictionary<string, object>> dataList = PreStoreStockListDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
- }
- public List<Dictionary<string, object>> PreStoreStockListDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- int StoreId = int.Parse(function.CheckInt(data["StoreId"].ToString())); //仓库Id
- 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<PreSendStockDetail> query = maindb.PreSendStockDetail.Where(m => m.FromStoreId == StoreId && m.Status >= 0 && m.Status <= 1 && m.ApplyFlag == 0);
- int skipNum = PageSize * (PageNum - 1);
- query = query.Skip(skipNum).Take(PageSize);
- foreach (var item in query.ToList())
- {
- Dictionary<string, object> curData = new Dictionary<string, object>();
- curData.Add("PosSn", item.SnNo);
- curData.Add("CreateDate", item.CreateDate);
- curData.Add("isGrant", item.AuthFlag); //占用小分仓额度标记
- 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
- #region 私有类-获取最多申请台数、箱数、每箱台数
- public class Machines
- {
- //最多申请台数
- public int findInventory { get; set; }
- //最多申请箱数
- public int boxes { get; set; }
- //每箱台数
- public int boxeNum { get; set; }
- }
- #endregion
- }
- }
|