修改 OEM 结算 快递流水 退款记录也有OEM_Amount 一 一对应 直接计算金额之和
This commit is contained in:
1 parent
8d6c4ebb84
commit
6f54b8a63f
5 files changed
+34
-62
No files matched your search
@@ -88,6 +88,10 @@ namespace KJD_Web.Controllers.WX
|
|||||||
ret = _statsService.GetShopOrderDetails(request.StartDate, request.EndDate, request.OrderType, "", request.ShopIds);
|
ret = _statsService.GetShopOrderDetails(request.StartDate, request.EndDate, request.OrderType, "", request.ShopIds);
|
||||||
return Ok(ApiResult.Success(ret));
|
return Ok(ApiResult.Success(ret));
|
||||||
}
|
}
|
||||||
|
catch (ArgumentException ex)
|
||||||
|
{
|
||||||
|
return Ok(ApiResult.Fail(ex.Message, ResultCode.ServerError));
|
||||||
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
return Ok(ApiResult.Fail("查询失败", ResultCode.ServerError));
|
return Ok(ApiResult.Fail("查询失败", ResultCode.ServerError));
|
||||||
@@ -197,7 +201,7 @@ namespace KJD_Web.Controllers.WX
|
|||||||
|
|
||||||
foreach (var item in ret)
|
foreach (var item in ret)
|
||||||
{
|
{
|
||||||
item.ShopId= dict[item.ShopId];
|
item.ShopId = dict[item.ShopId];
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(ApiResult.Success(ret));
|
return Ok(ApiResult.Success(ret));
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using MySqlX.XDevAPI;
|
using MySqlX.XDevAPI;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Store.Contracts.User.Entitys;
|
using Store.Contracts.User.Entitys;
|
||||||
|
using Store.Contracts.User.Enums;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
@@ -40,7 +41,7 @@ namespace KJD_Web.Services.Users
|
|||||||
// 获取OEM下面的所有用户
|
// 获取OEM下面的所有用户
|
||||||
var users = GetOEMUsers(oem.OemId, true);
|
var users = GetOEMUsers(oem.OemId, true);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (users.Count == 0)
|
if (users.Count == 0)
|
||||||
{//todo
|
{//todo
|
||||||
@@ -127,11 +128,12 @@ namespace KJD_Web.Services.Users
|
|||||||
decimal total_amount = 0m; // 总金额(元)
|
decimal total_amount = 0m; // 总金额(元)
|
||||||
decimal rebate_amount = 0m; // 正数部分(累计返利)
|
decimal rebate_amount = 0m; // 正数部分(累计返利)
|
||||||
DateTime now = DateTime.Now;
|
DateTime now = DateTime.Now;
|
||||||
|
int[] positiveTypes = [16, 20, 26, 31, 35, 39, 55];
|
||||||
List<int> UserPaymentTypeFiltert = [16, 20, 23, 26, 31, 34, 55];
|
int[] negativeTypes = [34, 23, 38, 32, 36, 40];
|
||||||
|
var paymentTypes = positiveTypes.Concat(negativeTypes).ToArray();
|
||||||
var paymentQuery = tr_freeSql.Select<UserPaymentRecordEntity>()
|
var paymentQuery = tr_freeSql.Select<UserPaymentRecordEntity>()
|
||||||
.Where(a => userNames.Contains(a.UserName))
|
.Where(a => userNames.Contains(a.UserName))
|
||||||
.Where(a => UserPaymentTypeFiltert.Contains(a.Type))
|
.Where(a => paymentTypes.Contains(a.Type))
|
||||||
.Where(a => a.Settlement == 0)
|
.Where(a => a.Settlement == 0)
|
||||||
.Where(a => a.IsDeleted == 0);
|
.Where(a => a.IsDeleted == 0);
|
||||||
//只有OEM结算才限制OEM创建时间。
|
//只有OEM结算才限制OEM创建时间。
|
||||||
@@ -139,58 +141,18 @@ namespace KJD_Web.Services.Users
|
|||||||
{
|
{
|
||||||
paymentQuery = paymentQuery.Where(a => a.CreateTime > oemAddTime.Value);
|
paymentQuery = paymentQuery.Where(a => a.CreateTime > oemAddTime.Value);
|
||||||
}
|
}
|
||||||
paymentQuery.OrderBy(a => a.Id);
|
var userPayments = paymentQuery.OrderBy(a => a.Id).ToList();
|
||||||
var userPayments = paymentQuery.ToList();
|
|
||||||
if (userPayments.Count > 0)
|
if (userPayments.Count > 0)
|
||||||
{
|
{
|
||||||
Debug.WriteLine(userPayments.Where(a => a.Type == 20).Sum(a => a.OemAmount));
|
var ids = userPayments.Select(a => a.Id).ToList();
|
||||||
///原始流水ID。
|
var userPaymentAmount = userPayments
|
||||||
List<long> ids = userPayments.Select(a => a.Id).ToList();
|
.GroupBy(a => new { a.Type, a.OrderId })
|
||||||
|
.Select(group => group.First())
|
||||||
var userPaymentUnique = userPayments.GroupBy(a => //去重
|
.Sum(a =>
|
||||||
new
|
|
||||||
{
|
{
|
||||||
a.Type,
|
var amount = Math.Abs(a.OemAmount ?? 0m);
|
||||||
a.OrderId
|
return positiveTypes.Contains(a.Type) ? amount : -amount;
|
||||||
}).Select(a => a.First()).ToList();
|
});
|
||||||
|
|
||||||
//经过计算过滤后的列表
|
|
||||||
List<UserPaymentRecordEntity> userPaymentCalculated = new List<UserPaymentRecordEntity>();
|
|
||||||
|
|
||||||
foreach (var item in userPaymentUnique)
|
|
||||||
{
|
|
||||||
if (item.Type == 20)
|
|
||||||
{
|
|
||||||
//item.OemAmount = item.Amount - 2.2m;
|
|
||||||
item.OemAmount = item.OemAmount;
|
|
||||||
}
|
|
||||||
else if (item.Type == 26)
|
|
||||||
{
|
|
||||||
//item.OemAmount = item.Amount - 2.5m;
|
|
||||||
item.OemAmount = item.OemAmount;
|
|
||||||
}
|
|
||||||
if (item.Type == 23)
|
|
||||||
{
|
|
||||||
var temp = userPaymentCalculated.FirstOrDefault(a => a.Type == 20 && a.OrderId == item.OrderId);
|
|
||||||
if (temp != null)
|
|
||||||
{
|
|
||||||
userPaymentCalculated.Remove(temp);//23 移除 20
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else if (item.Type == 34)
|
|
||||||
{
|
|
||||||
item.OemAmount = item.OemAmount * -1;
|
|
||||||
}
|
|
||||||
userPaymentCalculated.Add(item);
|
|
||||||
}
|
|
||||||
decimal userPaymentAmount = userPaymentCalculated.Sum(x => x.OemAmount ?? 0);//累计返利
|
|
||||||
//StringBuilder sb = new StringBuilder();
|
|
||||||
//sb.AppendLine("id,order_id,type,amount,oem_amount,time");
|
|
||||||
//foreach (var item in userPayments)
|
|
||||||
//{
|
|
||||||
// sb.AppendLine($"{item.Id},{item.OrderId},{item.Type},{item.Amount},{item.OemAmount},{item.CreateTime}");
|
|
||||||
//}
|
|
||||||
total_amount += userPaymentAmount;
|
total_amount += userPaymentAmount;
|
||||||
rebate_amount += userPaymentAmount;
|
rebate_amount += userPaymentAmount;
|
||||||
|
|
||||||
@@ -460,4 +422,4 @@ namespace KJD_Web.Services.Users
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public long Balance { get; set; }
|
public long Balance { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -477,7 +477,7 @@ namespace KJD_Web.Services.Users
|
|||||||
if (user == null) return false;
|
if (user == null) return false;
|
||||||
// 消费金额必须大于 0
|
// 消费金额必须大于 0
|
||||||
if (user.Balance <= 0) return false;
|
if (user.Balance <= 0) return false;
|
||||||
if (type != UserPaymentTypes.同步单号) return false;
|
if (type != UserPaymentTypes.同步物流) return false;
|
||||||
consumeAmount = (user.SyncLogisticsPerOrder ?? 0m) + consumeAmount;
|
consumeAmount = (user.SyncLogisticsPerOrder ?? 0m) + consumeAmount;
|
||||||
return user.Balance >= consumeAmount;
|
return user.Balance >= consumeAmount;
|
||||||
}
|
}
|
||||||
@@ -499,7 +499,7 @@ namespace KJD_Web.Services.Users
|
|||||||
{
|
{
|
||||||
throw new Exception("用户不存在");
|
throw new Exception("用户不存在");
|
||||||
}
|
}
|
||||||
if (type != UserPaymentTypes.同步单号) throw new Exception("不支持的类型");
|
if (type != UserPaymentTypes.同步物流) throw new Exception("不支持的类型");
|
||||||
var payItem = new UserPaymentRecordEntity
|
var payItem = new UserPaymentRecordEntity
|
||||||
{
|
{
|
||||||
Type = (int)type,
|
Type = (int)type,
|
||||||
|
|||||||
@@ -19,12 +19,18 @@ public enum UserPaymentTypes
|
|||||||
//运费退款扣除 = 7,
|
//运费退款扣除 = 7,
|
||||||
礼物单支出 = 16,
|
礼物单支出 = 16,
|
||||||
中转仓扣费支出 = 20,
|
中转仓扣费支出 = 20,
|
||||||
中转仓作废返还收入 = 23,
|
中转仓作废收入 = 23,
|
||||||
中转仓超重支出 = 24,
|
中转仓超重支出 = 24,
|
||||||
退货包裹扣费支出 = 26,
|
退货包裹扣费支出 = 26,
|
||||||
中转仓快递超重费用 = 28,
|
|
||||||
支付宝在线充值 = 30,
|
支付宝在线充值 = 30,
|
||||||
云仓退货支出 = 31,
|
云仓退货支出 = 31,
|
||||||
礼物单退费 = 34,
|
礼物单退费 = 34,
|
||||||
同步单号 = 55,
|
额外订单创建 = 35,
|
||||||
|
额外订单作废 = 36,
|
||||||
|
额外订单超重支出 = 37,
|
||||||
|
退货包裹作废返还 = 38,
|
||||||
|
同步物流 = 55,
|
||||||
|
额外包裹退货拦截花费 = 39,
|
||||||
|
额外包裹退货拦截花费退款 = 40,
|
||||||
|
额外包裹退货拦截超重花费 = 41,
|
||||||
}
|
}
|
||||||
@@ -82,7 +82,7 @@ public class VirtualLogisticsService : ITransientDependency
|
|||||||
}
|
}
|
||||||
var user = _userService.GetUserByUserName(userName);
|
var user = _userService.GetUserByUserName(userName);
|
||||||
if (user == null) throw new Exception("错误的账号");
|
if (user == null) throw new Exception("错误的账号");
|
||||||
if (_userService.CanAfford(userName, Contracts.User.Enums.UserPaymentTypes.同步单号, FIXEDFEES) == false)
|
if (_userService.CanAfford(userName, Contracts.User.Enums.UserPaymentTypes.同步物流, FIXEDFEES) == false)
|
||||||
{
|
{
|
||||||
throw new Exception("余额不足");
|
throw new Exception("余额不足");
|
||||||
}
|
}
|
||||||
@@ -181,7 +181,7 @@ public class VirtualLogisticsService : ITransientDependency
|
|||||||
throw new Exception("记录同步单失败");
|
throw new Exception("记录同步单失败");
|
||||||
}
|
}
|
||||||
//todo 更新UserBlance
|
//todo 更新UserBlance
|
||||||
_userService.UserPayment(user.UserName, orderId, type: Contracts.User.Enums.UserPaymentTypes.同步单号);
|
_userService.UserPayment(user.UserName, orderId, type: Contracts.User.Enums.UserPaymentTypes.同步物流);
|
||||||
return yhSyncs;
|
return yhSyncs;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user