StoreHouseController.cs 78 KB

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