123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- 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 MySystem.MainModels;
- using LitJson;
- using Library;
- using MySystem.Service.Main;
- using LKBAAlipayConfig;
- namespace MySystem.Areas.Api.Controllers.v1
- {
- [Area("Api")]
- [Route("/v1/qrcodeplatemain/[controller]/[action]")]
- public class MerchantDepositOrderController : BaseController
- {
- public MerchantDepositOrderController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
- {
- }
- #region 商户激活-确认支付
- [Authorize]
- public JsonResult Pay(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- AppResultJson result = PayDo(value);
- return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
- }
- private AppResultJson PayDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- int PayMode = int.Parse(function.CheckInt(data["PayMode"].ToString())); //支付方式(1 支付宝)
- int MerchantId = int.Parse(function.CheckInt(data["MerchantId"].ToString())); //商户Id
- int Id = int.Parse(function.CheckInt(data["Id"].ToString())); //订单记录Id
- Dictionary<string, object> Obj = new Dictionary<string, object>();
- var query = new MerchantDepositOrderService().QueryById(Id);
- if (query.Id > 0)
- {
- Dictionary<string, object> fields = new Dictionary<string, object>();
- fields.Add("Sort", PayMode); //支付方式(1 支付宝)
- MerchantDepositOrderService.Edit(fields, Id, false);
- string PayData = "";
- if (PayMode == 1)
- {
- string TotalPrice = query.ActPayPrice.ToString();
- function.WriteLog(query.OrderNo, "支付宝支付日志");
- function.WriteLog(TotalPrice.ToString(), "支付宝支付日志");
- function.WriteLog("商户激活—确认订单", "支付宝支付日志");
- string ProductName = "商户激活";
- PayData = new Alipay.AlipayPublicClass(_accessor.HttpContext).GetAlipayInfo(query.OrderNo, TotalPrice, ProductName, LKBAliPayInfo.AppId, LKBAliPayInfo.PrivateKey, SpHost + "/Api/Alipay/NoticePay2");
- function.WriteLog(PayData, "支付宝支付日志");
- }
- Obj.Add("PayData", PayData); //支付宝微信SDK所需数据
- }
- return new AppResultJson() { Status = "1", Info = "", Data = Obj };
- }
- #endregion
- #region 商户激活-确认订单
- [Authorize]
- public JsonResult ConfirmOrder(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- AppResultJson result = ConfirmOrderDo(value);
- return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
- }
- private AppResultJson ConfirmOrderDo(string value)
- {
- function.WriteLog(value, "商户激活—确认订单");
- JsonData data = JsonMapper.ToObject(value);
- int MerchantId = int.Parse(function.CheckInt(data["MerchantId"].ToString())); //商户Id
- Dictionary<string, object> Obj = new Dictionary<string, object>();
- MerchantInfo merchant = new MerchantInfoService().Query(MerchantId);
- string OrderNo = "D" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
- string check = RedisDbconn.Instance.Get<string>("ConfirmOrder:" + MerchantId + "_" + OrderNo);
- if (!string.IsNullOrEmpty(check))
- {
- return new AppResultJson() { Status = "-1", Info = "请勿重复下单!" };
- }
- RedisDbconn.Instance.Set("ConfirmOrder:" + MerchantId + "_" + OrderNo, "1");
- RedisDbconn.Instance.SetExpire("ConfirmOrder:" + MerchantId + "_" + OrderNo, 10);
- var IsBuy = new MerchantDepositOrderService().QueryByMerchantId(MerchantId);
- if (IsBuy.Id > 0) return new AppResultJson() { Status = "-1", Info = "请勿重复下单!" };
- decimal ActPayPrice = 365; //服务费总额
- var Id = MerchantDepositOrderUtil.AddMerchantDepositOrder(OrderNo, merchant.UserId, MerchantId, ActPayPrice);
- var query = new MerchantDepositOrderService().QueryById(Id);
- Obj.Add("Id", Id); //Id
- Obj.Add("CreateDate", query.CreateDate); //创建时间
- return new AppResultJson() { Status = "1", Info = "", Data = Obj };
- }
- #endregion
- #region 已激活商户-活动时间
- [Authorize]
- public JsonResult Info(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- AppResultJson result = InfoDo(value);
- return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
- }
- private AppResultJson InfoDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- int MerchantId = int.Parse(function.CheckInt(data["MerchantId"].ToString())); //商户Id
- Dictionary<string, object> Obj = new Dictionary<string, object>();
- var CreateDate = "";
- var StartDate = "";
- var EndDate = "";
- var Status = -1;
- var query = new MerchantDepositOrderService().QueryByMerchantId(MerchantId);
- if (query.Id > 0)
- {
- CreateDate = DateTime.Parse(query.UpdateDate.ToString()).Year + "年" + DateTime.Parse(query.UpdateDate.ToString()).Month + "月" + DateTime.Parse(query.UpdateDate.ToString()).Day + "日";
- StartDate = DateTime.Parse(query.UpdateDate.ToString()).AddMonths(1).Year + "年" + DateTime.Parse(query.UpdateDate.ToString()).AddMonths(1).Month + "月";
- EndDate = DateTime.Parse(query.UpdateDate.ToString()).AddMonths(11).Year + "年" + DateTime.Parse(query.UpdateDate.ToString()).AddMonths(11).Month + "月";
- Status = new MerchantInfoService().Query(MerchantId).ExamineStatus;
- }
- Obj.Add("CreateDate", CreateDate); //参与时间
- Obj.Add("StartDate", StartDate); //考核开始时间
- Obj.Add("EndDate", EndDate); //考核结束时间
- Obj.Add("Status", Status); //考核状态(-1 未参与 0 考核中 1 已通过 2 未通过 101 待领取 100 已领取 99 发放中)
- return new AppResultJson() { Status = "1", Info = "", Data = 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
- }
- }
|