PosMachinesTwoController.cs 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996
  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. #region 过期机具扣费列表
  653. /// <summary>
  654. /// 根据条件查询过期机具扣费列表
  655. /// </summary>
  656. /// <returns></returns>
  657. public IActionResult Indexs(PosMachinesTwo data, string right)
  658. {
  659. ViewBag.RightInfo = RightInfo;
  660. ViewBag.right = right;
  661. return View();
  662. }
  663. #endregion
  664. #region 根据条件查询过期机具扣费列表
  665. /// <summary>
  666. /// 过期机具扣费列表
  667. /// </summary>
  668. /// <returns></returns>
  669. public JsonResult IndexsData(PosMachinesTwo data, string PosSn, string UserIdMakerCode, string StoreMakerCode, string BrandId, string RecycEndDateData, string AmountYk, string Amountk, string AmountDk, int ShowFlag = 0, int page = 1, int limit = 30)
  670. {
  671. Dictionary<string, string> Fields = new Dictionary<string, string>();
  672. if (ShowFlag == 0)
  673. {
  674. Dictionary<string, object> objs = new Dictionary<string, object>();
  675. Dictionary<string, object> others = new Dictionary<string, object>();
  676. others.Add("TotalCount", 0);
  677. others.Add("AmountYks", 0);
  678. others.Add("AmountDks", 0);
  679. objs.Add("other", others);
  680. return Json(objs);
  681. }
  682. decimal AmountYks = 0;//已扣
  683. decimal AmountDks = 0;//待扣
  684. var time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  685. string condition = " and Status>-1 and RecycEndDate<'" + time + "' and ScanQrTrade>0 and ScanQrTrade<999 and BindingState=0";
  686. //所属创客编号
  687. if (!string.IsNullOrEmpty(UserIdMakerCode))
  688. {
  689. condition += " and BuyUserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  690. }
  691. //仓库所属创客编号
  692. if (!string.IsNullOrEmpty(StoreMakerCode))
  693. {
  694. var userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == StoreMakerCode) ?? new UserForMakerCode();
  695. var user = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new Users();
  696. var store = db.StoreHouse.Where(m => m.UserId == user.Id && m.Status > -1).ToList();
  697. var storeIds = "";
  698. foreach (var item in store)
  699. {
  700. storeIds += item.Id + ",";
  701. }
  702. storeIds = storeIds.TrimEnd(',');
  703. condition += " and StoreId in (" + storeIds + ")";
  704. }
  705. //品牌
  706. if (!string.IsNullOrEmpty(BrandId))
  707. {
  708. condition += " and BrandId =" + BrandId;
  709. }
  710. if (!string.IsNullOrEmpty(PosSn))
  711. {
  712. condition += " and PosSn =" + PosSn + "";
  713. }
  714. // if (!string.IsNullOrEmpty(AmountYk))
  715. // {
  716. // condition += " and BrandId =" + BrandId;
  717. // }
  718. // if (!string.IsNullOrEmpty(Amountk))
  719. // {
  720. // condition += " and BrandId =" + BrandId;
  721. // }
  722. // if (!string.IsNullOrEmpty(AmountDk))
  723. // {
  724. // condition += " and BrandId =" + BrandId;
  725. // }
  726. if (!string.IsNullOrEmpty(RecycEndDateData))
  727. {
  728. string[] datelist = RecycEndDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  729. string start = datelist[0];
  730. string end = datelist[1];
  731. condition += " and RecycEndDate>='" + start + " 00:00:00' and RecycEndDate<='" + end + " 23:59:59'";
  732. }
  733. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("PosMachinesTwo", Fields, "Id desc", "0", page, limit, condition);
  734. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  735. foreach (Dictionary<string, object> dic in diclist)
  736. {
  737. //绑定状态
  738. int BindingState = int.Parse(dic["BindingState"].ToString());
  739. if (BindingState == 0) dic["BindingState"] = "未绑定";
  740. if (BindingState == 1) dic["BindingState"] = "已绑定";
  741. //激活状态
  742. int ActivationState = int.Parse(dic["ActivationState"].ToString());
  743. if (ActivationState == 0) dic["ActivationState"] = "未激活";
  744. if (ActivationState == 1) dic["ActivationState"] = "已激活";
  745. //所属创客
  746. int BuyUserId = int.Parse(function.CheckInt(dic["BuyUserId"].ToString()));
  747. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == BuyUserId) ?? new Users();
  748. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  749. dic["UserIdRealName"] = userid_Users.RealName;
  750. dic.Remove("BuyUserId");
  751. //所属仓库
  752. int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString()));
  753. StoreHouse storeid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  754. dic["StoreIdCode"] = storeid_StoreHouse.StoreNo;
  755. dic["StoreIdName"] = storeid_StoreHouse.StoreName;
  756. dic.Remove("StoreId");
  757. //产品类型
  758. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  759. decimal ScanQrTrade = decimal.Parse(dic["ScanQrTrade"].ToString());
  760. var brandInfo = dic["BrandId"].ToString();
  761. decimal amount = 0;
  762. if (brandInfo.Contains("电签"))
  763. {
  764. amount = 200;
  765. }
  766. if (brandInfo.Contains("大POS"))
  767. {
  768. amount = 300;
  769. }
  770. if (ScanQrTrade > 0 && ScanQrTrade < 999)
  771. {
  772. dic["AmountYk"] = amount;
  773. dic["Amountk"] = ScanQrTrade;
  774. dic["AmountDk"] = amount - ScanQrTrade;
  775. // AmountYks += ScanQrTrade;
  776. // AmountDks += amount - ScanQrTrade;
  777. }
  778. if (ScanQrTrade == 999)
  779. {
  780. dic["AmountYk"] = amount;
  781. dic["Amountk"] = amount;
  782. dic["AmountDk"] = 0;
  783. // AmountYks += amount;
  784. }
  785. //参加活动
  786. dic["ActivityList"] = RelationClass.GetProfitObjectsActivesList(dic["ActivityList"].ToString());
  787. //绑定商户
  788. int BindMerchantId = int.Parse(function.CheckInt(dic["BindMerchantId"].ToString()));
  789. PosMerchantInfo bindmerchantid_MerchantInfo = db.PosMerchantInfo.FirstOrDefault(m => m.Id == BindMerchantId) ?? new PosMerchantInfo();
  790. dic["BindMerchantIdMerchantNo"] = bindmerchantid_MerchantInfo.MerchantNo;
  791. dic["BindMerchantIdMerchantName"] = bindmerchantid_MerchantInfo.MerchantName;
  792. dic.Remove("BindMerchantId");
  793. //机具类型
  794. int PosSnType = int.Parse(dic["PosSnType"].ToString());
  795. if (PosSnType == 0) dic["PosSnType"] = "购买机具";
  796. if (PosSnType == 1) dic["PosSnType"] = "赠送机具";
  797. //设备类型
  798. string DeviceType = dic["DeviceType"].ToString();
  799. if (DeviceType == "KysSignPos") dic["DeviceType"] = "快益刷电签POS";
  800. if (DeviceType == "KssSignPos") dic["DeviceType"] = "快闪刷电签POS";
  801. if (DeviceType == "") dic["DeviceType"] = "";
  802. //盟主信息
  803. int LeaderUserId = int.Parse(function.CheckInt(dic["LeaderUserId"].ToString()));
  804. if (LeaderUserId != 0)
  805. {
  806. Users users = db.Users.FirstOrDefault(m => m.Id == LeaderUserId) ?? new Users();
  807. dic["UserInfo"] = users.MakerCode + "_" + users.RealName;
  808. }
  809. //是否为第一台机具
  810. int IsFirst = int.Parse(dic["IsFirst"].ToString());
  811. if (IsFirst == 0) dic["IsFirst"] = "否";
  812. if (IsFirst == 1) dic["IsFirst"] = "是";
  813. //循环开始时间
  814. // if (!string.IsNullOrEmpty(dic["RecycEndDate"].ToString()))
  815. // {
  816. // // var RecycStartDate = Convert.ToDateTime(dic["RecycEndDate"].ToString()).AddDays(-360).ToString("yyyy-MM-dd HH:mm:ss");
  817. // // dic["RecycStartDate"] = RecycStartDate;
  818. // string PosSn = dic["PosSn"].ToString();
  819. // bool op = db.StoreChangeHistory.Any(m => m.SnNo == PosSn && m.TransType == 2);
  820. // if(op)
  821. // {
  822. // StoreChangeHistory item = db.StoreChangeHistory.FirstOrDefault(m => m.SnNo == PosSn && m.TransType == 2) ?? new StoreChangeHistory();
  823. // dic["RecycStartDate"] = item.ToDate == null ? "" : item.ToDate.Value.ToString("yyyy-MM-dd");
  824. // }
  825. // }
  826. //实际押金
  827. string SeoKeyword = dic["SeoKeyword"].ToString();
  828. if (SeoKeyword.Length > 2)
  829. {
  830. SeoKeyword = (decimal.Parse(SeoKeyword) / 100).ToString();
  831. }
  832. dic["SeoKeyword"] = SeoKeyword;
  833. //设置押金
  834. string PrizeParams = dic["PrizeParams"].ToString();
  835. dic["PrizeParams"] = PrizeParams;
  836. //所属运营中心
  837. int OpId = int.Parse(dic["OpId"].ToString());
  838. if (OpId != 0)
  839. {
  840. var sys = opdb.SysAdmin.FirstOrDefault(m => m.QueryCount > 0 && m.UserId == OpId) ?? new OpModels.SysAdmin();
  841. dic["OpCode"] = sys.OpCode;
  842. }
  843. }
  844. Dictionary<string, object> other = new Dictionary<string, object>();
  845. int TotalCount = 0;//总机具数
  846. DataTable dt = OtherMySqlConn.dtable("select count(0) from PosMachinesTwo where 1=1" + condition);
  847. if (dt.Rows.Count > 0)
  848. {
  849. TotalCount = int.Parse(function.CheckNum(dt.Rows[0][0].ToString()));
  850. }
  851. DataTable dts = OtherMySqlConn.dtable("select Id from PosMachinesTwo where 1=1" + condition);
  852. var Ids = "";
  853. foreach (DataRow item in dts.Rows)
  854. {
  855. Ids += item["Id"].ToString() + ",";
  856. }
  857. var Id = "," + Ids;
  858. var pos = db.PosMachinesTwo.Where(m => Id.Contains("," + m.Id + ",")).ToList();
  859. string[] strids = Ids.TrimEnd(',').Split(',');
  860. foreach (var items in strids)
  861. {
  862. int posId = int.Parse(items);
  863. var posInfo = pos.FirstOrDefault(m => m.Id == posId) ?? new PosMachinesTwo();
  864. decimal ScanQrTrade = decimal.Parse(posInfo.ScanQrTrade.ToString());
  865. var brandInfo = RelationClass.GetKqProductBrandInfo(int.Parse(posInfo.BrandId.ToString()));
  866. decimal amount = 0;
  867. if (brandInfo.Contains("电签"))
  868. {
  869. amount = 200;
  870. }
  871. if (brandInfo.Contains("大POS"))
  872. {
  873. amount = 300;
  874. }
  875. if (ScanQrTrade > 0 && ScanQrTrade < 999)
  876. {
  877. AmountYks += ScanQrTrade;
  878. AmountDks += amount - ScanQrTrade;
  879. }
  880. if (ScanQrTrade == 999)
  881. {
  882. AmountYks += amount;
  883. }
  884. }
  885. other.Add("TotalCount", TotalCount);
  886. other.Add("AmountYks", AmountYks);
  887. other.Add("AmountDks", AmountDks);
  888. obj.Add("other", other);
  889. return Json(obj);
  890. }
  891. #endregion
  892. }
  893. }