| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- namespace app\modules\alliance\behaviors;
- use app\models\Admin;
- use app\models\AgentApply;
- use app\models\AgentBind;
- use app\models\SaasUser;
- use yii\base\ActionFilter;
- use yii\helpers\Json;
- use yii\web\Response;
- class goodsAgentAuth extends ActionFilter
- {
- // 不验证登录白名单
- const ALLOW_LIST = [];
- public function beforeAction($action)
- {
- $access_token = input_params('access_token');
- if (!$access_token && in_array(\Yii::$app->controller->getRoute(), self::ALLOW_LIST)) {
- return true;
- }
- $saas_user = SaasUser::findIdentityByAccessToken($access_token);
- if (empty($access_token) && $saas_user) {
- \Yii::$app->response->format = Response::FORMAT_JSON;
- \Yii::$app->response->data = [
- 'code' => 401,
- 'msg' => '登陆失败'
- ];
- return false;
- }
- if (!$saas_user) {
- \Yii::$app->response->format = Response::FORMAT_JSON;
- \Yii::$app->response->data = [
- 'code' => 401,
- 'msg' => '登陆失败'
- ];
- return false;
- }
- $admin = Admin::findOne(['type' => 'goods_agent', 'is_delete' => 0, 'saas_user_id' => $saas_user->id]);
- $agent_bind = AgentBind::findOne(['id' => $admin->type_id, 'type' => 1]);
- if (empty($admin) || empty($agent_bind)) {
- $agent_apply = AgentApply::findOne(['saas_user_id' => $saas_user->id, 'is_delete' => 0, 'agent_type' => 2]);
- if ($agent_apply) {
- if ((int)$agent_apply->status === 0) {
- \Yii::$app->response->format = Response::FORMAT_JSON;
- \Yii::$app->response->data = [
- 'code' => 1,
- 'msg' => '产品代理申请单信息审核中'
- ];
- return false;
- }
- if ((int)$agent_apply->status === 2) {
- \Yii::$app->response->format = Response::FORMAT_JSON;
- \Yii::$app->response->data = [
- 'code' => 1,
- 'msg' => '产品代理申请单信息审核未通过'
- ];
- return false;
- }
- }
- \Yii::$app->response->format = Response::FORMAT_JSON;
- \Yii::$app->response->data = [
- 'code' => 1,
- 'msg' => '当前用户没有申请产品代理信息'
- ];
- return false;
- } else {
- \Yii::$app->jwt->setAdmin($admin);
- \Yii::$app->response->format = Response::FORMAT_JSON;
- \Yii::$app->response->data = [
- 'code' => 0,
- 'msg' => '获取成功'
- ];
- return true;
- }
- }
- }
|