| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace app\modules\alliance\behaviors;
- use app\models\SaasUser;
- use yii\base\ActionFilter;
- use yii\web\Response;
- class AgentFrontStaff extends ActionFilter
- {
- const ALLOW_LIST = [
- 'alliance/agentStaff/sorting-goods/goods-detail',
- 'alliance/agentStaff/sorting-goods/search-goods'
- ];
- public function beforeAction($action)
- {
- $access_token = input_params('access_token');
- $saas_user = SaasUser::findIdentityByAccessToken($access_token);
- if (!$saas_user) {
- \Yii::$app->response->format = Response::FORMAT_JSON;
- \Yii::$app->response->data = [
- 'code' => 401,
- 'msg' => '登录失败'
- ];
- return false;
- }
- $agentFrontStaff = \app\models\AgentFrontStaff::findOne(['saas_id' => $saas_user->id, 'is_delete' => 0]);
- if (!$agentFrontStaff) {
- if (in_array(\Yii::$app->controller->getRoute(), self::ALLOW_LIST)) {
- $agentFrontDriver = \app\models\Driver::findOne(['saas_user_id' => $saas_user->id, 'is_delete' => 0]);
- if ($agentFrontDriver) {
- $action->controller->agentFrontId = $agentFrontDriver->admin_id;
- $action->controller->agentDriverId = $agentFrontDriver->id ?? 0;
- return true;
- }
- }
- \Yii::$app->response->format = Response::FORMAT_JSON;
- \Yii::$app->response->data = [
- 'code' => 1,
- 'msg' => '非仓库员工'
- ];
- return false;
- }
- if (!intval($agentFrontStaff->status)) {
- \Yii::$app->response->format = Response::FORMAT_JSON;
- \Yii::$app->response->data = [
- 'code' => 1,
- 'msg' => '员工账户已经被禁用'
- ];
- return false;
- }
- $action->controller->agentFrontStaffId = $agentFrontStaff->id;
- $action->controller->agentFrontId = $agentFrontStaff->front_agent_admin_id;
- return parent::beforeAction($action);
- }
- }
|