From 95334b874ad4fd1d2569947db4b1a647403fac6c Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 4 Jan 2025 11:43:27 +0800 Subject: [PATCH 1/5] =?UTF-8?q?fix(admin):=20=E4=BF=AE=E5=A4=8D=E9=A2=84?= =?UTF-8?q?=E5=94=AE=E8=AE=A2=E5=8D=95=E5=88=9B=E5=BB=BA=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改了 VIP 价格的计算逻辑,移除了条件判断 - 更新了用户角色验证的错误提示信息 - 优化了订单创建流程中的异常处理 --- app/admin/logic/beforehand_order/BeforehandOrderLogic.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php index d9bef6369..e707297b9 100644 --- a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php +++ b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php @@ -411,7 +411,7 @@ class BeforehandOrderLogic extends BaseLogic 'admin_id' => $admin_id, 'total_price' => $arr['total_price'], 'price' => $arr['price'], - 'vip_price' => $price==0?$arr['price']:$price, + 'vip_price' => $price, 'purchase' => $arr['purchase'], 'oid' => $res['id'], 'code' => $res['code'], @@ -870,10 +870,10 @@ class BeforehandOrderLogic extends BaseLogic if($order['uid']>0){ $user_ship = User::where('id', $order['uid'])->value('user_ship'); if($user_ship==0){ - throw new BusinessException('用户id不能为0'); + throw new BusinessException('用户角色id不能为0'); } }else{ - throw new BusinessException('用户id不能为0'); + throw new BusinessException('该订单没选择会员用户'); } $total_price = 0; $pay_price = 0; From c82b6ade42c6424ec21492dde23520423d065b83 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 4 Jan 2025 12:09:11 +0800 Subject: [PATCH 2/5] =?UTF-8?q?refactor(exception):=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除自定义 MyBusinessException 类 - 统一使用 support\exception\BusinessException - 在 ExceptionHandler 中增加日志记录 - 更新相关文件中的异常处理逻辑 --- app/ExceptionHandler.php | 5 +++++ app/MyBusinessException.php | 20 ------------------- app/admin/validate/LoginValidate.php | 1 - app/api/lists/store/SystemStoreLists.php | 3 +-- app/store/logic/LoginLogic.php | 2 -- .../StoreBranchProductLogic.php | 1 - 6 files changed, 6 insertions(+), 26 deletions(-) delete mode 100644 app/MyBusinessException.php diff --git a/app/ExceptionHandler.php b/app/ExceptionHandler.php index 483b9d6bb..0ba7badc3 100644 --- a/app/ExceptionHandler.php +++ b/app/ExceptionHandler.php @@ -7,6 +7,7 @@ use Next\VarDumper\Dumper; use Next\VarDumper\DumperHandler; use support\exception\BusinessException; use support\exception\Handler; +use support\Log; use Throwable; use Webman\Http\Request; use Webman\Http\Response; @@ -22,6 +23,7 @@ class ExceptionHandler extends Handler return \response(self::convertToHtml($exception)); }elseif ($exception instanceof BusinessException) { if ($request->expectsJson()) { + Log::error('BusinessException:',['msg'=>$exception->getMessage(),'file'=>$exception->getFile(),'line'=>$exception->getLine()]); return json(['code' => 0, 'msg' => $exception->getMessage(),'show'=>1]); } return response($exception->getMessage()); @@ -35,9 +37,12 @@ class ExceptionHandler extends Handler $error['file'] = $exception->getFile(); $error['line'] = $exception->getLine(); } + Log::error('Exception:',['msg'=>$exception->getMessage(),'file'=>$exception->getFile(),'line'=>$exception->getLine()]); return response(json_encode($error, JSON_UNESCAPED_UNICODE)); } // 非json请求则返回一个页面 + Log::error('other:',['msg'=>$exception->getMessage(),'file'=>$exception->getFile(),'line'=>$exception->getLine()]); + return new Response(200, [], 'msg:'.$exception->getMessage().'。line:'.$exception->getLine().'。file:'.$exception->getFile()); } } diff --git a/app/MyBusinessException.php b/app/MyBusinessException.php deleted file mode 100644 index bebfa4e05..000000000 --- a/app/MyBusinessException.php +++ /dev/null @@ -1,20 +0,0 @@ -expectsJson()) { - return json(['code' => $this->getCode() ?: 500, 'msg' => $this->getMessage(),'show'=>1]); - } - // 非json请求则返回一个页面 - return new Response(200, [], $this->getMessage()); - } -} \ No newline at end of file diff --git a/app/admin/validate/LoginValidate.php b/app/admin/validate/LoginValidate.php index 02dac88a3..5b39f4489 100644 --- a/app/admin/validate/LoginValidate.php +++ b/app/admin/validate/LoginValidate.php @@ -9,7 +9,6 @@ use app\common\enum\AdminTerminalEnum; use app\common\model\auth\Admin; use app\common\service\ConfigService; use app\common\validate\BaseValidate; -use app\MyBusinessException; use support\exception\BusinessException; use Webman\Config; diff --git a/app/api/lists/store/SystemStoreLists.php b/app/api/lists/store/SystemStoreLists.php index a45511f34..b48eaae63 100644 --- a/app/api/lists/store/SystemStoreLists.php +++ b/app/api/lists/store/SystemStoreLists.php @@ -9,8 +9,7 @@ use app\common\model\order\Cart; use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\system_store\SystemStore; use app\common\lists\ListsSearchInterface; -use app\MyBusinessException; -use think\Exception; + /** diff --git a/app/store/logic/LoginLogic.php b/app/store/logic/LoginLogic.php index 453a991c1..adec25c4f 100644 --- a/app/store/logic/LoginLogic.php +++ b/app/store/logic/LoginLogic.php @@ -20,8 +20,6 @@ use app\common\model\system_store\SystemStoreStaff; use app\store\service\AdminTokenService; use app\common\model\auth\AdminRole; use app\common\service\FileService; -use app\MyBusinessException; -use think\facade\Db; use Webman\Config; /** diff --git a/app/store/logic/store_branch_product/StoreBranchProductLogic.php b/app/store/logic/store_branch_product/StoreBranchProductLogic.php index 7837ac1b5..9b1bce6c7 100644 --- a/app/store/logic/store_branch_product/StoreBranchProductLogic.php +++ b/app/store/logic/store_branch_product/StoreBranchProductLogic.php @@ -9,7 +9,6 @@ use app\common\model\store_product\StoreProduct; use app\common\logic\BaseLogic; use app\common\model\store_category\StoreCategory; use app\common\model\store_product_attr_value\StoreProductAttrValue; -use app\MyBusinessException; use support\exception\BusinessException; use think\facade\Db; From 1504af08922452094b82109b9995b9f8d6b77a5e Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 4 Jan 2025 12:16:31 +0800 Subject: [PATCH 3/5] =?UTF-8?q?fix(admin):=20=E4=BF=AE=E5=A4=8D=E5=BA=93?= =?UTF-8?q?=E5=AD=98=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 SqlChannelLog 函数的第二个参数从 $branch_product['id'] 修改为 $storeBranchProduct['id'],以确保记录正确的商品 ID - 此修改解决了库存日志中商品 ID 不正确的问题,保证了日志数据的准确性 --- .../logic/system_store_storage/SystemStoreStorageLogic.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php b/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php index 0a9208d50..474af6944 100644 --- a/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php +++ b/app/admin/logic/system_store_storage/SystemStoreStorageLogic.php @@ -76,7 +76,7 @@ class SystemStoreStorageLogic extends BaseLogic $storeBranchProduct = StoreProductLogic::ordinary(['id' => $find['product_id']], $find['store_id'], 0, $storeProduct); $storeBranchProduct->stock = $find['nums']; $storeBranchProduct->save(); - SqlChannelLog('StoreBranchProduct', $branch_product['id'], $find['nums'], 1,Request()->url()); + SqlChannelLog('StoreBranchProduct', $storeBranchProduct['id'], $find['nums'], 1,Request()->url()); } }else{ $find->save(['status'=>1,'staff_id'=>$params['staff_id']??0,'admin_id'=>$params['admin_id']??0,'mark'=>'确认时间:'.date('Y-m-d H:i:s',time())]); From 24cd3ef82829dc16a746ba7e5367825559f68fb2 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 4 Jan 2025 12:40:13 +0800 Subject: [PATCH 4/5] =?UTF-8?q?feat(model):=20=E6=B7=BB=E5=8A=A0=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E5=BF=BD=E7=95=A5=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 StoreBranchProduct、WarehouseProduct 和 WarehouseProductStorege 模型中添加 $ignoreLogFields 属性 - 设置需要忽略日志记录的字段列表,以保护敏感信息和减少不必要的日志数据 --- .../StoreBranchProduct.php | 29 ++++++++++++++++++- .../warehouse_product/WarehouseProduct.php | 29 ++++++++++++++++++- .../WarehouseProductStorege.php | 6 +++- 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/app/common/model/store_branch_product/StoreBranchProduct.php b/app/common/model/store_branch_product/StoreBranchProduct.php index 494edb295..4f782f0f0 100644 --- a/app/common/model/store_branch_product/StoreBranchProduct.php +++ b/app/common/model/store_branch_product/StoreBranchProduct.php @@ -21,7 +21,34 @@ class StoreBranchProduct extends BaseModel use SoftDelete; protected $name = 'store_branch_product'; protected $deleteTime = 'delete_time'; - + public $ignoreLogFields = [ + 'top_cate_id', + 'two_cate_id', + 'cate_id', + 'store_name', + 'image', + 'price', + 'vip_price', + 'cost', + 'purchase', + 'total_price', + 'store_info', + 'keyword', + 'bar_code', + 'rose', + 'status', + 'product_type', + 'unit', + 'batch', + 'store_batch', + 'sort', + 'label_id', + 'is_lack', + 'manufacturer_information', + 'status', + 'create_time', + 'update_time', + ]; public function unitName() diff --git a/app/common/model/warehouse_product/WarehouseProduct.php b/app/common/model/warehouse_product/WarehouseProduct.php index fb086e088..451a42768 100644 --- a/app/common/model/warehouse_product/WarehouseProduct.php +++ b/app/common/model/warehouse_product/WarehouseProduct.php @@ -18,7 +18,34 @@ class WarehouseProduct extends BaseModel use SoftDelete; protected $name = 'warehouse_product'; protected $deleteTime = 'delete_time'; - + public $ignoreLogFields = [ + 'price', + 'total_price', + 'status', + 'pay_type', + 'is_pay', + 'vip_price', + 'cost', + 'purchase', + 'total_price', + 'mark', + 'after_nums', + 'before_nums', + 'batch', + 'enter_admin_id', + 'admin_id', + 'financial_pm', + 'expiration_date', + 'manufacture', + 'code', + 'oid', + 'unit', + 'store_id', + 'supplier_id', + 'warehouse_id', + 'create_time', + 'update_time', + ]; public static function onBeforeWrite($data) { try { diff --git a/app/common/model/warehouse_product_storege/WarehouseProductStorege.php b/app/common/model/warehouse_product_storege/WarehouseProductStorege.php index 172b611f8..4dfe1a65f 100644 --- a/app/common/model/warehouse_product_storege/WarehouseProductStorege.php +++ b/app/common/model/warehouse_product_storege/WarehouseProductStorege.php @@ -18,7 +18,11 @@ class WarehouseProductStorege extends BaseModel use SoftDelete; protected $name = 'warehouse_product_storege'; protected $deleteTime = 'delete_time'; - + public $ignoreLogFields = [ + 'price', + 'total_price', + 'update_time', + ]; public static function onBeforeWrite($data) { try { From cbbd75cf60d6633cfa0b67e2b4fdeaa10ed00a3e Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 4 Jan 2025 15:08:29 +0800 Subject: [PATCH 5/5] =?UTF-8?q?fix(warehouse):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=BB=93=E5=BA=93=E8=B0=83=E6=8B=A8=E5=BA=93=E5=AD=98=E6=95=B0?= =?UTF-8?q?=E9=87=8F=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改 decStock 和 incStock 方法,使用 bcsub 和 bcadd 函数进行精确计算 - 从数据库中获取对象后再更新,以确保操作的原子性和准确性 - 优化 SqlChannelLog 调用,使用正确的参数记录日志 --- .../WarehouseProductLogic.php | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/app/admin/logic/warehouse_product/WarehouseProductLogic.php b/app/admin/logic/warehouse_product/WarehouseProductLogic.php index 3fd3e1bdf..29ee35a5d 100644 --- a/app/admin/logic/warehouse_product/WarehouseProductLogic.php +++ b/app/admin/logic/warehouse_product/WarehouseProductLogic.php @@ -346,31 +346,28 @@ class WarehouseProductLogic extends BaseLogic //减少 private static function decStock($res) { - $res = WarehouseProductStorege::where('warehouse_id', $res['warehouse_id']) - ->where('product_id', $res['product_id']) - ->dec('nums', $res['nums']) - ->save(); - SqlChannelLog('WarehouseProductStorege', $res['id'], $res['nums'], -1, Request()->url()); + $res1 = WarehouseProductStorege::where('warehouse_id', $res['warehouse_id']) + ->where('product_id', $res['product_id'])->find(); + $res1->save(['nums'=>bcsub($res1['nums'], $res['nums'],2)]); + SqlChannelLog('WarehouseProductStorege', $res1['id'], $res['nums'], -1, Request()->url()); - $res2 = StoreBranchProduct::where('id', $res['id']) - ->dec('stock', $res['nums']) - ->update(); + $res2 = StoreBranchProduct::where('id', $res['id'])->find(); + $res2->save(['stock'=>bcsub($res2['stock'], $res['nums'],2)]); SqlChannelLog('StoreBranchProduct', $res2['id'], $res['nums'], -1, Request()->url()); } //增加 private static function incStock($res, $params) { - $res = WarehouseProductStorege::where('warehouse_id', $res['warehouse_id']) + $res1 = WarehouseProductStorege::where('warehouse_id', $res['warehouse_id']) ->where('product_id', $res['product_id']) - ->inc('nums', $params['nums']) - ->save(); - SqlChannelLog('WarehouseProductStorege', $res['id'], $res['nums'], 1, Request()->url()); + ->find(); + $res1->save(['nums'=>bcadd($res1['nums'], $params['nums'],2)]); + + SqlChannelLog('WarehouseProductStorege', $res1['id'], $res['nums'], 1, Request()->url()); - - $res2 = StoreBranchProduct::where('id', $res['id']) - ->inc('stock', $params['nums']) - ->save(); + $res2 = StoreBranchProduct::where('id', $res['id'])->find(); + $res2->save(['stock'=>bcadd($res2['stock'], $params['nums'],2)]); SqlChannelLog('StoreBranchProduct', $res2['id'], $res['nums'], 1, Request()->url()); } }