| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- <?php
- 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;
- use bizGhs\order\classes\PurchaseOrderClass;
- use bizHd\purchase\classes\PurchaseClass;
- use yii\console\Controller;
- use Yii;
- class ClearController extends Controller
- {
- //补回 xhOrderCgClear
- public function actionBc()
- {
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- if (getenv('YII_ENV') == 'production') {
- $autoId = 817342;
- } else {
- $autoId = 1426;
- }
- $query = new \yii\db\Query();
- $query->from(Clear::tableName());
- $query->where(['>', 'id', $autoId]);
- foreach ($query->batch(500) as $changeList) {
- $ids = array_column($changeList, 'id');
- $relate = OrderCgClearClass::getAllByCondition(['clearId' => ['in', $ids]], null, '*', 'clearId');
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- foreach ($changeList as $clear) {
- $clearId = $clear['id'] ?? 0;
- $clearSn = $clear['orderSn'] ?? '';
- $status = $clear['status'] ?? 1;
- $clearAmount = $clear['actPrice'] ?? 0;
- $purchaseIds = $clear['purchaseIds'] ?? '';
- $saleIds = $clear['saleIds'] ?? '';
- $clearStyle = $clear['clearStyle'] ?? 1;
- if (!isset($relate[$clearId])) {
- if ($clearStyle == 3) {
- if (!empty($purchaseIds)) {
- $purchaseIdList = explode(',', $purchaseIds);
- $purchaseInfo = PurchaseOrderClass::getAllByCondition(['id' => ['in', $purchaseIdList]], null, 'id,orderSn', 'id');
- foreach ($purchaseInfo as $purchase) {
- $purchaseId = $purchase['id'] ?? 0;
- $purchaseOrderSn = $purchase['orderSn'] ?? 0;
- $addData = ['orderId' => 0, 'orderSn' => '', 'cgId' => $purchaseId, 'cgSn' => $purchaseOrderSn,
- 'clearId' => $clearId, 'clearSn' => $clearSn, 'amount' => $clearAmount, 'status' => $status];
- OrderCgClearClass::add($addData);
- echo "ghs cg clearId {$clearId} OK ### \n";
- }
- } else {
- echo "供货商采购 clearId {$clearId} 有缺数据 \n";
- }
- } else {
- if (!empty($saleIds) && !empty($purchaseIds)) {
- $saleIdList = explode(',', $saleIds);
- $purchaseIdList = explode(',', $purchaseIds);
- $saleInfo = OrderClass::getAllByCondition(['id' => ['in', $saleIdList]], null, 'id,orderSn,purchaseId');
- $purchaseInfo = PurchaseClass::getAllByCondition(['id' => ['in', $purchaseIdList]], null, 'id,orderSn', 'id');
- if (!empty($saleInfo)) {
- foreach ($saleInfo as $sale) {
- $saleId = $sale['id'] ?? 0;
- $purchaseId = $sale['purchaseId'] ?? 0;
- $saleOrderSn = $sale['orderSn'] ?? '';
- $purchase = $purchaseInfo[$purchaseId] ?? [];
- if (empty($purchase)) {
- echo "purchase {$purchaseId} 没有找到 \n";
- exit();
- }
- $purchaseOrderSn = $purchase['orderSn'] ?? '';
- $addData = ['orderId' => $saleId, 'orderSn' => $saleOrderSn, 'cgId' => $purchaseId, 'cgSn' => $purchaseOrderSn,
- 'clearId' => $clearId, 'clearSn' => $clearSn, 'amount' => $clearAmount, 'status' => $status];
- OrderCgClearClass::add($addData);
- }
- echo "hd cg clearId {$clearId} OK *** \n";
- }
- } else {
- echo "花店采购 clearId {$clearId} 有缺数据 \n";
- }
- }
- } else {
- echo "有记录 {$clearId} \n";
- }
- }
- $transaction->commit();
- } catch (\Exception $e) {
- $transaction->rollBack();
- $msg = $e->getMessage();
- echo "报错了:" . $msg . "\n";
- }
- }
- }
- public function actionBalance()
- {
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- //$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();
- $msg = $e->getMessage();
- echo "报错了:" . $msg . "\n";
- }
- }
- }
- 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);
- $query = new \yii\db\Query();
- $query->from(Ghs::tableName());
- $query->where(['ownPtStyle' => 2]);
- foreach ($query->batch(500) as $ghsList) {
- $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();
- $msg = $e->getMessage();
- echo "报错了:" . $msg . "\n";
- }
- }
- }
- }
|