0, 'msg' => '请传入 orderId,例如:php yii distribution/calc-order 12345'], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) . PHP_EOL; return 1; } try { $result = DistributionCommissionClass::calcAndPersist($orderId); echo json_encode($result, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) . PHP_EOL; return 0; } catch (\Throwable $e) { echo json_encode(['ok' => 0, 'msg' => $e->getMessage()], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) . PHP_EOL; return 1; } } /** * 仅预览计佣结果(与 calc-order 同一套规则,不写库) */ public function actionPreviewOrder($orderId = 0) { $orderId = (int)$orderId; if ($orderId <= 0) { echo json_encode(['ok' => 0, 'msg' => '请传入 orderId'], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) . PHP_EOL; return 1; } try { $result = DistributionCommissionClass::calculatePreview($orderId); echo json_encode($result, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) . PHP_EOL; return 0; } catch (\Throwable $e) { echo json_encode(['ok' => 0, 'msg' => $e->getMessage()], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) . PHP_EOL; return 1; } } /** * 到期分销结佣(finishTime + settleDays) * 用法:php yii distribution/settle-due 200 * @param int $limit 单次处理条数 * @param int $shopId 0 全部门店 * @return int */ public function actionSettleDue($limit = 200, $shopId = 0) { $result = DistributionSettleClass::runDueSettle((int)$limit, (int)$shopId); echo json_encode(array_merge(['ok' => 1], $result), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) . PHP_EOL; return !empty($result['failed']) ? 1 : 0; } }