新增续费接口,移除旧续费API

OEM结算 增加续费返现
This commit is contained in:
chfei committed 2026-09-16 12:05:45 +08:00
1 parent b86134357c
commit 1df94a1d28
29 files changed
+1784 -103

No files matched your search

+113 -59
View File
@@ -17,6 +17,10 @@ namespace KJD_Web.BLL.WXXD
{
public class WXOemManage
{
/// <summary>
/// 店铺续费手续费 15
/// </summary>
const int ShopRenewFee = 15;
/// <summary>
/// 手续费
/// </summary>
@@ -603,7 +607,7 @@ namespace KJD_Web.BLL.WXXD
WHERE A.oem_id = '{MysqlUtils.ReplaceSqlSpecial(oem_id)}'";
var userDt = mySql.ExecuteDataTable(sql);
if (!string.IsNullOrEmpty(mySql.Message) || userDt == null || userDt.Rows.Count == 0)
return 0;
return 0;//找不到用户或数据库错误返回
List<string> userLst = userDt.Rows.Cast<DataRow>()
.Select(r => r["user_name"].ParseToString())
@@ -611,80 +615,130 @@ namespace KJD_Web.BLL.WXXD
.Distinct()
.ToList();
if (userLst.Count == 0)
return 0;
return 0;//用户列表空 返回
decimal total_amount = 0m; // 总金额(元)
decimal rebate_amount = 0m; // 正数部分(累计返利)
string now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
// 2. 该oem所有账户的未结算流水,按id升序
sql = "SELECT * FROM `wxxd`.`user_payment_record` WHERE user_name IN ('" + string.Join("','", userLst) + "') AND type IN (20,23,26,16,31,34) AND settlement=0 AND is_deleted=0 ORDER BY id ASC";
var flowDt = mySql.ExecuteDataTable(sql);
if (!string.IsNullOrEmpty(mySql.Message) || flowDt == null || flowDt.Rows.Count == 0)
if (!string.IsNullOrEmpty(mySql.Message))
return 0;
decimal total_amount = 0m; // 总金额(元)
decimal rebate_amount = 0m; // 正数部分(累计返利)
HashSet<string> deductedOrderSet = new HashSet<string>(); // type=23 已扣减的订单
HashSet<string> giftsOrderSet = new HashSet<string>(); // type=34 礼物已扣减的订单
List<long> settleIdLst = new List<long>(); // 参与结算的流水id
foreach (DataRow row in flowDt.Rows)
if (flowDt != null && flowDt.Rows.Count > 0)
{
int type = row["type"].ParseToInt();
decimal amount = row["amount"].ParseToDecimal();
decimal oem_amount = row["oem_amount"].ParseToDecimal();
long flowId = row["id"].ParseToLong();
HashSet<string> deductedOrderSet = new HashSet<string>(); // type=23 已扣减的订单
HashSet<string> giftsOrderSet = new HashSet<string>(); // type=34 礼物已扣减的订单
List<long> settleIdLst = new List<long>(); // 参与结算的流水id
decimal itemAmount = 0m;
if (type == 20)
itemAmount = amount - 2.2m;
else if (type == 26)
itemAmount = amount - 2.5m;
else if (type == 16)
itemAmount = oem_amount;
else if (type == 31)
itemAmount = oem_amount;
else if (type == 23)
foreach (DataRow row in flowDt.Rows)
{
// 同一个订单只能减少一次
string orderId = row["order_id"].ParseToString();
if (orderId.IsNullOrEmpty() || deductedOrderSet.Contains(orderId))
continue;
deductedOrderSet.Add(orderId);
itemAmount = -(amount - 2.2m);
}
else if (type == 34)
{
// 同一个订单只能减少一次
string orderId = row["order_id"].ParseToString();
if (orderId.IsNullOrEmpty() || giftsOrderSet.Contains(orderId))
continue;
giftsOrderSet.Add(orderId);
itemAmount = -oem_amount;
}
else
{
continue; // 其他类型不计入
int type = row["type"].ParseToInt();
decimal amount = row["amount"].ParseToDecimal();
decimal oem_amount = row["oem_amount"].ParseToDecimal();
long flowId = row["id"].ParseToLong();
decimal itemAmount = 0m;
if (type == 20)
itemAmount = amount - 2.2m;
else if (type == 26)
itemAmount = amount - 2.5m;
else if (type == 16)
itemAmount = oem_amount;
else if (type == 31)
itemAmount = oem_amount;
else if (type == 23)
{
// 同一个订单只能减少一次
string orderId = row["order_id"].ParseToString();
if (orderId.IsNullOrEmpty() || deductedOrderSet.Contains(orderId))
continue;
deductedOrderSet.Add(orderId);
itemAmount = -(amount - 2.2m);
}
else if (type == 34)
{
// 同一个订单只能减少一次
string orderId = row["order_id"].ParseToString();
if (orderId.IsNullOrEmpty() || giftsOrderSet.Contains(orderId))
continue;
giftsOrderSet.Add(orderId);
itemAmount = -oem_amount;
}
else
{
continue; // 其他类型不计入
}
total_amount += itemAmount;
rebate_amount += itemAmount;
settleIdLst.Add(flowId);
}
total_amount += itemAmount;
rebate_amount += itemAmount;
if (settleIdLst.Count == 0)
return 0;
settleIdLst.Add(flowId);
//更新用户流水记录表结算
sql = "UPDATE wxxd.user_payment_record SET settlement=1,settlement_time='" + now + "' WHERE id IN (" + string.Join(",", settleIdLst) + ")";
var flowRst = mySql.ExecuteAffectedRows(sql);
if (!string.IsNullOrEmpty(mySql.Message) || flowRst <= 0)
throw new Exception("标记流水结算失败");
}
if (settleIdLst.Count == 0)
//读取用户店铺续费
sql = "SELECT id,delta_points FROM `wxxd`.`user_points_record` WHERE user_name IN ('" + string.Join("','", userLst) + "') AND option_type ='续费' AND settlement=0 ORDER BY id ASC";
var userPointsDt = mySql.ExecuteDataTable(sql);
if (!string.IsNullOrEmpty(mySql.Message))
return 0;
if (userPointsDt != null && userPointsDt.Rows.Count > 0) //更新用户流水记录表结算
{
int count = userPointsDt.Rows.Count;
//结算商铺续费
List<long> settleIdLst = new List<long>(); // 参与结算的流水id
foreach (DataRow row in userPointsDt.Rows)
{
long flowId = row["id"].ParseToLong();
decimal points = row["delta_points"].ParseToDecimal();
decimal itemAmount = points * 1;//比例1:1
itemAmount = itemAmount - ShopRenewFee;
total_amount += itemAmount;
rebate_amount += itemAmount;
settleIdLst.Add(flowId);
}
sql = "UPDATE wxxd.user_points_record SET settlement=1,settlement_time='" + now + "' WHERE id IN (" + string.Join(",", settleIdLst) + ")";
var flowRst = mySql.ExecuteAffectedRows(sql);
if (!string.IsNullOrEmpty(mySql.Message) || flowRst <= 0)
throw new Exception("商铺流水结算失败");
}
long total_fen = (long)Math.Round(total_amount * 100m);
long rebate_fen = (long)Math.Round(rebate_amount * 100m);
string now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
// 3. 写oem金额 + 更新流水状态(同一事务)
sql = "UPDATE wxxd.oem SET available_balance=available_balance+" + total_fen +
", total_rebate_amount=total_rebate_amount+" + rebate_fen +
" WHERE oem_id='" + oem_id + "'";
var oemRst = mySql.ExecuteAffectedRows(sql);
if (!string.IsNullOrEmpty(mySql.Message) || oemRst <= 0)
throw new Exception("结算流水到账户失败");
sql = "UPDATE wxxd.user_payment_record SET settlement=1,settlement_time='" + now + "' WHERE id IN (" + string.Join(",", settleIdLst) + ")";
var flowRst = mySql.ExecuteAffectedRows(sql);
if (!string.IsNullOrEmpty(mySql.Message) || flowRst <= 0)
throw new Exception("标记流水结算失败");
if (total_fen > 0 || rebate_fen > 0)
{
//写oem金额 + 更新流水状态
sql = "UPDATE wxxd.oem SET available_balance=available_balance+" + total_fen +
", total_rebate_amount=total_rebate_amount+" + rebate_fen +
" WHERE oem_id='" + oem_id + "'";
var oemRst = mySql.ExecuteAffectedRows(sql);
if (!string.IsNullOrEmpty(mySql.Message) || oemRst <= 0)
throw new Exception("结算流水到账户失败");
}
return total_fen;
}
+2 -2
View File
@@ -902,9 +902,9 @@ namespace KJD_Web.BLL.WXXD
{
return "{\"code\":500,\"msg\":\"操作对象不能为空\"}";
}
if (delta_points <= 0 && option_type == "续费")
if (option_type == "续费")
{
return "{\"code\":500,\"msg\":\"续费金额错误,需大于0\"}";
return "{\"code\":500,\"msg\":\"续费金额错误\"}";
}
if (delta_points == 0)
{