Browse Source

[智价云] 补充移动端个人信息详情接口

tangyuanwang 1 tuần trước cách đây
mục cha
commit
bde8227737

+ 46 - 0
app/Http/Controllers/Api/Personnel/Employee.php

@@ -5,6 +5,9 @@ namespace App\Http\Controllers\Api\Personnel;
 use App\Http\Controllers\Api\Api;
 use App\Http\Requests\Api\Personnel\Employee as Request;
 use App\Models\Api\Personnel\Employee as EmployeeModel;
+use App\Models\Api\Personnel\Department as DepartmentModel;
+use App\Models\Api\Personnel\Roles as RolesModel;
+use App\Models\Api\Citys as CitysModel;
 
 /**
  * 人员信息管理-员工管理
@@ -45,4 +48,47 @@ class Employee extends Api
         // 加载模板
         return        json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
     }
+
+
+
+    /**
+     * 个人信息详情
+     * @author    唐远望
+     * @version   1.0
+     * @date      2026-03-03
+     */
+    public function personal_info(Request $request, EmployeeModel $EmployeeModel, DepartmentModel $DepartmentModel, RolesModel $RolesModel, CitysModel $CitysModel)
+    {
+        $request->scene('personal_info')->validate();
+        $user_info = $this->checkLogin();
+        if (!$user_info) return json_send(['code' => 'error', 'msg' => '请先登录']);
+        $company_id = $user_info['company_id'];
+        // 接收参数
+        $map = ['id' => $user_info['uid']];
+        // 权限判断
+        $map['company_id'] = $company_id;
+        $field = ['id', 'employee_code', 'name', 'mobile', 'email', 'department_ids', 'duty_type', 'role_id', 'city_ids', 'open_notice', 'insert_time', 'update_time', 'status'];
+        $data = $EmployeeModel->where($map)->select($field)->first();
+        if (!$data)     return json_send(['code' => 'error', 'msg' => '记录不存在']);
+        // 查询部门信息
+        $department_ids = explode(',', $data['department_ids']);
+        $department_info = $DepartmentModel->whereIn('id', $department_ids)->select(['id', 'name'])->get()->toarray();
+        // 查询角色信息
+        $role_where = ['id' => $data['role_id']];
+        $role_where['company_id'] = $company_id;
+        $role_info = $RolesModel->where($role_where)->first();
+        // 查询城市信息
+        $city_ids = explode(',', $data['city_ids']);
+        $city_info = [];
+        if (count($city_ids) > 0) {
+            $city_info = $CitysModel->whereIn('id', $city_ids)->pluck('name');
+        }
+        //截取字符串
+        $data['department_ids'] = $data['department_ids'] != '' ? substr($data['department_ids'], 1, strlen($data['department_ids']) - 2) : '';
+        $data['department_name'] = isset($department_info) ? array_column($department_info, 'name') : '';
+        $data['role_name'] = isset($role_info['name']) ? $role_info['name'] : '';
+        $data['city_info'] = $city_info;
+        // 加载模板
+        return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $data]);
+    }
 }

+ 1 - 0
app/Http/Requests/Api/Personnel/Employee.php

@@ -47,6 +47,7 @@ class Employee extends BaseRequest
         'edit'                  => ['id','name', 'mobile','department_id','role_id','open_notice'],
         'set_status'              => ['id', 'status'],
         'delete'                  => ['id'],
+        'personal_info'           => [],
     ];
 
     /**

+ 246 - 0
app/Models/Api/Citys.php

@@ -0,0 +1,246 @@
+<?php
+
+namespace App\Models\Api;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * 城市模型
+ * 
+ */
+class Citys extends Model
+{
+    use HasFactory;
+
+    // 与模型关联的表名
+    protected $table = 'city';
+    // 是否主动维护时间戳
+    public $timestamps = false;
+    // 定义时间戳字段名
+    // const CREATED_AT = 'insert_time';
+    // const UPDATED_AT = 'update_time';
+
+    /**
+     * 添加数据
+     * 
+     */
+    public function add($data)
+    {
+        // 时间
+        $data['insert_time']                = time();
+        $data['update_time']                = time();
+        // 写入数据表
+        $id                                    = $this->query()->insertGetId($data);
+        // 失败返回0
+        if (!$id)                          return 0;
+        // 返回结果
+        return                              $id;
+    }
+
+    /**
+     * 添加数据
+     * 
+     */
+    public function edit($id, $data)
+    {
+        // 更新时间
+        $data['update_time']                = time();
+        // 写入数据表
+        $result                                = $this->query()->where([['id', '=', $id]])->update($data);
+        // 失败返回0
+        if (!$result)                      return 0;
+        // 返回结果
+        return                              $id;
+    }
+
+
+
+    /**
+     * 获取列表
+     * @param   Bool    $force  是否强制更新
+     * 
+     */
+    public function getList($force = false)
+    {
+        // 结果数据
+        $list                  = $force ? [] : cache('admin:city:list');
+        // 不存在数据
+        if (!$list) {
+            // 从数据库获取数据
+            $data              = $this->query()->where([['status', '=', 0], ['level', '<', 3]])->get(['id', 'name', 'pid']);
+            // 是否有数据
+            $data              = $data ? $data->toArray() : [];
+            // 循环处理数据
+            $list              = [];
+            // 进行更新
+            foreach ($data as $value) {
+                // 重组数据
+                $list[$value['id']] = $value;
+            }
+            $list = $this->getTree($list);
+            // 存起来
+            cache(['admin:city:list' => $list]);
+        }
+
+        // 返回结果
+        return                  $list;
+    }
+
+    /**
+     * 获取城市ID列表
+     * @param   Bool    $force  是否强制更新
+     * 
+     */
+    public function get_city_id_list($force = false)
+    {
+        // 结果数据
+        $list                  = $force ? [] : cache('admin:city_id:list');
+        // 不存在数据
+        if (!$list) {
+            // 从数据库获取数据
+            $data              = $this->query()->where([['status', '=', 0], ['level', '<=', 2]])->get(['id', 'name', 'pid'])->keyBy('name')->toarray();
+            // 是否有数据
+            $list              = $data ? $data : [];
+            // 存起来
+            cache(['admin:city_id:list' => $list]);
+        }
+        // 返回结果
+        return                  $list;
+    }
+
+    /**
+     * 获取省份ID列表
+     * @param   Bool    $force  是否强制更新
+     * 
+     */
+    public function get_province_id_list($force = false)
+    {
+        // 结果数据
+        $list                  = $force ? [] : cache('admin:province_id:list');
+        // 不存在数据
+        if (!$list) {
+            // 从数据库获取数据
+            $data              = $this->query()->where([['status', '=', 0], ['level', '=', 1]])->get(['id', 'name', 'pid'])->keyBy('name')->toarray();
+            // 是否有数据
+            $list              = $data ? $data : [];
+            // 存起来
+            cache(['admin:province_id:list' => $list]);
+        }
+        // 返回结果
+        return                  $list;
+    }
+
+
+
+    /**
+     * 获取某个
+     * 
+     * @param   int         $id     ID
+     * @param   string     $field   指定字段
+     * 
+     */
+    public function getOne($id, $field = '')
+    {
+        // 获取列表数据
+        $list                   = $this->getList();
+        // 获取数据
+        $one                    = isset($list[$id]) ? $list[$id] : [];
+        // 返回值
+        return                  empty($field) ? $one : (isset($one[$field]) ? $one[$field] : null);
+    }
+
+
+    /**
+     * 获取某个地区名称
+     * @author 唐远望
+     * @verson 1.0
+     * @date 2025-12-23
+     * 
+     */
+    public function get_city_name($id, $force = false)
+    {
+        $list                  = $force ? [] : cache('admin:city:source_list_name');
+        // 不存在数据
+        if (!$list) {
+            // 获取列表数据
+            $list_data              = $this->query()->where([['status', '=', 0], ['level', '<', 3]])->get(['id', 'name', 'pid'])->toArray();
+            if (!empty($list_data)) {
+                foreach ($list_data as $key => $value) {
+                    $list[$value['id']] = $value['name'];
+                }
+            }
+            cache(['admin:city:source_list_name' => $list]);
+        }
+        // 获取数据
+        $one                    = isset($list[$id]) ? $list[$id] : [];
+        // 返回值
+        return                 $one;
+    }
+
+    /**
+     * 获取城市对应的ID
+     * 
+     * @param   string         $name 城市名
+     * 
+     */
+    public function getIdByName($name)
+    {
+        // 返回结果
+        return                  (int) $this->query()->where([['name', '=', $name]])->value('id');
+    }
+
+    /**
+     * 获取城市列表
+     * 
+     */
+    public function getCityList()
+    {
+        // 城市json
+        $cityList               = @file_get_contents(resource_path('./js/') . 'city.json');
+        // 解码
+        $cityList               = (array) json_decode($cityList, true);
+        // 返回结果
+        return                  $cityList;
+    }
+
+    /**
+
+     * 无限极分类
+
+     * @param type $array
+
+     * @return type $new_array
+
+     */
+
+    public function getTree($array)
+    {
+
+        //遍历数组,按照id作为键名重新组建新的数组
+
+        $new_array = [];
+
+        foreach ($array as $v) {
+
+            $new_array[$v['id']] = $v;
+        }
+
+        //遍历新的数组,对每一个值的pid进行判断,判断新数组中是否存在键名为pid的值,如果存在,当前值为存在的pid的子节点,不存在,当前值为一级节点,添加到返回的数据中作为一级节点。这里使用引用传值是因为直接传值是不会影响到函数外边的变量值,我们这里要给一级节点添加子节点(sons),所以需要用到引用传值。
+
+        $return_tree = [];
+
+        foreach ($new_array as $kk => $vv) {
+
+            if (isset($new_array[$vv['pid']])) {
+
+                $new_array[$vv['pid']]['sons'][] = &$new_array[$kk];
+            } else {
+
+                $return_tree[] = &$new_array[$kk];
+            }
+        }
+
+        return $return_tree;
+    }
+}

+ 148 - 0
app/Models/Api/Personnel/Department.php

@@ -0,0 +1,148 @@
+<?php
+
+namespace App\Models\Api\Personnel;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Support\Facades\DB;
+
+/**
+ * 部门模型
+ * @author 唐远望
+ * @version 1.0
+ * @date 2025-12-04
+ */
+class Department extends Model
+{
+    use HasFactory;
+    // 与模型关联的表名
+    protected $table = 'personnel_department';
+    // 是否主动维护时间戳
+    public $timestamps = false;
+    // 定义时间戳字段名
+    // const CREATED_AT = 'insert_time';
+    // const UPDATED_AT = 'update_time';
+
+
+    /**
+     * 添加
+     * @author 唐远望
+     * @version 1.0
+     * @date 2025-12-04
+     */
+    public function addDepartment_content($data)
+    {
+        $insert_data = [
+            'name' => $data['name'],
+            'company_id'=> $data['company_id'],
+            'insert_time' => time(),
+        ];
+        $Department_id = $this->insertGetId($insert_data);
+        return $Department_id;
+    }
+
+
+    /**
+     * 写入数据
+     * @author 唐远望
+     * @version 1.0
+     * @date 2025-12-04
+     * @param $data
+     * @return bool
+     */
+    public function addDepartment($data)
+    {
+        DB::beginTransaction();
+        try {
+            $this->addDepartment_content($data);
+            DB::commit();
+            return true;
+            // 成功处理...
+        } catch (\Exception $e) {
+            DB::rollBack();
+            // 错误处理...
+            return false;
+        }
+    }
+
+
+    /**
+     * 编辑内容
+     * @author 唐远望
+     * @version 1.0
+     * @date 2025-12-04
+     * @param $data
+     * @return bool
+     */
+    public function editDepartment_content($Department, $data)
+    {
+        $Department->name = $data['name'];
+        $Department->update_time = time();
+        $Department->save();
+        return true;
+    }
+
+
+
+    /**
+     * 更新数据
+     * @author 唐远望
+     * @version 1.0
+     * @date 2025-12-04
+     * @param $data
+     * @return bool
+     */
+    public function updateDepartment($where, $data)
+    {
+        DB::beginTransaction();
+        try {
+            $this->editDepartment_content($where, $data);
+            DB::commit();
+            return true;
+            // 成功处理...
+        } catch (\Exception $e) {
+            DB::rollBack();
+            // 错误处理...
+            return false;
+        }
+    }
+
+    /**
+     * 修改状态
+     * @author 唐远望
+     * @version 1.0
+     * @date 2025-12-04
+     * @param $id
+     * @param $status
+     * @return bool
+     */
+    public function changeStatus($where, $status)
+    {
+        $Department = $this->where($where)->first();
+        if (!$Department) {
+            return false;
+        }
+        $Department->status = $status;
+        $Department->update_time = time();
+        $Department->save();
+        return true;
+    }
+
+    /**
+     * 删除数据
+     * @author 唐远望
+     * @version 1.0
+     * @date 2025-12-04
+     * @param $id
+     * @return bool
+     */
+    public function deleteDepartment($where)
+    {
+        $Department = $this->where($where)->first();
+        if (!$Department) {
+            return false;
+        }
+        $Department->delete();
+        return true;
+    }
+}

+ 153 - 0
app/Models/Api/Personnel/Roles.php

@@ -0,0 +1,153 @@
+<?php
+
+namespace App\Models\Api\Personnel;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Support\Facades\DB;
+use App\Models\Manager\Personnel\RolesAuthRule as RolesAuthRuleModel;
+
+/**
+ * 角色模型
+ * @author 唐远望
+ * @version 1.0
+ * @date 2025-12-05
+ */
+class Roles extends Model
+{
+   use HasFactory;
+    // 与模型关联的表名
+    protected $table = 'personnel_roles';
+    // 是否主动维护时间戳
+    public $timestamps = false;
+    // 定义时间戳字段名
+    // const CREATED_AT = 'insert_time';
+    // const UPDATED_AT = 'update_time';
+
+
+    /**
+     * 添加
+     * @author 唐远望
+     * @version 1.0
+     * @date 2025-12-05
+     */
+    public function addRoles_content($data)
+    {
+        $insert_data = [
+            'name' => $data['name'],
+            'company_id' => $data['company_id'],
+            'insert_time' => time(),
+        ];
+        $Roles_id = $this->insertGetId($insert_data);
+        return $Roles_id;
+    }
+
+
+    /**
+     * 写入数据
+     * @author 唐远望
+     * @version 1.0
+     * @date 2025-12-05
+     * @param $data
+     * @return bool
+     */
+    public function addRoles($data)
+    {
+        $RolesAuthRuleModel = new RolesAuthRuleModel();
+        DB::beginTransaction();
+        try {
+            $role_id=$this->addRoles_content($data);
+            $RolesAuthRuleModel->addRolesAuthRule(['role_id'=> $role_id,'menu_ids'=>$data['menu_ids']]);
+            DB::commit();
+            return true;
+            // 成功处理...
+        } catch (\Exception $e) {
+            DB::rollBack();
+            // 错误处理...
+            return false;
+        }
+    }
+
+
+    /**
+     * 编辑内容
+     * @author 唐远望
+     * @version 1.0
+     * @date 2025-12-05
+     * @param $data
+     * @return bool
+     */
+    public function editRoles_content($Roles, $data)
+    {
+        $Roles->name = $data['name'];
+        $Roles->update_time = time();
+        $Roles->save();
+        return true;
+    }
+
+
+
+    /**
+     * 更新数据
+     * @author 唐远望
+     * @version 1.0
+     * @date 2025-12-05
+     * @param $data
+     * @return bool
+     */
+    public function updateRoles($Roles, $data)
+    {
+        $RolesAuthRuleModel = new RolesAuthRuleModel();
+        DB::beginTransaction();
+        try {
+            $this->editRoles_content($Roles, $data);
+            $RolesAuthRuleModel->addRolesAuthRule(['role_id'=> $Roles->id,'menu_ids'=>$data['menu_ids']]);
+            DB::commit();
+            return true;
+            // 成功处理...
+        } catch (\Exception $e) {
+            DB::rollBack();
+            // 错误处理...
+            return false;
+        }
+    }
+
+    /**
+     * 修改状态
+     * @author 唐远望
+     * @version 1.0
+     * @date 2025-12-05
+     * @param $id
+     * @param $status
+     * @return bool
+     */
+    public function changeStatus($where, $status)
+    {
+        $Roles = $this->where($where)->first();
+        if (!$Roles) {
+            return false;
+        }
+        $Roles->status = $status;
+        $Roles->update_time = time();
+        $Roles->save();
+        return true;
+    }
+
+    /**
+     * 删除数据
+     * @author 唐远望
+     * @version 1.0
+     * @date 2025-12-05
+     * @param $id
+     * @return bool
+     */
+    public function deleteRoles($where)
+    {
+        $Roles = $this->where($where)->first();
+        if (!$Roles) {
+            return false;
+        }
+        $Roles->delete();
+        return true;
+    }
+}

+ 2 - 0
routes/api.php

@@ -57,6 +57,8 @@ Route::any('process/violation_store/set_processing_status', [App\Http\Controller
 
 // 员工管理-列表
 Route::any('personnel_employee/list', [App\Http\Controllers\Api\Personnel\Employee::class, 'list']);
+// 员工管理-个人信息详情
+Route::any('personnel_employee/personal_info', [App\Http\Controllers\Api\Personnel\Employee::class, 'personal_info']);
 
 // ------数据清洗配置------
 // 低价商品-列表