StoreMachineApplyOperateController.cs 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942
  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.Threading.Tasks;
  10. using Microsoft.AspNetCore.Mvc;
  11. using Microsoft.AspNetCore.Http;
  12. using Microsoft.Extensions.Logging;
  13. using Microsoft.Extensions.Options;
  14. using MySystem.OpModels;
  15. using Library;
  16. using LitJson;
  17. using MySystemLib;
  18. namespace MySystem.Areas.Admin.Controllers
  19. {
  20. [Area("Admin")]
  21. [Route("Admin/[controller]/[action]")]
  22. public class StoreMachineApplyOperateController : BaseController
  23. {
  24. public StoreMachineApplyOperateController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  25. {
  26. OtherMySqlConn.connstr = ConfigurationManager.AppSettings["OpSqlConnStr"].ToString();
  27. }
  28. #region 运营中心机具申请记录列表
  29. /// <summary>
  30. /// 根据条件查询运营中心机具申请记录列表
  31. /// </summary>
  32. /// <returns></returns>
  33. public IActionResult Index(StoreMachineApply data, string right)
  34. {
  35. ViewBag.RightInfo = RightInfo;
  36. ViewBag.right = right;
  37. return View();
  38. }
  39. #endregion
  40. #region 根据条件查询运营中心机具申请记录列表
  41. /// <summary>
  42. /// 运营中心机具申请记录列表
  43. /// </summary>
  44. /// <returns></returns>
  45. public JsonResult IndexData(StoreMachineApply data, string MakerCode, string OpCode, string CreateDateData, string StatusSelect, int page = 1, int limit = 30)
  46. {
  47. Dictionary<string, string> Fields = new Dictionary<string, string>();
  48. Fields.Add("ApplyNo", "1"); //申请单号
  49. Fields.Add("SendMode", "1"); //发货方式
  50. string condition = " and Status>-1 and Sort=0";
  51. if (!string.IsNullOrEmpty(CreateDateData))
  52. {
  53. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  54. string start = datelist[0];
  55. string end = datelist[1];
  56. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  57. }
  58. //创客编号
  59. if (!string.IsNullOrEmpty(MakerCode))
  60. {
  61. condition += " and UserId in (select UserId from SysAdmin where MakerCode='" + MakerCode + "')";
  62. }
  63. //运营中心编号
  64. if (!string.IsNullOrEmpty(OpCode))
  65. {
  66. condition += " and UserId in (select UserId from SysAdmin where OpCode='" + OpCode + "')";
  67. }
  68. if (!string.IsNullOrEmpty(StatusSelect))
  69. {
  70. condition += " and Status=" + StatusSelect + "";
  71. }
  72. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.OpTables).IndexData("StoreMachineApply", Fields, "Id desc", "0", page, limit, condition);
  73. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  74. foreach (Dictionary<string, object> dic in diclist)
  75. {
  76. //品牌
  77. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  78. int Status = int.Parse(dic["Status"].ToString());
  79. if (Status == 0) dic["StatusName"] = "待配货";
  80. if (Status == 1) dic["StatusName"] = "已发货";
  81. if (Status == 2) dic["StatusName"] = "已驳回";
  82. //创客
  83. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  84. SysAdmin sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.UserId == UserId) ?? new SysAdmin();
  85. dic["MakerName"] = sysAdmin.MakerName;
  86. dic["MakerCode"] = sysAdmin.MakerCode;
  87. dic["OpCode"] = sysAdmin.OpCode;
  88. dic.Remove("UserId");
  89. }
  90. return Json(obj);
  91. }
  92. #endregion
  93. #region 运营中心机具券申请记录列表
  94. /// <summary>
  95. /// 根据条件查询运营中心机具券申请记录列表
  96. /// </summary>
  97. /// <returns></returns>
  98. public IActionResult Indexs(StoreMachineApply data, string right)
  99. {
  100. ViewBag.RightInfo = RightInfo;
  101. ViewBag.right = right;
  102. return View();
  103. }
  104. #endregion
  105. #region 根据条件查询运营中心机具券申请记录列表
  106. /// <summary>
  107. /// 运营中心机具券申请记录列表
  108. /// </summary>
  109. /// <returns></returns>
  110. public JsonResult IndexsData(StoreMachineApply data, string MakerCode, string OpCode, string CreateDateData, string StatusSelect, int page = 1, int limit = 30)
  111. {
  112. Dictionary<string, string> Fields = new Dictionary<string, string>();
  113. Fields.Add("ApplyNo", "1"); //申请单号
  114. Fields.Add("SendMode", "1"); //发货方式
  115. string condition = " and Status>-1 and Sort=1";
  116. if (!string.IsNullOrEmpty(CreateDateData))
  117. {
  118. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  119. string start = datelist[0];
  120. string end = datelist[1];
  121. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  122. }
  123. //创客编号
  124. if (!string.IsNullOrEmpty(MakerCode))
  125. {
  126. condition += " and UserId in (select UserId from SysAdmin where MakerCode='" + MakerCode + "')";
  127. }
  128. //运营中心编号
  129. if (!string.IsNullOrEmpty(OpCode))
  130. {
  131. condition += " and UserId in (select UserId from SysAdmin where OpCode='" + OpCode + "')";
  132. }
  133. if (!string.IsNullOrEmpty(StatusSelect))
  134. {
  135. condition += " and Status=" + StatusSelect + "";
  136. }
  137. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.OpTables).IndexData("StoreMachineApply", Fields, "Id desc", "0", page, limit, condition);
  138. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  139. foreach (Dictionary<string, object> dic in diclist)
  140. {
  141. //品牌
  142. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  143. int Status = int.Parse(dic["Status"].ToString());
  144. if (Status == 0) dic["StatusName"] = "待配货";
  145. if (Status == 1) dic["StatusName"] = "已发货";
  146. if (Status == 2) dic["StatusName"] = "已驳回";
  147. //创客
  148. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  149. SysAdmin sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.UserId == UserId) ?? new SysAdmin();
  150. dic["MakerName"] = sysAdmin.MakerName;
  151. dic["MakerCode"] = sysAdmin.MakerCode;
  152. dic["OpCode"] = sysAdmin.OpCode;
  153. dic.Remove("UserId");
  154. }
  155. return Json(obj);
  156. }
  157. #endregion
  158. #region 增加分仓机具申请记录
  159. /// <summary>
  160. /// 增加或修改分仓机具申请记录信息
  161. /// </summary>
  162. /// <returns></returns>
  163. public IActionResult Add(string right)
  164. {
  165. ViewBag.RightInfo = RightInfo;
  166. ViewBag.right = right;
  167. return View();
  168. }
  169. #endregion
  170. #region 增加分仓机具申请记录
  171. /// <summary>
  172. /// 增加或修改分仓机具申请记录信息
  173. /// </summary>
  174. /// <returns></returns>
  175. [HttpPost]
  176. public string Add(StoreMachineApply data)
  177. {
  178. Dictionary<string, object> Fields = new Dictionary<string, object>();
  179. Fields.Add("BrandId", data.BrandId); //品牌
  180. Fields.Add("ApplyNo", data.ApplyNo); //申请单号
  181. Fields.Add("ApplyNum", data.ApplyNum); //申请台数
  182. Fields.Add("SendNum", data.SendNum); //发货台数
  183. Fields.Add("UseAmount", data.UseAmount); //使用额度
  184. Fields.Add("SendMode", data.SendMode); //发货方式
  185. Fields.Add("ErpCode", data.ErpCode); //快递单号
  186. Fields.Add("SendSn", data.SendSn); //发货SN数据
  187. Fields.Add("UserId", data.UserId); //创客
  188. Fields.Add("SeoTitle", data.SeoTitle);
  189. Fields.Add("SeoKeyword", data.SeoKeyword);
  190. Fields.Add("SeoDescription", data.SeoDescription);
  191. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.OpTables).Add("StoreMachineApply", Fields, 0);
  192. AddSysLog(data.Id.ToString(), "StoreMachineApply", "add");
  193. opdb.SaveChanges();
  194. return "success";
  195. }
  196. #endregion
  197. #region 修改分仓机具申请记录
  198. /// <summary>
  199. /// 增加或修改分仓机具申请记录信息
  200. /// </summary>
  201. /// <returns></returns>
  202. public IActionResult Edit(string right, int Id = 0)
  203. {
  204. ViewBag.RightInfo = RightInfo;
  205. ViewBag.right = right;
  206. StoreMachineApply editData = opdb.StoreMachineApply.FirstOrDefault(m => m.Id == Id) ?? new StoreMachineApply();
  207. ViewBag.data = editData;
  208. Models.WebCMSEntities db = new Models.WebCMSEntities();
  209. // Users users = db.Users.FirstOrDefault(m => m.Id == editData.UserId) ?? new Users();
  210. SysAdmin sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.Status == 0 && m.UserId == editData.UserId) ?? new SysAdmin();
  211. ViewBag.UserId = sysAdmin.Id;
  212. ViewBag.MakerCode = sysAdmin.MakerCode;
  213. ViewBag.MakerName = sysAdmin.MakerName;
  214. ViewBag.UseAmount = editData.UseAmount;
  215. JsonData SendSnList = new JsonData();
  216. SendSnList = JsonMapper.ToObject(editData.SendSn);//申请数据
  217. List<Dictionary<string, object>> KsProductList = new List<Dictionary<string, object>>();
  218. for (int i = 0; i < SendSnList.Count; i++)
  219. {
  220. int BrandId = Convert.ToInt32(SendSnList[i]["BrandId"].ToString());
  221. int Num = Convert.ToInt32(SendSnList[i]["ApplyNum"].ToString());
  222. var products = db.KqProducts.Where(m => m.Id == BrandId).ToList();
  223. foreach (var product in products)
  224. {
  225. Dictionary<string, object> item = new Dictionary<string, object>();
  226. item.Add("BrandId", BrandId); //商品Id
  227. item.Add("Name", product.Name); //商品名称
  228. item.Add("Num", Num); //商品数量
  229. KsProductList.Add(item);
  230. }
  231. }
  232. ViewBag.KsProductList = KsProductList;
  233. return View();
  234. }
  235. #endregion
  236. #region 修改分仓机具申请记录
  237. /// <summary>
  238. /// 增加或修改分仓机具申请记录信息
  239. /// </summary>
  240. /// <returns></returns>
  241. [HttpPost]
  242. public string Edit(StoreMachineApply data)
  243. {
  244. Dictionary<string, object> Fields = new Dictionary<string, object>();
  245. Fields.Add("SendSn", data.SendSn); //发货SN数据
  246. JsonData SendSnList = new JsonData();
  247. SendSnList = JsonMapper.ToObject(data.SendSn);//申请数据
  248. int ApplyNum = 0;
  249. for (int i = 0; i < SendSnList.Count; i++)
  250. {
  251. int num = Convert.ToInt32(SendSnList[i]["ApplyNum"].ToString());
  252. ApplyNum += num;
  253. }
  254. Fields.Add("BrandId", data.BrandId); //品牌
  255. Fields.Add("ApplyNo", data.ApplyNo); //申请单号
  256. Fields.Add("ApplyNum", ApplyNum); //申请台数
  257. Fields.Add("SendNum", data.SendNum); //发货台数
  258. Fields.Add("UseAmount", data.UseAmount); //使用额度
  259. Fields.Add("SendMode", data.SendMode); //发货方式
  260. Fields.Add("ErpCode", data.ErpCode); //快递单号
  261. Fields.Add("UserId", data.UserId); //创客
  262. Fields.Add("SeoTitle", SysUserName + '-' + SysRealName);
  263. Fields.Add("SeoKeyword", data.SeoKeyword);
  264. Fields.Add("SeoDescription", data.SeoDescription);
  265. new AdminContentOther(_accessor.HttpContext, PublicFunction.OpTables).Edit("StoreMachineApply", Fields, data.Id);
  266. AddSysLog(data.Id.ToString(), "OpStoreMachineApply", "update");
  267. db.SaveChanges();
  268. return "success";
  269. }
  270. #endregion
  271. #region 删除分仓机具申请记录信息
  272. /// <summary>
  273. /// 删除分仓机具申请记录信息
  274. /// </summary>
  275. /// <returns></returns>
  276. public string Delete(string Id)
  277. {
  278. string[] idlist = Id.Split(new char[] { ',' });
  279. AddSysLog(Id, "StoreMachineApply", "del");
  280. foreach (string subid in idlist)
  281. {
  282. int id = int.Parse(subid);
  283. Dictionary<string, object> Fields = new Dictionary<string, object>();
  284. Fields.Add("Status", -1);
  285. new AdminContentOther(_accessor.HttpContext, PublicFunction.OpTables).Edit("StoreMachineApply", Fields, id);
  286. }
  287. db.SaveChanges();
  288. return "success";
  289. }
  290. #endregion
  291. #region 开启
  292. /// <summary>
  293. /// 开启
  294. /// </summary>
  295. /// <returns></returns>
  296. public string Open(string Id)
  297. {
  298. string[] idlist = Id.Split(new char[] { ',' });
  299. AddSysLog(Id, "StoreMachineApply", "open");
  300. foreach (string subid in idlist)
  301. {
  302. int id = int.Parse(subid);
  303. Dictionary<string, object> Fields = new Dictionary<string, object>();
  304. Fields.Add("Status", 1);
  305. new AdminContentOther(_accessor.HttpContext, PublicFunction.OpTables).Edit("StoreMachineApply", Fields, id);
  306. }
  307. db.SaveChanges();
  308. return "success";
  309. }
  310. #endregion
  311. #region 关闭
  312. /// <summary>
  313. /// 关闭
  314. /// </summary>
  315. /// <returns></returns>
  316. public string Close(string Id)
  317. {
  318. string[] idlist = Id.Split(new char[] { ',' });
  319. AddSysLog(Id, "StoreMachineApply", "close");
  320. foreach (string subid in idlist)
  321. {
  322. int id = int.Parse(subid);
  323. Dictionary<string, object> Fields = new Dictionary<string, object>();
  324. Fields.Add("Status", 2);
  325. var query = opdb.StoreMachineApply.FirstOrDefault(m => m.Id == id);
  326. var users = opdb.UserAccount.FirstOrDefault(m => m.Status == 0 && m.UserId == query.UserId) ?? new UserAccount();
  327. if (users.Id > 0)
  328. {
  329. users.ValidAmount += query.UseAmount;
  330. var amountRecord = opdb.AmountRecord.Add(new AmountRecord()
  331. {
  332. CreateDate = DateTime.Now,
  333. CreateMan = SysUserName + "-" + SysRealName,
  334. SeoDescription = "机具申请驳回",
  335. OperateType = 1,//增加
  336. BeforeAmount = users.ValidAmount,
  337. AfterAmount = users.ValidAmount + query.UseAmount,
  338. UseAmount = query.UseAmount,
  339. UserId = query.UserId,
  340. ApplyId = query.Id,
  341. }).Entity;
  342. opdb.SaveChanges();
  343. }
  344. new AdminContentOther(_accessor.HttpContext, PublicFunction.OpTables).Edit("StoreMachineApply", Fields, id);
  345. }
  346. db.SaveChanges();
  347. return "success";
  348. }
  349. #endregion
  350. #region 排序
  351. /// <summary>
  352. /// 排序
  353. /// </summary>
  354. /// <param name="Id"></param>
  355. public string Sort(int Id, int Sort)
  356. {
  357. new AdminContentOther(_accessor.HttpContext, PublicFunction.OpTables).Sort("StoreMachineApply", Sort, Id);
  358. AddSysLog(Id.ToString(), "StoreMachineApply", "sort");
  359. return "success";
  360. }
  361. #endregion
  362. #region 导入数据
  363. /// <summary>
  364. /// 导入数据
  365. /// </summary>
  366. /// <param name="ExcelData"></param>
  367. public string Import(string ExcelData)
  368. {
  369. ExcelData = HttpUtility.UrlDecode(ExcelData);
  370. JsonData list = JsonMapper.ToObject(ExcelData);
  371. for (int i = 1; i < list.Count; i++)
  372. {
  373. JsonData dr = list[i];
  374. opdb.StoreMachineApply.Add(new StoreMachineApply()
  375. {
  376. CreateDate = DateTime.Now,
  377. UpdateDate = DateTime.Now,
  378. });
  379. db.SaveChanges();
  380. }
  381. AddSysLog("0", "OpStoreMachineApply", "Import");
  382. return "success";
  383. }
  384. #endregion
  385. #region 导出Excel
  386. /// <summary>
  387. /// 导出Excel
  388. /// </summary>
  389. /// <returns></returns>
  390. public JsonResult ExportExcel(StoreMachineApply data, string BrandIdSelect, string UserIdRealName, string UserIdMakerCode)
  391. {
  392. Dictionary<string, string> Fields = new Dictionary<string, string>();
  393. Fields.Add("CreateDate", "3"); //时间
  394. Fields.Add("ApplyNo", "1"); //申请单号
  395. Fields.Add("SendMode", "1"); //发货方式
  396. string condition = " and Status>-1";
  397. //品牌
  398. if (!string.IsNullOrEmpty(BrandIdSelect))
  399. {
  400. condition += " and BrandId=" + BrandIdSelect;
  401. }
  402. //创客真实姓名
  403. if (!string.IsNullOrEmpty(UserIdRealName))
  404. {
  405. condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  406. }
  407. //创客编号
  408. if (!string.IsNullOrEmpty(UserIdMakerCode))
  409. {
  410. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  411. }
  412. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.OpTables).IndexData("StoreMachineApply", Fields, "Id desc", "0", 1, 20000, condition, "BrandId,ApplyNo,ApplyNum,SendNum,UseAmount,SendMode,ErpCode,UserId", false);
  413. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  414. foreach (Dictionary<string, object> dic in diclist)
  415. {
  416. //品牌
  417. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  418. dic["StatusName"] = dic["Status"].ToString() == "1" ? "正常" : "关闭";
  419. //运营中心
  420. int OpId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  421. SysAdmin sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.Id == OpId) ?? new SysAdmin();
  422. // Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  423. dic["MakerName"] = sysAdmin.MakerName;
  424. dic["MakerCode"] = sysAdmin.MakerCode;
  425. dic["OpCode"] = sysAdmin.OpCode;
  426. dic.Remove("OpId");
  427. }
  428. Dictionary<string, object> result = new Dictionary<string, object>();
  429. result.Add("Status", "1");
  430. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  431. result.Add("Obj", diclist);
  432. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  433. ReturnFields.Add("BrandId", "品牌");
  434. ReturnFields.Add("ApplyNo", "申请单号");
  435. ReturnFields.Add("ApplyNum", "申请台数");
  436. ReturnFields.Add("SendNum", "发货台数");
  437. ReturnFields.Add("UseAmount", "使用额度");
  438. ReturnFields.Add("SendMode", "发货方式");
  439. ReturnFields.Add("ErpCode", "快递单号");
  440. ReturnFields.Add("MakerName", "创客真实姓名");
  441. ReturnFields.Add("MakerName", "创客编号");
  442. ReturnFields.Add("OpCode", "运营中心编号");
  443. result.Add("Fields", ReturnFields);
  444. AddSysLog("0", "OpStoreMachineApply", "ExportExcel");
  445. return Json(result);
  446. }
  447. #endregion
  448. #region 审核发货
  449. public IActionResult AuditSend(string right, int Id = 0)
  450. {
  451. ViewBag.RightInfo = RightInfo;
  452. ViewBag.right = right;
  453. StoreMachineApply editData = opdb.StoreMachineApply.FirstOrDefault(m => m.Id == Id) ?? new StoreMachineApply();
  454. ViewBag.data = editData;
  455. SysAdmin sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.Status == 0 && m.UserId == editData.UserId) ?? new SysAdmin();
  456. // Users users = db.Users.FirstOrDefault(m => m.Id == editData.UserId) ?? new Users();
  457. ViewBag.OpCode = sysAdmin.OpCode;
  458. ViewBag.MakerCode = sysAdmin.MakerCode;
  459. ViewBag.MakerName = sysAdmin.MakerName;
  460. return View();
  461. }
  462. #endregion
  463. //TODO:总仓给运营中心机关联的分仓发货应操作哪些数据
  464. #region 审核发货
  465. [HttpPost]
  466. public string AuditSend(StoreMachineApply data, string ExcelData)
  467. {
  468. Dictionary<string, object> Fields = new Dictionary<string, object>();
  469. Fields.Add("ApplyNum", data.ApplyNum); //申请数
  470. Fields.Add("SendNum", data.ApplyNum); //发货数
  471. Fields.Add("ErpCode", data.ErpCode); //快递单号
  472. Fields.Add("SendMode", data.SendMode); //发货方式
  473. Fields.Add("SeoKeyword", data.SeoKeyword); //申请描述
  474. Fields.Add("Status", 1);
  475. AddSysLog(data.Id.ToString(), "StoreMachineApply", "AuditSend");
  476. Dictionary<string, object> Obj = new Dictionary<string, object>();
  477. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  478. List<SendInfo> sendInfos = new List<SendInfo>();
  479. List<CheckSendInfo> checksendInfos = new List<CheckSendInfo>();
  480. StoreMachineApply apply = opdb.StoreMachineApply.FirstOrDefault(m => m.Id == data.Id) ?? new StoreMachineApply();
  481. JsonData ApplyList = JsonMapper.ToObject(apply.SendSn);
  482. decimal ApplyAmount = 0;
  483. decimal Amount = 0;
  484. for (int i = 0; i < ApplyList.Count; i++)
  485. {
  486. int num = Convert.ToInt32(ApplyList[i]["ApplyNum"].ToString());
  487. int BrandIds = Convert.ToInt32(ApplyList[i]["BrandId"].ToString());
  488. //自动匹配品牌
  489. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == BrandIds);
  490. if (brandInfo.Name.Contains("电签"))
  491. {
  492. ApplyAmount += num * 100;
  493. }
  494. if (brandInfo.Name.Contains("大POS"))
  495. {
  496. ApplyAmount += num * 150;
  497. }
  498. }
  499. Amount = apply.UseAmount - ApplyAmount;
  500. Models.StoreHouse tostore = new Models.StoreHouse();
  501. Models.StoreHouse fromstore = new Models.StoreHouse();
  502. var BrandId = 0;
  503. var FromStoreId = 0;
  504. string error = "";
  505. if (string.IsNullOrEmpty(ExcelData))
  506. {
  507. return "Warning|" + "请选择要导入的数据";
  508. }
  509. ExcelData = HttpUtility.UrlDecode(ExcelData);
  510. JsonData list = JsonMapper.ToObject(ExcelData);
  511. //判断各品牌发货数量是否符合
  512. if (list.Count - 1 > apply.ApplyNum)
  513. {
  514. return "Warning|" + "机具发货数量过多!";
  515. }
  516. if (list.Count - 1 < apply.ApplyNum)
  517. {
  518. return "Warning|" + "机具发货数量不足!";
  519. }
  520. for (int index = 1; index < list.Count; index++)
  521. {
  522. JsonData dr = list[index];
  523. string itemJson = dr.ToJson();
  524. string SnNo = itemJson.Contains("\"A\"") ? dr["A"].ToString() : "";
  525. string Brand = itemJson.Contains("\"B\"") ? dr["B"].ToString() : "";
  526. string BatchNo = itemJson.Contains("\"C\"") ? dr["C"].ToString() : "";
  527. string OutNote = itemJson.Contains("\"D\"") ? dr["D"].ToString() : "";
  528. BrandId = Convert.ToInt32(Brand);
  529. if (BrandId == 1) FromStoreId = 7;
  530. if (BrandId == 2) FromStoreId = 721;
  531. if (BrandId == 3) FromStoreId = 697;
  532. if (BrandId == 4) FromStoreId = 774;
  533. if (BrandId == 5) FromStoreId = 775;
  534. if (BrandId == 6) FromStoreId = 871;
  535. if (BrandId == 7) FromStoreId = 1047;
  536. if (BrandId == 8) FromStoreId = 4831;
  537. if (BrandId == 9) FromStoreId = 4832;
  538. CheckSendInfo items = checksendInfos.FirstOrDefault(m => m.BrandId == BrandId);
  539. if (items == null)
  540. {
  541. CheckSendInfo rows = new CheckSendInfo()
  542. {
  543. BrandId = BrandId,
  544. Num = 1
  545. };
  546. checksendInfos.Add(rows);
  547. }
  548. else
  549. {
  550. items.Num += 1;
  551. }
  552. }
  553. for (int i = 0; i < ApplyList.Count; i++)
  554. {
  555. int num = Convert.ToInt32(ApplyList[i]["ApplyNum"].ToString());
  556. int BrandIds = Convert.ToInt32(ApplyList[i]["BrandId"].ToString());
  557. if (BrandIds == 1) FromStoreId = 7;
  558. if (BrandIds == 2) FromStoreId = 721;
  559. if (BrandIds == 3) FromStoreId = 697;
  560. if (BrandIds == 4) FromStoreId = 774;
  561. if (BrandIds == 5) FromStoreId = 775;
  562. if (BrandIds == 6) FromStoreId = 871;
  563. if (BrandIds == 7) FromStoreId = 1047;
  564. if (BrandIds == 8) FromStoreId = 4831;
  565. if (BrandIds == 9) FromStoreId = 4832;
  566. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == BrandIds);
  567. CheckSendInfo items = checksendInfos.FirstOrDefault(m => m.BrandId == BrandIds) ?? new CheckSendInfo();
  568. if (items.Num > num)
  569. {
  570. return "Warning|" + "该条发货记录的" + brandInfo.Name + "发货数量过多!";
  571. }
  572. if (items.Num < num)
  573. {
  574. return "Warning|" + "该条发货记录的" + brandInfo.Name + "发货数量不足!";
  575. }
  576. }
  577. List<string> PosSnList = new List<string>();
  578. for (int index = 1; index < list.Count; index++)
  579. {
  580. JsonData dr = list[index];
  581. string itemJson = dr.ToJson();
  582. string SnNo = itemJson.Contains("\"A\"") ? dr["A"].ToString() : "";
  583. string Brand = itemJson.Contains("\"B\"") ? dr["B"].ToString() : "";
  584. BrandId = Convert.ToInt32(Brand);
  585. Models.MachineForSnNo posInfo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SnNo) ?? new Models.MachineForSnNo();
  586. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == posInfo.SnId) ?? new Models.PosMachinesTwo();
  587. if (posInfo.SnId > 0)
  588. {
  589. if (pos.Id > 0)
  590. {
  591. if (pos.BrandId != BrandId)
  592. {
  593. error += "以下操作失败" + SnNo + ',' + "该机具品牌填写错误" + '\n';
  594. }
  595. }
  596. if (BrandId == 1) FromStoreId = 7;
  597. if (BrandId == 2) FromStoreId = 721;
  598. if (BrandId == 3) FromStoreId = 697;
  599. if (BrandId == 4) FromStoreId = 774;
  600. if (BrandId == 5) FromStoreId = 775;
  601. if (BrandId == 6) FromStoreId = 871;
  602. if (BrandId == 7) FromStoreId = 1047;
  603. if (BrandId == 8) FromStoreId = 4831;
  604. if (BrandId == 9) FromStoreId = 4832;
  605. if (PosSnList.Contains(SnNo))
  606. {
  607. error += "以下操作失败" + SnNo + ',' + "该机具重复发货" + '\n';
  608. }
  609. PosSnList.Add(SnNo);
  610. }
  611. else
  612. {
  613. error += "以下操作失败" + SnNo + ',' + "未找到该机具" + '\n';
  614. }
  615. }
  616. if (!string.IsNullOrEmpty(error))
  617. {
  618. return "Warning|" + error;
  619. }
  620. Dictionary<string, int> storeData = new Dictionary<string, int>();
  621. Dictionary<string, int> toStoreData = new Dictionary<string, int>();
  622. for (int index = 1; index < list.Count; index++)
  623. {
  624. JsonData dr = list[index];
  625. string itemJson = dr.ToJson();
  626. string SnNo = itemJson.Contains("\"A\"") ? dr["A"].ToString() : "";
  627. string Brand = itemJson.Contains("\"B\"") ? dr["B"].ToString() : "";
  628. string BatchNo = itemJson.Contains("\"C\"") ? dr["C"].ToString() : "";
  629. string OutNote = itemJson.Contains("\"D\"") ? dr["D"].ToString() : "";
  630. BrandId = Convert.ToInt32(Brand);
  631. if (BrandId == 1) FromStoreId = 7;
  632. if (BrandId == 2) FromStoreId = 721;
  633. if (BrandId == 3) FromStoreId = 697;
  634. if (BrandId == 4) FromStoreId = 774;
  635. if (BrandId == 5) FromStoreId = 775;
  636. if (BrandId == 6) FromStoreId = 871;
  637. if (BrandId == 7) FromStoreId = 1047;
  638. if (BrandId == 8) FromStoreId = 4831;
  639. if (BrandId == 9) FromStoreId = 4832;
  640. tostore = db.StoreHouse.FirstOrDefault(m => m.Sort > 0 && m.UserId == apply.UserId && m.BrandId == BrandId.ToString() && m.Status == 1);
  641. SendInfo item = sendInfos.FirstOrDefault(m => m.FromStoreId == FromStoreId && m.ToStoreId == tostore.Id && m.BrandId == BrandId);
  642. if (item == null)
  643. {
  644. SendInfo row = new SendInfo()
  645. {
  646. FromStoreId = FromStoreId,
  647. ToStoreId = tostore.Id,
  648. BrandId = BrandId,
  649. Num = 1
  650. };
  651. sendInfos.Add(row);
  652. }
  653. else
  654. {
  655. item.Num += 1;
  656. }
  657. apply.SeoDescription = function.CheckString(SnNo) + ',';
  658. fromstore = db.StoreHouse.FirstOrDefault(m => m.Id == FromStoreId);
  659. // tostore = db.StoreHouse.FirstOrDefault(m => m.Sort > 0 && m.UserId == apply.UserId && m.BrandId == BrandId.ToString() && m.Status == 1);
  660. Models.MachineForSnNo machinefor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SnNo) ?? new Models.MachineForSnNo();
  661. Models.PosMachinesTwo machine = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machinefor.SnId && m.BuyUserId == 0 && m.UserId == 0) ?? new Models.PosMachinesTwo();
  662. if (machine.Id > 0)
  663. {
  664. if (machine.BrandId != BrandId)
  665. {
  666. return machine.PosSn + "与表格里填写的品牌不一致";
  667. }
  668. else
  669. {
  670. Models.StoreStockChange stockchange = db.StoreStockChange.Add(new Models.StoreStockChange()
  671. {
  672. CreateDate = DateTime.Now,
  673. CreateMan = SysUserName,
  674. Sort = data.Id,//库存变动关联申请记录表
  675. StoreId = FromStoreId, //出货仓库
  676. BrandId = BrandId, //产品类型
  677. ProductName = RelationClass.GetKqProductBrandInfo(BrandId), //产品名称
  678. BizBatchNo = BatchNo, //业务批次号
  679. TransType = 1, //交易类型
  680. SnNo = SnNo, //SN编号
  681. StockOpDirect = 1, //库存操作方向
  682. SnStatus = 1, //SN状态
  683. DeviceVendor = machine.DeviceName, //设备厂商
  684. DeviceModel = machine.DeviceKind, //设备型号
  685. DeviceType = machine.DeviceType, //设备类型
  686. FromUserId = fromstore.UserId, //出货人
  687. FromDate = DateTime.Now, //出库时间
  688. FromRemark = OutNote, //出库备注
  689. ToUserId = tostore.UserId, //收货人
  690. ToStoreId = fromstore.Id, //退货收货仓库
  691. SourceStoreId = machine.SourceStoreId, //源仓库编号
  692. BrandType = machine.DeviceType, //品牌类型
  693. }).Entity;
  694. string ChangeNo = "CS";
  695. int StoreStockChangeId = stockchange.Id;
  696. string StoreStockChangeIdString = StoreStockChangeId.ToString();
  697. for (int j = 0; j < 18 - StoreStockChangeId.ToString().Length; j++)
  698. {
  699. StoreStockChangeIdString = "0" + StoreStockChangeIdString;
  700. }
  701. ChangeNo += StoreStockChangeIdString;
  702. stockchange.ChangeNo = ChangeNo; //交易流水编号
  703. machine.StoreId = tostore.Id;
  704. db.StoreChangeHistory.Add(new Models.StoreChangeHistory()
  705. {
  706. CreateDate = DateTime.Now,
  707. UserId = fromstore.UserId, //创客
  708. BrandId = BrandId, //产品类型
  709. ChangeRecordNo = ChangeNo, //变更记录单号
  710. BizBatchNo = BatchNo, //业务批次号
  711. TransType = 1, //交易类型
  712. SnNo = SnNo, //SN编号
  713. SnType = machine.PosSnType, //SN机具类型
  714. StockOpDirect = 1, //库存操作方向
  715. DeviceVendor = machine.DeviceName, //设备厂商
  716. DeviceModel = machine.DeviceKind, //设备型号
  717. DeviceType = machine.DeviceType, //设备类型
  718. FromUserId = fromstore.UserId, //出货创客
  719. FromDate = DateTime.Now, //出库时间
  720. FromRemark = OutNote, //出库备注
  721. SourceStoreId = machine.SourceStoreId, //源仓库
  722. StoreId = fromstore.Id, //仓库
  723. ToUserId = tostore.UserId,//收货创客
  724. });
  725. //修改机具所属仓库
  726. machine.StoreId = tostore.Id;
  727. machine.UpdateDate = DateTime.Now;
  728. //添加机具所属运营中心
  729. machine.OpId = tostore.UserId;
  730. db.SaveChanges();
  731. }
  732. }
  733. else
  734. {
  735. return "总仓无该机具";
  736. }
  737. }
  738. foreach (var item in sendInfos)
  739. {
  740. //出货仓库数据调整
  741. Models.StoreHouse storeCH = db.StoreHouse.FirstOrDefault(m => m.Id == item.FromStoreId) ?? new Models.StoreHouse();
  742. Models.StoreBalance balance = db.StoreBalance.Add(new Models.StoreBalance()
  743. {
  744. CreateDate = DateTime.Now,
  745. StoreId = storeCH.Id, //仓库
  746. TransType = 1, //交易类型
  747. BrandId = BrandId, //产品类型
  748. OpStoreNum = item.Num, //操作库存数
  749. OpSymbol = "-", //操作符
  750. BeforeTotalNum = storeCH.TotalNum, //操作前总库存数
  751. AfterTotalNum = storeCH.TotalNum - item.Num, //操作后总库存数
  752. BeforeLaveNum = storeCH.LaveNum, //操作前剩余库存数
  753. AfterLaveNum = storeCH.LaveNum - item.Num, //操作后剩余库存数
  754. BeforeOutNum = storeCH.OutNum, //操作前出库数
  755. AfterOutNum = storeCH.OutNum + item.Num, //操作后出库数
  756. }).Entity;
  757. string ChangeNo1 = "CS";
  758. int StoreStockChangeId1 = balance.Id;
  759. string StoreStockChangeId1String = StoreStockChangeId1.ToString();
  760. for (int i = 0; i < 18 - StoreStockChangeId1.ToString().Length; i++)
  761. {
  762. StoreStockChangeId1String = "0" + StoreStockChangeId1String;
  763. }
  764. ChangeNo1 += StoreStockChangeId1String;
  765. balance.TransRecordNo = ChangeNo1; //交易流水编号
  766. storeCH.LaveNum -= item.Num;
  767. storeCH.OutNum += item.Num;
  768. //收货仓库数据调整
  769. Models.StoreHouse storeSH = db.StoreHouse.FirstOrDefault(m => m.Id == item.ToStoreId) ?? new Models.StoreHouse();
  770. balance = db.StoreBalance.Add(new Models.StoreBalance()
  771. {
  772. CreateDate = DateTime.Now,
  773. StoreId = storeSH.Id, //仓库
  774. TransType = 0, //交易类型
  775. BrandId = BrandId, //产品类型
  776. OpStoreNum = item.Num, //操作库存数
  777. OpSymbol = "+", //操作符
  778. BeforeTotalNum = storeSH.TotalNum, //操作前总库存数
  779. AfterTotalNum = storeSH.TotalNum + item.Num, //操作后总库存数
  780. BeforeLaveNum = storeSH.LaveNum, //操作前剩余库存数
  781. AfterLaveNum = storeSH.LaveNum + item.Num, //操作后剩余库存数
  782. BeforeOutNum = storeSH.OutNum, //操作前出库数
  783. AfterOutNum = storeSH.OutNum, //操作后出库数
  784. }).Entity;
  785. string ChangeNo2 = "CS";
  786. int StoreStockChangeId2 = balance.Id;
  787. string StoreStockChangeId2String = StoreStockChangeId2.ToString();
  788. for (int i = 0; i < 18 - StoreStockChangeId2.ToString().Length; i++)
  789. {
  790. StoreStockChangeId2String = "0" + StoreStockChangeId2String;
  791. }
  792. ChangeNo2 += StoreStockChangeId2String;
  793. balance.TransRecordNo = ChangeNo2; //交易流水编号
  794. storeSH.TotalNum += item.Num;
  795. storeSH.LaveNum += item.Num;
  796. var sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.QueryCount == 1 && m.Status == 0 && m.UserId == storeSH.UserId) ?? new SysAdmin();
  797. if (sysAdmin.Id > 0)
  798. {
  799. sysAdmin.TotalMachineCount += item.Num;
  800. }
  801. }
  802. apply.SeoTitle = SysUserName + '-' + SysRealName;//添加操作人信息
  803. apply.UseAmount = ApplyAmount;
  804. db.SaveChanges();
  805. new AdminContentOther(_accessor.HttpContext, PublicFunction.OpTables).Edit("StoreMachineApply", Fields, data.Id);
  806. string SendData = "{\"Kind\":\"2\",\"Data\":{\"UserId\":\"" + apply.UserId + "\",\"Amount\":\"" + Amount + "\",\"OperateType\":\"1\"}}";
  807. RedisDbconn.Instance.AddList("StoreApplyQueue", SendData);
  808. return "success";
  809. }
  810. #endregion
  811. //发货信息实体类
  812. private class SendInfo
  813. {
  814. public int FromStoreId { get; set; }
  815. public int ToStoreId { get; set; }
  816. public int BrandId { get; set; }
  817. public int Num { get; set; }
  818. }
  819. //检查发货信息实体类
  820. private class CheckSendInfo
  821. {
  822. public int BrandId { get; set; }
  823. public int Num { get; set; }
  824. }
  825. }
  826. }