| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace addons\Purchase\api\modules\v1\controllers;
- use addons\Purchase\common\models\PurchaseManager;
- use common\enums\StatusEnum;
- use Yii;
- use api\controllers\OnAuthController;
- /**
- * 会员控制器
- *
- * Class ManagerController
- * @package addons\Purchase\api\modules\v1\controllers
- */
- class ManagerController extends OnAuthController
- {
- public $modelClass = '';
- /**
- * 不用进行登录验证的方法
- *
- * 例如: ['index', 'update', 'create', 'view', 'delete']
- * 默认全部需要验证
- *
- * @var array
- */
- protected $authOptional = ['index'];
- /**
- * 首页
- *
- * @return string
- */
- public function actionIndex()
- {
- return 'Hello world';
- }
- /**
- * @notes:资格申请
- * @return mixed|void|null
- * @author: lun
- * @Time: 2022/10/24 15:05
- */
- public function actionApply()
- {
- $request = Yii::$app->request;
- if ($request->isPost) {
- $post = Yii::$app->request->post();
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($post,[
- [['mobile','is_poss'], 'integer'],
- [['license','store_info','idcart_front','idcart_back','idcart_hands'], 'string'],
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- // 检查是否曾经申请过
- $apply = PurchaseManager::find()->where(['user_id' => $this->user_id, 'status' => StatusEnum::ENABLED])->asArray()->one();
- if ($apply && $apply['is_poss'] == StatusEnum::ENABLED) return $this->error('您的申请已通过,无需再次申请');
- // 保存数据
- $post['user_id'] = $this->user_id;
- $res = PurchaseManager::setData($this->mall_id, $post);
- if ($res === false) return $this->error('提交失败:' . PurchaseManager::getStaticError());
- return $this->success('提交成功', $res);
- } else {
- // 查询申请记录
- $data = PurchaseManager::find()->where(['mall_id' => $this->mall_id, 'user_id' => $this->user_id, 'status' => StatusEnum::ENABLED])->asArray()->one();
- return $this->success('获取成功', $data);
- }
- }
- }
|