diff --git a/KJD_WebService/BLL/BXX/BXXProductManage.cs b/KJD_WebService/BLL/BXX/BXXProductManage.cs
index bdd21fe..e3cc1cd 100644
--- a/KJD_WebService/BLL/BXX/BXXProductManage.cs
+++ b/KJD_WebService/BLL/BXX/BXXProductManage.cs
@@ -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))
diff --git a/KJD_WebService/BLL/WXXD/WXUserManage.cs b/KJD_WebService/BLL/WXXD/WXUserManage.cs
index 7019047..cc70874 100644
--- a/KJD_WebService/BLL/WXXD/WXUserManage.cs
+++ b/KJD_WebService/BLL/WXXD/WXUserManage.cs
@@ -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() : "";
diff --git a/KJD_WebService/Controllers/BXX/BXXProductController.cs b/KJD_WebService/Controllers/BXX/BXXProductController.cs
index 3c7cb1a..0e0eaa4 100644
--- a/KJD_WebService/Controllers/BXX/BXXProductController.cs
+++ b/KJD_WebService/Controllers/BXX/BXXProductController.cs
@@ -18,375 +18,375 @@ namespace KJD_Web.Controllers.BXX
{
public IHttpActionResult get_product_spu_id_list()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().GetProductSpuIdLst(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().GetProductSpuIdLst(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
//AddProdDownSku
public IHttpActionResult add_prod_down_sku()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().AddProdDownSku(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().AddProdDownSku(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
public IHttpActionResult get_prod_down_sku_lst_by_sku_codes()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().GetProdDownSkuLstBySkuCodes(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().GetProdDownSkuLstBySkuCodes(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
public IHttpActionResult get_product_list()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().GetProductList(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().GetProductList(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
public IHttpActionResult get_product_detail_list()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().GetProductList(jsontext, true);
+ var result = jsontext;
+ result = new BXXProductManage().GetProductList(jsontext, true);
- return JsonString(result);
+ return JsonString(result);
}
public IHttpActionResult get_product_list_random()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().GetProductListRandom(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().GetProductListRandom(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
public IHttpActionResult add_prod_wx_complate()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().AddProdWXComplate(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().AddProdWXComplate(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
public IHttpActionResult get_prod_wx_complate_list()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().GetProdWXComplateList(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().GetProdWXComplateList(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
public IHttpActionResult get_sku_replace_img_list_random()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().GetSkuReplaceImgListRandom(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().GetSkuReplaceImgListRandom(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
public IHttpActionResult add_product()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().AddProduct(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().AddProduct(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
public IHttpActionResult mdy_product()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().MdyProduct(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().MdyProduct(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
public IHttpActionResult mdy_violation_prod()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().MdyViolationProd(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().MdyViolationProd(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
public IHttpActionResult mdy_best_sale_prod()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().MdyBestSaleProd(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().MdyBestSaleProd(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
public IHttpActionResult del_db_product()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().DelDbProd(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().DelDbProd(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
public IHttpActionResult mdy_db_product()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().MdyDBProduct(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().MdyDBProduct(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
public IHttpActionResult get_product_groups()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().GetProductGroups(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().GetProductGroups(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
public IHttpActionResult add_product_groups()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().AddProductGroup(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().AddProductGroup(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
public IHttpActionResult del_product_groups()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().DelProductGroup(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().DelProductGroup(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
public IHttpActionResult get_product_notes()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().GetProductNotes(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().GetProductNotes(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
public IHttpActionResult add_product_notes()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().AddProductNotes(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().AddProductNotes(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
public IHttpActionResult del_product_notes()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().DelProductNotes(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().DelProductNotes(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
public IHttpActionResult get_pdd_product_cates()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().GetProductMainCates(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().GetProductMainCates(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
public IHttpActionResult get_product_cates()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().GetProductCates(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().GetProductCates(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
public IHttpActionResult add_sku_img_replace()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().AddSkuImgReplace(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().AddSkuImgReplace(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
public IHttpActionResult mdy_sku_img_replace()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().MdySkuImgReplace(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().MdySkuImgReplace(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
public IHttpActionResult get_sku_img_replace_list()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().GetSkuImgReplaceList(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().GetSkuImgReplaceList(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
public IHttpActionResult get_sku_img_replace_detail_list()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().GetSkuImgReplaceList(jsontext, true);
+ var result = jsontext;
+ result = new BXXProductManage().GetSkuImgReplaceList(jsontext, true);
- return JsonString(result);
+ return JsonString(result);
}
//AddSkuImg
public IHttpActionResult add_sku_img()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().AddSkuImg(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().AddSkuImg(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
public IHttpActionResult get_wx_tokens()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new WXShopManage().E57GetWxTokens(jsontext);
+ var result = jsontext;
+ result = new WXShopManage().E57GetWxTokens(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
public IHttpActionResult wx_api_get_all_cate()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().WxApiGetWxAllCate(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().WxApiGetWxAllCate(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
public IHttpActionResult wx_api_category_classify()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().WxApiCategoryClassify(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().WxApiCategoryClassify(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
public IHttpActionResult wx_api_upload_image()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().WxApiUploadImage(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().WxApiUploadImage(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
//AddJSTSku
public IHttpActionResult add_jst_sku()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().AddJSTSku(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().AddJSTSku(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
public IHttpActionResult mdy_jst_sku()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().MdyJSTSku(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().MdyJSTSku(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
public IHttpActionResult get_jst_sku_list()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().GetJSTSkuList(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().GetJSTSkuList(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
public IHttpActionResult set_random_company_product_config()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().SetRandomCompanyProductConfig(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().SetRandomCompanyProductConfig(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
public IHttpActionResult get_random_company_product_config()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().GetRandomCompanyProductConfig(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().GetRandomCompanyProductConfig(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
///
@@ -394,12 +394,12 @@ namespace KJD_Web.Controllers.BXX
///
public IHttpActionResult add_relation()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().AddRelation(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().AddRelation(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
///
@@ -407,42 +407,54 @@ namespace KJD_Web.Controllers.BXX
///
public IHttpActionResult get_relation()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().GetRelation(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().GetRelation(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
public IHttpActionResult add_mdy_jst_product_ban()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().AddMdyJstProductBan(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().AddMdyJstProductBan(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
public IHttpActionResult get_jst_product_coid_list()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().GetJstProductCoidList(jsontext);
+ var result = jsontext;
+ result = new BXXProductManage().GetJstProductCoidList(jsontext);
- return JsonString(result);
+ return JsonString(result);
}
public IHttpActionResult get_jst_product_ban_platform_list()
{
- string jsontext = GetRequestJsonString();
+ string jsontext = GetRequestJsonString();
- var result = jsontext;
- result = new BXXProductManage().GetJstProductBanPlatformList(jsontext);
+ var result = 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);
+ }
+
}
}
diff --git a/KJD_WebService/Controllers/WX/WXUser_N_Controller.cs b/KJD_WebService/Controllers/WX/WXUser_N_Controller.cs
index 6b4c014..f832fa7 100644
--- a/KJD_WebService/Controllers/WX/WXUser_N_Controller.cs
+++ b/KJD_WebService/Controllers/WX/WXUser_N_Controller.cs
@@ -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
}
}
+ ///
+ /// 购买图片检测配额
+ ///
+ ///
+ ///
+ [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));
+ }
+ }
+
+ ///
+ /// 外部调用 图片检测配额消费
+ ///
+ ///
+ ///
+ [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));
+ }
+ }
}
}
diff --git a/KJD_WebService/KJD_WebService.csproj b/KJD_WebService/KJD_WebService.csproj
index c6efe62..a71be28 100644
--- a/KJD_WebService/KJD_WebService.csproj
+++ b/KJD_WebService/KJD_WebService.csproj
@@ -228,6 +228,7 @@
+
@@ -278,6 +279,7 @@
+
diff --git a/KJD_WebService/Model/UserLoginResultParam.cs b/KJD_WebService/Model/UserLoginResultParam.cs
index 21de029..453359a 100644
--- a/KJD_WebService/Model/UserLoginResultParam.cs
+++ b/KJD_WebService/Model/UserLoginResultParam.cs
@@ -112,6 +112,6 @@ namespace KJD_Web.Model
/// 店铺续租平台保底金额 有OEM 平台默认抽成15
///
public decimal? shop_renewal_platform_floor_fee { get; set; }
-
+ public int image_analysis_quota { get; set; }
}
}
\ No newline at end of file
diff --git a/KJD_WebService/Requests/Users/PurchaseImageQuotaRequest.cs b/KJD_WebService/Requests/Users/PurchaseImageQuotaRequest.cs
new file mode 100644
index 0000000..a6ea2e3
--- /dev/null
+++ b/KJD_WebService/Requests/Users/PurchaseImageQuotaRequest.cs
@@ -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;
+
+///
+/// 购买图片检测配额
+///
+public class ImageAnalysisRequest : SignRequestBase
+{
+ ///
+ /// 购买金额
+ ///
+ public int Amount { get; set; }
+}
\ No newline at end of file
diff --git a/KJD_WebService/Services/Products/ProductService.cs b/KJD_WebService/Services/Products/ProductService.cs
new file mode 100644
index 0000000..eed59bc
--- /dev/null
+++ b/KJD_WebService/Services/Products/ProductService.cs
@@ -0,0 +1,10 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+
+namespace KJD_Web.Services.Products;
+
+public class ProductService
+{
+}
\ No newline at end of file
diff --git a/KJD_WebService/Services/Users/UserService.cs b/KJD_WebService/Services/Users/UserService.cs
index a343013..531dc30 100644
--- a/KJD_WebService/Services/Users/UserService.cs
+++ b/KJD_WebService/Services/Users/UserService.cs
@@ -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;
-
+ ///
+ /// AI图片包 1张 价格 分
+ ///
+ private const int AIImageAmount = 1;
private readonly IFreeSql _freeSql;
private readonly ILoggerFacade _logger;
@@ -243,6 +247,50 @@ namespace KJD_Web.Services.Users
return response;
}
+ ///
+ /// 购买图片检测购买份额
+ /// 最少1块钱
+ ///
+ ///
+ 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()
+ .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()
+ .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();
}
+
+ ///
+ /// 积分消费
+ ///
+ ///
+ 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(payItem).ExecuteAffrows();
+ if (affrows != 1)
+ {
+ _logger.Error($"积分消费失败:{userName},{type}");
+ throw new Exception("积分消费失败");
+ }
+ affrows = trFreeSql.Update()
+ .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();
+ }
+
+
///
/// 获取用户配置
///
diff --git a/KJD_WebService/Web.config b/KJD_WebService/Web.config
index f04f505..be19e20 100644
--- a/KJD_WebService/Web.config
+++ b/KJD_WebService/Web.config
@@ -35,6 +35,8 @@
-->
+
+