AgentFrontStaff.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace app\modules\alliance\behaviors;
  3. use app\models\SaasUser;
  4. use yii\base\ActionFilter;
  5. use yii\web\Response;
  6. class AgentFrontStaff extends ActionFilter
  7. {
  8. const ALLOW_LIST = [
  9. 'alliance/agentStaff/sorting-goods/goods-detail',
  10. 'alliance/agentStaff/sorting-goods/search-goods'
  11. ];
  12. public function beforeAction($action)
  13. {
  14. $access_token = input_params('access_token');
  15. $saas_user = SaasUser::findIdentityByAccessToken($access_token);
  16. if (!$saas_user) {
  17. \Yii::$app->response->format = Response::FORMAT_JSON;
  18. \Yii::$app->response->data = [
  19. 'code' => 401,
  20. 'msg' => '登录失败'
  21. ];
  22. return false;
  23. }
  24. $agentFrontStaff = \app\models\AgentFrontStaff::findOne(['saas_id' => $saas_user->id, 'is_delete' => 0]);
  25. if (!$agentFrontStaff) {
  26. if (in_array(\Yii::$app->controller->getRoute(), self::ALLOW_LIST)) {
  27. $agentFrontDriver = \app\models\Driver::findOne(['saas_user_id' => $saas_user->id, 'is_delete' => 0]);
  28. if ($agentFrontDriver) {
  29. $action->controller->agentFrontId = $agentFrontDriver->admin_id;
  30. $action->controller->agentDriverId = $agentFrontDriver->id ?? 0;
  31. return true;
  32. }
  33. }
  34. \Yii::$app->response->format = Response::FORMAT_JSON;
  35. \Yii::$app->response->data = [
  36. 'code' => 1,
  37. 'msg' => '非仓库员工'
  38. ];
  39. return false;
  40. }
  41. if (!intval($agentFrontStaff->status)) {
  42. \Yii::$app->response->format = Response::FORMAT_JSON;
  43. \Yii::$app->response->data = [
  44. 'code' => 1,
  45. 'msg' => '员工账户已经被禁用'
  46. ];
  47. return false;
  48. }
  49. $action->controller->agentFrontStaffId = $agentFrontStaff->id;
  50. $action->controller->agentFrontId = $agentFrontStaff->front_agent_admin_id;
  51. return parent::beforeAction($action);
  52. }
  53. }