结算流水 增加 34 类型 礼物订单发送失败扣除金额

This commit is contained in:
chfei committed 2026-09-04 15:07:12 +08:00
1 parent 1514916d69
commit 0039ca5bf6
1 file changed
+22 -12
+22 -12
View File
@@ -275,7 +275,7 @@ namespace KJD_Web.BLL.WXXD
try
{
this.SettleOemFlows(mySql, oemInfo.oem_id);
this.SettleOemFlows(mySql, oemInfo.oem_id);
mySql.Commit();
}
catch (Exception)
@@ -589,7 +589,7 @@ namespace KJD_Web.BLL.WXXD
{
if (oem_id.IsNullOrEmpty())
return 0;
// 1. 找到该oem下所有账户
// 1. 找到该oem下所有账户
string sql = $@"SELECT user_name, '主账号' AS account_type
FROM `wxxd`.`user`
WHERE oem_id = '{MysqlUtils.ReplaceSqlSpecial(oem_id)}'
@@ -602,7 +602,7 @@ namespace KJD_Web.BLL.WXXD
ON A.user_name = B.parent_user_name
WHERE A.oem_id = '{MysqlUtils.ReplaceSqlSpecial(oem_id)}'";
var userDt = mySql.ExecuteDataTable(sql);
if (!string.IsNullOrEmpty(mySql.Message) || userDt == null || userDt.Rows.Count == 0)
if (!string.IsNullOrEmpty(mySql.Message) || userDt == null || userDt.Rows.Count == 0)
return 0;
List<string> userLst = userDt.Rows.Cast<DataRow>()
@@ -612,14 +612,15 @@ namespace KJD_Web.BLL.WXXD
.ToList();
if (userLst.Count == 0)
return 0;
// 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) 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)
// 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)
return 0;
decimal total_amount = 0m; // 总金额(元)
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)
@@ -647,6 +648,15 @@ namespace KJD_Web.BLL.WXXD
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; // 其他类型不计入
@@ -663,16 +673,16 @@ namespace KJD_Web.BLL.WXXD
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金额 + 更新流水状态(同一事务)
// 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)
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) + ")";
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("标记流水结算失败");
return total_fen;