Skip to content

Commit

Permalink
Merge pull request #115 from Qsnh/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Qsnh authored May 18, 2020
2 parents 17d5d11 + e61f642 commit 4af4c0b
Show file tree
Hide file tree
Showing 35 changed files with 518 additions and 87 deletions.
60 changes: 32 additions & 28 deletions app/Constant/ApiV2Constant.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,26 @@

class ApiV2Constant
{
const PARAMS_ERROR = 'params error';
const PLEASE_INPUT_IMAGE_CAPTCHA = 'image_captcha.required';
const IMAGE_CAPTCHA_ERROR = 'image_captcha_error';
public const YES = 1;

public const PARAMS_ERROR = 'params error';
public const PLEASE_INPUT_IMAGE_CAPTCHA = 'image_captcha.required';
public const IMAGE_CAPTCHA_ERROR = 'image_captcha_error';

const USER_MOBILE_NOT_EXISTS = 'mobile not exists';
const MOBILE_HAS_EXISTS = 'mobile has exists';
const MOBILE_OR_PASSWORD_ERROR = 'mobile not exists or password error';
const MOBILE_CODE_ERROR = 'mobile code error';
public const USER_MOBILE_NOT_EXISTS = 'mobile not exists';
public const MOBILE_HAS_EXISTS = 'mobile has exists';
public const MOBILE_OR_PASSWORD_ERROR = 'mobile not exists or password error';
public const MOBILE_CODE_ERROR = 'mobile code error';

const MEMBER_HAS_LOCKED = 'current user was locked,please contact administrator';
public const MEMBER_HAS_LOCKED = 'current user was locked,please contact administrator';

const VIDEO_NO_AUTH = 'please buy this video before see';
public const VIDEO_NO_AUTH = 'please buy this video before see';

const SMS_CODE_EXPIRE = 60;
const MOBILE_CODE_CACHE_KEY = 'm:%s';
public const SMS_CODE_EXPIRE = 60;
public const MOBILE_CODE_CACHE_KEY = 'm:%s';

const ERROR_CODE = 1;
const ERROR_NO_AUTH_CODE = 401;
public const ERROR_CODE = 1;
public const ERROR_NO_AUTH_CODE = 401;

/**
* @OpenApi\Annotations\Schemas(
Expand All @@ -48,13 +50,15 @@ class ApiV2Constant
* @OA\Property(property="published_at",type="string",description="上线时间"),
* @OA\Property(property="seo_keywords",type="string",description="seo_keywords"),
* @OA\Property(property="seo_description",type="string",description="seo_description"),
* @OA\Property(property="category_id",type="string",description="分类id"),
* @OA\Property(property="category_id",type="integer",description="分类id"),
* @OA\Property(property="is_rec",type="integer",description="推荐"),
* @OA\Property(property="user_count",type="integer",description="订阅人数"),
* )
* )
*/
const MODEL_COURSE_FIELD = [
public const MODEL_COURSE_FIELD = [
'id', 'title', 'slug', 'thumb', 'charge', 'short_description', 'render_desc', 'seo_keywords',
'seo_description', 'published_at', 'category_id',
'seo_description', 'published_at', 'is_rec', 'user_count',
];

/**
Expand All @@ -79,7 +83,7 @@ class ApiV2Constant
* ),
* )
*/
const MODEL_VIDEO_FIELD = [
public const MODEL_VIDEO_FIELD = [
'id', 'course_id', 'title', 'slug', 'view_num', 'short_description', 'render_desc', 'seo_keywords',
'seo_description', 'published_at', 'charge', 'chapter_id', 'duration',
];
Expand All @@ -100,7 +104,7 @@ class ApiV2Constant
* ),
* )
*/
const MODEL_MEMBER_FIELD = [
public const MODEL_MEMBER_FIELD = [
'id', 'avatar', 'nick_name', 'mobile', 'is_lock', 'is_active', 'role_id', 'role_expired_at',
'invite_balance', 'role',
];
Expand All @@ -118,7 +122,7 @@ class ApiV2Constant
* ),
* )
*/
const MODEL_ROLE_FIELD = [
public const MODEL_ROLE_FIELD = [
'id', 'name', 'charge', 'expire_days', 'desc_rows',
];
/**
Expand All @@ -133,10 +137,10 @@ class ApiV2Constant
* ),
* )
*/
const MODEL_COURSE_CHAPTER_FIELD = [
public const MODEL_COURSE_CHAPTER_FIELD = [
'id', 'course_id', 'title',
];
const MODEL_COURSE_CATEGORY_FIELD = [
public const MODEL_COURSE_CATEGORY_FIELD = [
'id', 'name', 'parent_id',
];
/**
Expand All @@ -152,7 +156,7 @@ class ApiV2Constant
* ),
* )
*/
const MODEL_COURSE_COMMENT_FIELD = [
public const MODEL_COURSE_COMMENT_FIELD = [
'id', 'user_id', 'render_content', 'created_at',
];
/**
Expand All @@ -168,7 +172,7 @@ class ApiV2Constant
* ),
* )
*/
const MODEL_VIDEO_COMMENT_FIELD = [
public const MODEL_VIDEO_COMMENT_FIELD = [
'id', 'user_id', 'render_content', 'created_at',
];
/**
Expand All @@ -190,7 +194,7 @@ class ApiV2Constant
* ),
* )
*/
const MODEL_ORDER_FIELD = [
public const MODEL_ORDER_FIELD = [
'id', 'user_id', 'charge', 'order_id', 'payment_method', 'status_text', 'payment_text', 'continue_pay',
'goods', 'created_at',
];
Expand All @@ -207,10 +211,10 @@ class ApiV2Constant
* ),
* )
*/
const MODEL_ORDER_GOODS_FIELD = [
public const MODEL_ORDER_GOODS_FIELD = [
'num', 'goods_text', 'charge', 'goods_type',
];
const MODEL_PROMO_CODE_FIELD = [
public const MODEL_PROMO_CODE_FIELD = [
'id', 'code', 'expired_at', 'invited_user_reward',
];

Expand All @@ -226,7 +230,7 @@ class ApiV2Constant
* ),
* )
*/
const MODEL_SLIDER_FIELD = [
public const MODEL_SLIDER_FIELD = [
'thumb', 'url', 'sort',
];

Expand All @@ -244,7 +248,7 @@ class ApiV2Constant
* ),
* )
*/
const MODEL_NOTIFICATON_FIELD = [
public const MODEL_NOTIFICATON_FIELD = [
'id', 'notifiable_id', 'data', 'read_at', 'created_at',
];
}
30 changes: 15 additions & 15 deletions app/Constant/BackendApiConstant.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@

class BackendApiConstant
{
const GUARD = 'administrator';
public const GUARD = 'administrator';

const OLD_PASSWORD_ERROR = '原密码错误';
const ADMINISTRATOR_ACCOUNT_CANT_DELETE = '当前用户是超级管理员账户无法删除';
const PERMISSION_BAN_DELETE_FOR_CHILDREN = '该权限下还有角色,请先删除该角色';
const ROLE_BAN_DELETE_FOR_ADMINISTRATOR = '该角色下还存在管理员,请先删除相应的管理员';
const ROLE_BAN_DELETE_FOR_INIT_ADMINISTRATOR = '超管角色无法删除';
const COURSE_CHAPTER_BAN_DELETE_FOR_VIDEOS = '无法删除,该章节下面存在视频';
const COURSE_BAN_DELETE_FOR_VIDEOS = '该课程下存在视频,无法删除';
public const OLD_PASSWORD_ERROR = '原密码错误';
public const ADMINISTRATOR_ACCOUNT_CANT_DELETE = '当前用户是超级管理员账户无法删除';
public const PERMISSION_BAN_DELETE_FOR_CHILDREN = '该权限下还有角色,请先删除该角色';
public const ROLE_BAN_DELETE_FOR_ADMINISTRATOR = '该角色下还存在管理员,请先删除相应的管理员';
public const ROLE_BAN_DELETE_FOR_INIT_ADMINISTRATOR = '超管角色无法删除';
public const COURSE_CHAPTER_BAN_DELETE_FOR_VIDEOS = '无法删除,该章节下面存在视频';
public const COURSE_BAN_DELETE_FOR_VIDEOS = '该课程下存在视频,无法删除';

const LOGIN_USERNAME_REQUIRED = '请输入用户名';
const LOGIN_PASSWORD_REQUIRED = '请输入密码';
const LOGIN_PASSWORD_ERROR = '密码错误';
public const LOGIN_USERNAME_REQUIRED = '请输入用户名';
public const LOGIN_PASSWORD_REQUIRED = '请输入密码';
public const LOGIN_PASSWORD_ERROR = '密码错误';

const ADMINISTRATOR_NOT_EXISTS = '用户名不存在';
public const ADMINISTRATOR_NOT_EXISTS = '用户名不存在';

const ERROR_CODE = 500;
const NO_AUTH_CODE = 401;
public const ERROR_CODE = 500;
public const NO_AUTH_CODE = 401;

const LOCAL_PUBLIC_DISK = 'public';
public const LOCAL_PUBLIC_DISK = 'public';
}
53 changes: 53 additions & 0 deletions app/Http/Controllers/Api/V2/IndexBannerController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/*
* This file is part of the Qsnh/meedu.
*
* (c) XiaoTeng <616896861@qq.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace App\Http\Controllers\Api\V2;

use App\Constant\ApiV2Constant;
use App\Services\Course\Services\CourseService;
use App\Services\Other\Services\IndexBannerService;
use App\Services\Course\Interfaces\CourseServiceInterface;
use App\Services\Other\Interfaces\IndexBannerServiceInterface;

class IndexBannerController extends BaseController
{
/**
* @var IndexBannerService
*/
protected $indexBannerService;

/**
* @var CourseService
*/
protected $courseService;

public function __construct(IndexBannerServiceInterface $indexBannerService, CourseServiceInterface $courseService)
{
$this->indexBannerService = $indexBannerService;
$this->courseService = $courseService;
}

public function all()
{
$data = $this->indexBannerService->all();
foreach ($data as $key => $banner) {
$data[$key]['courses'] = [];
$courseIds = explode(',', $banner['course_ids']);
if ($courseIds) {
$courses = $this->courseService->getList($courseIds);
$courses = arr2_clear($courses, ApiV2Constant::MODEL_COURSE_FIELD);
$data[$key]['courses'] = $courses;
}
}

return $this->data($data);
}
}
4 changes: 4 additions & 0 deletions app/Http/Controllers/Api/V2/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ public function createVideoOrder(Request $request)
{
$videoId = $request->input('video_id');
$video = $this->videoService->find($videoId);
if ($video['is_ban_sell'] === ApiV2Constant::YES) {
flash(__('this video cannot be sold'));
return back();
}
if ($video['charge'] === 0) {
return $this->error(__('video cant buy'));
}
Expand Down
23 changes: 18 additions & 5 deletions app/Http/Controllers/Backend/Api/V1/CourseCommentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,35 @@

namespace App\Http\Controllers\Backend\Api\V1;

use Illuminate\Http\Request;
use App\Models\CourseComment;
use App\Services\Course\Models\Course;

class CourseCommentController extends BaseController
{
public function index()
public function index(Request $request)
{
$courseId = $request->input('course_id');
$comments = CourseComment::with(['user', 'course'])
->when($courseId, function ($query) use ($courseId) {
$query->where('course_id', $courseId);
})
->orderByDesc('id')
->paginate(request()->input('size', 12));
->paginate($request->input('size', 12));

return $this->successData($comments);
$courses = Course::query()->select(['id', 'title'])->get();

return $this->successData([
'data' => $comments,
'courses' => $courses,
]);
}

public function destroy($id)
public function destroy(Request $request)
{
CourseComment::destroy($id);
$ids = $request->input('ids');

CourseComment::destroy($ids);

return $this->success();
}
Expand Down
6 changes: 6 additions & 0 deletions app/Http/Controllers/Backend/Api/V1/CourseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,10 @@ public function subscribeUsers(Request $request, $courseId)
$users = User::select(['id', 'nick_name', 'avatar', 'mobile'])->whereIn('id', array_column($data->all(), 'user_id'))->get()->keyBy('id');
return $this->successData(compact('data', 'users'));
}

public function all()
{
$courses = Course::query()->select(['id', 'title'])->get();
return $this->successData(['data' => $courses]);
}
}
21 changes: 18 additions & 3 deletions app/Http/Controllers/Backend/Api/V1/CourseVideoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

namespace App\Http\Controllers\Backend\Api\V1;

use App\Models\Video;
use App\Models\Course;
use Illuminate\Http\Request;
use App\Services\Course\Models\Video;
use App\Services\Course\Models\Course;
use App\Http\Requests\Backend\CourseVideoRequest;

class CourseVideoController extends BaseController
Expand Down Expand Up @@ -53,6 +53,8 @@ public function store(CourseVideoRequest $request, Video $video)
{
$video->fill($request->filldata())->save();

$this->hook($video->course_id);

return $this->success();
}

Expand All @@ -70,13 +72,26 @@ public function update(CourseVideoRequest $request, $id)
$video = Video::findOrFail($id);
$video->fill($request->filldata())->save();

$this->hook($video->course_id);

return $this->success();
}

public function destroy($id)
{
Video::destroy($id);
$video = Video::findOrFail($id);
$courseId = $video->course_id;
$video->delete();

$this->hook($courseId);

return $this->success();
}

protected function hook($courseId)
{
$count = Video::query()->where('course_id', $courseId)->where('charge', '>', 0)->count();
$isFree = $count === 0;
Course::query()->where('id', $courseId)->update(['is_free' => $isFree]);
}
}
6 changes: 6 additions & 0 deletions app/Http/Controllers/Backend/Api/V1/RoleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@

class RoleController extends BaseController
{
public function all()
{
$roles = Role::query()->get();
return $this->successData(['data' => $roles]);
}

public function index()
{
$roles = Role::orderByDesc('id')->paginate(request()->input('size', 12));
Expand Down
Loading

0 comments on commit 4af4c0b

Please sign in to comment.