| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- namespace App\Models\Manager;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- use App\Models\Manager\AdminUser as AdminUserModel;
- use App\Models\Manager\Personnel\Employee as EmployeeModel;
- use App\Models\Manager\External\Company as CompanyModel;
- /**
- * 后台管理员操作历史
- *
- */
- class AdminHistory extends Model
- {
- use HasFactory;
- // 与模型关联的表名
- protected $table = 'admin_history';
- // 定义时间戳字段名
- // const CREATED_AT = 'insert_time';
- // const UPDATED_AT = 'update_time';
- /**
- * 添加数据
- *
- * @param Int $uid 用户ID
- * @param String $table 操作表
- * @param Int $type 操作类型,1添加,2修改,3=删除
- * @param Array $oldData 旧数据
- * @param Array $oldData 新数据
- * @param String $general_description 操作描述
- *
- */
- public function addAll($admin_menu_name,$company_id='0', $uid, $is_admin, $table, $type, $oldData, $newData, $general_description = '')
- {
- $user_name = '';
- if ($is_admin == 1){
- $user_name = (new AdminUserModel())->where(['uid'=>$uid])->value('username');
- }else{
- $user_name = (new EmployeeModel())->where(['id'=>$uid])->value('name');
- }
- $company_name = (new CompanyModel())->where(['id'=>$company_id])->value('company_name');
- $insert_data = [
- // 操作用户
- 'user_name' => isset($user_name)? $user_name : '',
- // 品牌方公司名称
- 'company_name' => isset($company_name)? $company_name : '',
- // 公司ID
- 'company_id' => $company_id,
- // 模块菜单名称
- 'module_menu_name' => $admin_menu_name,
- //操作描述
- 'general_description' => $general_description,
- // 操作类型
- 'notes_type' => $type,
- // 操作表名
- 'table_name' => $table,
- // 操作用户
- 'admin_uid' => $uid,
- // 是否是管理员
- 'is_admin' => $is_admin,
- // 操作之前
- 'before_value' => json_encode($oldData),
- // 操作之后
- 'after_value' => json_encode($newData),
- // 时间
- 'insert_time' => time(),
- ];
- // 结果
- $result = $this->insertGetId($insert_data);
- // 如果有数据
- return $result;
- }
- }
|