PosMachinesTwoController.cs 33 KB

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