PosMachinesTwoController.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  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.Data;
  10. using System.Threading.Tasks;
  11. using Microsoft.AspNetCore.Mvc;
  12. using Microsoft.AspNetCore.Http;
  13. using Microsoft.Extensions.Logging;
  14. using Microsoft.Extensions.Options;
  15. using MySystem.Models;
  16. using Library;
  17. using LitJson;
  18. using MySystemLib;
  19. namespace MySystem.Areas.Admin.Controllers
  20. {
  21. [Area("Admin")]
  22. [Route("Admin/[controller]/[action]")]
  23. public class PosMachinesTwoController : BaseController
  24. {
  25. public PosMachinesTwoController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  26. {
  27. OtherMySqlConn.connstr = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  28. }
  29. #region 机具库列表
  30. /// <summary>
  31. /// 根据条件查询机具库列表
  32. /// </summary>
  33. /// <returns></returns>
  34. public IActionResult Index(PosMachinesTwo data, string right)
  35. {
  36. ViewBag.RightInfo = RightInfo;
  37. ViewBag.right = right;
  38. return View();
  39. }
  40. #endregion
  41. #region 根据条件查询机具库列表
  42. /// <summary>
  43. /// 机具库列表
  44. /// </summary>
  45. /// <returns></returns>
  46. public JsonResult IndexData(PosMachinesTwo data, string BindingStateSelect, string ActivationStateSelect, string UserIdMakerCode, string UserIdRealName, string StoreIdCode, string StoreIdName, string BrandId, string ActivationDateData, string BindingDateData, string IsStoreSelect, string OpCode, int ShowFlag = 0, int page = 1, int limit = 30)
  47. {
  48. Dictionary<string, string> Fields = new Dictionary<string, string>();
  49. Fields.Add("PosSn", "1"); //SN编号
  50. Fields.Add("BrandId", "0"); //品牌
  51. if (ShowFlag == 0)
  52. {
  53. Dictionary<string, object> objs = new Dictionary<string, object>();
  54. Dictionary<string, object> others = new Dictionary<string, object>();
  55. others.Add("TotalCount", 0);
  56. others.Add("KysCount99", 0);
  57. others.Add("KssCount99", 0);
  58. others.Add("KssCoun198", 0);
  59. others.Add("KssCount298", 0);
  60. objs.Add("other", others);
  61. return Json(objs);
  62. }
  63. string condition = " and Status>-1";
  64. //是否仓库机
  65. if (!string.IsNullOrEmpty(IsStoreSelect))
  66. {
  67. if (int.Parse(IsStoreSelect) > 0)
  68. {
  69. condition += " and UserId=0 and BuyUserId=0";
  70. }
  71. }
  72. //绑定状态
  73. if (!string.IsNullOrEmpty(BindingStateSelect))
  74. {
  75. condition += " and BindingState=" + BindingStateSelect;
  76. }
  77. //激活状态
  78. if (!string.IsNullOrEmpty(ActivationStateSelect))
  79. {
  80. condition += " and ActivationState=" + ActivationStateSelect;
  81. }
  82. //所属创客编号
  83. if (!string.IsNullOrEmpty(UserIdMakerCode))
  84. {
  85. condition += " and BuyUserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  86. }
  87. //所属创客真实姓名
  88. if (!string.IsNullOrEmpty(UserIdRealName))
  89. {
  90. condition += " and BuyUserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  91. }
  92. //所属仓库编号
  93. if (!string.IsNullOrEmpty(StoreIdCode))
  94. {
  95. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreIdCode + "')";
  96. }
  97. //所属仓库名称
  98. if (!string.IsNullOrEmpty(StoreIdName))
  99. {
  100. condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreIdName + "')";
  101. }
  102. //运营中心编号
  103. if (!string.IsNullOrEmpty(OpCode))
  104. {
  105. var sysUser = opdb.SysAdmin.FirstOrDefault(m => m.OpCode == OpCode) ?? new OpModels.SysAdmin();
  106. if (sysUser.Id > 0)
  107. {
  108. condition += " and OpId=" + sysUser.UserId;
  109. }
  110. }
  111. //品牌
  112. if (!string.IsNullOrEmpty(BrandId))
  113. {
  114. condition += " and BrandId =" + BrandId;
  115. }
  116. if (!string.IsNullOrEmpty(ActivationDateData))
  117. {
  118. string[] datelist = ActivationDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  119. string start = datelist[0];
  120. string end = datelist[1];
  121. condition += " and ActivationTime>='" + start + " 00:00:00' and ActivationTime<='" + end + " 23:59:59'";
  122. }
  123. if (!string.IsNullOrEmpty(BindingDateData))
  124. {
  125. string[] datelist = BindingDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  126. string start = datelist[0];
  127. string end = datelist[1];
  128. condition += " and BindingTime>='" + start + " 00:00:00' and BindingTime<='" + end + " 23:59:59'";
  129. }
  130. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("PosMachinesTwo", Fields, "Id desc", "0", page, limit, condition);
  131. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  132. foreach (Dictionary<string, object> dic in diclist)
  133. {
  134. //绑定状态
  135. int BindingState = int.Parse(dic["BindingState"].ToString());
  136. if (BindingState == 0) dic["BindingState"] = "未绑定";
  137. if (BindingState == 1) dic["BindingState"] = "已绑定";
  138. //激活状态
  139. int ActivationState = int.Parse(dic["ActivationState"].ToString());
  140. if (ActivationState == 0) dic["ActivationState"] = "未激活";
  141. if (ActivationState == 1) dic["ActivationState"] = "已激活";
  142. //所属创客
  143. int BuyUserId = int.Parse(function.CheckInt(dic["BuyUserId"].ToString()));
  144. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == BuyUserId) ?? new Users();
  145. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  146. dic["UserIdRealName"] = userid_Users.RealName;
  147. dic.Remove("BuyUserId");
  148. //所属仓库
  149. int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString()));
  150. StoreHouse storeid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  151. dic["StoreIdCode"] = storeid_StoreHouse.StoreNo;
  152. dic["StoreIdName"] = storeid_StoreHouse.StoreName;
  153. dic.Remove("StoreId");
  154. //产品类型
  155. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  156. //参加活动
  157. dic["ActivityList"] = RelationClass.GetProfitObjectsActivesList(dic["ActivityList"].ToString());
  158. //绑定商户
  159. int BindMerchantId = int.Parse(function.CheckInt(dic["BindMerchantId"].ToString()));
  160. PosMerchantInfo bindmerchantid_MerchantInfo = db.PosMerchantInfo.FirstOrDefault(m => m.Id == BindMerchantId) ?? new PosMerchantInfo();
  161. dic["BindMerchantIdMerchantNo"] = bindmerchantid_MerchantInfo.MerchantNo;
  162. dic["BindMerchantIdMerchantName"] = bindmerchantid_MerchantInfo.MerchantName;
  163. dic.Remove("BindMerchantId");
  164. //机具类型
  165. int PosSnType = int.Parse(dic["PosSnType"].ToString());
  166. if (PosSnType == 0) dic["PosSnType"] = "购买机具";
  167. if (PosSnType == 1) dic["PosSnType"] = "赠送机具";
  168. //设备类型
  169. string DeviceType = dic["DeviceType"].ToString();
  170. if (DeviceType == "KysSignPos") dic["DeviceType"] = "快益刷电签POS";
  171. if (DeviceType == "KssSignPos") dic["DeviceType"] = "快闪刷电签POS";
  172. if (DeviceType == "") dic["DeviceType"] = "";
  173. //盟主信息
  174. int LeaderUserId = int.Parse(function.CheckInt(dic["LeaderUserId"].ToString()));
  175. if (LeaderUserId != 0)
  176. {
  177. Users users = db.Users.FirstOrDefault(m => m.Id == LeaderUserId) ?? new Users();
  178. dic["UserInfo"] = users.MakerCode + "_" + users.RealName;
  179. }
  180. //是否为第一台机具
  181. int IsFirst = int.Parse(dic["IsFirst"].ToString());
  182. if (IsFirst == 0) dic["IsFirst"] = "否";
  183. if (IsFirst == 1) dic["IsFirst"] = "是";
  184. //循环开始时间
  185. // if (!string.IsNullOrEmpty(dic["RecycEndDate"].ToString()))
  186. // {
  187. // // var RecycStartDate = Convert.ToDateTime(dic["RecycEndDate"].ToString()).AddDays(-360).ToString("yyyy-MM-dd HH:mm:ss");
  188. // // dic["RecycStartDate"] = RecycStartDate;
  189. // string PosSn = dic["PosSn"].ToString();
  190. // bool op = db.StoreChangeHistory.Any(m => m.SnNo == PosSn && m.TransType == 2);
  191. // if(op)
  192. // {
  193. // StoreChangeHistory item = db.StoreChangeHistory.FirstOrDefault(m => m.SnNo == PosSn && m.TransType == 2) ?? new StoreChangeHistory();
  194. // dic["RecycStartDate"] = item.ToDate == null ? "" : item.ToDate.Value.ToString("yyyy-MM-dd");
  195. // }
  196. // }
  197. //实际押金
  198. string SeoKeyword = dic["SeoKeyword"].ToString();
  199. if (SeoKeyword.Length > 2)
  200. {
  201. SeoKeyword = (decimal.Parse(SeoKeyword) / 100).ToString();
  202. }
  203. dic["SeoKeyword"] = SeoKeyword;
  204. //设置押金
  205. string PrizeParams = dic["PrizeParams"].ToString();
  206. dic["PrizeParams"] = PrizeParams;
  207. //所属运营中心
  208. int OpId = int.Parse(dic["OpId"].ToString());
  209. if (OpId != 0)
  210. {
  211. var sys = opdb.SysAdmin.FirstOrDefault(m => m.QueryCount > 0 && m.UserId == OpId) ?? new OpModels.SysAdmin();
  212. dic["OpCode"] = sys.OpCode;
  213. }
  214. }
  215. Dictionary<string, object> other = new Dictionary<string, object>();
  216. int TotalCount = 0;//总机具数
  217. DataTable dt = OtherMySqlConn.dtable("select count(0) from PosMachinesTwo where 1=1" + condition);
  218. if (dt.Rows.Count > 0)
  219. {
  220. TotalCount = int.Parse(function.CheckNum(dt.Rows[0][0].ToString()));
  221. }
  222. // dt = OtherMySqlConn.dtable("select sum(TotalPrice) from Orders where PayStatus=1" + condition);
  223. // if (dt.Rows.Count > 0)
  224. // {
  225. // FailAmount = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  226. // }
  227. other.Add("TotalCount", TotalCount);
  228. other.Add("KysCount99", 0);
  229. other.Add("KssCount99", 0);
  230. other.Add("KssCoun198", 0);
  231. other.Add("KssCount298", 0);
  232. obj.Add("other", other);
  233. return Json(obj);
  234. }
  235. #endregion
  236. #region 增加机具库
  237. /// <summary>
  238. /// 增加或修改机具库信息
  239. /// </summary>
  240. /// <returns></returns>
  241. public IActionResult Add(string right)
  242. {
  243. ViewBag.RightInfo = RightInfo;
  244. ViewBag.right = right;
  245. return View();
  246. }
  247. #endregion
  248. #region 增加机具库
  249. /// <summary>
  250. /// 增加或修改机具库信息
  251. /// </summary>
  252. /// <returns></returns>
  253. [HttpPost]
  254. public string Add(PosMachinesTwo data)
  255. {
  256. Dictionary<string, object> Fields = new Dictionary<string, object>();
  257. Fields.Add("SeoTitle", data.SeoTitle);
  258. Fields.Add("SeoKeyword", data.SeoKeyword);
  259. Fields.Add("SeoDescription", data.SeoDescription);
  260. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("PosMachinesTwo", Fields, 0);
  261. AddSysLog(data.Id.ToString(), "PosMachinesTwo", "add");
  262. db.SaveChanges();
  263. return "success";
  264. }
  265. #endregion
  266. #region 修改机具库
  267. /// <summary>
  268. /// 增加或修改机具库信息
  269. /// </summary>
  270. /// <returns></returns>
  271. public IActionResult Edit(string right, int Id = 0)
  272. {
  273. ViewBag.RightInfo = RightInfo;
  274. ViewBag.right = right;
  275. PosMachinesTwo editData = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id) ?? new PosMachinesTwo();
  276. ViewBag.data = editData;
  277. return View();
  278. }
  279. #endregion
  280. #region 修改机具库
  281. /// <summary>
  282. /// 增加或修改机具库信息
  283. /// </summary>
  284. /// <returns></returns>
  285. [HttpPost]
  286. public string Edit(PosMachinesTwo data)
  287. {
  288. Dictionary<string, object> Fields = new Dictionary<string, object>();
  289. Fields.Add("PosSnType", data.PosSnType);
  290. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMachinesTwo", Fields, data.Id);
  291. AddSysLog(data.Id.ToString(), "PosMachinesTwo", "update");
  292. db.SaveChanges();
  293. return "success";
  294. }
  295. #endregion
  296. #region 未使用机具归位总仓
  297. /// <summary>
  298. /// 未使用机具归位总仓
  299. /// </summary>
  300. /// <returns></returns>
  301. public IActionResult Home(string right, int Id = 0)
  302. {
  303. ViewBag.RightInfo = RightInfo;
  304. ViewBag.right = right;
  305. PosMachinesTwo editData = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id) ?? new PosMachinesTwo();
  306. ViewBag.data = editData;
  307. return View();
  308. }
  309. #endregion
  310. #region 未使用机具归位总仓
  311. /// <summary>
  312. /// 未使用机具归位总仓
  313. /// </summary>
  314. /// <returns></returns>
  315. [HttpPost]
  316. public string Home(PosMachinesTwo data)
  317. {
  318. Dictionary<string, object> Fields = new Dictionary<string, object>();
  319. Fields.Add("SeoTitle", "");
  320. Fields.Add("SeoKeyword", "");
  321. Fields.Add("PosSnType", 0);
  322. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMachinesTwo", Fields, data.Id);
  323. AddSysLog(data.Id.ToString(), "PosMachinesTwo", "home");
  324. db.SaveChanges();
  325. return "success";
  326. }
  327. #endregion
  328. #region 删除机具库信息
  329. /// <summary>
  330. /// 删除机具库信息
  331. /// </summary>
  332. /// <returns></returns>
  333. public string Delete(string Id)
  334. {
  335. string[] idlist = Id.Split(new char[] { ',' });
  336. AddSysLog(Id, "PosMachinesTwo", "del");
  337. foreach (string subid in idlist)
  338. {
  339. int id = int.Parse(subid);
  340. Dictionary<string, object> Fields = new Dictionary<string, object>();
  341. Fields.Add("Status", -1);
  342. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMachinesTwo", Fields, id);
  343. }
  344. db.SaveChanges();
  345. return "success";
  346. }
  347. #endregion
  348. #region 开启
  349. /// <summary>
  350. /// 开启
  351. /// </summary>
  352. /// <returns></returns>
  353. public string Open(string Id)
  354. {
  355. string[] idlist = Id.Split(new char[] { ',' });
  356. AddSysLog(Id, "PosMachinesTwo", "open");
  357. foreach (string subid in idlist)
  358. {
  359. int id = int.Parse(subid);
  360. Dictionary<string, object> Fields = new Dictionary<string, object>();
  361. Fields.Add("Status", 1);
  362. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMachinesTwo", Fields, id);
  363. }
  364. db.SaveChanges();
  365. return "success";
  366. }
  367. #endregion
  368. #region 关闭
  369. /// <summary>
  370. /// 关闭
  371. /// </summary>
  372. /// <returns></returns>
  373. public string Close(string Id)
  374. {
  375. string[] idlist = Id.Split(new char[] { ',' });
  376. AddSysLog(Id, "PosMachinesTwo", "close");
  377. foreach (string subid in idlist)
  378. {
  379. int id = int.Parse(subid);
  380. Dictionary<string, object> Fields = new Dictionary<string, object>();
  381. Fields.Add("Status", 0);
  382. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMachinesTwo", Fields, id);
  383. }
  384. db.SaveChanges();
  385. return "success";
  386. }
  387. #endregion
  388. #region 排序
  389. /// <summary>
  390. /// 排序
  391. /// </summary>
  392. /// <param name="Id"></param>
  393. public string Sort(int Id, int Sort)
  394. {
  395. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("PosMachinesTwo", Sort, Id);
  396. AddSysLog(Id.ToString(), "PosMachinesTwo", "sort");
  397. return "success";
  398. }
  399. #endregion
  400. #region 导入数据
  401. /// <summary>
  402. /// 导入数据
  403. /// </summary>
  404. /// <param name="ExcelData"></param>
  405. public string Import(string ExcelData, int Kind = 0)
  406. {
  407. ExcelData = HttpUtility.UrlDecode(ExcelData);
  408. JsonData list = JsonMapper.ToObject(ExcelData);
  409. if (Kind == 1)
  410. {
  411. string error = "";
  412. List<string> PosSnList = new List<string>();
  413. for (int i = 1; i < list.Count; i++)
  414. {
  415. JsonData dr = list[i];
  416. string itemJson = dr.ToJson();
  417. string PosSn = itemJson.Contains("\"A\"") ? dr["A"].ToString() : "";
  418. string BrandId = itemJson.Contains("\"B\"") ? dr["B"].ToString() : "";
  419. string MakerCode = itemJson.Contains("\"C\"") ? dr["C"].ToString() : "";
  420. string StoreNo = itemJson.Contains("\"D\"") ? dr["D"].ToString() : "";
  421. string No = itemJson.Contains("\"E\"") ? dr["E"].ToString() : "";
  422. string Remark = itemJson.Contains("\"F\"") ? dr["F"].ToString() : "";
  423. UserForMakerCode userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  424. var user = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new Users();
  425. MachineForSnNo machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn) ?? new MachineForSnNo();
  426. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId && m.BrandId == Convert.ToInt32(BrandId) && m.UserId == user.Id && m.BindingState == 0);
  427. if (posInfo == null)
  428. {
  429. error += "以下操作失败" + PosSn + ',' + "未找到该品牌的机具" + '\n';
  430. }
  431. else if (PosSnList.Contains(PosSn))
  432. {
  433. error += "以下操作失败" + PosSn + ',' + "该机具号重复" + '\n';
  434. }
  435. else if (!string.IsNullOrEmpty(error))
  436. {
  437. return "Warning|" + error;
  438. }
  439. else
  440. {
  441. PosSnList.Add(PosSn);
  442. }
  443. }
  444. for (int i = 1; i < list.Count; i++)
  445. {
  446. JsonData dr = list[i];
  447. string itemJson = dr.ToJson();
  448. string PosSn = itemJson.Contains("\"A\"") ? dr["A"].ToString() : "";
  449. string BrandId = itemJson.Contains("\"B\"") ? dr["B"].ToString() : "";
  450. string MakerCode = itemJson.Contains("\"C\"") ? dr["C"].ToString() : "";
  451. string StoreNo = itemJson.Contains("\"D\"") ? dr["D"].ToString() : "";
  452. string No = itemJson.Contains("\"E\"") ? dr["E"].ToString() : "";
  453. string Remark = itemJson.Contains("\"F\"") ? dr["F"].ToString() : "";
  454. decimal amount = 0;
  455. UserForMakerCode userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  456. var user = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new Users();
  457. var userAccount = db.UserAccount.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new UserAccount();
  458. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == Convert.ToInt32(BrandId)) ?? new KqProducts();
  459. if (brandInfo.Name.Contains("电签"))
  460. {
  461. amount = 200;
  462. }
  463. if (brandInfo.Name.Contains("大POS"))
  464. {
  465. amount = 300;
  466. }
  467. userAccount.ValidAmount += amount;
  468. string text = string.Format("导入机具驳回仓库,UserId: '" + user.Id + "',BeforeChangeAmount:'" + userAccount.ValidAmount + "',AfterChangeAmount:'" + userAccount.ValidAmount + amount + "',ChangeAmount:'" + amount + "',Time'" + DateTime.Now + "'");
  469. function.WriteLog(text, "机具驳回仓库");//机具驳回仓库日志
  470. db.SaveChanges();
  471. MachineForSnNo machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn) ?? new MachineForSnNo();
  472. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId && m.BrandId == Convert.ToInt32(BrandId) && m.UserId == user.Id && m.BindingState == 0);
  473. if (posInfo != null)
  474. {
  475. var storehouse = db.StoreHouse.FirstOrDefault(m => m.Id == posInfo.StoreId);
  476. StoreStockChange stockchange = db.StoreStockChange.Add(new StoreStockChange()
  477. {
  478. CreateDate = DateTime.Now,
  479. CreateMan = SysUserName,
  480. StoreId = storehouse.Id, //出货 仓库
  481. BrandId = Convert.ToInt32(BrandId), //产品类型
  482. ProductName = RelationClass.GetKqProductBrandInfo(Convert.ToInt32(BrandId)), //产品名称
  483. BizBatchNo = No, //业务批次号
  484. TransType = 1, //交易类型
  485. SnNo = PosSn, //SN编号
  486. StockOpDirect = 1, //库存操作方向
  487. SnStatus = 1, //SN状态
  488. DeviceVendor = posInfo.DeviceName, //设备厂商
  489. DeviceModel = posInfo.DeviceKind, //设备型号
  490. DeviceType = posInfo.DeviceType, //设备类型
  491. SourceStoreId = posInfo.SourceStoreId, //源仓库编号
  492. BrandType = posInfo.DeviceType, //品牌类型
  493. }).Entity;
  494. db.StoreChangeHistory.Add(new StoreChangeHistory()
  495. {
  496. CreateDate = DateTime.Now,
  497. UserId = user.Id, //创客
  498. BrandId = Convert.ToInt32(BrandId), //产品类型
  499. ChangeRecordNo = "JJBH" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8), //变更记录单号
  500. SeoTitle = "机具驳回仓库",
  501. BizBatchNo = No, //业务批次号
  502. SnNo = PosSn, //SN编号
  503. });
  504. StoreBalance balance = db.StoreBalance.Add(new StoreBalance()
  505. {
  506. CreateDate = DateTime.Now,
  507. StoreId = posInfo.StoreId, //仓库
  508. BrandId = Convert.ToInt32(BrandId), //产品类型
  509. OpStoreNum = 1, //操作库存数
  510. OpSymbol = "+", //操作符
  511. BeforeTotalNum = storehouse.TotalNum, //操作前总库存数
  512. AfterTotalNum = storehouse.TotalNum + 1, //操作后总库存数
  513. BeforeLaveNum = storehouse.LaveNum, //操作前剩余库存数
  514. AfterLaveNum = storehouse.LaveNum + 1, //操作后剩余库存数
  515. BeforeOutNum = storehouse.OutNum, //操作前出库数
  516. AfterOutNum = storehouse.OutNum - 1, //操作后出库数
  517. }).Entity;
  518. }
  519. }
  520. db.SaveChanges();
  521. }
  522. AddSysLog("0", "MachinesRejectStore", "Import");
  523. return "success";
  524. }
  525. #endregion
  526. #region 导出Excel
  527. /// <summary>
  528. /// 导出Excel
  529. /// </summary>
  530. /// <returns></returns>
  531. public JsonResult ExportExcel(PosMachinesTwo data, string BindingStateSelect, string ActivationStateSelect, string UserIdMakerCode, string UserIdRealName, string StoreIdCode, string StoreIdName)
  532. {
  533. Dictionary<string, string> Fields = new Dictionary<string, string>();
  534. Fields.Add("PosSn", "1"); //SN编号
  535. Fields.Add("BrandId", "0"); //品牌
  536. string condition = " and Status>-1";
  537. //绑定状态
  538. if (!string.IsNullOrEmpty(BindingStateSelect))
  539. {
  540. condition += " and BindingState=" + BindingStateSelect;
  541. }
  542. //激活状态
  543. if (!string.IsNullOrEmpty(ActivationStateSelect))
  544. {
  545. condition += " and ActivationState=" + ActivationStateSelect;
  546. }
  547. //所属创客编号
  548. if (!string.IsNullOrEmpty(UserIdMakerCode))
  549. {
  550. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  551. }
  552. //所属创客真实姓名
  553. if (!string.IsNullOrEmpty(UserIdRealName))
  554. {
  555. condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  556. }
  557. //所属仓库编号
  558. if (!string.IsNullOrEmpty(StoreIdCode))
  559. {
  560. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreIdCode + "')";
  561. }
  562. //所属仓库名称
  563. if (!string.IsNullOrEmpty(StoreIdName))
  564. {
  565. condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreIdName + "')";
  566. }
  567. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("PosMachinesTwo", Fields, "Id desc", "0", 1, 20000, condition, "BindingState,ActivationState,UserId,StoreId,PosSn,BrandId,ActivityList,BindMerchantId,PosSnType,DeviceType,BindingTime,ActivationTime,TransferTime", false);
  568. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  569. foreach (Dictionary<string, object> dic in diclist)
  570. {
  571. //绑定状态
  572. int BindingState = int.Parse(dic["BindingState"].ToString());
  573. if (BindingState == 0) dic["BindingState"] = "未绑定";
  574. if (BindingState == 1) dic["BindingState"] = "已绑定";
  575. //绑定时间
  576. if (!string.IsNullOrEmpty(dic["BindingTime"].ToString()))
  577. {
  578. DateTime BindingTime = Convert.ToDateTime(dic["BindingTime"].ToString());
  579. }
  580. //激活状态
  581. int ActivationState = int.Parse(dic["ActivationState"].ToString());
  582. if (ActivationState == 0) dic["ActivationState"] = "未激活";
  583. if (ActivationState == 1) dic["ActivationState"] = "已激活";
  584. //激活时间
  585. if (!string.IsNullOrEmpty(dic["ActivationTime"].ToString()))
  586. {
  587. DateTime ActivationTime = Convert.ToDateTime(dic["ActivationTime"].ToString());
  588. }
  589. //划拨时间
  590. if (!string.IsNullOrEmpty(dic["TransferTime"].ToString()))
  591. {
  592. DateTime TransferTime = Convert.ToDateTime(dic["TransferTime"].ToString());
  593. }
  594. //所属创客
  595. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  596. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  597. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  598. dic["UserIdRealName"] = userid_Users.RealName;
  599. dic.Remove("UserId");
  600. //所属仓库
  601. int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString()));
  602. StoreHouse storeid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  603. dic["StoreIdCode"] = storeid_StoreHouse.StoreNo;
  604. dic["StoreIdName"] = storeid_StoreHouse.StoreName;
  605. dic.Remove("StoreId");
  606. //产品类型
  607. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  608. //参加活动
  609. // dic["ActivityList"] = RelationClass.GetProfitObjectsActivesList(dic["ActivityList"].ToString());
  610. //绑定商户
  611. int BindMerchantId = int.Parse(function.CheckInt(dic["BindMerchantId"].ToString()));
  612. PosMerchantInfo bindmerchantid_MerchantInfo = db.PosMerchantInfo.FirstOrDefault(m => m.Id == BindMerchantId) ?? new PosMerchantInfo();
  613. dic["BindMerchantIdMerchantNo"] = bindmerchantid_MerchantInfo.MerchantNo;
  614. dic["BindMerchantIdMerchantName"] = bindmerchantid_MerchantInfo.MerchantName;
  615. dic.Remove("BindMerchantId");
  616. //机具类型
  617. int PosSnType = int.Parse(dic["PosSnType"].ToString());
  618. if (PosSnType == 0) dic["PosSnType"] = "购买机具";
  619. if (PosSnType == 1) dic["PosSnType"] = "赠送机具";
  620. // //设备类型
  621. // string DeviceType = dic["DeviceType"].ToString();
  622. // if (DeviceType == "KysSignPos") dic["DeviceType"] = "快益刷电签POS";
  623. // if (DeviceType == "KssSignPos") dic["DeviceType"] = "快闪刷电签POS";
  624. // if (DeviceType == "") dic["DeviceType"] = "";
  625. }
  626. Dictionary<string, object> result = new Dictionary<string, object>();
  627. result.Add("Status", "1");
  628. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  629. result.Add("Obj", diclist);
  630. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  631. ReturnFields.Add("UserIdMakerCode", "创客编号");
  632. ReturnFields.Add("UserIdRealName", "创客姓名");
  633. ReturnFields.Add("StoreIdCode", "仓库编号");
  634. ReturnFields.Add("StoreIdName", "仓库名称");
  635. ReturnFields.Add("BrandId", "产品类型");
  636. ReturnFields.Add("PosSn", "SN编号");
  637. ReturnFields.Add("PosSnType", "SN类型");
  638. // ReturnFields.Add("ActivityList", "参加活动");
  639. ReturnFields.Add("BindMerchantIdMerchantNo", "绑定商户编号");
  640. ReturnFields.Add("BindMerchantIdMerchantName", "绑定商户姓名");
  641. ReturnFields.Add("DeviceType", "设备类型");
  642. ReturnFields.Add("BindingState", "绑定状态");
  643. ReturnFields.Add("BindingTime", "绑定时间");
  644. ReturnFields.Add("ActivationState", "激活状态");
  645. ReturnFields.Add("ActivationTime", "激活时间");
  646. ReturnFields.Add("TransferTime", "划拨时间");
  647. result.Add("Fields", ReturnFields);
  648. AddSysLog("0", "PosMachinesTwo", "ExportExcel");
  649. return Json(result);
  650. }
  651. #endregion
  652. }
  653. }