ソースを参照

feature/2025-12-26-SEND_USER_PERFORMANCE

ryan 1 週間 前
コミット
50e0f3e5f0

+ 48 - 0
common/models/UserPerformance.php

@@ -237,4 +237,52 @@ class UserPerformance extends \common\components\ActiveRecord
 
         return true;
     }
+
+    /**
+     * 绩效奖金发放
+     * @param $userId
+     * @param $amount
+     * @param $bountyPeriodNum
+     * @return bool
+     * @throws Exception
+     */
+    public static function sentUserPerformanceApi($userId, $amount, $bountyPeriodNum): bool
+    {
+        if ($amount == 0) {
+            return true;
+        }
+
+        // 会员国家
+        $countryCode = Countries::getById(User::getEnCodeInfo($userId)['COUNTRY_ID'])['CODE'];
+
+        $db = \Yii::$app->db;
+        $transaction = $db->beginTransaction();
+        try {
+            // 奖金发放
+            $id = 'EP' . Tool::generateUserPerformanceNo($countryCode);
+            self::insertOne([
+                'ID' => $id,
+                'USER_ID' => $userId,
+                'AMOUNTS' => $amount,
+                'ORIGINAL' => $amount,
+                'STATUS_ID' => self::NEWS,
+                'EXPIRED_AT' => date('Y-m-d H:i:s', strtotime('+1 year', time())),
+                'CREATED_AT' => date('Y-m-d H:i:s', time()),
+                'UPDATED_AT' => date('Y-m-d  H:i:s', time()),
+                'REMARK' => DealType::getDealTypeTagById(DealType::USER_PERFORMANCE_SEND),
+                'BOUNTY_PERIOD_NUM' => $bountyPeriodNum,
+                'PAID_PERIOD_NUM' => $bountyPeriodNum-1,
+            ]);
+
+            // 写日志
+            UserPerformanceLogs::changeAmountLogs($id, $amount, $bountyPeriodNum-1, '', DealType::getDealTypeTagById(DealType::USER_PERFORMANCE_SEND));
+
+            $transaction->commit();
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            throw new Exception(sprintf('PB奖金挂网异常:File: %s, Line: {%s}, message: %s', $e->getFile(), $e->getLine(), $e->getMessage()));
+        }
+
+        return true;
+    }
 }

+ 1 - 0
frontendApi/config/params.php

@@ -22,6 +22,7 @@ return [
         'v1/site/languages',
 //        'v1/site/countries',
         'v1/bonus/period',
+        'v1/bonus/sent-user-performance',
         ],
     'noCheckPermissionActions' => [],
 ];

+ 1 - 0
frontendApi/config/urlManagerRules.php

@@ -161,6 +161,7 @@ return [
             'GET fc-point' => 'fc-point',
             'GET historical-cumulative-bonus' => 'historical-cumulative-bonus',
             'GET period' => 'period',
+            'POST sent-user-performance' => 'sent-user-performance',
         ],
     ],
     [

+ 13 - 0
frontendApi/modules/v1/controllers/BonusController.php

@@ -917,4 +917,17 @@ class BonusController extends BaseController {
 
         return static::notice(['data' => $data]);
     }
+
+    function actionSentUserPerformance()
+    {
+        if (\Yii::$app->request->isPost) {
+            $param = \Yii::$app->request->post();
+            foreach ($param as $value){
+                UserPerformance::sentUserPerformanceApi($value['user_id'], $value['amount'], $value['period']);
+            }
+            return static::notice(Yii::t('app', 'successfully'));
+        } else {
+            return static::notice(Yii::t('app', 'illegalRequest'), 400);
+        }
+    }
 }