Forráskód Böngészése

Merge branch 'master' into dev

shish 2 hónapja
szülő
commit
a440411632
1 módosított fájl, 51 hozzáadás és 11 törlés
  1. 51 11
      console/controllers/ClearController.php

+ 51 - 11
console/controllers/ClearController.php

@@ -5,6 +5,8 @@ namespace console\controllers;
 use biz\ghs\classes\GhsBackClass;
 use bizGhs\clear\classes\OrderCgClearClass;
 use bizGhs\clear\models\Clear;
+use bizGhs\custom\classes\CustomClass;
+use bizGhs\custom\services\GhsRechargeSettleService;
 use bizGhs\ghs\classes\GhsClass;
 use bizGhs\ghs\models\Ghs;
 use bizGhs\order\classes\OrderClass;
@@ -109,28 +111,23 @@ class ClearController extends Controller
 
     }
 
-    public function actionGhsBalance()
+    public function actionBalance()
     {
         ini_set('memory_limit', '2045M');
         set_time_limit(0);
-
-        $sql = "delete from xhGhsBack";
-        Yii::$app->db->createCommand($sql)->execute();
-
+        //$sql = "delete from xhGhsBack";
+        //Yii::$app->db->createCommand($sql)->execute();
         $query = new \yii\db\Query();
         $query->from(Ghs::tableName());
         $query->where(['ownPtStyle' => 1]);
         $query->andWhere(['>', 'balance', 0]);
         foreach ($query->batch(500) as $ghsList) {
-
             $connection = Yii::$app->db;
             $transaction = $connection->beginTransaction();
             try {
-
                 foreach ($ghsList as $ghs) {
                     GhsBackClass::add($ghs);
                 }
-
                 $transaction->commit();
             } catch (\Exception $e) {
                 $transaction->rollBack();
@@ -140,7 +137,50 @@ class ClearController extends Controller
         }
     }
 
-    public function actionGhsUp()
+    public function actionBalanceBack()
+    {
+        $list = GhsBackClass::getAllByCondition(['id>' => 0], null, '*', 'id', true);
+        if (!empty($list)) {
+            foreach ($list as $ghs) {
+                $ownPtStyle = $ghs['ownPtStyle'] ?? 1;
+                $balance = $ghs['balance'] ?? 0;
+                $customId = $ghs['customId'] ?? 0;
+                if ($ownPtStyle == 1) {
+                    $custom = CustomClass::getById($customId, true);
+                    if (!empty($custom)) {
+                        $shopId = $ghs['shopId'] ?? 0;
+                        $shop = \bizGhs\shop\classes\ShopClass::getById($shopId, true);
+                        if (!empty($shop)) {
+                            $connection = Yii::$app->db;
+                            $transaction = $connection->beginTransaction();
+                            try {
+                                $staff = new \stdClass();
+                                $staff->id = 0;
+                                $staff->name = '';
+                                $params = [
+                                    'remark' => '系统升级恢复',
+                                    'rechargeType' => 0, // 0 代表正常充值
+                                ];
+                                // 模拟商家帮充并自动销挂账,payWay 设为 0 (线下微信)
+                                GhsRechargeSettleService::merchantRechargeWithAutoClear($custom, $balance, $shop, $staff, 0, $params);
+                                $transaction->commit();
+                                echo "customId: {$customId} 充值成功 {$balance} 元\n";
+                            } catch (\Exception $e) {
+                                $transaction->rollBack();
+                                echo "customId: {$customId} 充值失败: " . $e->getMessage() . "\n";
+                            }
+                        } else {
+                            echo "customId: {$customId} 找不到对应的 shop\n";
+                        }
+                    } else {
+                        echo "customId: {$customId} 找不到对应的 custom\n";
+                    }
+                }
+            }
+        }
+    }
+
+    public function actionGhsGhs()
     {
         ini_set('memory_limit', '2045M');
         set_time_limit(0);
@@ -153,14 +193,14 @@ class ClearController extends Controller
             $connection = Yii::$app->db;
             $transaction = $connection->beginTransaction();
             try {
-
                 foreach ($ghsList as $ghs) {
                     $ghsId = $ghs['id'] ?? 0;
                     $balance = PurchaseOrderClass::sum(['ghsId' => $ghsId, 'debt' => 1], 'actPrice');
                     $debtNum = PurchaseOrderClass::getCount(['ghsId' => $ghsId, 'debt' => 1]);
                     GhsClass::updateById($ghsId, ['balance' => -$balance, 'debtNum' => $debtNum]);
+                    $customId = $ghs['customId'] ?? 0;
+                    CustomClass::updateById($customId, ['balance' => -$balance, 'debtNum' => $debtNum]);
                 }
-
                 $transaction->commit();
             } catch (\Exception $e) {
                 $transaction->rollBack();