erp/app/Models/Log.php

128 lines
3.2 KiB
PHP
Raw Normal View History

<?php
namespace App\Models;
2022-08-01 14:28:49 +08:00
use App\Models\traits\Filter;
2022-08-01 17:06:43 +08:00
use Illuminate\Support\Facades\Auth;
2022-08-01 14:28:49 +08:00
class Log extends Model
{
2022-08-01 14:28:49 +08:00
use Filter;
2022-08-01 14:28:49 +08:00
//查询字段
public $fieldSearchable = [
2022-08-01 17:06:43 +08:00
'module',
2022-08-01 14:28:49 +08:00
'action',
'target_type',
'target_id',
'target_field',
'user_id',
2022-08-11 18:09:15 +08:00
'start_time',
'end_time',
2022-08-01 14:28:49 +08:00
];
2022-08-01 17:06:43 +08:00
public $fillable = [
'module',
'action',
'target_type',
'target_id',
'target_field',
'before_update',
'after_update',
];
2022-08-01 17:19:36 +08:00
public function getModuleAttribute($value)
{
$map = [
'goods' => '商品',
'menu' => '菜单',
'permission' => '权限',
'role' => '角色',
'user' => '用户',
2022-08-08 10:43:59 +08:00
'plat' => '平台',
'file' => '文件',
2022-08-01 17:19:36 +08:00
];
return $map[$value] ?? $value;
2022-08-01 17:19:36 +08:00
}
public function getActionAttribute($value)
{
$map = [
'GET' => '查看',
'POST' => '新增',
'PATCH' => '更新',
'DELETE' => '删除',
];
return $map[$value] ?? $value;
2022-08-01 17:19:36 +08:00
}
public function getTargetTypeAttribute($value)
{
$map = [
'goods_sku' => '商品&规格',
'goods_type' => '商品种类',
'goods_brand' => '商品品牌',
'permission' => '权限',
'role' => '角色',
'menu' => '菜单',
'user' => '用户',
2022-08-08 10:43:59 +08:00
'upload' => '上传',
'kuaituantuan' => '快团团',
'miaoxuan' => '妙选',
'goods' => '商品',
2022-08-01 17:19:36 +08:00
];
return $map[$value] ?? $value;
2022-08-01 17:19:36 +08:00
}
public function getTargetFieldAttribute($value)
{
$map = [
'add' => '创建',
'status' => '状态',
'name' => '名称',
'title' => '名称',
'import' => '导入',
'export' => '导出',
'set' => '设置',
2022-08-08 10:43:59 +08:00
'cost' => '成本',
'stock' => '库存',
'inventory' => '库存盘点',
2022-08-17 18:42:40 +08:00
'reserve' => '预留量 ',
2022-08-24 10:35:44 +08:00
'timingInventory' => '7点盘点',
2022-08-17 18:42:40 +08:00
'pdd.ktt.goods.query.list' => '快团团下载绑定商品',
'arrived_today_num' => '今日到货',
'loss_num' => '损耗',
'pdd.pop.auth.token.create' => '快团团授权',
'reference_price' => '参考价格',
'update' => '更新',
2022-08-20 13:42:22 +08:00
'pdd.ktt.goods.incr.quantity' => '快团团库存同步',
2022-08-24 10:35:44 +08:00
'pdd.ktt.order.list' => '快团团下载订单',
'pdd.ktt.increment.order.query' => '快团团增量下载订单'
2022-08-01 17:19:36 +08:00
];
return $map[$value] ?? $value;
2022-08-01 17:19:36 +08:00
}
2022-08-01 17:06:43 +08:00
public function setUserIdAttribute($value)
{
2022-08-04 13:21:45 +08:00
$this->attributes['user_id'] = Auth::id() ?: $value;
2022-08-01 17:06:43 +08:00
}
public function add($targetId = 0, $targetField = '')
{
2022-08-24 10:35:44 +08:00
$this->attributes['user_id'] = Auth::id() ?? 999;
2022-08-01 17:06:43 +08:00
$this->attributes['target_id'] = $targetId;
$this->attributes['target_field'] = $targetField;
return $this->save();
}
2022-08-01 17:21:55 +08:00
public function user()
{
return $this->hasOne(User::class, 'id', 'user_id');
}
}