8000 Dev by Qsnh · Pull Request #91 · Qsnh/meedu · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Dev #91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 1, 2020
Merged

Dev #91

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

8000
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions app/Constant/ApiV2Constant.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,22 @@ class ApiV2Constant
];
const MODEL_ORDER_FIELD = [
'user_id', 'charge', 'order_id', 'payment_method', 'status_text', 'payment_text', 'continue_pay',
'goods', 'created_at',
];
/**
* @OpenApi\Annotations\Schemas(
* @OA\Schema(
* schema="OrderGoods",
* type="object",
* title="订单商品",
* @OA\Property(property="num",type="integer",description="订购数量"),
* @OA\Property(property="goods_text",type="integer",description="商品名"),
* @OA\Property(property="charge",type="string",description="价格"),
* @OA\Property(property="goods_type",type="string",description="商品类型"),
* ),
* )
*/
const MODEL_ORDER_GOODS_FIELD = [
'num', 'goods_text', 'charge', 'goods_type',
];
}
17 changes: 6 additions & 11 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
use App\Constant\ApiV2Constant;
use App\Constant\BackendApiConstant;
use Illuminate\Auth\AuthenticationException;
use App\Http\Controllers\Frontend\Traits\JsonResponseTrait;
use App\Http\Controllers\Api\V2\Traits\ResponseTrait;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

class Handler extends ExceptionHandler
{
use JsonResponseTrait;
use ResponseTrait;

/**
* A list of the exception types that are not reported.
Expand All @@ -44,11 +44,9 @@ class Handler extends ExceptionHandler
];

/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $exception
* @param Exception $exception
* @return mixed|void
* @throws Exception
*/
public function report(Exception $exception)
{
Expand Down Expand Up @@ -80,10 +78,7 @@ public function render($request, Exception $exception)
if (Str::contains($request->getUri(), '/api/v2')) {
$code = ApiV2Constant::ERROR_CODE;
$exception instanceof AuthenticationException && $code = ApiV2Constant::ERROR_NO_AUTH_CODE;
return response()->json([
'code' => $code,
'message' => __('error'),
]);
return $this->error(__('error'), $code);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions app/Exceptions/ServiceException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@

namespace App\Exceptions;

use App\Http\Controllers\Frontend\Traits\JsonResponseTrait;
use App\Http\Controllers\Api\V2\Traits\ResponseTrait;

class ServiceException extends \Exception
{
use JsonResponseTrait;
use ResponseTrait;

public function render()
{
$message = $this->getMessage();
if (request()->wantsJson()) {
return $this->jsonError($message);
return $this->error($message);
}
flash($message);

Expand Down
7 changes: 7 additions & 0 deletions app/Exceptions/SystemException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@

namespace App\Exceptions;

use App\Http\Controllers\Api\V2\Traits\ResponseTrait;

class SystemException extends \Exception
{
use ResponseTrait;

public function render()
{
if (request()->wantsJson()) {
return $this->error(__('error'));
}
abort(500, $this->getMessage());
}
}
3 changes: 2 additions & 1 deletion app/Http/Controllers/Api/V2/CaptchaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ public function imageCaptcha(Captcha $captcha)
* tags={"其它&quo AE88 t;},
* @OA\RequestBody(description="",@OA\JsonContent(
* @OA\Property(property="mobile",description="手机号",type="string"),
* @OA\Property(property="mobile_code",description="手机验证码",type="string"),
* @OA\Property(property="image_captcha",description="图形验证码",type="string"),
* @OA\Property(property="image_key",description="图形验证码key",type="string"),
* @OA\Property(property="scene",description="scene[login:登录,register:注册,password_reset:密码重置]",type="string"),
* )),
* @OA\Response(
Expand Down
5 changes: 5 additions & 0 deletions app/Http/Controllers/Api/V2/MemberController.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
* @OA\Property(property="payment_text",type="string",description="支付渠道"),
* @OA\Property(property="payment_method",type="string",description="支付渠道的支付方式"),
* @OA\Property(property="continue_pay",type="integer",description="是否可以继续支付"),
* @OA\Property(property="created_at",type="string",description="时间"),
* @OA\Property(property="goods",type="array",description="订单商品",@OA\Items(ref="#/components/schemas/OrderGoods")),
* ),
* @OA\Schema(
* schema="UserInviteBalanceRecord",
Expand Down Expand Up @@ -440,6 +442,9 @@ public function orders(Request $request)
'list' => $list,
] = $this->orderService->userOrdersPaginate($page, $pageSize);
$list = arr2_clear($list, ApiV2Constant::MODEL_ORDER_FIELD);
foreach ($list as $key => $val) {
$list[$key]['goods'] = arr2_clear($val['goods'], ApiV2Constant::MODEL_ORDER_GOODS_FIELD);
}
$orders = $this->paginator($list, $total, $page, $pageSize);

return $this->data($orders);
Expand Down
19 changes: 19 additions & 0 deletions F438 app/Http/Controllers/Backend/Api/V1/MemberController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
namespace App\Http\Controllers\Backend\Api\V1;

use App\User;
use Illuminate\Support\Arr;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use App\Http\Requests\Backend\MemberRequest;
use App\Events\UserInviteBalanceWithdrawHandledEvent;
use App\Services\Member\Models\UserInviteBalanceWithdrawOrder;
Expand Down Expand Up @@ -49,13 +51,15 @@ public function store(MemberRequest $request)
return $this->success();
}

// 用户提现订单
public function inviteBalanceWithdrawOrders(Request $request)
{
$orders = UserInviteBalanceWithdrawOrder::latest()->paginate($request->input('size', 12));
$users = \App\Services\Member\Models\User::whereIn('id', $orders->pluck('user_id'))->get()->keyBy('id');
return $this->successData(compact('orders', 'users'));
}

// 用户提现订单处理
public function inviteBalanceWithdrawOrderHandle(Request $request)
{
$ids = $request->input('ids');
Expand All @@ -68,4 +72,19 @@ public function inviteBalanceWithdrawOrderHandle(Request $request)
event(new UserInviteBalanceWithdrawHandledEvent($ids, $status));
return $this->success();
}

// 用户编辑
public function update(Request $request, $id)
{
$user = User::findOrFail($id);
$data = $request->all();
$data = Arr::only($data, [
'avatar', 'nick_name', 'mobile', 'password',
'is_lock', 'is_active', 'role_id', 'role_expired_at',
'invite_user_id', 'invite_balance', 'invite_user_expired_at',
]);
($data['password'] ?? '') && $data['password'] = Hash::make($data['password']);
$user->fill($data)->save();
return $this->success();
}
}
4 changes: 2 additions & 2 deletions app/Http/Controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

namespace App\Http\Controllers;

use App\Http\Controllers\Frontend\Traits\JsonResponseTrait;
use App\Http\Controllers\Api\V2\Traits\ResponseTrait;

class BaseController extends Controller
{
use JsonResponseTrait;
use ResponseTrait;
}
14 changes: 7 additions & 7 deletions app/Http/Controllers/Frontend/AjaxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function courseCommentHandler(CourseOrVideoCommentCreateRequest $request,
$comment = $this->courseCommentService->create($course['id'], $content);
$user = $this->userService->find(Auth::id(), ['role']);

return $this->jsonSuccess([
return $this->data([
'content' => $comment['render_content'],
'created_at' => Carbon::parse($comment['created_at'])->diffForHumans(),
'user' => [
Expand All @@ -97,7 +97,7 @@ public function videoCommentHandler(CourseOrVideoCommentCreateRequest $request,
$comment = $this->videoCommentService->create($video['id'], $content);
$user = $this->userService->find(Auth::id(), ['role']);

return $this->jsonSuccess([
return $this->data([
'content' => $comment['render_content'],
'created_at' => Carbon::parse($comment['created_at'])->diffForHumans(),
'user' => [
Expand All @@ -116,19 +116,19 @@ public function promoCodeCheck(Request $request)
{
$promoCode = $request->input('promo_code');
if (!$promoCode) {
return $this->jsonError(__('error'));
return $this->error(__('error'));
}
$code = $this->promoCodeService->findCode($promoCode);
if (!$code) {
return $this->jsonError(__('promo code not exists'));
return $this->error(__('promo code not exists'));
}
if ($code['expired_at'] && Carbon::now()->gt($code['expired_at'])) {
return $this->jsonError(__('promo code has expired'));
return $this->error(__('promo code has expired'));
}
if (!$this->businessState->promoCodeCanUse($code)) {
return $this->jsonError(__('user cant use this promo code'));
return $this->error(__('user cant use this promo code'));
}
return $this->jsonSuccess([
return $this->data([
'id' => $code['id'],
'discount' => $code['invited_user_reward'],
]);
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Frontend/SmsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ protected function sendHandler($mobile, $sessionKey, $templateId)

$this->smsService->sendCode($mobile, $code, $templateId);

return $this->jsonSuccess();
return $this->success();
}
}
33 changes: 0 additions & 33 deletions app/Http/Controllers/Frontend/Traits/JsonResponseTrait.php

This file was deleted.

2 changes: 1 addition & 1 deletion app/Http/Controllers/Frontend/UploadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public function imageHandler(UploadImageRequest $request)
{
[$path, $url] = $request->filldata();

return $this->jsonSuccess(compact('path', 'url'));
return $this->data(compact('path', 'url'));
}
}
2 changes: 0 additions & 2 deletions app/Http/Requests/ApiV2/SmsRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public function rules()
];
return [
'mobile' => 'required',
'mobile_code' => 'required',
'image_captcha' => 'required',
'image_key' => 'required',
'scene' => 'in:' . implode(',', $scenes),
Expand All @@ -31,7 +30,6 @@ public function messages()
{
return [
'mobile.required' => __('mobile.required'),
'mobile_code.required' => __('mobile_code.required'),
'image_captcha.required' => __('image_captcha.required'),
'image_key.required' => __('image_key.required'),
'scene.in' => __('sms_scene_error'),
Expand Down
4 changes: 2 additions & 2 deletions app/Meedu/ServiceProxy/ServiceProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ protected function limitHandler($name, $args)
return;
}
/**
* @var LimiterInfo
* @var $limiterInfo LimiterInfo
*/
$limiterInfo = call_user_func_array($this->limit[$name], $args);
/**
* @var RateLimiter
* @var $rateLimiter RateLimiter
*/
$rateLimiter = app()->make(RateLimiter::class);
if ($rateLimiter->tooManyAttempts($limiterInfo->getName(), $limiterInfo->getMaxTimes())) {
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<exclude>
<directory suffix=".php">./app/Models</directory>
<directory suffix=".php">./app/Services/*/Models</directory>
<directory suffix=".php">./app/Http/Controllers/Backend/Api/V1</directory>
<file>./app/User.php</file>
</exclude>
</whitelist>
Expand Down
Loading
0