// +---------------------------------------------------------------------- declare (strict_types=1); namespace app\admin\controller\store; use think\response\Json; use think\db\exception\DbException; use think\db\exception\DataNotFoundException; use think\db\exception\ModelNotFoundException; use app\admin\controller\Controller; use app\admin\model\store\Module as ModuleModel; /** * 商家后台功能模块控制器 * Class Module * @package app\store\controller */ class Module extends Controller { /** * 获取系统默认的功能模块 * @return Json */ public function default(): Json { $default = ModuleModel::getDefaultConfig(); return $this->renderSuccess(compact('default')); } /** * 获取指定商家的功能模块 * @param int $storeId * @return Json * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException */ public function detail(int $storeId): Json { $model = new ModuleModel; $moduleKeys = $model->getConfigValue($storeId); return $this->renderSuccess(compact('moduleKeys')); } /** * 更新指定商家的功能模块 * @param int $storeId * @return Json * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException */ public function edit(int $storeId): Json { $model = ModuleModel::getDetail($storeId); if ($model->edit($this->postForm())) { return $this->renderSuccess('操作成功'); } return $this->renderError($model->getError() ?: '添加失败'); } }