|
|
@@ -46,62 +46,4 @@ class GhsController extends Controller
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public function actionDebt()
|
|
|
- {
|
|
|
- util::stop('已关闭');
|
|
|
- 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);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
}
|