PosMachinesTwoController.cs 32 KB

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