feat: 增加onBeforeWriteonAfterWrite方法在StoreFinanceFlowSystemStore模型中以记录更新前后的日志

This commit is contained in:
mkm 2024-09-28 15:32:31 +08:00
parent 2a17dde78d
commit e58b0fbac5
2 changed files with 29 additions and 3 deletions

View File

@ -36,10 +36,22 @@ class StoreFinanceFlow extends BaseModel
{ {
return $this->hasOne(SystemStoreStaff::class, 'id', 'staff_id')->bind(['staff_name']); return $this->hasOne(SystemStoreStaff::class, 'id', 'staff_id')->bind(['staff_name']);
} }
public static function onBeforeWrite($data)
{
try {
$where = $data->getWhere();
if($data){
$find = self::where($where)->field(array_keys($data->toArray()))->find();
if($find){
channelLog(array_merge($find->toArray(),$where),'store_finance_flow','更新前');
}
}
} catch (Throwable $e) {
Log::error('store_finance_flow:' . $e->getMessage());
}
}
public static function onAfterWrite($data){ public static function onAfterWrite($data){
try{ try{
channelLog($data->getOrigin(),'store_finance_flow','更新前');
channelLog($data->toArray(),'store_finance_flow','更新后'); channelLog($data->toArray(),'store_finance_flow','更新后');
}catch(Throwable $e){ }catch(Throwable $e){
Log::error('store_finance_flow:'.$e->getMessage()); Log::error('store_finance_flow:'.$e->getMessage());

View File

@ -19,9 +19,23 @@ class SystemStore extends BaseModel
protected $name = 'system_store'; protected $name = 'system_store';
protected $deleteTime = 'delete_time'; protected $deleteTime = 'delete_time';
public static function onBeforeWrite($data)
{
try {
$where = $data->getWhere();
if($data){
$find = self::where($where)->field(array_keys($data->toArray()))->find();
if($find){
channelLog(array_merge($find->toArray(),$where),'system_store','更新前');
}
}
} catch (Throwable $e) {
Log::error('system_store:' . $e->getMessage());
}
}
public static function onAfterWrite($data){ public static function onAfterWrite($data){
try{ try{
channelLog($data->getOrigin(),'system_store','更新前');
channelLog($data->toArray(),'system_store','更新后'); channelLog($data->toArray(),'system_store','更新后');
}catch(Throwable $e){ }catch(Throwable $e){
Log::error('system_store:'.$e->getMessage()); Log::error('system_store:'.$e->getMessage());