Browse Source

PC端基础

lizhen_gitee 8 months ago
parent
commit
16af01516a

+ 14 - 0
application/api/behavior/PcAdminLog.php

@@ -0,0 +1,14 @@
+<?php
+
+namespace app\api\behavior;
+
+class PcAdminLog
+{
+    public function run(&$response)
+    {
+        //只记录POST请求的日志
+        if (request()->isPost() && config('pc_admin.auto_record_log')) {
+            \app\common\model\PcAdminLog::record();
+        }
+    }
+}

+ 5 - 6
application/api/controller/company/Index.php

@@ -3,6 +3,7 @@
 namespace app\api\controller\company;
 
 use app\common\controller\Apic;
+use app\common\model\PcAdminLog;
 use fast\Random;
 use think\Config;
 use think\Validate;
@@ -38,7 +39,7 @@ class Index extends Apic
         $ret = $this->auth->login($username, $password);
         if ($ret) {
             $data = $this->auth->getUserinfo_simple();
-            $this->success(__('Logged in successful'), $data);
+            $this->success('登录成功', $data);
         } else {
             $msg = $this->auth->getError();
             $msg = $msg ? $msg : __('Username or password is incorrect');
@@ -58,16 +59,14 @@ class Index extends Apic
             $this->error(__('Invalid parameters'));
         }
         $this->auth->logout();
-        $this->success(__('Logout successful'));
+        $this->success('退出成功');
     }
 
 
     //用户详细资料
-    public function getUserinfo($type = 1){
+    public function getUserinfo(){
         $info = $this->auth->getUserinfo();
-        if($type == 'return'){
-            return $info;
-        }
+
         $this->success(__('success'),$info);
     }
 

+ 18 - 0
application/api/tags.php

@@ -0,0 +1,18 @@
+<?php
+
+// +----------------------------------------------------------------------
+// | ThinkPHP [ WE CAN DO IT JUST THINK ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
+// +----------------------------------------------------------------------
+// | Author: liu21st <liu21st@gmail.com>
+// +----------------------------------------------------------------------
+// 应用行为扩展定义文件
+return [
+    // 应用结束
+    'app_end'      => [
+        'app\\api\\behavior\\PcAdminLog',
+    ],
+];

+ 19 - 1
application/common/library/Authcompany.php

@@ -310,16 +310,34 @@ class Authcompany
     /**
      * 获取会员基本信息
      */
+    public function getUserinfo_simple()
+    {
+        $data = $this->_user->toArray();
+        $allowFields = $this->getAllowFields();
+        $userinfo = array_intersect_key($data, array_flip($allowFields));
+        $userinfo = array_merge($userinfo, Tokencompany::get($this->_token));
+
+        //追加
+        $userinfo['avatar'] = localpath_to_netpath($userinfo['avatar']);
+
+        return $userinfo;
+    }
+    /**
+     * 获取会员基本信息
+     */
     public function getUserinfo()
     {
         $data = $this->_user->toArray();
         $allowFields = $this->getAllowFields();
         $userinfo = array_intersect_key($data, array_flip($allowFields));
-        $userinfo = array_merge($userinfo, Tokencompany::get($this->_token)); //staff_id在token里得到了,合并进去了
+        $userinfo = array_merge($userinfo, Tokencompany::get($this->_token));
 
         //追加
         $userinfo['avatar'] = localpath_to_netpath($userinfo['avatar']);
 
+        //追加公司信息
+        $userinfo['company'] = Db::name('company')->field('id,companyname')->where('id',$userinfo['company_id'])->find();
+
         return $userinfo;
     }
 

+ 2 - 2
application/common/library/Tokencompany.php

@@ -121,9 +121,9 @@ class Tokencompany
      * @param int|null $expire  有效时间 0为永久
      * @return boolean
      */
-    public static function set($token, $user_id, $expire = null,$staff_id = 0)
+    public static function set($token, $user_id, $expire = null)
     {
-        return self::init()->set($token, $user_id, $expire,$staff_id);
+        return self::init()->set($token, $user_id, $expire);
     }
 
     /**

+ 1 - 1
application/common/library/tokencompany/Driver.php

@@ -26,7 +26,7 @@ abstract class Driver
      * @param   int    $expire  过期时长,0表示无限,单位秒
      * @return bool
      */
-    abstract function set($token, $user_id, $expire = 0,$staff_id = 0);
+    abstract function set($token, $user_id, $expire = 0);
 
     /**
      * 获取Token内的信息

+ 3 - 4
application/common/library/tokencompany/driver/Mysql.php

@@ -51,11 +51,11 @@ class Mysql extends Driver
      * @param int    $expire  过期时长,0表示无限,单位秒
      * @return bool
      */
-    public function set($token, $user_id, $expire = null,$staff_id = 0)
+    public function set($token, $user_id, $expire = null)
     {
         $expiretime = !is_null($expire) && $expire !== 0 ? time() + $expire : 0;
         $token = $this->getEncryptedToken($token);
-        $this->handler->insert(['token' => $token, 'user_id' => $user_id, 'createtime' => time(), 'expiretime' => $expiretime, 'staff_id'=>$staff_id]);
+        $this->handler->insert(['token' => $token, 'user_id' => $user_id, 'createtime' => time(), 'expiretime' => $expiretime]);
         return true;
     }
 
@@ -67,11 +67,10 @@ class Mysql extends Driver
     public function get($token)
     {
         //方便测试
-        if(strpos($token,'testuid_') !== false && config('app_debug') === true){
+        if(strpos($token,'testuid_') !== false && config('api_exception') === true){
             $uid = substr($token,8);
             return [
                 'user_id' => intval($uid),
-                'staff_id' => 0,
             ];
         }
         //方便测试

+ 29 - 0
application/common/model/PcAdmin.php

@@ -0,0 +1,29 @@
+<?php
+
+namespace app\common\model;
+
+use think\Db;
+use think\Model;
+
+/**
+ * 会员模型
+ */
+class PcAdmin extends Model
+{
+
+    // 表名
+    protected $name = 'pc_admin';
+    // 开启自动写入时间戳字段
+    protected $autoWriteTimestamp = false;
+    // 定义时间戳字段名
+    protected $createTime = false;
+    protected $updateTime = false;
+    // 追加属性
+    protected $append = [
+    ];
+
+
+
+
+
+}

+ 2 - 1
application/common/model/PcAdminLog.php

@@ -84,7 +84,8 @@ class PcAdminLog extends Model
             'admin_id'  => $admin_id,
             'username'  => $username,
             'useragent' => substr(request()->server('HTTP_USER_AGENT'), 0, 255),
-            'ip'        => xss_clean(strip_tags(request()->ip()))
+            'ip'        => xss_clean(strip_tags(request()->ip())),
+            'company_id'=> $auth->company_id,
         ]);
     }
 

+ 1 - 0
application/config.php

@@ -375,6 +375,7 @@ return [
     //公司管理员
     'pc_admin' => [
         'login_failure_retry'   => true,
+        'auto_record_log'       => true,
     ],
 
 ];