123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Data;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Http;
- using Microsoft.Extensions.Logging;
- using Microsoft.Extensions.Options;
- using Microsoft.AspNetCore.Authorization;
- using System.Web;
- using MySystem.MainModels;
- using LitJson;
- using Library;
- using System.Text;
- /// <summary>
- /// 商户验证相关接口
- /// </summary>
- namespace MySystem.Areas.Api.Controllers.v1
- {
- [Area("Api")]
- [Route("/Api/v1/[controller]/[action]")]
- public class DepositQueryController : BaseController
- {
- public DepositQueryController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
- {
- }
- #region 获取商户机具押金列表
- [Authorize]
- public JsonResult CheckMerchants(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- AppResultJson result = CheckMerchantsDo(value);
- return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
- }
- public AppResultJson CheckMerchantsDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- string SN = data["SN"].ToString(); //机具SN
- string MerchantName = data["MerchantName"].ToString(); //商户名称
- string MerchantCertId = data["MerchantCertId"].ToString(); //商户身份证号
- string MerchantMobile = data["MerchantMobile"].ToString(); //商户手机号
- string MobileCode = data["MobileCode"].ToString(); //短信验证码
- if (string.IsNullOrEmpty(MerchantMobile))
- {
- return new AppResultJson() { Status = "-1", Info = "请填写手机号" };
- }
- if (MerchantMobile.Length > 11)
- {
- return new AppResultJson() { Status = "-1", Info = "手机号最多11个字符" };
- }
- if (function.CheckMobile(MerchantMobile) == "")
- {
- return new AppResultJson() { Status = "-1", Info = "请填写正确的手机号" };
- }
- MobileCodeCheck mobilecheck = RedisDbconn.Instance.Get<MobileCodeCheck>("MobileCodeCheck:" + MerchantMobile);
- if (mobilecheck == null)
- {
- return new AppResultJson() { Status = "-1", Info = "短信验证码不正确" };
- }
- if (mobilecheck.CheckCode != MobileCode)
- {
- return new AppResultJson() { Status = "-1", Info = "短信验证码不正确" };
- }
- //通过机具SN查询并更新商户数据
- List<PosMachinesTwo> posMachinesTwos = maindb.PosMachinesTwo.Where(m => m.Status > -1 && m.PosSn == SN).ToList();
- if (posMachinesTwos.Count > 0)
- {
- maindb.PosMerchantInfo.Add(new PosMerchantInfo()
- {
- MerIdcardNo = MerchantCertId,
- MerRealName = MerchantName,
- MerchantMobile = MerchantMobile
- });
- maindb.SaveChanges();
- }
- List<PosMerchantInfo> merchants = maindb.PosMerchantInfo.Where(m => m.MerIdcardNo == MerchantCertId).ToList();
- if (merchants.Count == 0)
- {
- merchants = maindb.PosMerchantInfo.Where(m => m.MerRealName.Contains(MerchantName)).ToList();
- }
- List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
- foreach (PosMerchantInfo sub in merchants)
- {
- Dictionary<string, object> item = new Dictionary<string, object>();
- item.Add("Id", sub.Id);
- item.Add("MerchantName", sub.MerchantName);
- item.Add("MerchantCode", sub.KqMerNo);
- item.Add("ProductName", RelationClass.GetKqProductBrandInfo(sub.BrandId));
- list.Add(item);
- }
- return new AppResultJson() { Status = "1", Info = "", Data = list };
- }
- #endregion
- #region 通用-通过商户编号查询商户信息-2
- [Authorize]
- public JsonResult QueryMerchantInfo2(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- AppResultJson Obj = QueryMerchantInfo2Do(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
- }
- public AppResultJson QueryMerchantInfo2Do(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- string SN = data["SN"].ToString(); //机具SN
- string MerchantNo = data["MerchantNo"].ToString(); //商户编号
- string MerchantName = data["MerchantName"].ToString(); //商户名称
- string MerchantMobile = data["MerchantMobile"].ToString(); //商户手机号
- string MerchantCertId = data["MerchantCertId"].ToString(); //商户身份证号
- string MobileCode = data["MobileCode"].ToString(); //短信验证码
- Dictionary<string, object> Obj = new Dictionary<string, object>();
- List<Dictionary<string, object>> datalist = new List<Dictionary<string, object>>();
- if (string.IsNullOrEmpty(MerchantMobile))
- {
- return new AppResultJson() { Status = "-1", Info = "请填写手机号" };
- }
- if (MerchantMobile.Length > 11)
- {
- return new AppResultJson() { Status = "-1", Info = "手机号最多11个字符" };
- }
- if (function.CheckMobile(MerchantMobile) == "")
- {
- return new AppResultJson() { Status = "-1", Info = "请填写正确的手机号" };
- }
- MobileCodeCheck mobilecheck = RedisDbconn.Instance.Get<MobileCodeCheck>("MobileCodeCheck:" + MerchantMobile);
- if (mobilecheck == null)
- {
- return new AppResultJson() { Status = "-1", Info = "短信验证码不正确" };
- }
- if (mobilecheck.CheckCode != MobileCode)
- {
- return new AppResultJson() { Status = "-1", Info = "短信验证码不正确" };
- }
- RedisDbconn.Instance.Clear("MobileCodeCheck:" + MerchantMobile);
- string CheckMobile = MerchantMobile.Substring(0, 3) + "****" + MerchantMobile.Substring(7);
- //通过机具SN查询并更新商户数据
- List<PosMachinesTwo> posMachinesTwos = maindb.PosMachinesTwo.Where(m => m.Status > -1 && m.PosSn == SN).ToList();
- if (posMachinesTwos.Count > 0)
- {
- maindb.PosMerchantInfo.Add(new PosMerchantInfo()
- {
- MerIdcardNo = MerchantCertId,
- MerRealName = MerchantName,
- MerchantMobile = MerchantMobile
- });
- maindb.SaveChanges();
- }
- PosMerchantInfo merchant = maindb.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerchantNo);
- if (merchant == null)
- {
- return new AppResultJson() { Status = "-1", Info = "", Data = Obj };
- }
- bool CheckCertId = maindb.PosMerchantOtherInfo.Any(m => m.CertId == MerchantCertId);
- if (function.CheckNull(merchant.MerchantMobile).Contains("****") && !CheckCertId)
- {
- merchant.MerRealName = MerchantName;
- merchant.MerchantMobile = MerchantMobile;
- merchant.MerIdcardNo = MerchantCertId;
- PosMerchantOtherInfo other = maindb.PosMerchantOtherInfo.FirstOrDefault(m => m.CertId == MerchantCertId);
- if (other == null)
- {
- maindb.PosMerchantOtherInfo.Add(new PosMerchantOtherInfo()
- {
- CertId = MerchantCertId,
- MerchantId = merchant.Id,
- RealName = MerchantName,
- MerNo = MerchantNo,
- BrandId = merchant.BrandId,
- });
- }
- else
- {
- other.MerchantId = merchant.Id;
- other.RealName = MerchantName;
- other.MerNo = MerchantNo;
- other.BrandId = merchant.BrandId;
- }
- maindb.SaveChanges();
- }
- bool checkPos = maindb.PosMachinesTwo.Any(m => m.Status > -1 && m.BindMerchantId == merchant.Id);
- PosMachinesTwo pos = new PosMachinesTwo();
- if (checkPos)
- {
- pos = maindb.PosMachinesTwo.Where(m => m.Status > -1 && m.BindMerchantId == merchant.Id).OrderByDescending(m => m.SeoKeyword).FirstOrDefault() ?? new PosMachinesTwo();
- }
- Obj.Add("MerRealName", merchant.MerRealName); //商户真实名称
- Obj.Add("MerchantMobile", merchant.MerchantMobile); //商户手机号
- Obj.Add("SN", pos.PosSn); //机具SN号
- Obj.Add("type", RelationClass.GetKqProductBrandInfo(merchant.BrandId)); //品牌名称
- if (pos.ActivationState == 1)
- {
- Obj.Add("createTime", pos.ActivationTime == null ? "" : pos.ActivationTime.Value.ToString("yyyy-MM-dd")); //创建时间
- }
- else
- {
- Obj.Add("createTime", "未激活");
- }
- Obj.Add("totalTurnover", pos.CreditTrade.ToString("f2")); //累计交易额
- Obj.Add("mounthTurnover", PosMerchantTradeSummaryDbconn.Instance.GetDateTimeTrade(merchant.Id, DateTime.Now.ToString("yyyyMM"))); //本月交易额
- decimal deposit = decimal.Parse(function.CheckNum(pos.SeoKeyword));
- if (pos.BrandId != 2 && pos.BrandId != 7)
- {
- deposit = deposit / 100;
- }
- Obj.Add("deposit", deposit.ToString("f2")); //押金金额
- Obj.Add("policy", "押99返100,押199返200,押299返300"); //返押政策
- bool status = maindb.ActiveReward.Any(m => m.KqSnNo == pos.PosSn);
- Obj.Add("status", status ? "未返" : "已返"); //返押金状态
- if (status)
- {
- Obj.Add("reason", ""); //返回失败原因
- }
- else
- {
- string reason = "";
- if (string.IsNullOrEmpty(pos.SeoKeyword))
- {
- reason = "处理中";
- }
- else if (pos.CreditTrade < 1000)
- {
- reason = "贷记卡交易未满1000";
- }
- Obj.Add("reason", reason);
- }
- return new AppResultJson() { Status = "1", Info = "", Data = Obj };
- }
- #endregion
- }
- }
|