PosMerchantInfoController.cs 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875
  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. using System.Text.RegularExpressions;
  14. namespace MySystem.Areas.Api.Controllers.v1.pos
  15. {
  16. [Area("Api")]
  17. [Route("Api/v1/pos/[controller]/[action]")]
  18. public class PosMerchantInfoController : BaseController
  19. {
  20. public PosMerchantInfoController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  21. {
  22. }
  23. #region 创客-首页-我的商户-商户资料完善
  24. [Authorize]
  25. public JsonResult EditInfo(string value)
  26. {
  27. value = DesDecrypt(value);
  28. JsonData data = JsonMapper.ToObject(value);
  29. AppResultJson result = EditInfoDo(value);
  30. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  31. }
  32. public AppResultJson EditInfoDo(string value)
  33. {
  34. JsonData data = JsonMapper.ToObject(value);
  35. string MerchantMobile = data["MerchantMobile"].ToString(); //商户手机号
  36. string MerRealName = data["MerRealName"].ToString(); //商户真实姓名
  37. string MerIdcardNo = data["MerIdcardNo"].ToString(); //商户身份证号
  38. bool check = maindb.PosMerchantInfo.Any(m => m.MerIdcardNo == MerIdcardNo);
  39. if (check)
  40. {
  41. return new AppResultJson() { Status = "-1", Info = "资料已提交,请勿重复操作" };
  42. }
  43. Dictionary<string, object> Obj = new Dictionary<string, object>();
  44. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  45. PosMerchantInfo query = maindb.PosMerchantInfo.FirstOrDefault(m => m.Id == Id);
  46. if (query != null)
  47. {
  48. string checkMobile = MerchantMobile.Substring(0, 3) + "****" + MerchantMobile.Substring(7);
  49. if (checkMobile != query.MerchantMobile)
  50. {
  51. return new AppResultJson() { Status = "-1", Info = "手机号不正确,请核实后重试", Data = Obj };
  52. }
  53. query.MerchantMobile = MerchantMobile; //商户手机号
  54. query.MerRealName = MerRealName; //商户真实姓名
  55. query.MerIdcardNo = MerIdcardNo; //商户身份证号
  56. query.SeoTitle = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  57. maindb.PosMerchantOtherInfo.Add(new PosMerchantOtherInfo()
  58. {
  59. CertId = MerIdcardNo,
  60. MerchantId = query.Id,
  61. RealName = MerRealName,
  62. MerNo = query.MerchantNo,
  63. BrandId = query.BrandId,
  64. });
  65. maindb.SaveChanges();
  66. }
  67. Obj.Add("Id", query.Id); //Id
  68. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  69. }
  70. #endregion
  71. #region 通用-通过商户编号查询商户信息
  72. [Authorize]
  73. public JsonResult QueryMerchantInfo(string value)
  74. {
  75. value = DesDecrypt(value);
  76. JsonData data = JsonMapper.ToObject(value);
  77. Dictionary<string, object> Obj = QueryMerchantInfoDo(value);
  78. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  79. }
  80. public Dictionary<string, object> QueryMerchantInfoDo(string value)
  81. {
  82. JsonData data = JsonMapper.ToObject(value);
  83. string MerchantNo = data["MerchantNo"].ToString(); //商户编号
  84. Dictionary<string, object> Obj = new Dictionary<string, object>();
  85. PosMerchantInfo merchant = maindb.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerchantNo) ?? new PosMerchantInfo();
  86. bool checkPos = maindb.PosMachinesTwo.Any(m => m.Status > -1 && m.BindMerchantId == merchant.Id);
  87. PosMachinesTwo pos = new PosMachinesTwo();
  88. if (checkPos)
  89. {
  90. pos = maindb.PosMachinesTwo.Where(m => m.Status > -1 && m.BindMerchantId == merchant.Id).OrderByDescending(m => m.SeoKeyword).FirstOrDefault() ?? new PosMachinesTwo();
  91. }
  92. Obj.Add("userName", merchant.MerRealName); //商户名称
  93. Obj.Add("tel", merchant.MerchantMobile); //商户手机号
  94. // Obj.Add("SN", ""); //机具SN号
  95. Obj.Add("type", RelationClass.GetKqProductBrandInfo(merchant.BrandId)); //品牌名称
  96. if (pos.ActivationState == 1)
  97. {
  98. Obj.Add("createTime", pos.ActivationTime == null ? "" : pos.ActivationTime.Value.ToString("yyyy-MM-dd")); //创建时间
  99. }
  100. else
  101. {
  102. Obj.Add("createTime", "未激活");
  103. }
  104. Obj.Add("totalTurnover", pos.CreditTrade.ToString("f2")); //累计交易额
  105. Obj.Add("mounthTurnover", PosMerchantTradeSummaryDbconn.Instance.GetDateTimeTrade(merchant.Id, DateTime.Now.ToString("yyyyMM"))); //本月交易额
  106. decimal deposit = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  107. if (pos.BrandId != 2 && pos.BrandId != 7)
  108. {
  109. deposit = deposit / 100;
  110. }
  111. Obj.Add("deposit", deposit.ToString("f2")); //押金金额
  112. Obj.Add("policy", "押99返100,押199返200,押299返300"); //返押政策
  113. bool status = maindb.ActiveReward.Any(m => m.KqSnNo == pos.PosSn);
  114. Obj.Add("status", status ? "未返" : "已返"); //返押金状态
  115. if (status)
  116. {
  117. Obj.Add("reason", ""); //返回失败原因
  118. }
  119. else
  120. {
  121. string reason = "";
  122. if (string.IsNullOrEmpty(pos.SeoKeyword))
  123. {
  124. reason = "处理中";
  125. }
  126. else if (pos.CreditTrade < 1000)
  127. {
  128. reason = "贷记卡交易未满1000";
  129. }
  130. Obj.Add("reason", reason);
  131. }
  132. return Obj;
  133. }
  134. #endregion
  135. #region 通用-通过商户编号查询商户信息-2
  136. [Authorize]
  137. public JsonResult QueryMerchantInfo2(string value)
  138. {
  139. value = DesDecrypt(value);
  140. JsonData data = JsonMapper.ToObject(value);
  141. Dictionary<string, object> Obj = QueryMerchantInfo2Do(value);
  142. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  143. }
  144. public Dictionary<string, object> QueryMerchantInfo2Do(string value)
  145. {
  146. JsonData data = JsonMapper.ToObject(value);
  147. string MerchantNo = data["MerchantNo"].ToString(); //商户编号
  148. string MerchantName = data["MerchantName"].ToString(); //商户名称
  149. string MerchantMobile = data["MerchantMobile"].ToString(); //商户手机号
  150. string MerchantCertId = data["MerchantCertId"].ToString(); //商户身份证号
  151. Dictionary<string, object> Obj = new Dictionary<string, object>();
  152. PosMerchantInfo merchant = maindb.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerchantNo);
  153. if (merchant == null)
  154. {
  155. return Obj;
  156. }
  157. bool CheckCertId = maindb.PosMerchantOtherInfo.Any(m => m.CertId == MerchantCertId);
  158. if (function.CheckNull(merchant.MerchantMobile).Contains("****") && !CheckCertId)
  159. {
  160. merchant.MerRealName = MerchantName;
  161. merchant.MerchantMobile = MerchantMobile;
  162. merchant.MerIdcardNo = MerchantCertId;
  163. PosMerchantOtherInfo other = maindb.PosMerchantOtherInfo.FirstOrDefault(m => m.CertId == MerchantCertId);
  164. if (other == null)
  165. {
  166. maindb.PosMerchantOtherInfo.Add(new PosMerchantOtherInfo()
  167. {
  168. CertId = MerchantCertId,
  169. MerchantId = merchant.Id,
  170. RealName = MerchantName,
  171. MerNo = MerchantNo,
  172. BrandId = merchant.BrandId,
  173. });
  174. }
  175. else
  176. {
  177. other.MerchantId = merchant.Id;
  178. other.RealName = MerchantName;
  179. other.MerNo = MerchantNo;
  180. other.BrandId = merchant.BrandId;
  181. }
  182. maindb.SaveChanges();
  183. }
  184. bool checkPos = maindb.PosMachinesTwo.Any(m => m.Status > -1 && m.BindMerchantId == merchant.Id);
  185. PosMachinesTwo pos = new PosMachinesTwo();
  186. if (checkPos)
  187. {
  188. pos = maindb.PosMachinesTwo.Where(m => m.Status > -1 && m.BindMerchantId == merchant.Id).OrderByDescending(m => m.SeoKeyword).FirstOrDefault() ?? new PosMachinesTwo();
  189. }
  190. Obj.Add("userName", merchant.MerRealName); //商户名称
  191. Obj.Add("tel", merchant.MerchantMobile); //商户手机号
  192. // Obj.Add("SN", ""); //机具SN号
  193. Obj.Add("type", RelationClass.GetKqProductBrandInfo(merchant.BrandId)); //品牌名称
  194. if (pos.ActivationState == 1)
  195. {
  196. Obj.Add("createTime", pos.ActivationTime == null ? "" : pos.ActivationTime.Value.ToString("yyyy-MM-dd")); //创建时间
  197. }
  198. else
  199. {
  200. Obj.Add("createTime", "未激活");
  201. }
  202. Obj.Add("totalTurnover", pos.CreditTrade.ToString("f2")); //累计交易额
  203. Obj.Add("mounthTurnover", PosMerchantTradeSummaryDbconn.Instance.GetDateTimeTrade(merchant.Id, DateTime.Now.ToString("yyyyMM"))); //本月交易额
  204. decimal deposit = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  205. if (pos.BrandId != 2 && pos.BrandId != 7)
  206. {
  207. deposit = deposit / 100;
  208. }
  209. Obj.Add("deposit", deposit.ToString("f2")); //押金金额
  210. Obj.Add("policy", "押99返100,押199返200,押299返300"); //返押政策
  211. bool status = maindb.ActiveReward.Any(m => m.KqSnNo == pos.PosSn);
  212. Obj.Add("status", status ? "未返" : "已返"); //返押金状态
  213. if (status)
  214. {
  215. Obj.Add("reason", ""); //返回失败原因
  216. }
  217. else
  218. {
  219. string reason = "";
  220. if (string.IsNullOrEmpty(pos.SeoKeyword))
  221. {
  222. reason = "处理中";
  223. }
  224. else if (pos.CreditTrade < 1000)
  225. {
  226. reason = "贷记卡交易未满1000";
  227. }
  228. Obj.Add("reason", reason);
  229. }
  230. return Obj;
  231. }
  232. #endregion
  233. #region 通用-匹配满足商户的列表
  234. [Authorize]
  235. public JsonResult CheckMerchants(string value)
  236. {
  237. value = DesDecrypt(value);
  238. JsonData data = JsonMapper.ToObject(value);
  239. string MerchantName = data["MerchantName"].ToString(); //商户名称
  240. string MerchantMobile = data["MerchantMobile"].ToString(); //商户手机号
  241. string MerchantCertId = data["MerchantCertId"].ToString(); //商户身份证号
  242. string MobileCode = data["MobileCode"].ToString(); //短信验证码
  243. if (string.IsNullOrEmpty(MerchantMobile))
  244. {
  245. return Json(new AppResultJson() { Status = "-1", Info = "请填写手机号" });
  246. }
  247. if (MerchantMobile.Length > 11)
  248. {
  249. return Json(new AppResultJson() { Status = "-1", Info = "手机号最多11个字符" });
  250. }
  251. if (function.CheckMobile(MerchantMobile) == "")
  252. {
  253. return Json(new AppResultJson() { Status = "-1", Info = "请填写正确的手机号" });
  254. }
  255. MobileCodeCheck mobilecheck = RedisDbconn.Instance.Get<MobileCodeCheck>("MobileCodeCheck:" + MerchantMobile);
  256. if (mobilecheck == null)
  257. {
  258. return Json(new AppResultJson() { Status = "-1", Info = "短信验证码不正确" });
  259. }
  260. if (mobilecheck.CheckCode != MobileCode)
  261. {
  262. return Json(new AppResultJson() { Status = "-1", Info = "短信验证码不正确" });
  263. }
  264. RedisDbconn.Instance.Clear("MobileCodeCheck:" + MerchantMobile);
  265. string CheckMobile = MerchantMobile.Substring(0, 3) + "****" + MerchantMobile.Substring(7);
  266. List<PosMerchantInfo> merchants = maindb.PosMerchantInfo.Where(m => m.MerIdcardNo == MerchantCertId).ToList();
  267. if (merchants.Count == 0)
  268. {
  269. merchants = maindb.PosMerchantInfo.Where(m => m.MerchantMobile == CheckMobile && m.MerchantName.Contains(MerchantName)).ToList();
  270. }
  271. List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
  272. foreach (PosMerchantInfo sub in merchants)
  273. {
  274. Dictionary<string, object> item = new Dictionary<string, object>();
  275. item.Add("Id", sub.Id);
  276. item.Add("MerchantName", sub.MerchantName);
  277. item.Add("MerchantCode", sub.KqMerNo);
  278. item.Add("ProductName", RelationClass.GetKqProductBrandInfo(sub.BrandId));
  279. list.Add(item);
  280. }
  281. return Json(new AppResultJson() { Status = "1", Info = "", Data = list });
  282. }
  283. #endregion
  284. #region 通用-检查商户是否存在
  285. [Authorize]
  286. public JsonResult CheckMerchantInfo(string value)
  287. {
  288. value = DesDecrypt(value);
  289. JsonData data = JsonMapper.ToObject(value);
  290. string MerchantMobile = data["MerchantMobile"].ToString(); //商户手机号
  291. string MerRealName = data["MerRealName"].ToString(); //商户真实姓名
  292. string MerIdcardNo = data["MerIdcardNo"].ToString(); //商户身份证号
  293. Dictionary<string, object> Obj = new Dictionary<string, object>();
  294. bool Exist = maindb.PosMerchantInfo.Any(m => m.MerIdcardNo == MerIdcardNo);
  295. Obj.Add("Exist", Exist ? 1 : 0);
  296. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  297. }
  298. #endregion
  299. #region 创客-首页-押金查询登录
  300. [Authorize]
  301. public JsonResult MerchantLogin(string value)
  302. {
  303. value = DesDecrypt(value);
  304. JsonData data = JsonMapper.ToObject(value);
  305. AppResultJson result = MerchantLoginDo(value);
  306. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  307. }
  308. public AppResultJson MerchantLoginDo(string value)
  309. {
  310. JsonData data = JsonMapper.ToObject(value);
  311. string MerchantMobile = data["MerchantMobile"].ToString(); //商户手机号
  312. string MobileCode = data["MobileCode"].ToString(); //短信验证码
  313. if (MerchantMobile.Length != 11 || !function.IsInt(MerchantMobile) || MerchantMobile.Substring(0, 1) != "1")
  314. {
  315. return new AppResultJson() { Status = "-1", Info = "手机号不正确" };
  316. }
  317. MobileCodeCheck mobilecheck = RedisDbconn.Instance.Get<MobileCodeCheck>("MobileCodeCheck:" + MerchantMobile);
  318. if (mobilecheck == null)
  319. {
  320. return new AppResultJson() { Status = "-1", Info = "短信验证码不正确" };
  321. }
  322. if (mobilecheck.CheckCode != MobileCode)
  323. {
  324. return new AppResultJson() { Status = "-1", Info = "短信验证码不正确" };
  325. }
  326. RedisDbconn.Instance.Clear("MobileCodeCheck:" + MerchantMobile);
  327. Dictionary<string, object> Obj = new Dictionary<string, object>();
  328. var AuthFlag = 0;
  329. var check = maindb.UserFamilyMember.Any(m => m.Mobile == MerchantMobile);
  330. if (check)
  331. {
  332. var info = maindb.UserFamilyMember.FirstOrDefault(m => m.Mobile == MerchantMobile) ?? new UserFamilyMember();
  333. Obj.Add("AuthFlag", info.Status);
  334. Obj.Add("MerRealName", info.Name);
  335. Obj.Add("MerIdcardNo", info.IdCardNo);
  336. }
  337. else
  338. {
  339. var query = maindb.UserFamilyMember.Add(new UserFamilyMember()
  340. {
  341. CreateDate = DateTime.Now,
  342. Mobile = MerchantMobile,
  343. }).Entity;
  344. maindb.SaveChanges();
  345. Obj.Add("AuthFlag", AuthFlag);
  346. }
  347. return new AppResultJson() { Status = "1", Info = "登录成功", Data = Obj };
  348. }
  349. #endregion
  350. #region 创客-首页-押金查询认证
  351. [Authorize]
  352. public JsonResult MerchantAuth(string value)
  353. {
  354. value = DesDecrypt(value);
  355. JsonData data = JsonMapper.ToObject(value);
  356. AppResultJson result = MerchantAuthDo(value);
  357. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  358. }
  359. public AppResultJson MerchantAuthDo(string value)
  360. {
  361. JsonData data = JsonMapper.ToObject(value);
  362. string MerchantMobile = data["MerchantMobile"].ToString(); //商户手机号
  363. string MerRealName = data["MerRealName"].ToString(); //商户真实姓名
  364. string MerIdcardNo = data["MerIdcardNo"].ToString(); //商户身份证号
  365. Dictionary<string, object> Obj = new Dictionary<string, object>();
  366. string result = IdCardCheckForThree.Instance.Do(MerchantMobile, MerIdcardNo, MerRealName);
  367. JsonData jsonObj = JsonMapper.ToObject(result);
  368. if (jsonObj["result_code"].ToString() == "0")
  369. {
  370. if (jsonObj["state"].ToString() == "1")
  371. {
  372. var check = maindb.UserFamilyMember.Any(m => m.IdCardNo == MerIdcardNo);
  373. if (check)
  374. {
  375. return new AppResultJson() { Status = "-1", Info = "该身份证已认证", Data = Obj };
  376. }
  377. else
  378. {
  379. var info = maindb.UserFamilyMember.FirstOrDefault(m => m.Mobile == MerchantMobile) ?? new UserFamilyMember();
  380. info.Status = 1;
  381. info.UpdateDate = DateTime.Now;
  382. info.Name = MerRealName;
  383. info.IdCardNo = MerIdcardNo;
  384. maindb.SaveChanges();
  385. var idCard1 = MerIdcardNo.Substring(0, 6);
  386. var idCard2 = MerIdcardNo.Substring(MerIdcardNo.Length - 4, 4);
  387. var posMerchantInfoList = maindb.PosMerchantInfo.Where(m => m.MerIdcardNo.StartsWith(idCard1) && m.MerIdcardNo.EndsWith(idCard2) && m.MerchantName.Contains(MerRealName)).ToList();
  388. foreach (var item in posMerchantInfoList)
  389. {
  390. var posMer = posMerchantInfoList.FirstOrDefault(m => m.Id == item.Id) ?? new PosMerchantInfo();
  391. posMer.MerchantMobile = MerchantMobile;
  392. posMer.MerRealName = MerRealName;
  393. posMer.MerIdcardNo = MerIdcardNo;
  394. maindb.SaveChanges();
  395. }
  396. }
  397. }
  398. else
  399. {
  400. return new AppResultJson() { Status = "-1", Info = jsonObj["result_message"].ToString(), Data = Obj };
  401. }
  402. }
  403. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  404. }
  405. #endregion
  406. #region 创客-首页-押金查询详情列表
  407. [Authorize]
  408. public JsonResult MerchantDepositList(string value)
  409. {
  410. value = DesDecrypt(value);
  411. JsonData data = JsonMapper.ToObject(value);
  412. List<MerchantDepositList> dataList = MerchantDepositListDo(value);
  413. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  414. }
  415. public List<MerchantDepositList> MerchantDepositListDo(string value)
  416. {
  417. JsonData data = JsonMapper.ToObject(value);
  418. string MerchantMobile = data["MerchantMobile"].ToString(); //商户手机号
  419. string MerRealName = data["MerRealName"].ToString(); //商户真实姓名
  420. string MerIdcardNo = data["MerIdcardNo"].ToString(); //商户身份证号
  421. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  422. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  423. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  424. List<MerchantDepositList> merchantDepositLists = new List<MerchantDepositList>();
  425. PosMerchantInfo firstPos = maindb.PosMerchantInfo.FirstOrDefault(m => m.MerIdcardNo == MerIdcardNo && m.MerchantName.Contains(MerRealName) && m.StandardStatus == 1);
  426. if (firstPos != null)
  427. {
  428. merchantDepositLists.Add(PosItem(firstPos));
  429. }
  430. IQueryable<PosMerchantInfo> query = maindb.PosMerchantInfo.Where(m => m.MerIdcardNo == MerIdcardNo && m.MerchantName.Contains(MerRealName) && m.StandardStatus != 1).OrderBy(m => m.Id);
  431. if (PageNum == 1)
  432. {
  433. query = query.Take(PageSize);
  434. }
  435. else
  436. {
  437. int skipNum = PageSize * (PageNum - 1);
  438. query = query.Skip(skipNum).Take(PageSize);
  439. }
  440. foreach (var subdata in query.ToList())
  441. {
  442. merchantDepositLists.Add(PosItem(subdata));
  443. }
  444. if (firstPos == null)
  445. {
  446. merchantDepositLists = merchantDepositLists.OrderBy(m => m.CreateDate).ToList();
  447. }
  448. return merchantDepositLists;
  449. }
  450. private MerchantDepositList PosItem(PosMerchantInfo subdata)
  451. {
  452. MerchantDepositList merchantDepositList = new MerchantDepositList();
  453. MachineForSnNo forSnNo = maindb.MachineForSnNo.FirstOrDefault(m => m.SnNo == subdata.KqSnNo) ?? new MachineForSnNo();
  454. PosMachinesTwo pos = maindb.PosMachinesTwo.FirstOrDefault(m => m.Status > -1 && m.Id == forSnNo.SnId) ?? new PosMachinesTwo();
  455. var depositRreturn = maindb.MerchantDepositReturns.FirstOrDefault(m => m.MerchantId == subdata.Id) ?? new MerchantDepositReturns();
  456. decimal DepositMoney = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  457. if (pos.BrandId != 2 && pos.BrandId != 7)
  458. {
  459. DepositMoney = DepositMoney / 100;
  460. }
  461. //人工已退
  462. if (subdata.StandardStatus == -2)
  463. {
  464. merchantDepositList.Status = -2;
  465. }
  466. else
  467. {
  468. // 未达标
  469. if (subdata.StandardMonths < 10)
  470. {
  471. merchantDepositList.Status = 0;
  472. }
  473. //已达标
  474. if (subdata.StandardMonths == 10)
  475. {
  476. merchantDepositList.Status = 4;
  477. }
  478. //达标失败
  479. if (subdata.StandardMonths >= 0 && subdata.StandardStatus == -1)
  480. {
  481. merchantDepositList.Status = -1;
  482. }
  483. //已返还
  484. if (subdata.StandardStatus == 1)
  485. {
  486. merchantDepositList.Status = 1;
  487. }
  488. //领取达标奖
  489. if (subdata.StandardStatus == 101)
  490. {
  491. merchantDepositList.Status = 101;
  492. }
  493. }
  494. merchantDepositList.MerchantId = subdata.Id;
  495. merchantDepositList.MerRealName = subdata.MerRealName;
  496. merchantDepositList.KqSnNo = subdata.KqSnNo;
  497. merchantDepositList.BrandId = RelationClass.GetKqProductBrandInfo(subdata.BrandId);
  498. merchantDepositList.CreateDate = Convert.ToDateTime(pos.BindingTime);
  499. merchantDepositList.DepositMoney = DepositMoney;
  500. merchantDepositList.Months = subdata.StandardMonths;
  501. merchantDepositList.TradeAmtForMonth = PosMerchantTradeSummaryDbconn.Instance.GetDateTimeTrade(subdata.Id, DateTime.Now.ToString("yyyyMM"));
  502. return merchantDepositList;
  503. }
  504. #endregion
  505. #region 创客-首页-押金查询详情添加
  506. [Authorize]
  507. public JsonResult CheckDeposit(string value)
  508. {
  509. value = DesDecrypt(value);
  510. JsonData data = JsonMapper.ToObject(value);
  511. AppResultJson result = CheckDepositDo(value);
  512. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  513. }
  514. public AppResultJson CheckDepositDo(string value)
  515. {
  516. JsonData data = JsonMapper.ToObject(value);
  517. string MerchantMobile = data["MerchantMobile"].ToString(); //商户手机号
  518. string MerRealName = data["MerRealName"].ToString(); //商户真实姓名
  519. string MerIdcardNo = data["MerIdcardNo"].ToString(); //商户身份证号
  520. string KqSnNo = data["KqSnNo"].ToString(); //渠道SN号
  521. if (string.IsNullOrEmpty(MerchantMobile))
  522. {
  523. return new AppResultJson() { Status = "-1", Info = "请填写商户手机号" };
  524. }
  525. if (MerchantMobile.Length != 11 || !function.IsInt(MerchantMobile) || MerchantMobile.Substring(0, 1) != "1")
  526. {
  527. return new AppResultJson() { Status = "-1", Info = "商户手机号不正确" };
  528. }
  529. if (string.IsNullOrEmpty(MerRealName))
  530. {
  531. return new AppResultJson() { Status = "-1", Info = "请填写商户真实姓名" };
  532. }
  533. if (string.IsNullOrEmpty(MerIdcardNo))
  534. {
  535. return new AppResultJson() { Status = "-1", Info = "请填写商户身份证号" };
  536. }
  537. if (MerIdcardNo.Length != 18 || !function.IsInt(MerIdcardNo.Substring(0, 17)))
  538. {
  539. return new AppResultJson() { Status = "-1", Info = "商户身份证号不正确" };
  540. }
  541. MerIdcardNo = MerIdcardNo.ToUpper();
  542. Dictionary<string, object> Obj = new Dictionary<string, object>();
  543. MachineForSnNo forSnNo = maindb.MachineForSnNo.FirstOrDefault(m => m.SnNo == KqSnNo);
  544. if (forSnNo == null)
  545. {
  546. return new AppResultJson() { Status = "-1", Info = "机具号不存在" };
  547. }
  548. //判断机具是否属于该商户
  549. var mobile1 = MerchantMobile.Substring(0, 3);
  550. var mobile2 = MerchantMobile.Substring(MerchantMobile.Length - 4, 4);
  551. var idCard1 = MerIdcardNo.Substring(0, 6);
  552. var idCard2 = MerIdcardNo.Substring(MerIdcardNo.Length - 4, 4);
  553. var idCard11 = MerIdcardNo.Substring(0, 4);
  554. var idCard22 = MerIdcardNo.Substring(MerIdcardNo.Length - 3, 3);
  555. var idCard23 = MerIdcardNo.Substring(MerIdcardNo.Length - 2, 2);
  556. var checks = maindb.PosMerchantInfo.FirstOrDefault(m => m.KqSnNo == KqSnNo) ?? new PosMerchantInfo();
  557. PosMerchantInfo posMerchant = new PosMerchantInfo();
  558. if (!string.IsNullOrEmpty(checks.MerIdcardNo))
  559. {
  560. posMerchant = maindb.PosMerchantInfo.FirstOrDefault(m => m.KqSnNo == KqSnNo && ((m.MerIdcardNo.StartsWith(idCard1) && m.MerIdcardNo.ToUpper().EndsWith(idCard2)) || (m.MerIdcardNo.StartsWith(idCard11) && m.MerIdcardNo.ToUpper().EndsWith(idCard22)) || (m.MerIdcardNo.StartsWith(idCard11) && m.MerIdcardNo.ToUpper().EndsWith(idCard23))) && (m.MerchantName.Contains(MerRealName) || m.MerchantName == MerRealName || m.MerchantName.StartsWith(MerRealName.Substring(0, 1)))) ?? new PosMerchantInfo();
  561. }
  562. else
  563. {
  564. posMerchant = maindb.PosMerchantInfo.FirstOrDefault(m => m.KqSnNo == KqSnNo && m.MerchantMobile.StartsWith(mobile1) && m.MerchantMobile.EndsWith(mobile2) && m.MerchantName.Contains(MerRealName)) ?? new PosMerchantInfo();
  565. }
  566. PosMachinesTwo pos = maindb.PosMachinesTwo.FirstOrDefault(m => m.Status > -1 && m.Id == forSnNo.SnId && m.BindMerchantId == posMerchant.Id) ?? new PosMachinesTwo();
  567. if (pos.Id == 0)
  568. {
  569. return new AppResultJson() { Status = "-1", Info = "该机具不在您的名下或不存在" };
  570. }
  571. if (pos.ActivationState == 0)
  572. {
  573. return new AppResultJson() { Status = "-1", Info = "机具未激活" };
  574. }
  575. if ((!function.CheckNull(posMerchant.MerIdcardNo).Contains("*") || !function.CheckNull(posMerchant.MerchantMobile).Contains("*")) && !string.IsNullOrEmpty(posMerchant.MerIdcardNo) && pos.BrandId != 6)
  576. {
  577. return new AppResultJson() { Status = "-1", Info = "该机具已添加" };
  578. }
  579. if (!function.CheckNull(posMerchant.MerIdcardNo).Contains("*") && !string.IsNullOrEmpty(posMerchant.MerIdcardNo) && pos.BrandId == 6)
  580. {
  581. return new AppResultJson() { Status = "-1", Info = "该机具已添加" };
  582. }
  583. int IsFirst = 1;
  584. bool check = maindb.PosMerchantInfo.Any(m => m.MerIdcardNo == MerIdcardNo);
  585. if (check)
  586. {
  587. IsFirst = 0;
  588. }
  589. PosMerchantInfo query = maindb.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  590. if (query != null)
  591. {
  592. query.UpdateDate = DateTime.Now; //修改时间
  593. query.MerchantMobile = MerchantMobile; //商户手机号
  594. query.MerRealName = MerRealName; //商户真实姓名
  595. query.MerIdcardNo = MerIdcardNo; //商户身份证号
  596. query.Sort = IsFirst;
  597. maindb.SaveChanges();
  598. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  599. }
  600. return new AppResultJson() { Status = "-1", Info = "查无此商户", Data = Obj };
  601. }
  602. #endregion
  603. #region 创客-首页-押金查询-商户详情
  604. [Authorize]
  605. public JsonResult Detail(string value)
  606. {
  607. value = DesDecrypt(value);
  608. JsonData data = JsonMapper.ToObject(value);
  609. Dictionary<string, object> Obj = DetailDo(value);
  610. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  611. }
  612. public Dictionary<string, object> DetailDo(string value)
  613. {
  614. JsonData data = JsonMapper.ToObject(value);
  615. Dictionary<string, object> Obj = new Dictionary<string, object>();
  616. int MerchantId = int.Parse(function.CheckInt(data["MerchantId"].ToString()));
  617. PosMerchantInfo query = PosMerchantInfoDbconn.Instance.Get(MerchantId) ?? new PosMerchantInfo();
  618. MachineForMerNo forMerNo = maindb.MachineForMerNo.FirstOrDefault(m => m.MerNo == query.KqMerNo) ?? new MachineForMerNo();
  619. Obj.Add("MerRealName", query.MerRealName); //商户真实姓名
  620. Obj.Add("KqSnNo", query.KqSnNo); //渠道SN号
  621. Obj.Add("KqSnId", forMerNo.SnId); //机具Id
  622. Obj.Add("ProductType", RelationClass.GetKqProductBrandInfo(query.BrandId)); //来源产品
  623. Obj.Add("TradeTotal", PosMerchantTradeSummaryDbconn.Instance.GetTrade(query.Id)); //总交易额
  624. return Obj;
  625. }
  626. #endregion
  627. #region 创客-首页-押金查询-商户详情-交易统计
  628. [Authorize]
  629. public JsonResult MerchantTradeList(string value)
  630. {
  631. value = DesDecrypt(value);
  632. JsonData data = JsonMapper.ToObject(value);
  633. Dictionary<string, object> Other = new Dictionary<string, object>();
  634. List<Dictionary<string, object>> dataList = MerchantTradeListDo(value, out Other);
  635. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Other });
  636. }
  637. public List<Dictionary<string, object>> MerchantTradeListDo(string value, out Dictionary<string, object> Other)
  638. {
  639. JsonData data = JsonMapper.ToObject(value);
  640. string TradeMonth = data["TradeMonth"].ToString(); //交易月
  641. int MerchantId = int.Parse(data["MerchantId"].ToString()); //商户Id
  642. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  643. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  644. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  645. var query = maindb.PosMerchantTradeSummay.Where(m => m.MerchantId == MerchantId && m.TradeMonth == TradeMonth);
  646. if (PageNum == 1)
  647. {
  648. query = query.Take(PageSize);
  649. }
  650. else
  651. {
  652. int skipNum = PageSize * (PageNum - 1);
  653. query = query.Skip(skipNum).Take(PageSize);
  654. }
  655. foreach (var DateString in query.ToList())
  656. {
  657. Dictionary<string, object> curData = new Dictionary<string, object>();
  658. curData.Add("TradeDate", DateString.TradeDate); //交易日
  659. curData.Add("TradeAmt", DateString.TradeAmount); //交易额
  660. dataList.Add(curData);
  661. }
  662. Other = new Dictionary<string, object>();
  663. Other.Add("MonthTradeAmt", PosMerchantTradeSummaryDbconn.Instance.GetDateTimeTrade(MerchantId, TradeMonth));
  664. return dataList;
  665. }
  666. #endregion
  667. #region 创客-首页-押金查询-详情
  668. [Authorize]
  669. public JsonResult DepositMerchantList(string value)
  670. {
  671. value = DesDecrypt(value);
  672. JsonData data = JsonMapper.ToObject(value);
  673. List<Dictionary<string, object>> dataList = DepositMerchantListDo(value);
  674. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  675. }
  676. public List<Dictionary<string, object>> DepositMerchantListDo(string value)
  677. {
  678. JsonData data = JsonMapper.ToObject(value);
  679. string MerIdcardNo = data["MerIdcardNo"].ToString(); //商户身份证号
  680. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  681. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  682. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  683. IQueryable<PosMerchantInfo> query = maindb.PosMerchantInfo.Where(m => m.MerIdcardNo == MerIdcardNo).OrderBy(m => m.Id);
  684. if (PageNum == 1)
  685. {
  686. query = query.Take(PageSize);
  687. }
  688. else
  689. {
  690. int skipNum = PageSize * (PageNum - 1);
  691. query = query.Skip(skipNum).Take(PageSize);
  692. }
  693. int index = 0;
  694. foreach (var subdata in query.ToList())
  695. {
  696. index += 1;
  697. Dictionary<string, object> curData = new Dictionary<string, object>();
  698. curData.Add("Id", subdata.Id);
  699. curData.Add("MerRealName", subdata.MerRealName); //商户真实姓名
  700. curData.Add("KqSnNo", subdata.KqSnNo); //渠道SN号
  701. curData.Add("BrandId", RelationClass.GetKqProductBrandInfo(subdata.BrandId)); //品牌
  702. curData.Add("CreateDate", subdata.CreateDate == null ? "" : subdata.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //CreateDate
  703. MachineForSnNo forSnNo = maindb.MachineForSnNo.FirstOrDefault(m => m.SnNo == subdata.KqSnNo) ?? new MachineForSnNo();
  704. PosMachinesTwo pos = maindb.PosMachinesTwo.FirstOrDefault(m => m.Status > -1 && m.Id == forSnNo.SnId) ?? new PosMachinesTwo();
  705. decimal DepositMoney = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  706. if (pos.BrandId != 2 && pos.BrandId != 7)
  707. {
  708. DepositMoney = DepositMoney / 100;
  709. }
  710. curData.Add("DepositMoney", DepositMoney.ToString("f2")); //押金金额
  711. int Months = 0;
  712. int Status = 0;
  713. string MonthString = "";
  714. if (pos.BindingState == 1)
  715. {
  716. DateTime start = DateTime.Parse(subdata.CreateDate.Value.AddMonths(1).ToString("yyyy-MM") + "-01 00:00:00");
  717. DateTime end = DateTime.Parse(DateTime.Now.ToString("yyyy-MM") + "-01 00:00:00");
  718. while (start <= end)
  719. {
  720. decimal checkTrade = PosMerchantTradeSummaryDbconn.Instance.GetDateTimeTrade(subdata.Id, start.ToString("yyyyMM"));
  721. if (checkTrade >= 10000)
  722. {
  723. Months += 1;
  724. start = start.AddMonths(1);
  725. Status = 1;
  726. }
  727. else
  728. {
  729. if (start.ToString("yyyy-MM") != DateTime.Now.ToString("yyyy-MM"))
  730. {
  731. Months = start.Month;
  732. MonthString = start.ToString("yyyy-MM");
  733. start = end.AddSeconds(1);
  734. Status = 5;
  735. }
  736. else
  737. {
  738. start = start.AddMonths(1);
  739. }
  740. }
  741. }
  742. }
  743. curData.Add("Status", Status); //返押状态
  744. if (Status == 5)
  745. {
  746. curData.Add("Months", MonthString); //未达标月
  747. }
  748. else
  749. {
  750. curData.Add("Months", Months); //连续达标月数
  751. }
  752. curData.Add("TradeAmtForMonth", PosMerchantTradeSummaryDbconn.Instance.GetDateTimeTrade(subdata.Id, DateTime.Now.ToString("yyyyMM"))); //本月交易额
  753. curData.Add("DepositStatus", 0); //返押状态
  754. curData.Add("MerType", index == 1 ? 1 : 0); //机具类型
  755. dataList.Add(curData);
  756. }
  757. return dataList;
  758. }
  759. #endregion
  760. #region 创客-首页-押金查询-退押金-确认信息
  761. [Authorize]
  762. public JsonResult ReturnDepositForConfirm(string value)
  763. {
  764. value = DesDecrypt(value);
  765. JsonData data = JsonMapper.ToObject(value);
  766. Dictionary<string, object> Obj = ReturnDepositForConfirmDo(value);
  767. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  768. }
  769. public Dictionary<string, object> ReturnDepositForConfirmDo(string value)
  770. {
  771. JsonData data = JsonMapper.ToObject(value);
  772. Dictionary<string, object> Obj = new Dictionary<string, object>();
  773. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  774. PosMerchantInfo query = maindb.PosMerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new PosMerchantInfo();
  775. Obj.Add("MerchantMobile", query.MerchantMobile); //商户手机号
  776. Obj.Add("MerRealName", query.MerRealName); //商户真实姓名
  777. Obj.Add("MerIdcardNo", query.MerIdcardNo); //商户身份证号
  778. return Obj;
  779. }
  780. #endregion
  781. #region 通过机具Id查询机具号和商户名称
  782. [Authorize]
  783. public JsonResult SearchInfo(string value)
  784. {
  785. value = DesDecrypt(value);
  786. JsonData data = JsonMapper.ToObject(value);
  787. Dictionary<string, object> Obj = SearchInfoDo(value);
  788. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  789. }
  790. public Dictionary<string, object> SearchInfoDo(string value)
  791. {
  792. JsonData data = JsonMapper.ToObject(value);
  793. Dictionary<string, object> Obj = new Dictionary<string, object>();
  794. int SnId = int.Parse(function.CheckInt(data["SnId"].ToString()));
  795. int IsOk = 0;
  796. PosMachinesTwo pos = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == SnId) ?? new PosMachinesTwo();
  797. if (pos.BuyUserId != pos.UserId)
  798. {
  799. IsOk = 1;
  800. }
  801. PosMerchantInfo query = maindb.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  802. string Name = Regex.Replace(function.CheckNull(query.MerchantName), "[0-9][a-zA-Z]", "");
  803. Obj.Add("IsOk", IsOk); //是否商户型创客
  804. Obj.Add("PosSn", pos.PosSn); //机具号
  805. Obj.Add("MerchantName", Name); //商户名称
  806. return Obj;
  807. }
  808. #endregion
  809. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  810. /// <summary>
  811. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  812. /// </summary>
  813. /// <param name="value">请求的参数(json字符串)</param>
  814. /// <param name="signField">要签名的字段</param>
  815. /// <returns></returns>
  816. private string CheckSign(string value, string[] signField)
  817. {
  818. JsonData json = JsonMapper.ToObject(value);
  819. Dictionary<string, string> dic = new Dictionary<string, string>();
  820. for (int i = 0; i < signField.Length; i++)
  821. {
  822. dic.Add(signField[i], json[signField[i]].ToString());
  823. }
  824. string sign = json["sign"].ToString(); //客户端签名字符串
  825. return new Sign().sign(dic, sign);
  826. }
  827. #endregion
  828. }
  829. }