| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <?php
- namespace console\controllers;
- use bizGhs\clear\classes\OrderCgClearClass;
- use bizGhs\order\classes\OrderClearClass;
- use bizGhs\order\classes\OrderClass;
- use bizHd\purchase\classes\PurchaseClass;
- use bizHd\purchase\classes\PurchaseClearClass;
- use common\components\dict;
- use yii\console\Controller;
- use yii\console\ExitCode;
- class ClearController extends Controller
- {
- /** @var int 是否仅预览,1=是 */
- public $dryRun = 0;
- /** @var int 每批处理条数 */
- public $batchSize = 200;
- /** @var int 指定结账单 ID,0=全部 */
- public $clearId = 0;
- public function options($actionID)
- {
- return array_merge(parent::options($actionID), [
- 'dryRun',
- 'batchSize',
- 'clearId',
- ]);
- }
- //更新 ssh 2023503
- public function actionUpdate()
- {
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- $list = OrderClearClass::getAllByCondition(['status' => 2], null, '*', null, true);
- if (!empty($list)) {
- foreach ($list as $clear) {
- $payTime = $clear->payTime ?? '';
- $saleIds = $clear->saleIds ?? '';
- $ids = explode(',', trim($saleIds));
- print_r($ids);
- if (!empty($ids)) {
- OrderClass::updateByIds($ids, ['clearTime' => $payTime]);
- }
- $purchaseIds = $clear->purchaseIds ?? '';
- $purchaseIds = explode(',', $purchaseIds);
- print_r($purchaseIds);
- if (!empty($purchaseIds)) {
- PurchaseClass::updateByIds($purchaseIds, ['clearTime' => $payTime]);
- }
- echo "-----------------\n";
- }
- }
- }
- /**
- * 历史 xhClear 回填 xhOrderCgClear
- *
- * 用法:
- * php yii clear/backfill-order-cg-clear
- * php yii clear/backfill-order-cg-clear --dryRun=1
- * php yii clear/backfill-order-cg-clear --clearId=123
- */
- public function actionBackfillOrderCgClear()
- {
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- if ($this->batchSize < 1) {
- $this->stderr("batchSize 必须大于 0\n");
- return ExitCode::UNSPECIFIED_ERROR;
- }
- $hd2Gys = dict::getDict('clearStyle', 'hd2Gys');
- $gys2Hd = dict::getDict('clearStyle', 'gys2Hd');
- $where = [
- 'clearStyle' => ['in', [intval($hd2Gys), intval($gys2Hd)]],
- ];
- if ($this->clearId > 0) {
- $where['id'] = intval($this->clearId);
- }
- $lastId = 0;
- $total = 0;
- $inserted = 0;
- $skipped = 0;
- $this->stdout(sprintf(
- "开始回填 xhOrderCgClear,dryRun=%d,batchSize=%d,clearId=%d\n",
- (int)$this->dryRun,
- $this->batchSize,
- (int)$this->clearId
- ));
- while (true) {
- $batchWhere = $where;
- if ($lastId > 0) {
- $batchWhere['id>'] = $lastId;
- }
- $list = PurchaseClearClass::getLimitList('*', $batchWhere, $this->batchSize, 'id asc');
- if (empty($list)) {
- break;
- }
- foreach ($list as $clear) {
- $total++;
- $lastId = intval($clear['id'] ?? 0);
- $saleIds = trim($clear['saleIds'] ?? '');
- $purchaseIds = trim($clear['purchaseIds'] ?? '');
- if ($saleIds === '' && $purchaseIds === '') {
- $skipped++;
- continue;
- }
- if ($this->dryRun) {
- $this->stdout("dryRun clearId={$lastId} saleIds={$saleIds} purchaseIds={$purchaseIds}\n");
- continue;
- }
- $count = OrderCgClearClass::backfillFromClear($clear);
- if ($count > 0) {
- $inserted += $count;
- $this->stdout("clearId={$lastId} 写入 {$count} 行\n");
- } else {
- $skipped++;
- }
- }
- if (count($list) < $this->batchSize) {
- break;
- }
- }
- $this->stdout("完成:扫描 {$total} 条,写入 {$inserted} 行关系,跳过 {$skipped} 条\n");
- return ExitCode::OK;
- }
- }
|