123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- 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.RegularExpressions;
- namespace MySystem.Areas.Api.Controllers.v1.pos
- {
- [Area("Api")]
- [Route("Api/v1/pos/[controller]/[action]")]
- public class PosMerchantInfoController : BaseController
- {
- public PosMerchantInfoController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
- {
- }
- #region 创客-首页-我的商户-商户资料完善
- [Authorize]
- public JsonResult EditInfo(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- AppResultJson result = EditInfoDo(value);
- return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
- }
- public AppResultJson EditInfoDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- string MerchantMobile = data["MerchantMobile"].ToString(); //商户手机号
- string MerRealName = data["MerRealName"].ToString(); //商户真实姓名
- string MerIdcardNo = data["MerIdcardNo"].ToString(); //商户身份证号
- bool check = maindb.PosMerchantInfo.Any(m => m.MerIdcardNo == MerIdcardNo);
- if (check)
- {
- return new AppResultJson() { Status = "-1", Info = "资料已提交,请勿重复操作" };
- }
- Dictionary<string, object> Obj = new Dictionary<string, object>();
- int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
- PosMerchantInfo query = maindb.PosMerchantInfo.FirstOrDefault(m => m.Id == Id);
- if (query != null)
- {
- string checkMobile = MerchantMobile.Substring(0, 3) + "****" + MerchantMobile.Substring(7);
- if (checkMobile != query.MerchantMobile)
- {
- return new AppResultJson() { Status = "-1", Info = "手机号不正确,请核实后重试", Data = Obj };
- }
- query.MerchantMobile = MerchantMobile; //商户手机号
- query.MerRealName = MerRealName; //商户真实姓名
- query.MerIdcardNo = MerIdcardNo; //商户身份证号
- query.SeoTitle = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
- maindb.PosMerchantOtherInfo.Add(new PosMerchantOtherInfo()
- {
- CertId = MerIdcardNo,
- MerchantId = query.Id,
- RealName = MerRealName,
- MerNo = query.MerchantNo,
- BrandId = query.BrandId,
- });
- maindb.SaveChanges();
- }
- Obj.Add("Id", query.Id); //Id
- return new AppResultJson() { Status = "1", Info = "", Data = Obj };
- }
- #endregion
- #region 通用-通过商户编号查询商户信息
- [Authorize]
- public JsonResult QueryMerchantInfo(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- Dictionary<string, object> Obj = QueryMerchantInfoDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
- }
- public Dictionary<string, object> QueryMerchantInfoDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- string MerchantNo = data["MerchantNo"].ToString(); //商户编号
- Dictionary<string, object> Obj = new Dictionary<string, object>();
- PosMerchantInfo merchant = maindb.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerchantNo) ?? new PosMerchantInfo();
- 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("userName", merchant.MerRealName); //商户名称
- Obj.Add("tel", merchant.MerchantMobile); //商户手机号
- // Obj.Add("SN", ""); //机具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 Obj;
- }
- #endregion
- #region 通用-通过商户编号查询商户信息-2
- [Authorize]
- public JsonResult QueryMerchantInfo2(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- Dictionary<string, object> Obj = QueryMerchantInfo2Do(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
- }
- public Dictionary<string, object> QueryMerchantInfo2Do(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- string MerchantNo = data["MerchantNo"].ToString(); //商户编号
- string MerchantName = data["MerchantName"].ToString(); //商户名称
- string MerchantMobile = data["MerchantMobile"].ToString(); //商户手机号
- string MerchantCertId = data["MerchantCertId"].ToString(); //商户身份证号
- Dictionary<string, object> Obj = new Dictionary<string, object>();
- PosMerchantInfo merchant = maindb.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == MerchantNo);
- if (merchant == null)
- {
- return 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("userName", merchant.MerRealName); //商户名称
- Obj.Add("tel", merchant.MerchantMobile); //商户手机号
- // Obj.Add("SN", ""); //机具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 Obj;
- }
- #endregion
- #region 通用-匹配满足商户的列表
- [Authorize]
- public JsonResult CheckMerchants(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- string MerchantName = data["MerchantName"].ToString(); //商户名称
- string MerchantMobile = data["MerchantMobile"].ToString(); //商户手机号
- string MerchantCertId = data["MerchantCertId"].ToString(); //商户身份证号
- string MobileCode = data["MobileCode"].ToString(); //短信验证码
- if (string.IsNullOrEmpty(MerchantMobile))
- {
- return Json(new AppResultJson() { Status = "-1", Info = "请填写手机号" });
- }
- if (MerchantMobile.Length > 11)
- {
- return Json(new AppResultJson() { Status = "-1", Info = "手机号最多11个字符" });
- }
- if (function.CheckMobile(MerchantMobile) == "")
- {
- return Json(new AppResultJson() { Status = "-1", Info = "请填写正确的手机号" });
- }
- MobileCodeCheck mobilecheck = RedisDbconn.Instance.Get<MobileCodeCheck>("MobileCodeCheck:" + MerchantMobile);
- if (mobilecheck == null)
- {
- return Json(new AppResultJson() { Status = "-1", Info = "短信验证码不正确" });
- }
- if (mobilecheck.CheckCode != MobileCode)
- {
- return Json(new AppResultJson() { Status = "-1", Info = "短信验证码不正确" });
- }
- RedisDbconn.Instance.Clear("MobileCodeCheck:" + MerchantMobile);
- string CheckMobile = MerchantMobile.Substring(0, 3) + "****" + MerchantMobile.Substring(7);
- List<PosMerchantInfo> merchants = maindb.PosMerchantInfo.Where(m => m.MerIdcardNo == MerchantCertId).ToList();
- if (merchants.Count == 0)
- {
- merchants = maindb.PosMerchantInfo.Where(m => m.MerchantMobile == CheckMobile && m.MerchantName.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 Json(new AppResultJson() { Status = "1", Info = "", Data = list });
- }
- #endregion
- #region 通用-检查商户是否存在
- [Authorize]
- public JsonResult CheckMerchantInfo(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- string MerchantMobile = data["MerchantMobile"].ToString(); //商户手机号
- string MerRealName = data["MerRealName"].ToString(); //商户真实姓名
- string MerIdcardNo = data["MerIdcardNo"].ToString(); //商户身份证号
- Dictionary<string, object> Obj = new Dictionary<string, object>();
- bool Exist = maindb.PosMerchantInfo.Any(m => m.MerIdcardNo == MerIdcardNo);
- Obj.Add("Exist", Exist ? 1 : 0);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
- }
- #endregion
- #region 创客-首页-押金查询登录
- [Authorize]
- public JsonResult MerchantLogin(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- AppResultJson result = MerchantLoginDo(value);
- return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
- }
- public AppResultJson MerchantLoginDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- string MerchantMobile = data["MerchantMobile"].ToString(); //商户手机号
- string MobileCode = data["MobileCode"].ToString(); //短信验证码
- if (MerchantMobile.Length != 11 || !function.IsInt(MerchantMobile) || MerchantMobile.Substring(0, 1) != "1")
- {
- 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);
- Dictionary<string, object> Obj = new Dictionary<string, object>();
- var AuthFlag = 0;
- var check = maindb.UserFamilyMember.Any(m => m.Mobile == MerchantMobile);
- if (check)
- {
- var info = maindb.UserFamilyMember.FirstOrDefault(m => m.Mobile == MerchantMobile) ?? new UserFamilyMember();
- Obj.Add("AuthFlag", info.Status);
- Obj.Add("MerRealName", info.Name);
- Obj.Add("MerIdcardNo", info.IdCardNo);
- }
- else
- {
- var query = maindb.UserFamilyMember.Add(new UserFamilyMember()
- {
- CreateDate = DateTime.Now,
- Mobile = MerchantMobile,
- }).Entity;
- maindb.SaveChanges();
- Obj.Add("AuthFlag", AuthFlag);
- }
- return new AppResultJson() { Status = "1", Info = "登录成功", Data = Obj };
- }
- #endregion
- #region 创客-首页-押金查询认证
- [Authorize]
- public JsonResult MerchantAuth(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- AppResultJson result = MerchantAuthDo(value);
- return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
- }
- public AppResultJson MerchantAuthDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- string MerchantMobile = data["MerchantMobile"].ToString(); //商户手机号
- string MerRealName = data["MerRealName"].ToString(); //商户真实姓名
- string MerIdcardNo = data["MerIdcardNo"].ToString(); //商户身份证号
- Dictionary<string, object> Obj = new Dictionary<string, object>();
- string result = IdCardCheckForThree.Instance.Do(MerchantMobile, MerIdcardNo, MerRealName);
- JsonData jsonObj = JsonMapper.ToObject(result);
- if (jsonObj["result_code"].ToString() == "0")
- {
- if (jsonObj["state"].ToString() == "1")
- {
- var check = maindb.UserFamilyMember.Any(m => m.IdCardNo == MerIdcardNo);
- if (check)
- {
- return new AppResultJson() { Status = "-1", Info = "该身份证已认证", Data = Obj };
- }
- else
- {
- var info = maindb.UserFamilyMember.FirstOrDefault(m => m.Mobile == MerchantMobile) ?? new UserFamilyMember();
- info.Status = 1;
- info.UpdateDate = DateTime.Now;
- info.Name = MerRealName;
- info.IdCardNo = MerIdcardNo;
- maindb.SaveChanges();
- var idCard1 = MerIdcardNo.Substring(0, 6);
- var idCard2 = MerIdcardNo.Substring(MerIdcardNo.Length - 4, 4);
- var posMerchantInfoList = maindb.PosMerchantInfo.Where(m => m.MerIdcardNo.StartsWith(idCard1) && m.MerIdcardNo.EndsWith(idCard2) && m.MerchantName.Contains(MerRealName)).ToList();
- foreach (var item in posMerchantInfoList)
- {
- var posMer = posMerchantInfoList.FirstOrDefault(m => m.Id == item.Id) ?? new PosMerchantInfo();
- posMer.MerchantMobile = MerchantMobile;
- posMer.MerRealName = MerRealName;
- posMer.MerIdcardNo = MerIdcardNo;
- maindb.SaveChanges();
- }
- }
- }
- else
- {
- return new AppResultJson() { Status = "-1", Info = jsonObj["result_message"].ToString(), Data = Obj };
- }
- }
- return new AppResultJson() { Status = "1", Info = "", Data = Obj };
- }
- #endregion
- #region 创客-首页-押金查询详情列表
- [Authorize]
- public JsonResult MerchantDepositList(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- List<MerchantDepositList> dataList = MerchantDepositListDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
- }
- public List<MerchantDepositList> MerchantDepositListDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- string MerchantMobile = data["MerchantMobile"].ToString(); //商户手机号
- string MerRealName = data["MerRealName"].ToString(); //商户真实姓名
- string MerIdcardNo = data["MerIdcardNo"].ToString(); //商户身份证号
- int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
- int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
- List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
- List<MerchantDepositList> merchantDepositLists = new List<MerchantDepositList>();
- PosMerchantInfo firstPos = maindb.PosMerchantInfo.FirstOrDefault(m => m.MerIdcardNo == MerIdcardNo && m.MerchantName.Contains(MerRealName) && m.StandardStatus == 1);
- if (firstPos != null)
- {
- merchantDepositLists.Add(PosItem(firstPos));
- }
- IQueryable<PosMerchantInfo> query = maindb.PosMerchantInfo.Where(m => m.MerIdcardNo == MerIdcardNo && m.MerchantName.Contains(MerRealName) && m.StandardStatus != 1).OrderBy(m => m.Id);
- if (PageNum == 1)
- {
- query = query.Take(PageSize);
- }
- else
- {
- int skipNum = PageSize * (PageNum - 1);
- query = query.Skip(skipNum).Take(PageSize);
- }
- foreach (var subdata in query.ToList())
- {
- merchantDepositLists.Add(PosItem(subdata));
- }
- if (firstPos == null)
- {
- merchantDepositLists = merchantDepositLists.OrderBy(m => m.CreateDate).ToList();
- }
- return merchantDepositLists;
- }
- private MerchantDepositList PosItem(PosMerchantInfo subdata)
- {
- MerchantDepositList merchantDepositList = new MerchantDepositList();
- MachineForSnNo forSnNo = maindb.MachineForSnNo.FirstOrDefault(m => m.SnNo == subdata.KqSnNo) ?? new MachineForSnNo();
- PosMachinesTwo pos = maindb.PosMachinesTwo.FirstOrDefault(m => m.Status > -1 && m.Id == forSnNo.SnId) ?? new PosMachinesTwo();
- var depositRreturn = maindb.MerchantDepositReturns.FirstOrDefault(m => m.MerchantId == subdata.Id) ?? new MerchantDepositReturns();
- decimal DepositMoney = decimal.Parse(function.CheckNum(pos.SeoKeyword));
- if (pos.BrandId != 2 && pos.BrandId != 7)
- {
- DepositMoney = DepositMoney / 100;
- }
- //人工已退
- if (subdata.StandardStatus == -2)
- {
- merchantDepositList.Status = -2;
- }
- else
- {
- // 未达标
- if (subdata.StandardMonths < 10)
- {
- merchantDepositList.Status = 0;
- }
- //已达标
- if (subdata.StandardMonths == 10)
- {
- merchantDepositList.Status = 4;
- }
- //达标失败
- if (subdata.StandardMonths >= 0 && subdata.StandardStatus == -1)
- {
- merchantDepositList.Status = -1;
- }
- //已返还
- if (subdata.StandardStatus == 1)
- {
- merchantDepositList.Status = 1;
- }
- //领取达标奖
- if (subdata.StandardStatus == 101)
- {
- merchantDepositList.Status = 101;
- }
- }
- merchantDepositList.MerchantId = subdata.Id;
- merchantDepositList.MerRealName = subdata.MerRealName;
- merchantDepositList.KqSnNo = subdata.KqSnNo;
- merchantDepositList.BrandId = RelationClass.GetKqProductBrandInfo(subdata.BrandId);
- merchantDepositList.CreateDate = Convert.ToDateTime(pos.BindingTime);
- merchantDepositList.DepositMoney = DepositMoney;
- merchantDepositList.Months = subdata.StandardMonths;
- merchantDepositList.TradeAmtForMonth = PosMerchantTradeSummaryDbconn.Instance.GetDateTimeTrade(subdata.Id, DateTime.Now.ToString("yyyyMM"));
- return merchantDepositList;
- }
- #endregion
- #region 创客-首页-押金查询详情添加
- [Authorize]
- public JsonResult CheckDeposit(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- AppResultJson result = CheckDepositDo(value);
- return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
- }
- public AppResultJson CheckDepositDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- string MerchantMobile = data["MerchantMobile"].ToString(); //商户手机号
- string MerRealName = data["MerRealName"].ToString(); //商户真实姓名
- string MerIdcardNo = data["MerIdcardNo"].ToString(); //商户身份证号
- string KqSnNo = data["KqSnNo"].ToString(); //渠道SN号
- if (string.IsNullOrEmpty(MerchantMobile))
- {
- return new AppResultJson() { Status = "-1", Info = "请填写商户手机号" };
- }
- if (MerchantMobile.Length != 11 || !function.IsInt(MerchantMobile) || MerchantMobile.Substring(0, 1) != "1")
- {
- return new AppResultJson() { Status = "-1", Info = "商户手机号不正确" };
- }
- if (string.IsNullOrEmpty(MerRealName))
- {
- return new AppResultJson() { Status = "-1", Info = "请填写商户真实姓名" };
- }
- if (string.IsNullOrEmpty(MerIdcardNo))
- {
- return new AppResultJson() { Status = "-1", Info = "请填写商户身份证号" };
- }
- if (MerIdcardNo.Length != 18 || !function.IsInt(MerIdcardNo.Substring(0, 17)))
- {
- return new AppResultJson() { Status = "-1", Info = "商户身份证号不正确" };
- }
- MerIdcardNo = MerIdcardNo.ToUpper();
- Dictionary<string, object> Obj = new Dictionary<string, object>();
- MachineForSnNo forSnNo = maindb.MachineForSnNo.FirstOrDefault(m => m.SnNo == KqSnNo);
- if (forSnNo == null)
- {
- return new AppResultJson() { Status = "-1", Info = "机具号不存在" };
- }
- //判断机具是否属于该商户
- var mobile1 = MerchantMobile.Substring(0, 3);
- var mobile2 = MerchantMobile.Substring(MerchantMobile.Length - 4, 4);
- var idCard1 = MerIdcardNo.Substring(0, 6);
- var idCard2 = MerIdcardNo.Substring(MerIdcardNo.Length - 4, 4);
- var idCard11 = MerIdcardNo.Substring(0, 4);
- var idCard22 = MerIdcardNo.Substring(MerIdcardNo.Length - 3, 3);
- var idCard23 = MerIdcardNo.Substring(MerIdcardNo.Length - 2, 2);
- var checks = maindb.PosMerchantInfo.FirstOrDefault(m => m.KqSnNo == KqSnNo) ?? new PosMerchantInfo();
- PosMerchantInfo posMerchant = new PosMerchantInfo();
- if (!string.IsNullOrEmpty(checks.MerIdcardNo))
- {
- 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();
- }
- else
- {
- posMerchant = maindb.PosMerchantInfo.FirstOrDefault(m => m.KqSnNo == KqSnNo && m.MerchantMobile.StartsWith(mobile1) && m.MerchantMobile.EndsWith(mobile2) && m.MerchantName.Contains(MerRealName)) ?? new PosMerchantInfo();
- }
- PosMachinesTwo pos = maindb.PosMachinesTwo.FirstOrDefault(m => m.Status > -1 && m.Id == forSnNo.SnId && m.BindMerchantId == posMerchant.Id) ?? new PosMachinesTwo();
- if (pos.Id == 0)
- {
- return new AppResultJson() { Status = "-1", Info = "该机具不在您的名下或不存在" };
- }
- if (pos.ActivationState == 0)
- {
- return new AppResultJson() { Status = "-1", Info = "机具未激活" };
- }
- if ((!function.CheckNull(posMerchant.MerIdcardNo).Contains("*") || !function.CheckNull(posMerchant.MerchantMobile).Contains("*")) && !string.IsNullOrEmpty(posMerchant.MerIdcardNo) && pos.BrandId != 6)
- {
- return new AppResultJson() { Status = "-1", Info = "该机具已添加" };
- }
- if (!function.CheckNull(posMerchant.MerIdcardNo).Contains("*") && !string.IsNullOrEmpty(posMerchant.MerIdcardNo) && pos.BrandId == 6)
- {
- return new AppResultJson() { Status = "-1", Info = "该机具已添加" };
- }
- int IsFirst = 1;
- bool check = maindb.PosMerchantInfo.Any(m => m.MerIdcardNo == MerIdcardNo);
- if (check)
- {
- IsFirst = 0;
- }
- PosMerchantInfo query = maindb.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
- if (query != null)
- {
- query.UpdateDate = DateTime.Now; //修改时间
- query.MerchantMobile = MerchantMobile; //商户手机号
- query.MerRealName = MerRealName; //商户真实姓名
- query.MerIdcardNo = MerIdcardNo; //商户身份证号
- query.Sort = IsFirst;
- maindb.SaveChanges();
- return new AppResultJson() { Status = "1", Info = "", Data = Obj };
- }
- return new AppResultJson() { Status = "-1", Info = "查无此商户", Data = Obj };
- }
- #endregion
- #region 创客-首页-押金查询-商户详情
- [Authorize]
- public JsonResult Detail(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- Dictionary<string, object> Obj = DetailDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
- }
- public Dictionary<string, object> DetailDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- Dictionary<string, object> Obj = new Dictionary<string, object>();
- int MerchantId = int.Parse(function.CheckInt(data["MerchantId"].ToString()));
- PosMerchantInfo query = PosMerchantInfoDbconn.Instance.Get(MerchantId) ?? new PosMerchantInfo();
- MachineForMerNo forMerNo = maindb.MachineForMerNo.FirstOrDefault(m => m.MerNo == query.KqMerNo) ?? new MachineForMerNo();
- Obj.Add("MerRealName", query.MerRealName); //商户真实姓名
- Obj.Add("KqSnNo", query.KqSnNo); //渠道SN号
- Obj.Add("KqSnId", forMerNo.SnId); //机具Id
- Obj.Add("ProductType", RelationClass.GetKqProductBrandInfo(query.BrandId)); //来源产品
- Obj.Add("TradeTotal", PosMerchantTradeSummaryDbconn.Instance.GetTrade(query.Id)); //总交易额
- return Obj;
- }
- #endregion
- #region 创客-首页-押金查询-商户详情-交易统计
- [Authorize]
- public JsonResult MerchantTradeList(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- Dictionary<string, object> Other = new Dictionary<string, object>();
- List<Dictionary<string, object>> dataList = MerchantTradeListDo(value, out Other);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Other });
- }
- public List<Dictionary<string, object>> MerchantTradeListDo(string value, out Dictionary<string, object> Other)
- {
- JsonData data = JsonMapper.ToObject(value);
- string TradeMonth = data["TradeMonth"].ToString(); //交易月
- int MerchantId = int.Parse(data["MerchantId"].ToString()); //商户Id
- int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
- int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
- List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
- var query = maindb.PosMerchantTradeSummay.Where(m => m.MerchantId == MerchantId && m.TradeMonth == TradeMonth);
- if (PageNum == 1)
- {
- query = query.Take(PageSize);
- }
- else
- {
- int skipNum = PageSize * (PageNum - 1);
- query = query.Skip(skipNum).Take(PageSize);
- }
- foreach (var DateString in query.ToList())
- {
- Dictionary<string, object> curData = new Dictionary<string, object>();
- curData.Add("TradeDate", DateString.TradeDate); //交易日
- curData.Add("TradeAmt", DateString.TradeAmount); //交易额
- dataList.Add(curData);
- }
- Other = new Dictionary<string, object>();
- Other.Add("MonthTradeAmt", PosMerchantTradeSummaryDbconn.Instance.GetDateTimeTrade(MerchantId, TradeMonth));
- return dataList;
- }
- #endregion
- #region 创客-首页-押金查询-详情
- [Authorize]
- public JsonResult DepositMerchantList(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- List<Dictionary<string, object>> dataList = DepositMerchantListDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
- }
- public List<Dictionary<string, object>> DepositMerchantListDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- string MerIdcardNo = data["MerIdcardNo"].ToString(); //商户身份证号
- int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
- int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
- List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
- IQueryable<PosMerchantInfo> query = maindb.PosMerchantInfo.Where(m => m.MerIdcardNo == MerIdcardNo).OrderBy(m => m.Id);
- if (PageNum == 1)
- {
- query = query.Take(PageSize);
- }
- else
- {
- int skipNum = PageSize * (PageNum - 1);
- query = query.Skip(skipNum).Take(PageSize);
- }
- int index = 0;
- foreach (var subdata in query.ToList())
- {
- index += 1;
- Dictionary<string, object> curData = new Dictionary<string, object>();
- curData.Add("Id", subdata.Id);
- curData.Add("MerRealName", subdata.MerRealName); //商户真实姓名
- curData.Add("KqSnNo", subdata.KqSnNo); //渠道SN号
- curData.Add("BrandId", RelationClass.GetKqProductBrandInfo(subdata.BrandId)); //品牌
- curData.Add("CreateDate", subdata.CreateDate == null ? "" : subdata.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //CreateDate
- MachineForSnNo forSnNo = maindb.MachineForSnNo.FirstOrDefault(m => m.SnNo == subdata.KqSnNo) ?? new MachineForSnNo();
- PosMachinesTwo pos = maindb.PosMachinesTwo.FirstOrDefault(m => m.Status > -1 && m.Id == forSnNo.SnId) ?? new PosMachinesTwo();
- decimal DepositMoney = decimal.Parse(function.CheckNum(pos.SeoKeyword));
- if (pos.BrandId != 2 && pos.BrandId != 7)
- {
- DepositMoney = DepositMoney / 100;
- }
- curData.Add("DepositMoney", DepositMoney.ToString("f2")); //押金金额
- int Months = 0;
- int Status = 0;
- string MonthString = "";
- if (pos.BindingState == 1)
- {
- DateTime start = DateTime.Parse(subdata.CreateDate.Value.AddMonths(1).ToString("yyyy-MM") + "-01 00:00:00");
- DateTime end = DateTime.Parse(DateTime.Now.ToString("yyyy-MM") + "-01 00:00:00");
- while (start <= end)
- {
- decimal checkTrade = PosMerchantTradeSummaryDbconn.Instance.GetDateTimeTrade(subdata.Id, start.ToString("yyyyMM"));
- if (checkTrade >= 10000)
- {
- Months += 1;
- start = start.AddMonths(1);
- Status = 1;
- }
- else
- {
- if (start.ToString("yyyy-MM") != DateTime.Now.ToString("yyyy-MM"))
- {
- Months = start.Month;
- MonthString = start.ToString("yyyy-MM");
- start = end.AddSeconds(1);
- Status = 5;
- }
- else
- {
- start = start.AddMonths(1);
- }
- }
- }
- }
- curData.Add("Status", Status); //返押状态
- if (Status == 5)
- {
- curData.Add("Months", MonthString); //未达标月
- }
- else
- {
- curData.Add("Months", Months); //连续达标月数
- }
- curData.Add("TradeAmtForMonth", PosMerchantTradeSummaryDbconn.Instance.GetDateTimeTrade(subdata.Id, DateTime.Now.ToString("yyyyMM"))); //本月交易额
- curData.Add("DepositStatus", 0); //返押状态
- curData.Add("MerType", index == 1 ? 1 : 0); //机具类型
- dataList.Add(curData);
- }
- return dataList;
- }
- #endregion
- #region 创客-首页-押金查询-退押金-确认信息
- [Authorize]
- public JsonResult ReturnDepositForConfirm(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- Dictionary<string, object> Obj = ReturnDepositForConfirmDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
- }
- public Dictionary<string, object> ReturnDepositForConfirmDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- Dictionary<string, object> Obj = new Dictionary<string, object>();
- int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
- PosMerchantInfo query = maindb.PosMerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new PosMerchantInfo();
- Obj.Add("MerchantMobile", query.MerchantMobile); //商户手机号
- Obj.Add("MerRealName", query.MerRealName); //商户真实姓名
- Obj.Add("MerIdcardNo", query.MerIdcardNo); //商户身份证号
- return Obj;
- }
- #endregion
- #region 通过机具Id查询机具号和商户名称
- [Authorize]
- public JsonResult SearchInfo(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- Dictionary<string, object> Obj = SearchInfoDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
- }
- public Dictionary<string, object> SearchInfoDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- Dictionary<string, object> Obj = new Dictionary<string, object>();
- int SnId = int.Parse(function.CheckInt(data["SnId"].ToString()));
- int IsOk = 0;
- PosMachinesTwo pos = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == SnId) ?? new PosMachinesTwo();
- if (pos.BuyUserId != pos.UserId)
- {
- IsOk = 1;
- }
- PosMerchantInfo query = maindb.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
- string Name = Regex.Replace(function.CheckNull(query.MerchantName), "[0-9][a-zA-Z]", "");
- Obj.Add("IsOk", IsOk); //是否商户型创客
- Obj.Add("PosSn", pos.PosSn); //机具号
- Obj.Add("MerchantName", Name); //商户名称
- return Obj;
- }
- #endregion
- #region 检查签名是否合法,合法返回1,不合法返回提示信息
- /// <summary>
- /// 检查签名是否合法,合法返回1,不合法返回提示信息
- /// </summary>
- /// <param name="value">请求的参数(json字符串)</param>
- /// <param name="signField">要签名的字段</param>
- /// <returns></returns>
- private string CheckSign(string value, string[] signField)
- {
- JsonData json = JsonMapper.ToObject(value);
- Dictionary<string, string> dic = new Dictionary<string, string>();
- for (int i = 0; i < signField.Length; i++)
- {
- dic.Add(signField[i], json[signField[i]].ToString());
- }
- string sign = json["sign"].ToString(); //客户端签名字符串
- return new Sign().sign(dic, sign);
- }
- #endregion
- }
- }
|