| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- namespace addons\Store\client\controllers;
- use addons\Store\common\services\MerchantReduceProfitService;
- use addons\Store\common\services\MerchantService;
- use common\enums\ApiStatusEnum;
- use yii\helpers\Json;
- /**
- * 商户
- * @package addons\Store\client\controllers
- */
- class MerchantController extends BaseController
- {
- /**
- * 商户号设置
- *
- * @return void
- */
- public function actionSetting()
- {
- if ($this->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);
- }
- }
|