Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Comsenz/Discuz
Browse files Browse the repository at this point in the history
  • Loading branch information
gynnnn committed Jul 10, 2020
2 parents c731d38 + 5390514 commit 490e73b
Show file tree
Hide file tree
Showing 119 changed files with 1,088 additions and 1,316 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,9 @@ public function search(User $actor, $filter, $limit = null, $offset = 0)
// 获取主题作者用户组
if (!empty($threads->get($threadID))) {
$thread = $threads->get($threadID);
$threadUser = $thread->user;
$item->thread_is_approved = $thread->is_approved;
$item->thread_created_at = $thread->formatDate('created_at');
$threadUser = $thread->user;
if (!empty($threadUser)) {
$item->thread_username = $threadUser->username;
$item->thread_user_groups = $threadUser->groups->pluck('name')->join(',');
Expand Down
17 changes: 0 additions & 17 deletions app/Api/Controller/Order/ListOrdersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,23 +127,6 @@ public function data(ServerRequestInterface $request, Document $document)
'pageCount' => ceil($this->total / $limit),
]);

// 主题标题
if (in_array('thread.firstPost', $include)) {
$orders->load('thread.firstPost')
->map(function (Order $order) {
if ($order->thread) {
if ($order->thread->type == 1) {
$title = Str::limit($order->thread->title, 40);
} else {
$title = Str::limit($order->thread->firstPost->content, 40);
$title = str_replace("\n", '', $title);
}

$order->thread->title = htmlspecialchars($title);
}
});
}

return $orders->loadMissing($include);
}

Expand Down
2 changes: 1 addition & 1 deletion app/Api/Controller/Settings/SetSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
$settings->each(function ($setting) {
$this->settings->set(
Arr::get($setting, 'key'),
Arr::get($setting, 'value'),
trim(Arr::get($setting, 'value')),
Arr::get($setting, 'tag')
);
});
Expand Down
2 changes: 1 addition & 1 deletion app/Api/Controller/Settings/UploadLogoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected function data(ServerRequestInterface $request, Document $document)

UrlGenerator::setRequest($request);

$type = Arr::get($request->getParsedBody(), 'type');
$type = Arr::get($request->getParsedBody(), 'type', 'logo');
$file = Arr::get($request->getUploadedFiles(), 'logo');

$verifyFile = new UploadedFile(
Expand Down
2 changes: 1 addition & 1 deletion app/Api/Controller/Threads/CreateThreadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function data(ServerRequestInterface $request, Document $document)
{
$actor = $request->getAttribute('actor');
$ip = ip($request->getServerParams());
$port = Arr::get($request->getServerParams(), 'REMOTE_PORT');
$port = Arr::get($request->getServerParams(), 'REMOTE_PORT');

return $this->bus->dispatch(
new CreateThread($actor, $request->getParsedBody()->get('data', []), $ip, $port)
Expand Down
3 changes: 2 additions & 1 deletion app/Api/Controller/Threads/ListThreadsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,10 @@ private function applyFilters(Builder $query, array $filter, User $actor)

//话题文章
if ($topicId = Arr::get($filter, 'topicId', '0')) {
//更新话题阅读数
//更新话题阅读数、主题数
$topic = Topic::find($topicId);
$topic->refreshTopicViewCount();
$topic->refreshTopicThreadCount();

$query->join('thread_topic', 'threads.id', '=', 'thread_topic.thread_id')
->where('thread_topic.topic_id', $topicId);
Expand Down
34 changes: 32 additions & 2 deletions app/Api/Controller/Topic/ListTopicController.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,39 @@ protected function data(ServerRequestInterface $request, Document $document)
*/
public function search($filter, $sort, $limit = null, $offset = 0)
{
$query = $this->topics->query();
$query = $this->topics->query()->select('topics.*');

if ($username = trim(Arr::get($filter, 'username'))) {
$query->join('users', 'users.id', '=', 'topics.user_id')
->where('users.username', 'like', '%'.$username.'%');
}

if ($content = trim(Arr::get($filter, 'content'))) {
$query->where('content', 'like', '%'.$content.'%');
$query->where('topics.content', 'like', '%'.$content.'%');
}

if ($createdAtBegin = Arr::get($filter, 'createdAtBegin')) {
$query->where('topics.created_at', '>=', $createdAtBegin);
}

if ($createdAtEnd = Arr::get($filter, 'createdAtEnd')) {
$query->where('topics.created_at', '<=', $createdAtEnd);
}

if ($threadCountBegin = Arr::get($filter, 'threadCountBegin')) {
$query->where('topics.thread_count', '>=', $threadCountBegin);
}

if ($threadCountEnd = Arr::get($filter, 'threadCountEnd')) {
$query->where('topics.thread_count', '<=', $threadCountEnd);
}

if ($viewCountBegin = Arr::get($filter, 'viewCountBegin')) {
$query->where('topics.view_count', '>=', $viewCountBegin);
}

if ($viewCountEnd = Arr::get($filter, 'viewCountEnd')) {
$query->where('topics.view_count', '<=', $viewCountEnd);
}

foreach ((array) $sort as $field => $order) {
Expand Down
2 changes: 1 addition & 1 deletion app/Api/Controller/Users/AbstractWechatUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ abstract protected function getType();

protected function fixData($rawUser, $actor)
{
$data = array_merge($rawUser, ['user_id' => $actor->id, $this->getType() => $rawUser['openid']]);
$data = array_merge($rawUser, ['user_id' => $actor->id ?: null, $this->getType() => $rawUser['openid']]);
unset($data['openid'], $data['language']);
$data['privilege'] = serialize($data['privilege']);
return $data;
Expand Down
17 changes: 7 additions & 10 deletions app/Api/Controller/Users/WechatMiniProgramLoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@
use Discuz\Auth\AssertPermissionTrait;
use Discuz\Auth\Exception\PermissionDeniedException;
use Discuz\Socialite\Exception\SocialiteException;
use EasyWeChat\Factory;
use Discuz\Wechat\EasyWechatTrait;
use EasyWeChat\Kernel\Exceptions\DecryptException;
use EasyWeChat\Kernel\Exceptions\InvalidConfigException;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Contracts\Cache\Repository;
use Illuminate\Contracts\Events\Dispatcher as Events;
use Illuminate\Contracts\Validation\Factory as ValidationFactory;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Psr\Http\Message\ServerRequestInterface;
use Tobscure\JsonApi\Document;

class WechatMiniProgramLoginController extends AbstractResourceController
{
use AssertPermissionTrait;
use EasyWechatTrait;

public $serializer = TokenSerializer::class;

protected $easyWeChat;

protected $bus;

protected $cache;
Expand All @@ -46,9 +46,8 @@ class WechatMiniProgramLoginController extends AbstractResourceController

protected $settings;

public function __construct(Factory $easyWeChat, Dispatcher $bus, Repository $cache, ValidationFactory $validation, Events $events, SettingsRepository $settings)
public function __construct(Dispatcher $bus, Repository $cache, ValidationFactory $validation, Events $events, SettingsRepository $settings)
{
$this->easyWeChat = $easyWeChat;
$this->bus = $bus;
$this->cache = $cache;
$this->validation = $validation;
Expand All @@ -74,10 +73,7 @@ protected function data(ServerRequestInterface $request, Document $document)
['js_code' => 'required','iv' => 'required','encryptedData' => 'required']
)->validate();

$app = $this->easyWeChat::miniProgram([
'app_id' => $this->settings->get('miniprogram_app_id', 'wx_miniprogram'),
'secret' => $this->settings->get('miniprogram_app_secret', 'wx_miniprogram'),
]);
$app = $this->miniProgram();
//获取小程序登陆session key
$authSession = $app->auth->session($js_code);
if (isset($authSession['errcode']) && $authSession['errcode'] != 0) {
Expand Down Expand Up @@ -121,7 +117,8 @@ protected function data(ServerRequestInterface $request, Document $document)
$this->assertPermission((bool)$this->settings->get('register_close'));

$data['code'] = Arr::get($attributes, 'code');
$data['username'] = $wechatUser->nickname;
//用户名只允许15个字
$data['username'] = Str::of($wechatUser->nickname)->substr(0, 15);
$data['register_ip'] = ip($request->getServerParams());
$data['register_port'] = Arr::get($request->getServerParams(), 'REMOTE_PORT');
$user = $this->bus->dispatch(
Expand Down
10 changes: 5 additions & 5 deletions app/Api/Controller/Users/WechatWebUserLoginEventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@
namespace App\Api\Controller\Users;

use App\Settings\SettingsRepository;
use Discuz\Wechat\EasyWechatTrait;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Support\Arr;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use EasyWeChat\Factory;
use Psr\Http\Server\RequestHandlerInterface;
use Discuz\Http\DiscuzResponseFactory;

class WechatWebUserLoginEventController implements RequestHandlerInterface
{
use EasyWechatTrait;

/**
* 微信参数
*
Expand All @@ -31,6 +32,7 @@ class WechatWebUserLoginEventController implements RequestHandlerInterface
protected $bus;

/**
* @param SettingsRepository $setting
* @param Dispatcher $bus
*/
public function __construct(SettingsRepository $setting, Dispatcher $bus)
Expand All @@ -42,12 +44,10 @@ public function __construct(SettingsRepository $setting, Dispatcher $bus)
public function handle(ServerRequestInterface $request): ResponseInterface
{
$wx_config = [
'app_id'=> $this->settings->get('offiaccount_app_id', 'wx_offiaccount'),
'secret'=>$this->settings->get('offiaccount_app_secret', 'wx_offiaccount'),
'token' => $this->settings->get('oplatform_app_token', 'wx_oplatform'),
'aes_key' => $this->settings->get('oplatform_app_aes_key', 'wx_oplatform')
];
$app = Factory::officialAccount($wx_config);
$app = $this->offiaccount($wx_config);
$response = $app->server->serve();

return DiscuzResponseFactory::HtmlResponse($response->getContent());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
use App\Commands\Users\WebUserEvent;
use App\Settings\SettingsRepository;
use Discuz\Http\DiscuzResponseFactory;
use Discuz\Wechat\EasyWechatTrait;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Support\Arr;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use EasyWeChat\Factory;
use Psr\Http\Server\RequestHandlerInterface;


class WechatWebUserLoginPostEventController implements RequestHandlerInterface
{
use EasyWechatTrait;

/**
* 微信参数
*
Expand All @@ -45,12 +45,10 @@ public function __construct(SettingsRepository $setting, Dispatcher $bus)
public function handle(ServerRequestInterface $request): ResponseInterface
{
$wx_config = [
'app_id'=> $this->settings->get('offiaccount_app_id', 'wx_offiaccount'),
'secret'=>$this->settings->get('offiaccount_app_secret', 'wx_offiaccount'),
'token' => $this->settings->get('oplatform_app_token', 'wx_oplatform'),
'aes_key' => $this->settings->get('oplatform_app_aes_key', 'wx_oplatform')
];
$app = Factory::officialAccount($wx_config);
$app = $this->offiaccount($wx_config);
$this->bus->dispatch(
new WebUserEvent($app)
);
Expand Down
31 changes: 5 additions & 26 deletions app/Api/Controller/Wechat/OffIAccountAssetDeleteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@

use Discuz\Auth\AssertPermissionTrait;
use Discuz\Auth\Exception\PermissionDeniedException;
use Discuz\Contracts\Setting\SettingsRepository;
use Discuz\Http\DiscuzResponseFactory;
use EasyWeChat\Kernel\Exceptions\InvalidConfigException as InvalidConfigExceptionAlias;
use GuzzleHttp\Exception\GuzzleException;
use Discuz\Wechat\EasyWechatTrait;
use Illuminate\Support\Arr;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use EasyWeChat\Factory;

/**
* 微信公众号 - 删除单条永久素材
Expand All @@ -27,43 +24,25 @@
class OffIAccountAssetDeleteController implements RequestHandlerInterface
{
use AssertPermissionTrait;
use EasyWechatTrait;

/**
* @var Factory
* @var $easyWechat
*/
protected $easyWechat;

/**
* @var SettingsRepository
*/
protected $settings;

/**
* WechatMiniProgramCodeController constructor.
*
* @param Factory $easyWechat
* @param SettingsRepository $settings
*/
public function __construct(Factory $easyWechat, SettingsRepository $settings)
public function __construct()
{
$this->settings = $settings;

$config = [
'app_id' => $this->settings->get('offiaccount_app_id', 'wx_offiaccount'),
'secret' => $this->settings->get('offiaccount_app_secret', 'wx_offiaccount'),
'response_type' => 'array',
];

$this->easyWechat = $easyWechat::officialAccount($config);
$this->easyWechat = $this->offiaccount();
}

/**
* @param ServerRequestInterface $request
* @return ResponseInterface
* @throws GuzzleException
* @throws InvalidConfigExceptionAlias
* @throws PermissionDeniedException
* @throws \Exception
*/
public function handle(ServerRequestInterface $request): ResponseInterface
{
Expand Down
Loading

0 comments on commit 490e73b

Please sign in to comment.