From 03cc208b1ddf9434afe4b7faa44baa743e38d28a Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 6 Jan 2025 11:00:46 +0800 Subject: [PATCH] =?UTF-8?q?refactor(model):=20=E7=A7=BB=E9=99=A4=E9=97=A8?= =?UTF-8?q?=E5=BA=97=E3=80=81=E4=BB=93=E5=BA=93=E5=92=8C=E5=BA=93=E5=AD=98?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E4=B8=AD=E7=9A=84=E6=97=A5=E5=BF=97=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E9=92=A9=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除了 StoreBranchProduct、WarehouseProduct 和 WarehouseProductStorege 模型中的 onBeforeWrite 和 onAfterWrite 钩子方法 - 移除了用于记录更新前后日志的代码 - 简化了模型结构,提高了代码可读性和性能 --- .../StoreBranchProduct.php | 21 ------------------ .../warehouse_product/WarehouseProduct.php | 22 ------------------- .../WarehouseProductStorege.php | 22 ------------------- 3 files changed, 65 deletions(-) diff --git a/app/common/model/store_branch_product/StoreBranchProduct.php b/app/common/model/store_branch_product/StoreBranchProduct.php index 4f782f0f0..f36b7d9d7 100644 --- a/app/common/model/store_branch_product/StoreBranchProduct.php +++ b/app/common/model/store_branch_product/StoreBranchProduct.php @@ -68,25 +68,4 @@ class StoreBranchProduct extends BaseModel { return $this->hasOne(StoreProduct::class,'id','product_id'); } - 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),'branch_product','更新前'); - } - } - } catch (Throwable $e) { - Log::error('branch_product:' . $e->getMessage()); - } - } - public static function onAfterWrite($data){ - try{ - channelLog($data->toArray(),'branch_product','更新后'); - }catch(Throwable $e){ - Log::error('branch_product:'.$e->getMessage()); - } - } } \ No newline at end of file diff --git a/app/common/model/warehouse_product/WarehouseProduct.php b/app/common/model/warehouse_product/WarehouseProduct.php index 451a42768..54cbcbd3e 100644 --- a/app/common/model/warehouse_product/WarehouseProduct.php +++ b/app/common/model/warehouse_product/WarehouseProduct.php @@ -46,26 +46,4 @@ class WarehouseProduct extends BaseModel 'create_time', 'update_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),'warehouse_product','更新前'); - } - } - } catch (Throwable $e) { - Log::error('warehouse_product:' . $e->getMessage()); - } - } - - public static function onAfterWrite($data){ - try{ - channelLog($data->toArray(),'warehouse_product','更新后'); - }catch(Throwable $e){ - Log::error('warehouse_product:'.$e->getMessage()); - } - } } \ No newline at end of file diff --git a/app/common/model/warehouse_product_storege/WarehouseProductStorege.php b/app/common/model/warehouse_product_storege/WarehouseProductStorege.php index 4dfe1a65f..927b771e3 100644 --- a/app/common/model/warehouse_product_storege/WarehouseProductStorege.php +++ b/app/common/model/warehouse_product_storege/WarehouseProductStorege.php @@ -23,26 +23,4 @@ class WarehouseProductStorege extends BaseModel 'total_price', 'update_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), 'warehouse_product_storege', '更新前'); - } - } - } catch (Throwable $e) { - Log::error('warehouse_product_storege:' . $e->getMessage()); - } - } - public static function onAfterWrite($data) - { - try { - channelLog($data->toArray(), 'warehouse_product_storege', '更新后'); - } catch (Throwable $e) { - Log::error('warehouse_product_storege:' . $e->getMessage()); - } - } }