PosMachinesTwoController.cs 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193
  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 > 3)
  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 导入金控入库时间数据
  527. /// <summary>
  528. /// 导入金控入库时间数据
  529. /// </summary>
  530. /// <param name="ImportCreateData"></param>
  531. public string ImportCreateData(string ExcelData)
  532. {
  533. ExcelData = HttpUtility.UrlDecode(ExcelData);
  534. JsonData list = JsonMapper.ToObject(ExcelData);
  535. string error = "";
  536. string info = "";
  537. var brandInfo = db.KqProducts.ToList();
  538. for (int i = 1; i < list.Count; i++)
  539. {
  540. JsonData dr = list[i];
  541. string itemJson = dr.ToJson();
  542. string PosSn = itemJson.Contains("\"A\"") ? dr["A"].ToString() : "";
  543. string CreateDate = itemJson.Contains("\"B\"") ? dr["B"].ToString() : "";
  544. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn) ?? new PosMachinesTwo();
  545. if (pos.Id > 0)
  546. {
  547. var brandName = brandInfo.FirstOrDefault(m => m.Id == pos.BrandId);
  548. if (brandName.Name.StartsWith("金控"))
  549. {
  550. info += "机具Sn:" + PosSn + "原入库时间:" + pos.CreateDate + "新入库时间:" + CreateDate;
  551. pos.CreateDate = DateTime.Parse(CreateDate);
  552. }
  553. else
  554. {
  555. error += "以下操作失败" + PosSn + ',' + "该机具号品牌不符合修改规则" + '\n';
  556. }
  557. }
  558. else
  559. {
  560. error += "以下操作失败" + PosSn + ',' + "该机具号不存在" + '\n';
  561. }
  562. }
  563. if (!string.IsNullOrEmpty(error))
  564. {
  565. return "Warning|" + error;
  566. }
  567. else
  568. {
  569. db.SaveChanges();
  570. string text = string.Format("导入金控入库时间数据: '" + info + "',操作人: '" + SysUserName + "_" + SysRealName + "',Time'" + DateTime.Now + "'");
  571. function.WriteLog(text, "导入金控入库时间数据");
  572. AddSysLog("0", "ImportCreateData", "Import");
  573. return "success";
  574. }
  575. }
  576. #endregion
  577. #region 导入数据
  578. public IActionResult Import(string right)
  579. {
  580. ViewBag.RightInfo = RightInfo;
  581. ViewBag.right = right;
  582. return View();
  583. }
  584. /// <summary>
  585. /// 导入数据
  586. /// </summary>
  587. /// <param name="ExcelData"></param>
  588. [HttpPost]
  589. public string ImportPost(string ExcelPath)
  590. {
  591. string key = function.MD5_16(Guid.NewGuid().ToString());
  592. RedisDbconn.Instance.AddList("ExcelImportV2", ExcelPath + "#cut#ImportJKCreateData#cut#" + key + "#cut#" + SysUserName);
  593. return "success|" + key;
  594. }
  595. public string CheckImport(string key)
  596. {
  597. string result = RedisDbconn.Instance.Get<string>("CheckImport:" + key);
  598. if (!string.IsNullOrEmpty(result))
  599. {
  600. string[] datalist = result.Split('|');
  601. if (datalist[0] == "success")
  602. {
  603. return result;
  604. }
  605. return datalist[0];
  606. }
  607. return "0";
  608. }
  609. public Dictionary<string, object> CheckImportV2(string key)
  610. {
  611. Dictionary<string, object> Obj = new Dictionary<string, object>();
  612. string result = RedisDbconn.Instance.Get<string>("CheckImport:" + key);
  613. if (!string.IsNullOrEmpty(result))
  614. {
  615. string[] datalist = result.Split('|');
  616. if (datalist[0] == "success")
  617. {
  618. List<string> errList = RedisDbconn.Instance.GetList<string>("ErrList" + key);
  619. if (errList.Count > 0)
  620. {
  621. Obj.Add("status", 2);
  622. Obj.Add("errList", errList);
  623. }
  624. else
  625. {
  626. Obj.Add("status", 1);
  627. Obj.Add("data", result);
  628. }
  629. return Obj;
  630. }
  631. Obj.Add("status", 0);
  632. Obj.Add("data", datalist[0]);
  633. return Obj;
  634. }
  635. Obj.Add("status", -1);
  636. Obj.Add("data", "执行中...");
  637. return Obj;
  638. }
  639. #endregion
  640. #region 导出Excel
  641. /// <summary>
  642. /// 导出Excel
  643. /// </summary>
  644. /// <returns></returns>
  645. public JsonResult ExportExcel(PosMachinesTwo data, string BindingStateSelect, string ActivationStateSelect, string UserIdMakerCode, string UserIdRealName, string StoreIdCode, string StoreIdName, string BrandId, string ActivationDateData, string BindingDateData, string IsStoreSelect, string OpCode)
  646. {
  647. Dictionary<string, string> Fields = new Dictionary<string, string>();
  648. Fields.Add("PosSn", "1"); //SN编号
  649. Fields.Add("BrandId", "0"); //品牌
  650. string condition = " and Status>-1";
  651. //是否仓库机
  652. if (!string.IsNullOrEmpty(IsStoreSelect))
  653. {
  654. if (int.Parse(IsStoreSelect) > 0)
  655. {
  656. condition += " and UserId=0 and BuyUserId=0";
  657. }
  658. }
  659. //绑定状态
  660. if (!string.IsNullOrEmpty(BindingStateSelect))
  661. {
  662. condition += " and BindingState=" + BindingStateSelect;
  663. }
  664. //激活状态
  665. if (!string.IsNullOrEmpty(ActivationStateSelect))
  666. {
  667. condition += " and ActivationState=" + ActivationStateSelect;
  668. }
  669. //所属创客编号
  670. if (!string.IsNullOrEmpty(UserIdMakerCode))
  671. {
  672. condition += " and BuyUserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  673. }
  674. //所属创客真实姓名
  675. if (!string.IsNullOrEmpty(UserIdRealName))
  676. {
  677. condition += " and BuyUserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  678. }
  679. //所属仓库编号
  680. if (!string.IsNullOrEmpty(StoreIdCode))
  681. {
  682. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreIdCode + "')";
  683. }
  684. //所属仓库名称
  685. if (!string.IsNullOrEmpty(StoreIdName))
  686. {
  687. condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreIdName + "')";
  688. }
  689. //运营中心编号
  690. if (!string.IsNullOrEmpty(OpCode))
  691. {
  692. var sysUser = opdb.SysAdmin.FirstOrDefault(m => m.OpCode == OpCode) ?? new OpModels.SysAdmin();
  693. if (sysUser.Id > 0)
  694. {
  695. condition += " and OpId=" + sysUser.UserId;
  696. }
  697. }
  698. //品牌
  699. if (!string.IsNullOrEmpty(BrandId))
  700. {
  701. condition += " and BrandId =" + BrandId;
  702. }
  703. if (!string.IsNullOrEmpty(ActivationDateData))
  704. {
  705. string[] datelist = ActivationDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  706. string start = datelist[0];
  707. string end = datelist[1];
  708. condition += " and ActivationTime>='" + start + " 00:00:00' and ActivationTime<='" + end + " 23:59:59'";
  709. }
  710. if (!string.IsNullOrEmpty(BindingDateData))
  711. {
  712. string[] datelist = BindingDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  713. string start = datelist[0];
  714. string end = datelist[1];
  715. condition += " and BindingTime>='" + start + " 00:00:00' and BindingTime<='" + end + " 23:59:59'";
  716. }
  717. // //绑定状态
  718. // if (!string.IsNullOrEmpty(BindingStateSelect))
  719. // {
  720. // condition += " and BindingState=" + BindingStateSelect;
  721. // }
  722. // //激活状态
  723. // if (!string.IsNullOrEmpty(ActivationStateSelect))
  724. // {
  725. // condition += " and ActivationState=" + ActivationStateSelect;
  726. // }
  727. // //所属创客编号
  728. // if (!string.IsNullOrEmpty(UserIdMakerCode))
  729. // {
  730. // condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  731. // }
  732. // //所属创客真实姓名
  733. // if (!string.IsNullOrEmpty(UserIdRealName))
  734. // {
  735. // condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  736. // }
  737. // //所属仓库编号
  738. // if (!string.IsNullOrEmpty(StoreIdCode))
  739. // {
  740. // condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreIdCode + "')";
  741. // }
  742. // //所属仓库名称
  743. // if (!string.IsNullOrEmpty(StoreIdName))
  744. // {
  745. // condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreIdName + "')";
  746. // }
  747. 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,OpId", false);
  748. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  749. foreach (Dictionary<string, object> dic in diclist)
  750. {
  751. //绑定状态
  752. int BindingState = int.Parse(dic["BindingState"].ToString());
  753. if (BindingState == 0) dic["BindingState"] = "未绑定";
  754. if (BindingState == 1) dic["BindingState"] = "已绑定";
  755. //绑定时间
  756. if (!string.IsNullOrEmpty(dic["BindingTime"].ToString()))
  757. {
  758. DateTime BindingTime = Convert.ToDateTime(dic["BindingTime"].ToString());
  759. }
  760. //激活状态
  761. int ActivationState = int.Parse(dic["ActivationState"].ToString());
  762. if (ActivationState == 0) dic["ActivationState"] = "未激活";
  763. if (ActivationState == 1) dic["ActivationState"] = "已激活";
  764. //激活时间
  765. if (!string.IsNullOrEmpty(dic["ActivationTime"].ToString()))
  766. {
  767. DateTime ActivationTime = Convert.ToDateTime(dic["ActivationTime"].ToString());
  768. }
  769. //划拨时间
  770. if (!string.IsNullOrEmpty(dic["TransferTime"].ToString()))
  771. {
  772. DateTime TransferTime = Convert.ToDateTime(dic["TransferTime"].ToString());
  773. }
  774. //所属创客
  775. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  776. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  777. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  778. dic["UserIdRealName"] = userid_Users.RealName;
  779. dic.Remove("UserId");
  780. //所属仓库
  781. int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString()));
  782. StoreHouse storeid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  783. dic["StoreIdCode"] = storeid_StoreHouse.StoreNo;
  784. dic["StoreIdName"] = storeid_StoreHouse.StoreName;
  785. dic.Remove("StoreId");
  786. //产品类型
  787. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  788. //参加活动
  789. // dic["ActivityList"] = RelationClass.GetProfitObjectsActivesList(dic["ActivityList"].ToString());
  790. //绑定商户
  791. int BindMerchantId = int.Parse(function.CheckInt(dic["BindMerchantId"].ToString()));
  792. PosMerchantInfo bindmerchantid_MerchantInfo = db.PosMerchantInfo.FirstOrDefault(m => m.Id == BindMerchantId) ?? new PosMerchantInfo();
  793. dic["BindMerchantIdMerchantNo"] = bindmerchantid_MerchantInfo.MerchantNo;
  794. dic["BindMerchantIdMerchantName"] = bindmerchantid_MerchantInfo.MerchantName;
  795. dic.Remove("BindMerchantId");
  796. //机具类型
  797. int PosSnType = int.Parse(dic["PosSnType"].ToString());
  798. if (PosSnType == 0) dic["PosSnType"] = "兑换机具";
  799. if (PosSnType == 1) dic["PosSnType"] = "循环机具";
  800. //所属运营中心
  801. int OpId = int.Parse(dic["OpId"].ToString());
  802. if (OpId != 0)
  803. {
  804. var sys = opdb.SysAdmin.FirstOrDefault(m => m.QueryCount > 0 && m.UserId == OpId) ?? new OpModels.SysAdmin();
  805. dic["OpCode"] = sys.OpCode;
  806. }
  807. // //设备类型
  808. // string DeviceType = dic["DeviceType"].ToString();
  809. // if (DeviceType == "KysSignPos") dic["DeviceType"] = "快益刷电签POS";
  810. // if (DeviceType == "KssSignPos") dic["DeviceType"] = "快闪刷电签POS";
  811. // if (DeviceType == "") dic["DeviceType"] = "";
  812. }
  813. Dictionary<string, object> result = new Dictionary<string, object>();
  814. result.Add("Status", "1");
  815. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  816. result.Add("Obj", diclist);
  817. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  818. ReturnFields.Add("UserIdMakerCode", "创客编号");
  819. ReturnFields.Add("UserIdRealName", "创客姓名");
  820. ReturnFields.Add("StoreIdCode", "仓库编号");
  821. ReturnFields.Add("StoreIdName", "仓库名称");
  822. ReturnFields.Add("BrandId", "产品类型");
  823. ReturnFields.Add("PosSn", "SN编号");
  824. ReturnFields.Add("PosSnType", "SN类型");
  825. // ReturnFields.Add("ActivityList", "参加活动");
  826. ReturnFields.Add("BindMerchantIdMerchantNo", "绑定商户编号");
  827. ReturnFields.Add("BindMerchantIdMerchantName", "绑定商户姓名");
  828. ReturnFields.Add("DeviceType", "设备类型");
  829. ReturnFields.Add("BindingState", "绑定状态");
  830. ReturnFields.Add("BindingTime", "绑定时间");
  831. ReturnFields.Add("ActivationState", "激活状态");
  832. ReturnFields.Add("ActivationTime", "激活时间");
  833. ReturnFields.Add("TransferTime", "划拨时间");
  834. ReturnFields.Add("OpCode", "所属运营中心");
  835. result.Add("Fields", ReturnFields);
  836. AddSysLog("0", "PosMachinesTwo", "ExportExcel");
  837. return Json(result);
  838. }
  839. #endregion
  840. #region 过期机具扣费列表
  841. /// <summary>
  842. /// 根据条件查询过期机具扣费列表
  843. /// </summary>
  844. /// <returns></returns>
  845. public IActionResult Indexs(PosMachinesTwo data, string right)
  846. {
  847. ViewBag.RightInfo = RightInfo;
  848. ViewBag.right = right;
  849. return View();
  850. }
  851. #endregion
  852. #region 根据条件查询过期机具扣费列表
  853. /// <summary>
  854. /// 过期机具扣费列表
  855. /// </summary>
  856. /// <returns></returns>
  857. 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)
  858. {
  859. Dictionary<string, string> Fields = new Dictionary<string, string>();
  860. if (ShowFlag == 0)
  861. {
  862. Dictionary<string, object> objs = new Dictionary<string, object>();
  863. Dictionary<string, object> others = new Dictionary<string, object>();
  864. others.Add("TotalCount", 0);
  865. others.Add("AmountYks", 0);
  866. others.Add("AmountDks", 0);
  867. objs.Add("other", others);
  868. return Json(objs);
  869. }
  870. decimal AmountYks = 0;//已扣
  871. decimal AmountDks = 0;//待扣
  872. var time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  873. string condition = " and Status>-1 and RecycEndDate<'" + time + "' and ScanQrTrade>0 and ScanQrTrade<999 and BindingState=0";
  874. //所属创客编号
  875. if (!string.IsNullOrEmpty(UserIdMakerCode))
  876. {
  877. condition += " and BuyUserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  878. }
  879. //仓库所属创客编号
  880. if (!string.IsNullOrEmpty(StoreMakerCode))
  881. {
  882. var userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == StoreMakerCode) ?? new UserForMakerCode();
  883. var user = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new Users();
  884. var store = db.StoreHouse.Where(m => m.UserId == user.Id && m.Status > -1).ToList();
  885. var storeIds = "";
  886. foreach (var item in store)
  887. {
  888. storeIds += item.Id + ",";
  889. }
  890. storeIds = storeIds.TrimEnd(',');
  891. condition += " and StoreId in (" + storeIds + ")";
  892. }
  893. //品牌
  894. if (!string.IsNullOrEmpty(BrandId))
  895. {
  896. condition += " and BrandId =" + BrandId;
  897. }
  898. if (!string.IsNullOrEmpty(PosSn))
  899. {
  900. condition += " and PosSn =" + PosSn + "";
  901. }
  902. // if (!string.IsNullOrEmpty(AmountYk))
  903. // {
  904. // condition += " and BrandId =" + BrandId;
  905. // }
  906. // if (!string.IsNullOrEmpty(Amountk))
  907. // {
  908. // condition += " and BrandId =" + BrandId;
  909. // }
  910. // if (!string.IsNullOrEmpty(AmountDk))
  911. // {
  912. // condition += " and BrandId =" + BrandId;
  913. // }
  914. if (!string.IsNullOrEmpty(RecycEndDateData))
  915. {
  916. string[] datelist = RecycEndDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  917. string start = datelist[0];
  918. string end = datelist[1];
  919. condition += " and RecycEndDate>='" + start + " 00:00:00' and RecycEndDate<='" + end + " 23:59:59'";
  920. }
  921. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("PosMachinesTwo", Fields, "Id desc", "0", page, limit, condition);
  922. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  923. foreach (Dictionary<string, object> dic in diclist)
  924. {
  925. //绑定状态
  926. int BindingState = int.Parse(dic["BindingState"].ToString());
  927. if (BindingState == 0) dic["BindingState"] = "未绑定";
  928. if (BindingState == 1) dic["BindingState"] = "已绑定";
  929. //激活状态
  930. int ActivationState = int.Parse(dic["ActivationState"].ToString());
  931. if (ActivationState == 0) dic["ActivationState"] = "未激活";
  932. if (ActivationState == 1) dic["ActivationState"] = "已激活";
  933. //所属创客
  934. int BuyUserId = int.Parse(function.CheckInt(dic["BuyUserId"].ToString()));
  935. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == BuyUserId) ?? new Users();
  936. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  937. dic["UserIdRealName"] = userid_Users.RealName;
  938. dic.Remove("BuyUserId");
  939. //所属仓库
  940. int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString()));
  941. StoreHouse storeid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  942. dic["StoreIdCode"] = storeid_StoreHouse.StoreNo;
  943. dic["StoreIdName"] = storeid_StoreHouse.StoreName;
  944. dic.Remove("StoreId");
  945. //产品类型
  946. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  947. decimal ScanQrTrade = decimal.Parse(dic["ScanQrTrade"].ToString());
  948. var brandInfo = dic["BrandId"].ToString();
  949. decimal amount = 0;
  950. if (brandInfo.Contains("电签"))
  951. {
  952. amount = 200;
  953. }
  954. if (brandInfo.Contains("大POS"))
  955. {
  956. amount = 300;
  957. }
  958. if (ScanQrTrade > 0 && ScanQrTrade < 999)
  959. {
  960. dic["AmountYk"] = amount;
  961. dic["Amountk"] = ScanQrTrade;
  962. dic["AmountDk"] = amount - ScanQrTrade;
  963. // AmountYks += ScanQrTrade;
  964. // AmountDks += amount - ScanQrTrade;
  965. }
  966. if (ScanQrTrade == 999)
  967. {
  968. dic["AmountYk"] = amount;
  969. dic["Amountk"] = amount;
  970. dic["AmountDk"] = 0;
  971. // AmountYks += amount;
  972. }
  973. //参加活动
  974. dic["ActivityList"] = RelationClass.GetProfitObjectsActivesList(dic["ActivityList"].ToString());
  975. //绑定商户
  976. int BindMerchantId = int.Parse(function.CheckInt(dic["BindMerchantId"].ToString()));
  977. PosMerchantInfo bindmerchantid_MerchantInfo = db.PosMerchantInfo.FirstOrDefault(m => m.Id == BindMerchantId) ?? new PosMerchantInfo();
  978. dic["BindMerchantIdMerchantNo"] = bindmerchantid_MerchantInfo.MerchantNo;
  979. dic["BindMerchantIdMerchantName"] = bindmerchantid_MerchantInfo.MerchantName;
  980. dic.Remove("BindMerchantId");
  981. //机具类型
  982. int PosSnType = int.Parse(dic["PosSnType"].ToString());
  983. if (PosSnType == 0) dic["PosSnType"] = "兑换机具";
  984. if (PosSnType == 1) dic["PosSnType"] = "循环机具";
  985. //设备类型
  986. string DeviceType = dic["DeviceType"].ToString();
  987. if (DeviceType == "KysSignPos") dic["DeviceType"] = "快益刷电签POS";
  988. if (DeviceType == "KssSignPos") dic["DeviceType"] = "快闪刷电签POS";
  989. if (DeviceType == "") dic["DeviceType"] = "";
  990. //盟主信息
  991. int LeaderUserId = int.Parse(function.CheckInt(dic["LeaderUserId"].ToString()));
  992. if (LeaderUserId != 0)
  993. {
  994. Users users = db.Users.FirstOrDefault(m => m.Id == LeaderUserId) ?? new Users();
  995. dic["UserInfo"] = users.MakerCode + "_" + users.RealName;
  996. }
  997. //是否为第一台机具
  998. int IsFirst = int.Parse(dic["IsFirst"].ToString());
  999. if (IsFirst == 0) dic["IsFirst"] = "否";
  1000. if (IsFirst == 1) dic["IsFirst"] = "是";
  1001. //循环开始时间
  1002. // if (!string.IsNullOrEmpty(dic["RecycEndDate"].ToString()))
  1003. // {
  1004. // // var RecycStartDate = Convert.ToDateTime(dic["RecycEndDate"].ToString()).AddDays(-360).ToString("yyyy-MM-dd HH:mm:ss");
  1005. // // dic["RecycStartDate"] = RecycStartDate;
  1006. // string PosSn = dic["PosSn"].ToString();
  1007. // bool op = db.StoreChangeHistory.Any(m => m.SnNo == PosSn && m.TransType == 2);
  1008. // if(op)
  1009. // {
  1010. // StoreChangeHistory item = db.StoreChangeHistory.FirstOrDefault(m => m.SnNo == PosSn && m.TransType == 2) ?? new StoreChangeHistory();
  1011. // dic["RecycStartDate"] = item.ToDate == null ? "" : item.ToDate.Value.ToString("yyyy-MM-dd");
  1012. // }
  1013. // }
  1014. //实际押金
  1015. string SeoKeyword = dic["SeoKeyword"].ToString();
  1016. if (SeoKeyword.Length > 2)
  1017. {
  1018. SeoKeyword = (decimal.Parse(SeoKeyword) / 100).ToString();
  1019. }
  1020. dic["SeoKeyword"] = SeoKeyword;
  1021. //设置押金
  1022. string PrizeParams = dic["PrizeParams"].ToString();
  1023. dic["PrizeParams"] = PrizeParams;
  1024. //所属运营中心
  1025. int OpId = int.Parse(dic["OpId"].ToString());
  1026. if (OpId != 0)
  1027. {
  1028. var sys = opdb.SysAdmin.FirstOrDefault(m => m.QueryCount > 0 && m.UserId == OpId) ?? new OpModels.SysAdmin();
  1029. dic["OpCode"] = sys.OpCode;
  1030. }
  1031. }
  1032. Dictionary<string, object> other = new Dictionary<string, object>();
  1033. int TotalCount = 0;//总机具数
  1034. DataTable dt = OtherMySqlConn.dtable("select count(0) from PosMachinesTwo where 1=1" + condition);
  1035. if (dt.Rows.Count > 0)
  1036. {
  1037. TotalCount = int.Parse(function.CheckNum(dt.Rows[0][0].ToString()));
  1038. }
  1039. DataTable dts = OtherMySqlConn.dtable("select Id from PosMachinesTwo where 1=1" + condition);
  1040. var Ids = "";
  1041. foreach (DataRow item in dts.Rows)
  1042. {
  1043. Ids += item["Id"].ToString() + ",";
  1044. }
  1045. var Id = "," + Ids;
  1046. var pos = db.PosMachinesTwo.Where(m => Id.Contains("," + m.Id + ",")).ToList();
  1047. string[] strids = Ids.TrimEnd(',').Split(',');
  1048. foreach (var items in strids)
  1049. {
  1050. int posId = int.Parse(items);
  1051. var posInfo = pos.FirstOrDefault(m => m.Id == posId) ?? new PosMachinesTwo();
  1052. decimal ScanQrTrade = decimal.Parse(posInfo.ScanQrTrade.ToString());
  1053. var brandInfo = RelationClass.GetKqProductBrandInfo(int.Parse(posInfo.BrandId.ToString()));
  1054. decimal amount = 0;
  1055. if (brandInfo.Contains("电签"))
  1056. {
  1057. amount = 200;
  1058. }
  1059. if (brandInfo.Contains("大POS"))
  1060. {
  1061. amount = 300;
  1062. }
  1063. if (ScanQrTrade > 0 && ScanQrTrade < 999)
  1064. {
  1065. AmountYks += ScanQrTrade;
  1066. AmountDks += amount - ScanQrTrade;
  1067. }
  1068. if (ScanQrTrade == 999)
  1069. {
  1070. AmountYks += amount;
  1071. }
  1072. }
  1073. other.Add("TotalCount", TotalCount);
  1074. other.Add("AmountYks", AmountYks);
  1075. other.Add("AmountDks", AmountDks);
  1076. obj.Add("other", other);
  1077. return Json(obj);
  1078. }
  1079. #endregion
  1080. }
  1081. }