Browse Source

写一些日志

master
weigang 5 years ago
parent
commit
2f7b965c84
  1. 5
      app/Constants/v3/LogLabel.php
  2. 6
      app/Controller/v3/CommunityController.php
  3. 2
      app/Controller/v3/OrderOfflineController.php
  4. 6
      app/Controller/v3/WithdrawController.php
  5. 16
      app/Exception/ErrorCodeException.php
  6. 2
      app/Service/v3/Implementations/AppointmentTimeService.php
  7. 14
      app/Service/v3/Implementations/CouponService.php
  8. 2
      app/Service/v3/Implementations/DistributionPriceService.php
  9. 2
      app/Service/v3/Implementations/VerifyCodeService.php
  10. 2
      app/Service/v3/Implementations/WxLoginService.php

5
app/Constants/v3/LogLabel.php

@ -17,6 +17,11 @@ class LogLabel extends AbstractConstants
*/ */
const ERROR_CODE_EXCEPTION = 'error_code_exception_log'; const ERROR_CODE_EXCEPTION = 'error_code_exception_log';
/**
* @Message("ErrorCode异常抛出")
*/
const ERROR_CODE_EXCEPTION_LOG_DATA = 'error_code_exception_log_data';
/** /**
* @Message("线上订单") * @Message("线上订单")
*/ */

6
app/Controller/v3/CommunityController.php

@ -19,9 +19,11 @@ class CommunityController extends BaseController
*/ */
protected $userCommunityService; protected $userCommunityService;
public function bind(CommunityBindRequest $request)
// public function bind(CommunityBindRequest $request)
public function bind()
{ {
$data = $request->validated();
// $data = $request->validated();
$data = $this->request->all();
$jsonData = $data['json_data'] ?? json_encode([]); $jsonData = $data['json_data'] ?? json_encode([]);
$res = $this->userCommunityService->bind(UserRelationBind::BIND_TYPE_COMMUNITY, $data['source_id'], $data['user_id'], $jsonData); $res = $this->userCommunityService->bind(UserRelationBind::BIND_TYPE_COMMUNITY, $data['source_id'], $data['user_id'], $jsonData);
return $this->success(['id' => $res->id]); return $this->success(['id' => $res->id]);

2
app/Controller/v3/OrderOfflineController.php

@ -82,7 +82,7 @@ class OrderOfflineController extends BaseController
->first(); ->first();
if (empty($orderMain)) { if (empty($orderMain)) {
throw new ErrorCodeException(ErrorCode::ORDER_NOT_AVAILABLE);
throw new ErrorCodeException(ErrorCode::ORDER_NOT_AVAILABLE, '', ['message' => '当面付订单完成页', 'data' => ['global_order_id' => $globalOrderId,'user_id' => $userId]]);
} }
return $this->success(['order_main' => $orderMain]); return $this->success(['order_main' => $orderMain]);

6
app/Controller/v3/WithdrawController.php

@ -69,7 +69,7 @@ class WithdrawController extends BaseController
$store = Store::query()->where(['user_id' => $userId, 'id' => $storeId])->first(); $store = Store::query()->where(['user_id' => $userId, 'id' => $storeId])->first();
if (empty($store)) { if (empty($store)) {
$msg = ['user_id' => $userId, 'storeId' => $storeId]; $msg = ['user_id' => $userId, 'storeId' => $storeId];
throw new ErrorCodeException(ErrorCode::STORE_NOT_AVAILABLE,json_encode($msg));
throw new ErrorCodeException(ErrorCode::STORE_NOT_AVAILABLE,'',$msg);
} }
$data['balance'] = UserBalance::query() $data['balance'] = UserBalance::query()
@ -130,7 +130,7 @@ class WithdrawController extends BaseController
$store = Store::query()->where(['user_id' => $userId, 'id' => $storeId])->first(); $store = Store::query()->where(['user_id' => $userId, 'id' => $storeId])->first();
if (empty($store)) { if (empty($store)) {
$msg = ['user_id' => $userId, 'storeId' => $storeId]; $msg = ['user_id' => $userId, 'storeId' => $storeId];
throw new ErrorCodeException(ErrorCode::STORE_NOT_AVAILABLE, '[稍后重试]' . json_encode($msg));
throw new ErrorCodeException(ErrorCode::STORE_NOT_AVAILABLE, '' , $msg);
} }
// 校验余额 // 校验余额
@ -138,7 +138,7 @@ class WithdrawController extends BaseController
->where(['source_id' => $store->user_id, 'user_type' => UserType::STORE]) ->where(['source_id' => $store->user_id, 'user_type' => UserType::STORE])
->first(); ->first();
if ($money > $balance->balance) { if ($money > $balance->balance) {
throw new ErrorCodeException(ErrorCode::STORE_WITHDRAW_INSUFFICIENT_BALANCE);
throw new ErrorCodeException(ErrorCode::STORE_WITHDRAW_INSUFFICIENT_BALANCE, '', ['message' => '商户提现余额不足','data' => ['money' => $money, 'balance' => $balance->balance]]);
} }
Db::beginTransaction(); Db::beginTransaction();

16
app/Exception/ErrorCodeException.php

@ -11,15 +11,29 @@ declare(strict_types=1);
*/ */
namespace App\Exception; namespace App\Exception;
use App\Commons\Log;
use App\Constants\v3\ErrorCode; use App\Constants\v3\ErrorCode;
use App\Constants\v3\LogLabel;
use Hyperf\Server\Exception\ServerException; use Hyperf\Server\Exception\ServerException;
use Throwable; use Throwable;
use Hyperf\Di\Annotation\Inject;
class ErrorCodeException extends ServerException class ErrorCodeException extends ServerException
{ {
public function __construct(int $code = 0, string $message = null, Throwable $previous = null)
/**
* @Inject
* @var Log
*/
protected $log;
public function __construct(int $code = 0, string $message = null, $logData=[], Throwable $previous = null)
{ {
if (!empty($logData)) {
$this->log->event(LogLabel::ERROR_CODE_EXCEPTION_LOG_DATA, ['logData' => json_encode($logData)]);
}
if (is_null($message)) { if (is_null($message)) {
$message = ErrorCode::getMessage($code); $message = ErrorCode::getMessage($code);
} else { } else {

2
app/Service/v3/Implementations/AppointmentTimeService.php

@ -39,7 +39,7 @@ class AppointmentTimeService implements AppointmentTimeServiceInterface
$stores = Store::query()->whereIn('id',$sotreIds)->get()->toArray(); $stores = Store::query()->whereIn('id',$sotreIds)->get()->toArray();
if(empty($stores)){ if(empty($stores)){
$msg = ['sotreIds'=>$sotreIds,"shopcartIds"=>$shopcartIds]; $msg = ['sotreIds'=>$sotreIds,"shopcartIds"=>$shopcartIds];
throw new ErrorCodeException(ErrorCode::STORE_NOT_AVAILABLE,json_encode($msg));
throw new ErrorCodeException(ErrorCode::STORE_NOT_AVAILABLE,'',$msg);
} }
$time1Arr = []; $time1Arr = [];
$time2Arr = []; $time2Arr = [];

14
app/Service/v3/Implementations/CouponService.php

@ -97,7 +97,7 @@ class CouponService implements CouponServiceInterface
->update(['number_remain' => $numberRemain, 'status' => $status]); ->update(['number_remain' => $numberRemain, 'status' => $status]);
if (!$upRes) { if (!$upRes) {
Db::rollBack(); Db::rollBack();
throw new ErrorCodeException(ErrorCode::COUPON_USE_FAILURE, '更新优惠券数量失败');
throw new ErrorCodeException(ErrorCode::COUPON_USE_FAILURE, '更新优惠券数量失败', ['id' => $coupon['id'],'number_remain' => $numberRemain, 'status' => $status]);
} }
// 缓存使用记录 // 缓存使用记录
$usedRes = $this->cacheTodayCouponUsed($coupon['user_id'], $coupon['coupon_id'], $coupon['id']); $usedRes = $this->cacheTodayCouponUsed($coupon['user_id'], $coupon['coupon_id'], $coupon['id']);
@ -107,7 +107,17 @@ class CouponService implements CouponServiceInterface
} }
} else { } else {
Db::rollBack(); Db::rollBack();
throw new ErrorCodeException(ErrorCode::COUPON_USE_FAILURE, '新增优惠券使用记录到数据库失败');
throw new ErrorCodeException(ErrorCode::COUPON_USE_FAILURE, '新增优惠券使用记录到数据库失败', [
'user_id' => $coupon['user_id'],
'user_receive_id' => $coupon['id'],
'coupon_id' => $coupon['coupon_id'],
'order_main_id' => $globalOrderId,
'use_time' => time(),
'return_time' => 0,
'number' => 1,
'status' => 1,
'update_time' => 0,
]);
} }
} }

2
app/Service/v3/Implementations/DistributionPriceService.php

@ -27,7 +27,7 @@ class DistributionPriceService implements DistributionPriceServiceInterface
$distributionPrice = bcmul(1.50,($km-3),2); $distributionPrice = bcmul(1.50,($km-3),2);
break; break;
case ($km > $deliveryDistance) : case ($km > $deliveryDistance) :
throw new ErrorCodeException(ErrorCode::LOCATION_LONG_DISTANCE);
throw new ErrorCodeException(ErrorCode::LOCATION_LONG_DISTANCE,'',['message' => '超出配送范围', 'data' => ['距离' => $km, '配送距离' => $deliveryDistance]]);
break; break;
default: default:
$distributionPrice = 0; $distributionPrice = 0;

2
app/Service/v3/Implementations/VerifyCodeService.php

@ -49,7 +49,7 @@ class VerifyCodeService implements VerifyCodeServiceInterface
600 600
); );
if (!$expireRes) { if (!$expireRes) {
throw new ErrorCodeException(ErrorCode::VERIFY_CODE_ERROR);
throw new ErrorCodeException(ErrorCode::VERIFY_CODE_ERROR, '', ['message' => '验证码有效期设置失败', 'data' => ['ssdbkey' => SsdbKeys::VERIFY_CODE.$userId.'_'.$tel]]);
} }
// 发送短信 // 发送短信

2
app/Service/v3/Implementations/WxLoginService.php

@ -25,7 +25,7 @@ class WxLoginService implements \App\Service\v3\Interfaces\WxLoginServiceInterfa
$result = $app->auth->session($code); $result = $app->auth->session($code);
if (isset($result['errcode'])&&$result['errcode'] != 0) { if (isset($result['errcode'])&&$result['errcode'] != 0) {
throw new ErrorCodeException(ErrorCode::WXLOGIN_INVALID_CODE);
throw new ErrorCodeException(ErrorCode::WXLOGIN_INVALID_CODE, '', ['message' => '微信登录失败', 'data' => $result, 'code' => $code]);
} }
// 更新或者插入用户数据 // 更新或者插入用户数据

Loading…
Cancel
Save