request->isAjax) { $service = new MerchantService(['mall_id' => $this->mall_id, 'store_id' => $this->store_id]); return $this->success('ok', [ 'setting' => $service->getSetting(), 'link' => $service->getSignLink(), ], ApiStatusEnum::CODE_SUCCESS, 0); } return $this->render('setting'); } /** * 保存设置 * * @return void */ public function actionSaveSetting() { if ($this->request->isAjax) { $setting = $this->request->post(); unset($setting['_csrf']); $service = new MerchantService(['mall_id' => $this->mall_id, 'store_id' => $this->store_id]); return $service->setSetting($setting) ? $this->success('ok') : $this->error('保存失败'); } } /** * 让利设置 * @return mixed */ public function actionProfitSetting() { if (\Yii::$app->request->isAjax) { $service = new MerchantReduceProfitService(); if (\Yii::$app->request->isPost) { $setting = $this->request->post(); // 数据校验 $res = \Yii::$app->services->validate->validate($setting, [ [['new_rate'], 'required'], [['new_rate'], 'number'], [['id'], 'integer'], ], [ 'rate' => '让利比例', ]); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $ret = $service->save($this->mall_id, 0, $this->store_id, $setting['new_rate'], intval($setting['id'] ?? 0)); return is_string($ret) ? $this->error($ret) : $this->success('提交成功'); } else { // 当前让利, 需要从higo插件取 $ret = $service->profit($this->mall_id, 0, $this->store_id); return $this->success('获取成功', $ret); } } return $this->render($this->action->id); } }