| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?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\util;
- use yii\console\Controller;
- use Yii;
- class GhsController extends Controller
- {
- 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');
- $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);
- }
- }
- }
- }
- }
- }
|