PosMachinesController.cs 29 KB

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