Browse Source

采销3.0初步版本,运营账号列表及删除,token校验暂时关闭

wufeng 2 years ago
parent
commit
7b350a6179
6 changed files with 635 additions and 531 deletions
  1. 1 1
      .env
  2. 126 100
      app/admin/common/User.php
  3. 36 19
      app/admin/controller/Base.php
  4. 459 403
      app/admin/controller/User.php
  5. 3 1
      app/admin/route/app.php
  6. 10 7
      app/common.php

+ 1 - 1
.env

@@ -1 +1 @@
-APP_DEBUG = true
[APP]
DEFAULT_TIMEZONE = Asia/Shanghai


[LANG]
default_lang = zh-cn

[USER]
hosturl=
+APP_DEBUG = true
[APP]
DEFAULT_TIMEZONE = Asia/Shanghai


[LANG]
default_lang = zh-cn

[USER]
hosturl=http://user.test241.wanyuhengtong.com/

+ 126 - 100
app/admin/common/User.php

@@ -4,108 +4,134 @@
 namespace app\admin\common;
 
 
-class User {
-	private $appid='';
-	private $appkey='';
-	private  $Sign;
-	private  $param=[];
-	private  $header=["Content-Type"=>"multipart/json;charset=utf-8"];
-	private  $host;
-	private  $api=[
-		"login"=>'login',
-		"verifyToken"=>'verifyToken',
-		"register"=>'register',
-		"userlist"=>'userlist',
-		"usersave"=>'usersave',
-		"userstatus"=>'userstatus',
-		"userinfo"=>'userinfo',
-		"setpasswd"=>'setpasswd',
-		"setcompany"=>'setcompany',
-		"companystatus"=>'companystatus',
-		"userlistbycompany"=>'userlistbycompany',
-		"useradd"=>'useradd',
-		];
-	public function __construct() {
-		$this->Sign=new Sign($this->appid,$this->appkey);
-		$this->host=env("user.hosturl",'');
-	}
-	/**
-	 * 生成请求header参数
-	 */
-	private function makeHeader(){
-		$headerArr=["appid"=>$this->appid,"noce"=>randomkeys(16),"sign"=>'',"timestamp"=>time()];
-		$value =array_merge($this->param,$headerArr);
+class User
+{
+    private $appid = 'cx';
+    private $appkey = 'cx123123';
+    private $Sign;
+    private $param = [];
+    private $header = ["Content-Type" => "multipart/json;charset=utf-8"];
+    private $host;
+    private $api = [
+        "login" => 'login',
+        "verifyToken" => 'verifyToken',
+        "register" => 'register',
+        "userlist" => 'userlist',
+        "usersave" => 'usersave',
+        "userstatus" => 'userstatus',
+        "userinfo" => 'userinfo',
+        "setpasswd" => 'setpasswd',
+        "setcompany" => 'setcompany',
+        "companystatus" => 'companystatus',
+        "userlistbycompany" => 'userlistbycompany',
+        "useradd" => 'useradd',
+        "userDelete" => 'userDelete',//删除
+    ];
+
+    public function __construct()
+    {
+        $this->Sign = new Sign($this->appid, $this->appkey);
+        $this->host = env("user.hosturl", '');
+    }
+
+    /**
+     * 生成请求header参数
+     */
+    private function makeHeader()
+    {
+        $headerArr = ["appid" => $this->appid, "noce" => randomkeys(16), "sign" => '', "timestamp" => time()];
+        $value = array_merge($this->param, $headerArr);
         $headerArr['sign'] = $this->Sign->makeSign($value);
-        foreach ($headerArr as $key=>$value){
-			$this->header[]=$key.":".$value;
+        foreach ($headerArr as $key => $value) {
+            $this->header[] = $key . ":" . $value;
+        }
+    }
+
+    /**模拟post 请求数据
+     * @param $url
+     * @param array $param
+     */
+    private function post($url, $param = [])
+    {
+        $this->param = $param;
+        $this->makeHeader();
+        if (is_array($param)) $post = http_build_query($param);
+        $curl = curl_init();
+        curl_setopt($curl, CURLOPT_URL, $url);
+        curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)');
+        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
+        curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
+        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
+        if ($post) {
+            curl_setopt($curl, CURLOPT_POST, 1);
+            curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
         }
-	}
-	/**模拟post 请求数据
-	* @param $url
-	* @param array $param
-	*/
-	private function post($url,$param=[]){
-		$this->param =$param;
-		$this->makeHeader();
-		if(is_array($param)) $post=http_build_query($param);
-	    $curl = curl_init();
-	    curl_setopt($curl, CURLOPT_URL, $url);
-	    curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)');
-	    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
-	    curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
-	    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
-	    if($post) {
-	        curl_setopt($curl, CURLOPT_POST, 1);
-	        curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
-	    }
-	    curl_setopt($curl, CURLOPT_TIMEOUT, 10);
-	    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
-	    curl_setopt($curl, CURLOPT_HTTPHEADER, $this->header);
-	    $data = curl_exec($curl);
-	    if (curl_errno($curl)) {
-	        return curl_error($curl);
-	    }
-	    curl_close($curl);
-	    return $data;
-	}
-	/** 登录接口
-	* @param $param
-	 * @return bool|string
-	 */
-	public function Login($param){
-		return $this->post($this->host.$this->api["login"],$param);
-	}
-
-	public function VerifyTokens($param){
-		return $this->post($this->host.$this->api["verifyToken"],$param);
-	}
-
-	public function GetUserInfo($param){
-		return $this->post($this->host.$this->api["userinfo"],$param);
-	}
-
-	public function GetUserlist($param){
-		return $this->post($this->host.$this->api["userlist"],$param);
-	}
-
-	public function GetList($param){
-		return $this->post($this->host.$this->api["userlistbycompany"],$param);
-	}
-
-	public function GetAccountall($param){
-		return $this->post($this->host.$this->api["userlist"],$param);
-	}
-
-	public function resetPasswd($param){
-		return $this->post($this->host.$this->api["setpasswd"],$param);
-	}
-
-	public function resetInfo($param){
-		return $this->post($this->host.$this->api["usersave"],$param);
-	}
-	public function resetState($param){
-		return $this->post($this->host.$this->api["userstatus"],$param);
-	}
+        curl_setopt($curl, CURLOPT_TIMEOUT, 10);
+        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+        curl_setopt($curl, CURLOPT_HTTPHEADER, $this->header);
+        $data = curl_exec($curl);
+        if (curl_errno($curl)) {
+            return curl_error($curl);
+        }
+        curl_close($curl);
+        return $data;
+    }
+
+    /** 登录接口
+     * @param $param
+     * @return bool|string
+     */
+    public function Login($param)
+    {
+        return $this->post($this->host . $this->api["login"], $param);
+    }
+
+    public function VerifyTokens($param)
+    {
+        return $this->post($this->host . $this->api["verifyToken"], $param);
+    }
+
+    public function GetUserInfo($param)
+    {
+        return $this->post($this->host . $this->api["userinfo"], $param);
+    }
+
+    public function GetUserlist($param)
+    {
+        return $this->post($this->host . $this->api["userlist"], $param);
+    }
+
+    public function GetList($param)
+    {
+        return $this->post($this->host . $this->api["userlistbycompany"], $param);
+    }
+
+    public function GetAccountall($param)
+    {
+        return $this->post($this->host . $this->api["userlist"], $param);
+    }
+
+    public function resetPasswd($param)
+    {
+        return $this->post($this->host . $this->api["setpasswd"], $param);
+    }
+
+    public function resetInfo($param)
+    {
+        return $this->post($this->host . $this->api["usersave"], $param);
+    }
+
+    public function resetState($param)
+    {
+        return $this->post($this->host . $this->api["userstatus"], $param);
+    }
+
+
+    //删除
+    public function userDelete(array $param = [])
+    {
+        return $this->post($this->host . $this->api['userDelete'], $param);
+    }
 
 
 }

+ 36 - 19
app/admin/controller/Base.php

@@ -9,39 +9,56 @@ use app\admin\model\ProcessOrder;
 use think\App;
 use think\facade\Db;
 use app\admin\model\DataGroup as DataGroupModel;
+use think\facade\Validate;
 
 class Base extends \app\BaseController
 {
     public  $post=[];
-    public  $uid='';
-    public  $uname='';
-    public  $roleid='';
+    public  $uid=0;//账户id
+    public  $uname='';//账户名称
+    public  $roleid=0;//角色id
+    public  $level=0;//角色等级,1.系统超级管理员,2.企业管理员,3.企业人员
+    private $white=['login'];
 
     public function __construct(App $app)
     {
         parent::__construct($app);
         $this->post =$this->request->post();
-        $this->validateToken();
+
+        if(!in_array($this->request->pathinfo(),$this->white)) $this->validateToken();
     }
 
     public function validateToken()
     {
-        $token = isset($this->post['token']) ? trim($this->post['token']) : "";
-        if($token==""){
-            return error_show(101,'token不能为空');
-        }
-        $effetc = VerifyTokens($token);
-        if(!empty($effetc) && $effetc['code']!=0) {
-            return error_show($effetc['code'], $effetc['message']);
-        }
+        //这个地方不能用return json_show()方法,无法阻止代码继续执行
+        $val = Validate::rule([
+            'token'=>'require',
+            'supplierNo'=>'require|length:18',
+        ]);
 
-        $this->uid=isset($effetc['data']['user']['id']) ?$effetc['data']['user']['id']:"";
-        $this->uname=isset($effetc['data']['user']['nickname']) ?$effetc['data']['user']['nickname']:"";
-        $uid = Db::name("user_role")->where(['uid'=>$this->uid,"is_del"=>0,"status"=>1])->find();
-        if($uid==false || $uid['status']==0){
-            return error_show(102,'账户已禁用');
-        }
-        $this->roleid = $uid['roleid'];//权限id
+        if(!$val->check($this->post)) return error_show(1004,$val->getError());
+
+//        $token = isset($this->post['token']) ? trim($this->post['token']) : "";
+//        if($token==""){
+//            return error_show(101,'token不能为空');
+//        }
+        $effetc = VerifyTokens($this->post['token']);
+        if(!empty($effetc) && $effetc['code']!=0) return error_show($effetc['code'], $effetc['message']);
+        if(!in_array($this->post['supplierNo'],array_column($effetc['data']['company_relaton'],'companyCode'))) return error_show(1004,'该企业尚未关联');
+
+        $this->uid=isset($effetc['data']['id']) ?$effetc['data']['id']:"";
+        $this->uname=isset($effetc['data']['nickname']) ?$effetc['data']['nickname']:"";
+        $role = Db::name('user_role')
+            ->alias('a')
+            ->field('a.id,a.status,a.roleid,b.role_name,b.level')
+            ->leftJoin('role b','b.id=a.roleid')
+            ->where(['a.uid'=>$this->uid,'a.is_del'=>0,'a.status'=>1,'b.supplierNo'=>$this->post['supplierNo']])
+            ->findOrEmpty();
+
+        if(empty($role) || $role['status']==0) return error_show(102,'该企业尚未开通对应角色');
+
+        $this->roleid = $role['roleid'];//权限id
+        $this->level = $role['level'];//权限id
     }
 
 

File diff suppressed because it is too large
+ 459 - 403
app/admin/controller/User.php


+ 3 - 1
app/admin/route/app.php

@@ -133,7 +133,9 @@ Route::rule('allotgetin', 'admin/Allot/getin');
 Route::rule('allotvesio', 'admin/Allot/vesio');
 Route::rule('allotgood', 'admin/Allot/goodlist');
 
-Route::rule('userlist', 'admin/User/list');
+//【运营账号】
+Route::rule('login', 'admin/User/login');//登录
+Route::rule('userlist', 'admin/User/list');//列表
 Route::rule('userinfo', 'admin/User/userInfo');
 Route::rule('userall', 'admin/User/userAll');
 Route::rule("userstatus", "admin/User/UserStatus");

+ 10 - 7
app/common.php

@@ -104,14 +104,17 @@ function makeSalt(){
  * @throws \think\exception\DbException
  */
 function VerifyTokens($token){
-    $host = Config::get("app");
-    $url = $host["api_host"]."/Api/verify_token";
-    $data=[
-        "token"=>$token
-    ];
-    $response=curl_request($url,$data);
+//    $host = Config::get("app");
+//    $url = $host["api_host"]."/Api/verify_token";
+//    $data=[
+//        "token"=>$token
+//    ];
+//    $response=curl_request($url,$data);
 
-    return json_decode($response,true);
+    $userCommon = new \app\admin\common\User();
+    $rs = $userCommon->VerifyTokens(['token'=>$token]);
+
+    return json_decode($rs,true);
 }
 
 

Some files were not shown because too many files changed in this diff