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

Dev #177

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 19 commits into from
Jun 7, 2021
Merged

Dev #177

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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ php-cs-fixer.phar
_ide_helper.php
package-lock.json
/storage/install.lock
.phpunit.result.cache
.phpunit.result.cache

public/mix-manifest.json
17 changes: 0 additions & 17 deletions CONTRIBUTING.md

This file was deleted.

24 changes: 8 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@
</a>
</p>

## 安装方式

- [x] 使用傻瓜安装包安装 [下载地址](https://www.yuque.com/meedu/kbanfm)
- [x] [宝塔一键安装(适合技术能力一般的用户)](https://www.yuque.com/meedu/fvvkbf/qvb006)
- [x] [手动安装教程(适合技术能力较强的用户)](https://www.yuque.com/meedu/fvvkbf/hhl2wk)
- [x] MeEdu 安装服务(适合小白用户)。由 MeEdu 作者亲自帮您安装。具体查看:[MeEdu托管服务](https://meedu.vip/topic/205) 。
- [x] [MeEdu 宝塔手动安装最新版(手把手教学)](https://www.yuque.com/meedu/fvvkbf/gkape0)

## FAQ
## 常用链接

- [MeEdu 官网](https://meedu.vip)
- [MeEdu 插件商城](https://meedu.vip/addons)
Expand All @@ -25,19 +17,19 @@
- [MeEdu 常见问题总结](https://www.yuque.com/meedu/yr7rek)
- [MeEdu API文档](https://meedu-v2-xiaoteng.doc.coding.io/)

## 收费插件
## 安装

| 插件 | 插件 | 插件 |
| --- | --- | --- |
| [问答模块](https://meedu.vip/addons/38/Wenda) | [试题插件](https://meedu.vip/addons/36/Paper) | [团购](https://meedu.vip/addons/33/TuanGou) |
| [秒杀](https://meedu.vip/addons/32/MiaoSha) | [阿里云HLS加密播放](https://meedu.vip/addons/30/AliyunHls) | [腾讯云HLS加密播放](https://meedu.vip/addons/27/TencentCloudHls) |
| [学习路径](https://meedu.vip/addons/26/LearningPaths) | [图文收费](https://meedu.vip/addons/16/MeeduTopics) | [电子书模块](https://meedu.vip/addons/17/MeeduBooks) |
- [x] 使用傻瓜安装包安装 [下载地址](https://www.yuque.com/meedu/kbanfm)
- [x] [宝塔一键安装(适合技术能力一般的用户)](https://www.yuque.com/meedu/fvvkbf/qvb006)
- [x] [手动安装教程(适合技术能力较强的用户)](https://www.yuque.com/meedu/fvvkbf/hhl2wk)
- [x] MeEdu 安装服务(适合小白用户)。由 MeEdu 作者亲自帮您安装。具体查看:[MeEdu托管服务](https://meedu.vip/topic/205) 。
- [x] [MeEdu 宝塔手动安装最新版(手把手教学)](https://www.yuque.com/meedu/fvvkbf/gkape0)

## 鸣谢

感谢下面小伙伴提供支付宝和微信相关支付账号(排名不分前后):

| 昵称 | |
| 昵称 | 网址 |
| --- | --- |
| `Baiyuetribe` | [https://github.com/Baiyuetribe](https://github.com/Baiyuetribe) |
| `逸企邦` | [https://easeco.cn](https://easeco.cn) |
Expand Down
68 changes: 68 additions & 0 deletions app/Bus/WechatBindBus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

/*
* This file is part of the Qsnh/meedu.
*
* (c) XiaoTeng <616896861@qq.com>
*/

namespace App\Bus;

use Illuminate\Support\Str;
use App\Businesses\BusinessState;
use App\Constant\FrontendConstant;
use App\Exceptions\ServiceException;
use App\Services\Member\Services\SocialiteService;
use App\Services\Member\Interfaces\SocialiteServiceInterface;

class WechatBindBus
{
public const PREFIX = 'bind_';

protected $bus;

public function __construct(BusinessState $businessState)
{
$this->bus = $businessState;
}

public function isBind($code)
{
return Str::startsWith($code, self::PREFIX);
}

public function userId($code): int
{
$rows = explode('_', str_replace(self::PREFIX, '', $code));
return (int)($rows[0] ?? 0);
}

public function qrcode(int $userId)
{
$code = $this->code($userId);
$image = wechat_qrcode_image($code);
return compact('code', 'image');
}

public function code(int $userId): string
{
return sprintf('%s%d_%s', self::PREFIX, $userId, Str::random(5));
}

public function handle(string $code, string $appId, array $userData = [])
{
$userId = $this->userId($code);
if (!$userId) {
throw new ServiceException(__('参数错误'));
}

$this->bus->socialiteBindCheck($userId, FrontendConstant::WECHAT_LOGIN_SIGN, $appId);

/**
* @var SocialiteService $socialiteService
*/
$socialiteService = app()->make(SocialiteServiceInterface::class);

$socialiteService->bindApp($userId, FrontendConstant::WECHAT_LOGIN_SIGN, $appId, $userData);
}
}
21 changes: 21 additions & 0 deletions app/Businesses/BusinessState.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Carbon\Carbon;
use App\Constant\FrontendConstant;
use App\Exceptions\ServiceException;
use Illuminate\Support\Facades\Auth;
use App\Services\Course\Models\Video;
use App\Services\Course\Models\Course;
Expand All @@ -18,11 +19,13 @@
use App\Services\Order\Services\OrderService;
use App\Services\Course\Services\CourseService;
use App\Services\Order\Services\PromoCodeService;
use App\Services\Member\Services\SocialiteService;
use App\Services\Base\Interfaces\ConfigServiceInterface;
use App\Services\Member\Interfaces\UserServiceInterface;
use App\Services\Order\Interfaces\OrderServiceInterface;
use App\Services\Course\Interfaces\CourseServiceInterface;
use App\Services\Order\Interfaces\PromoCodeServiceInterface;
use App\Services\Member\Interfaces\SocialiteServiceInterface;

class BusinessState
{
Expand Down Expand Up @@ -324,4 +327,22 @@ public function enabledMpScanLogin(): bool

return $enabledOAuthLogin === 1;
}

public function socialiteBindCheck(int $userId, string $app, string $appId): void
{
/**
* @var SocialiteService $socialiteService
*/
$socialiteService = app()->make(SocialiteServiceInterface::class);

$hasBindSocialites = $socialiteService->userSocialites($userId);
if (in_array($app, array_column($hasBindSocialites, 'app'))) {
throw new ServiceException(__('您已经绑定了该渠道的账号'));
}

// 读取当前社交账号绑定的用户id
if ($socialiteService->getBindUserId($app, $appId)) {
throw new ServiceException(__('当前渠道账号已绑定了其它账号'));
}
}
}
2 changes: 1 addition & 1 deletion app/Constant/ApiV2Constant.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class ApiV2Constant
*/
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', 'is_ban_sell',
'seo_description', 'published_at', 'charge', 'chapter_id', 'duration', 'is_ban_sell', 'free_seconds',
];
/**
* @OpenApi\Annotations\Schemas(
Expand Down
39 changes: 39 additions & 0 deletions app/Hooks/MpWechatSubscribeHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@

use App\Bus\AuthBus;
use App\Meedu\Wechat;
use App\Bus\WechatBindBus;
use App\Constant\CacheConstant;
use App\Meedu\Hooks\HookParams;
use App\Exceptions\ServiceException;
use App\Meedu\Hooks\HookRuntimeInterface;
use App\Services\Base\Services\CacheService;
use App\Services\Base\Services\ConfigService;
use App\Services\Base\Interfaces\CacheServiceInterface;
use App\Services\Base\Interfaces\ConfigServiceInterface;

class MpWechatSubscribeHook implements HookRuntimeInterface
{
Expand All @@ -33,10 +37,36 @@ public function handle(HookParams $params, \Closure $next)
return $next($params);
}


$openid = $params->getValue('FromUserName');
$userData = Wechat::getInstance()->user->get($openid);
$unionId = $userData['unionid'] ?? '';

/**
* @var WechatBindBus $wechatBindBus
*/
$wechatBindBus = app()->make(WechatBindBus::class);

if ($wechatBindBus->isBind($eventKey)) {
// 微信公众号扫码绑定
try {
$wechatBindBus->handle($eventKey, $openid, (array)$userData);

$params->setResponse(__('微信账号已成功绑定'));
} catch (ServiceException $exception) {
$params->setResponse($exception->getMessage());
} catch (\Exception $exception) {
exception_record($exception);
$params->setResponse(__('系统错误'));
}
return $next($params);
}


// ------
// 下面是微信公众号扫码登录逻辑
// ------

/**
* @var AuthBus $authBus
*/
Expand All @@ -56,6 +86,15 @@ public function handle(HookParams $params, \Closure $next)
CacheConstant::WECHAT_SCAN_LOGIN['expire']
);

/**
* @var ConfigService $configService
*/
$configService = app()->make(ConfigServiceInterface::class);
$replyContent = $configService->getMpWechatScanLoginAlert() ?? '';

// 登录成功的回复语
$params->setResponse($replyContent);

return $next($params);
}
}
49 changes: 48 additions & 1 deletion app/Http/Controllers/Backend/Api/V1/MemberController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

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

use Carbon\Carbon;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Services\Member\Models\Role;
Expand Down Expand Up @@ -39,7 +41,7 @@ public function index(Request $request)
$keywords = $request->input('keywords', '');
$roleId = $request->input('role_id');
$tagId = $request->input('tag_id');
$sort = $request->input('sort', 'created_at');
$sort = $request->input('sort', 'id');
$order = $request->input('order', 'desc');

$members = User::with(['role', 'tags'])
Expand Down Expand Up @@ -387,4 +389,49 @@ public function userVideoWatchRecords(Request $request, $id)
'videos' => $videos,
]);
}

public function import(Request $request)
{
// ([0] => mobile, [1] => password)
$users = $request->input('users');
if (!$users || !is_array($users)) {
return $this->error(__('请导入数据'));
}

$mobiles = array_column($users, 0);

// 手机号存在检测
$mobileChunk = array_chunk($mobiles, 500);
foreach ($mobileChunk as $item) {
$exists = User::query()->whereIn('mobile', $item)->select(['mobile'])->get();
if ($exists->isNotEmpty()) {
return $this->error(sprintf('%s已存在', implode(',', $exists->pluck('mobile')->toArray())));
}
}

DB::transaction(function () use ($users) {
// 批量添加
foreach (array_chunk($users, 500) as $usersItem) {
$data = [];
foreach ($usersItem as $item) {
$data[] = [
'mobile' => $item[0],
'avatar' => url(config('meedu.member.default_avatar')),
'nick_name' => mb_substr($item[0], 0, 8) . '_' . Str::random(5),
'is_active' => config('meedu.member.is_active_default'),
'is_lock' => config('meedu.member.is_lock_default'),
'password' => Hash::make($item[1]),
'created_at' => Carbon::now(),
];
}
if (!$data) {
continue;
}

User::insert($data);
}
});

return $this->success();
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function recordRedirectTo(): void
// 主动配置redirect
$redirect = $request->input('redirect');
if (!$redirect) {
$redirect = session('_previous.url') ?: url('/');
$redirect = url('/');
}

// 存储redirectTo
Expand Down
Loading
0