StoreMachineApplyOperateController.cs 41 KB

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