AI Assistant 6 miesięcy temu
rodzic
commit
097548e7e1

+ 7 - 7
app/Module/Transfer/Logics/FeeStatisticsLogic.php

@@ -149,7 +149,7 @@ class FeeStatisticsLogic
      * @param int $appId 应用ID
      * @return array
      */
-    public static function getStatsByDateRange(string $startDate, string $endDate, int $appId = 0): array
+    public static function getStatsByDateRange(string $startDate, string $endDate, int $appId ): array
     {
         $data = TransferFeeDailyStats::getByDateRange($startDate, $endDate, $appId);
 
@@ -249,15 +249,15 @@ class FeeStatisticsLogic
         if ($appId > 0) {
             // 重新统计指定应用
             $app = TransferApp::findOrFail($appId);
-            
+
             // 删除原有统计数据
             TransferFeeDailyStats::where('stat_date', $date)
                 ->where('transfer_app_id', $appId)
                 ->delete();
-            
+
             // 重新统计
             $result = self::processAppStatistics($app, $date);
-            
+
             return [
                 'date' => $date,
                 'app_id' => $appId,
@@ -266,7 +266,7 @@ class FeeStatisticsLogic
         } else {
             // 重新统计所有应用
             TransferFeeDailyStats::where('stat_date', $date)->delete();
-            
+
             return self::runDailyStatistics($date);
         }
     }
@@ -285,7 +285,7 @@ class FeeStatisticsLogic
 
         foreach ($apps as $app) {
             $statsRecord = TransferFeeDailyStats::getByDateAndApp($date, $app->id);
-            
+
             if (!$statsRecord) {
                 $validationResults[] = [
                     'app_id' => $app->id,
@@ -307,7 +307,7 @@ class FeeStatisticsLogic
                 ->get();
 
             $actualStats = self::calculateOrderStats($actualOrders);
-            
+
             $isValid = (
                 $statsRecord->total_order_count == $actualStats['total_order_count'] &&
                 bccomp($statsRecord->total_fee_amount, $actualStats['total_fee_amount'], 10) == 0

+ 1 - 8
app/Module/Transfer/Models/TransferApp.php

@@ -222,15 +222,8 @@ class TransferApp extends ModelCore
         return $this->fee_account_uid > 0 ? $this->fee_account_uid : 1;
     }
 
-    /**
-     * 获取手续费收取账户信息
-     */
-    public function getFeeAccount()
-    {
-        $feeAccountUid = $this->getFeeAccountUid();
 
-        return \App\Module\Fund\Services\FundService::getAccountInfo($feeAccountUid);
-    }
+
 
     /**
      * 计算转入手续费

+ 25 - 25
app/Module/Transfer/Services/FeeStatisticsService.php

@@ -28,27 +28,27 @@ class FeeStatisticsService
     {
         try {
             $date = $date ?: Carbon::yesterday()->format('Y-m-d');
-            
+
             Log::info("开始执行手续费每日统计", ['date' => $date]);
-            
+
             $result = FeeStatisticsLogic::runDailyStatistics($date);
-            
+
             Log::info("手续费每日统计完成", [
                 'date' => $date,
                 'processed_apps' => count($result['apps']),
                 'total_orders' => $result['summary']['total_orders'],
                 'total_fee' => $result['summary']['total_fee']
             ]);
-            
+
             return $result;
-            
+
         } catch (\Exception $e) {
             Log::error("手续费每日统计失败", [
                 'date' => $date ?? 'unknown',
                 'error' => $e->getMessage(),
                 'trace' => $e->getTraceAsString()
             ]);
-            
+
             throw $e;
         }
     }
@@ -61,7 +61,7 @@ class FeeStatisticsService
      * @param int $appId 应用ID(0表示所有应用)
      * @return array
      */
-    public static function getStatsByDateRange(string $startDate, string $endDate, int $appId = 0): array
+    public static function getStatsByDateRange(string $startDate, string $endDate,$appId): array
     {
         try {
             return FeeStatisticsLogic::getStatsByDateRange($startDate, $endDate, $appId);
@@ -72,7 +72,7 @@ class FeeStatisticsService
                 'app_id' => $appId,
                 'error' => $e->getMessage()
             ]);
-            
+
             return [
                 'error' => $e->getMessage(),
                 'data' => [],
@@ -106,7 +106,7 @@ class FeeStatisticsService
                 'app_id' => $appId,
                 'error' => $e->getMessage()
             ]);
-            
+
             return [
                 'error' => $e->getMessage(),
                 'year' => $year,
@@ -135,7 +135,7 @@ class FeeStatisticsService
                 'app_id' => $appId,
                 'error' => $e->getMessage()
             ]);
-            
+
             return [
                 'error' => $e->getMessage(),
                 'data' => []
@@ -155,16 +155,16 @@ class FeeStatisticsService
         try {
             $endDate = Carbon::yesterday()->format('Y-m-d');
             $startDate = Carbon::yesterday()->subDays($days - 1)->format('Y-m-d');
-            
+
             return self::getStatsByDateRange($startDate, $endDate, $appId);
-            
+
         } catch (\Exception $e) {
             Log::error("获取手续费趋势数据失败", [
                 'days' => $days,
                 'app_id' => $appId,
                 'error' => $e->getMessage()
             ]);
-            
+
             return [
                 'error' => $e->getMessage(),
                 'data' => [],
@@ -192,7 +192,7 @@ class FeeStatisticsService
                 'limit' => $limit,
                 'error' => $e->getMessage()
             ]);
-            
+
             return [
                 'error' => $e->getMessage(),
                 'data' => []
@@ -211,24 +211,24 @@ class FeeStatisticsService
     {
         try {
             Log::info("开始重新统计手续费数据", ['date' => $date, 'app_id' => $appId]);
-            
+
             $result = FeeStatisticsLogic::restatistics($date, $appId);
-            
+
             Log::info("重新统计手续费数据完成", [
                 'date' => $date,
                 'app_id' => $appId,
                 'result' => $result
             ]);
-            
+
             return $result;
-            
+
         } catch (\Exception $e) {
             Log::error("重新统计手续费数据失败", [
                 'date' => $date,
                 'app_id' => $appId,
                 'error' => $e->getMessage()
             ]);
-            
+
             throw $e;
         }
     }
@@ -260,22 +260,22 @@ class FeeStatisticsService
     {
         try {
             $cutoffDate = Carbon::now()->subDays($retentionDays)->format('Y-m-d');
-            
+
             $deletedCount = TransferFeeDailyStats::where('stat_date', '<', $cutoffDate)->delete();
-            
+
             Log::info("清理过期手续费统计数据", [
                 'cutoff_date' => $cutoffDate,
                 'deleted_count' => $deletedCount
             ]);
-            
+
             return $deletedCount;
-            
+
         } catch (\Exception $e) {
             Log::error("清理过期手续费统计数据失败", [
                 'retention_days' => $retentionDays,
                 'error' => $e->getMessage()
             ]);
-            
+
             throw $e;
         }
     }
@@ -295,7 +295,7 @@ class FeeStatisticsService
                 'date' => $date,
                 'error' => $e->getMessage()
             ]);
-            
+
             return [
                 'valid' => false,
                 'error' => $e->getMessage(),

+ 2 - 0
app/Module/UrsPromotion/AdminControllers/UrsPartnerDividendController.php

@@ -41,6 +41,8 @@ class UrsPartnerDividendController extends AdminController
         return Grid::make(new UrsPartnerDividendRepository(), function (Grid $grid) {
             // 基础列配置
             $grid->column('id', 'ID')->sortable();
+            $grid->column('transfer_app_id', 'transfer_app_id');
+
             $grid->column('dividend_date', '分红日期')->sortable();
             $grid->column('total_fee_amount', '总手续费')->sortable()->display(function ($value) {
                 return number_format($value, 4) . ' 钻石';

+ 9 - 12
app/Module/UrsPromotion/Logics/UrsPartnerDividendLogic.php

@@ -49,10 +49,10 @@ class UrsPartnerDividendLogic
             Log::warning($message);
             return ['success' => false, 'message' => $message];
         }
-
+        $transferAppId = 2;
         try {
             // 1. 获取今日手续费统计
-            $totalFeeAmount = $this->getTodayTotalFeeAmount($date);
+            $totalFeeAmount = $this->getTodayTotalFeeAmount($date,$transferAppId);
             if ($totalFeeAmount <= 0) {
                 $message = "日期 {$date} 没有手续费收入,无需分红";
                 Log::info($message);
@@ -75,7 +75,7 @@ class UrsPartnerDividendLogic
             $perPartnerAmount = bcdiv($dividendAmount, $partnerCount, 10);
 
             // 5. 创建或获取分红记录(幂等性)
-            $dividendRecord = $this->createOrGetDividendRecord($date, $totalFeeAmount, $dividendAmount, $partnerCount, $perPartnerAmount);
+            $dividendRecord = $this->createOrGetDividendRecord($date, $totalFeeAmount, $dividendAmount, $partnerCount, $perPartnerAmount,$transferAppId);
 
             // 6. 分批处理分红详情
             $result = $this->processDividendDetailsBatch($dividendRecord, $partners, $perPartnerAmount);
@@ -124,11 +124,11 @@ class UrsPartnerDividendLogic
     /**
      * 获取今日总手续费金额
      */
-    private function getTodayTotalFeeAmount(string $date): string
+    private function getTodayTotalFeeAmount(string $date,$appId): string
     {
         try {
             // 获取所有应用的手续费统计
-            $result = FeeStatisticsService::getStatsByDateRange($date, $date);
+            $result = FeeStatisticsService::getStatsByDateRange($date, $date,$appId);
 
             // 检查是否有错误
             if (isset($result['error'])) {
@@ -203,7 +203,7 @@ class UrsPartnerDividendLogic
     /**
      * 创建或获取分红记录(幂等性)
      */
-    private function createOrGetDividendRecord(string $date, string $totalFeeAmount, string $dividendAmount, int $partnerCount, string $perPartnerAmount): UrsPartnerDividendRecord
+    private function createOrGetDividendRecord(string $date, string $totalFeeAmount, string $dividendAmount, int $partnerCount, string $perPartnerAmount,int $transferAppId): UrsPartnerDividendRecord
     {
         // 先尝试获取已存在的记录
         $existingRecord = UrsPartnerDividendRecord::getByDate($date);
@@ -215,11 +215,8 @@ class UrsPartnerDividendLogic
             return $existingRecord;
         }
 
-        // 获取默认的转账应用ID (假设使用第一个启用的应用)
-        $transferApp = TransferApp::where('is_enabled', true)->first();
-        if (!$transferApp) {
-            throw new \Exception('没有找到可用的转账应用');
-        }
+
+
 
         return UrsPartnerDividendRecord::create([
             'dividend_date' => $date,
@@ -227,7 +224,7 @@ class UrsPartnerDividendLogic
             'dividend_amount' => $dividendAmount,
             'partner_count' => $partnerCount,
             'per_partner_amount' => $perPartnerAmount,
-            'transfer_app_id' => $transferApp->id,
+            'transfer_app_id' => $transferAppId,
             'status' => UrsPartnerDividendRecord::STATUS_PROCESSING
         ]);
     }