123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346 |
- 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
- {
- [Area("Api")]
- [Route("Api/v1/pos/[controller]/[action]")]
- public class SmallStoreHouseController : BaseController
- {
- public SmallStoreHouseController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
- {
- OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
- }
- #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
- 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<KqProducts> brandList = maindb.KqProducts.ToList();
- DataTable dt = new DataTable();
- if (!string.IsNullOrEmpty(SearchKey))
- {
- var UserForMakerCode = maindb.UserForMakerCode.FirstOrDefault(m => m.MakerCode == SearchKey);
- if (UserForMakerCode != null)
- {
- var ToUserIds = UserForMakerCode.UserId.ToString();
- var ToUserIdss = Convert.ToInt32(ToUserIds);
- dt = OtherMySqlConn.dtable("select ToUserId,count(Id) count from PreSendStockDetail where FromUserId='" + UserId + "' and `Status`>=0 and `Status`<=1 and ApplyFlag=0 and ToUserId='" + ToUserIdss + "' group by ToUserId");
- }
- else
- {
- var SnNo = SearchKey;
- var SnNos = Convert.ToInt32(SnNo);
- dt = OtherMySqlConn.dtable("select ToUserId,count(Id) count from PreSendStockDetail where FromUserId='" + UserId + "' and `Status`>=0 and `Status`<=1 and ApplyFlag=0 and SnNo like '%" + SnNos + "%' group by ToUserId");
- }
- }
- else
- {
- dt = OtherMySqlConn.dtable("select ToUserId,count(Id) count from PreSendStockDetail where FromUserId='" + UserId + "' and `Status`>=0 and `Status`<=1 and ApplyFlag=0 group by ToUserId");
- }
- // foreach (DataRow item in dt.Rows)
- // {
- // int ToUserId = int.Parse(item["ToUserId"].ToString());
- // Dictionary<string, object> userInfo = new Dictionary<string, object>();
- // Users user = maindb.Users.FirstOrDefault(m => m.Id == ToUserId);
- // userInfo.Add("UserId", ToUserId);//创客Id
- // userInfo.Add("UserName", user.RealName);//创客姓名
- // userInfo.Add("MakerCode", user.MakerCode);//创客编号
- // userInfo.Add("Mobile", user.Mobile);//手机号
- // // userInfo.Add("HeadPhoto", DefaultPic(user.HeadPhoto));//头像
- // userInfo.Add("HeadPhoto", DefaultPic(user.HeadPhoto));//头像
- // userInfo.Add("UserLevel", user.UserLevel);//职级
- // List<Dictionary<string, object>> brands = new List<Dictionary<string, object>>();
- // bool op = false;
- // foreach (var items in brandList)
- // {
- // List<PreSendStockDetail> mydata = maindb.PreSendStockDetail.Where(m => m.FromUserId == UserId && m.ToUserId == ToUserId && m.BrandId == items.Id && m.Status >= 0 && m.Status <= 1 && m.ApplyFlag == 0).ToList();
- // if (mydata.Count > 0)
- // {
- // Dictionary<string, object> brandInfo = new Dictionary<string, object>();
- // KqProducts kqProducts = maindb.KqProducts.FirstOrDefault(m => m.Id == items.Id);
- // brandInfo.Add("Id", items.Id);//产品类型Id
- // brandInfo.Add("Name", items.Name);//产品类型名称
- // List<Dictionary<string, object>> snList = new List<Dictionary<string, object>>();
- // foreach (var subdata in mydata)
- // {
- // Dictionary<string, object> curData = new Dictionary<string, object>();
- // var pos = maindb.PosMachinesTwo.FirstOrDefault( m => m.Id == subdata.SnId) ?? new PosMachinesTwo();
- // curData.Add("Id", subdata.Id);//记录Id
- // curData.Add("SnId", subdata.SnId);//机具Id
- // curData.Add("SnNo", subdata.SnNo); //机具SN
- // curData.Add("Status", subdata.Status); //确认状态(0 待确认,1 已确认)
- // curData.Add("isGrant", subdata.AuthFlag); //占用小分仓额度标记
- // curData.Add("CreateDate", pos.CreateDate == null ? "" : pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss"));//入库时间
- // snList.Add(curData);
- // }
- // brandInfo.Add("SnList", snList);
- // brands.Add(brandInfo);
- // op = true;
- // }
- // }
- //new 优化
- foreach (DataRow item in dt.Rows)
- {
- int ToUserId = int.Parse(item["ToUserId"].ToString());
- Dictionary<string, object> userInfo = new Dictionary<string, object>();
- Users user = maindb.Users.FirstOrDefault(m => m.Id == ToUserId);
- userInfo.Add("UserId", ToUserId);//创客Id
- userInfo.Add("UserName", user.RealName);//创客姓名
- userInfo.Add("MakerCode", user.MakerCode);//创客编号
- userInfo.Add("Mobile", user.Mobile);//手机号
- userInfo.Add("HeadPhoto", DefaultPic(user.HeadPhoto));//头像
- userInfo.Add("UserLevel", user.UserLevel);//职级
- List<Dictionary<string, object>> brands = new List<Dictionary<string, object>>();
- List<PreSendStockDetail> mydata = maindb.PreSendStockDetail.Where(m => m.FromUserId == UserId && m.ToUserId == ToUserId && m.Status >= 0 && m.Status <= 1 && m.ApplyFlag == 0).ToList();
- bool op = false;
- foreach (var items in brandList)
- {
- var mydatas = mydata.Where(m => m.BrandId == items.Id).ToList();
- if (mydatas.Count > 0)
- {
- Dictionary<string, object> brandInfo = new Dictionary<string, object>();
- KqProducts kqProducts = maindb.KqProducts.FirstOrDefault(m => m.Id == items.Id);
- brandInfo.Add("Id", items.Id);//产品类型Id
- brandInfo.Add("Name", items.Name);//产品类型名称
- List<Dictionary<string, object>> snList = new List<Dictionary<string, object>>();
- foreach (var subdata in mydatas)
- {
- Dictionary<string, object> curData = new Dictionary<string, object>();
- var pos = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == subdata.SnId) ?? new PosMachinesTwo();
- curData.Add("Id", subdata.Id);//记录Id
- curData.Add("SnId", subdata.SnId);//机具Id
- curData.Add("SnNo", subdata.SnNo); //机具SN
- curData.Add("Status", subdata.Status); //确认状态(0 待确认,1 已确认)
- curData.Add("isGrant", subdata.AuthFlag); //占用小分仓额度标记
- curData.Add("CreateDate", pos.CreateDate == null ? "" : pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss"));//入库时间
- snList.Add(curData);
- }
- brandInfo.Add("SnList", snList);
- brands.Add(brandInfo);
- op = true;
- }
- }
- if (op)
- {
- userInfo.Add("BrandList", brands);
- dataList.Add(userInfo);
- }
- }
- dataList = dataList.Skip((PageNum - 1) * PageSize).Take(PageSize).ToList();//分页的重点
- 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);
- string MakerCode = data["MakerCode"].ToString(); //搜索创客编号
- int FromUserId = int.Parse(function.CheckInt(data["FromUserId"].ToString())); //出货创客Id
- int FromStoreId = int.Parse(function.CheckInt(data["FromStoreId"].ToString())); //出货创客仓库Id
- var UserIdStr = FromUserId.ToString();
- Users users = maindb.Users.FirstOrDefault(m => m.MakerCode == MakerCode);
- Dictionary<string, object> Obj = new Dictionary<string, object>();
- SmallStoreHouse query = maindb.SmallStoreHouse.FirstOrDefault(m => m.UserId == users.Id);
- if (query == null)
- {
- query = maindb.SmallStoreHouse.Add(new SmallStoreHouse()
- {
- CreateDate = DateTime.Now, //创建时间
- SeoDescription = UserIdStr,//描述--创建创客Id
- // Remark = FromUserId.ToString(),//备注--创建创客Id
- Mobile = users.Mobile, //手机号
- LaveNum = 10, //剩余库存数
- UserId = users.Id, //所属创客Id
- StoreName = users.RealName, //仓库名称
- StoreNo = users.MakerCode, //仓库编号
- }).Entity;
- maindb.SaveChanges();
- }
- else if (query != null)
- {
- if (!query.SeoDescription.Contains(UserIdStr))
- {
- query.SeoDescription = query.SeoDescription + ',' + UserIdStr;
- maindb.SaveChanges();
- }
- }
- Obj.Add("LaveNum", query.LaveNum); //剩余库存数
- Obj.Add("TotalNum", query.TotalNum); //库存数
- return Obj;
- }
- #endregion
- #region 创客-首页-仓库管理-出货记录-按天
- [Authorize]
- public JsonResult ForDate(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- List<Dictionary<string, object>> dataList = ForDateDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
- }
- public List<Dictionary<string, object>> ForDateDo(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 Month = data["Month"].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<StoreStockChange> query = maindb.StoreStockChange.Where(m => m.Status > 0);
- if (!string.IsNullOrEmpty(data["StoreId"].ToString()))
- {
- query = query.Where(m => m.StoreId == StoreId);
- }
- if (!string.IsNullOrEmpty(data["BrandId"].ToString()))
- {
- query = query.Where(m => m.BrandId == BrandId);
- }
- int TotalCount = query.Count();
- query = query.OrderByDescending(m => m.Sort).ThenByDescending(m => m.Id);
- if (PageNum == 1)
- {
- query = query.Take(PageSize);
- }
- else
- {
- int skipNum = PageSize * (PageNum - 1);
- query = query.Skip(skipNum).Take(PageSize);
- }
- var mydata = query.ToList();
- foreach (var subdata in mydata)
- {
- Dictionary<string, object> curData = new Dictionary<string, object>();
- curData.Add("Date", ""); //日期
- curData.Add("SnCount", ""); //机具数量
- curData.Add("SnNos", ""); //机具列表
- dataList.Add(curData);
- }
- return dataList;
- }
- #endregion
- #region 创客-首页-仓库管理-出货记录-按月
- [Authorize]
- public JsonResult ForMonth(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- List<Dictionary<string, object>> dataList = ForMonthDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
- }
- public List<Dictionary<string, object>> ForMonthDo(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())); //产品类型
- 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<StoreStockChange> query = maindb.StoreStockChange.Where(m => m.Status > 0);
- if (!string.IsNullOrEmpty(data["StoreId"].ToString()))
- {
- query = query.Where(m => m.StoreId == StoreId);
- }
- if (!string.IsNullOrEmpty(data["BrandId"].ToString()))
- {
- query = query.Where(m => m.BrandId == BrandId);
- }
- int TotalCount = query.Count();
- query = query.OrderByDescending(m => m.Sort).ThenByDescending(m => m.Id);
- if (PageNum == 1)
- {
- query = query.Take(PageSize);
- }
- else
- {
- int skipNum = PageSize * (PageNum - 1);
- query = query.Skip(skipNum).Take(PageSize);
- }
- var mydata = query.ToList();
- foreach (var subdata in mydata)
- {
- Dictionary<string, object> curData = new Dictionary<string, object>();
- curData.Add("Month", ""); //月份
- curData.Add("SendCount", ""); //总发货
- 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
- }
- }
|