|
|
@@ -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;
|
|
|
+ }
|
|
|
}
|