Browse Source

修改一些文字和提现的异常跑出逻辑

master
weigang 5 years ago
parent
commit
f85df0373e
  1. 20
      app/Constants/v3/ErrorCode.php
  2. 6
      app/Controller/v3/WithdrawController.php
  3. 9
      app/Service/v3/Implementations/CouponService.php
  4. 20
      app/Service/v3/Implementations/OrderOnlineService.php
  5. 25
      app/Service/v3/Implementations/PaymentService.php

20
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;

6
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());
}
}

9
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);
}
}

20
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());
}
}

25
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;

Loading…
Cancel
Save