From dbffca022d1d8134c3584863d2f174a9e2174212 Mon Sep 17 00:00:00 2001 From: gongfuxiang Date: Wed, 22 Mar 2023 12:06:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E9=94=99=E8=AF=AF=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E5=97=AF=E5=93=BC=E8=B4=AD=E7=89=A9=E8=BD=A6=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E5=88=A4=E6=96=AD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/service/GoodsCartService.php | 12 ++++- app/service/GoodsService.php | 78 ++++++++++++++++++-------------- 2 files changed, 55 insertions(+), 35 deletions(-) diff --git a/app/service/GoodsCartService.php b/app/service/GoodsCartService.php index 7ed6c7bbf..d4bfc6d0a 100644 --- a/app/service/GoodsCartService.php +++ b/app/service/GoodsCartService.php @@ -117,11 +117,21 @@ class GoodsCartService $v['buy_max_number'] = ($v['buy_max_number'] <= 0) ? $v['inventory']: $v['buy_max_number']; // 错误处理 - if(empty($v['error_msg']) && $v['is_invalid'] == 1) + if(!isset($v['is_error']) || $v['is_error'] == 0) + { + $v['is_error'] = 0; + $v['error_msg'] = ''; + } + if($v['is_error'] == 0 && $v['is_invalid'] == 1) { $v['is_error'] = 1; $v['error_msg'] = MyLang('goods_already_invalid_title'); } + if($v['is_error'] == 0 && $v['inventory'] <= 0) + { + $v['is_error'] = 1; + $v['error_msg'] = MyLang('goods_no_inventory_title'); + } } } return DataReturn(MyLang('operate_success'), 0, $data); diff --git a/app/service/GoodsService.php b/app/service/GoodsService.php index 4b3d892dc..cd6f083be 100755 --- a/app/service/GoodsService.php +++ b/app/service/GoodsService.php @@ -525,40 +525,6 @@ class GoodsService $v['user_cart_count'] = (!empty($user_cart) && array_key_exists($data_id, $user_cart)) ? $user_cart[$data_id] : 0; } - // 错误处理 - if(!isset($v['is_error']) || $v['is_error'] == 0) - { - $v['is_error'] = 0; - $v['error_msg'] = ''; - } - if($v['is_error'] == 0 && array_key_exists('is_delete_time', $v) && $v['is_delete_time'] != 0) - { - $v['is_error'] = 1; - $v['error_msg'] = MyLang('goods_already_nullify_title'); - } - // 是否上架 - if($v['is_error'] == 0 && array_key_exists('is_shelves', $v) && $v['is_shelves'] != 1) - { - $v['is_error'] = 1; - $v['error_msg'] = MyLang('goods_already_shelves_title'); - } - // 是否有库存 - if($v['is_error'] == 0 && array_key_exists('inventory', $v) && $v['inventory'] <= 0) - { - $v['is_error'] = 1; - $v['error_msg'] = MyLang('goods_no_inventory_title'); - } - // 没错误则判断类型是否一致 - if($v['is_error'] == 0 && array_key_exists('site_type', $v) && !empty($data_id)) - { - $ret = self::IsGoodsSiteTypeConsistent($data_id, $v['site_type']); - if($ret['code'] != 0) - { - $v['is_error'] = 1; - $v['error_msg'] = $ret['msg']; - } - } - // 价格字段 // 原价 // 价格 @@ -608,6 +574,50 @@ class GoodsService 'params' => &$params, 'data' => &$data, ]); + + // 错误处理 + if(!empty($data) & is_array($data)) + { + foreach($data as &$gv) + { + // 数据主键id + $data_id = isset($v[$data_key_field]) ? $v[$data_key_field] : 0; + + // 错误处理 + if(!isset($gv['is_error']) || $gv['is_error'] == 0) + { + $gv['is_error'] = 0; + $gv['error_msg'] = ''; + } + if($gv['is_error'] == 0 && array_key_exists('is_delete_time', $gv) && $gv['is_delete_time'] != 0) + { + $gv['is_error'] = 1; + $gv['error_msg'] = MyLang('goods_already_nullify_title'); + } + // 是否上架 + if($gv['is_error'] == 0 && array_key_exists('is_shelves', $gv) && $gv['is_shelves'] != 1) + { + $gv['is_error'] = 1; + $gv['error_msg'] = MyLang('goods_already_shelves_title'); + } + // 是否有库存 + if($gv['is_error'] == 0 && array_key_exists('inventory', $gv) && $gv['inventory'] <= 0) + { + $gv['is_error'] = 1; + $gv['error_msg'] = MyLang('goods_no_inventory_title'); + } + // 没错误则判断类型是否一致 + if($gv['is_error'] == 0 && array_key_exists('site_type', $gv) && !empty($data_id)) + { + $ret = self::IsGoodsSiteTypeConsistent($data_id, $gv['site_type']); + if($ret['code'] != 0) + { + $gv['is_error'] = 1; + $gv['error_msg'] = $ret['msg']; + } + } + } + } } return DataReturn('success', 0, $data); }