StoreMachineApplyOperateController.cs 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023
  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. // Users users = db.Users.FirstOrDefault(m => m.Id == editData.UserId) ?? new Users();
  209. SysAdmin sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.Status == 0 && m.UserId == editData.UserId) ?? new SysAdmin();
  210. ViewBag.UserId = sysAdmin.UserId;
  211. ViewBag.MakerCode = sysAdmin.MakerCode;
  212. ViewBag.MakerName = sysAdmin.MakerName;
  213. ViewBag.UseAmount = editData.UseAmount;
  214. JsonData SendSnList = new JsonData();
  215. SendSnList = JsonMapper.ToObject(editData.SendSn);//申请数据
  216. List<Dictionary<string, object>> KsProductList = new List<Dictionary<string, object>>();
  217. for (int i = 0; i < SendSnList.Count; i++)
  218. {
  219. int BrandId = Convert.ToInt32(SendSnList[i]["BrandId"].ToString());
  220. int Num = Convert.ToInt32(SendSnList[i]["ApplyNum"].ToString());
  221. var products = db.KqProducts.Where(m => m.Id == BrandId).ToList();
  222. foreach (var product in products)
  223. {
  224. Dictionary<string, object> item = new Dictionary<string, object>();
  225. item.Add("BrandId", BrandId); //商品Id
  226. item.Add("Name", product.Name); //商品名称
  227. item.Add("Num", Num); //商品数量
  228. KsProductList.Add(item);
  229. }
  230. }
  231. ViewBag.KsProductList = KsProductList;
  232. return View();
  233. }
  234. #endregion
  235. #region 修改分仓机具申请记录
  236. /// <summary>
  237. /// 增加或修改分仓机具申请记录信息
  238. /// </summary>
  239. /// <returns></returns>
  240. [HttpPost]
  241. public string Edit(StoreMachineApply data)
  242. {
  243. Dictionary<string, object> Fields = new Dictionary<string, object>();
  244. Fields.Add("SendSn", data.SendSn); //发货SN数据
  245. JsonData SendSnList = new JsonData();
  246. SendSnList = JsonMapper.ToObject(data.SendSn);//申请数据
  247. int ApplyNum = 0;
  248. for (int i = 0; i < SendSnList.Count; i++)
  249. {
  250. int num = Convert.ToInt32(SendSnList[i]["ApplyNum"].ToString());
  251. ApplyNum += num;
  252. }
  253. Fields.Add("BrandId", data.BrandId); //品牌
  254. Fields.Add("ApplyNo", data.ApplyNo); //申请单号
  255. Fields.Add("ApplyNum", ApplyNum); //申请台数
  256. Fields.Add("SendNum", data.SendNum); //发货台数
  257. Fields.Add("UseAmount", data.UseAmount); //使用额度
  258. Fields.Add("SendMode", data.SendMode); //发货方式
  259. Fields.Add("ErpCode", data.ErpCode); //快递单号
  260. Fields.Add("UserId", data.UserId); //创客
  261. Fields.Add("SeoKeyword", data.SeoKeyword);
  262. Fields.Add("SeoDescription", data.SeoDescription);
  263. new AdminContentByConn(_accessor.HttpContext, PublicFunction.OpTables, OpConn).Edit("StoreMachineApply", Fields, data.Id);
  264. AddSysLog(data.Id.ToString(), "OpStoreMachineApply", "update");
  265. db.SaveChanges();
  266. return "success";
  267. }
  268. #endregion
  269. #region 删除分仓机具申请记录信息
  270. /// <summary>
  271. /// 删除分仓机具申请记录信息
  272. /// </summary>
  273. /// <returns></returns>
  274. public string Delete(string Id)
  275. {
  276. string[] idlist = Id.Split(new char[] { ',' });
  277. AddSysLog(Id, "StoreMachineApply", "del");
  278. foreach (string subid in idlist)
  279. {
  280. int id = int.Parse(subid);
  281. Dictionary<string, object> Fields = new Dictionary<string, object>();
  282. Fields.Add("Status", -1);
  283. new AdminContentByConn(_accessor.HttpContext, PublicFunction.OpTables, OpConn).Edit("StoreMachineApply", Fields, id);
  284. }
  285. db.SaveChanges();
  286. return "success";
  287. }
  288. #endregion
  289. #region 开启
  290. /// <summary>
  291. /// 开启
  292. /// </summary>
  293. /// <returns></returns>
  294. public string Open(string Id)
  295. {
  296. string[] idlist = Id.Split(new char[] { ',' });
  297. AddSysLog(Id, "StoreMachineApply", "open");
  298. foreach (string subid in idlist)
  299. {
  300. int id = int.Parse(subid);
  301. Dictionary<string, object> Fields = new Dictionary<string, object>();
  302. Fields.Add("Status", 1);
  303. new AdminContentByConn(_accessor.HttpContext, PublicFunction.OpTables, OpConn).Edit("StoreMachineApply", Fields, id);
  304. }
  305. db.SaveChanges();
  306. return "success";
  307. }
  308. #endregion
  309. #region 关闭
  310. /// <summary>
  311. /// 关闭
  312. /// </summary>
  313. /// <returns></returns>
  314. public string Close(string Id)
  315. {
  316. string[] idlist = Id.Split(new char[] { ',' });
  317. AddSysLog(Id, "StoreMachineApplyOperate", "close");
  318. foreach (string subid in idlist)
  319. {
  320. int id = int.Parse(subid);
  321. Dictionary<string, object> Fields = new Dictionary<string, object>();
  322. Fields.Add("Status", 2);
  323. var query = opdb.StoreMachineApply.FirstOrDefault(m => m.Id == id);
  324. string[] amountlist = query.SeoTitle.Split(',');
  325. decimal ValidAmount = decimal.Parse(amountlist[0]);
  326. decimal TotalAmt = decimal.Parse(amountlist[1]);
  327. decimal ValidForGetAmount = decimal.Parse(amountlist[2]);
  328. var users = opdb.UserAccount.FirstOrDefault(m => m.Status == 0 && m.UserId == query.UserId) ?? new UserAccount();
  329. if (users.Id > 0)
  330. {
  331. var amountRecord = opdb.AmountRecord.Add(new AmountRecord()
  332. {
  333. CreateDate = DateTime.Now,
  334. CreateMan = SysUserName + "-" + SysRealName,
  335. SeoDescription = "机具申请驳回",
  336. OperateType = 1,//增加
  337. BeforeAmount = users.ValidAmount + users.TotalAmt + users.ValidForGetAmount,
  338. AfterAmount = users.ValidAmount + users.TotalAmt + users.ValidForGetAmount + query.UseAmount,
  339. UseAmount = query.UseAmount,
  340. UserId = query.UserId,
  341. ApplyId = query.Id,
  342. }).Entity;
  343. users.ValidAmount += ValidAmount;
  344. users.TotalAmt += TotalAmt;
  345. users.ValidForGetAmount += ValidForGetAmount;
  346. opdb.SaveChanges();
  347. }
  348. new AdminContentByConn(_accessor.HttpContext, PublicFunction.OpTables, OpConn).Edit("StoreMachineApply", Fields, id);
  349. }
  350. db.SaveChanges();
  351. return "success";
  352. }
  353. #endregion
  354. #region 排序
  355. /// <summary>
  356. /// 排序
  357. /// </summary>
  358. /// <param name="Id"></param>
  359. public string Sort(int Id, int Sort)
  360. {
  361. new AdminContentByConn(_accessor.HttpContext, PublicFunction.OpTables, OpConn).Sort("StoreMachineApply", Sort, Id);
  362. AddSysLog(Id.ToString(), "StoreMachineApply", "sort");
  363. return "success";
  364. }
  365. #endregion
  366. #region 导入数据
  367. /// <summary>
  368. /// 导入数据
  369. /// </summary>
  370. /// <param name="ExcelData"></param>
  371. public string Import(string ExcelData)
  372. {
  373. ExcelData = HttpUtility.UrlDecode(ExcelData);
  374. JsonData list = JsonMapper.ToObject(ExcelData);
  375. for (int i = 1; i < list.Count; i++)
  376. {
  377. JsonData dr = list[i];
  378. opdb.StoreMachineApply.Add(new StoreMachineApply()
  379. {
  380. CreateDate = DateTime.Now,
  381. UpdateDate = DateTime.Now,
  382. });
  383. db.SaveChanges();
  384. }
  385. AddSysLog("0", "OpStoreMachineApply", "Import");
  386. return "success";
  387. }
  388. #endregion
  389. #region 导出Excel
  390. /// <summary>
  391. /// 导出Excel
  392. /// </summary>
  393. /// <returns></returns>
  394. public JsonResult ExportExcel(StoreMachineApply data, string BrandIdSelect, string UserIdRealName, string UserIdMakerCode)
  395. {
  396. Dictionary<string, string> Fields = new Dictionary<string, string>();
  397. Fields.Add("CreateDate", "3"); //时间
  398. Fields.Add("ApplyNo", "1"); //申请单号
  399. Fields.Add("SendMode", "1"); //发货方式
  400. string condition = " and Status>-1";
  401. //品牌
  402. if (!string.IsNullOrEmpty(BrandIdSelect))
  403. {
  404. condition += " and BrandId=" + BrandIdSelect;
  405. }
  406. //创客真实姓名
  407. if (!string.IsNullOrEmpty(UserIdRealName))
  408. {
  409. condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  410. }
  411. //创客编号
  412. if (!string.IsNullOrEmpty(UserIdMakerCode))
  413. {
  414. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  415. }
  416. 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);
  417. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  418. foreach (Dictionary<string, object> dic in diclist)
  419. {
  420. //品牌
  421. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  422. dic["StatusName"] = dic["Status"].ToString() == "1" ? "正常" : "关闭";
  423. //运营中心
  424. int OpId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  425. SysAdmin sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.Id == OpId) ?? new SysAdmin();
  426. // Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  427. dic["MakerName"] = sysAdmin.MakerName;
  428. dic["MakerCode"] = sysAdmin.MakerCode;
  429. dic["OpCode"] = sysAdmin.OpCode;
  430. dic.Remove("OpId");
  431. }
  432. Dictionary<string, object> result = new Dictionary<string, object>();
  433. result.Add("Status", "1");
  434. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  435. result.Add("Obj", diclist);
  436. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  437. ReturnFields.Add("BrandId", "品牌");
  438. ReturnFields.Add("ApplyNo", "申请单号");
  439. ReturnFields.Add("ApplyNum", "申请台数");
  440. ReturnFields.Add("SendNum", "发货台数");
  441. ReturnFields.Add("UseAmount", "使用额度");
  442. ReturnFields.Add("SendMode", "发货方式");
  443. ReturnFields.Add("ErpCode", "快递单号");
  444. ReturnFields.Add("MakerName", "创客真实姓名");
  445. ReturnFields.Add("MakerName", "创客编号");
  446. ReturnFields.Add("OpCode", "运营中心编号");
  447. result.Add("Fields", ReturnFields);
  448. AddSysLog("0", "OpStoreMachineApply", "ExportExcel");
  449. return Json(result);
  450. }
  451. #endregion
  452. #region 审核发货
  453. public IActionResult AuditSend(string right, int Id = 0)
  454. {
  455. ViewBag.RightInfo = RightInfo;
  456. ViewBag.right = right;
  457. StoreMachineApply editData = opdb.StoreMachineApply.FirstOrDefault(m => m.Id == Id) ?? new StoreMachineApply();
  458. ViewBag.data = editData;
  459. SysAdmin sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.Status == 0 && m.UserId == editData.UserId) ?? new SysAdmin();
  460. ViewBag.OpCode = sysAdmin.OpCode;
  461. ViewBag.MakerCode = sysAdmin.MakerCode;
  462. ViewBag.MakerName = sysAdmin.MakerName;
  463. return View();
  464. }
  465. #endregion
  466. #region 审核发货
  467. [HttpPost]
  468. public string AuditSend(StoreMachineApply data, string ExcelData)
  469. {
  470. Dictionary<string, object> Fields = new Dictionary<string, object>();
  471. Fields.Add("ApplyNum", data.ApplyNum); //申请数
  472. Fields.Add("SendNum", data.ApplyNum); //发货数
  473. Fields.Add("ErpCode", data.ErpCode); //快递单号
  474. Fields.Add("SendMode", data.SendMode); //发货方式
  475. Fields.Add("SeoKeyword", data.SeoKeyword); //申请描述
  476. Fields.Add("Status", 1);
  477. AddSysLog(data.Id.ToString(), "StoreMachineApply", "AuditSend");
  478. Dictionary<string, object> Obj = new Dictionary<string, object>();
  479. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  480. List<SendInfo> sendInfos = new List<SendInfo>();
  481. List<CheckSendInfo> checksendInfos = new List<CheckSendInfo>();
  482. StoreMachineApply apply = opdb.StoreMachineApply.FirstOrDefault(m => m.Id == data.Id) ?? new StoreMachineApply();
  483. string[] amountlist = apply.SeoTitle.Split(',');
  484. decimal ValidAmount = decimal.Parse(amountlist[0]);
  485. decimal TotalAmt = decimal.Parse(amountlist[1]);
  486. decimal ValidForGetAmount = decimal.Parse(amountlist[2]);
  487. JsonData ApplyList = JsonMapper.ToObject(apply.SendSn);
  488. decimal ApplyAmount = 0;
  489. decimal Amount = 0;
  490. for (int i = 0; i < ApplyList.Count; i++)
  491. {
  492. int num = Convert.ToInt32(ApplyList[i]["ApplyNum"].ToString());
  493. int BrandIds = Convert.ToInt32(ApplyList[i]["BrandId"].ToString());
  494. //自动匹配品牌
  495. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == BrandIds);
  496. if (brandInfo.Name.Contains("电签"))
  497. {
  498. ApplyAmount += num * 100;
  499. }
  500. if (brandInfo.Name.Contains("大POS"))
  501. {
  502. ApplyAmount += num * 150;
  503. }
  504. }
  505. Amount = apply.UseAmount - ApplyAmount;
  506. Models.StoreHouse tostore = new Models.StoreHouse();
  507. Models.StoreHouse fromstore = new Models.StoreHouse();
  508. var BrandId = 0;
  509. var FromStoreId = 0;
  510. string error = "";
  511. if (string.IsNullOrEmpty(ExcelData))
  512. {
  513. return "Warning|" + "请选择要导入的数据";
  514. }
  515. ExcelData = HttpUtility.UrlDecode(ExcelData);
  516. JsonData list = JsonMapper.ToObject(ExcelData);
  517. //判断各品牌发货数量是否符合
  518. if (list.Count - 1 > apply.ApplyNum)
  519. {
  520. return "Warning|" + "机具发货数量过多!";
  521. }
  522. if (list.Count - 1 < apply.ApplyNum)
  523. {
  524. return "Warning|" + "机具发货数量不足!";
  525. }
  526. for (int index = 1; index < list.Count; index++)
  527. {
  528. JsonData dr = list[index];
  529. string itemJson = dr.ToJson();
  530. string SnNo = itemJson.Contains("\"A\"") ? dr["A"].ToString() : "";
  531. string Brand = itemJson.Contains("\"B\"") ? dr["B"].ToString() : "";
  532. string BatchNo = itemJson.Contains("\"C\"") ? dr["C"].ToString() : "";
  533. string OutNote = itemJson.Contains("\"D\"") ? dr["D"].ToString() : "";
  534. BrandId = Convert.ToInt32(Brand);
  535. if (BrandId == 1) FromStoreId = 7;
  536. if (BrandId == 2) FromStoreId = 721;
  537. if (BrandId == 3) FromStoreId = 697;
  538. if (BrandId == 4) FromStoreId = 774;
  539. if (BrandId == 5) FromStoreId = 775;
  540. if (BrandId == 6) FromStoreId = 871;
  541. if (BrandId == 7) FromStoreId = 1047;
  542. if (BrandId == 8) FromStoreId = 4831;
  543. if (BrandId == 9) FromStoreId = 4832;
  544. if (BrandId == 10) FromStoreId = 5512;
  545. if (BrandId == 11) FromStoreId = 5513;
  546. CheckSendInfo items = checksendInfos.FirstOrDefault(m => m.BrandId == BrandId);
  547. if (items == null)
  548. {
  549. CheckSendInfo rows = new CheckSendInfo()
  550. {
  551. BrandId = BrandId,
  552. Num = 1
  553. };
  554. checksendInfos.Add(rows);
  555. }
  556. else
  557. {
  558. items.Num += 1;
  559. }
  560. }
  561. for (int i = 0; i < ApplyList.Count; i++)
  562. {
  563. int num = Convert.ToInt32(ApplyList[i]["ApplyNum"].ToString());
  564. int BrandIds = Convert.ToInt32(ApplyList[i]["BrandId"].ToString());
  565. if (BrandIds == 1) FromStoreId = 7;
  566. if (BrandIds == 2) FromStoreId = 721;
  567. if (BrandIds == 3) FromStoreId = 697;
  568. if (BrandIds == 4) FromStoreId = 774;
  569. if (BrandIds == 5) FromStoreId = 775;
  570. if (BrandIds == 6) FromStoreId = 871;
  571. if (BrandIds == 7) FromStoreId = 1047;
  572. if (BrandIds == 8) FromStoreId = 4831;
  573. if (BrandIds == 9) FromStoreId = 4832;
  574. if (BrandId == 10) FromStoreId = 5512;
  575. if (BrandId == 11) FromStoreId = 5513;
  576. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == BrandIds);
  577. CheckSendInfo items = checksendInfos.FirstOrDefault(m => m.BrandId == BrandIds) ?? new CheckSendInfo();
  578. if (items.Num > num)
  579. {
  580. return "Warning|" + "该条发货记录的" + brandInfo.Name + "发货数量过多!";
  581. }
  582. if (items.Num < num)
  583. {
  584. return "Warning|" + "该条发货记录的" + brandInfo.Name + "发货数量不足!";
  585. }
  586. }
  587. List<string> PosSnList = new List<string>();
  588. for (int index = 1; index < list.Count; index++)
  589. {
  590. JsonData dr = list[index];
  591. string itemJson = dr.ToJson();
  592. string SnNo = itemJson.Contains("\"A\"") ? dr["A"].ToString() : "";
  593. string Brand = itemJson.Contains("\"B\"") ? dr["B"].ToString() : "";
  594. BrandId = Convert.ToInt32(Brand);
  595. if (BrandId == 1) FromStoreId = 7;
  596. if (BrandId == 2) FromStoreId = 721;
  597. if (BrandId == 3) FromStoreId = 697;
  598. if (BrandId == 4) FromStoreId = 774;
  599. if (BrandId == 5) FromStoreId = 775;
  600. if (BrandId == 6) FromStoreId = 871;
  601. if (BrandId == 7) FromStoreId = 1047;
  602. if (BrandId == 8) FromStoreId = 4831;
  603. if (BrandId == 9) FromStoreId = 4832;
  604. if (BrandId == 10) FromStoreId = 5512;
  605. if (BrandId == 11) FromStoreId = 5513;
  606. Models.MachineForSnNo posInfo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SnNo) ?? new Models.MachineForSnNo();
  607. 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();
  608. if (pos.BindingState == 1 || pos.ActivationState == 1)
  609. {
  610. error += "以下操作失败" + SnNo + ',' + "该机具已绑定或已激活" + '\n';
  611. }
  612. if (posInfo.SnId > 0)
  613. {
  614. if (pos.Id > 0)
  615. {
  616. if (pos.BrandId != BrandId)
  617. {
  618. error += "以下操作失败" + SnNo + ',' + "该机具品牌填写错误" + '\n';
  619. }
  620. }
  621. if (PosSnList.Contains(SnNo))
  622. {
  623. error += "以下操作失败" + SnNo + ',' + "该机具重复发货" + '\n';
  624. }
  625. PosSnList.Add(SnNo);
  626. }
  627. else
  628. {
  629. error += "以下操作失败" + SnNo + ',' + "未找到该机具或者该机具不符合发货条件" + '\n';
  630. }
  631. }
  632. if (!string.IsNullOrEmpty(error))
  633. {
  634. return "Warning|" + error;
  635. }
  636. Dictionary<string, int> storeData = new Dictionary<string, int>();
  637. Dictionary<string, int> toStoreData = new Dictionary<string, int>();
  638. var amount = 0;
  639. for (int index = 1; index < list.Count; index++)
  640. {
  641. JsonData dr = list[index];
  642. string itemJson = dr.ToJson();
  643. string SnNo = itemJson.Contains("\"A\"") ? dr["A"].ToString() : "";
  644. string Brand = itemJson.Contains("\"B\"") ? dr["B"].ToString() : "";
  645. string BatchNo = itemJson.Contains("\"C\"") ? dr["C"].ToString() : "";
  646. string OutNote = itemJson.Contains("\"D\"") ? dr["D"].ToString() : "";
  647. BrandId = Convert.ToInt32(Brand);
  648. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == BrandId);
  649. if (brandInfo != null)
  650. {
  651. if (brandInfo.Name.Contains("电签"))
  652. {
  653. amount = 100;
  654. }
  655. if (brandInfo.Name.Contains("大POS"))
  656. {
  657. amount = 150;
  658. }
  659. }
  660. if (BrandId == 1) FromStoreId = 7;
  661. if (BrandId == 2) FromStoreId = 721;
  662. if (BrandId == 3) FromStoreId = 697;
  663. if (BrandId == 4) FromStoreId = 774;
  664. if (BrandId == 5) FromStoreId = 775;
  665. if (BrandId == 6) FromStoreId = 871;
  666. if (BrandId == 7) FromStoreId = 1047;
  667. if (BrandId == 8) FromStoreId = 4831;
  668. if (BrandId == 9) FromStoreId = 4832;
  669. if (BrandId == 10) FromStoreId = 5512;
  670. if (BrandId == 11) FromStoreId = 5513;
  671. tostore = db.StoreHouse.FirstOrDefault(m => m.Sort > 0 && m.UserId == apply.UserId && m.BrandId == BrandId.ToString() && m.Status == 1);
  672. SendInfo item = sendInfos.FirstOrDefault(m => m.FromStoreId == FromStoreId && m.ToStoreId == tostore.Id && m.BrandId == BrandId);
  673. if (item == null)
  674. {
  675. SendInfo row = new SendInfo()
  676. {
  677. FromStoreId = FromStoreId,
  678. ToStoreId = tostore.Id,
  679. BrandId = BrandId,
  680. Num = 1
  681. };
  682. sendInfos.Add(row);
  683. }
  684. else
  685. {
  686. item.Num += 1;
  687. }
  688. apply.SeoDescription = function.CheckString(SnNo) + ',';
  689. fromstore = db.StoreHouse.FirstOrDefault(m => m.Id == FromStoreId);
  690. Models.MachineForSnNo machinefor = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == SnNo) ?? new Models.MachineForSnNo();
  691. Models.PosMachinesTwo machine = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machinefor.SnId && m.BuyUserId == 0 && m.UserId == 0) ?? new Models.PosMachinesTwo();
  692. if (machine.Id > 0)
  693. {
  694. if (machine.BrandId != BrandId)
  695. {
  696. return machine.PosSn + "与表格里填写的品牌不一致";
  697. }
  698. else
  699. {
  700. Models.StoreStockChange stockchange = db.StoreStockChange.Add(new Models.StoreStockChange()
  701. {
  702. CreateDate = DateTime.Now,
  703. CreateMan = SysUserName,
  704. Sort = data.Id,//库存变动关联申请记录表
  705. StoreId = FromStoreId, //出货仓库
  706. BrandId = BrandId, //产品类型
  707. ProductName = RelationClass.GetKqProductBrandInfo(BrandId), //产品名称
  708. BizBatchNo = BatchNo, //业务批次号
  709. TransType = 1, //交易类型
  710. SnNo = SnNo, //SN编号
  711. StockOpDirect = 1, //库存操作方向
  712. SnStatus = 1, //SN状态
  713. DeviceVendor = machine.DeviceName, //设备厂商
  714. DeviceModel = machine.DeviceKind, //设备型号
  715. DeviceType = machine.DeviceType, //设备类型
  716. FromUserId = fromstore.UserId, //出货人
  717. FromDate = DateTime.Now, //出库时间
  718. FromRemark = OutNote, //出库备注
  719. ToUserId = tostore.UserId, //收货人
  720. ToStoreId = fromstore.Id, //退货收货仓库
  721. SourceStoreId = machine.SourceStoreId, //源仓库编号
  722. BrandType = machine.DeviceType, //品牌类型
  723. }).Entity;
  724. string ChangeNo = "CS";
  725. int StoreStockChangeId = stockchange.Id;
  726. string StoreStockChangeIdString = StoreStockChangeId.ToString();
  727. for (int j = 0; j < 18 - StoreStockChangeId.ToString().Length; j++)
  728. {
  729. StoreStockChangeIdString = "0" + StoreStockChangeIdString;
  730. }
  731. ChangeNo += StoreStockChangeIdString;
  732. stockchange.ChangeNo = ChangeNo; //交易流水编号
  733. machine.StoreId = tostore.Id;
  734. db.StoreChangeHistory.Add(new Models.StoreChangeHistory()
  735. {
  736. CreateDate = DateTime.Now,
  737. UserId = fromstore.UserId, //创客
  738. BrandId = BrandId, //产品类型
  739. ChangeRecordNo = ChangeNo, //变更记录单号
  740. BizBatchNo = BatchNo, //业务批次号
  741. TransType = 1, //交易类型
  742. SnNo = SnNo, //SN编号
  743. SnType = machine.PosSnType, //SN机具类型
  744. StockOpDirect = 1, //库存操作方向
  745. DeviceVendor = machine.DeviceName, //设备厂商
  746. DeviceModel = machine.DeviceKind, //设备型号
  747. DeviceType = machine.DeviceType, //设备类型
  748. FromUserId = fromstore.UserId, //出货创客
  749. FromDate = DateTime.Now, //出库时间
  750. FromRemark = OutNote, //出库备注
  751. SourceStoreId = machine.SourceStoreId, //源仓库
  752. StoreId = fromstore.Id, //仓库
  753. ToUserId = tostore.UserId,//收货创客
  754. });
  755. //修改机具所属仓库
  756. machine.StoreId = tostore.Id;
  757. machine.UpdateDate = DateTime.Now;
  758. //添加机具所属运营中心
  759. machine.OpId = tostore.UserId;
  760. // //额度标记
  761. // if (ValidAmount >= amount)
  762. // {
  763. // ValidAmount -= amount;
  764. // // machine.OpReserveKind = 3;
  765. // }
  766. // else if (TotalAmt >= amount)
  767. // {
  768. // TotalAmt -= amount;
  769. // // machine.OpReserveKind = 1;
  770. // }
  771. // else if (ValidForGetAmount >= amount)
  772. // {
  773. // ValidForGetAmount -= amount;
  774. // // machine.OpReserveKind = 2;
  775. // }
  776. if (ValidAmount >= amount)
  777. {
  778. ValidAmount -= amount;
  779. machine.OpReserve3 = amount;
  780. machine.OpReserve1 = 0;
  781. machine.OpReserve2 = 0;
  782. }
  783. else
  784. {
  785. if (TotalAmt >= amount)
  786. {
  787. TotalAmt -= amount - ValidAmount;
  788. machine.OpReserve3 = ValidAmount;
  789. machine.OpReserve1 = amount - ValidAmount;
  790. machine.OpReserve2 = 0;
  791. }
  792. else
  793. {
  794. if (ValidForGetAmount >= amount)
  795. {
  796. ValidForGetAmount -= amount - TotalAmt;
  797. machine.OpReserve3 = 0;
  798. machine.OpReserve1 = TotalAmt;
  799. machine.OpReserve2 = amount - TotalAmt;
  800. }
  801. }
  802. }
  803. db.SaveChanges();
  804. }
  805. }
  806. else
  807. {
  808. return "总仓无该机具";
  809. }
  810. }
  811. foreach (var item in sendInfos)
  812. {
  813. //出货仓库数据调整
  814. Models.StoreHouse storeCH = db.StoreHouse.FirstOrDefault(m => m.Id == item.FromStoreId) ?? new Models.StoreHouse();
  815. Models.StoreBalance balance = db.StoreBalance.Add(new Models.StoreBalance()
  816. {
  817. CreateDate = DateTime.Now,
  818. StoreId = storeCH.Id, //仓库
  819. TransType = 1, //交易类型
  820. BrandId = BrandId, //产品类型
  821. OpStoreNum = item.Num, //操作库存数
  822. OpSymbol = "-", //操作符
  823. BeforeTotalNum = storeCH.TotalNum, //操作前总库存数
  824. AfterTotalNum = storeCH.TotalNum - item.Num, //操作后总库存数
  825. BeforeLaveNum = storeCH.LaveNum, //操作前剩余库存数
  826. AfterLaveNum = storeCH.LaveNum - item.Num, //操作后剩余库存数
  827. BeforeOutNum = storeCH.OutNum, //操作前出库数
  828. AfterOutNum = storeCH.OutNum + item.Num, //操作后出库数
  829. }).Entity;
  830. string ChangeNo1 = "CS";
  831. int StoreStockChangeId1 = balance.Id;
  832. string StoreStockChangeId1String = StoreStockChangeId1.ToString();
  833. for (int i = 0; i < 18 - StoreStockChangeId1.ToString().Length; i++)
  834. {
  835. StoreStockChangeId1String = "0" + StoreStockChangeId1String;
  836. }
  837. ChangeNo1 += StoreStockChangeId1String;
  838. balance.TransRecordNo = ChangeNo1; //交易流水编号
  839. storeCH.LaveNum -= item.Num;
  840. storeCH.OutNum += item.Num;
  841. //收货仓库数据调整
  842. Models.StoreHouse storeSH = db.StoreHouse.FirstOrDefault(m => m.Id == item.ToStoreId) ?? new Models.StoreHouse();
  843. balance = db.StoreBalance.Add(new Models.StoreBalance()
  844. {
  845. CreateDate = DateTime.Now,
  846. StoreId = storeSH.Id, //仓库
  847. TransType = 0, //交易类型
  848. BrandId = BrandId, //产品类型
  849. OpStoreNum = item.Num, //操作库存数
  850. OpSymbol = "+", //操作符
  851. BeforeTotalNum = storeSH.TotalNum, //操作前总库存数
  852. AfterTotalNum = storeSH.TotalNum + item.Num, //操作后总库存数
  853. BeforeLaveNum = storeSH.LaveNum, //操作前剩余库存数
  854. AfterLaveNum = storeSH.LaveNum + item.Num, //操作后剩余库存数
  855. BeforeOutNum = storeSH.OutNum, //操作前出库数
  856. AfterOutNum = storeSH.OutNum, //操作后出库数
  857. }).Entity;
  858. string ChangeNo2 = "CS";
  859. int StoreStockChangeId2 = balance.Id;
  860. string StoreStockChangeId2String = StoreStockChangeId2.ToString();
  861. for (int i = 0; i < 18 - StoreStockChangeId2.ToString().Length; i++)
  862. {
  863. StoreStockChangeId2String = "0" + StoreStockChangeId2String;
  864. }
  865. ChangeNo2 += StoreStockChangeId2String;
  866. balance.TransRecordNo = ChangeNo2; //交易流水编号
  867. storeSH.TotalNum += item.Num;
  868. storeSH.LaveNum += item.Num;
  869. var sysAdmin = opdb.SysAdmin.FirstOrDefault(m => m.QueryCount == 1 && m.Status == 0 && m.UserId == storeSH.UserId) ?? new SysAdmin();
  870. if (sysAdmin.Id > 0)
  871. {
  872. sysAdmin.TotalMachineCount += item.Num;
  873. opdb.SaveChanges();
  874. }
  875. }
  876. apply.SeoTitle = SysUserName + '-' + SysRealName;//添加操作人信息
  877. apply.UseAmount = ApplyAmount;
  878. db.SaveChanges();
  879. new AdminContentByConn(_accessor.HttpContext, PublicFunction.OpTables, OpConn).Edit("StoreMachineApply", Fields, data.Id);
  880. string SendData = "{\"Kind\":\"2\",\"Data\":{\"UserId\":\"" + apply.UserId + "\",\"Amount\":\"" + Amount + "\",\"OperateType\":\"1\"}}";
  881. RedisDbconn.Instance.AddList("StoreApplyQueue", SendData);
  882. return "success";
  883. }
  884. #endregion
  885. //发货信息实体类
  886. private class SendInfo
  887. {
  888. public int FromStoreId { get; set; }
  889. public int ToStoreId { get; set; }
  890. public int BrandId { get; set; }
  891. public int Num { get; set; }
  892. }
  893. //检查发货信息实体类
  894. private class CheckSendInfo
  895. {
  896. public int BrandId { get; set; }
  897. public int Num { get; set; }
  898. }
  899. }
  900. }