|
|
@@ -2,12 +2,35 @@
|
|
|
|
|
|
namespace mall\controllers;
|
|
|
|
|
|
-use bizMall\ad\services\AdService;
|
|
|
-use bizMall\goods\services\CategoryService;
|
|
|
-use bizMall\goods\services\GoodsCategoryService;
|
|
|
use common\components\util;
|
|
|
+use Yii;
|
|
|
+use yii\web\HttpException;
|
|
|
|
|
|
class MainController extends BaseController
|
|
|
{
|
|
|
+ public $guestAccess = ['index', 'error'];
|
|
|
|
|
|
-}
|
|
|
+ /**
|
|
|
+ * 默认首页:供健康检查、域名根路径访问,避免 defaultRoute 404
|
|
|
+ */
|
|
|
+ public function actionIndex()
|
|
|
+ {
|
|
|
+ util::success([
|
|
|
+ 'service' => 'app-mall',
|
|
|
+ 'status' => 'ok',
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 统一 JSON 错误输出(替代不存在的 site/error)
|
|
|
+ */
|
|
|
+ public function actionError()
|
|
|
+ {
|
|
|
+ $exception = Yii::$app->errorHandler->exception;
|
|
|
+ if ($exception instanceof HttpException) {
|
|
|
+ util::error($exception->statusCode, $exception->getMessage());
|
|
|
+ }
|
|
|
+ $message = $exception ? $exception->getMessage() : '服务器错误';
|
|
|
+ util::fail($message);
|
|
|
+ }
|
|
|
+}
|