PosMachinesController.cs 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.AspNetCore.Http;
  6. using Microsoft.Extensions.Logging;
  7. using Microsoft.Extensions.Options;
  8. using Microsoft.AspNetCore.Authorization;
  9. using System.Web;
  10. using MySystem.Models.Main1;
  11. using LitJson;
  12. using Library;
  13. using MySystem.Service.Main;
  14. namespace MySystem.Areas.Api.Controllers.v1
  15. {
  16. [Area("Api")]
  17. [Route("Api/v1/[controller]/[action]")]
  18. public class PosMachinesController : BaseController
  19. {
  20. public PosMachinesController(IHttpContextAccessor accessor) : base(accessor)
  21. {
  22. }
  23. #region 商户-二维码关联音箱
  24. // [Authorize]
  25. public JsonResult List(string value)
  26. {
  27. value = DesDecrypt(value);
  28. value = value.Replace("null", "\"\"");
  29. JsonData data = JsonMapper.ToObject(value);
  30. List<Dictionary<string, object>> dataList = ListDo(value);
  31. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  32. }
  33. public List<Dictionary<string, object>> ListDo(string value)
  34. {
  35. JsonData data = JsonMapper.ToObject(value);
  36. int BindMerchantId = int.Parse(function.CheckInt(data["BindMerchantId"].ToString())); //绑定商户
  37. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  38. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  39. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  40. Models.Main.MerchantInfo merchant = MerchantInfoDbconn.Instance.Get(BindMerchantId) ?? new Models.Main.MerchantInfo();
  41. List<Dictionary<string, object>> query = PosMachinesService.List(new List<RelationData>(), " and BindMerchantId=" + BindMerchantId, PageNum, PageSize);
  42. foreach (var subdata in query)
  43. {
  44. Dictionary<string, object> curData = new Dictionary<string, object>();
  45. curData.Add("BindingTime", subdata["BindingTime"].ToString()); //绑定时间
  46. curData.Add("PosSn", subdata["PosSn"].ToString()); //SN编号
  47. curData.Add("Id", subdata["Id"].ToString()); //Id
  48. curData.Add("MerchantName", merchant.Name); //商户名称
  49. string CheckKey = "_" + subdata["Id"].ToString();
  50. int BindCount = MachineForQrCodeDbconn.Instance.GetList(BindMerchantId).Count(m => m.DataId.EndsWith(CheckKey));
  51. curData.Add("BindCount", BindCount); //关联数量
  52. dataList.Add(curData);
  53. }
  54. return dataList;
  55. }
  56. #endregion
  57. #region 商户-已绑音箱
  58. // [Authorize]
  59. public JsonResult BindedMachines(string value)
  60. {
  61. value = DesDecrypt(value);
  62. value = value.Replace("null", "\"\"");
  63. JsonData data = JsonMapper.ToObject(value);
  64. List<Dictionary<string, object>> dataList = BindedMachinesDo(value);
  65. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  66. }
  67. public List<Dictionary<string, object>> BindedMachinesDo(string value)
  68. {
  69. JsonData data = JsonMapper.ToObject(value);
  70. int BindMerchantId = int.Parse(function.CheckInt(data["BindMerchantId"].ToString())); //绑定商户
  71. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  72. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  73. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  74. Models.Main.MerchantInfo merchant = MerchantInfoDbconn.Instance.Get(BindMerchantId) ?? new Models.Main.MerchantInfo();
  75. List<int> query = PosMachinesDbconn.Instance.GetList(BindMerchantId, PageNum, PageSize);
  76. foreach (int MachineId in query)
  77. {
  78. PosMachines subdata = PosMachinesDbconn.Instance.Get(MachineId) ?? new PosMachines();
  79. Dictionary<string, object> curData = new Dictionary<string, object>();
  80. curData.Add("BindingTime", subdata.BindingTime == null ? "" : subdata.BindingTime.Value.ToString("yyyy-MM-dd")); //绑定时间
  81. curData.Add("PosSn", subdata.PosSn); //SN编号
  82. curData.Add("Id", subdata.Id); //Id
  83. curData.Add("MachineNo", subdata.Detail);
  84. curData.Add("MerchantName", merchant.Name); //商户名称
  85. string CheckKey = "_" + subdata.Id;
  86. List<Models.Main.MachineForQrCode> QrCodes = MachineForQrCodeDbconn.Instance.GetList(BindMerchantId);
  87. QrCodes = QrCodes.Where(m => m.DataId.EndsWith(CheckKey)).ToList();
  88. curData.Add("BindCount", QrCodes.Count); //关联数量
  89. List<Dictionary<string, object>> QrCodeList = new List<Dictionary<string, object>>();
  90. foreach (Models.Main.MachineForQrCode QrCode in QrCodes)
  91. {
  92. Dictionary<string, object> item = new Dictionary<string, object>();
  93. string DataId = QrCode.DataId;
  94. if (DataId.Contains("_"))
  95. {
  96. DataId = DataId.Split('_')[0];
  97. }
  98. item.Add("Id", DataId);
  99. item.Add("Type", 1);
  100. item.Add("BindDate", QrCode.BindDate == null ? "" : QrCode.BindDate.Value.ToString("yyyy-MM-dd"));
  101. item.Add("Sn", QrCode.SnNo);
  102. item.Add("MachineNo", QrCode.MachineSnNo);
  103. QrCodeList.Add(item);
  104. }
  105. curData.Add("QrCodeList", QrCodeList); //二维码列表
  106. dataList.Add(curData);
  107. }
  108. return dataList;
  109. }
  110. #endregion
  111. #region 商户-替换音箱码
  112. // [Authorize]
  113. public JsonResult ReplaceMachines(string value)
  114. {
  115. value = DesDecrypt(value);
  116. value = value.Replace("null", "\"\"");
  117. JsonData data = JsonMapper.ToObject(value);
  118. List<Dictionary<string, object>> dataList = ReplaceMachinesDo(value);
  119. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  120. }
  121. public List<Dictionary<string, object>> ReplaceMachinesDo(string value)
  122. {
  123. JsonData data = JsonMapper.ToObject(value);
  124. int BindMerchantId = int.Parse(function.CheckInt(data["BindMerchantId"].ToString())); //绑定商户
  125. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  126. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  127. string CheckKey = "_" + BindMerchantId;
  128. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  129. List<Dictionary<string, object>> query = MerchantQrCodeService.List(new List<RelationData>(), " and MerchantId=" + BindMerchantId, 1, 1000);
  130. foreach (Dictionary<string, object> subdata in query)
  131. {
  132. Dictionary<string, object> curData = new Dictionary<string, object>();
  133. curData.Add("BindingTime", subdata["UpdateDate"].ToString()); //绑定时间
  134. curData.Add("PosSn", subdata["SnNo"].ToString()); //SN编号
  135. curData.Add("Id", subdata["Id"].ToString()); //Id
  136. dataList.Add(curData);
  137. }
  138. return dataList;
  139. }
  140. #endregion
  141. #region 商户-确认关联音箱
  142. // [Authorize]
  143. public JsonResult Add(string value)
  144. {
  145. value = DesDecrypt(value);
  146. value = value.Replace("null", "\"\"");
  147. JsonData data = JsonMapper.ToObject(value);
  148. AppResultJson result = AddDo(value);
  149. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  150. }
  151. public AppResultJson AddDo(string value)
  152. {
  153. JsonData data = JsonMapper.ToObject(value);
  154. int BindMerchantId = int.Parse(function.CheckInt(data["BindMerchantId"].ToString())); //绑定商户
  155. // string QrCodeId = data["QrCodeId"].ToString(); //二维码Id
  156. int QrCodeId = int.Parse(function.CheckInt(data["QrCodeId"].ToString())); //二维码Id
  157. string MachineId = data["MachineId"].ToString(); //音箱Id
  158. Dictionary<string, object> Obj = new Dictionary<string, object>();
  159. Models.Main.MerchantQrCode qrcode = MerchantQrCodeService.Query(QrCodeId);
  160. PosMachines machine = PosMachinesDbconn.Instance.Get(MachineId) ?? new PosMachines();
  161. Models.Main.MachineForQrCode query = new Models.Main.MachineForQrCode()
  162. {
  163. DataId = QrCodeId + "_" + MachineId,
  164. MerchantId = BindMerchantId,
  165. BindDate = DateTime.Now,
  166. SnNo = qrcode.SnNo,
  167. MachineSnNo = machine.PosSn,
  168. };
  169. machine.BindingState = 1;
  170. qrcode.MachineId = int.Parse(MachineId);
  171. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  172. }
  173. #endregion
  174. #region 商户-绑定列表
  175. // [Authorize]
  176. public JsonResult BindList(string value)
  177. {
  178. value = DesDecrypt(value);
  179. value = value.Replace("null", "\"\"");
  180. JsonData data = JsonMapper.ToObject(value);
  181. List<Dictionary<string, object>> dataList = BindListDo(value);
  182. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  183. }
  184. public List<Dictionary<string, object>> BindListDo(string value)
  185. {
  186. JsonData data = JsonMapper.ToObject(value);
  187. int BindMerchantId = int.Parse(function.CheckInt(data["BindMerchantId"].ToString())); //绑定商户
  188. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  189. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  190. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  191. string condition = "";
  192. if (!string.IsNullOrEmpty(data["BindMerchantId"].ToString()))
  193. {
  194. condition += " and BindMerchantId=" + BindMerchantId;
  195. }
  196. List<Dictionary<string, object>> query = PosMachinesService.List(new List<RelationData>(), condition, PageNum, PageSize);
  197. foreach (var subdata in query)
  198. {
  199. Dictionary<string, object> curData = new Dictionary<string, object>();
  200. curData.Add("BindingTime", subdata["BindingTime"].ToString()); //绑定时间
  201. curData.Add("PosSn", subdata["PosSn"].ToString()); //SN编号
  202. curData.Add("MerchantName", ""); //商户名称
  203. curData.Add("MerchantLogo", ""); //商户Logo
  204. dataList.Add(curData);
  205. }
  206. return dataList;
  207. }
  208. #endregion
  209. #region 商户-绑定机具
  210. // [Authorize]
  211. public JsonResult Bind(string value)
  212. {
  213. value = DesDecrypt(value);
  214. value = value.Replace("null", "\"\"");
  215. JsonData data = JsonMapper.ToObject(value);
  216. AppResultJson result = BindDo(value);
  217. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  218. }
  219. public AppResultJson BindDo(string value)
  220. {
  221. JsonData data = JsonMapper.ToObject(value);
  222. string PosSn = data["PosSn"].ToString(); //SN编号
  223. int BindMerchantId = int.Parse(function.CheckInt(data["BindMerchantId"].ToString())); //绑定商户
  224. Models.Main.MerchantInfo merchant = MerchantInfoService.Query(BindMerchantId);
  225. Dictionary<string, object> Obj = new Dictionary<string, object>();
  226. PosMachines query = new PosMachines();
  227. query = new PosMachines()
  228. {
  229. CreateDate = DateTime.Now, //创建时间
  230. UpdateDate = DateTime.Now, //修改时间
  231. BuyUserId = merchant.UserId, //绑定所属创客Id
  232. UserId = merchant.UserId, //绑定所属创客Id
  233. PosSn = PosSn, //SN编号
  234. BindMerchantId = BindMerchantId, //绑定商户
  235. };
  236. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  237. }
  238. #endregion
  239. #region 商户-已绑音箱解除关联
  240. // [Authorize]
  241. public JsonResult Remove(string value)
  242. {
  243. value = DesDecrypt(value);
  244. value = value.Replace("null", "\"\"");
  245. JsonData data = JsonMapper.ToObject(value);
  246. AppResultJson result = RemoveDo(value);
  247. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  248. }
  249. public AppResultJson RemoveDo(string value)
  250. {
  251. JsonData data = JsonMapper.ToObject(value);
  252. int BindMerchantId = int.Parse(function.CheckInt(data["BindMerchantId"].ToString())); //绑定商户
  253. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  254. Dictionary<string, object> Obj = new Dictionary<string, object>();
  255. string CheckKey = "_" + Id;
  256. var list = main1db.MachineForQrCode.Select(m => new { m.MerchantId, m.DataId }).Where(m => m.MerchantId == BindMerchantId && m.DataId.EndsWith(CheckKey)).ToList();
  257. foreach (var sub in list)
  258. {
  259. Models.Main.MachineForQrCode edit = maindb.MachineForQrCode.FirstOrDefault(m => m.DataId == sub.DataId);
  260. if (edit != null)
  261. {
  262. maindb.MachineForQrCode.Remove(edit);
  263. int MachineId = int.Parse(function.CheckInt(edit.DataId.Split('_')[1]));
  264. PosMachines machine = main1db.PosMachines.FirstOrDefault(m => m.BindMerchantId == MachineId);
  265. if (machine != null)
  266. {
  267. machine.BindMerchantId = 0;
  268. machine.BuyUserId = 0;
  269. machine.UserId = 0;
  270. }
  271. }
  272. }
  273. main1db.SaveChanges();
  274. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  275. }
  276. #endregion
  277. #region 首页-客小爽产品-机具管理-已绑定机具列表
  278. // [Authorize]
  279. public JsonResult MyMachinesForBind(string value)
  280. {
  281. value = DesDecrypt(value);
  282. value = value.Replace("null", "\"\"");
  283. JsonData data = JsonMapper.ToObject(value);
  284. Dictionary<string, object> Other = new Dictionary<string, object>();
  285. List<Dictionary<string, object>> dataList = MyMachinesForBindDo(value, out Other);
  286. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Other });
  287. }
  288. public List<Dictionary<string, object>> MyMachinesForBindDo(string value, out Dictionary<string, object> Other)
  289. {
  290. JsonData data = JsonMapper.ToObject(value);
  291. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //所属创客
  292. int BrandId = int.Parse(function.CheckInt(data["BrandId"].ToString())); //产品类型
  293. string SnNo = data["SnNo"].ToString(); //SN号
  294. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  295. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  296. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  297. if (!string.IsNullOrEmpty(SnNo))
  298. {
  299. PageSize = 100000;
  300. }
  301. IQueryable<PosMachinesTwo> query = main1db.PosMachinesTwo.Where(m => m.Status > -1 && m.BuyUserId == UserId && m.BindingState == 1 && m.OpId == 2);
  302. if (!string.IsNullOrEmpty(SnNo))
  303. {
  304. query = query.Where(m => m.PosSn == SnNo);
  305. }
  306. Other = new Dictionary<string, object>();
  307. if (PageNum == 1)
  308. {
  309. Other.Add("count", query.Count());
  310. query = query.Take(PageSize);
  311. }
  312. else
  313. {
  314. int skipNum = PageSize * (PageNum - 1);
  315. query = query.Skip(skipNum).Take(PageSize);
  316. }
  317. foreach (var subdata in query.ToList())
  318. {
  319. Dictionary<string, object> curData = new Dictionary<string, object>();
  320. int IsLeader = 0;//是否为大盟主机(0-否 1-是)
  321. if (subdata.LeaderUserId > 0)
  322. {
  323. IsLeader = 1;
  324. }
  325. else
  326. {
  327. IsLeader = 0;
  328. }
  329. curData.Add("ActivationState", subdata.ActivationState == 1 ? "已激活" : "未激活"); //激活状态
  330. curData.Add("PosSn", subdata.PosSn); //SN编号
  331. curData.Add("PosSnType", RelationClass.GetPosSnTypeInfo(subdata.PosSnType)); //机具类型
  332. curData.Add("Id", subdata.Id); //Id
  333. decimal Deposit = 299;
  334. if (BrandId == 6)
  335. {
  336. Deposit = 249;
  337. }
  338. if (!string.IsNullOrEmpty(subdata.PrizeParams))
  339. {
  340. Deposit = decimal.Parse(function.CheckNum(subdata.PrizeParams));
  341. }
  342. curData.Add("Deposit", Deposit);
  343. Models.Main.MerchantAddInfo merchant = maindb.MerchantAddInfo.FirstOrDefault(m => m.Id == subdata.BindMerchantId) ?? new Models.Main.MerchantAddInfo();
  344. curData.Add("BindedMerchant", merchant.CertMerchantName);
  345. curData.Add("IsLeader", IsLeader);
  346. dataList.Add(curData);
  347. }
  348. return dataList;
  349. }
  350. #endregion
  351. #region 首页-客小爽产品-机具管理-总机具列表
  352. // [Authorize]
  353. public JsonResult MyMachines(string value)
  354. {
  355. value = DesDecrypt(value);
  356. value = value.Replace("null", "\"\"");
  357. JsonData data = JsonMapper.ToObject(value);
  358. Dictionary<string, object> Other = new Dictionary<string, object>();
  359. List<Dictionary<string, object>> dataList = MyMachinesDo(value, out Other);
  360. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Other });
  361. }
  362. public List<Dictionary<string, object>> MyMachinesDo(string value, out Dictionary<string, object> Other)
  363. {
  364. JsonData data = JsonMapper.ToObject(value);
  365. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //所属创客
  366. int BrandId = int.Parse(function.CheckInt(data["BrandId"].ToString())); //产品类型
  367. string SnNo = data["SnNo"].ToString(); //SN号
  368. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  369. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  370. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  371. if (!string.IsNullOrEmpty(SnNo))
  372. {
  373. PageSize = 100000;
  374. }
  375. IQueryable<PosMachinesTwo> query = main1db.PosMachinesTwo.Where(m => m.Status > -1 && m.BuyUserId == UserId && m.BrandId == BrandId);
  376. if (!string.IsNullOrEmpty(SnNo))
  377. {
  378. query = query.Where(m => m.PosSn == SnNo);
  379. }
  380. Other = new Dictionary<string, object>();
  381. if (PageNum == 1)
  382. {
  383. Other.Add("count", query.Count());
  384. query = query.Take(PageSize);
  385. }
  386. else
  387. {
  388. int skipNum = PageSize * (PageNum - 1);
  389. query = query.Skip(skipNum).Take(PageSize);
  390. }
  391. foreach (var subdata in query.ToList())
  392. {
  393. Dictionary<string, object> curData = new Dictionary<string, object>();
  394. int IsLeader = 0;//是否为大盟主机(0-否 1-是)
  395. if (subdata.LeaderUserId > 0)
  396. {
  397. IsLeader = 1;
  398. }
  399. else
  400. {
  401. IsLeader = 0;
  402. }
  403. curData.Add("PosSn", subdata.PosSn); //SN编号
  404. curData.Add("PosSnType", RelationClass.GetPosSnTypeInfo(subdata.PosSnType)); //机具类型
  405. curData.Add("Id", subdata.Id); //Id
  406. curData.Add("CreateDate", subdata.TransferTime == null ? "" : subdata.TransferTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); //CreateDate
  407. StoreHouse store = StoreHouseDbconn.Instance.Get(subdata.StoreId) ?? new StoreHouse();
  408. curData.Add("FromStore", store.StoreName); //来自仓库
  409. decimal Deposit = 299;
  410. if (BrandId == 6)
  411. {
  412. Deposit = 249;
  413. }
  414. if (!string.IsNullOrEmpty(subdata.PrizeParams))
  415. {
  416. Deposit = decimal.Parse(function.CheckNum(subdata.PrizeParams));
  417. }
  418. curData.Add("Deposit", Deposit);
  419. curData.Add("IsLeader", IsLeader);
  420. dataList.Add(curData);
  421. }
  422. return dataList;
  423. }
  424. #endregion
  425. #region 首页-客小爽产品-机具管理-未绑定机具列表
  426. // [Authorize]
  427. public JsonResult MyMachinesForUnBind(string value)
  428. {
  429. value = DesDecrypt(value);
  430. value = value.Replace("null", "\"\"");
  431. JsonData data = JsonMapper.ToObject(value);
  432. Dictionary<string, object> Other = new Dictionary<string, object>();
  433. List<Dictionary<string, object>> dataList = MyMachinesForUnBindDo(value, out Other);
  434. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Other });
  435. }
  436. public List<Dictionary<string, object>> MyMachinesForUnBindDo(string value, out Dictionary<string, object> Other)
  437. {
  438. JsonData data = JsonMapper.ToObject(value);
  439. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //所属创客
  440. int BrandId = int.Parse(function.CheckInt(data["BrandId"].ToString())); //产品类型
  441. string SnNo = data["SnNo"].ToString(); //SN号
  442. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  443. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  444. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  445. if (!string.IsNullOrEmpty(SnNo))
  446. {
  447. PageSize = 100000;
  448. }
  449. IQueryable<PosMachinesTwo> query = main1db.PosMachinesTwo.Where(m => m.Status > -1 && m.BuyUserId == UserId && m.BindingState == 0);
  450. if (!string.IsNullOrEmpty(SnNo))
  451. {
  452. query = query.Where(m => m.PosSn == SnNo && m.PosSnType == 0);
  453. }
  454. Other = new Dictionary<string, object>();
  455. if (PageNum == 1)
  456. {
  457. Other.Add("count", query.Count());
  458. query = query.Take(PageSize);
  459. }
  460. else
  461. {
  462. int skipNum = PageSize * (PageNum - 1);
  463. query = query.Skip(skipNum).Take(PageSize);
  464. }
  465. foreach (var subdata in query.ToList())
  466. {
  467. Dictionary<string, object> curData = new Dictionary<string, object>();
  468. int IsLeader = 0;//是否为大盟主机(0-否 1-是)
  469. if (subdata.LeaderUserId > 0)
  470. {
  471. IsLeader = 1;
  472. }
  473. else
  474. {
  475. IsLeader = 0;
  476. }
  477. curData.Add("PosSn", subdata.PosSn); //SN编号
  478. curData.Add("PosSnType", RelationClass.GetPosSnTypeInfo(subdata.PosSnType)); //机具类型
  479. curData.Add("Id", subdata.Id); //Id
  480. if (subdata.RecycEndDate != null)
  481. {
  482. TimeSpan ts = subdata.RecycEndDate.Value - DateTime.Now;
  483. curData.Add("ActDays", ts.TotalDays.ToString("f0")); //活动剩余天数
  484. }
  485. else
  486. {
  487. curData.Add("ActDays", 0); //活动剩余天数
  488. }
  489. curData.Add("CreateDate", subdata.CreateDate.Value.ToString("yyyy-MM-dd")); //机具初始日期
  490. curData.Add("EndDate", subdata.RecycEndDate == null ? "" : subdata.RecycEndDate.Value.ToString("yyyy-MM-dd")); //截止日期
  491. decimal Deposit = 299;
  492. if (BrandId == 6)
  493. {
  494. Deposit = 249;
  495. }
  496. if (!string.IsNullOrEmpty(subdata.PrizeParams))
  497. {
  498. Deposit = decimal.Parse(function.CheckNum(subdata.PrizeParams));
  499. }
  500. curData.Add("Deposit", Deposit);
  501. curData.Add("IsLeader", IsLeader);
  502. dataList.Add(curData);
  503. }
  504. return dataList;
  505. }
  506. #endregion
  507. #region 首页-客小爽产品-机具管理-已绑定机具列表
  508. // [Authorize]
  509. public JsonResult MyMachinesForBind2(string value)
  510. {
  511. value = DesDecrypt(value);
  512. value = value.Replace("null", "\"\"");
  513. JsonData data = JsonMapper.ToObject(value);
  514. Dictionary<string, object> Other = new Dictionary<string, object>();
  515. List<Dictionary<string, object>> dataList = MyMachinesForBind2Do(value, out Other);
  516. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Other });
  517. }
  518. public List<Dictionary<string, object>> MyMachinesForBind2Do(string value, out Dictionary<string, object> Other)
  519. {
  520. JsonData data = JsonMapper.ToObject(value);
  521. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //所属创客
  522. int BrandId = int.Parse(function.CheckInt(data["BrandId"].ToString())); //产品类型
  523. string SnNo = data["SnNo"].ToString(); //SN号
  524. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  525. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  526. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  527. if (!string.IsNullOrEmpty(SnNo))
  528. {
  529. PageSize = 100000;
  530. }
  531. IQueryable<PosMachines> query = main1db.PosMachines.Where(m => m.Status > -1 && m.BuyUserId == UserId && m.BindingState == 1 && m.DeviceKind == "2");
  532. if (!string.IsNullOrEmpty(SnNo))
  533. {
  534. query = query.Where(m => m.PosSn == SnNo);
  535. }
  536. Other = new Dictionary<string, object>();
  537. if (PageNum == 1)
  538. {
  539. Other.Add("count", query.Count());
  540. query = query.Take(PageSize);
  541. }
  542. else
  543. {
  544. int skipNum = PageSize * (PageNum - 1);
  545. query = query.Skip(skipNum).Take(PageSize);
  546. }
  547. foreach (var subdata in query.ToList())
  548. {
  549. Dictionary<string, object> curData = new Dictionary<string, object>();
  550. curData.Add("ActivationState", subdata.ActivationState == 1 ? "已激活" : "未激活"); //激活状态
  551. curData.Add("PosSn", subdata.PosSn); //SN编号
  552. curData.Add("PosSnType", RelationClass.GetPosSnTypeInfo(subdata.PosSnType)); //机具类型
  553. curData.Add("Id", subdata.Id); //Id
  554. decimal Deposit = 299;
  555. if (BrandId == 6)
  556. {
  557. Deposit = 249;
  558. }
  559. if (!string.IsNullOrEmpty(subdata.PrizeParams))
  560. {
  561. Deposit = decimal.Parse(function.CheckNum(subdata.PrizeParams));
  562. }
  563. curData.Add("Deposit", Deposit);
  564. var merchant = maindb.MerchantAddInfo.FirstOrDefault(m => m.Id == subdata.BindMerchantId) ?? new Models.Main.MerchantAddInfo();
  565. curData.Add("BindedMerchant", merchant.CertMerchantName);
  566. curData.Add("IsLeader", 0);
  567. dataList.Add(curData);
  568. }
  569. return dataList;
  570. }
  571. #endregion
  572. #region 首页-客小爽产品-机具管理-总机具列表
  573. // [Authorize]
  574. public JsonResult MyMachines2(string value)
  575. {
  576. value = DesDecrypt(value);
  577. value = value.Replace("null", "\"\"");
  578. JsonData data = JsonMapper.ToObject(value);
  579. Dictionary<string, object> Other = new Dictionary<string, object>();
  580. List<Dictionary<string, object>> dataList = MyMachines2Do(value, out Other);
  581. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Other });
  582. }
  583. public List<Dictionary<string, object>> MyMachines2Do(string value, out Dictionary<string, object> Other)
  584. {
  585. JsonData data = JsonMapper.ToObject(value);
  586. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //所属创客
  587. int BrandId = int.Parse(function.CheckInt(data["BrandId"].ToString())); //产品类型
  588. string SnNo = data["SnNo"].ToString(); //SN号
  589. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  590. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  591. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  592. if (!string.IsNullOrEmpty(SnNo))
  593. {
  594. PageSize = 100000;
  595. }
  596. IQueryable<PosMachines> query = main1db.PosMachines.Where(m => m.Status > -1 && m.BuyUserId == UserId && m.BrandId == BrandId);
  597. if (!string.IsNullOrEmpty(SnNo))
  598. {
  599. query = query.Where(m => m.PosSn == SnNo);
  600. }
  601. Other = new Dictionary<string, object>();
  602. if (PageNum == 1)
  603. {
  604. Other.Add("count", query.Count());
  605. query = query.Take(PageSize);
  606. }
  607. else
  608. {
  609. int skipNum = PageSize * (PageNum - 1);
  610. query = query.Skip(skipNum).Take(PageSize);
  611. }
  612. foreach (var subdata in query.ToList())
  613. {
  614. Dictionary<string, object> curData = new Dictionary<string, object>();
  615. int IsLeader = 0;//是否为大盟主机(0-否 1-是)
  616. curData.Add("PosSn", subdata.PosSn); //SN编号
  617. curData.Add("PosSnType", RelationClass.GetPosSnTypeInfo(subdata.PosSnType)); //机具类型
  618. curData.Add("Id", subdata.Id); //Id
  619. curData.Add("CreateDate", subdata.TransferTime == null ? "" : subdata.TransferTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); //CreateDate
  620. StoreHouse store = StoreHouseDbconn.Instance.Get(subdata.StoreId) ?? new StoreHouse();
  621. curData.Add("FromStore", store.StoreName); //来自仓库
  622. decimal Deposit = 299;
  623. if (BrandId == 6)
  624. {
  625. Deposit = 249;
  626. }
  627. if (!string.IsNullOrEmpty(subdata.PrizeParams))
  628. {
  629. Deposit = decimal.Parse(function.CheckNum(subdata.PrizeParams));
  630. }
  631. curData.Add("Deposit", Deposit);
  632. curData.Add("IsLeader", IsLeader);
  633. dataList.Add(curData);
  634. }
  635. return dataList;
  636. }
  637. #endregion
  638. #region 首页-客小爽产品-机具管理-未绑定机具列表
  639. // [Authorize]
  640. public JsonResult MyMachinesForUnBind2(string value)
  641. {
  642. value = DesDecrypt(value);
  643. value = value.Replace("null", "\"\"");
  644. JsonData data = JsonMapper.ToObject(value);
  645. Dictionary<string, object> Other = new Dictionary<string, object>();
  646. List<Dictionary<string, object>> dataList = MyMachinesForUnBind2Do(value, out Other);
  647. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Other });
  648. }
  649. public List<Dictionary<string, object>> MyMachinesForUnBind2Do(string value, out Dictionary<string, object> Other)
  650. {
  651. JsonData data = JsonMapper.ToObject(value);
  652. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //所属创客
  653. int BrandId = int.Parse(function.CheckInt(data["BrandId"].ToString())); //产品类型
  654. string SnNo = data["SnNo"].ToString(); //SN号
  655. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  656. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  657. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  658. if (!string.IsNullOrEmpty(SnNo))
  659. {
  660. PageSize = 100000;
  661. }
  662. IQueryable<PosMachines> query = main1db.PosMachines.Where(m => m.Status > -1 && m.BuyUserId == UserId && m.BindingState == 0);
  663. if (!string.IsNullOrEmpty(SnNo))
  664. {
  665. query = query.Where(m => m.PosSn == SnNo && m.PosSnType == 0);
  666. }
  667. Other = new Dictionary<string, object>();
  668. if (PageNum == 1)
  669. {
  670. Other.Add("count", query.Count());
  671. query = query.Take(PageSize);
  672. }
  673. else
  674. {
  675. int skipNum = PageSize * (PageNum - 1);
  676. query = query.Skip(skipNum).Take(PageSize);
  677. }
  678. foreach (var subdata in query.ToList())
  679. {
  680. Dictionary<string, object> curData = new Dictionary<string, object>();
  681. int IsLeader = 0;
  682. curData.Add("PosSn", subdata.PosSn); //SN编号
  683. curData.Add("PosSnType", RelationClass.GetPosSnTypeInfo(subdata.PosSnType)); //机具类型
  684. curData.Add("Id", subdata.Id); //Id
  685. if (subdata.RecycEndDate != null)
  686. {
  687. TimeSpan ts = subdata.RecycEndDate.Value - DateTime.Now;
  688. curData.Add("ActDays", ts.TotalDays.ToString("f0")); //活动剩余天数
  689. }
  690. else
  691. {
  692. curData.Add("ActDays", 0); //活动剩余天数
  693. }
  694. curData.Add("CreateDate", subdata.CreateDate.Value.ToString("yyyy-MM-dd")); //机具初始日期
  695. curData.Add("EndDate", subdata.RecycEndDate == null ? "" : subdata.RecycEndDate.Value.ToString("yyyy-MM-dd")); //截止日期
  696. decimal Deposit = 299;
  697. if (BrandId == 6)
  698. {
  699. Deposit = 249;
  700. }
  701. if (!string.IsNullOrEmpty(subdata.PrizeParams))
  702. {
  703. Deposit = decimal.Parse(function.CheckNum(subdata.PrizeParams));
  704. }
  705. curData.Add("Deposit", Deposit);
  706. curData.Add("IsLeader", IsLeader);
  707. dataList.Add(curData);
  708. }
  709. return dataList;
  710. }
  711. #endregion
  712. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  713. /// <summary>
  714. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  715. /// </summary>
  716. /// <param name="value">请求的参数(json字符串)</param>
  717. /// <param name="signField">要签名的字段</param>
  718. /// <returns></returns>
  719. private string CheckSign(string value, string[] signField)
  720. {
  721. JsonData json = JsonMapper.ToObject(value);
  722. Dictionary<string, string> dic = new Dictionary<string, string>();
  723. for (int i = 0; i < signField.Length; i++)
  724. {
  725. dic.Add(signField[i], json[signField[i]].ToString());
  726. }
  727. string sign = json["sign"].ToString(); //客户端签名字符串
  728. return new Sign().sign(dic, sign);
  729. }
  730. #endregion
  731. }
  732. }