From f85df0373ec2838b121f152b4f492b044eae9c64 Mon Sep 17 00:00:00 2001 From: weigang Date: Sun, 13 Sep 2020 11:46:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=80=E4=BA=9B=E6=96=87?= =?UTF-8?q?=E5=AD=97=E5=92=8C=E6=8F=90=E7=8E=B0=E7=9A=84=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E8=B7=91=E5=87=BA=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Constants/v3/ErrorCode.php | 20 +++++++-------- app/Controller/v3/WithdrawController.php | 6 ++--- .../v3/Implementations/CouponService.php | 9 ++++--- .../v3/Implementations/OrderOnlineService.php | 20 +++++++++------ .../v3/Implementations/PaymentService.php | 25 ++++++++++++------- 5 files changed, 47 insertions(+), 33 deletions(-) diff --git a/app/Constants/v3/ErrorCode.php b/app/Constants/v3/ErrorCode.php index 99e64b2..a7beedb 100644 --- a/app/Constants/v3/ErrorCode.php +++ b/app/Constants/v3/ErrorCode.php @@ -152,7 +152,7 @@ class ErrorCode extends AbstractConstants /** * 商户已休息 - * @Message("当前商户已歇业") + * @Message("该商户已歇业") */ const STORE_REST = 709; @@ -192,7 +192,7 @@ class ErrorCode extends AbstractConstants /************************************/ /** * 已卖光 - * @Message("已卖光") + * @Message("该商品已卖光") */ const GOODS_INVENTORY_ERROR = 1101; @@ -204,13 +204,13 @@ class ErrorCode extends AbstractConstants /** * 已下架 - * @Message("商品已下架") + * @Message("商品可能已下架") */ const GOODS_ON_SALE_NO = 1103; /** * 已下架 - * @Message("商品不存在") + * @Message("商品可能已下架") */ const GOODS_NOT_EXISTS = 1104; @@ -220,7 +220,7 @@ class ErrorCode extends AbstractConstants /** * 当前特价商品已被购买过 - * @Message("当前特价商品已被购买过") + * @Message("该活动商品您已买过") */ const GOODS_ACTIVITY_BUY = 1151; @@ -232,31 +232,31 @@ class ErrorCode extends AbstractConstants /** * 已卖光 - * @Message("商品已卖光") + * @Message("该商品已卖光") */ const GOODS_ACTIVITY_INVENTORY_ERROR = 1153; /** * 已下架 - * @Message("商品已下架") + * @Message("商品可能已下架") */ const GOODS_ACTIVITY_ON_SALE_NO = 1154; /** * 商品超过限购数量 - * @Message("商品超过限购数量") + * @Message("有活动商品超过限购数量") */ const GOODS_ACTIVITY_RESTRICT_LIMIT = 1155; /** * 订单中部分活动商品不可使用优惠券 - * @Message("有活动商品不可使用优惠券") + * @Message("订单中有不能使用优惠券的商品") */ const GOODS_ACTIVITY_CANNOT_USE_COUPON = 1156; /** * 活动商品不存在 - * @Message("商品不存在") + * @Message("活动商品可能已下架") */ const GOODS_ACTIVITY_NOT_EXISTS = 1156; diff --git a/app/Controller/v3/WithdrawController.php b/app/Controller/v3/WithdrawController.php index 689c4ae..5dce312 100644 --- a/app/Controller/v3/WithdrawController.php +++ b/app/Controller/v3/WithdrawController.php @@ -127,7 +127,7 @@ class WithdrawController extends BaseController $storeId = $this->request->input('store_id'); $store = Store::query()->where(['user_id' => $userId, 'id' => $storeId])->first(); if (empty($store)) { - throw new ErrorCodeException(ErrorCode::STORE_NOT_AVAILABLE); + throw new ErrorCodeException(ErrorCode::STORE_NOT_AVAILABLE, '[稍后重试]'); } // 校验余额 @@ -190,11 +190,11 @@ class WithdrawController extends BaseController } catch (\Exception $e) { Db::rollBack(); $this->log->event(LogLabel::STORE_WITHDRAW_FAIL_LOG, [ - 'exception' => $e->getMessage(), + 'msg' => $e->getMessage(), 'withdraw' => json_encode($withdraw), 'params' => json_encode(['balance' => $balance->balance, 'user_id' => $userId, 'store_id' => $storeId]), ]); - throw new ErrorCodeException(ErrorCode::STORE_WITHDRAW_FAIL); + throw new ErrorCodeException(ErrorCode::STORE_WITHDRAW_FAIL, '[请稍后重试]'.$e->getMessage()); } } diff --git a/app/Service/v3/Implementations/CouponService.php b/app/Service/v3/Implementations/CouponService.php index 8924015..3a84cc1 100644 --- a/app/Service/v3/Implementations/CouponService.php +++ b/app/Service/v3/Implementations/CouponService.php @@ -97,17 +97,17 @@ class CouponService implements CouponServiceInterface ->update(['number_remain' => $numberRemain, 'status' => $status]); if (!$upRes) { Db::rollBack(); - throw new ErrorCodeException(ErrorCode::COUPON_USE_FAILURE); + throw new ErrorCodeException(ErrorCode::COUPON_USE_FAILURE, '更新优惠券数量失败'); } // 缓存使用记录 $usedRes = $this->cacheTodayCouponUsed($coupon['user_id'], $coupon['coupon_id'], $coupon['id']); if (!$usedRes) { Db::rollBack(); - throw new ErrorCodeException(ErrorCode::COUPON_USE_FAILURE); + throw new ErrorCodeException(ErrorCode::COUPON_USE_FAILURE, '缓存优惠券使用记录失败'); } } else { Db::rollBack(); - throw new ErrorCodeException(ErrorCode::COUPON_USE_FAILURE); + throw new ErrorCodeException(ErrorCode::COUPON_USE_FAILURE, '新增优惠券使用记录到数据库失败'); } } @@ -116,7 +116,8 @@ class CouponService implements CouponServiceInterface Db::commit(); } catch (\Exception $e) { Db::rollBack(); - throw new ErrorCodeException(ErrorCode::COUPON_USE_FAILURE, $e->getMessage()); + $this->log->event(LogLabel::ORDER_ONLINE_LOG, ['msg' => '下单时优惠券使用失败'.$e->getMessage(), 'data' => '']); + throw new ErrorCodeException(ErrorCode::COUPON_USE_FAILURE); } } diff --git a/app/Service/v3/Implementations/OrderOnlineService.php b/app/Service/v3/Implementations/OrderOnlineService.php index f6e6af7..71bdaf3 100644 --- a/app/Service/v3/Implementations/OrderOnlineService.php +++ b/app/Service/v3/Implementations/OrderOnlineService.php @@ -130,7 +130,12 @@ class OrderOnlineService implements OrderOnlineServiceInterface $canRealUseCoupons = $couponRecs['available']; $canRealUseCouponRecIds = array_values(array_column($canRealUseCoupons, 'id')); if (!empty(array_diff($receiveCouponIds, $canRealUseCouponRecIds))) { - throw new ErrorCodeException(ErrorCode::GOODS_ACTIVITY_CANNOT_USE_COUPON, '[优惠券不可用]'.$receiveCouponIds.'_'.$canRealUseCouponRecIds); + $this->log->event(LogLabel::ORDER_ONLINE_LOG, ['msg' => '订单中有不能使用优惠券的商品', 'data' => json_encode([ + 'all_user_coupons_rec' => json_encode($couponRecs), + 'can_real_user_coupons' => json_encode($canRealUseCoupons), + 'receive_coupon_ids' => json_encode($canRealUseCouponRecIds), + ])]); + throw new ErrorCodeException(ErrorCode::GOODS_ACTIVITY_CANNOT_USE_COUPON); } // 处理购物车数据,计算订单金额、子订单数据处理等 @@ -168,20 +173,20 @@ class OrderOnlineService implements OrderOnlineServiceInterface if ($cart->activity_type == 1) { $goods = Goods::query()->lockForUpdate()->with('store')->find($cart->goods_id); if (empty($goods)) { - throw new ErrorCodeException(ErrorCode::ORDER_GOODS_NOT_AVAILABLE, '[商品失效1]'.$cart->goods_id); + throw new ErrorCodeException(ErrorCode::GOODS_NOT_EXISTS, '['.$cart->goods_id.']'); } $check = $this->goodsService->check($goods, $cart->num); if (true !== $check) { - throw new ErrorCodeException($check, '[商品失效2]'.$cart->goods_id); + throw new ErrorCodeException($check, '['.$goods->name.'/'.$goods->goods_unit.']'); } } elseif ($cart->activity_type == 2) { $goods = GoodsActivity::query()->lockForUpdate()->with('store')->find($cart->goods_id); if (empty($goods)) { - throw new ErrorCodeException(ErrorCode::ORDER_GOODS_NOT_AVAILABLE, '[商品失效3]'.$cart->goods_id); + throw new ErrorCodeException(ErrorCode::GOODS_ACTIVITY_NOT_EXISTS, '['.$cart->goods_id.']'); } $check = $this->goodsActivityService->check($goods, $cart->num, $userId); if (true !== $check) { - throw new ErrorCodeException($check, '[商品失效4]'.$cart->goods_id); + throw new ErrorCodeException($check, '['.$goods->name.'/'.$goods->goods_unit.']'); } } @@ -306,7 +311,8 @@ class OrderOnlineService implements OrderOnlineServiceInterface // 判断是否有购买多个特价商品 $check = $this->goodsActivityService->checkOrderActivityCount($dataOrderGoods); if(!$check){ - throw new ErrorCodeException(ErrorCode::GOODS_ACTIVITY_RESTRICT_LIMIT, '[同一订单同种类型活动商品]'.json_encode($dataOrderGoods)); + $this->log->event(LogLabel::ORDER_ONLINE_LOG, ['msg' => '订单中有活动商品超过限购数量', 'data' => json_encode($dataOrderGoods)]); + throw new ErrorCodeException(ErrorCode::GOODS_ACTIVITY_RESTRICT_LIMIT); } // 订单成功,做一些处理 @@ -333,7 +339,7 @@ class OrderOnlineService implements OrderOnlineServiceInterface return $this->paymentService->do($globalOrderId, $totalAmount, $userId, config('wechat.notify_url.online')); } catch (Exception $e) { Db::rollBack(); - $this->log->event(LogLabel::ORDER_ONLINE_LOG, ['exception_msg' => $e->getMessage()]); + $this->log->event(LogLabel::ORDER_ONLINE_LOG, ['msg' => $e->getMessage()]); throw new ErrorCodeException(ErrorCode::ORDER_ONLINE_FAIL, $e->getMessage()); } } diff --git a/app/Service/v3/Implementations/PaymentService.php b/app/Service/v3/Implementations/PaymentService.php index f2e37e1..d3fa31d 100644 --- a/app/Service/v3/Implementations/PaymentService.php +++ b/app/Service/v3/Implementations/PaymentService.php @@ -93,7 +93,7 @@ class PaymentService implements PaymentServiceInterface } catch (\Exception $e) { $this->log->event(LogLabel::ORDER_PAYMENT_LOG, ['payment_do_exception_msg' => $e->getMessage()]); - throw new ErrorCodeException(ErrorCode::PAYMENT_FAIL, '[支付失败]'.$e->getMessage()); + throw new ErrorCodeException(ErrorCode::PAYMENT_FAIL, '[稍后重试]'); } } @@ -182,25 +182,32 @@ class PaymentService implements PaymentServiceInterface 'result' => json_encode($result), 'desc' => $desc ]); - throw new ErrorCodeException(ErrorCode::PAYMENT_FAIL, $result['return_msg']); + throw new ErrorCodeException(ErrorCode::PAYMENT_FAIL); } if ($result['result_code'] != 'SUCCESS') { - $this->log->event(LogLabel::PAY_TO_WX_FAIL_LOG, [ - 'exception_payToWx' => $result['err_code_des'], - 'result' => json_encode($result), - 'desc' => $desc - ]); - throw new ErrorCodeException(ErrorCode::PAYMENT_FAIL); // 如果是商户余额不足等原因,要发送短信给老总 - $arr = ['NOTENOUGH','AMOUNT_LIMIT']; + $arr = ['NOTENOUGH','AMOUNT_LIMIT','NO_AUTH']; if (in_array($result['error_code'], $arr)) { $redis = ApplicationContext::getContainer()->get(Redis::class); if (!$redis->exists('send_withdraw_refuse_reson_'.date('Ymd'))) { $this->smsAliSendService->doWithdrawFail($result['error_code'], $result['error_code_des']); } } + + $this->log->event(LogLabel::PAY_TO_WX_FAIL_LOG, [ + 'exception_payToWx' => $result['err_code_des'], + 'result' => json_encode($result), + 'desc' => $desc + ]); + + $arr = ['NAME_MISMATCH','V2_ACCOUNT_SIMPLE_BAN', 'SENDNUM_LIMIT']; + $msg = ''; + if (in_array($result['error_code'], $arr)) { + $msg = $result['error_code_des']; + } + throw new ErrorCodeException(ErrorCode::PAYMENT_FAIL, $msg); } return true;