StoreMachineApplyOperateController.cs 40 KB

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