| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Http;
- using Microsoft.Extensions.Logging;
- using Microsoft.Extensions.Options;
- using System.Collections.Generic;
- using LitJson;
- using Library;
- using System.Linq;
- using System;
- using MySystem.MainModels;
- using System.IO;
- namespace MySystem.Areas.Api.Controllers.v1
- {
- public class OutApiController : BaseController
- {
- public OutApiController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
- {
- }
- #region 设置服务费
- [Route("/api/v1/deposit/set")]
- public JsonResult SetDeposit()
- {
- StreamReader sr = new StreamReader(Request.Body);
- string requestMes = sr.ReadToEnd();
- JsonData data = JsonMapper.ToObject(requestMes);
- Dictionary<string, object> req = new Dictionary<string, object>();
- string PosSn = data["posSn"].ToString();
- PosMachinesTwo pos = maindb.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
- if(pos == null)
- {
- return Json(new AppResultJson() { Status = "-1", Info = "机具号不正确" });
- }
- req.Add("PosSnId", pos.Id);
- req.Add("BrandId", data["brandId"].ToString());
- req.Add("Deposit", data["deposit"].ToString());
- string CallBackUrl = "";
- if(requestMes.Contains("\"callBackUrl\""))
- {
- CallBackUrl = data["callBackUrl"].ToString();
- }
- req.Add("CallBackUrl", CallBackUrl);
- RedisDbconn.Instance.AddList("ChangePosFeeQueue", Newtonsoft.Json.JsonConvert.SerializeObject(req));
- return Json(new AppResultJson() { Status = "1", Info = "" });
- }
- #endregion
- #region 设置费率
- [Route("/api/v1/fee/set")]
- public JsonResult SetFee()
- {
- StreamReader sr = new StreamReader(Request.Body);
- string requestMes = sr.ReadToEnd();
- JsonData data = JsonMapper.ToObject(requestMes);
- string PosSn = data["posSn"].ToString();
- PosMachinesTwo pos = maindb.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
- if(pos == null)
- {
- return Json(new AppResultJson() { Status = "-1", Info = "机具号不正确" });
- }
- int PosId = pos.Id;
- int BrandId = int.Parse(data["brandId"].ToString());
- decimal FeeRate = decimal.Parse(data["feeRate"].ToString());
- int FeeExtra = int.Parse(data["feeExtra"].ToString());
- string CallBackUrl = "";
- if(requestMes.Contains("\"callBackUrl\""))
- {
- CallBackUrl = data["callBackUrl"].ToString();
- }
- PosMerchantInfo mer = maindb.PosMerchantInfo.FirstOrDefault(m => m.Id == PosId) ?? new PosMerchantInfo();
- PosMachinesFeeChangeRecord query = maindb.PosMachinesFeeChangeRecord.FirstOrDefault(m => m.PosId == PosId && m.Status == 0);
- if(query == null)
- {
- query = maindb.PosMachinesFeeChangeRecord.Add(new PosMachinesFeeChangeRecord()
- {
- CreateDate = DateTime.Now, //创建时间
- PosId = PosId, //机具Id
- }).Entity;
- maindb.SaveChanges();
- }
- query.UpdateDate = DateTime.Now; //创建时间
- query.Sort = pos.BrandId; //品牌Id
- query.UserId = pos.BuyUserId; //创客
- query.PosId = PosId; //机具Id
- query.PosSn = pos.PosSn;
- query.MerNo = mer.MerchantNo;
- query.MerchantId = mer.Id;
- query.PosUserId = pos.BuyUserId; //机具所属人
- query.ChangeFee = FeeRate; //调整费率
- maindb.SaveChanges();
- int ChangeKind = 0;
- if(FeeRate == 0.63M && FeeExtra == 3)
- {
- ChangeKind = 1;
- }
- else if(FeeRate == 0.63M && FeeExtra == 0)
- {
- ChangeKind = 2;
- }
- else if(FeeRate == 0.6M && FeeExtra == 0)
- {
- ChangeKind = 3;
- }
- // PosId:机具Id
- // Kind:1或2,1为费率0.63+3,2为费率0.63,3为费率0.6
- // OpMan:操作人,app传创客编号,后台传SysUserName
- string info = "{\"RecordId\":\"" + query.Id + "\",\"PosId\":\"" + pos.Id + "\",\"Fee\": \"" + FeeRate.ToString("f0").TrimEnd('0') + "\",\"Kind\": \"" + ChangeKind + "\",\"OpMan\": \"接口\",\"CallBackUrl\":\"" + CallBackUrl + "\"}";
- RedisDbconn.Instance.AddList("SetDepositQueue", info);
- return Json(new AppResultJson() { Status = "1", Info = "" });
- }
- #endregion
- // [Route("/api/v1/{c1}/{c2}")]
- // public JsonResult ToApServer(string c1, string c2, string value)
- // {
- // string apis = function.CheckNull(RedisDbconn.Instance.Get<string>("ToApServer"));
- // function.WriteLog(DateTime.Now.ToString() + "\n" + value, "接口转发日志");
- // string hasDo = "";
- // if (apis.Contains(c1 + "/" + c2))
- // {
- // value = dbconn.DesEncrypt(value, "*ga34|^7");
- // }
- // else
- // {
- // hasDo = "do";
- // }
- // function.WriteLog(value, "接口转发日志");
- // string url = AppConfig.Base.ApHost + "api/v1/" + c1 + "/" + c2 + hasDo;
- // function.WriteLog(url, "接口转发日志");
- // string result = function.PostWebRequest(url, "value=" + value);
- // function.WriteLog(str: result, "接口转发日志");
- // JsonData data = JsonMapper.ToObject(result);
- // if(result.Contains("\"status\""))
- // {
- // return Json(new AppResultJson() { Status = data["status"].ToString(), Data = data["data"].ToJson(), Info = data["info"].ToString(), Other = data["other"] == null ? "" : data["other"].ToJson(), Timestamp = int.Parse(function.CheckInt(data["timestamp"].ToString())) });
- // }
- // return Json(new AppResultJson() { Status = "1", Data = result, Info = "" });
- // }
- }
- }
|