StoreHouseController.cs 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400
  1. /*
  2. * 仓库
  3. */
  4. using System;
  5. using System.Web;
  6. using System.Collections.Generic;
  7. using System.Diagnostics;
  8. using System.Linq;
  9. using System.Data;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. using Microsoft.AspNetCore.Mvc;
  13. using Microsoft.AspNetCore.Http;
  14. using Microsoft.Extensions.Logging;
  15. using Microsoft.Extensions.Options;
  16. using MySystem.Models;
  17. using Library;
  18. using LitJson;
  19. using MySystemLib;
  20. namespace MySystem.Areas.Admin.Controllers
  21. {
  22. [Area("Admin")]
  23. [Route("Admin/[controller]/[action]")]
  24. public class StoreHouseController : BaseController
  25. {
  26. public StoreHouseController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  27. {
  28. OtherMySqlConn.connstr = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  29. }
  30. #region 仓库列表
  31. /// <summary>
  32. /// 根据条件查询仓库列表
  33. /// </summary>
  34. /// <returns></returns>
  35. public IActionResult Index(StoreHouse data, string right)
  36. {
  37. ViewBag.RightInfo = RightInfo;
  38. ViewBag.right = right;
  39. return View();
  40. }
  41. #endregion
  42. #region 根据条件查询仓库列表
  43. /// <summary>
  44. /// 仓库列表
  45. /// </summary>
  46. /// <returns></returns>
  47. public JsonResult IndexData(StoreHouse data, string UserIdMakerCode, string UserIdRealName, string ManageUserIdRealName, string ManageUserIdMobile, string ManageUserIdMakerCode, string StoreStatusSelect, string CreateDateData, int ShowFlag = 0, int page = 1, int limit = 30)
  48. {
  49. Dictionary<string, string> Fields = new Dictionary<string, string>();
  50. Fields.Add("StoreNo", "1"); //仓库编号
  51. Fields.Add("StoreName", "1"); //仓库名称
  52. Fields.Add("ManagerEmail", "1"); //管理者邮箱
  53. if (ShowFlag == 0)
  54. {
  55. Dictionary<string, object> objs = new Dictionary<string, object>();
  56. return Json(objs);
  57. }
  58. string condition = " and Status>-1";
  59. //仓库归属人创客编号
  60. if (!string.IsNullOrEmpty(UserIdMakerCode))
  61. {
  62. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  63. }
  64. //仓库归属人真实姓名
  65. if (!string.IsNullOrEmpty(UserIdRealName))
  66. {
  67. DataTable dt = OtherMySqlConn.dtable("SELECT Id FROM Users WHERE RealName like '%" + UserIdRealName + "%'");
  68. var Count = dt.Rows.Count;
  69. int times = 0;
  70. string UserIds = "";
  71. foreach (DataRow item in dt.Rows)
  72. {
  73. times++;
  74. if (times == Count)
  75. {
  76. UserIds += item["Id"].ToString();
  77. }
  78. else
  79. {
  80. UserIds += item["Id"].ToString() + ",";
  81. }
  82. }
  83. // condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  84. condition += " and UserId in (" + UserIds + ")";
  85. }
  86. //仓库管理员真实姓名
  87. if (!string.IsNullOrEmpty(ManageUserIdRealName))
  88. {
  89. DataTable dts = OtherMySqlConn.dtable("SELECT Id FROM Users WHERE RealName like '%" + ManageUserIdRealName + "%'");
  90. var Counts = dts.Rows.Count;
  91. int time = 1;
  92. string UserIdss = "";
  93. foreach (DataRow items in dts.Rows)
  94. {
  95. time++;
  96. if (time == Counts)
  97. {
  98. UserIdss += items["Id"].ToString();
  99. }
  100. else
  101. {
  102. UserIdss += items["Id"].ToString() + ",";
  103. }
  104. }
  105. // condition += " and ManageUserId in (select ManageUserId from UserForRealName where RealName='" + ManageUserIdRealName + "')";
  106. condition += " and UserId in (" + UserIdss + ")";
  107. }
  108. //仓库管理员手机号
  109. if (!string.IsNullOrEmpty(ManageUserIdMobile))
  110. {
  111. condition += " and ManageUserId in (select ManageUserId from UserForMobile where Mobile='" + ManageUserIdMobile + "')";
  112. }
  113. //仓库管理员创客编号
  114. if (!string.IsNullOrEmpty(ManageUserIdMakerCode))
  115. {
  116. condition += " and ManageUserId in (select ManageUserId from UserForMakerCode where MakerCode='" + ManageUserIdMakerCode + "')";
  117. }
  118. //仓库状态
  119. if (!string.IsNullOrEmpty(StoreStatusSelect))
  120. {
  121. condition += " and StoreStatus=" + StoreStatusSelect;
  122. }
  123. if (!string.IsNullOrEmpty(CreateDateData))
  124. {
  125. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  126. string start = datelist[0];
  127. string end = datelist[1];
  128. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  129. }
  130. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("StoreHouse", Fields, "Id desc", "0", page, limit, condition);
  131. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  132. foreach (Dictionary<string, object> dic in diclist)
  133. {
  134. //仓库归属人
  135. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  136. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  137. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  138. dic["UserIdRealName"] = userid_Users.RealName;
  139. //产品类型
  140. dic["BrandId"] = RelationClass.GetKqProductBrandList(dic["BrandId"].ToString());
  141. //仓库管理员
  142. int ManageUserId = int.Parse(function.CheckInt(dic["ManageUserId"].ToString()));
  143. Users manageuserid_Users = db.Users.FirstOrDefault(m => m.Id == ManageUserId) ?? new Users();
  144. dic["ManageUserIdRealName"] = manageuserid_Users.RealName;
  145. dic["ManageUserIdMobile"] = manageuserid_Users.Mobile;
  146. dic["ManageUserIdMakerCode"] = manageuserid_Users.MakerCode;
  147. //仓库类型
  148. int StoreType = int.Parse(dic["StoreType"].ToString());
  149. if (StoreType == 0) dic["StoreType"] = "实体仓";
  150. if (StoreType == 1) dic["StoreType"] = "虚拟仓";
  151. //仓库状态
  152. int StoreStatus = int.Parse(dic["StoreStatus"].ToString());
  153. if (StoreStatus == 1) dic["StoreStatus"] = "启用";
  154. if (StoreStatus == 0) dic["StoreStatus"] = "禁用";
  155. //仓库归属类型
  156. int StoreKind = int.Parse(dic["StoreKind"].ToString());
  157. if (StoreKind == 0) dic["StoreKind"] = "分仓";
  158. if (StoreKind == 1) dic["StoreKind"] = "总仓";
  159. //小分仓
  160. int Id = int.Parse(function.CheckInt(dic["Id"].ToString()));
  161. int PreCount = db.PreSendStockDetail.Count(m => m.FromStoreId == Id && m.ApplyFlag == 0 && m.Status >= 0 && m.Status <= 1);
  162. dic["PreNum"] = PreCount.ToString();
  163. //分仓额度
  164. var amount = db.UserAccount.FirstOrDefault(m => m.Id == UserId) ?? new UserAccount();
  165. var ValidAmount = amount.ValidAmount;
  166. var FixedAmount = amount.FixedAmount;
  167. var TempAmount = amount.TempAmount + amount.TempAmountForBalance;
  168. var check = db.StoreHouseAmountPromiss.Any(m => m.ToUserId == UserId);
  169. decimal PromissAmount = 0;
  170. var ThisMonthPreAmount = amount.ThisMonthPreAmount;
  171. var ValidPreAmount = amount.ValidPreAmount;
  172. if (check)
  173. {
  174. PromissAmount = db.StoreHouseAmountPromiss.Where(m => m.Status == 1 && m.ToUserId == UserId).Sum(m => m.PromissAmount);
  175. }
  176. dic["ValidAmount"] = ValidAmount.ToString();//可用额度
  177. dic["FixedAmount"] = FixedAmount.ToString();//固定额度
  178. dic["TempAmount"] = TempAmount.ToString();//临时额度
  179. dic["PromissAmount"] = PromissAmount.ToString();//担保金额
  180. dic["ThisMonthPreAmount"] = PromissAmount.ToString();//本月小分仓额度
  181. dic["ValidPreAmount"] = PromissAmount.ToString();//可用小分仓额度
  182. }
  183. return Json(obj);
  184. }
  185. #endregion
  186. #region 增加仓库
  187. /// <summary>
  188. /// 增加或修改仓库信息
  189. /// </summary>
  190. /// <returns></returns>
  191. public IActionResult Add(string right)
  192. {
  193. ViewBag.RightInfo = RightInfo;
  194. ViewBag.right = right;
  195. return View();
  196. }
  197. #endregion
  198. #region 增加仓库
  199. /// <summary>
  200. /// 增加或修改仓库信息
  201. /// </summary>
  202. /// <returns></returns>
  203. [HttpPost]
  204. public string Add(StoreHouse data, string ManageMakerCode, string MakerCode)
  205. {
  206. string BrandIdString = data.BrandId;
  207. if (!string.IsNullOrEmpty(BrandIdString))
  208. {
  209. string[] BrandIdList = BrandIdString.Split(',');
  210. foreach (string BrandId in BrandIdList)
  211. {
  212. Dictionary<string, object> Fields = new Dictionary<string, object>();
  213. Fields.Add("CreateMan", SysUserName); //创建人
  214. Fields.Add("StoreName", data.StoreName); //仓库名称
  215. UserForMakerCode user = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  216. if (user == null)
  217. {
  218. return "您输入的仓库归属创客编号不存在,请重新输入正确的仓库归属创客编号";
  219. }
  220. Fields.Add("UserId", user.UserId); //仓库归属人
  221. Fields.Add("Areas", data.Areas); //所属地区
  222. Fields.Add("Address", data.Address); //仓库地址
  223. UserForMakerCode manage = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ManageMakerCode);
  224. if (manage == null)
  225. {
  226. return "您输入的仓库负责人编号不存在,请重新输入正确的仓库负责人编号";
  227. }
  228. Fields.Add("ManageUserId", manage.UserId); //仓库管理员
  229. Fields.Add("ManagerEmail", data.ManagerEmail); //管理者邮箱
  230. Fields.Add("ManageMobile", data.ManageMobile);
  231. Fields.Add("Remark", data.Remark); //备注
  232. Fields.Add("LimitTopUserId", data.LimitTopUserId); //限制创客特殊仓库
  233. Fields.Add("StoreKind", data.StoreKind); //仓库归属类型
  234. int bid = int.Parse(BrandId);
  235. KqProducts pro = db.KqProducts.FirstOrDefault(m => m.Id == bid) ?? new KqProducts();
  236. Fields.Add("BrandId", BrandId);
  237. Fields.Add("ProductName", pro.Name);
  238. Fields.Add("StoreStatus", 1);
  239. Fields.Add("Status", 1);
  240. var name = db.StoreHouse.FirstOrDefault(m => m.UserId == user.UserId && m.BrandId == BrandId && m.StoreName == data.StoreName);
  241. if (name != null)
  242. {
  243. return "您的仓库名重复,请重新填写";
  244. }
  245. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("StoreHouse", Fields, 0);
  246. StoreHouse edit = db.StoreHouse.FirstOrDefault(m => m.Id == Id);
  247. if (edit != null)
  248. {
  249. string No = Id.ToString();
  250. for (int i = 0; i < 7 - Id.ToString().Length; i++)
  251. {
  252. No = "0" + No;
  253. }
  254. No = "S" + No;
  255. edit.StoreNo = No;
  256. db.StoreForCode.Add(new StoreForCode()
  257. {
  258. Code = No,
  259. StoreId = Id,
  260. });
  261. RedisDbconn.Instance.Set("StoreForCode:" + No, Id);
  262. }
  263. StoreForName storeForName = db.StoreForName.FirstOrDefault(m => m.Name == data.StoreName);
  264. if (storeForName == null)
  265. {
  266. db.StoreForName.Add(new StoreForName()
  267. {
  268. Name = data.StoreName,
  269. StoreId = Id,
  270. });
  271. }
  272. else
  273. {
  274. storeForName.StoreId = Id;
  275. }
  276. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == user.UserId);
  277. if (account == null)
  278. {
  279. account = db.UserAccount.Add(new UserAccount()
  280. {
  281. Id = user.UserId,
  282. UserId = user.UserId,
  283. }).Entity;
  284. db.SaveChanges();
  285. }
  286. if (account.FixedAmount == 0 && account.ValidAmount == 0)
  287. {
  288. account.FixedAmount = 20000;
  289. account.ValidAmount = 20000;
  290. }
  291. RedisDbconn.Instance.Set("StoreForName:" + data.StoreName, Id);
  292. AddSysLog(data.Id.ToString(), "StoreHouse", "add");
  293. db.SaveChanges();
  294. SetRedis(Id, user.UserId);
  295. }
  296. }
  297. return "success";
  298. }
  299. #endregion
  300. #region 修改仓库
  301. /// <summary>
  302. /// 增加或修改仓库信息
  303. /// </summary>
  304. /// <returns></returns>
  305. public IActionResult Edit(string right, int Id = 0)
  306. {
  307. ViewBag.RightInfo = RightInfo;
  308. ViewBag.right = right;
  309. StoreHouse editData = db.StoreHouse.FirstOrDefault(m => m.Id == Id) ?? new StoreHouse();
  310. ViewBag.data = editData;
  311. Users manage = db.Users.FirstOrDefault(m => m.Id == editData.ManageUserId) ?? new Users();
  312. ViewBag.ManageMakerCode = manage.MakerCode;
  313. ViewBag.ManageRealName = manage.RealName;
  314. Users user = db.Users.FirstOrDefault(m => m.Id == editData.ManageUserId) ?? new Users();
  315. ViewBag.MakerCode = user.MakerCode;
  316. return View();
  317. }
  318. #endregion
  319. #region 修改仓库
  320. /// <summary>
  321. /// 增加或修改仓库信息
  322. /// </summary>
  323. /// <returns></returns>
  324. [HttpPost]
  325. public string Edit(StoreHouse data, string ManageMakerCode, string MakerCode)
  326. {
  327. Dictionary<string, object> Fields = new Dictionary<string, object>();
  328. Fields.Add("CreateMan", SysUserName); //创建人
  329. Fields.Add("StoreName", data.StoreName); //仓库名称
  330. UserForMakerCode user = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  331. if (user == null)
  332. {
  333. return "您输入的仓库归属创客编号不存在,请重新输入正确的仓库归属创客编号";
  334. }
  335. Fields.Add("UserId", user.UserId); //仓库归属人
  336. Fields.Add("Areas", data.Areas); //所属地区
  337. Fields.Add("Address", data.Address); //仓库地址
  338. UserForMakerCode manage = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ManageMakerCode);
  339. if (manage == null)
  340. {
  341. return "您输入的仓库负责人编号不存在,请重新输入正确的仓库负责人编号";
  342. }
  343. Fields.Add("ManageUserId", manage.UserId); //仓库管理员
  344. Fields.Add("ManagerEmail", data.ManagerEmail); //管理者邮箱
  345. Fields.Add("ManageMobile", data.ManageMobile);
  346. Fields.Add("Remark", data.Remark); //备注
  347. Fields.Add("LimitTopUserId", data.LimitTopUserId); //限制创客特殊仓库
  348. Fields.Add("StoreKind", data.StoreKind); //仓库归属类型
  349. Fields.Add("Status", data.Status);
  350. Fields.Add("StoreStatus", data.Status);
  351. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreHouse", Fields, data.Id);
  352. AddSysLog(data.Id.ToString(), "StoreHouse", "update");
  353. db.SaveChanges();
  354. SetRedis(data.Id, user.UserId);
  355. return "success";
  356. }
  357. #endregion
  358. #region 一键添加仓库
  359. /// <summary>
  360. /// 一件添加仓库
  361. /// </summary>
  362. /// <returns></returns>
  363. public IActionResult Edits(string right, int Id = 0)
  364. {
  365. ViewBag.RightInfo = RightInfo;
  366. ViewBag.right = right;
  367. StoreHouse editData = db.StoreHouse.FirstOrDefault(m => m.Id == Id) ?? new StoreHouse();
  368. ViewBag.data = editData;
  369. Users manage = db.Users.FirstOrDefault(m => m.Id == editData.ManageUserId) ?? new Users();
  370. ViewBag.ManageMakerCode = manage.MakerCode;
  371. ViewBag.ManageRealName = manage.RealName;
  372. Users user = db.Users.FirstOrDefault(m => m.Id == editData.ManageUserId) ?? new Users();
  373. ViewBag.MakerCode = user.MakerCode;
  374. return View();
  375. }
  376. #endregion
  377. #region 一键添加仓库
  378. /// <summary>
  379. /// 一键添加仓库
  380. /// </summary>
  381. /// <returns></returns>
  382. [HttpPost]
  383. public string Edits(StoreHouse data, string ManageMakerCode, string MakerCode)
  384. {
  385. Dictionary<string, object> Fields = new Dictionary<string, object>();
  386. StoreHouse storeHouse = db.StoreHouse.FirstOrDefault(m => m.Id == data.Id);
  387. var brand = db.StoreHouse.FirstOrDefault(m => m.UserId == storeHouse.UserId && m.BrandId == data.BrandId);
  388. if (brand != null)
  389. {
  390. return "您已有该品牌类型的仓库,请重新选择";
  391. }
  392. var name = db.StoreHouse.FirstOrDefault(m => m.UserId == storeHouse.UserId && m.StoreName == data.StoreName);
  393. if (name != null)
  394. {
  395. return "您的仓库名重复,请重新填写";
  396. }
  397. Fields.Add("StoreName", data.StoreName); //仓库名称
  398. UserForMakerCode user = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  399. if (user == null)
  400. {
  401. return "您输入的仓库归属创客编号不存在,请重新输入正确的仓库归属创客编号";
  402. }
  403. Fields.Add("UserId", user.UserId); //仓库归属人
  404. Fields.Add("Areas", data.Areas); //所属地区
  405. Fields.Add("Address", data.Address); //仓库地址
  406. UserForMakerCode manage = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ManageMakerCode);
  407. if (manage == null)
  408. {
  409. return "您输入的仓库负责人编号不存在,请重新输入正确的仓库负责人编号";
  410. }
  411. Fields.Add("CreateMan", SysUserName); //创建人
  412. Fields.Add("ManageUserId", manage.UserId); //仓库管理员
  413. Fields.Add("ManagerEmail", data.ManagerEmail); //管理者邮箱
  414. Fields.Add("ManageMobile", data.ManageMobile);
  415. Fields.Add("Remark", data.Remark); //备注
  416. Fields.Add("LimitTopUserId", data.LimitTopUserId); //限制创客特殊仓库
  417. Fields.Add("StoreKind", data.StoreKind); //仓库归属类型
  418. int bid = Convert.ToInt32(data.BrandId);
  419. KqProducts pro = db.KqProducts.FirstOrDefault(m => m.Id == bid) ?? new KqProducts();
  420. Fields.Add("BrandId", data.BrandId);
  421. Fields.Add("ProductName", pro.Name);
  422. Fields.Add("StoreStatus", 1);
  423. Fields.Add("Status", 1);
  424. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("StoreHouse", Fields, 0);
  425. StoreHouse edit = db.StoreHouse.FirstOrDefault(m => m.Id == Id);
  426. if (edit != null)
  427. {
  428. string No = Id.ToString();
  429. for (int i = 0; i < 7 - Id.ToString().Length; i++)
  430. {
  431. No = "0" + No;
  432. }
  433. No = "S" + No;
  434. edit.StoreNo = No;
  435. db.StoreForCode.Add(new StoreForCode()
  436. {
  437. Code = No,
  438. StoreId = Id,
  439. });
  440. RedisDbconn.Instance.Set("StoreForCode:" + No, Id);
  441. }
  442. StoreForName storeForName = db.StoreForName.FirstOrDefault(m => m.Name == data.StoreName);
  443. if (storeForName == null)
  444. {
  445. db.StoreForName.Add(new StoreForName()
  446. {
  447. Name = data.StoreName,
  448. StoreId = Id,
  449. });
  450. }
  451. else
  452. {
  453. storeForName.StoreId = Id;
  454. }
  455. RedisDbconn.Instance.Set("StoreForName:" + data.StoreName, Id);
  456. AddSysLog(data.Id.ToString(), "StoreHouse", "add");
  457. db.SaveChanges();
  458. SetRedis(Id, user.UserId);
  459. return "success";
  460. }
  461. #endregion
  462. #region 删除仓库信息
  463. /// <summary>
  464. /// 删除仓库信息
  465. /// </summary>
  466. /// <returns></returns>
  467. public string Delete(string Id)
  468. {
  469. string[] idlist = Id.Split(new char[] { ',' });
  470. AddSysLog(Id, "StoreHouse", "del");
  471. foreach (string subid in idlist)
  472. {
  473. int id = int.Parse(subid);
  474. Dictionary<string, object> Fields = new Dictionary<string, object>();
  475. Fields.Add("Status", -1);
  476. StoreHouse edit = db.StoreHouse.FirstOrDefault(m => m.Id == id);
  477. if (edit != null)
  478. {
  479. StoreForCode code = db.StoreForCode.FirstOrDefault(m => m.Code == edit.StoreNo);
  480. if (code != null)
  481. {
  482. db.StoreForCode.Remove(code);
  483. }
  484. StoreForName name = db.StoreForName.FirstOrDefault(m => m.Name == edit.StoreName);
  485. if (name != null)
  486. {
  487. db.StoreForName.Remove(name);
  488. }
  489. }
  490. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreHouse", Fields, id);
  491. }
  492. db.SaveChanges();
  493. return "success";
  494. }
  495. #endregion
  496. #region 开启
  497. /// <summary>
  498. /// 开启
  499. /// </summary>
  500. /// <returns></returns>
  501. public string Open(string Id)
  502. {
  503. string[] idlist = Id.Split(new char[] { ',' });
  504. AddSysLog(Id, "StoreHouse", "open");
  505. foreach (string subid in idlist)
  506. {
  507. int id = int.Parse(subid);
  508. Dictionary<string, object> Fields = new Dictionary<string, object>();
  509. Fields.Add("Status", 1);
  510. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreHouse", Fields, id);
  511. }
  512. db.SaveChanges();
  513. return "success";
  514. }
  515. #endregion
  516. #region 关闭
  517. /// <summary>
  518. /// 关闭
  519. /// </summary>
  520. /// <returns></returns>
  521. public string Close(string Id)
  522. {
  523. string[] idlist = Id.Split(new char[] { ',' });
  524. AddSysLog(Id, "StoreHouse", "close");
  525. foreach (string subid in idlist)
  526. {
  527. int id = int.Parse(subid);
  528. Dictionary<string, object> Fields = new Dictionary<string, object>();
  529. Fields.Add("Status", 0);
  530. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreHouse", Fields, id);
  531. }
  532. db.SaveChanges();
  533. return "success";
  534. }
  535. #endregion
  536. #region 排序
  537. /// <summary>
  538. /// 排序
  539. /// </summary>
  540. /// <param name="Id"></param>
  541. public string Sort(int Id, int Sort)
  542. {
  543. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("StoreHouse", Sort, Id);
  544. AddSysLog(Id.ToString(), "StoreHouse", "sort");
  545. return "success";
  546. }
  547. #endregion
  548. #region 导入数据
  549. public IActionResult Import(string right, string ExcelKind)
  550. {
  551. ViewBag.RightInfo = RightInfo;
  552. ViewBag.right = right;
  553. ViewBag.ExcelKind = ExcelKind;
  554. return View();
  555. }
  556. /// <summary>
  557. /// 导入数据
  558. /// </summary>
  559. /// <param name="ExcelData"></param>
  560. [HttpPost]
  561. public string ImportPost(string ExcelPath, int Kind = 0)
  562. {
  563. // RedisDbconn.Instance.AddList("ExcelImport", ExcelPath + "#cut#" + Kind);
  564. string key = function.MD5_16(Guid.NewGuid().ToString());
  565. RedisDbconn.Instance.AddList("ExcelImportV2", ExcelPath + "#cut#" + Kind + "#cut#" + key + "#cut#" + SysUserName);
  566. return "success|" + key;
  567. }
  568. // [HttpPost]
  569. // public Dictionary<string, object> ImportPostV2(string ExcelPath, int Kind = 0)
  570. // {
  571. // Dictionary<string, object> Obj = new Dictionary<string, object>();
  572. // string key = function.MD5_16(Guid.NewGuid().ToString());
  573. // RedisDbconn.Instance.AddList("ExcelImportV2", ExcelPath + "#cut#" + Kind + "#cut#" + key);
  574. // Obj.Add("status", "success");
  575. // Obj.Add("key", key);
  576. // Obj.Add("errlist", RedisDbconn.Instance.GetList<string>("ErrList" + key));
  577. // return Obj;
  578. // }
  579. public string CheckImport(string key)
  580. {
  581. string result = RedisDbconn.Instance.Get<string>("CheckImport:" + key);
  582. if (!string.IsNullOrEmpty(result))
  583. {
  584. string[] datalist = result.Split('|');
  585. if (datalist[0] == "success")
  586. {
  587. return result;
  588. }
  589. return datalist[0];
  590. }
  591. return "0";
  592. }
  593. public Dictionary<string, object> CheckImportV2(string key)
  594. {
  595. Dictionary<string, object> Obj = new Dictionary<string, object>();
  596. string result = RedisDbconn.Instance.Get<string>("CheckImport:" + key);
  597. if (!string.IsNullOrEmpty(result))
  598. {
  599. string[] datalist = result.Split('|');
  600. if (datalist[0] == "success")
  601. {
  602. List<string> errList = RedisDbconn.Instance.GetList<string>("ErrList" + key);
  603. if (errList.Count > 0)
  604. {
  605. Obj.Add("status", 2);
  606. Obj.Add("errList", errList);
  607. }
  608. else
  609. {
  610. Obj.Add("status", 1);
  611. Obj.Add("data", result);
  612. }
  613. return Obj;
  614. }
  615. Obj.Add("status", 0);
  616. Obj.Add("data", datalist[0]);
  617. return Obj;
  618. }
  619. Obj.Add("status", -1);
  620. Obj.Add("data", "执行中...");
  621. return Obj;
  622. }
  623. #endregion
  624. #region 机具驳回仓库
  625. /// <summary>
  626. /// 机具驳回仓库
  627. /// </summary>
  628. /// <param name="ExcelData"></param>
  629. public string RejectStore(string ExcelData, int ExcelKind = 0)
  630. {
  631. ExcelData = HttpUtility.UrlDecode(ExcelData);
  632. JsonData list = JsonMapper.ToObject(ExcelData);
  633. if (ExcelKind == 1)
  634. {
  635. string error = "";
  636. decimal amount = 0;
  637. List<string> PosSnList = new List<string>();
  638. for (int i = 1; i < list.Count; i++)
  639. {
  640. JsonData dr = list[i];
  641. string itemJson = dr.ToJson();
  642. string PosSn = itemJson.Contains("\"A\"") ? dr["A"].ToString() : "";
  643. string BrandId = itemJson.Contains("\"B\"") ? dr["B"].ToString() : "";
  644. string MakerCode = itemJson.Contains("\"C\"") ? dr["C"].ToString() : "";
  645. string StoreNo = itemJson.Contains("\"D\"") ? dr["D"].ToString() : "";
  646. string No = itemJson.Contains("\"E\"") ? dr["E"].ToString() : "";
  647. string Remark = itemJson.Contains("\"F\"") ? dr["F"].ToString() : "";
  648. UserForMakerCode userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  649. StoreForCode storeForCode = db.StoreForCode.FirstOrDefault(m => m.Code == StoreNo);
  650. var store = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCode.StoreId && m.BrandId == BrandId) ?? new StoreHouse();
  651. MachineForSnNo machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn) ?? new MachineForSnNo();
  652. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId && m.BrandId == Convert.ToInt32(BrandId) && m.BindingState == 0 && m.BuyUserId == userForMakerCode.UserId) ?? new PosMachinesTwo();
  653. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId && m.BrandId == Convert.ToInt32(BrandId) && m.BindingState == 0) ?? new PosMachinesTwo();
  654. if (pos.Id == 0)
  655. {
  656. error += "以下操作失败" + PosSn + ',' + "未找到创客" + MakerCode + "的该台机具" + '\n';
  657. }
  658. if (store.Id == 0)
  659. {
  660. error += "以下操作失败" + PosSn + ',' + StoreNo + ',' + "未找到该仓库" + '\n';
  661. }
  662. if (posInfo.Id == 0)
  663. {
  664. error += "以下操作失败" + PosSn + ',' + "未找到该品牌的未使用机具" + '\n';
  665. }
  666. if (PosSnList.Contains(PosSn))
  667. {
  668. error += "以下操作失败" + PosSn + ',' + "该机具号重复" + '\n';
  669. }
  670. else
  671. {
  672. PosSnList.Add(PosSn);
  673. var fromStore = db.StoreHouse.FirstOrDefault(m => m.Id == pos.StoreId && m.BrandId == BrandId) ?? new StoreHouse();
  674. var toStore = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCode.StoreId && m.BrandId == BrandId) ?? new StoreHouse();
  675. var user = db.Users.FirstOrDefault(m => m.Id == toStore.UserId) ?? new Users();
  676. var userAccount = db.UserAccount.FirstOrDefault(m => m.Id == toStore.UserId) ?? new UserAccount();
  677. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == Convert.ToInt32(BrandId)) ?? new KqProducts();
  678. var fuserMachineData = db.UserMachineData.FirstOrDefault(m => m.IdBrand == userForMakerCode.UserId + "_" + brandInfo.Id);
  679. if (brandInfo.Name.Contains("电签"))
  680. {
  681. amount = 200;
  682. }
  683. if (brandInfo.Name.Contains("大POS"))
  684. {
  685. amount = 300;
  686. }
  687. userAccount.ValidAmount -= amount;
  688. db.SaveChanges();
  689. if (posInfo != null)
  690. {
  691. if (fromStore.Id != toStore.Id)
  692. {
  693. var changeNo = "JJBH" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  694. StoreStockChange stockchange = db.StoreStockChange.Add(new StoreStockChange()
  695. {
  696. CreateDate = DateTime.Now,
  697. StoreId = fromStore.Id, //出货仓库
  698. ToStoreId = toStore.Id, //发货仓库
  699. BrandId = Convert.ToInt32(BrandId), //产品类型
  700. ProductName = RelationClass.GetKqProductBrandInfo(Convert.ToInt32(BrandId)), //产品名称
  701. ChangeNo = changeNo, //变更记录单号
  702. BizBatchNo = No, //业务批次号
  703. TransType = 4, //交易类型
  704. SnNo = PosSn, //SN编号
  705. StockOpDirect = 1, //库存操作方向
  706. SnStatus = 1, //SN状态
  707. DeviceVendor = posInfo.DeviceName, //设备厂商
  708. DeviceModel = posInfo.DeviceKind, //设备型号
  709. DeviceType = posInfo.DeviceType, //设备类型
  710. SourceStoreId = posInfo.SourceStoreId, //源仓库编号
  711. BrandType = posInfo.DeviceType, //品牌类型
  712. }).Entity;
  713. db.SaveChanges();
  714. db.StoreChangeHistory.Add(new StoreChangeHistory()
  715. {
  716. CreateDate = DateTime.Now,
  717. UserId = user.Id, //创客
  718. StoreId = fromStore.Id, //出货仓库
  719. ToStoreId = toStore.Id, //发货仓库
  720. BrandId = Convert.ToInt32(BrandId), //产品类型
  721. ChangeRecordNo = changeNo, //变更记录单号
  722. SeoTitle = "机具驳回仓库",
  723. BizBatchNo = No, //业务批次号
  724. TransType = 4,//驳回
  725. SnNo = PosSn, //SN编号
  726. });
  727. db.SaveChanges();
  728. StoreBalance fbalance = db.StoreBalance.Add(new StoreBalance()
  729. {
  730. CreateDate = DateTime.Now,
  731. StoreId = fromStore.Id, //仓库
  732. BrandId = Convert.ToInt32(BrandId), //产品类型
  733. OpStoreNum = 1, //操作库存数
  734. OpSymbol = "-", //操作符
  735. BeforeTotalNum = fromStore.TotalNum, //操作前总库存数
  736. AfterTotalNum = fromStore.TotalNum - 1, //操作后总库存数
  737. BeforeLaveNum = fromStore.LaveNum, //操作前剩余库存数
  738. AfterLaveNum = fromStore.LaveNum - 1, //操作后剩余库存数
  739. BeforeOutNum = fromStore.OutNum, //操作前出库数
  740. AfterOutNum = fromStore.OutNum - 1, //操作后出库数
  741. }).Entity;
  742. db.SaveChanges();
  743. StoreBalance tbalance = db.StoreBalance.Add(new StoreBalance()
  744. {
  745. CreateDate = DateTime.Now,
  746. StoreId = toStore.Id, //仓库
  747. BrandId = Convert.ToInt32(BrandId), //产品类型
  748. OpStoreNum = 1, //操作库存数
  749. OpSymbol = "+", //操作符
  750. BeforeTotalNum = toStore.TotalNum, //操作前总库存数
  751. AfterTotalNum = toStore.TotalNum + 1, //操作后总库存数
  752. BeforeLaveNum = toStore.LaveNum, //操作前剩余库存数
  753. AfterLaveNum = toStore.LaveNum + 1, //操作后剩余库存数
  754. BeforeOutNum = toStore.OutNum, //操作前出库数
  755. AfterOutNum = toStore.OutNum, //操作后出库数
  756. }).Entity;
  757. db.SaveChanges();
  758. posInfo.StoreId = toStore.Id;
  759. posInfo.BuyUserId = 0;
  760. posInfo.UserId = 0;
  761. posInfo.RecycEndDate = null;
  762. posInfo.PosSnType = 0;
  763. posInfo.BindMerchantId = 0;
  764. posInfo.ActivityList = null;
  765. posInfo.ScanQrTrade = 0;
  766. posInfo.DebitCardTrade = 0;
  767. posInfo.PrizeParams = null;
  768. posInfo.IsVip = 0;
  769. posInfo.CreditTrade = 0;
  770. posInfo.UserNav = null;
  771. posInfo.TransferTime = null;
  772. posInfo.IsPurchase = 0;
  773. posInfo.BindingTime = null;
  774. posInfo.BindingState = 0;
  775. posInfo.ActivationTime = null;
  776. posInfo.ActivationState = 0;
  777. posInfo.LeaderUserId = 0;
  778. posInfo.PreUserId = 0;
  779. posInfo.IsFirst = 0;
  780. fuserMachineData.TotalMachineCount -= 1;
  781. fuserMachineData.UnBindCount -= 1;
  782. toStore.TotalNum += 1;
  783. toStore.LaveNum += 1;
  784. fromStore.TotalNum -= 1;
  785. fromStore.LaveNum -= 1;
  786. db.SaveChanges();
  787. }
  788. else
  789. {
  790. var changeNo = "JJBH" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  791. StoreStockChange stockchange = db.StoreStockChange.Add(new StoreStockChange()
  792. {
  793. CreateDate = DateTime.Now,
  794. StoreId = fromStore.Id, //出货仓库
  795. ToStoreId = toStore.Id, //发货仓库
  796. BrandId = Convert.ToInt32(BrandId), //产品类型
  797. ProductName = RelationClass.GetKqProductBrandInfo(Convert.ToInt32(BrandId)), //产品名称
  798. ChangeNo = changeNo, //变更记录单号
  799. BizBatchNo = No, //业务批次号
  800. TransType = 4, //交易类型
  801. SnNo = PosSn, //SN编号
  802. StockOpDirect = 1, //库存操作方向
  803. SnStatus = 1, //SN状态
  804. DeviceVendor = posInfo.DeviceName, //设备厂商
  805. DeviceModel = posInfo.DeviceKind, //设备型号
  806. DeviceType = posInfo.DeviceType, //设备类型
  807. SourceStoreId = posInfo.SourceStoreId, //源仓库编号
  808. BrandType = posInfo.DeviceType, //品牌类型
  809. }).Entity;
  810. db.SaveChanges();
  811. db.StoreChangeHistory.Add(new StoreChangeHistory()
  812. {
  813. CreateDate = DateTime.Now,
  814. UserId = user.Id, //创客
  815. StoreId = fromStore.Id, //出货仓库
  816. ToStoreId = toStore.Id, //发货仓库
  817. BrandId = Convert.ToInt32(BrandId), //产品类型
  818. ChangeRecordNo = changeNo, //变更记录单号
  819. SeoTitle = "机具驳回仓库",
  820. BizBatchNo = No, //业务批次号
  821. SnNo = PosSn, //SN编号
  822. TransType = 4,//驳回
  823. });
  824. db.SaveChanges();
  825. StoreBalance balance = db.StoreBalance.Add(new StoreBalance()
  826. {
  827. CreateDate = DateTime.Now,
  828. StoreId = fromStore.Id, //仓库
  829. BrandId = Convert.ToInt32(BrandId), //产品类型
  830. OpStoreNum = 1, //操作库存数
  831. OpSymbol = "-", //操作符
  832. BeforeTotalNum = fromStore.TotalNum, //操作前总库存数
  833. AfterTotalNum = fromStore.TotalNum - 1, //操作后总库存数
  834. BeforeLaveNum = fromStore.LaveNum, //操作前剩余库存数
  835. AfterLaveNum = fromStore.LaveNum - 1, //操作后剩余库存数
  836. BeforeOutNum = fromStore.OutNum, //操作前出库数
  837. AfterOutNum = fromStore.OutNum - 1, //操作后出库数
  838. }).Entity;
  839. db.SaveChanges();
  840. posInfo.StoreId = toStore.Id;
  841. posInfo.BuyUserId = 0;
  842. posInfo.UserId = 0;
  843. posInfo.RecycEndDate = null;
  844. posInfo.PosSnType = 0;
  845. posInfo.BindMerchantId = 0;
  846. posInfo.ActivityList = null;
  847. posInfo.ScanQrTrade = 0;
  848. posInfo.DebitCardTrade = 0;
  849. posInfo.PrizeParams = null;
  850. posInfo.IsVip = 0;
  851. posInfo.CreditTrade = 0;
  852. posInfo.UserNav = null;
  853. posInfo.TransferTime = null;
  854. posInfo.IsPurchase = 0;
  855. posInfo.BindingTime = null;
  856. posInfo.BindingState = 0;
  857. posInfo.ActivationTime = null;
  858. posInfo.ActivationState = 0;
  859. posInfo.LeaderUserId = 0;
  860. posInfo.PreUserId = 0;
  861. posInfo.IsFirst = 0;
  862. fuserMachineData.TotalMachineCount -= 1;
  863. fuserMachineData.UnBindCount -= 1;
  864. toStore.LaveNum += 1;
  865. toStore.TotalNum += 1;
  866. db.SaveChanges();
  867. }
  868. db.SaveChanges();
  869. }
  870. }
  871. }
  872. if (!string.IsNullOrEmpty(error))
  873. {
  874. return "Warning|" + error;
  875. }
  876. }
  877. AddSysLog("0", "MachinesRejectStore", "Import");
  878. return "success";
  879. }
  880. #endregion
  881. #region 导出Excel
  882. /// <summary>
  883. /// 导出Excel
  884. /// </summary>
  885. /// <returns></returns>
  886. public JsonResult ExportExcel(StoreHouse data, string UserIdMakerCode, string UserIdRealName, string ManageUserIdRealName, string ManageUserIdMobile, string ManageUserIdMakerCode, string StoreStatusSelect)
  887. {
  888. Dictionary<string, string> Fields = new Dictionary<string, string>();
  889. Fields.Add("StoreNo", "1"); //仓库编号
  890. Fields.Add("CreateDate", "3"); //时间
  891. Fields.Add("StoreName", "1"); //仓库名称
  892. Fields.Add("ManagerEmail", "1"); //管理者邮箱
  893. string condition = " and Status>-1";
  894. //仓库归属人创客编号
  895. if (!string.IsNullOrEmpty(UserIdMakerCode))
  896. {
  897. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  898. }
  899. //仓库归属人真实姓名
  900. if (!string.IsNullOrEmpty(UserIdRealName))
  901. {
  902. condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  903. }
  904. //仓库管理员真实姓名
  905. if (!string.IsNullOrEmpty(ManageUserIdRealName))
  906. {
  907. condition += " and ManageUserId in (select ManageUserId from UserForRealName where RealName='" + ManageUserIdRealName + "')";
  908. }
  909. //仓库管理员手机号
  910. if (!string.IsNullOrEmpty(ManageUserIdMobile))
  911. {
  912. condition += " and ManageUserId in (select ManageUserId from UserForMobile where Mobile='" + ManageUserIdMobile + "')";
  913. }
  914. //仓库管理员创客编号
  915. if (!string.IsNullOrEmpty(ManageUserIdMakerCode))
  916. {
  917. condition += " and ManageUserId in (select ManageUserId from UserForMakerCode where MakerCode='" + ManageUserIdMakerCode + "')";
  918. }
  919. //仓库状态
  920. if (!string.IsNullOrEmpty(StoreStatusSelect))
  921. {
  922. condition += " and StoreStatus=" + StoreStatusSelect;
  923. }
  924. 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);
  925. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  926. foreach (Dictionary<string, object> dic in diclist)
  927. {
  928. //仓库归属人
  929. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  930. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  931. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  932. dic["UserIdRealName"] = userid_Users.RealName;
  933. //产品类型
  934. dic["BrandId"] = RelationClass.GetKqProductBrandList(dic["BrandId"].ToString());
  935. //仓库管理员
  936. int ManageUserId = int.Parse(function.CheckInt(dic["ManageUserId"].ToString()));
  937. Users manageuserid_Users = db.Users.FirstOrDefault(m => m.Id == ManageUserId) ?? new Users();
  938. dic["ManageUserIdRealName"] = manageuserid_Users.RealName;
  939. dic["ManageUserIdMobile"] = manageuserid_Users.Mobile;
  940. dic["ManageUserIdMakerCode"] = manageuserid_Users.MakerCode;
  941. //仓库类型
  942. int StoreType = int.Parse(dic["StoreType"].ToString());
  943. if (StoreType == 0) dic["StoreType"] = "实体仓";
  944. if (StoreType == 1) dic["StoreType"] = "虚拟仓";
  945. //仓库状态
  946. int StoreStatus = int.Parse(dic["StoreStatus"].ToString());
  947. if (StoreStatus == 1) dic["StoreStatus"] = "启用";
  948. if (StoreStatus == 0) dic["StoreStatus"] = "禁用";
  949. //仓库归属类型
  950. int StoreKind = int.Parse(dic["StoreKind"].ToString());
  951. if (StoreKind == 0) dic["StoreKind"] = "分仓";
  952. if (StoreKind == 1) dic["StoreKind"] = "总仓";
  953. }
  954. Dictionary<string, object> result = new Dictionary<string, object>();
  955. result.Add("Status", "1");
  956. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  957. result.Add("Obj", diclist);
  958. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  959. ReturnFields.Add("StoreNo", "仓库编号");
  960. ReturnFields.Add("StoreName", "仓库名称");
  961. ReturnFields.Add("UserIdMakerCode", "仓库归属人创客编号");
  962. ReturnFields.Add("UserIdRealName", "仓库归属人真实姓名");
  963. ReturnFields.Add("BrandId", "产品类型");
  964. ReturnFields.Add("Address", "仓库地址");
  965. ReturnFields.Add("ManageUserIdRealName", "仓库管理员真实姓名");
  966. ReturnFields.Add("ManageUserIdMobile", "仓库管理员手机号");
  967. ReturnFields.Add("ManageUserIdMakerCode", "仓库管理员创客编号");
  968. ReturnFields.Add("ManagerEmail", "管理者邮箱");
  969. ReturnFields.Add("StoreType", "仓库类型");
  970. ReturnFields.Add("TotalNum", "总库存数");
  971. ReturnFields.Add("LaveNum", "剩余库存数");
  972. ReturnFields.Add("OutNum", "出库数");
  973. ReturnFields.Add("LimitTopUserId", "限制创客特殊仓库");
  974. ReturnFields.Add("StoreStatus", "仓库状态");
  975. ReturnFields.Add("StoreKind", "仓库归属类型");
  976. result.Add("Fields", ReturnFields);
  977. AddSysLog("0", "StoreHouse", "ExportExcel");
  978. return Json(result);
  979. }
  980. #endregion
  981. #region 仓库列表
  982. /// <summary>
  983. /// 根据条件查询仓库列表
  984. /// </summary>
  985. /// <returns></returns>
  986. public IActionResult Stat(StoreHouse data, string right)
  987. {
  988. ViewBag.RightInfo = RightInfo;
  989. ViewBag.right = right;
  990. return View();
  991. }
  992. #endregion
  993. #region 根据条件查询仓库列表
  994. /// <summary>
  995. /// 仓库列表
  996. /// </summary>
  997. /// <returns></returns>
  998. public JsonResult StatDo(string CreateDateData, int page = 1, int limit = 30)
  999. {
  1000. OtherMySqlConn.connstr = ConfigurationManager.AppSettings["StatSqlConnStr"].ToString();
  1001. string sCreateDate = DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00";
  1002. string eCreateDate = DateTime.Now.ToString("yyyy-MM-dd") + " 23:59:59";
  1003. if (!string.IsNullOrEmpty(CreateDateData))
  1004. {
  1005. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  1006. sCreateDate = datelist[0] + " 00:00:00";
  1007. eCreateDate = datelist[1] + " 23:59:59";
  1008. }
  1009. else
  1010. {
  1011. Dictionary<string, object> nodata = new Dictionary<string, object>();
  1012. nodata.Add("code", 0);
  1013. nodata.Add("msg", "");
  1014. nodata.Add("count", 0);
  1015. nodata.Add("data", new List<Dictionary<string, object>>());
  1016. return Json(nodata);
  1017. }
  1018. string minId = "0";
  1019. string maxId = "0";
  1020. string minPosId = "0";
  1021. string maxPosId = "0";
  1022. DataTable startDt = OtherMySqlConn.dtable("select min(Id) from StoreStockChange where CreateDate>='" + sCreateDate + "'");
  1023. if (startDt.Rows.Count > 0)
  1024. {
  1025. minId = function.CheckInt(startDt.Rows[0][0].ToString());
  1026. if (minId == "0")
  1027. {
  1028. startDt = OtherMySqlConn.dtable("select max(Id) from StoreStockChange");
  1029. if (startDt.Rows.Count > 0)
  1030. {
  1031. minId = function.CheckInt(startDt.Rows[0][0].ToString());
  1032. }
  1033. }
  1034. }
  1035. DataTable endDt = OtherMySqlConn.dtable("select max(Id) from StoreStockChange where CreateDate>='" + sCreateDate + "'");
  1036. if (endDt.Rows.Count > 0)
  1037. {
  1038. maxId = function.CheckInt(endDt.Rows[0][0].ToString());
  1039. if (minId == "0")
  1040. {
  1041. endDt = OtherMySqlConn.dtable("select max(Id) from StoreStockChange");
  1042. if (endDt.Rows.Count > 0)
  1043. {
  1044. maxId = function.CheckInt(endDt.Rows[0][0].ToString());
  1045. }
  1046. }
  1047. }
  1048. DataTable startPosDt = OtherMySqlConn.dtable("select min(Id) from PosMachinesTwo where ActivationTime>='" + sCreateDate + "'");
  1049. if (startPosDt.Rows.Count > 0)
  1050. {
  1051. minPosId = function.CheckInt(startPosDt.Rows[0][0].ToString());
  1052. if (minPosId == "0")
  1053. {
  1054. startPosDt = OtherMySqlConn.dtable("select max(Id) from PosMachinesTwo");
  1055. if (startPosDt.Rows.Count > 0)
  1056. {
  1057. minPosId = function.CheckInt(startPosDt.Rows[0][0].ToString());
  1058. }
  1059. }
  1060. }
  1061. DataTable endPosDt = OtherMySqlConn.dtable("select max(Id) from PosMachinesTwo where ActivationTime>='" + sCreateDate + "'");
  1062. if (endPosDt.Rows.Count > 0)
  1063. {
  1064. maxPosId = function.CheckInt(endPosDt.Rows[0][0].ToString());
  1065. if (maxPosId == "0")
  1066. {
  1067. endPosDt = OtherMySqlConn.dtable("select max(Id) from PosMachinesTwo");
  1068. if (endPosDt.Rows.Count > 0)
  1069. {
  1070. maxPosId = function.CheckInt(endPosDt.Rows[0][0].ToString());
  1071. }
  1072. }
  1073. }
  1074. 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");
  1075. int recordcount = list.Rows.Count;
  1076. List<Dictionary<string, object>> diclist = new List<Dictionary<string, object>>();
  1077. foreach (DataRow sub in list.Rows)
  1078. {
  1079. Dictionary<string, object> row = new Dictionary<string, object>();
  1080. row.Add("StoreName", sub["StoreName"].ToString());
  1081. row.Add("StoreNo", sub["StoreNo"].ToString());
  1082. row.Add("Mobile", sub["Mobile"].ToString());
  1083. row.Add("RealName", sub["RealName"].ToString());
  1084. row.Add("Name", sub["Name"].ToString());
  1085. row.Add("LaveNum", sub["LaveNum"].ToString());
  1086. row.Add("c1", sub["c1"].ToString());
  1087. row.Add("c2", sub["c2"].ToString());
  1088. row.Add("c3", sub["c3"].ToString());
  1089. diclist.Add(row);
  1090. }
  1091. Dictionary<string, object> obj = new Dictionary<string, object>();
  1092. obj.Add("code", 0);
  1093. obj.Add("msg", "");
  1094. obj.Add("count", recordcount);
  1095. obj.Add("data", diclist);
  1096. return Json(obj);
  1097. }
  1098. #endregion
  1099. #region 导出Excel
  1100. /// <summary>
  1101. /// 导出Excel
  1102. /// </summary>
  1103. /// <returns></returns>
  1104. public JsonResult StatExportExcel(string CreateDateData)
  1105. {
  1106. OtherMySqlConn.connstr = ConfigurationManager.AppSettings["StatSqlConnStr"].ToString();
  1107. string sCreateDate = DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00";
  1108. string eCreateDate = DateTime.Now.ToString("yyyy-MM-dd") + " 23:59:59";
  1109. if (!string.IsNullOrEmpty(CreateDateData))
  1110. {
  1111. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  1112. sCreateDate = datelist[0] + " 00:00:00";
  1113. eCreateDate = datelist[1] + " 23:59:59";
  1114. }
  1115. else
  1116. {
  1117. Dictionary<string, object> nodata = new Dictionary<string, object>();
  1118. nodata.Add("Status", "1");
  1119. nodata.Add("Info", "分仓统计数据报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  1120. nodata.Add("Obj", new List<Dictionary<string, object>>());
  1121. Dictionary<string, object> NoDataReturnFields = new Dictionary<string, object>();
  1122. NoDataReturnFields.Add("StoreName", "仓库名称");
  1123. NoDataReturnFields.Add("StoreNo", "仓库编号");
  1124. NoDataReturnFields.Add("Mobile", "仓库所属人手机号");
  1125. NoDataReturnFields.Add("RealName", "仓库所属人名称");
  1126. NoDataReturnFields.Add("MakerCode", "仓库所属人编码");
  1127. NoDataReturnFields.Add("ManageMakerCode", "仓库管理员编码");
  1128. NoDataReturnFields.Add("Name", "品牌");
  1129. NoDataReturnFields.Add("LaveNum", "当前库存");
  1130. NoDataReturnFields.Add("c1", "出库(调拨)量");
  1131. NoDataReturnFields.Add("c2", "出货(发货到创客)量");
  1132. NoDataReturnFields.Add("c3", "激活量");
  1133. nodata.Add("Fields", NoDataReturnFields);
  1134. return Json(nodata);
  1135. }
  1136. string minId = "0";
  1137. string maxId = "0";
  1138. string minPosId = "0";
  1139. string maxPosId = "0";
  1140. DataTable startDt = OtherMySqlConn.dtable("select min(Id) from StoreStockChange where CreateDate>='" + sCreateDate + "'");
  1141. if (startDt.Rows.Count > 0)
  1142. {
  1143. minId = function.CheckInt(startDt.Rows[0][0].ToString());
  1144. if (minId == "0")
  1145. {
  1146. startDt = OtherMySqlConn.dtable("select max(Id) from StoreStockChange");
  1147. if (startDt.Rows.Count > 0)
  1148. {
  1149. minId = function.CheckInt(startDt.Rows[0][0].ToString());
  1150. }
  1151. }
  1152. }
  1153. DataTable endDt = OtherMySqlConn.dtable("select max(Id) from StoreStockChange where CreateDate>='" + sCreateDate + "'");
  1154. if (endDt.Rows.Count > 0)
  1155. {
  1156. maxId = function.CheckInt(endDt.Rows[0][0].ToString());
  1157. if (minId == "0")
  1158. {
  1159. endDt = OtherMySqlConn.dtable("select max(Id) from StoreStockChange");
  1160. if (endDt.Rows.Count > 0)
  1161. {
  1162. maxId = function.CheckInt(endDt.Rows[0][0].ToString());
  1163. }
  1164. }
  1165. }
  1166. DataTable startPosDt = OtherMySqlConn.dtable("select min(Id) from PosMachinesTwo where ActivationTime>='" + sCreateDate + "'");
  1167. if (startPosDt.Rows.Count > 0)
  1168. {
  1169. minPosId = function.CheckInt(startPosDt.Rows[0][0].ToString());
  1170. if (minPosId == "0")
  1171. {
  1172. startPosDt = OtherMySqlConn.dtable("select max(Id) from PosMachinesTwo");
  1173. if (startPosDt.Rows.Count > 0)
  1174. {
  1175. minPosId = function.CheckInt(startPosDt.Rows[0][0].ToString());
  1176. }
  1177. }
  1178. }
  1179. DataTable endPosDt = OtherMySqlConn.dtable("select max(Id) from PosMachinesTwo where ActivationTime>='" + sCreateDate + "'");
  1180. if (endPosDt.Rows.Count > 0)
  1181. {
  1182. maxPosId = function.CheckInt(endPosDt.Rows[0][0].ToString());
  1183. if (maxPosId == "0")
  1184. {
  1185. endPosDt = OtherMySqlConn.dtable("select max(Id) from PosMachinesTwo");
  1186. if (endPosDt.Rows.Count > 0)
  1187. {
  1188. maxPosId = function.CheckInt(endPosDt.Rows[0][0].ToString());
  1189. }
  1190. }
  1191. }
  1192. 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");
  1193. int recordcount = list.Rows.Count;
  1194. List<Dictionary<string, object>> diclist = new List<Dictionary<string, object>>();
  1195. foreach (DataRow sub in list.Rows)
  1196. {
  1197. Dictionary<string, object> row = new Dictionary<string, object>();
  1198. row.Add("StoreName", sub["StoreName"].ToString());
  1199. row.Add("StoreNo", sub["StoreNo"].ToString());
  1200. row.Add("Mobile", sub["Mobile"].ToString());
  1201. row.Add("RealName", sub["RealName"].ToString());
  1202. row.Add("MakerCode", sub["MakerCode"].ToString());
  1203. row.Add("ManageMakerCode", sub["ManageMakerCode"].ToString());
  1204. row.Add("Name", sub["Name"].ToString());
  1205. row.Add("LaveNum", sub["LaveNum"].ToString());
  1206. row.Add("c1", sub["c1"].ToString());
  1207. row.Add("c2", sub["c2"].ToString());
  1208. row.Add("c3", sub["c3"].ToString());
  1209. diclist.Add(row);
  1210. }
  1211. Dictionary<string, object> result = new Dictionary<string, object>();
  1212. result.Add("Status", "1");
  1213. result.Add("Info", "分仓统计数据报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  1214. result.Add("Obj", diclist);
  1215. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  1216. ReturnFields.Add("StoreName", "仓库名称");
  1217. ReturnFields.Add("StoreNo", "仓库编号");
  1218. ReturnFields.Add("Mobile", "仓库所属人手机号");
  1219. ReturnFields.Add("RealName", "仓库所属人名称");
  1220. ReturnFields.Add("MakerCode", "仓库所属人编码");
  1221. ReturnFields.Add("ManageMakerCode", "仓库管理员编码");
  1222. ReturnFields.Add("Name", "品牌");
  1223. ReturnFields.Add("LaveNum", "当前库存");
  1224. ReturnFields.Add("c1", "出库(调拨)量");
  1225. ReturnFields.Add("c2", "出货(发货到创客)量");
  1226. ReturnFields.Add("c3", "激活量");
  1227. result.Add("Fields", ReturnFields);
  1228. AddSysLog("0", "StoreHouse", "StatExportExcel");
  1229. return Json(result);
  1230. }
  1231. #endregion
  1232. #region 同步数据
  1233. /// <summary>
  1234. /// 同步数据
  1235. /// </summary>
  1236. /// <returns></returns>
  1237. public string SycnData(int Id = 0)
  1238. {
  1239. if (Id > 0)
  1240. {
  1241. 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);
  1242. if (dt.Rows.Count > 0)
  1243. {
  1244. int CurLaveNum = int.Parse(function.CheckInt(dt.Rows[0]["CurLaveNum"].ToString()));
  1245. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == Id);
  1246. if (store != null)
  1247. {
  1248. store.LaveNum = CurLaveNum;
  1249. db.SaveChanges();
  1250. }
  1251. }
  1252. }
  1253. else
  1254. {
  1255. 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)");
  1256. foreach (DataRow dr in dt.Rows)
  1257. {
  1258. int StoreId = int.Parse(function.CheckInt(dr["Id"].ToString()));
  1259. int CurLaveNum = int.Parse(function.CheckInt(dr["CurLaveNum"].ToString()));
  1260. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId);
  1261. if (store != null)
  1262. {
  1263. store.LaveNum = CurLaveNum;
  1264. db.SaveChanges();
  1265. }
  1266. }
  1267. }
  1268. AddSysLog(Id, "StoreHouse", "SycnData");
  1269. db.SaveChanges();
  1270. return "success";
  1271. }
  1272. #endregion
  1273. #region 设置缓存
  1274. private void SetRedis(int Id, int UserId)
  1275. {
  1276. if (UserId > 0)
  1277. {
  1278. }
  1279. }
  1280. #endregion
  1281. }
  1282. }