|
@@ -0,0 +1,77 @@
|
|
|
|
+<?php
|
|
|
|
+
|
|
|
|
+namespace General\Services\Book;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 基础配置
|
|
|
|
+ * @property int $login_user_id
|
|
|
|
+ * @property string $login_user_role
|
|
|
|
+ * @property string $login_user_account
|
|
|
|
+ * @property object $login_user
|
|
|
|
+ * @property bool $has_edit_role
|
|
|
|
+ */
|
|
|
|
+trait BaseConfig
|
|
|
|
+{
|
|
|
|
+ public function __get(string $name)
|
|
|
|
+ {
|
|
|
|
+ if (!isset($this->$name)) {
|
|
|
|
+ $this->$name = $this->$name();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //获取当前登录用户ID
|
|
|
|
+ protected function login_user_id()
|
|
|
|
+ {
|
|
|
|
+ if (empty(session('manage_user'))) {
|
|
|
|
+ if (env('APP_ENV') == 'local') return 1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $user = unserialize(session('manage_user'));
|
|
|
|
+ return $user->id;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //获取当前登录用户角色
|
|
|
|
+ protected function login_user_role()
|
|
|
|
+ {
|
|
|
|
+ if (empty(session('manage_user'))) {
|
|
|
|
+ if (env('APP_ENV') == 'local') return 'admin';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $user = unserialize(session('manage_user'));
|
|
|
|
+ return $user->role;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //获取当前登录用户
|
|
|
|
+ protected function login_user_account()
|
|
|
|
+ {
|
|
|
|
+ if (empty(session('manage_user'))) {
|
|
|
|
+ if (env('APP_ENV') == 'local') return 'admin';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $user = unserialize(session('manage_user'));
|
|
|
|
+ return $user->account;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected function login_user()
|
|
|
|
+ {
|
|
|
|
+ if (empty(session('manage_user'))) {
|
|
|
|
+ if (env('APP_ENV') == 'local') return '';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $user = unserialize(session('manage_user'));
|
|
|
|
+ return $user;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 编辑权限
|
|
|
|
+ protected function has_edit_role()
|
|
|
|
+ {
|
|
|
|
+ $accounts = [
|
|
|
|
+ "zsy_sdb",
|
|
|
|
+ "zsy_zlj",
|
|
|
|
+ "zsy_gdy",
|
|
|
|
+ "zsy_lkf",
|
|
|
|
+ "zsy_pxp"
|
|
|
|
+ ];
|
|
|
|
+ return in_array($this->login_user_account, $accounts) ? true : false;
|
|
|
|
+ }
|
|
|
|
+}
|