| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- <?php
- namespace console\controllers;
- use biz\ghs\classes\GhsClass;
- use biz\shop\classes\MainClass;
- use biz\shop\classes\ShopClass;
- use biz\shop\models\Shop;
- use bizGhs\custom\classes\CustomClass;
- use bizGhs\order\classes\OrderClass;
- use bizGhs\order\models\Order;
- use bizHd\purchase\classes\PurchaseClass;
- use common\components\noticeUtil;
- use common\components\util;
- use yii\console\Controller;
- use Yii;
- class ShopController extends Controller
- {
- //【有用的脚本】总欠款变动记录跟踪 ./yii shop/total-debt-check ssh 20220909
- public function actionTotalDebtCheck()
- {
- //感觉好像没有用了,可以停了 ssh 20250724
- util::stop();
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- $list = ShopClass::getAllByCondition(['ptStyle' => 2], null, '*', null, true);
- if (!empty($list)) {
- foreach ($list as $shop) {
- $sjName = $shop->merchantName ?? '';
- $shopName = $shop->shopName ?? '';
- $mainId = $shop->mainId ?? 0;
- $main = MainClass::getById($mainId, true);
- if (empty($main)) {
- continue;
- }
- $customList = CustomClass::getAllByCondition(['ownMainId' => $mainId], null, '*', null, true);
- $ghsCustomDebt = 0;
- if (!empty($customList)) {
- foreach ($customList as $custom) {
- $debtAmount = $custom->debtAmount ?? 0;
- $ghsCustomDebt = bcadd($ghsCustomDebt, $debtAmount, 2);
- }
- }
- $hdCustomDebt = 0;
- $lsShopId = $shop->lsShopId ?? 0;
- $customList = \bizHd\custom\classes\CustomClass::getAllByCondition(['shopId' => $lsShopId], null, '*', null, true);
- if (!empty($customList)) {
- foreach ($customList as $custom) {
- $currentDebt = $custom->debtAmount ?? 0;
- $hdCustomDebt = bcadd($currentDebt, $hdCustomDebt, 2);
- }
- }
- $totalDebt = bcadd($ghsCustomDebt, $hdCustomDebt, 2);
- if (floatval($totalDebt) != floatval($main->debt)) {
- noticeUtil::push("{$sjName} {$shopName}的批零客户欠款总和跟main里的欠款不一致 总和欠款:{$totalDebt} main欠款:{$main->debt} mainId:{$mainId} | 批发:{$ghsCustomDebt} 零售:{$hdCustomDebt}", '15280215347');
- }
- }
- }
- }
- public function actionHasGhs()
- {
- $query = new \yii\db\Query();
- $query->from(Shop::tableName());
- $query->where(['ptStyle' => 1]);
- foreach ($query->batch() as $shopList) {
- foreach ($shopList as $shop) {
- $shopId = $shop['id'] ?? 0;
- $where = ['ownShopId' => $shopId];
- $count = GhsClass::getCount($where);
- if ($count == 0) {
- //无操作
- } elseif ($count == 1) {
- $ghs = GhsClass::getByCondition($where, true);
- $ghsId = $ghs->id ?? 0;
- if (!empty($ghsId)) {
- ShopClass::updateById($shopId, ['uniGhsId' => $ghsId]);
- }
- } else {
- ShopClass::updateById($shopId, ['hasManyGhs' => 1]);
- }
- }
- }
- }
- public function actionOrder()
- {
- $query = new \yii\db\Query();
- $query->from(Order::tableName());
- $query->where(['>', 'id', 0]);
- foreach ($query->batch() as $orderList) {
- foreach ($orderList as $order) {
- $payTime = $order['payTime'] ?? '';
- if (!empty($payTime) && $payTime != '0000-00-00 00:00:00') {
- $addTime = $order['addTime'] ?? '';
- if ($payTime > $addTime) {
- echo "id:{$order['id']} {$payTime} {$addTime}\n";
- OrderClass::updateById($order['id'], ['addTime' => $payTime]);
- $purchaseId = $order['purchaseId'] ?? 0;
- $cg = PurchaseClass::getById($purchaseId, true);
- if (!empty($cg)) {
- $cg->addTime = $payTime;
- $cg->save();
- }
- }
- }
- }
- }
- }
- public function actionCustom()
- {
- $custom = CustomClass::getAllByCondition(['id>' => 0], null, '*', null, true);
- if (empty($custom)) {
- echo '空';
- return false;
- }
- foreach ($custom as $item) {
- $shopId = $item->shopId ?? 0;
- $shop = ShopClass::getById($shopId, true);
- if ($shop->mainId != $item->mainId) {
- echo "客户id:{$item->id} {$shop->mainId} {$item->mainId}\n";
- if (!empty($shop->mainId)) {
- $item->mainId = $shop->mainId;
- $item->save();
- }
- }
- $ownShopId = $item->ownShopId ?? 0;
- $ownShop = ShopClass::getById($ownShopId, true);
- if ($ownShop->mainId != $item->ownMainId) {
- echo "客户own {$item->id} {$item->ownMainId} {$ownShop->mainId}\n";
- if (!empty($ownShop->mainId)) {
- $item->ownMainId = $ownShop->mainId;
- $item->save();
- }
- }
- }
- }
- public function actionGhs()
- {
- $ghs = GhsClass::getAllByCondition(['id>' => 0], null, '*', null, true);
- if (empty($ghs)) {
- echo '空';
- return false;
- }
- foreach ($ghs as $item) {
- $shopId = $item->shopId ?? 0;
- $mainId = $item->mainId ?? 0;
- $shop = ShopClass::getById($shopId, true);
- if ($shop->mainId != $mainId) {
- echo "ghs {$item->id} {$mainId} {$shop->mainId} \n";
- }
- $ownShopId = $item->ownShopId ?? 0;
- $ownMainId = $item->ownMainId ?? 0;
- $ownShop = ShopClass::getById($ownShopId, true);
- if ($ownShop->mainId != $ownMainId) {
- echo "ghs own {$item->id} {$ownMainId} {$ownShop->mainId} \n";
- if (!empty($ownShop->mainId)) {
- $item->ownMainId = $ownShop->mainId;
- $item->save();
- }
- }
- }
- }
- }
|