增加外部调用Apikey.
可以外部调用API 图片库扣费 bxx 商品库 增加API
This commit is contained in:
1 parent
08f8e2009f
commit
0e38a1e31f
13 files changed
+275
-3
No files matched your search
@@ -4358,6 +4358,33 @@ namespace KJD_Web.BLL.BXX
|
||||
return "{\"code\":19999,\"msg\":\"输入为空\"}";
|
||||
}
|
||||
|
||||
|
||||
public string SaveProductSafety(string inputData)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(inputData))
|
||||
{
|
||||
var timeCalc = DateTime.Now;
|
||||
if (!WXUserManage.GetSign(inputData))
|
||||
return "{\"code\":999,\"msg\":\"校验失败\"}";
|
||||
|
||||
int id = RegexUtils.GetStringQuery(ref inputData, "id").ParseToInt();
|
||||
|
||||
string conn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnKJD"].ConnectionString;
|
||||
MysqlUtils mySql = new MysqlUtils(conn);
|
||||
|
||||
string sql = "";
|
||||
var count = -1;
|
||||
|
||||
sql = "UPDATE bxx.product set is_safe=1 WHERE id="+id;
|
||||
|
||||
count = mySql.ExecuteAffectedRows(sql);
|
||||
|
||||
mySql.Close();
|
||||
return "{\"code\":200,\"msg\":\"success\"}";
|
||||
}
|
||||
return "{\"code\":19999,\"msg\":\"输入为空\"}";
|
||||
}
|
||||
|
||||
//public string XJGetAiImage(string inputData)
|
||||
//{
|
||||
// if (string.IsNullOrEmpty(inputData))
|
||||
|
||||
@@ -138,6 +138,7 @@ namespace KJD_Web.BLL.WXXD
|
||||
postage_per_order = row.Table.Columns.Contains("postage_per_order") ? row["postage_per_order"].ParseToNullableDecimal() : null,
|
||||
refund_postage_per_order = row.Table.Columns.Contains("refund_postage_per_order") ? row["refund_postage_per_order"].ParseToNullableDecimal() : null,
|
||||
gift_oem_amount_per_order = row.Table.Columns.Contains("gift_oem_amount_per_order") ? row["gift_oem_amount_per_order"].ParseToNullableDecimal() : null,
|
||||
image_analysis_quota = row.Table.Columns.Contains("image_analysis_quota") ? row["image_analysis_quota"].ParseToInt() : 0,
|
||||
};
|
||||
var main_authority = row.Table.Columns.Contains("main_authority") ? row["main_authority"].ParseToString() : "";
|
||||
var main_oem_id = row.Table.Columns.Contains("main_oem_id") ? row["main_oem_id"].ParseToString() : "";
|
||||
|
||||
@@ -444,5 +444,17 @@ namespace KJD_Web.Controllers.BXX
|
||||
|
||||
return JsonString(result);
|
||||
}
|
||||
|
||||
|
||||
public IHttpActionResult SaveProductSafety()
|
||||
{
|
||||
string jsontext = GetRequestJsonString();
|
||||
|
||||
var result = jsontext;
|
||||
result = new BXXProductManage().SaveProductSafety(jsontext);
|
||||
|
||||
return JsonString(result);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -4,10 +4,12 @@ using KJD_Web.Services.Users;
|
||||
using MAX.Core.Logger;
|
||||
using NaiBa.Util.Extension;
|
||||
using Org.BouncyCastle.Ocsp;
|
||||
using Store.Framework.DependencyInjection;
|
||||
using Store.Framework.Dtos;
|
||||
using Store.Framework.Models;
|
||||
using System;
|
||||
using System.Web.Http;
|
||||
using Ubiety.Dns.Core;
|
||||
|
||||
namespace KJD_Web.Controllers
|
||||
{
|
||||
@@ -15,9 +17,11 @@ namespace KJD_Web.Controllers
|
||||
{
|
||||
private readonly UserService _userService;
|
||||
private readonly ILoggerFacade _logger;
|
||||
|
||||
private readonly string OpenApiKey;
|
||||
public WXUserController(UserService userService, ILoggerFacade logger)
|
||||
{
|
||||
OpenApiKey = System.Configuration.ConfigurationManager.AppSettings["OpenApiKey"].ParseToString();
|
||||
|
||||
_userService = userService ?? throw new ArgumentNullException(nameof(userService));
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
}
|
||||
@@ -147,5 +151,64 @@ namespace KJD_Web.Controllers
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 购买图片检测配额
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IHttpActionResult BuyImageAnalysisQuota(ImageAnalysisRequest request)
|
||||
{
|
||||
if (!ValidateSign(request))
|
||||
{
|
||||
return Ok(ApiResult.Fail("校验失败", 999));
|
||||
}
|
||||
try
|
||||
{
|
||||
var response = _userService.BuyImageAnalysisQuota(request);
|
||||
return Ok(ApiResult.Success(response, "兑换成功"));
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
return Ok(ApiResult.Fail(ex.Message, ResultCode.ValidationError));
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
return Ok(ApiResult.Fail(ex.Message, ResultCode.BusinessError));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error(ex, "积分购买图片检测, UserName=" + (request == null ? null : request.UserName) + ", ShopId=" + (request == null ? null : request.Amount));
|
||||
return Ok(ApiResult.Fail("购买图片检测失败,请稍后重试", ResultCode.ServerError));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 外部调用 图片检测配额消费
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IHttpActionResult UseImageAnalysisQuota(string token, string userName)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (token != OpenApiKey)
|
||||
{
|
||||
return Ok(ApiResult.Fail("调用失败"));
|
||||
}
|
||||
if (userName == null)
|
||||
{
|
||||
throw new InvalidOperationException("不存在的用户");
|
||||
}
|
||||
var ret = _userService.UseImageAnalysisQuota(userName);
|
||||
return Ok(ApiResult.Success(ret, "兑换成功"));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error(ex, "外部调用失败");
|
||||
return Ok(ApiResult.Fail("消耗检图失败,请稍后重试", ResultCode.ServerError));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -228,6 +228,7 @@
|
||||
<Compile Include="Requests\Shops\ShopStatsGroupType.cs" />
|
||||
<Compile Include="Requests\Shops\ShopStatsRequest.cs" />
|
||||
<Compile Include="Requests\Users\CUUserInfoRequest.cs" />
|
||||
<Compile Include="Requests\Users\PurchaseImageQuotaRequest.cs" />
|
||||
<Compile Include="Requests\Users\RebateRecordRequest.cs" />
|
||||
<Compile Include="Requests\Users\UserConfigRequest.cs" />
|
||||
<Compile Include="Responses\Shops\ShopOrderDetailResponse.cs" />
|
||||
@@ -278,6 +279,7 @@
|
||||
<Compile Include="Requests\Users\ShopRenewRequest.cs" />
|
||||
<Compile Include="Services\ImageCacheService.cs" />
|
||||
<Compile Include="Services\Buyer\BuyerService.cs" />
|
||||
<Compile Include="Services\Products\ProductService.cs" />
|
||||
<Compile Include="Services\Shops\ShopRevenueStatisticsService.cs" />
|
||||
<Compile Include="Services\Shops\ShopService.cs" />
|
||||
<Compile Include="Services\Shops\ShopStatsJob.cs" />
|
||||
|
||||
@@ -112,6 +112,6 @@ namespace KJD_Web.Model
|
||||
/// 店铺续租平台保底金额 有OEM 平台默认抽成15
|
||||
/// </summary>
|
||||
public decimal? shop_renewal_platform_floor_fee { get; set; }
|
||||
|
||||
public int image_analysis_quota { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using Store.Framework.Dtos;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace KJD_Web.Requests.Users;
|
||||
|
||||
/// <summary>
|
||||
/// 购买图片检测配额
|
||||
/// </summary>
|
||||
public class ImageAnalysisRequest : SignRequestBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 购买金额
|
||||
/// </summary>
|
||||
public int Amount { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace KJD_Web.Services.Products;
|
||||
|
||||
public class ProductService
|
||||
{
|
||||
}
|
||||
@@ -6,6 +6,7 @@ using KJD_Web.Requests.Users;
|
||||
using KJD_Web.Utils;
|
||||
using MAX.Core.DependencyInjection;
|
||||
using MAX.Core.Logger;
|
||||
using MySqlX.XDevAPI.Relational;
|
||||
using NaiBa.Util.Extension;
|
||||
using Store.Contracts.Order.Entitys;
|
||||
using Store.Contracts.User.Entitys;
|
||||
@@ -31,7 +32,10 @@ namespace KJD_Web.Services.Users
|
||||
private const int ShopIdMaxLength = 50;
|
||||
private const int RemarkMaxLength = 255;
|
||||
private const int MaxRenewDuration = 120;
|
||||
|
||||
/// <summary>
|
||||
/// AI图片包 1张 价格 分
|
||||
/// </summary>
|
||||
private const int AIImageAmount = 1;
|
||||
private readonly IFreeSql _freeSql;
|
||||
private readonly ILoggerFacade _logger;
|
||||
|
||||
@@ -243,6 +247,50 @@ namespace KJD_Web.Services.Users
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 购买图片检测购买份额
|
||||
/// 最少1块钱
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
public int BuyImageAnalysisQuota(ImageAnalysisRequest request)
|
||||
{
|
||||
if (request == null) throw new ArgumentException("请求参数不能为空", nameof(request));
|
||||
if (string.IsNullOrWhiteSpace(request.UserName)) throw new ArgumentException("用户名不能为空", nameof(request.UserName));
|
||||
if (request.Amount == 0) throw new ArgumentException("购买金额不能小于1积分");
|
||||
|
||||
int ImageQuota = request.Amount * (AIImageAmount * 100);//检测图片配额数量
|
||||
using var work = _freeSql.CreateUnitOfWork();
|
||||
var trFreeSql = work.Orm;
|
||||
try
|
||||
{
|
||||
UserPointsPayment(request.UserName, request.Amount, PointsTypes.AI识图包, work.GetOrBeginTransaction());
|
||||
var affrows = trFreeSql.Update<UserEntity>()
|
||||
.Set(a => a.ImageAnalysisQuota + ImageQuota)
|
||||
.Where(a => a.UserName == request.UserName)
|
||||
.ExecuteAffrows();
|
||||
if (affrows != 1)
|
||||
{
|
||||
throw new InvalidOperationException("账户已发生改变,请刷新账户后重新操作");
|
||||
}
|
||||
work.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
work.Rollback();
|
||||
throw ex;
|
||||
}
|
||||
return ImageQuota;
|
||||
}
|
||||
|
||||
public bool UseImageAnalysisQuota(string userName)
|
||||
{
|
||||
var affrows = _freeSql.Update<UserEntity>()
|
||||
.Set(a => a.ImageAnalysisQuota - 1)
|
||||
.Where(a => a.UserName == userName)
|
||||
.ExecuteAffrows();
|
||||
return affrows == 1;
|
||||
}
|
||||
|
||||
private static void ValidateRequest(ShopRenewRequest request)
|
||||
{
|
||||
if (request == null)
|
||||
@@ -479,6 +527,57 @@ namespace KJD_Web.Services.Users
|
||||
work.Commit();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 积分消费
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
private void UserPointsPayment(string userName, int pointsCost, PointsTypes type, DbTransaction tarn = null)
|
||||
{
|
||||
using var work = tarn != null ? _freeSql.CreateUnitOfWork(tarn) : _freeSql.CreateUnitOfWork();
|
||||
var trFreeSql = work.Orm;
|
||||
if (pointsCost <= 0) throw new Exception("积分消耗不能小于1");
|
||||
var user = GetUserByUserName(userName);
|
||||
if (user == null)
|
||||
{
|
||||
throw new Exception("用户不存在");
|
||||
}
|
||||
if (user.Points < pointsCost) throw new Exception("余额不足");
|
||||
if (type != PointsTypes.AI识图包) throw new Exception("不支持的类型");
|
||||
var payItem = new UserPointsRecordEntity
|
||||
{
|
||||
UserName = userName,
|
||||
UserNick = user.NickName,
|
||||
DeltaPoints = pointsCost,
|
||||
OptionType = type.ToString(),
|
||||
OperatorType = "用户",
|
||||
OperatorName = userName,
|
||||
Remark = type.ToString(),
|
||||
AddTime = DateTime.Now,
|
||||
};
|
||||
|
||||
payItem.NewPoints = user.Points - payItem.DeltaPoints;
|
||||
var affrows = trFreeSql.Insert<UserPointsRecordEntity>(payItem).ExecuteAffrows();
|
||||
if (affrows != 1)
|
||||
{
|
||||
_logger.Error($"积分消费失败:{userName},{type}");
|
||||
throw new Exception("积分消费失败");
|
||||
}
|
||||
affrows = trFreeSql.Update<UserEntity>()
|
||||
.Set(a => a.Points, payItem.NewPoints)
|
||||
.Where(a => a.UserName == user.UserName)
|
||||
.Where(a => a.Points >= payItem.DeltaPoints)
|
||||
.ExecuteAffrows();
|
||||
if (affrows != 1)
|
||||
{
|
||||
_logger.Error($"积分消费失败,余额不足:{userName},{type}");
|
||||
throw new Exception("余额不足");
|
||||
}
|
||||
if (tarn == null)
|
||||
work.Commit();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户配置
|
||||
/// </summary>
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
<add key="Hangfire:Password" value="hangadmin" />-->
|
||||
<!--是否启用后台任务-->
|
||||
<add key="BackgroundJobs" value="false"/>
|
||||
<!--第三方调用API 直接走token-->
|
||||
<add key="OpenApiKey" value="e3b0c44298fc1c149afbf4c8996fb924"/>
|
||||
</appSettings>
|
||||
<!--
|
||||
有关 web.config 更改的说明,请参见 http://go.microsoft.com/fwlink/?LinkId=235367。
|
||||
|
||||
@@ -166,6 +166,11 @@ namespace Store.Contracts.User.Entitys
|
||||
[Column(Name = "shop_renewal_platform_floor_fee")]
|
||||
public decimal ShopRenewalPlatformFloorFee { get; set; } = 15;
|
||||
|
||||
/// <summary>
|
||||
/// 图片检测份额
|
||||
/// </summary>
|
||||
[Column(Name = "image_analysis_quota")]
|
||||
public int ImageAnalysisQuota { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否主账户
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Store.Contracts.User.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// 积分类型
|
||||
/// </summary>
|
||||
public enum PointsTypes
|
||||
{
|
||||
充值,
|
||||
续费,
|
||||
转入,
|
||||
转出,
|
||||
支付宝充值,
|
||||
AI识图包,
|
||||
}
|
||||
@@ -103,6 +103,19 @@ internal class UserTest
|
||||
var data = userService.GetUserAmountSummary("17734871710");
|
||||
Console.WriteLine(JsonConvert.SerializeObject(data));
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void BuyImageAnalysisQuota()
|
||||
{
|
||||
var userService = _container.Resolve<UserService>();
|
||||
var data = userService.BuyImageAnalysisQuota(new KJD_Web.Requests.Users.ImageAnalysisRequest
|
||||
{
|
||||
UserName = "18990991234",
|
||||
Amount = 1
|
||||
});
|
||||
Console.WriteLine(JsonConvert.SerializeObject(data));
|
||||
}
|
||||
//[Test]
|
||||
//public void Fill()
|
||||
//{
|
||||
|
||||
Reference in new issue
Block a user