StoreMachineApplyOperateController.cs 43 KB

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