DepositQueryController.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Data;
  5. using Microsoft.AspNetCore.Mvc;
  6. using Microsoft.AspNetCore.Http;
  7. using Microsoft.Extensions.Logging;
  8. using Microsoft.Extensions.Options;
  9. using Microsoft.AspNetCore.Authorization;
  10. using System.Web;
  11. using MySystem.MainModels;
  12. using LitJson;
  13. using Library;
  14. using System.Text;
  15. /// <summary>
  16. /// 商户验证相关接口
  17. /// </summary>
  18. namespace MySystem.Areas.Api.Controllers.v1
  19. {
  20. [Area("Api")]
  21. [Route("/Api/v1/[controller]/[action]")]
  22. public class DepositQueryController : BaseController
  23. {
  24. public DepositQueryController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  25. {
  26. }
  27. #region 获取商户机具押金列表
  28. [Authorize]
  29. public JsonResult CheckMerchants(string value)
  30. {
  31. value = DesDecrypt(value);
  32. JsonData data = JsonMapper.ToObject(value);
  33. AppResultJson result = CheckMerchantsDo(value);
  34. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  35. }
  36. public AppResultJson CheckMerchantsDo(string value)
  37. {
  38. JsonData data = JsonMapper.ToObject(value);
  39. string SN = data["SN"].ToString(); //机具SN
  40. string MerchantName = data["MerchantName"].ToString(); //商户名称
  41. string MerchantCertId = data["MerchantCertId"].ToString(); //商户身份证号
  42. string MerchantMobile = data["MerchantMobile"].ToString(); //商户手机号
  43. string MobileCode = data["MobileCode"].ToString(); //短信验证码
  44. if (string.IsNullOrEmpty(MerchantMobile))
  45. {
  46. return new AppResultJson() { Status = "-1", Info = "请填写手机号" };
  47. }
  48. if (MerchantMobile.Length > 11)
  49. {
  50. return new AppResultJson() { Status = "-1", Info = "手机号最多11个字符" };
  51. }
  52. if (function.CheckMobile(MerchantMobile) == "")
  53. {
  54. return new AppResultJson() { Status = "-1", Info = "请填写正确的手机号" };
  55. }
  56. MobileCodeCheck mobilecheck = RedisDbconn.Instance.Get<MobileCodeCheck>("MobileCodeCheck:" + MerchantMobile);
  57. if (mobilecheck == null)
  58. {
  59. return new AppResultJson() { Status = "-1", Info = "短信验证码不正确" };
  60. }
  61. if (mobilecheck.CheckCode != MobileCode)
  62. {
  63. return new AppResultJson() { Status = "-1", Info = "短信验证码不正确" };
  64. }
  65. //通过机具SN查询并更新商户数据
  66. List<PosMachinesTwo> posMachinesTwos = maindb.PosMachinesTwo.Where(m => m.Status > -1 && m.PosSn == SN).ToList();
  67. if (posMachinesTwos.Count > 0)
  68. {
  69. maindb.PosMerchantInfo.Add(new PosMerchantInfo()
  70. {
  71. MerIdcardNo = MerchantCertId,
  72. MerRealName = MerchantName,
  73. MerchantMobile = MerchantMobile
  74. });
  75. maindb.SaveChanges();
  76. }
  77. List<PosMerchantInfo> merchants = maindb.PosMerchantInfo.Where(m => m.MerIdcardNo == MerchantCertId).ToList();
  78. if (merchants.Count == 0)
  79. {
  80. merchants = maindb.PosMerchantInfo.Where(m => m.MerRealName.Contains(MerchantName)).ToList();
  81. }
  82. List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
  83. foreach (PosMerchantInfo sub in merchants)
  84. {
  85. Dictionary<string, object> item = new Dictionary<string, object>();
  86. item.Add("Id", sub.Id);
  87. item.Add("MerchantName", sub.MerchantName);
  88. item.Add("MerchantCode", sub.KqMerNo);
  89. item.Add("ProductName", RelationClass.GetKqProductBrandInfo(sub.BrandId));
  90. list.Add(item);
  91. }
  92. return new AppResultJson() { Status = "1", Info = "", Data = list };
  93. }
  94. #endregion
  95. #region 通用-通过商户编号查询商户信息-2
  96. [Authorize]
  97. public JsonResult QueryMerchantInfo2(string value)
  98. {
  99. value = DesDecrypt(value);
  100. JsonData data = JsonMapper.ToObject(value);
  101. AppResultJson Obj = QueryMerchantInfo2Do(value);
  102. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  103. }
  104. public AppResultJson QueryMerchantInfo2Do(string value)
  105. {
  106. JsonData data = JsonMapper.ToObject(value);
  107. string SN = data["SN"].ToString(); //机具SN
  108. string MerchantNo = data["MerchantNo"].ToString(); //商户编号
  109. string MerchantName = data["MerchantName"].ToString(); //商户名称
  110. string MerchantMobile = data["MerchantMobile"].ToString(); //商户手机号
  111. string MerchantCertId = data["MerchantCertId"].ToString(); //商户身份证号
  112. string MobileCode = data["MobileCode"].ToString(); //短信验证码
  113. Dictionary<string, object> Obj = new Dictionary<string, object>();
  114. List<Dictionary<string, object>> datalist = new List<Dictionary<string, object>>();
  115. if (string.IsNullOrEmpty(MerchantMobile))
  116. {
  117. return new AppResultJson() { Status = "-1", Info = "请填写手机号" };
  118. }
  119. if (MerchantMobile.Length > 11)
  120. {
  121. return new AppResultJson() { Status = "-1", Info = "手机号最多11个字符" };
  122. }
  123. if (function.CheckMobile(MerchantMobile) == "")
  124. {
  125. return new AppResultJson() { Status = "-1", Info = "请填写正确的手机号" };
  126. }
  127. MobileCodeCheck mobilecheck = RedisDbconn.Instance.Get<MobileCodeCheck>("MobileCodeCheck:" + MerchantMobile);
  128. if (mobilecheck == null)
  129. {
  130. return new AppResultJson() { Status = "-1", Info = "短信验证码不正确" };
  131. }
  132. if (mobilecheck.CheckCode != MobileCode)
  133. {
  134. return new AppResultJson() { Status = "-1", Info = "短信验证码不正确" };
  135. }
  136. RedisDbconn.Instance.Clear("MobileCodeCheck:" + MerchantMobile);
  137. string CheckMobile = MerchantMobile.Substring(0, 3) + "****" + MerchantMobile.Substring(7);
  138. //通过机具SN查询并更新商户数据
  139. List<PosMachinesTwo> posMachinesTwos = maindb.PosMachinesTwo.Where(m => m.Status > -1 && m.PosSn == SN).ToList();
  140. if (posMachinesTwos.Count > 0)
  141. {
  142. maindb.PosMerchantInfo.Add(new PosMerchantInfo()
  143. {
  144. MerIdcardNo = MerchantCertId,
  145. MerRealName = MerchantName,
  146. MerchantMobile = MerchantMobile
  147. });
  148. maindb.SaveChanges();
  149. }
  150. PosMerchantInfo merchant = maindb.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerchantNo);
  151. if (merchant == null)
  152. {
  153. return new AppResultJson() { Status = "-1", Info = "", Data = Obj };
  154. }
  155. bool CheckCertId = maindb.PosMerchantOtherInfo.Any(m => m.CertId == MerchantCertId);
  156. if (function.CheckNull(merchant.MerchantMobile).Contains("****") && !CheckCertId)
  157. {
  158. merchant.MerRealName = MerchantName;
  159. merchant.MerchantMobile = MerchantMobile;
  160. merchant.MerIdcardNo = MerchantCertId;
  161. PosMerchantOtherInfo other = maindb.PosMerchantOtherInfo.FirstOrDefault(m => m.CertId == MerchantCertId);
  162. if (other == null)
  163. {
  164. maindb.PosMerchantOtherInfo.Add(new PosMerchantOtherInfo()
  165. {
  166. CertId = MerchantCertId,
  167. MerchantId = merchant.Id,
  168. RealName = MerchantName,
  169. MerNo = MerchantNo,
  170. BrandId = merchant.BrandId,
  171. });
  172. }
  173. else
  174. {
  175. other.MerchantId = merchant.Id;
  176. other.RealName = MerchantName;
  177. other.MerNo = MerchantNo;
  178. other.BrandId = merchant.BrandId;
  179. }
  180. maindb.SaveChanges();
  181. }
  182. bool checkPos = maindb.PosMachinesTwo.Any(m => m.Status > -1 && m.BindMerchantId == merchant.Id);
  183. PosMachinesTwo pos = new PosMachinesTwo();
  184. if (checkPos)
  185. {
  186. pos = maindb.PosMachinesTwo.Where(m => m.Status > -1 && m.BindMerchantId == merchant.Id).OrderByDescending(m => m.SeoKeyword).FirstOrDefault() ?? new PosMachinesTwo();
  187. }
  188. Obj.Add("MerRealName", merchant.MerRealName); //商户真实名称
  189. Obj.Add("MerchantMobile", merchant.MerchantMobile); //商户手机号
  190. Obj.Add("SN", pos.PosSn); //机具SN号
  191. Obj.Add("type", RelationClass.GetKqProductBrandInfo(merchant.BrandId)); //品牌名称
  192. if (pos.ActivationState == 1)
  193. {
  194. Obj.Add("createTime", pos.ActivationTime == null ? "" : pos.ActivationTime.Value.ToString("yyyy-MM-dd")); //创建时间
  195. }
  196. else
  197. {
  198. Obj.Add("createTime", "未激活");
  199. }
  200. Obj.Add("totalTurnover", pos.CreditTrade.ToString("f2")); //累计交易额
  201. Obj.Add("mounthTurnover", PosMerchantTradeSummaryDbconn.Instance.GetDateTimeTrade(merchant.Id, DateTime.Now.ToString("yyyyMM"))); //本月交易额
  202. decimal deposit = decimal.Parse(function.CheckNum(pos.SeoKeyword));
  203. if (pos.BrandId != 2 && pos.BrandId != 7)
  204. {
  205. deposit = deposit / 100;
  206. }
  207. Obj.Add("deposit", deposit.ToString("f2")); //押金金额
  208. Obj.Add("policy", "押99返100,押199返200,押299返300"); //返押政策
  209. bool status = maindb.ActiveReward.Any(m => m.KqSnNo == pos.PosSn);
  210. Obj.Add("status", status ? "未返" : "已返"); //返押金状态
  211. if (status)
  212. {
  213. Obj.Add("reason", ""); //返回失败原因
  214. }
  215. else
  216. {
  217. string reason = "";
  218. if (string.IsNullOrEmpty(pos.SeoKeyword))
  219. {
  220. reason = "处理中";
  221. }
  222. else if (pos.CreditTrade < 1000)
  223. {
  224. reason = "贷记卡交易未满1000";
  225. }
  226. Obj.Add("reason", reason);
  227. }
  228. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  229. }
  230. #endregion
  231. }
  232. }