likang 3 роки тому
батько
коміт
59af4db0bc

+ 1 - 1
catch/api/Listen.php

@@ -95,7 +95,7 @@ trait Listen
             'Imei' => $obj->imei ? '' : $obj->imei,
             'Version' => $time,
             'Status' => 1,
-            'Content' => json_encode($data['data'])
+            //'Content' => json_encode($data['data'])
         ];
         Db::name('publish')->where($where)->update($content);
     }

+ 6 - 3
catch/hydraulic/controller/HydEquipment.php

@@ -115,6 +115,7 @@ class HydEquipment extends CatchController
                     'angular_resolution' => $data['angular_resolution']
 
                 ];
+
                 Wrench::create($wrench);
             }
         } catch (\Exception $e) {
@@ -200,6 +201,7 @@ class HydEquipment extends CatchController
         if ($data['equipment_type'] == 3 || $data['equipment_type'] == 4) {
 
             $wrench = [
+                'id' => $data['list']['id'],
                 // 编号
                 'number' => $data['number'],
                 //设备id
@@ -215,7 +217,8 @@ class HydEquipment extends CatchController
                 'angle_sensor' => $data['angle_sensor'],
                 // 扭矩
             ];
-            Wrench::where('id', $data['list']['id'])->update($wrench);
+
+            Wrench::update($wrench, ['id' => $data['list']['id']]);
         }
         return CatchResponse::success($this->hydEquipmentModel->updateBy($id, $hydequ));
     }
@@ -243,10 +246,10 @@ class HydEquipment extends CatchController
                     Hydraulic::where('eq_id', '=', $item['id'])->delete();
                 }
                 if ($item['equipment_type'] == 3 || $item['equipment_type'] == 4) {
-                    Wrench::where('eq_id', '=', $item['id'])->delete();
+                    $wrench =  Wrench::where('eq_id', '=', $item['id'])->find();
+                    $wrench->delete();
                 }
             }
-
             $this->hydEquipmentModel->deleteBy($id, true);
         } catch (\Exception $e) {
             Db::rollback();

+ 2 - 0
catch/hydraulic/model/Hydraulic.php

@@ -2,6 +2,7 @@
 
 namespace catchAdmin\hydraulic\model;
 
+use catchAdmin\api\Listen;
 use catcher\base\CatchModel as Model;
 use \think\facade\Db;
 use catchAdmin\system\model\SysDictData;
@@ -10,6 +11,7 @@ use catchAdmin\permissions\model\DataRangScopeTrait;
 class Hydraulic extends Model
 {
     use DataRangScopeTrait;
+
     // 表名
     public $name = 'hydraulic';
     // 数据库字段映射

+ 30 - 0
catch/hydraulic/model/Wrench.php

@@ -2,6 +2,7 @@
 
 namespace catchAdmin\hydraulic\model;
 
+use catchAdmin\api\Listen;
 use catcher\base\CatchModel as Model;
 use \think\facade\Db;
 use catchAdmin\system\model\SysDictData;
@@ -10,6 +11,7 @@ use catchAdmin\permissions\model\DataRangScopeTrait;
 class Wrench extends Model
 {
     use DataRangScopeTrait;
+    use Listen;
     // 表名
     public $name = 'wrench';
     // 数据库字段映射
@@ -134,4 +136,32 @@ class Wrench extends Model
             return '-';
         }
     }
+    /**
+     * 风机下发内容
+     */
+    public function addContent(&$obj)
+    {
+
+        $data = null;
+        $content = null;
+        $Hyd = Hydraulic::where('id', $obj->eq_id)->find();
+
+        $data = [
+            'id' => intval($obj->eq_id),
+            'number' => $obj->number,
+            'qualified' => intval($obj->checked_res),
+            'type' => intval($obj->angle_sensor) ? 2 : 1,
+            'minp' => intval($obj->min_pressure),
+            'maxp' => intval($obj->max_pressure),
+            'maxt' => intval($obj->max_torque),
+            'mint' => intval($obj->min_torque),
+            'angres' => intval($obj->angular_resolution),
+            'clt' => date('Y-m-d', $Hyd['check_last_time']),
+            'model' => strval($Hyd['equipment_model']),
+            'fixed' => strval($Hyd['fixed_asset_number'])
+        ];
+        $content['data'] = $data;
+        $content['type'] = 'Wrench';
+        return  $content;
+    }
 }

+ 48 - 40
catch/permissions/controller/User.php

@@ -1,4 +1,5 @@
 <?php
+
 namespace catchAdmin\permissions\controller;
 
 use catchAdmin\permissions\excel\UserExport;
@@ -24,7 +25,7 @@ class User extends CatchController
 
     public function __construct(Users $user)
     {
-       $this->user = $user;
+        $this->user = $user;
     }
 
     /**
@@ -38,16 +39,16 @@ class User extends CatchController
         return CatchResponse::paginate($this->user->getList());
     }
 
-  /**
-   * 获取用户信息
-   *
-   * @time 2020年01月07日
-   * @param CatchAuth $auth
-   * @throws \think\db\exception\DataNotFoundException
-   * @throws \think\db\exception\DbException
-   * @throws \think\db\exception\ModelNotFoundException
-   * @return \think\response\Json
-   */
+    /**
+     * 获取用户信息
+     *
+     * @time 2020年01月07日
+     * @param CatchAuth $auth
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @return \think\response\Json
+     */
     public function info(CatchAuth $auth)
     {
         $user = $auth->user();
@@ -77,21 +78,21 @@ class User extends CatchController
     public function save(CreateRequest $request)
     {
         // $area_id=json_encode($request->param('area_id'));
-       $params=$request->param();
-      
+        $params = $request->param();
 
 
-    //    $params['area_id']=json_encode($params['area_id']);
-       $params['realname']=$params['username'];
-     
-        $this->user->storeBy($params);
 
+        //    $params['area_id']=json_encode($params['area_id']);
+        $params['realname'] = $params['username'];
+        $params['equ_password'] = md5($params['password']);
+        $this->user->storeBy($params);
         $this->user->attachRoles($request->param('roles'));
 
         if ($request->param('jobs')) {
             $this->user->attachJobs($request->param('jobs'));
         }
 
+        $this->user->equUserUpdate($this->user);
         return CatchResponse::success('', '添加成功');
     }
 
@@ -118,13 +119,15 @@ class User extends CatchController
      */
     public function update($id, UpdateRequest $request)
     {
-        $params=$request->param();
+        $params = $request->param();
         // $params['area_id']=json_encode($params['area_id']);
 
-        if($params['password']==""){
+        if ($params['password'] == "") {
             unset($params['password']);
+        } else {
+            $params['equ_password'] = md5($params['password']);
         }
-        $params['realname']=$params['username'];
+        $params['realname'] = $params['username'];
         $this->user->updateBy($id, $params);
 
         $user = $this->user->findBy($id);
@@ -138,6 +141,8 @@ class User extends CatchController
         if (!empty($request->param('jobs'))) {
             $user->attachJobs($request->param('jobs'));
         }
+
+        $this->user->equUserUpdate($this->user->where('id', $id)->find());
         return CatchResponse::success();
     }
 
@@ -151,14 +156,17 @@ class User extends CatchController
     {
         $ids = Utils::stringToArrayBy($id);
 
-        foreach ($ids as $_id) {
-          $user = $this->user->findBy($_id);
-          // 删除角色
-          $user->detachRoles();
-          // 删除岗位
-          $user->detachJobs();
 
-          $this->user->deleteBy($_id,true);
+        foreach ($ids as $_id) {
+            $user = $this->user->findBy($_id);
+            $array = $user;
+            // 删除角色
+            $user->detachRoles();
+            // 删除岗位
+            $user->detachJobs();
+
+            $this->user->deleteBy($_id, true);
+            $this->user->equUserUpdate($array);
         }
 
         return CatchResponse::success();
@@ -176,11 +184,11 @@ class User extends CatchController
 
         foreach ($ids as $_id) {
 
-          $user = $this->user->findBy($_id);
+            $user = $this->user->findBy($_id);
 
-          $this->user->updateBy($_id, [
-            'status' => $user->status == Users::ENABLE ? Users::DISABLE : Users::ENABLE,
-          ]);
+            $this->user->updateBy($_id, [
+                'status' => $user->status == Users::ENABLE ? Users::DISABLE : Users::ENABLE,
+            ]);
         }
 
         return CatchResponse::success([], '操作成功');
@@ -197,13 +205,13 @@ class User extends CatchController
      */
     public function recover($id): \think\response\Json
     {
-       $trashedUser = $this->user->findBy($id, ['*'], true);
+        $trashedUser = $this->user->findBy($id, ['*'], true);
 
-       if ($this->user->where('email', $trashedUser->email)->find()) {
-           return CatchResponse::fail(sprintf('该恢复用户的邮箱 [%s] 已被占用', $trashedUser->email));
-       }
+        if ($this->user->where('email', $trashedUser->email)->find()) {
+            return CatchResponse::fail(sprintf('该恢复用户的邮箱 [%s] 已被占用', $trashedUser->email));
+        }
 
-       return CatchResponse::success($this->user->recover($id));
+        return CatchResponse::success($this->user->recover($id));
     }
 
     /**
@@ -254,7 +262,7 @@ class User extends CatchController
      */
     public function profile(ProfileRequest $request)
     {
-       return CatchResponse::success($this->user->updateBy($request->user()->id, $request->param()));
+        return CatchResponse::success($this->user->updateBy($request->user()->id, $request->param()));
     }
 
     /**
@@ -265,7 +273,7 @@ class User extends CatchController
         return CatchResponse::success($this->user->getAreaIdBy());
     }
 
-    
+
     /**
      *
      * @time 2019年12月07日
@@ -274,10 +282,10 @@ class User extends CatchController
      */
     public function getUserByDepart($depart_id): \think\response\Json
     {
-        
+
         return CatchResponse::success($this->user->getUserByDepart($depart_id));
     }
-    
+
     /**
      * 获取推送用户
      */

+ 23 - 22
catch/permissions/database/migrations/20191128114204_users.php

@@ -28,28 +28,29 @@ class Users extends Migrator
      */
     public function change()
     {
-        $table  =  $this->table('users',array('engine'=>'Innodb', 'comment' => '用户表', 'signed' => false));
-        $table->addColumn('username', 'string',array('null'=>true,'limit'  =>  20,'default'=>'','comment'=>'用户名'))
-            ->addColumn('password', 'string',array('null' => true,'limit'  =>  255,'comment'=>'用户密码'))
-            ->addColumn('sex', 'integer',['null'=>true,'default' => 0, 'comment'=>'性别'])
-            ->addColumn('email', 'string',array('null'=>true,'limit'  =>  100, 'comment'=>'邮箱 登录'))
-            ->addColumn('idcard', 'string',array('null'=>true,'limit'  =>  20, 'comment'=>'身份证'))
-            ->addColumn('user_no', 'string',array('null'=>true,'limit'  =>  20, 'comment'=>'用户编号'))
-            ->addColumn('department_id', 'integer',['null'=>true,'default' => 0, 'comment'=>'部门ID'])
-            ->addColumn('status', 'boolean',array('null'=>true,'limit'  =>  1,'default'=> 1,'comment'=>'用户状态 1 正常 2 禁用'))
-            ->addColumn('last_login_ip', 'string',array('null'=>true,'limit' => 50,'default'=>0,'comment'=>'最后登录IP'))
-            ->addColumn('last_login_time', 'integer',array('null'=>true,'default'=>0,'comment'=>'最后登录时间', 'signed' => false))
-            ->addColumn('wxmp_open_id', 'string', ['limit' => '30','null' => true,'signed' => true,'comment' => '微信小程序openid',])
-            ->addColumn('wx_open_id', 'string', ['limit' => '30','null' => true,'signed' => true,'comment' => '微信公众号openid',])
-            ->addColumn('wx_union_id', 'string', ['limit' => '50','null' => true,'signed' => true,'comment' => '微信unionid',])
-            ->addColumn('phone', 'string', ['null'=>true,'limit' => '20','null' => true,'signed' => true,'comment' => '手机号',])
-            ->addColumn('remember_token', 'string', ['limit' => 512,'default' => '','null'=>true,'comment' => '用户token'])
-            ->addColumn('realname', 'string', ['null'=>true,'default' => '', 'comment' => '姓名', 'limit' => 20])
-            ->addColumn('avatar', 'string', ['limit' => 255,'null'=>true,'default' => '','comment' => '用户头像','after' => 'email'])
-            ->addColumn('creator_id', 'integer',['null'=>true,'default' => 0, 'comment'=>'创建人ID'])
-            ->addColumn('created_at', 'integer', array('null'=>true,'default'=>0,'comment'=>'创建时间', 'signed' => false ))
-            ->addColumn('updated_at', 'integer', array('null'=>true,'default'=>0,'comment'=>'更新时间', 'signed' => false))
-            ->addColumn('deleted_at', 'integer', array('null'=>true,'default'=>0,'comment'=>'删除状态,0未删除 >0 已删除', 'signed' => false))
+        $table  =  $this->table('users', array('engine' => 'Innodb', 'comment' => '用户表', 'signed' => false));
+        $table->addColumn('username', 'string', array('null' => true, 'limit'  =>  20, 'default' => '', 'comment' => '用户名'))
+            ->addColumn('password', 'string', array('null' => true, 'limit'  =>  255, 'comment' => '用户密码'))
+            ->addColumn('sex', 'integer', ['null' => true, 'default' => 0, 'comment' => '性别'])
+            ->addColumn('email', 'string', array('null' => true, 'limit'  =>  100, 'comment' => '邮箱 登录'))
+            ->addColumn('idcard', 'string', array('null' => true, 'limit'  =>  20, 'comment' => '身份证'))
+            ->addColumn('user_no', 'string', array('null' => true, 'limit'  =>  20, 'comment' => '用户编号'))
+            ->addColumn('department_id', 'integer', ['null' => true, 'default' => 0, 'comment' => '部门ID'])
+            ->addColumn('status', 'boolean', array('null' => true, 'limit'  =>  1, 'default' => 1, 'comment' => '用户状态 1 正常 2 禁用'))
+            ->addColumn('last_login_ip', 'string', array('null' => true, 'limit' => 50, 'default' => 0, 'comment' => '最后登录IP'))
+            ->addColumn('last_login_time', 'integer', array('null' => true, 'default' => 0, 'comment' => '最后登录时间', 'signed' => false))
+            ->addColumn('wxmp_open_id', 'string', ['limit' => '30', 'null' => true, 'signed' => true, 'comment' => '微信小程序openid',])
+            ->addColumn('wx_open_id', 'string', ['limit' => '30', 'null' => true, 'signed' => true, 'comment' => '微信公众号openid',])
+            ->addColumn('wx_union_id', 'string', ['limit' => '50', 'null' => true, 'signed' => true, 'comment' => '微信unionid',])
+            ->addColumn('phone', 'string', ['null' => true, 'limit' => '20', 'null' => true, 'signed' => true, 'comment' => '手机号',])
+            ->addColumn('remember_token', 'string', ['limit' => 512, 'default' => '', 'null' => true, 'comment' => '用户token'])
+            ->addColumn('realname', 'string', ['null' => true, 'default' => '', 'comment' => '姓名', 'limit' => 20])
+            ->addColumn('equ_password', 'string', array('null' => true, 'limit'  =>  255, 'comment' => '设备密码'))
+            ->addColumn('avatar', 'string', ['limit' => 255, 'null' => true, 'default' => '', 'comment' => '用户头像', 'after' => 'email'])
+            ->addColumn('creator_id', 'integer', ['null' => true, 'default' => 0, 'comment' => '创建人ID'])
+            ->addColumn('created_at', 'integer', array('null' => true, 'default' => 0, 'comment' => '创建时间', 'signed' => false))
+            ->addColumn('updated_at', 'integer', array('null' => true, 'default' => 0, 'comment' => '更新时间', 'signed' => false))
+            ->addColumn('deleted_at', 'integer', array('null' => true, 'default' => 0, 'comment' => '删除状态,0未删除 >0 已删除', 'signed' => false))
             ->create();
     }
 }

+ 175 - 97
catch/permissions/model/Users.php

@@ -1,79 +1,84 @@
 <?php
+
 namespace catchAdmin\permissions\model;
 
+use catchAdmin\api\Listen;
 use catchAdmin\permissions\model\search\UserSearch;
 use catcher\base\CatchModel;
 use catcher\exceptions\FailedException;
 use catcher\Utils;
 use catchAdmin\permissions\model\DataRangScopeTrait;
 use think\facade\Db;
+
 class Users extends CatchModel
 {
     use HasRolesTrait;
     use HasJobsTrait;
     use UserSearch;
-     //权限过滤
-     use DataRangScopeTrait;
+    //权限过滤
+    use DataRangScopeTrait;
     protected $name = 'users';
 
     protected $field = [
-            'id', // 
-			'username', // 用户名
-			'password', // 用户密码
-			'email', // 邮箱 登录
-            'avatar', // 头像
-            'remember_token',
-            'creator_id', // 创建者ID
-            'department_id', // 部门ID
-			'status', // 用户状态 1 正常 2 禁用
-			'last_login_ip', // 最后登录IP
-			'last_login_time', // 最后登录时间
-			'created_at', // 创建时间
-			'updated_at', // 更新时间
-			'deleted_at', // 删除状态,0未删除 >0 已删除
-            'area_id', // 区域ID
-            'phone', // 手机号
-            'wxmp_open_id',
-            'wx_open_id',
-            'wx_union_id',
-            'school_id',
-            'grade_id',
-            'class_id',
-            'passive_rfid',
-            'realname',
-            'idcard',
-            'active_rfid',
-            'active_rfid_code',
-            'rfid_expire_date',
-            'student_no',
-            'card_status',
-            'rules_id',
-            'parents_id',
-            'sex',
-            'age',
-            'online_time',
-            'alarm_status',
-            'last_station_mac',
-            'birthday',
-            'addr',
-            'classes',
-            'manage_classes',
-            'subjects',
-            'card_type',
-            'student_type',
-            'student_status',
-            'voice',
-            'voice_size',
-            'voice_time',
-            'imei',
-            'battery_level',
-            'accesskey',
-            'secretkey',
-            'remark',
-            'dept_name',
-            'asset_admin',
-            'wifi_macs',
-            'user_no'
+        'id', // 
+        'username', // 用户名
+        'password', // 用户密码
+        'email', // 邮箱 登录
+        'avatar', // 头像
+        'remember_token',
+        'creator_id', // 创建者ID
+        'department_id', // 部门ID
+        'status', // 用户状态 1 正常 2 禁用
+        'last_login_ip', // 最后登录IP
+        'last_login_time', // 最后登录时间
+        'created_at', // 创建时间
+        'updated_at', // 更新时间
+        'deleted_at', // 删除状态,0未删除 >0 已删除
+        'area_id', // 区域ID
+        'phone', // 手机号
+        'wxmp_open_id',
+        'wx_open_id',
+        'wx_union_id',
+        'school_id',
+        'grade_id',
+        'class_id',
+        'passive_rfid',
+        'realname',
+        'idcard',
+        'active_rfid',
+        'active_rfid_code',
+        'rfid_expire_date',
+        'student_no',
+        'card_status',
+        'rules_id',
+        'parents_id',
+        'sex',
+        'age',
+        'online_time',
+        'alarm_status',
+        'last_station_mac',
+        'birthday',
+        'addr',
+        'classes',
+        'manage_classes',
+        'subjects',
+        'card_type',
+        'student_type',
+        'student_status',
+        'voice',
+        'voice_size',
+        'voice_time',
+        'imei',
+        'battery_level',
+        'accesskey',
+        'secretkey',
+        'remark',
+        'dept_name',
+        'asset_admin',
+        'wifi_macs',
+        'user_no',
+        //设备密码
+        'equ_password'
     ];
 
     /**
@@ -97,23 +102,23 @@ class Users extends CatchModel
      */
     public function getList(): \think\Paginator
     {
-        $no_display_roles = Db::table('roles')->whereIn('identify','personal,group_card_user,group_badge_user')->column('id');
+        $no_display_roles = Db::table('roles')->whereIn('identify', 'personal,group_card_user,group_badge_user')->column('id');
         $user = request()->user();
         $res = $this->dataRange()
-                    ->withoutField(['updated_at'], true)
-                    ->catchSearch()
-                    ->alias('u')
-                    ->join('user_has_roles r','u.id=r.uid')
-                    // ->distinct(true)
-                    ->group('u.id')
-                    ->where('u.id','<>',1) //超级管理员账号不显示
-                    ->where('u.id','<>',$user->id) //不显示自己
-                    ->whereNotIn('r.role_id',$no_display_roles)
-                    ->catchLeftJoin(Department::class, 'id', 'department_id', ['department_name'])
-                    ->order($this->aliasField('id'), 'desc')
-                    ->paginate();
-                    // var_dump($this->getLastSql());
-                    return $res;
+            ->withoutField(['updated_at'], true)
+            ->catchSearch()
+            ->alias('u')
+            ->join('user_has_roles r', 'u.id=r.uid')
+            // ->distinct(true)
+            ->group('u.id')
+            ->where('u.id', '<>', 1) //超级管理员账号不显示
+            ->where('u.id', '<>', $user->id) //不显示自己
+            ->whereNotIn('r.role_id', $no_display_roles)
+            ->catchLeftJoin(Department::class, 'id', 'department_id', ['department_name'])
+            ->order($this->aliasField('id'), 'desc')
+            ->paginate();
+        // var_dump($this->getLastSql());
+        return $res;
     }
 
     /**
@@ -142,8 +147,8 @@ class Users extends CatchModel
 
         return array_unique($permissionIds);
     }
-	
-	 /**
+
+    /**
      * 后台根据权限标识判断用户是否拥有某个权限
      * @param string $permission_mark
      * @return bool
@@ -156,12 +161,12 @@ class Users extends CatchModel
     public function can($permission_mark)
     {
         // 超级管理员直接返回true
-        if (Utils::isSuperAdmin()){
+        if (Utils::isSuperAdmin()) {
             return true;
         }
         // 查询当前用户的权限
         return in_array(
-            Permissions::where('permission_mark',$permission_mark)->value('id') ? : 0,
+            Permissions::where('permission_mark', $permission_mark)->value('id') ?: 0,
             $this->getPermissionsBy()
         );
     }
@@ -179,23 +184,22 @@ class Users extends CatchModel
      */
     public function getUserByDepart($value)
     {
-        
+
         return $this
-                ->where('department_id', $value)
-                ->field('id as value,username as text')
-                ->select();
+            ->where('department_id', $value)
+            ->field('id as value,username as text')
+            ->select();
     }
-    
+
     /**
      * 根据多个部门ID获取用户Ids
      */
     public function getUserByDepartIds($value)
     {
-        
+
         return $this
-                ->whereIn('department_id', $value)
-                ->column('id');
-               
+            ->whereIn('department_id', $value)
+            ->column('id');
     }
 
     /**
@@ -204,21 +208,21 @@ class Users extends CatchModel
     public function getPushUserList()
     {
         // 查出非家长、学生角色id
-        $allowed_roles = Db::table('roles')->whereNotIn('identify',['personal','group_card_user','group_badge_user'])->column('id');
+        $allowed_roles = Db::table('roles')->whereNotIn('identify', ['personal', 'group_card_user', 'group_badge_user'])->column('id');
         $allowed_roles_text = join(',', $allowed_roles);
         // 查出有这些角色的用户信息
         $res = $this->dataRange()
-                    ->catchSearch()
-                    ->alias('u')
-                    ->field('u.*')
-                    ->where('u.id','<>',1) //超级管理员账号不显示
-                    ->distinct(true)
-                    ->join('user_has_roles uhr', "uhr.role_id in ({$allowed_roles_text}) and uhr.uid = u.id")
-                    ->select()
-                    ->toArray();
+            ->catchSearch()
+            ->alias('u')
+            ->field('u.*')
+            ->where('u.id', '<>', 1) //超级管理员账号不显示
+            ->distinct(true)
+            ->join('user_has_roles uhr', "uhr.role_id in ({$allowed_roles_text}) and uhr.uid = u.id")
+            ->select()
+            ->toArray();
         // 非管理员,可能存在是管理员添加的账号,查不到自己,追加自己
         // var_dump($this->getLastSql());
-        if (!Utils::isSuperAdmin()){
+        if (!Utils::isSuperAdmin()) {
             $has_self = false;
             foreach ($res as $user) {
                 if ($user['id'] == request()->user()->id) {
@@ -231,4 +235,78 @@ class Users extends CatchModel
         }
         return $res;
     }
+    //下发设备
+    /**
+     * @Descripttion: 将用户下发给设备
+     * @name: likang
+     * @param {*} $user 用户数组
+     * @return {*}
+     */
+    public function equUserUpdate($user)
+    {
+        $roleid = [7, 9, 10];
+        $content = null;
+        $equ_user = [];
+        $where = [];
+        $wheres = [];
+        $permissions = null;
+        $where[] = ['uid', '=', $user['id']];
+        $where[] = ['role_id', 'in', $roleid];
+        $wheres[] = ['ContentType', '=', 'Users'];
+        $wheres[] = ['ContentId', '=', $user['id']];
+        $data = Db::name('user_has_roles')->where($where)->find();
+        $pubulish =  Db::name('publish')->where($wheres)->find();
+        $time = msectime();
+        //是否存在该设备
+        if ($data) {
+            if ($data['role_id'] == 7) {
+                $permissions = 10;
+            } else if ($data['role_id'] == 9) {
+                $permissions = 11;
+            } else if ($data['role_id'] == 10) {
+                $permissions = 12;
+            }
+
+            $equ_user = [
+                'id' => intval($user['id']),
+                'name' => strval($user['username']),
+                'pwd' => strval($user['equ_password']),
+                'perm' => intval($permissions)
+            ];
+            //判断下发的数据库中是否存在
+            if ($pubulish) {
+                $content = [
+                    'Type' => 'update',
+                    'ContentType' => 'Users',
+                    'ContentId' => $user['id'],
+                    'Version' => $time,
+                    'Status' => 1,
+                    'Content' => json_encode($equ_user)
+                ];
+                Db::name('publish')->where($wheres)->update($content);
+            } else {
+                $content = [
+                    'Type' => 'add',
+                    'ContentType' => 'Users',
+                    'ContentId' => $user['id'],
+                    'Version' => $time,
+                    'AddTime' => $time,
+                    'Status' => 1,
+                    'Content' => json_encode($equ_user)
+                ];
+                Db::name('publish')->save($content);
+            }
+        } else {
+            if ($pubulish) {
+                $content = [
+                    'Type' => 'delete',
+                    'Version' => $time,
+                    'Status' => 1,
+                ];
+                Db::name('publish')->where($wheres)->update($content);
+            }
+        }
+
+        return;
+    }
 }

+ 4 - 4
catch/wind/model/Fan.php

@@ -5,7 +5,7 @@
  * @Author: likang
  * @Date: 2022-05-27 13:34:31
  * @LastEditors: likang
- * @LastEditTime: 2022-07-07 11:00:49
+ * @LastEditTime: 2022-07-09 14:43:53
  */
 
 namespace catchAdmin\wind\model;
@@ -83,9 +83,9 @@ class Fan extends Model
         $data = null;
         $content = null;
         $data = [
-            'id' => $obj->id,
-            'wind_number' => Wind::where('id', $obj->wind_id)->value('number'),
-            'number' => $this->number,
+            'id' => intval($obj->id),
+            'wnum' => Wind::where('id', $obj->wind_id)->value('number'),
+            'number' => intval($this->number),
         ];
         $content['data'] = $data;
         $content['type'] = 'Fan';