123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644 |
- /*
- * 仓库
- */
- using System;
- using System.Web;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Data;
- using System.Threading;
- using System.Threading.Tasks;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Http;
- using Microsoft.Extensions.Logging;
- using Microsoft.Extensions.Options;
- using MySystem.Models;
- using Library;
- using LitJson;
- using MySystemLib;
- namespace MySystem.Areas.Admin.Controllers
- {
- [Area("Admin")]
- [Route("Admin/[controller]/[action]")]
- public class StoreHouseController : BaseController
- {
- public StoreHouseController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
- {
- OtherMySqlConn.connstr = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
- }
- #region 仓库列表
- /// <summary>
- /// 根据条件查询仓库列表
- /// </summary>
- /// <returns></returns>
- public IActionResult Index(StoreHouse data, string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- #endregion
- #region 根据条件查询仓库列表
- /// <summary>
- /// 仓库列表
- /// </summary>
- /// <returns></returns>
- public JsonResult IndexData(StoreHouse data, string UserIdMakerCode, string UserIdRealName, string BrandId, string ManageUserIdRealName, string ManageUserIdMobile, string ManageUserIdMakerCode, string StoreStatusSelect, string CreateDateData, string MakerCode, string YZOpCode, string OpStatusSelect, string StoreKindSelect, int ShowFlag = 0, int page = 1, int limit = 30)
- {
- Dictionary<string, string> Fields = new Dictionary<string, string>();
- Fields.Add("StoreNo", "1"); //仓库编号
- Fields.Add("StoreName", "1"); //仓库名称
- Fields.Add("ManagerEmail", "1"); //管理者邮箱
- if (ShowFlag == 0)
- {
- Dictionary<string, object> objs = new Dictionary<string, object>();
- return Json(objs);
- }
- string condition = " and Status>-1";
- //品牌
- if (!string.IsNullOrEmpty(BrandId))
- {
- condition += " and BrandId =" + BrandId;
- }
- //仓库归属人创客编号
- if (!string.IsNullOrEmpty(UserIdMakerCode))
- {
- condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
- }
- //仓库归属人真实姓名
- if (!string.IsNullOrEmpty(UserIdRealName))
- {
- DataTable dt = OtherMySqlConn.dtable("SELECT Id FROM Users WHERE RealName like '%" + UserIdRealName + "%'");
- var Count = dt.Rows.Count;
- // int times = 0;
- string UserIds = "";
- foreach (DataRow item in dt.Rows)
- {
- UserIds += item["Id"].ToString() + ",";
- }
- condition += " and UserId in (" + UserIds.TrimEnd(',') + ")";
- }
- //仓库管理员真实姓名
- if (!string.IsNullOrEmpty(ManageUserIdRealName))
- {
- DataTable dts = OtherMySqlConn.dtable("SELECT Id FROM Users WHERE RealName like '%" + ManageUserIdRealName + "%'");
- var Counts = dts.Rows.Count;
- // int time = 1;
- string UserIdss = "";
- foreach (DataRow items in dts.Rows)
- {
- UserIdss += items["Id"].ToString() + ",";
- }
- condition += " and UserId in (" + UserIdss.TrimEnd(',') + ")";
- }
- //仓库管理员手机号
- if (!string.IsNullOrEmpty(ManageUserIdMobile))
- {
- condition += " and ManageUserId in (select ManageUserId from UserForMobile where Mobile='" + ManageUserIdMobile + "')";
- }
- //仓库管理员创客编号
- if (!string.IsNullOrEmpty(ManageUserIdMakerCode))
- {
- condition += " and ManageUserId in (select ManageUserId from UserForMakerCode where MakerCode='" + ManageUserIdMakerCode + "')";
- }
- //仓库状态
- if (!string.IsNullOrEmpty(StoreStatusSelect))
- {
- condition += " and Status=" + StoreStatusSelect;
- }
- if (!string.IsNullOrEmpty(CreateDateData))
- {
- string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
- string start = datelist[0];
- string end = datelist[1];
- condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
- }
- //下线创客编号
- if (!string.IsNullOrEmpty(MakerCode))
- {
- var userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode) ?? new UserForMakerCode();
- if (userForMakerCode.UserId > 0)
- {
- var user = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId);
- var users = db.Users.Where(m => m.ParentNav.Contains("," + user.Id.ToString() + ",")).ToList();
- string userIds = "";
- foreach (var item in users)
- {
- userIds += item.Id + ",";
- }
- userIds += user.Id;//下线创客Id包含自己
- string Id = "";
- DataTable dt = OtherMySqlConn.dtable("SELECT Id FROM StoreHouse WHERE UserId IN(" + userIds.TrimEnd(',') + ") AND `Status`=1 AND Sort=0 AND UserId>1");
- foreach (DataRow item in dt.Rows)
- {
- Id += item["Id"].ToString() + ",";
- }
- condition += " and Id in (" + Id.TrimEnd(',') + ")";
- }
- }
- //是否关联
- if (!string.IsNullOrEmpty(OpStatusSelect))
- {
- if (int.Parse(OpStatusSelect) > 0)
- {
- condition += " and OpId>0";
- }
- else
- {
- condition += " and OpId=0";
- }
- }
- //是否运营仓
- if (!string.IsNullOrEmpty(StoreKindSelect))
- {
- if (int.Parse(StoreKindSelect) > 0)
- {
- condition += " and Sort>0 and StoreKind=2";
- }
- else
- {
- condition += " and Sort=0 and StoreKind!=2";
- }
- }
- Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("StoreHouse", Fields, "Id desc", "0", page, limit, condition);
- List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
- foreach (Dictionary<string, object> dic in diclist)
- {
- //仓库归属人
- int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
- Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
- dic["UserIdMakerCode"] = userid_Users.MakerCode;
- dic["UserIdRealName"] = userid_Users.RealName;
- //产品类型
- dic["BrandId"] = RelationClass.GetKqProductBrandList(dic["BrandId"].ToString());
- //仓库管理员
- int ManageUserId = int.Parse(function.CheckInt(dic["ManageUserId"].ToString()));
- Users manageuserid_Users = db.Users.FirstOrDefault(m => m.Id == ManageUserId) ?? new Users();
- dic["ManageUserIdRealName"] = manageuserid_Users.RealName;
- dic["ManageUserIdMobile"] = manageuserid_Users.Mobile;
- dic["ManageUserIdMakerCode"] = manageuserid_Users.MakerCode;
- //仓库类型
- int StoreType = int.Parse(dic["StoreType"].ToString());
- if (StoreType == 0) dic["StoreType"] = "实体仓";
- if (StoreType == 1) dic["StoreType"] = "虚拟仓";
- //仓库状态
- int Status = int.Parse(dic["Status"].ToString());
- if (Status == 1) dic["Status"] = "启用";
- if (Status == 0) dic["Status"] = "禁用";
- //仓库归属类型
- int StoreKind = int.Parse(dic["StoreKind"].ToString());
- if (StoreKind == 0) dic["StoreKind"] = "分仓";
- if (StoreKind == 1) dic["StoreKind"] = "总仓";
- if (StoreKind == 2) dic["StoreKind"] = "运营仓";
- }
- return Json(obj);
- }
- #endregion
- #region 增加仓库
- /// <summary>
- /// 增加或修改仓库信息
- /// </summary>
- /// <returns></returns>
- public IActionResult Add(string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- #endregion
- #region 增加仓库
- /// <summary>
- /// 增加或修改仓库信息
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- public string Add(StoreHouse data, string ManageMakerCode, string MakerCode)
- {
- string BrandIdString = data.BrandId;
- if (!string.IsNullOrEmpty(BrandIdString))
- {
- string[] BrandIdList = BrandIdString.Split(',');
- foreach (string BrandId in BrandIdList)
- {
- Dictionary<string, object> Fields = new Dictionary<string, object>();
- Fields.Add("CreateMan", SysUserName); //创建人
- Fields.Add("StoreName", data.StoreName); //仓库名称
- Fields.Add("FilePath", data.FilePath); //附件
- Fields.Add("Deposit", data.Deposit); //押金
- UserForMakerCode user = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
- if (user == null)
- {
- return "您输入的仓库归属创客编号不存在,请重新输入正确的仓库归属创客编号";
- }
- Fields.Add("UserId", user.UserId); //仓库归属人
- Fields.Add("Areas", data.Areas); //所属地区
- Fields.Add("Address", data.Address); //仓库地址
- UserForMakerCode manage = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ManageMakerCode);
- if (manage == null)
- {
- return "您输入的仓库负责人编号不存在,请重新输入正确的仓库负责人编号";
- }
- Fields.Add("ManageUserId", manage.UserId); //仓库管理员
- Fields.Add("ManagerEmail", data.ManagerEmail); //管理者邮箱
- Fields.Add("ManageMobile", data.ManageMobile);
- Fields.Add("Remark", data.Remark); //备注
- Fields.Add("LimitTopUserId", data.LimitTopUserId); //限制创客特殊仓库
- Fields.Add("StoreKind", data.StoreKind); //仓库归属类型
- int bid = int.Parse(BrandId);
- KqProducts pro = db.KqProducts.FirstOrDefault(m => m.Id == bid) ?? new KqProducts();
- Fields.Add("BrandId", BrandId);
- Fields.Add("ProductName", pro.Name);
- Fields.Add("StoreStatus", 1);
- Fields.Add("Status", 1);
- var name = db.StoreHouse.FirstOrDefault(m => m.UserId == user.UserId && m.BrandId == BrandId && m.StoreName == data.StoreName && m.OpId == 0);
- if (name != null)
- {
- return "您的仓库名重复,请重新填写";
- }
- int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("StoreHouse", Fields, 0);
- int StoreId = Id;
- var StoreNos = "";
- //添加分仓创建时间
- var users = db.Users.FirstOrDefault(m => m.Id == user.UserId) ?? new Users();
- if (users.Id > 0)
- {
- if (string.IsNullOrEmpty(users.CreateStoreDate.ToString()))
- {
- users.CreateStoreDate = DateTime.Now;
- db.SaveChanges();
- }
- }
- StoreHouse edit = db.StoreHouse.FirstOrDefault(m => m.Id == Id);
- if (edit != null)
- {
- string No = Id.ToString();
- for (int i = 0; i < 7 - Id.ToString().Length; i++)
- {
- No = "0" + No;
- }
- No = "S" + No;
- edit.StoreNo = No;
- StoreNos = No;
- db.StoreForCode.Add(new StoreForCode()
- {
- Code = No,
- StoreId = Id,
- });
- RedisDbconn.Instance.Set("StoreForCode:" + No, Id);
- }
- StoreForName storeForName = db.StoreForName.FirstOrDefault(m => m.Name == data.StoreName);
- if (storeForName == null)
- {
- db.StoreForName.Add(new StoreForName()
- {
- Name = data.StoreName,
- StoreId = Id,
- });
- }
- else
- {
- storeForName.StoreId = Id;
- }
- UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == user.UserId);
- if (account == null)
- {
- account = db.UserAccount.Add(new UserAccount()
- {
- Id = user.UserId,
- UserId = user.UserId,
- }).Entity;
- db.SaveChanges();
- }
- if (account.FixedAmount == 0 && account.ValidAmount == 0)
- {
- account.FixedAmount = 20000;
- account.ValidAmount = 20000;
- }
- account.StoreDeposit = data.Deposit;
- AddSysLog(data.Id.ToString(), "StoreHouse", "add");
- db.SaveChanges();
- SetRedis(Id, user.UserId);
- }
- }
- return "success";
- }
- #endregion
- #region 修改仓库
- /// <summary>
- /// 增加或修改仓库信息
- /// </summary>
- /// <returns></returns>
- public IActionResult Edit(string right, int Id = 0)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- StoreHouse editData = db.StoreHouse.FirstOrDefault(m => m.Id == Id) ?? new StoreHouse();
- ViewBag.data = editData;
- Users manage = db.Users.FirstOrDefault(m => m.Id == editData.ManageUserId) ?? new Users();
- ViewBag.ManageMakerCode = manage.MakerCode;
- ViewBag.ManageRealName = manage.RealName;
- Users user = db.Users.FirstOrDefault(m => m.Id == editData.UserId) ?? new Users();
- ViewBag.MakerCode = user.MakerCode;
- return View();
- }
- #endregion
- #region 修改仓库
- /// <summary>
- /// 增加或修改仓库信息
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- public string Edit(StoreHouse data, string ManageMakerCode, string MakerCode)
- {
- Dictionary<string, object> Fields = new Dictionary<string, object>();
- Fields.Add("CreateMan", SysUserName); //创建人
- Fields.Add("UpdateMan", SysUserName + "-" + SysRealName); //修改人
- Fields.Add("StoreName", data.StoreName); //仓库名称
- Fields.Add("FilePath", data.FilePath); //附件
- Fields.Add("Deposit", data.Deposit); //押金
- UserForMakerCode user = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
- if (user == null)
- {
- return "您输入的仓库归属创客编号不存在,请重新输入正确的仓库归属创客编号";
- }
- Fields.Add("UserId", user.UserId); //仓库归属人
- Fields.Add("ManagerEmail", data.ManagerEmail); //管理者邮箱
- Fields.Add("ManageMobile", data.ManageMobile);
- Fields.Add("Areas", data.Areas); //所属地区
- Fields.Add("Address", data.Address); //仓库地址
- UserForMakerCode manage = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ManageMakerCode);
- if (manage == null)
- {
- return "您输入的仓库负责人编号不存在,请重新输入正确的仓库负责人编号";
- }
- Fields.Add("ManageUserId", manage.UserId); //仓库管理员
- Fields.Add("Remark", data.Remark); //备注
- Fields.Add("LimitTopUserId", data.LimitTopUserId); //限制创客特殊仓库
- Fields.Add("StoreKind", data.StoreKind); //仓库归属类型
- Fields.Add("Status", data.Status);
- Fields.Add("StoreStatus", data.Status);
- var sto = db.StoreHouse.FirstOrDefault(m => m.Id == data.Id);
- var store = db.StoreHouse.Where(m => m.Sort == 0 && m.Status == 1 && m.UserId == sto.UserId).ToList();
- UserAccount userAccountOld = db.UserAccount.FirstOrDefault(m => m.Id == sto.UserId);
- UserAccount userAccount = db.UserAccount.FirstOrDefault(m => m.Id == user.UserId);
- decimal olddeposit = 0;//旧押金
- decimal newdeposit = 0;//新押金
- newdeposit = data.Deposit;
- olddeposit = sto.Deposit;
- if (sto.UserId != user.UserId)
- {
- var check = db.StoreHouse.Any(m => m.Sort == 0 && m.Status == 1 && m.UserId == user.UserId);
- if (check)
- {
- return "创客" + MakerCode + "名下已存在分仓,不可再变更";
- }
- else
- {
- if (userAccount == null)
- {
- userAccount = db.UserAccount.Add(new UserAccount()
- {
- Id = user.UserId,
- UserId = user.UserId,
- }).Entity;
- db.SaveChanges();
- }
- var checks = db.StoreHouseAmountPromiss.Any(m => m.ToUserId == sto.UserId);
- if (checks)
- {
- var storeHouseAmountPromiss = db.StoreHouseAmountPromiss.Where(m => m.Status == 1 && m.ToUserId == sto.UserId).ToList();
- foreach (var item in storeHouseAmountPromiss)
- {
- var info = storeHouseAmountPromiss.FirstOrDefault(m => m.Id == item.Id);
- info.UpdateDate = DateTime.Now;
- info.UpdateMan = SysRealName + "-" + SysUserName;
- info.ToUserId = user.UserId;
- }
- }
- userAccount.UpdateMan = SysUserName + "-" + SysRealName;
- userAccount.StoreDeposit = data.Deposit;
- userAccount.FixedAmount = userAccountOld.FixedAmount;
- userAccount.ValidAmount = userAccountOld.ValidAmount;
- userAccount.TempAmount = userAccountOld.TempAmount;
- userAccount.TempAmountForBalance = userAccountOld.TempAmountForBalance;
- userAccountOld.UpdateMan = SysUserName + "-" + SysRealName;
- userAccountOld.StoreDeposit = 0;
- userAccountOld.ValidAmount = 0;
- userAccountOld.FixedAmount = 0;
- userAccountOld.TempAmount = 0;
- userAccountOld.TempAmountForBalance = 0;
-
- }
- }
- else
- {
- userAccount.UpdateMan = SysUserName + "-" + SysRealName;
- userAccount.StoreDeposit = data.Deposit;
-
- foreach (var item in store)
- {
- var storeInfo = store.FirstOrDefault(m => m.Id == item.Id);
- storeInfo.UpdateMan = SysUserName + "-" + SysRealName;
- storeInfo.UserId = user.UserId;
- storeInfo.ManageUserId = manage.UserId;
- storeInfo.ManagerEmail = data.ManagerEmail;
- storeInfo.ManageMobile = data.ManageMobile;
- storeInfo.Address = data.Address;
- storeInfo.Areas = data.Areas;
- storeInfo.LimitTopUserId = data.LimitTopUserId;
- storeInfo.FilePath = data.FilePath;
- storeInfo.Deposit = data.Deposit;
- storeInfo.Remark = data.Remark;
- }
- }
- db.SaveChanges();
- new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreHouse", Fields, data.Id);
- AddSysLog(data.Id.ToString(), "StoreHouse", "update");
- db.SaveChanges();
- return "success";
- }
- #endregion
- #region 一键添加仓库
- /// <summary>
- /// 一件添加仓库
- /// </summary>
- /// <returns></returns>
- public IActionResult Edits(string right, int Id = 0)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- StoreHouse editData = db.StoreHouse.FirstOrDefault(m => m.Id == Id) ?? new StoreHouse();
- ViewBag.data = editData;
- Users manage = db.Users.FirstOrDefault(m => m.Id == editData.ManageUserId) ?? new Users();
- ViewBag.ManageMakerCode = manage.MakerCode;
- ViewBag.ManageRealName = manage.RealName;
- Users user = db.Users.FirstOrDefault(m => m.Id == editData.UserId) ?? new Users();
- ViewBag.MakerCode = user.MakerCode;
- return View();
- }
- #endregion
- #region 一键添加仓库
- /// <summary>
- /// 一键添加仓库
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- public string Edits(StoreHouse data, string ManageMakerCode, string MakerCode)
- {
- Dictionary<string, object> Fields = new Dictionary<string, object>();
- StoreHouse storeHouse = db.StoreHouse.FirstOrDefault(m => m.Id == data.Id);
- var brand = db.StoreHouse.FirstOrDefault(m => m.UserId == storeHouse.UserId && m.BrandId == data.BrandId && m.OpId == 0);
- if (brand != null)
- {
- return "您已有该品牌类型的仓库,请重新选择";
- }
- var name = db.StoreHouse.FirstOrDefault(m => m.UserId == storeHouse.UserId && m.StoreName == data.StoreName);
- if (name != null)
- {
- return "您的仓库名重复,请重新填写";
- }
- Fields.Add("StoreName", data.StoreName); //仓库名称
- UserForMakerCode user = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
- if (user == null)
- {
- return "您输入的仓库归属创客编号不存在,请重新输入正确的仓库归属创客编号";
- }
- Fields.Add("UserId", user.UserId); //仓库归属人
- Fields.Add("Areas", data.Areas); //所属地区
- Fields.Add("Address", data.Address); //仓库地址
- UserForMakerCode manage = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ManageMakerCode);
- if (manage == null)
- {
- return "您输入的仓库负责人编号不存在,请重新输入正确的仓库负责人编号";
- }
- Fields.Add("CreateMan", SysUserName); //创建人
- Fields.Add("ManageUserId", manage.UserId); //仓库管理员
- Fields.Add("ManagerEmail", data.ManagerEmail); //管理者邮箱
- Fields.Add("ManageMobile", data.ManageMobile);
- Fields.Add("Remark", data.Remark); //备注
- Fields.Add("FilePath", data.FilePath); //附件
- Fields.Add("Deposit", data.Deposit); //押金
- Fields.Add("LimitTopUserId", data.LimitTopUserId); //限制创客特殊仓库
- Fields.Add("StoreKind", data.StoreKind); //仓库归属类型
- int bid = Convert.ToInt32(data.BrandId);
- KqProducts pro = db.KqProducts.FirstOrDefault(m => m.Id == bid) ?? new KqProducts();
- Fields.Add("BrandId", data.BrandId);
- Fields.Add("ProductName", pro.Name);
- Fields.Add("StoreStatus", 1);
- Fields.Add("Status", 1);
- int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("StoreHouse", Fields, 0);
- int StoreId = Id;
- var StoreNos = "";
- //添加分仓创建时间
- var users = db.Users.FirstOrDefault(m => m.Id == user.UserId) ?? new Users();
- if (users.Id > 0)
- {
- if (string.IsNullOrEmpty(users.CreateStoreDate.ToString()))
- {
- users.CreateStoreDate = DateTime.Now;
- db.SaveChanges();
- }
- }
- StoreHouse edit = db.StoreHouse.FirstOrDefault(m => m.Id == Id);
- if (edit != null)
- {
- string No = Id.ToString();
- for (int i = 0; i < 7 - Id.ToString().Length; i++)
- {
- No = "0" + No;
- }
- No = "S" + No;
- edit.StoreNo = No;
- StoreNos = No;
- db.StoreForCode.Add(new StoreForCode()
- {
- Code = No,
- StoreId = Id,
- });
- RedisDbconn.Instance.Set("StoreForCode:" + No, Id);
- }
- StoreForName storeForName = db.StoreForName.FirstOrDefault(m => m.Name == data.StoreName);
- if (storeForName == null)
- {
- db.StoreForName.Add(new StoreForName()
- {
- Name = data.StoreName,
- StoreId = Id,
- });
- }
- else
- {
- storeForName.StoreId = Id;
- }
- UserAccount userAccount = db.UserAccount.FirstOrDefault(m => m.Id == user.UserId);
- if (userAccount == null)
- {
- userAccount = db.UserAccount.Add(new UserAccount()
- {
- Id = user.UserId,
- UserId = user.UserId,
- }).Entity;
- db.SaveChanges();
- }
- userAccount.StoreDeposit = data.Deposit;
- db.SaveChanges();
-
- AddSysLog(data.Id.ToString(), "StoreHouse", "add");
- db.SaveChanges();
- return "success";
- }
- #endregion
- #region 删除仓库信息
- /// <summary>
- /// 删除仓库信息
- /// </summary>
- /// <returns></returns>
- public string Delete(string Id)
- {
- string[] idlist = Id.Split(new char[] { ',' });
- AddSysLog(Id, "StoreHouse", "del");
- foreach (string subid in idlist)
- {
- int id = int.Parse(subid);
- Dictionary<string, object> Fields = new Dictionary<string, object>();
- Fields.Add("Status", -1);
- StoreHouse edit = db.StoreHouse.FirstOrDefault(m => m.Id == id);
- if (edit != null)
- {
- StoreForCode code = db.StoreForCode.FirstOrDefault(m => m.Code == edit.StoreNo);
- if (code != null)
- {
- db.StoreForCode.Remove(code);
- }
- StoreForName name = db.StoreForName.FirstOrDefault(m => m.Name == edit.StoreName);
- if (name != null)
- {
- db.StoreForName.Remove(name);
- }
- }
- new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreHouse", Fields, id);
- }
- db.SaveChanges();
- return "success";
- }
- #endregion
- #region 开启
- /// <summary>
- /// 开启
- /// </summary>
- /// <returns></returns>
- public string Open(string Id)
- {
- string[] idlist = Id.Split(new char[] { ',' });
- AddSysLog(Id, "StoreHouse", "open");
- foreach (string subid in idlist)
- {
- int id = int.Parse(subid);
- Dictionary<string, object> Fields = new Dictionary<string, object>();
- Fields.Add("Status", 1);
- new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreHouse", Fields, id);
- }
- db.SaveChanges();
- return "success";
- }
- #endregion
- #region 关闭
- /// <summary>
- /// 关闭
- /// </summary>
- /// <returns></returns>
- public string Close(string Id)
- {
- string[] idlist = Id.Split(new char[] { ',' });
- AddSysLog(Id, "StoreHouse", "close");
- foreach (string subid in idlist)
- {
- int id = int.Parse(subid);
- Dictionary<string, object> Fields = new Dictionary<string, object>();
- Fields.Add("Status", 0);
- new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreHouse", Fields, id);
- }
- db.SaveChanges();
- return "success";
- }
- #endregion
- #region 排序
- /// <summary>
- /// 排序
- /// </summary>
- /// <param name="Id"></param>
- public string Sort(int Id, int Sort)
- {
- new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("StoreHouse", Sort, Id);
- AddSysLog(Id.ToString(), "StoreHouse", "sort");
- return "success";
- }
- #endregion
- #region 导入数据
- public IActionResult Import(string right, string ExcelKind)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- ViewBag.ExcelKind = ExcelKind;
- return View();
- }
- /// <summary>
- /// 导入数据
- /// </summary>
- /// <param name="ExcelData"></param>
- [HttpPost]
- public string ImportPost(string ExcelPath, int Kind = 0)
- {
- string key = function.MD5_16(Guid.NewGuid().ToString());
- RedisDbconn.Instance.AddList("ExcelImportV2", ExcelPath + "#cut#" + Kind + "#cut#" + key + "#cut#" + SysUserName);
- return "success|" + key;
- }
- public string CheckImport(string key)
- {
- string result = RedisDbconn.Instance.Get<string>("CheckImport:" + key);
- if (!string.IsNullOrEmpty(result))
- {
- string[] datalist = result.Split('|');
- if (datalist[0] == "success")
- {
- return result;
- }
- return datalist[0];
- }
- return "0";
- }
- public Dictionary<string, object> CheckImportV2(string key)
- {
- Dictionary<string, object> Obj = new Dictionary<string, object>();
- string result = RedisDbconn.Instance.Get<string>("CheckImport:" + key);
- if (!string.IsNullOrEmpty(result))
- {
- string[] datalist = result.Split('|');
- if (datalist[0] == "success")
- {
- List<string> errList = RedisDbconn.Instance.GetList<string>("ErrList" + key);
- if (errList.Count > 0)
- {
- Obj.Add("status", 2);
- Obj.Add("errList", errList);
- }
- else
- {
- Obj.Add("status", 1);
- Obj.Add("data", result);
- }
- return Obj;
- }
- Obj.Add("status", 0);
- Obj.Add("data", datalist[0]);
- return Obj;
- }
- Obj.Add("status", -1);
- Obj.Add("data", "执行中...");
- return Obj;
- }
- #endregion
- #region 机具驳回仓库
- /// <summary>
- /// 机具驳回仓库
- /// </summary>
- /// <param name="ExcelData"></param>
- public string RejectStore(string ExcelData, int ExcelKind = 0)
- {
- ExcelData = HttpUtility.UrlDecode(ExcelData);
- JsonData list = JsonMapper.ToObject(ExcelData);
- if (ExcelKind == 1)
- {
- string error = "";
- decimal amount = 0;
- List<string> PosSnList = new List<string>();
- List<string> opData = new List<string>();
- for (int i = 1; i < list.Count; i++)
- {
- JsonData dr = list[i];
- string itemJson = dr.ToJson();
- string PosSn = itemJson.Contains("\"A\"") ? dr["A"].ToString() : "";
- string BrandId = itemJson.Contains("\"B\"") ? dr["B"].ToString() : "";
- string MakerCode = itemJson.Contains("\"C\"") ? dr["C"].ToString() : "";
- string StoreNo = itemJson.Contains("\"D\"") ? dr["D"].ToString() : "";
- string No = itemJson.Contains("\"E\"") ? dr["E"].ToString() : "";
- string Remark = itemJson.Contains("\"F\"") ? dr["F"].ToString() : "";
- if (string.IsNullOrEmpty(PosSn) || string.IsNullOrEmpty(BrandId) || string.IsNullOrEmpty(MakerCode) || string.IsNullOrEmpty(StoreNo))
- {
- return "失败,请检查机具Sn、品牌、创客编号、仓库编号是否为空!";
- }
- UserForMakerCode userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
- if (userForMakerCode == null)
- {
- return "未找到创客" + MakerCode + "相关创客关联数据" + '\n';
- }
- StoreForCode storeForCode = db.StoreForCode.FirstOrDefault(m => m.Code == StoreNo);
- if (storeForCode == null)
- {
- return "未找到仓库" + StoreNo + "相关关联数据" + '\n';
- }
- var store = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCode.StoreId && m.BrandId == BrandId) ?? new StoreHouse();
- MachineForSnNo machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn) ?? new MachineForSnNo();
- if (machineForSnNo == null)
- {
- return "未找到机具" + PosSn + "相关关联数据" + '\n';
- }
- var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId && m.BrandId == Convert.ToInt32(BrandId) && m.BindingState == 0 && m.BuyUserId == userForMakerCode.UserId) ?? new PosMachinesTwo();
- var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId && m.BrandId == Convert.ToInt32(BrandId) && m.BindingState == 0) ?? new PosMachinesTwo();
- if (pos.Id == 0)
- {
- error += "以下操作失败" + PosSn + ',' + "未找到创客" + MakerCode + "的该台机具" + '\n';
- }
- if (store.Id == 0)
- {
- error += "以下操作失败" + PosSn + ',' + StoreNo + ',' + "未找到该仓库" + '\n';
- }
- if (posInfo.Id == 0)
- {
- error += "以下操作失败" + PosSn + ',' + "未找到该品牌的未使用机具" + '\n';
- }
- if (PosSnList.Contains(PosSn))
- {
- error += "以下操作失败" + PosSn + ',' + "该机具号重复" + '\n';
- }
- else
- {
- PosSnList.Add(PosSn);
- }
- }
- if (!string.IsNullOrEmpty(error))
- {
- return "Warning|" + error;
- }
- else
- {
- for (int i = 1; i < list.Count; i++)
- {
- JsonData dr = list[i];
- string itemJson = dr.ToJson();
- string PosSn = itemJson.Contains("\"A\"") ? dr["A"].ToString() : "";
- string BrandId = itemJson.Contains("\"B\"") ? dr["B"].ToString() : "";
- string MakerCode = itemJson.Contains("\"C\"") ? dr["C"].ToString() : "";
- string StoreNo = itemJson.Contains("\"D\"") ? dr["D"].ToString() : "";
- string No = itemJson.Contains("\"E\"") ? dr["E"].ToString() : "";
- string Remark = itemJson.Contains("\"F\"") ? dr["F"].ToString() : "";
- UserForMakerCode userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
- StoreForCode storeForCode = db.StoreForCode.FirstOrDefault(m => m.Code == StoreNo);
- var store = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCode.StoreId && m.BrandId == BrandId) ?? new StoreHouse();
- MachineForSnNo machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn) ?? new MachineForSnNo();
- var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId && m.BrandId == Convert.ToInt32(BrandId) && m.BindingState == 0 && m.BuyUserId == userForMakerCode.UserId) ?? new PosMachinesTwo();
- var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId && m.BrandId == Convert.ToInt32(BrandId) && m.BindingState == 0) ?? new PosMachinesTwo();
- var fromStore = db.StoreHouse.FirstOrDefault(m => m.Id == pos.StoreId && m.BrandId == BrandId) ?? new StoreHouse();
- var toStore = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCode.StoreId && m.BrandId == BrandId) ?? new StoreHouse();
- var user = db.Users.FirstOrDefault(m => m.Id == toStore.UserId) ?? new Users();
- var userAccount = db.UserAccount.FirstOrDefault(m => m.Id == toStore.UserId) ?? new UserAccount();
- var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == Convert.ToInt32(BrandId)) ?? new KqProducts();
- var fuserMachineData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == userForMakerCode.UserId + "_" + brandInfo.Id);
- if (brandInfo.Name.Contains("电签"))
- {
- amount = 200;
- }
- if (brandInfo.Name.Contains("大POS"))
- {
- amount = 300;
- }
- userAccount.ValidAmount -= amount;
- db.SaveChanges();
- if (fromStore.Id != toStore.Id)
- {
- var changeNo = "JJBH" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
- StoreStockChange stockchange = db.StoreStockChange.Add(new StoreStockChange()
- {
- CreateDate = DateTime.Now,
- StoreId = fromStore.Id, //出货仓库
- ToStoreId = toStore.Id, //发货仓库
- BrandId = Convert.ToInt32(BrandId), //产品类型
- ProductName = RelationClass.GetKqProductBrandInfo(Convert.ToInt32(BrandId)), //产品名称
- ChangeNo = changeNo, //变更记录单号
- BizBatchNo = No, //业务批次号
- TransType = 4, //交易类型
- SnNo = PosSn, //SN编号
- StockOpDirect = 1, //库存操作方向
- SnStatus = 1, //SN状态
- DeviceVendor = posInfo.DeviceName, //设备厂商
- DeviceModel = posInfo.DeviceKind, //设备型号
- DeviceType = posInfo.DeviceType, //设备类型
- SourceStoreId = posInfo.SourceStoreId, //源仓库编号
- BrandType = posInfo.DeviceType, //品牌类型
- }).Entity;
- db.SaveChanges();
- db.StoreChangeHistory.Add(new StoreChangeHistory()
- {
- CreateDate = DateTime.Now,
- CreateMan = SysUserName,
- UserId = user.Id, //创客
- FromUserId = posInfo.BuyUserId,//来源创客
- ToUserId = toStore.UserId,//接收创客
- StoreId = fromStore.Id, //出货仓库
- ToStoreId = toStore.Id, //发货仓库
- BrandId = Convert.ToInt32(BrandId), //产品类型
- ChangeRecordNo = changeNo, //变更记录单号
- SeoTitle = "机具驳回仓库",
- BizBatchNo = No, //业务批次号
- TransType = 4,//驳回
- SnNo = PosSn, //SN编号
- });
- db.SaveChanges();
- StoreBalance fbalance = db.StoreBalance.Add(new StoreBalance()
- {
- CreateDate = DateTime.Now,
- StoreId = fromStore.Id, //仓库
- BrandId = Convert.ToInt32(BrandId), //产品类型
- OpStoreNum = 1, //操作库存数
- OpSymbol = "-", //操作符
- BeforeTotalNum = fromStore.TotalNum, //操作前总库存数
- AfterTotalNum = fromStore.TotalNum - 1, //操作后总库存数
- BeforeLaveNum = fromStore.LaveNum, //操作前剩余库存数
- AfterLaveNum = fromStore.LaveNum - 1, //操作后剩余库存数
- BeforeOutNum = fromStore.OutNum, //操作前出库数
- AfterOutNum = fromStore.OutNum - 1, //操作后出库数
- }).Entity;
- db.SaveChanges();
- StoreBalance tbalance = db.StoreBalance.Add(new StoreBalance()
- {
- CreateDate = DateTime.Now,
- StoreId = toStore.Id, //仓库
- BrandId = Convert.ToInt32(BrandId), //产品类型
- OpStoreNum = 1, //操作库存数
- OpSymbol = "+", //操作符
- BeforeTotalNum = toStore.TotalNum, //操作前总库存数
- AfterTotalNum = toStore.TotalNum + 1, //操作后总库存数
- BeforeLaveNum = toStore.LaveNum, //操作前剩余库存数
- AfterLaveNum = toStore.LaveNum + 1, //操作后剩余库存数
- BeforeOutNum = toStore.OutNum, //操作前出库数
- AfterOutNum = toStore.OutNum, //操作后出库数
- }).Entity;
- db.SaveChanges();
- if (!opData.Contains(posInfo.BuyUserId + ":" + posInfo.BrandId))
- {
- opData.Add(posInfo.BuyUserId + ":" + posInfo.BrandId);
- }
- posInfo.StoreId = toStore.Id;
- posInfo.BuyUserId = 0;
- posInfo.UserId = 0;
- posInfo.RecycEndDate = null;
- posInfo.PosSnType = 0;
- posInfo.BindMerchantId = 0;
- posInfo.ActivityList = null;
- posInfo.ScanQrTrade = 0;
- posInfo.DebitCardTrade = 0;
- posInfo.PrizeParams = null;
- posInfo.IsVip = 0;
- posInfo.CreditTrade = 0;
- posInfo.UserNav = null;
- posInfo.TransferTime = null;
- posInfo.IsPurchase = 0;
- posInfo.BindingTime = null;
- posInfo.BindingState = 0;
- posInfo.ActivationTime = null;
- posInfo.ActivationState = 0;
- posInfo.LeaderUserId = 0;
- posInfo.PreUserId = 0;
- posInfo.IsFirst = 0;
- fuserMachineData.TotalMachineCount -= 1;
- fuserMachineData.UnBindCount -= 1;
- toStore.TotalNum += 1;
- toStore.LaveNum += 1;
- fromStore.TotalNum -= 1;
- fromStore.LaveNum -= 1;
- PublicFunction.ClearPosHistory(db, posInfo.PosSn); //清除机具历史记录
- db.SaveChanges();
- }
- else
- {
- var changeNo = "JJBH" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
- StoreStockChange stockchange = db.StoreStockChange.Add(new StoreStockChange()
- {
- CreateDate = DateTime.Now,
- StoreId = fromStore.Id, //出货仓库
- ToStoreId = toStore.Id, //发货仓库
- BrandId = Convert.ToInt32(BrandId), //产品类型
- ProductName = RelationClass.GetKqProductBrandInfo(Convert.ToInt32(BrandId)), //产品名称
- ChangeNo = changeNo, //变更记录单号
- BizBatchNo = No, //业务批次号
- TransType = 4, //交易类型
- SnNo = PosSn, //SN编号
- StockOpDirect = 1, //库存操作方向
- SnStatus = 1, //SN状态
- DeviceVendor = posInfo.DeviceName, //设备厂商
- DeviceModel = posInfo.DeviceKind, //设备型号
- DeviceType = posInfo.DeviceType, //设备类型
- SourceStoreId = posInfo.SourceStoreId, //源仓库编号
- BrandType = posInfo.DeviceType, //品牌类型
- }).Entity;
- db.SaveChanges();
- db.StoreChangeHistory.Add(new StoreChangeHistory()
- {
- CreateDate = DateTime.Now,
- CreateMan = SysUserName,
- UserId = user.Id, //创客
- FromUserId = user.Id,//来源创客
- ToUserId = toStore.UserId,//接收创客
- StoreId = fromStore.Id, //出货仓库
- ToStoreId = toStore.Id, //发货仓库
- BrandId = Convert.ToInt32(BrandId), //产品类型
- ChangeRecordNo = changeNo, //变更记录单号
- SeoTitle = "机具驳回仓库",
- BizBatchNo = No, //业务批次号
- SnNo = PosSn, //SN编号
- TransType = 4,//驳回
- });
- db.SaveChanges();
- StoreBalance balance = db.StoreBalance.Add(new StoreBalance()
- {
- CreateDate = DateTime.Now,
- StoreId = fromStore.Id, //仓库
- BrandId = Convert.ToInt32(BrandId), //产品类型
- OpStoreNum = 1, //操作库存数
- OpSymbol = "-", //操作符
- BeforeTotalNum = fromStore.TotalNum, //操作前总库存数
- AfterTotalNum = fromStore.TotalNum - 1, //操作后总库存数
- BeforeLaveNum = fromStore.LaveNum, //操作前剩余库存数
- AfterLaveNum = fromStore.LaveNum - 1, //操作后剩余库存数
- BeforeOutNum = fromStore.OutNum, //操作前出库数
- AfterOutNum = fromStore.OutNum - 1, //操作后出库数
- }).Entity;
- db.SaveChanges();
- if (!opData.Contains(posInfo.BuyUserId + ":" + posInfo.BrandId))
- {
- opData.Add(posInfo.BuyUserId + ":" + posInfo.BrandId);
- }
- posInfo.StoreId = toStore.Id;
- posInfo.BuyUserId = 0;
- posInfo.UserId = 0;
- posInfo.RecycEndDate = null;
- posInfo.PosSnType = 0;
- posInfo.BindMerchantId = 0;
- posInfo.ActivityList = null;
- posInfo.ScanQrTrade = 0;
- posInfo.DebitCardTrade = 0;
- posInfo.PrizeParams = null;
- posInfo.IsVip = 0;
- posInfo.CreditTrade = 0;
- posInfo.UserNav = null;
- posInfo.TransferTime = null;
- posInfo.IsPurchase = 0;
- posInfo.BindingTime = null;
- posInfo.BindingState = 0;
- posInfo.ActivationTime = null;
- posInfo.ActivationState = 0;
- posInfo.LeaderUserId = 0;
- posInfo.PreUserId = 0;
- posInfo.IsFirst = 0;
- fuserMachineData.TotalMachineCount -= 1;
- fuserMachineData.UnBindCount -= 1;
- toStore.LaveNum += 1;
- toStore.TotalNum += 1;
- PublicFunction.ClearPosHistory(db, posInfo.PosSn); //清除机具历史记录
- db.SaveChanges();
- }
- db.SaveChanges();
- }
- }
- foreach (string sub in opData)
- {
- string[] datalist = sub.Split(":");
- PublicFunction.SycnMachineCount(int.Parse(datalist[0]), int.Parse(datalist[1]));
- }
- }
- AddSysLog("0", "MachinesRejectStore", "Import");
- return "success";
- }
- #endregion
- #region 导出Excel
- /// <summary>
- /// 导出Excel
- /// </summary>
- /// <returns></returns>
- public JsonResult ExportExcel(StoreHouse data, string UserIdMakerCode, string UserIdRealName, string ManageUserIdRealName, string ManageUserIdMobile, string ManageUserIdMakerCode, string StoreStatusSelect)
- {
- Dictionary<string, string> Fields = new Dictionary<string, string>();
- Fields.Add("StoreNo", "1"); //仓库编号
- Fields.Add("CreateDate", "3"); //时间
- Fields.Add("StoreName", "1"); //仓库名称
- Fields.Add("ManagerEmail", "1"); //管理者邮箱
- string condition = " and Status>-1";
- //仓库归属人创客编号
- if (!string.IsNullOrEmpty(UserIdMakerCode))
- {
- condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
- }
- //仓库归属人真实姓名
- if (!string.IsNullOrEmpty(UserIdRealName))
- {
- condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
- }
- //仓库管理员真实姓名
- if (!string.IsNullOrEmpty(ManageUserIdRealName))
- {
- condition += " and ManageUserId in (select ManageUserId from UserForRealName where RealName='" + ManageUserIdRealName + "')";
- }
- //仓库管理员手机号
- if (!string.IsNullOrEmpty(ManageUserIdMobile))
- {
- condition += " and ManageUserId in (select ManageUserId from UserForMobile where Mobile='" + ManageUserIdMobile + "')";
- }
- //仓库管理员创客编号
- if (!string.IsNullOrEmpty(ManageUserIdMakerCode))
- {
- condition += " and ManageUserId in (select ManageUserId from UserForMakerCode where MakerCode='" + ManageUserIdMakerCode + "')";
- }
- //仓库状态
- if (!string.IsNullOrEmpty(StoreStatusSelect))
- {
- condition += " and StoreStatus=" + StoreStatusSelect;
- }
- Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("StoreHouse", Fields, "Id desc", "0", 1, 20000, condition, "StoreNo,StoreName,UserId,BrandId,Address,ManageUserId,ManagerEmail,StoreType,TotalNum,LaveNum,OutNum,LimitTopUserId,StoreStatus,StoreKind", false);
- List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
- foreach (Dictionary<string, object> dic in diclist)
- {
- //仓库归属人
- int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
- Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
- dic["UserIdMakerCode"] = userid_Users.MakerCode;
- dic["UserIdRealName"] = userid_Users.RealName;
- //产品类型
- dic["BrandId"] = RelationClass.GetKqProductBrandList(dic["BrandId"].ToString());
- //仓库管理员
- int ManageUserId = int.Parse(function.CheckInt(dic["ManageUserId"].ToString()));
- Users manageuserid_Users = db.Users.FirstOrDefault(m => m.Id == ManageUserId) ?? new Users();
- dic["ManageUserIdRealName"] = manageuserid_Users.RealName;
- dic["ManageUserIdMobile"] = manageuserid_Users.Mobile;
- dic["ManageUserIdMakerCode"] = manageuserid_Users.MakerCode;
- //仓库类型
- int StoreType = int.Parse(dic["StoreType"].ToString());
- if (StoreType == 0) dic["StoreType"] = "实体仓";
- if (StoreType == 1) dic["StoreType"] = "虚拟仓";
- //仓库状态
- int StoreStatus = int.Parse(dic["StoreStatus"].ToString());
- if (StoreStatus == 1) dic["StoreStatus"] = "启用";
- if (StoreStatus == 0) dic["StoreStatus"] = "禁用";
- //仓库归属类型
- int StoreKind = int.Parse(dic["StoreKind"].ToString());
- if (StoreKind == 0) dic["StoreKind"] = "分仓";
- if (StoreKind == 1) dic["StoreKind"] = "总仓";
- }
- Dictionary<string, object> result = new Dictionary<string, object>();
- result.Add("Status", "1");
- result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
- result.Add("Obj", diclist);
- Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
- ReturnFields.Add("StoreNo", "仓库编号");
- ReturnFields.Add("StoreName", "仓库名称");
- ReturnFields.Add("UserIdMakerCode", "仓库归属人创客编号");
- ReturnFields.Add("UserIdRealName", "仓库归属人真实姓名");
- ReturnFields.Add("BrandId", "产品类型");
- ReturnFields.Add("Address", "仓库地址");
- ReturnFields.Add("ManageUserIdRealName", "仓库管理员真实姓名");
- ReturnFields.Add("ManageUserIdMobile", "仓库管理员手机号");
- ReturnFields.Add("ManageUserIdMakerCode", "仓库管理员创客编号");
- ReturnFields.Add("ManagerEmail", "管理者邮箱");
- ReturnFields.Add("StoreType", "仓库类型");
- ReturnFields.Add("TotalNum", "总库存数");
- ReturnFields.Add("LaveNum", "剩余库存数");
- ReturnFields.Add("OutNum", "出库数");
- ReturnFields.Add("LimitTopUserId", "限制创客特殊仓库");
- ReturnFields.Add("StoreStatus", "仓库状态");
- ReturnFields.Add("StoreKind", "仓库归属类型");
- result.Add("Fields", ReturnFields);
- AddSysLog("0", "StoreHouse", "ExportExcel");
- return Json(result);
- }
- #endregion
- #region 仓库列表
- /// <summary>
- /// 根据条件查询仓库列表
- /// </summary>
- /// <returns></returns>
- public IActionResult Stat(StoreHouse data, string right)
- {
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- return View();
- }
- #endregion
- #region 根据条件查询仓库列表
- /// <summary>
- /// 仓库列表
- /// </summary>
- /// <returns></returns>
- public JsonResult StatDo(string CreateDateData, int page = 1, int limit = 30)
- {
- OtherMySqlConn.connstr = ConfigurationManager.AppSettings["StatSqlConnStr"].ToString();
- string sCreateDate = DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00";
- string eCreateDate = DateTime.Now.ToString("yyyy-MM-dd") + " 23:59:59";
- if (!string.IsNullOrEmpty(CreateDateData))
- {
- string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
- sCreateDate = datelist[0] + " 00:00:00";
- eCreateDate = datelist[1] + " 23:59:59";
- }
- else
- {
- Dictionary<string, object> nodata = new Dictionary<string, object>();
- nodata.Add("code", 0);
- nodata.Add("msg", "");
- nodata.Add("count", 0);
- nodata.Add("data", new List<Dictionary<string, object>>());
- return Json(nodata);
- }
- string minId = "0";
- string maxId = "0";
- string minPosId = "0";
- string maxPosId = "0";
- DataTable startDt = OtherMySqlConn.dtable("select min(Id) from StoreStockChange where CreateDate>='" + sCreateDate + "'");
- if (startDt.Rows.Count > 0)
- {
- minId = function.CheckInt(startDt.Rows[0][0].ToString());
- if (minId == "0")
- {
- startDt = OtherMySqlConn.dtable("select max(Id) from StoreStockChange");
- if (startDt.Rows.Count > 0)
- {
- minId = function.CheckInt(startDt.Rows[0][0].ToString());
- }
- }
- }
- DataTable endDt = OtherMySqlConn.dtable("select max(Id) from StoreStockChange where CreateDate>='" + sCreateDate + "'");
- if (endDt.Rows.Count > 0)
- {
- maxId = function.CheckInt(endDt.Rows[0][0].ToString());
- if (minId == "0")
- {
- endDt = OtherMySqlConn.dtable("select max(Id) from StoreStockChange");
- if (endDt.Rows.Count > 0)
- {
- maxId = function.CheckInt(endDt.Rows[0][0].ToString());
- }
- }
- }
- DataTable startPosDt = OtherMySqlConn.dtable("select min(Id) from PosMachinesTwo where ActivationTime>='" + sCreateDate + "'");
- if (startPosDt.Rows.Count > 0)
- {
- minPosId = function.CheckInt(startPosDt.Rows[0][0].ToString());
- if (minPosId == "0")
- {
- startPosDt = OtherMySqlConn.dtable("select max(Id) from PosMachinesTwo");
- if (startPosDt.Rows.Count > 0)
- {
- minPosId = function.CheckInt(startPosDt.Rows[0][0].ToString());
- }
- }
- }
- DataTable endPosDt = OtherMySqlConn.dtable("select max(Id) from PosMachinesTwo where ActivationTime>='" + sCreateDate + "'");
- if (endPosDt.Rows.Count > 0)
- {
- maxPosId = function.CheckInt(endPosDt.Rows[0][0].ToString());
- if (maxPosId == "0")
- {
- endPosDt = OtherMySqlConn.dtable("select max(Id) from PosMachinesTwo");
- if (endPosDt.Rows.Count > 0)
- {
- maxPosId = function.CheckInt(endPosDt.Rows[0][0].ToString());
- }
- }
- }
- DataTable list = OtherMySqlConn.dtable("select * from (select s.StoreName,s.StoreNo,u.RealName,u.Mobile,k.Name,s.LaveNum,(select count(Id) from StoreStockChange where Id>=" + minId + " and Id<=" + maxId + " and CreateDate>='" + sCreateDate + "' and CreateDate<='" + eCreateDate + "' and StoreId=s.Id and TransType=1) as c1,(select count(Id) from StoreStockChange where Id>=" + minId + " and Id<=" + maxId + " and CreateDate>='" + sCreateDate + "' and CreateDate<='" + eCreateDate + "' and StoreId=s.Id and TransType in (10,11,2)) as c2,(select count(Id) from PosMachinesTwo where Id>=" + minPosId + " and Id<=" + maxPosId + " and ActivationState=1 and ActivationTime>='" + sCreateDate + "' and ActivationTime<='" + eCreateDate + "' and StoreId=s.Id) as c3 from StoreHouse s left join Users u on s.BrandId>0 and s.UserId=u.Id left join KqProducts k on s.BrandId=k.Id) tb where c1>0 or c2>0 or c3>0");
- int recordcount = list.Rows.Count;
- List<Dictionary<string, object>> diclist = new List<Dictionary<string, object>>();
- foreach (DataRow sub in list.Rows)
- {
- Dictionary<string, object> row = new Dictionary<string, object>();
- row.Add("StoreName", sub["StoreName"].ToString());
- row.Add("StoreNo", sub["StoreNo"].ToString());
- row.Add("Mobile", sub["Mobile"].ToString());
- row.Add("RealName", sub["RealName"].ToString());
- row.Add("Name", sub["Name"].ToString());
- row.Add("LaveNum", sub["LaveNum"].ToString());
- row.Add("c1", sub["c1"].ToString());
- row.Add("c2", sub["c2"].ToString());
- row.Add("c3", sub["c3"].ToString());
- diclist.Add(row);
- }
- Dictionary<string, object> obj = new Dictionary<string, object>();
- obj.Add("code", 0);
- obj.Add("msg", "");
- obj.Add("count", recordcount);
- obj.Add("data", diclist);
- return Json(obj);
- }
- #endregion
- #region 导出Excel
- /// <summary>
- /// 导出Excel
- /// </summary>
- /// <returns></returns>
- public JsonResult StatExportExcel(string CreateDateData)
- {
- OtherMySqlConn.connstr = ConfigurationManager.AppSettings["StatSqlConnStr"].ToString();
- string sCreateDate = DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00";
- string eCreateDate = DateTime.Now.ToString("yyyy-MM-dd") + " 23:59:59";
- if (!string.IsNullOrEmpty(CreateDateData))
- {
- string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
- sCreateDate = datelist[0] + " 00:00:00";
- eCreateDate = datelist[1] + " 23:59:59";
- }
- else
- {
- Dictionary<string, object> nodata = new Dictionary<string, object>();
- nodata.Add("Status", "1");
- nodata.Add("Info", "分仓统计数据报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
- nodata.Add("Obj", new List<Dictionary<string, object>>());
- Dictionary<string, object> NoDataReturnFields = new Dictionary<string, object>();
- NoDataReturnFields.Add("StoreName", "仓库名称");
- NoDataReturnFields.Add("StoreNo", "仓库编号");
- NoDataReturnFields.Add("Mobile", "仓库所属人手机号");
- NoDataReturnFields.Add("RealName", "仓库所属人名称");
- NoDataReturnFields.Add("MakerCode", "仓库所属人编码");
- NoDataReturnFields.Add("ManageMakerCode", "仓库管理员编码");
- NoDataReturnFields.Add("Name", "品牌");
- NoDataReturnFields.Add("LaveNum", "当前库存");
- NoDataReturnFields.Add("c1", "出库(调拨)量");
- NoDataReturnFields.Add("c2", "出货(发货到创客)量");
- NoDataReturnFields.Add("c3", "激活量");
- nodata.Add("Fields", NoDataReturnFields);
- return Json(nodata);
- }
- string minId = "0";
- string maxId = "0";
- string minPosId = "0";
- string maxPosId = "0";
- DataTable startDt = OtherMySqlConn.dtable("select min(Id) from StoreStockChange where CreateDate>='" + sCreateDate + "'");
- if (startDt.Rows.Count > 0)
- {
- minId = function.CheckInt(startDt.Rows[0][0].ToString());
- if (minId == "0")
- {
- startDt = OtherMySqlConn.dtable("select max(Id) from StoreStockChange");
- if (startDt.Rows.Count > 0)
- {
- minId = function.CheckInt(startDt.Rows[0][0].ToString());
- }
- }
- }
- DataTable endDt = OtherMySqlConn.dtable("select max(Id) from StoreStockChange where CreateDate>='" + sCreateDate + "'");
- if (endDt.Rows.Count > 0)
- {
- maxId = function.CheckInt(endDt.Rows[0][0].ToString());
- if (minId == "0")
- {
- endDt = OtherMySqlConn.dtable("select max(Id) from StoreStockChange");
- if (endDt.Rows.Count > 0)
- {
- maxId = function.CheckInt(endDt.Rows[0][0].ToString());
- }
- }
- }
- DataTable startPosDt = OtherMySqlConn.dtable("select min(Id) from PosMachinesTwo where ActivationTime>='" + sCreateDate + "'");
- if (startPosDt.Rows.Count > 0)
- {
- minPosId = function.CheckInt(startPosDt.Rows[0][0].ToString());
- if (minPosId == "0")
- {
- startPosDt = OtherMySqlConn.dtable("select max(Id) from PosMachinesTwo");
- if (startPosDt.Rows.Count > 0)
- {
- minPosId = function.CheckInt(startPosDt.Rows[0][0].ToString());
- }
- }
- }
- DataTable endPosDt = OtherMySqlConn.dtable("select max(Id) from PosMachinesTwo where ActivationTime>='" + sCreateDate + "'");
- if (endPosDt.Rows.Count > 0)
- {
- maxPosId = function.CheckInt(endPosDt.Rows[0][0].ToString());
- if (maxPosId == "0")
- {
- endPosDt = OtherMySqlConn.dtable("select max(Id) from PosMachinesTwo");
- if (endPosDt.Rows.Count > 0)
- {
- maxPosId = function.CheckInt(endPosDt.Rows[0][0].ToString());
- }
- }
- }
- DataTable list = OtherMySqlConn.dtable("select * from (select s.StoreName,s.StoreNo,u.RealName,u.Mobile,u.MakerCode,(select MakerCode from Users where Id=s.ManageUserId) as ManageMakerCode,k.Name,s.LaveNum,(select count(Id) from StoreStockChange where Id>=" + minId + " and Id<=" + maxId + " and CreateDate>='" + sCreateDate + "' and CreateDate<='" + eCreateDate + "' and StoreId=s.Id and TransType=1) as c1,(select count(Id) from StoreStockChange where Id>=" + minId + " and Id<=" + maxId + " and CreateDate>='" + sCreateDate + "' and CreateDate<='" + eCreateDate + "' and StoreId=s.Id and TransType in (10,11,2)) as c2,(select count(Id) from PosMachinesTwo where Id>=" + minPosId + " and Id<=" + maxPosId + " and ActivationState=1 and ActivationTime>='" + sCreateDate + "' and ActivationTime<='" + eCreateDate + "' and StoreId=s.Id) as c3 from StoreHouse s left join Users u on s.BrandId>0 and s.UserId=u.Id left join KqProducts k on s.BrandId=k.Id) tb where c1>0 or c2>0 or c3>0");
- int recordcount = list.Rows.Count;
- List<Dictionary<string, object>> diclist = new List<Dictionary<string, object>>();
- foreach (DataRow sub in list.Rows)
- {
- Dictionary<string, object> row = new Dictionary<string, object>();
- row.Add("StoreName", sub["StoreName"].ToString());
- row.Add("StoreNo", sub["StoreNo"].ToString());
- row.Add("Mobile", sub["Mobile"].ToString());
- row.Add("RealName", sub["RealName"].ToString());
- row.Add("MakerCode", sub["MakerCode"].ToString());
- row.Add("ManageMakerCode", sub["ManageMakerCode"].ToString());
- row.Add("Name", sub["Name"].ToString());
- row.Add("LaveNum", sub["LaveNum"].ToString());
- row.Add("c1", sub["c1"].ToString());
- row.Add("c2", sub["c2"].ToString());
- row.Add("c3", sub["c3"].ToString());
- diclist.Add(row);
- }
- Dictionary<string, object> result = new Dictionary<string, object>();
- result.Add("Status", "1");
- result.Add("Info", "分仓统计数据报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
- result.Add("Obj", diclist);
- Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
- ReturnFields.Add("StoreName", "仓库名称");
- ReturnFields.Add("StoreNo", "仓库编号");
- ReturnFields.Add("Mobile", "仓库所属人手机号");
- ReturnFields.Add("RealName", "仓库所属人名称");
- ReturnFields.Add("MakerCode", "仓库所属人编码");
- ReturnFields.Add("ManageMakerCode", "仓库管理员编码");
- ReturnFields.Add("Name", "品牌");
- ReturnFields.Add("LaveNum", "当前库存");
- ReturnFields.Add("c1", "出库(调拨)量");
- ReturnFields.Add("c2", "出货(发货到创客)量");
- ReturnFields.Add("c3", "激活量");
- result.Add("Fields", ReturnFields);
- AddSysLog("0", "StoreHouse", "StatExportExcel");
- return Json(result);
- }
- #endregion
- #region 同步数据
- /// <summary>
- /// 同步数据
- /// </summary>
- /// <returns></returns>
- public string SycnData(int Id = 0)
- {
- if (Id > 0)
- {
- DataTable dt = OtherMySqlConn.dtable("select Id,(select count(Id) from PosMachinesTwo where StoreId=s.Id and BuyUserId=0 and PreUserId=0 and Status>-1) as CurLaveNum from StoreHouse s where Id=" + Id);
- if (dt.Rows.Count > 0)
- {
- int CurLaveNum = int.Parse(function.CheckInt(dt.Rows[0]["CurLaveNum"].ToString()));
- StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == Id);
- if (store != null)
- {
- store.LaveNum = CurLaveNum;
- db.SaveChanges();
- }
- }
- }
- else
- {
- DataTable dt = OtherMySqlConn.dtable("select s.Id,LaveNum,count(p.Id) as CurLaveNum from StoreHouse s left join PosMachinesTwo p on s.Id=p.StoreId and s.BrandId=p.BrandId and p.BuyUserId=0 and p.PreUserId=0 and p.Status>-1 group by s.Id HAVING LaveNum!=count(p.Id)");
- foreach (DataRow dr in dt.Rows)
- {
- int StoreId = int.Parse(function.CheckInt(dr["Id"].ToString()));
- int CurLaveNum = int.Parse(function.CheckInt(dr["CurLaveNum"].ToString()));
- StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId);
- if (store != null)
- {
- store.LaveNum = CurLaveNum;
- db.SaveChanges();
- }
- }
- }
- AddSysLog(Id, "StoreHouse", "SycnData");
- db.SaveChanges();
- return "success";
- }
- #endregion
- #region 重置仓库额度
- /// <summary>
- /// 重置仓库额度
- /// </summary>
- /// <returns></returns>
- public string SycnAmountData(int Id = 0)
- {
- if (Id > 0)
- {
- var storeHouse = db.StoreHouse.FirstOrDefault(m => m.Id == Id && m.Sort == 0) ?? new StoreHouse();
- RedisDbconn.Instance.AddList("ResetStoreReserveQueue", storeHouse.UserId);
- }
- AddSysLog(Id, "StoreHouse", "SycnAmountData");
- db.SaveChanges();
- return "success";
- }
- #endregion
- #region 设置缓存
- private void SetRedis(int Id, int UserId)
- {
- if (UserId > 0)
- {
- }
- }
- #endregion
- #region 关联分仓
- /// <summary>
- /// 关联分仓
- /// </summary>
- /// <returns></returns>
- public IActionResult BatchSetting(string right, string StoreIds)
- {
- string[] idlist = StoreIds.Split(new char[] { ',' });
- decimal totalAmount = 0;
- decimal deposit = 0;
- var userIds = "";
- foreach (var item in idlist)
- {
- int StoreId = int.Parse(item);
- var amount = 0;
- var tamount = 0;
- var storeInfo = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId);
- var posCount = db.PosMachinesTwo.Count(m => m.StoreId == StoreId && m.UserId == 0 && m.BuyUserId == 0 && m.OpId == 0);
- var BrandId = int.Parse(storeInfo.BrandId);
- var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == BrandId);
- if (brandInfo.Name.Contains("电签"))
- {
- amount = 100;
- }
- if (brandInfo.Name.Contains("大POS"))
- {
- amount = 150;
- }
- if (!userIds.Contains(storeInfo.UserId + ","))
- {
- userIds += storeInfo.UserId + ",";
- deposit += storeInfo.Deposit;
- }
- tamount = amount * posCount;//扣减运营中心该品牌机具额度
- totalAmount += tamount;//关联分仓打标记运营中心所需额度
- }
- ViewBag.RightInfo = RightInfo;
- ViewBag.right = right;
- ViewBag.totalAmount = "关联分仓机具需要额度:" + totalAmount;
- ViewBag.deposit = "关联分仓获得押金:" + deposit;
- return View();
- }
- #endregion
-
- }
- }
|