StoreMachineApplyOperateController.cs 44 KB

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