Przeglądaj źródła

feat: EK-879: 【AE】管理员增加“Country”属性,根据所选国家限制登录后所显示的奖金、余额等数据(二期).

kevinElken 9 miesięcy temu
rodzic
commit
26389c2f46

+ 5 - 0
backendApi/modules/v1/models/Admin.php

@@ -132,6 +132,11 @@ class Admin extends ActiveRecord
         return $data ? $data['ADMIN_NAME'] : null;
     }
 
+    public static function getRoleIdById($id){
+        $data = self::findOneAsArray('ID=:ID', [':ID' => $id], 'ADMIN_NAME');
+        return $data ? $data['ROLE_ID'] : null;
+    }
+
     /**
      * 操作日志记录条件
      * @return array

+ 1 - 3
common/models/forms/UserBonusForm.php

@@ -2,7 +2,6 @@
 namespace common\models\forms;
 
 use common\components\Model;
-use Yii;
 use yii\base\Exception;
 
 /**
@@ -48,8 +47,7 @@ class UserBonusForm extends Model
         // 异步处理添加任务
         $settings = \Yii::$app->params['swooleAsyncTimer'];
         $bonusSettings = \Yii::$app->params['swooleBonusConfig'];
-        $adminId = Yii::$app->getUser()->getUserInfo()['id'];
-        $settings = array_merge($settings, $bonusSettings, ['admin' => $adminId]);
+        $settings = array_merge($settings, $bonusSettings);
         $taskKey = \Yii::$app->swooleAsyncTimer->asyncHandle('bonus/auto-withdraw', \Yii::$app->request->get(), $settings);
         if($taskKey === false){
             $this->addError('perf', '请求失败');

+ 29 - 3
common/models/forms/WithdrawForm.php

@@ -2,6 +2,9 @@
 
 namespace common\models\forms;
 
+use backendApi\modules\v1\models\Admin;
+use backendApi\modules\v1\models\AdminCountry;
+use backendApi\modules\v1\models\AdminRole;
 use common\components\Model;
 use common\helpers\Cache;
 use common\helpers\Date;
@@ -735,11 +738,34 @@ class WithdrawForm extends Model {
      *
      * @throws \yii\db\Exception
      */
-    public function batchWithdraw($limit, $start){
+    public function batchWithdraw($limit, $start, $params){
         $config = Cache::getSystemConfig();
         $minAmount = $config['manualWithdrawMinAmount']['VALUE'];
+
+        $condition = '';
+        $adminRoleId = Admin::getRoleIdById($params['handleUserId']);
+        $isSuper = AdminRole::isSuperAdmin($adminRoleId);
+        if (!$isSuper) {
+            $adminCountry = AdminCountry::getCountry($params['handleUserId']);
+            $quotedAdminCountry = array_map(function($item) {
+                return "'" . addslashes($item) . "'";
+            }, $adminCountry);
+
+            $condition .= " AND U.COUNTRY_ID IN (" . implode(',', $quotedAdminCountry) . ")";
+        }
+
         // 查找有奖金的用户
-        $allData = UserBonus::find()->select('USER_ID, USER_NAME, ID_CARD, BONUS')->from(UserBonus::tableName().' AS UB')->join('LEFT JOIN', User::tableName().' AS U','UB.USER_ID = U.ID')->where("BONUS>$minAmount")->offset(0)->limit($limit)->orderBy('U.ID')->asArray()->all();
+        $allData = UserBonus::find()
+            ->select('USER_ID, USER_NAME, ID_CARD, BONUS')
+            ->from(UserBonus::tableName().' AS UB')
+            ->join('INNER JOIN', User::tableName() . ' AS U','UB.USER_ID = U.ID ' . $condition)
+            ->where("BONUS>$minAmount")
+            ->offset(0)
+            ->limit($limit)
+            ->orderBy('U.ID')
+            ->asArray()
+            ->all();
+
         if($allData){
             foreach ($allData as $data){
                 $db = \Yii::$app->db;
@@ -787,7 +813,7 @@ class WithdrawForm extends Model {
             unset($allData);
             $start = $start + $limit;
 
-            return self::batchWithdraw($limit, $start);
+            return self::batchWithdraw($limit, $start, $params);
         }
         return true;
     }

+ 8 - 6
console/controllers/BonusController.php

@@ -7,6 +7,9 @@
  */
 namespace console\controllers;
 
+use backendApi\modules\v1\models\Admin;
+use backendApi\modules\v1\models\AdminCountry;
+use backendApi\modules\v1\models\AdminRole;
 use backendApi\modules\v1\models\lists\bonus\BalanceList;
 use backendApi\modules\v1\models\lists\bonus\CfLxAuditList;
 use backendApi\modules\v1\models\lists\bonus\FlowBalanceList;
@@ -59,6 +62,7 @@ use common\models\forms\WithdrawForm;
 use common\models\LogAsync;
 use common\models\Withdraw;
 use common\models\UserBonus;
+use Yii;
 use yii\db\Exception;
 
 class BonusController extends BaseController
@@ -532,12 +536,10 @@ class BonusController extends BaseController
     public function actionAutoWithdraw($taskKey){
         $params = Cache::getAsyncParams($taskKey);
 
-        LoggerTool::debug(['actionAutoWithdraw', $params]);
-
-//        Cache::setWithdrawLock(1);
-//        $formModel = new WithdrawForm();
-//        $formModel->batchWithdraw(1000,0);
-//        Cache::setWithdrawLock(0);
+        Cache::setWithdrawLock(1);
+        $formModel = new WithdrawForm();
+        $formModel->batchWithdraw(1000,0, $params);
+        Cache::setWithdrawLock(0);
     }
 
     /**