StoreMachineApplyOperateController.cs 46 KB

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