| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- namespace addons\OperationCenter\api\modules\v1\controllers;
- use addons\OperationCenter\common\services\ApplyService;
- use addons\OperationCenter\common\services\SettingService;
- use api\controllers\OnAuthController;
- use Yii;
- /**
- * 申请控制器
- *
- * ApplyController class
- * @package addons\OperationCenter\api\modules\v1\controllers
- */
- class ApplyController extends OnAuthController
- {
- /**
- * @var string
- */
- public $modelClass = '';
- /**
- * @var boolean
- */
- public $enableCsrfValidation = false;
- /**
- * 不用进行登录验证的方法
- *
- * 例如: ['index', 'update', 'create', 'view', 'delete']
- * 默认全部需要验证
- *
- * @var array
- */
- protected $authOptional = ['index'];
- /**
- * 获取申请状态
- *
- * @return string
- */
- public function actionGetApplyStatus()
- {
- $service = new ApplyService(['mall_id' => $this->mall_id]);
- return $this->success('ok', $service->getApplyStatus($this->user_id));
- }
- /**
- * 获取申请配置
- *
- * @return string
- */
- public function actionGetApplyConfig()
- {
- $service = new SettingService(['mall_id' => $this->mall_id]);
- return $this->success('ok', $service->getApplyConfig());
- }
- /**
- * 添加申请
- *
- * @return string
- */
- public function actionAddApply()
- {
- $data = $this->request->post();
- $service = new ApplyService(['mall_id' => $this->mall_id]);
- // 申请项
- $apply_for = $service->getApplyingFor();
- $apply_for = array_merge($apply_for, [
- 'province', 'province_id', 'city', 'city_id', 'district', 'district_id', 'logo'
- ]);
- // 验证
- $validate = Yii::$app->services->validate->validate($data, [
- [$apply_for, 'required'],
- [['town', 'town_id'], 'safe']
- ]);
- if ($validate === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- return $service->addApply($this->user_id, $data)
- ? $this->success('ok')
- : $this->error(sprintf('申请失败: %s', $service->getError()));
- }
- }
|