增加外部调用Apikey.

可以外部调用API 图片库扣费
bxx 商品库 增加API
This commit is contained in:
chfei committed 2026-11-06 19:24:34 +08:00
1 parent 08f8e2009f
commit 0e38a1e31f
13 files changed
+443 -171

No files matched your search

@@ -4358,6 +4358,33 @@ namespace KJD_Web.BLL.BXX
return "{\"code\":19999,\"msg\":\"输入为空\"}"; 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) //public string XJGetAiImage(string inputData)
//{ //{
// if (string.IsNullOrEmpty(inputData)) // if (string.IsNullOrEmpty(inputData))
+1
View File
@@ -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, 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, 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, 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_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() : ""; var main_oem_id = row.Table.Columns.Contains("main_oem_id") ? row["main_oem_id"].ParseToString() : "";
@@ -18,375 +18,375 @@ namespace KJD_Web.Controllers.BXX
{ {
public IHttpActionResult get_product_spu_id_list() public IHttpActionResult get_product_spu_id_list()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().GetProductSpuIdLst(jsontext); result = new BXXProductManage().GetProductSpuIdLst(jsontext);
return JsonString(result); return JsonString(result);
} }
//AddProdDownSku //AddProdDownSku
public IHttpActionResult add_prod_down_sku() public IHttpActionResult add_prod_down_sku()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().AddProdDownSku(jsontext); result = new BXXProductManage().AddProdDownSku(jsontext);
return JsonString(result); return JsonString(result);
} }
public IHttpActionResult get_prod_down_sku_lst_by_sku_codes() public IHttpActionResult get_prod_down_sku_lst_by_sku_codes()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().GetProdDownSkuLstBySkuCodes(jsontext); result = new BXXProductManage().GetProdDownSkuLstBySkuCodes(jsontext);
return JsonString(result); return JsonString(result);
} }
public IHttpActionResult get_product_list() public IHttpActionResult get_product_list()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().GetProductList(jsontext); result = new BXXProductManage().GetProductList(jsontext);
return JsonString(result); return JsonString(result);
} }
public IHttpActionResult get_product_detail_list() public IHttpActionResult get_product_detail_list()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().GetProductList(jsontext, true); result = new BXXProductManage().GetProductList(jsontext, true);
return JsonString(result); return JsonString(result);
} }
public IHttpActionResult get_product_list_random() public IHttpActionResult get_product_list_random()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().GetProductListRandom(jsontext); result = new BXXProductManage().GetProductListRandom(jsontext);
return JsonString(result); return JsonString(result);
} }
public IHttpActionResult add_prod_wx_complate() public IHttpActionResult add_prod_wx_complate()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().AddProdWXComplate(jsontext); result = new BXXProductManage().AddProdWXComplate(jsontext);
return JsonString(result); return JsonString(result);
} }
public IHttpActionResult get_prod_wx_complate_list() public IHttpActionResult get_prod_wx_complate_list()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().GetProdWXComplateList(jsontext); result = new BXXProductManage().GetProdWXComplateList(jsontext);
return JsonString(result); return JsonString(result);
} }
public IHttpActionResult get_sku_replace_img_list_random() public IHttpActionResult get_sku_replace_img_list_random()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().GetSkuReplaceImgListRandom(jsontext); result = new BXXProductManage().GetSkuReplaceImgListRandom(jsontext);
return JsonString(result); return JsonString(result);
} }
public IHttpActionResult add_product() public IHttpActionResult add_product()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().AddProduct(jsontext); result = new BXXProductManage().AddProduct(jsontext);
return JsonString(result); return JsonString(result);
} }
public IHttpActionResult mdy_product() public IHttpActionResult mdy_product()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().MdyProduct(jsontext); result = new BXXProductManage().MdyProduct(jsontext);
return JsonString(result); return JsonString(result);
} }
public IHttpActionResult mdy_violation_prod() public IHttpActionResult mdy_violation_prod()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().MdyViolationProd(jsontext); result = new BXXProductManage().MdyViolationProd(jsontext);
return JsonString(result); return JsonString(result);
} }
public IHttpActionResult mdy_best_sale_prod() public IHttpActionResult mdy_best_sale_prod()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().MdyBestSaleProd(jsontext); result = new BXXProductManage().MdyBestSaleProd(jsontext);
return JsonString(result); return JsonString(result);
} }
public IHttpActionResult del_db_product() public IHttpActionResult del_db_product()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().DelDbProd(jsontext); result = new BXXProductManage().DelDbProd(jsontext);
return JsonString(result); return JsonString(result);
} }
public IHttpActionResult mdy_db_product() public IHttpActionResult mdy_db_product()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().MdyDBProduct(jsontext); result = new BXXProductManage().MdyDBProduct(jsontext);
return JsonString(result); return JsonString(result);
} }
public IHttpActionResult get_product_groups() public IHttpActionResult get_product_groups()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().GetProductGroups(jsontext); result = new BXXProductManage().GetProductGroups(jsontext);
return JsonString(result); return JsonString(result);
} }
public IHttpActionResult add_product_groups() public IHttpActionResult add_product_groups()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().AddProductGroup(jsontext); result = new BXXProductManage().AddProductGroup(jsontext);
return JsonString(result); return JsonString(result);
} }
public IHttpActionResult del_product_groups() public IHttpActionResult del_product_groups()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().DelProductGroup(jsontext); result = new BXXProductManage().DelProductGroup(jsontext);
return JsonString(result); return JsonString(result);
} }
public IHttpActionResult get_product_notes() public IHttpActionResult get_product_notes()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().GetProductNotes(jsontext); result = new BXXProductManage().GetProductNotes(jsontext);
return JsonString(result); return JsonString(result);
} }
public IHttpActionResult add_product_notes() public IHttpActionResult add_product_notes()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().AddProductNotes(jsontext); result = new BXXProductManage().AddProductNotes(jsontext);
return JsonString(result); return JsonString(result);
} }
public IHttpActionResult del_product_notes() public IHttpActionResult del_product_notes()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().DelProductNotes(jsontext); result = new BXXProductManage().DelProductNotes(jsontext);
return JsonString(result); return JsonString(result);
} }
public IHttpActionResult get_pdd_product_cates() public IHttpActionResult get_pdd_product_cates()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().GetProductMainCates(jsontext); result = new BXXProductManage().GetProductMainCates(jsontext);
return JsonString(result); return JsonString(result);
} }
public IHttpActionResult get_product_cates() public IHttpActionResult get_product_cates()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().GetProductCates(jsontext); result = new BXXProductManage().GetProductCates(jsontext);
return JsonString(result); return JsonString(result);
} }
public IHttpActionResult add_sku_img_replace() public IHttpActionResult add_sku_img_replace()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().AddSkuImgReplace(jsontext); result = new BXXProductManage().AddSkuImgReplace(jsontext);
return JsonString(result); return JsonString(result);
} }
public IHttpActionResult mdy_sku_img_replace() public IHttpActionResult mdy_sku_img_replace()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().MdySkuImgReplace(jsontext); result = new BXXProductManage().MdySkuImgReplace(jsontext);
return JsonString(result); return JsonString(result);
} }
public IHttpActionResult get_sku_img_replace_list() public IHttpActionResult get_sku_img_replace_list()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().GetSkuImgReplaceList(jsontext); result = new BXXProductManage().GetSkuImgReplaceList(jsontext);
return JsonString(result); return JsonString(result);
} }
public IHttpActionResult get_sku_img_replace_detail_list() public IHttpActionResult get_sku_img_replace_detail_list()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().GetSkuImgReplaceList(jsontext, true); result = new BXXProductManage().GetSkuImgReplaceList(jsontext, true);
return JsonString(result); return JsonString(result);
} }
//AddSkuImg //AddSkuImg
public IHttpActionResult add_sku_img() public IHttpActionResult add_sku_img()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().AddSkuImg(jsontext); result = new BXXProductManage().AddSkuImg(jsontext);
return JsonString(result); return JsonString(result);
} }
public IHttpActionResult get_wx_tokens() public IHttpActionResult get_wx_tokens()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new WXShopManage().E57GetWxTokens(jsontext); result = new WXShopManage().E57GetWxTokens(jsontext);
return JsonString(result); return JsonString(result);
} }
public IHttpActionResult wx_api_get_all_cate() public IHttpActionResult wx_api_get_all_cate()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().WxApiGetWxAllCate(jsontext); result = new BXXProductManage().WxApiGetWxAllCate(jsontext);
return JsonString(result); return JsonString(result);
} }
public IHttpActionResult wx_api_category_classify() public IHttpActionResult wx_api_category_classify()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().WxApiCategoryClassify(jsontext); result = new BXXProductManage().WxApiCategoryClassify(jsontext);
return JsonString(result); return JsonString(result);
} }
public IHttpActionResult wx_api_upload_image() public IHttpActionResult wx_api_upload_image()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().WxApiUploadImage(jsontext); result = new BXXProductManage().WxApiUploadImage(jsontext);
return JsonString(result); return JsonString(result);
} }
//AddJSTSku //AddJSTSku
public IHttpActionResult add_jst_sku() public IHttpActionResult add_jst_sku()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().AddJSTSku(jsontext); result = new BXXProductManage().AddJSTSku(jsontext);
return JsonString(result); return JsonString(result);
} }
public IHttpActionResult mdy_jst_sku() public IHttpActionResult mdy_jst_sku()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().MdyJSTSku(jsontext); result = new BXXProductManage().MdyJSTSku(jsontext);
return JsonString(result); return JsonString(result);
} }
public IHttpActionResult get_jst_sku_list() public IHttpActionResult get_jst_sku_list()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().GetJSTSkuList(jsontext); result = new BXXProductManage().GetJSTSkuList(jsontext);
return JsonString(result); return JsonString(result);
} }
public IHttpActionResult set_random_company_product_config() public IHttpActionResult set_random_company_product_config()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().SetRandomCompanyProductConfig(jsontext); result = new BXXProductManage().SetRandomCompanyProductConfig(jsontext);
return JsonString(result); return JsonString(result);
} }
public IHttpActionResult get_random_company_product_config() public IHttpActionResult get_random_company_product_config()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().GetRandomCompanyProductConfig(jsontext); result = new BXXProductManage().GetRandomCompanyProductConfig(jsontext);
return JsonString(result); return JsonString(result);
} }
/// <summary> /// <summary>
@@ -394,12 +394,12 @@ namespace KJD_Web.Controllers.BXX
/// </summary> /// </summary>
public IHttpActionResult add_relation() public IHttpActionResult add_relation()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().AddRelation(jsontext); result = new BXXProductManage().AddRelation(jsontext);
return JsonString(result); return JsonString(result);
} }
/// <summary> /// <summary>
@@ -407,42 +407,54 @@ namespace KJD_Web.Controllers.BXX
/// </summary> /// </summary>
public IHttpActionResult get_relation() public IHttpActionResult get_relation()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().GetRelation(jsontext); result = new BXXProductManage().GetRelation(jsontext);
return JsonString(result); return JsonString(result);
} }
public IHttpActionResult add_mdy_jst_product_ban() public IHttpActionResult add_mdy_jst_product_ban()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().AddMdyJstProductBan(jsontext); result = new BXXProductManage().AddMdyJstProductBan(jsontext);
return JsonString(result); return JsonString(result);
} }
public IHttpActionResult get_jst_product_coid_list() public IHttpActionResult get_jst_product_coid_list()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().GetJstProductCoidList(jsontext); result = new BXXProductManage().GetJstProductCoidList(jsontext);
return JsonString(result); return JsonString(result);
} }
public IHttpActionResult get_jst_product_ban_platform_list() public IHttpActionResult get_jst_product_ban_platform_list()
{ {
string jsontext = GetRequestJsonString(); string jsontext = GetRequestJsonString();
var result = jsontext; var result = jsontext;
result = new BXXProductManage().GetJstProductBanPlatformList(jsontext); result = new BXXProductManage().GetJstProductBanPlatformList(jsontext);
return JsonString(result); 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 MAX.Core.Logger;
using NaiBa.Util.Extension; using NaiBa.Util.Extension;
using Org.BouncyCastle.Ocsp; using Org.BouncyCastle.Ocsp;
using Store.Framework.DependencyInjection;
using Store.Framework.Dtos; using Store.Framework.Dtos;
using Store.Framework.Models; using Store.Framework.Models;
using System; using System;
using System.Web.Http; using System.Web.Http;
using Ubiety.Dns.Core;
namespace KJD_Web.Controllers namespace KJD_Web.Controllers
{ {
@@ -15,9 +17,11 @@ namespace KJD_Web.Controllers
{ {
private readonly UserService _userService; private readonly UserService _userService;
private readonly ILoggerFacade _logger; private readonly ILoggerFacade _logger;
private readonly string OpenApiKey;
public WXUserController(UserService userService, ILoggerFacade logger) public WXUserController(UserService userService, ILoggerFacade logger)
{ {
OpenApiKey = System.Configuration.ConfigurationManager.AppSettings["OpenApiKey"].ParseToString();
_userService = userService ?? throw new ArgumentNullException(nameof(userService)); _userService = userService ?? throw new ArgumentNullException(nameof(userService));
_logger = logger ?? throw new ArgumentNullException(nameof(logger)); _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));
}
}
} }
} }
+2
View File
@@ -228,6 +228,7 @@
<Compile Include="Requests\Shops\ShopStatsGroupType.cs" /> <Compile Include="Requests\Shops\ShopStatsGroupType.cs" />
<Compile Include="Requests\Shops\ShopStatsRequest.cs" /> <Compile Include="Requests\Shops\ShopStatsRequest.cs" />
<Compile Include="Requests\Users\CUUserInfoRequest.cs" /> <Compile Include="Requests\Users\CUUserInfoRequest.cs" />
<Compile Include="Requests\Users\PurchaseImageQuotaRequest.cs" />
<Compile Include="Requests\Users\RebateRecordRequest.cs" /> <Compile Include="Requests\Users\RebateRecordRequest.cs" />
<Compile Include="Requests\Users\UserConfigRequest.cs" /> <Compile Include="Requests\Users\UserConfigRequest.cs" />
<Compile Include="Responses\Shops\ShopOrderDetailResponse.cs" /> <Compile Include="Responses\Shops\ShopOrderDetailResponse.cs" />
@@ -278,6 +279,7 @@
<Compile Include="Requests\Users\ShopRenewRequest.cs" /> <Compile Include="Requests\Users\ShopRenewRequest.cs" />
<Compile Include="Services\ImageCacheService.cs" /> <Compile Include="Services\ImageCacheService.cs" />
<Compile Include="Services\Buyer\BuyerService.cs" /> <Compile Include="Services\Buyer\BuyerService.cs" />
<Compile Include="Services\Products\ProductService.cs" />
<Compile Include="Services\Shops\ShopRevenueStatisticsService.cs" /> <Compile Include="Services\Shops\ShopRevenueStatisticsService.cs" />
<Compile Include="Services\Shops\ShopService.cs" /> <Compile Include="Services\Shops\ShopService.cs" />
<Compile Include="Services\Shops\ShopStatsJob.cs" /> <Compile Include="Services\Shops\ShopStatsJob.cs" />
+1 -1
View File
@@ -112,6 +112,6 @@ namespace KJD_Web.Model
/// 店铺续租平台保底金额 有OEM 平台默认抽成15 /// 店铺续租平台保底金额 有OEM 平台默认抽成15
/// </summary> /// </summary>
public decimal? shop_renewal_platform_floor_fee { get; set; } 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
{
}
+100 -1
View File
@@ -6,6 +6,7 @@ using KJD_Web.Requests.Users;
using KJD_Web.Utils; using KJD_Web.Utils;
using MAX.Core.DependencyInjection; using MAX.Core.DependencyInjection;
using MAX.Core.Logger; using MAX.Core.Logger;
using MySqlX.XDevAPI.Relational;
using NaiBa.Util.Extension; using NaiBa.Util.Extension;
using Store.Contracts.Order.Entitys; using Store.Contracts.Order.Entitys;
using Store.Contracts.User.Entitys; using Store.Contracts.User.Entitys;
@@ -31,7 +32,10 @@ namespace KJD_Web.Services.Users
private const int ShopIdMaxLength = 50; private const int ShopIdMaxLength = 50;
private const int RemarkMaxLength = 255; private const int RemarkMaxLength = 255;
private const int MaxRenewDuration = 120; private const int MaxRenewDuration = 120;
/// <summary>
/// AI图片包 1张 价格 分
/// </summary>
private const int AIImageAmount = 1;
private readonly IFreeSql _freeSql; private readonly IFreeSql _freeSql;
private readonly ILoggerFacade _logger; private readonly ILoggerFacade _logger;
@@ -243,6 +247,50 @@ namespace KJD_Web.Services.Users
return response; 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) private static void ValidateRequest(ShopRenewRequest request)
{ {
if (request == null) if (request == null)
@@ -479,6 +527,57 @@ namespace KJD_Web.Services.Users
work.Commit(); 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>
/// 获取用户配置 /// 获取用户配置
/// </summary> /// </summary>
+2
View File
@@ -35,6 +35,8 @@
<add key="Hangfire:Password" value="hangadmin" />--> <add key="Hangfire:Password" value="hangadmin" />-->
<!--是否启用后台任务--> <!--是否启用后台任务-->
<add key="BackgroundJobs" value="false"/> <add key="BackgroundJobs" value="false"/>
<!--第三方调用API 直接走token-->
<add key="OpenApiKey" value="e3b0c44298fc1c149afbf4c8996fb924"/>
</appSettings> </appSettings>
<!-- <!--
有关 web.config 更改的说明,请参见 http://go.microsoft.com/fwlink/?LinkId=235367。 有关 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")] [Column(Name = "shop_renewal_platform_floor_fee")]
public decimal ShopRenewalPlatformFloorFee { get; set; } = 15; public decimal ShopRenewalPlatformFloorFee { get; set; } = 15;
/// <summary>
/// 图片检测份额
/// </summary>
[Column(Name = "image_analysis_quota")]
public int ImageAnalysisQuota { get; set; }
/// <summary> /// <summary>
/// 是否主账户 /// 是否主账户
+20
View File
@@ -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识图包,
}
+13
View File
@@ -103,6 +103,19 @@ internal class UserTest
var data = userService.GetUserAmountSummary("17734871710"); var data = userService.GetUserAmountSummary("17734871710");
Console.WriteLine(JsonConvert.SerializeObject(data)); 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] //[Test]
//public void Fill() //public void Fill()
//{ //{