123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- 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
- {
- [Area("Api")]
- [Route("Api/v1/[controller]/[action]")]
- public class StoreHouseController : BaseController
- {
- public StoreHouseController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
- {
- }
- #region 创客-商城-确认支付-发货仓库
- [Authorize]
- public JsonResult SendStores(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- List<Dictionary<string, object>> dataList = SendStoresDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
- }
- public List<Dictionary<string, object>> SendStoresDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客Id
- string BrandId = data["BrandId"].ToString(); //品牌Id
- string searchContent = data["searchContent"].ToString();
- int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
- int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
- Users user = UsersDbconn.Instance.Get(UserId) ?? new Users();
- List<int> uids = new List<int>();
- uids.Add(1);
- uids.Add(UserId);
- if (!string.IsNullOrEmpty(user.ParentNav))
- {
- string ParentNav = function.CheckNull(user.ParentNav).Trim(',').Replace(",,", ",");
- string[] ParentNavList = ParentNav.Split(',');
- // foreach (string uid in ParentNavList)
- // {
- // uids.Add(int.Parse(uid));
- // }
- int TopUserId = 0;
- if (ParentNavList.Length > 1)
- {
- TopUserId = int.Parse(ParentNavList[1]);
- }
- else
- {
- TopUserId = int.Parse(ParentNavList[0]);
- }
- string UidString = "," + TopUserId + ",";
- var subusers = maindb.Users.Select(m => new { m.Id, m.ParentNav }).Where(m => m.ParentNav.Contains(UidString)).ToList();
- foreach (var subuser in subusers)
- {
- uids.Add(subuser.Id);
- }
- uids.Add(TopUserId);
- }
- // string UidString = "," + UserId + ",";
- // var subusers = maindb.Users.Select(m => new { m.Id, m.ParentNav }).Where(m => m.ParentNav.Contains(UidString)).ToList();
- // foreach (var subuser in subusers)
- // {
- // uids.Add(subuser.Id);
- // }
- List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
- IQueryable<StoreHouse> query = maindb.StoreHouse.Where(m => m.Status == 1);
- if (UserId == 1)
- {
- query = query.Where(m => m.LaveNum > 0 && m.BrandId == BrandId);
- }
- else
- {
- query = query.Where(m => uids.Contains(m.UserId) && m.LaveNum > 0 && m.BrandId == BrandId);
- }
- // IQueryable<StoreHouse> query = maindb.StoreHouse.Where(m => m.LaveNum > 0 && m.BrandId == BrandId);
- if (!string.IsNullOrEmpty(searchContent))
- {
- query = query.Where(m => m.StoreName.Contains(searchContent));
- }
- query = query.OrderBy(m => m.UserId);
- if (PageNum == 1)
- {
- query = query.Take(PageSize);
- }
- else
- {
- int skipNum = PageSize * (PageNum - 1);
- query = query.Skip(skipNum).Take(PageSize);
- }
- foreach (StoreHouse subdata in query.ToList())
- {
- // StoreHouse subdata = StoreHouseDbconn.Instance.Get(id) ?? new StoreHouse();
- Dictionary<string, object> curData = new Dictionary<string, object>();
- curData.Add("StoreName", subdata.StoreName); //仓库名称
- curData.Add("Address", subdata.Address); //仓库地址
- curData.Add("LaveNum", subdata.LaveNum); //剩余库存数
- curData.Add("Areas", function.CheckNull(subdata.Areas).Replace(",", "")); //所属地区
- curData.Add("Id", subdata.Id); //Id
- dataList.Add(curData);
- }
- return dataList;
- }
- #endregion
- #region 创客-商城-确认支付-发货仓库详情
- [Authorize]
- public JsonResult SendStoreDetail(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- Dictionary<string, object> Obj = SendStoreDetailDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
- }
- public Dictionary<string, object> SendStoreDetailDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- string UserId = data["UserId"].ToString(); //创客Id
- Dictionary<string, object> Obj = new Dictionary<string, object>();
- StoreHouse query = new StoreHouse();
- int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
- query = StoreHouseDbconn.Instance.Get(Id) ?? new StoreHouse();
- Obj.Add("StoreName", query.StoreName); //仓库名称
- Obj.Add("Address", query.Address); //仓库地址
- Obj.Add("LaveNum", query.LaveNum); //剩余库存数
- Obj.Add("Areas", function.CheckNull(query.Areas).Replace(",", "")); //所属地区
- Users user = UsersDbconn.Instance.Get(query.ManageUserId) ?? new Users();
- Obj.Add("ManageName", user.RealName); //仓库联系人名称
- if(query.ManageUserId == 1)
- {
- Obj.Add("ManageMobile", "19141324516"); //仓库联系人手机号
- }
- else
- {
- Obj.Add("ManageMobile", user.Mobile); //仓库联系人手机号
- }
- Obj.Add("Id", query.Id); //Id
- return Obj;
- }
- #endregion
- #region 首页-仓库管理-主界面产品
- [Authorize]
- public JsonResult IndexList(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- List<Dictionary<string, object>> dataList = IndexListDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
- }
- public List<Dictionary<string, object>> IndexListDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- int UserId = int.Parse(function.CheckInt(data["UserId"].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<StoreHouse> query = maindb.StoreHouse.Where(m => m.UserId == UserId && m.Sort == 0 && m.Status > 0).ToList(); //StoreHouseDbconn.Instance.GetList(UserId, PageNum, PageSize);
- foreach (StoreHouse subdata in query)
- {
- // StoreHouse subdata = StoreHouseDbconn.Instance.Get(id) ?? new StoreHouse();
- Dictionary<string, object> curData = new Dictionary<string, object>();
- curData.Add("ProductName", subdata.ProductName); //产品名称
- int PreCount = maindb.PreSendStockDetail.Count(m => m.FromStoreId == subdata.Id && m.ApplyFlag == 0 && m.Status >= 0 && m.Status <= 1);
- curData.Add("LaveNum", subdata.LaveNum); //剩余库存数
- curData.Add("PreCount", PreCount); //预发机数
- curData.Add("Id", subdata.Id); //Id
- curData.Add("BrandId", subdata.BrandId);
- curData.Add("Icon", ""); //产品图标
- 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
- }
- }
|