SalesmanStoreUserAdmin.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace app\modules\alliance\behaviors;
  3. use app\models\Admin;
  4. use app\models\Salesman;
  5. use app\models\SalesmanNewStore;
  6. use app\models\Supplier;
  7. use yii\base\ActionFilter;
  8. use yii\helpers\Json;
  9. use Yii;
  10. use yii\web\Response;
  11. class SalesmanStoreUserAdmin extends ActionFilter
  12. {
  13. // 接口白名单
  14. public static $allow_list = [
  15. ];
  16. public function beforeAction($action)
  17. {
  18. $params_r = $_REQUEST['r'];
  19. if (in_array($params_r, self::$allow_list)) {
  20. return true;
  21. }
  22. $saas_user = get_saas_user();
  23. if (!$saas_user) {
  24. //未登录
  25. \Yii::$app->response->format = Response::FORMAT_JSON;
  26. \Yii::$app->response->data = [
  27. 'code' => 401,
  28. 'msg' => '登陆状态异常,请重新登陆'
  29. ];
  30. return false;
  31. }
  32. $salesman = Salesman::findOne(['saas_user_id' => $saas_user->id, 'is_delete' => 0]);
  33. if (!$salesman) {
  34. //不是业务员
  35. \Yii::$app->response->format = Response::FORMAT_JSON;
  36. \Yii::$app->response->data = [
  37. 'code' => 1,
  38. 'msg' => '不是业务员'
  39. ];
  40. return false;
  41. }
  42. $s_id = input_params('s_id', 0);
  43. $salesman_new_store = SalesmanNewStore::findOne(['id' => $s_id, 'is_delete' => 0, 'salesman_saas_id' => $saas_user->id]);
  44. if (!$salesman_new_store) {
  45. //数据错误
  46. \Yii::$app->response->format = Response::FORMAT_JSON;
  47. \Yii::$app->response->data = [
  48. 'code' => 1,
  49. 'msg' => '数据错误,非当前业务员数据'
  50. ];
  51. return false;
  52. }
  53. $is_food = 0;
  54. if ($salesman_new_store->store_params) {
  55. $store_params = json_decode($salesman_new_store->store_params, true);
  56. if (!empty($store_params)) {
  57. $is_food = $store_params['is_food'];
  58. }
  59. }
  60. $action->controller->is_food = (int)$is_food;
  61. $action->controller->store_id = $salesman_new_store->store_id;
  62. $action->controller->s_id = $s_id;
  63. $action->controller->mini_id = $salesman_new_store->store_mini_id;
  64. $action->controller->ali_mini_id = $salesman_new_store->store_ali_mini_id;
  65. return parent::beforeAction($action);
  66. }
  67. }