| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- namespace console\controllers;
- use biz\shop\models\Shop;
- use bizGhs\ghs\classes\GhsClass;
- use bizGhs\ghs\classes\GhsDebtRecordClass;
- use bizGhs\order\classes\PurchaseOrderClass;
- use common\components\dict;
- use common\components\noticeUtil;
- use common\components\util;
- use yii\console\Controller;
- use Yii;
- class GhsController extends Controller
- {
- //供货商欠款跟踪 ssh 20240629 重要脚本
- public function actionAdjustDebt()
- {
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- $query = new \yii\db\Query();
- $query->from(Shop::tableName());
- $query->where(['ptStyle' => 2]);
- foreach ($query->batch(10) as $batch) {
- foreach ($batch as $shop) {
- $sjName = $shop['merchantName'] ?? '';
- $shopName = $shop['shopName'] ?? '';
- $name = $sjName . ' ' . $shopName;
- $where = ['ownShopId' => $shop['id']];
- $ghsList = GhsClass::getAllByCondition($where, null, '*', null, true);
- if (!empty($ghsList)) {
- foreach ($ghsList as $ghs) {
- $ghsName = $ghs->name ?? '';
- $ghsId = $ghs->id ?? 0;
- $totalDebtAmount = PurchaseOrderClass::sum(['ghsId' => $ghsId, 'status' => 4, 'debt' => PurchaseOrderClass::DEBT_YES], 'actPrice');
- $totalDebtAmount = empty($totalDebtAmount) ? 0 : $totalDebtAmount;
- $ghsDebtAmount = $ghs->debtAmount ?? 0;
- if (floatval($totalDebtAmount) != floatval($ghsDebtAmount)) {
- noticeUtil::push("{$name}的供货商{$ghsName}({$ghsId})应付金额不一致。登记金额:{$ghsDebtAmount} 汇总金额:{$totalDebtAmount}", '15280215347');
- }
- }
- }
- }
- }
- }
- public function actionDebt()
- {
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- $sql = 'TRUNCATE `xhGhsDebtRecord`;';
- Yii::$app->db->createCommand($sql)->execute();
- $query = new \yii\db\Query();
- $query->from(Shop::tableName());
- $query->where(['ptStyle' => 2]);
- foreach ($query->batch(10) as $batch) {
- foreach ($batch as $shop) {
- $shopId = $shop['id'] ?? 0;
- $sjId = $shop['sjId'] ?? 0;
- $where = ['ownShopId' => $shop['id']];
- $ghsList = GhsClass::getAllByCondition($where, null, '*', null, true);
- if (!empty($ghsList)) {
- foreach ($ghsList as $ghs) {
- $ghsId = $ghs->id ?? 0;
- $totalDebtAmount = PurchaseOrderClass::sum(['ghsId' => $ghsId, 'status' => 4, 'debt' => PurchaseOrderClass::DEBT_YES], 'actPrice');
- $totalDebtAmount = empty($totalDebtAmount) ? 0 : $totalDebtAmount;
- $ghsAddDebtKey = 'ghs_change_debt_' . $ghsId;
- $lock = util::lock($ghsAddDebtKey);
- if (!$lock) {
- echo "供货商 {$ghsId} 数据没有初始化\n";
- continue;
- }
- if ($totalDebtAmount > 0) {
- $ghs->debt = 2;
- } else {
- $ghs->debt = 1;
- }
- $ghs->debtAmount = $totalDebtAmount;
- $ghs->save();
- $capitalType = dict::getDict('capitalType', 'ghsPurchase', 'id');
- $debtData = [
- 'ghsId' => $ghsId,
- 'relateId' => 0,
- 'ptStyle' => 2,
- 'capitalType' => $capitalType,
- 'amount' => $totalDebtAmount,
- 'balance' => $totalDebtAmount,
- 'io' => 1,
- 'event' => '欠款数据初始化',
- 'sjId' => $sjId,
- 'shopId' => $shopId,
- ];
- GhsDebtRecordClass::add($debtData);
- util::unlock($ghsAddDebtKey);
- }
- }
- }
- }
- }
- }
|