Commit ea0f7bb5 authored by 刘招铃's avatar 刘招铃

按nova修改原型图

parent f1cbd4e5
......@@ -18,4 +18,3 @@ public/fonts
!storage/app/public/avatars
storage/debugbar/
../.idea
......@@ -28,9 +28,9 @@ class Kernel extends ConsoleKernel
// $schedule->command('inspire')
// ->hourly();
Log::info('定时任务进来---');
$schedule->command('larabbs:calculate-active-user')->everyMinute();
// $schedule->command('larabbs:sync-user-actived-at')->dailyAt('00:00');
$schedule->command('larabbs:sync-user-actived-at')->everyMinute();
$schedule->command('larabbs:calculate-active-user')->hourly();
$schedule->command('larabbs:sync-user-actived-at')->dailyAt('00:00');
// $schedule->command('larabbs:sync-user-actived-at')->everyMinute();
}
/**
......
......@@ -17,6 +17,6 @@ class Category extends Model
}
public function nvaCategories(){
return $this->newQuery()->get(['id','name']);
return $this->newQuery()->orderByDesc('sort_num')->get(['id','name']);
}
}
......@@ -2,6 +2,8 @@
namespace App\Models;
use Illuminate\Support\Facades\DB;
class Topic extends Model
{
protected $fillable = [
......@@ -57,4 +59,28 @@ class Topic extends Model
$this->reply_count = $this->replies->count();
$this->save();
}
public static function recentDaysTopic(array $date){
$res = static::query()
->select(
DB::raw('DATE(created_at) as date'),
DB::raw('COUNT(*) as count')
)
->whereBetween('created_at',$date)
->groupBy('date')
->pluck('count','date')
->toArray();
return $res;
}
//无数据日期补0
public static function recentCount($dateArr,$countArr){
foreach ($dateArr as $date){
if (!isset($countArr[$date])){
$countArr[$date] = 0;
}
}
return $countArr;
}
}
......@@ -5,8 +5,11 @@ namespace App\Models;
use App\Models\Traits\ActiveUserHelper;
use App\Models\Traits\LastActivedAtHelper;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
......@@ -102,4 +105,29 @@ class User extends Authenticatable implements MustVerifyEmail
public function managerContent(){
return $this->can('manager_content');
}
public static function recentDaysUser(array $date){
$res = static::query()
->select(
DB::raw('DATE(created_at) as date'),
DB::raw('COUNT(*) as count')
)
->whereBetween('created_at',$date)
->groupBy('date')
->pluck('count','date')
->toArray();
return $res;
}
//无数据日期补0
public static function recentCount($dateArr,$countArr){
foreach ($dateArr as $date){
if (!isset($countArr[$date])){
$countArr[$date] = 0;
}
}
return $countArr;
}
}
......@@ -33,7 +33,7 @@ class Category extends Resource
* @var array
*/
public static $search = [
'id','name'
'id','name','description'
];
public static function label()
......@@ -51,8 +51,9 @@ class Category extends Resource
{
return [
ID::make()->sortable(),
Text::make('name'),
Text::make('description'),
Text::make('名称','name')->rules('required'),
Text::make('描述','description')->rules('required'),
Text::make('排序','sort_num')->rules('required'),
Text::make('Topics', function () {
return $this->topics->count();
})->onlyOnIndex(),
......
<?php
namespace App\Nova\Filters;
use App\Nova\Category;
use Illuminate\Http\Request;
use Laravel\Nova\Filters\Filter;
class CategoryFilter extends Filter
{
public $name = '分类';
/**
* The filter's component.
*
* @var string
*/
public $component = 'select-filter';
/**
* Apply the filter to the given query.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Database\Eloquent\Builder $query
* @param mixed $value
* @return \Illuminate\Database\Eloquent\Builder
*/
public function apply(Request $request, $query, $value)
{
return $query->where('category_id', $value);
}
/**
* Get the filter's available options.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function options(Request $request)
{
return \App\Models\Category::query()->pluck('id','name')->toArray();
}
}
<?php
namespace App\Nova\Filters;
use Illuminate\Http\Request;
use Laravel\Nova\Filters\Filter;
class HasReplyFilter extends Filter
{
public $name = '评论';
/**
* The filter's component.
*
* @var string
*/
public $component = 'select-filter';
/**
* Apply the filter to the given query.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Database\Eloquent\Builder $query
* @param mixed $value
* @return \Illuminate\Database\Eloquent\Builder
*/
public function apply(Request $request, $query, $value)
{
return $value === 'yes'?$query->has('replies'):$query->doesntHave('replies');
}
/**
* Get the filter's available options.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function options(Request $request)
{
return [
'有评论'=>'yes',
'无评论'=>'no',
];
}
}
<?php
namespace App\Nova\Filters;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use Laravel\Nova\Filters\DateFilter;
class UserCreatedEndFilter extends DateFilter
{
public $name = '注册截止日期';
/**
* Apply the filter to the given query.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Database\Eloquent\Builder $query
* @param mixed $value
* @return \Illuminate\Database\Eloquent\Builder
*/
public function apply(Request $request, $query, $value)
{
$value = Carbon::parse($value);
return $query->where('created_at','<',$value);
}
}
<?php
namespace App\Nova\Filters;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use Laravel\Nova\Filters\DateFilter;
class UserCreatedStartFilter extends DateFilter
{
public $name = '注册开始日期';
/**
* Apply the filter to the given query.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Database\Eloquent\Builder $query
* @param mixed $value
* @return \Illuminate\Database\Eloquent\Builder
*/
public function apply(Request $request, $query, $value)
{
$value = Carbon::parse($value);
return $query->where('created_at','>',$value);
}
}
<?php
namespace App\Nova\Filters;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Laravel\Nova\Filters\Filter;
use Spatie\Permission\Models\Role;
class UserRoleFilter extends Filter
{
public $name='归属角色';
/**
* The filter's component.
*
* @var string
*/
public $component = 'select-filter';
/**
* Apply the filter to the given query.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Database\Eloquent\Builder $query
* @param mixed $value
* @return \Illuminate\Database\Eloquent\Builder
*/
public function apply(Request $request, $query, $value)
{
return $query->whereHas('roles',function ($query)use($value){
$query->where('role_id', $value);
});
}
/**
* Get the filter's available options.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function options(Request $request)
{
return Role::query()->pluck('id','name')->all();
// return DB::table('roles')->pluck('id','name')->all();
}
}
......@@ -11,6 +11,7 @@ class Link extends Resource
{
use ReBuildAuthrizable;
public static $group = '站点管理';
/**
* The model the resource corresponds to.
*
......@@ -31,9 +32,14 @@ class Link extends Resource
* @var array
*/
public static $search = [
'id',
'id','title','link'
];
public static function label()
{
return '推荐';
}
/**
* Get the fields displayed by the resource.
*
......@@ -44,8 +50,8 @@ class Link extends Resource
{
return [
ID::make()->sortable(),
Text::make('title'),
Text::make('link'),
Text::make('名称','title')->rules('required'),
Text::make('链接','link')->rules('required'),
];
}
......
<?php
namespace App\Nova\Metrics;
use App\Models\Topic;
use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Metrics\Value;
class NewTopics extends Value
{
/**
* Calculate the value of the metric.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return mixed
*/
public function calculate(NovaRequest $request)
{
return $this->count($request, Topic::class);
}
/**
* Get the ranges available for the metric.
*
* @return array
*/
public function ranges()
{
return [
30 => '30 Days',
60 => '60 Days',
365 => '365 Days',
'TODAY' => 'Today',
'MTD' => 'Month To Date',
'QTD' => 'Quarter To Date',
'YTD' => 'Year To Date',
];
}
/**
* Determine for how many minutes the metric should be cached.
*
* @return \DateTimeInterface|\DateInterval|float|int
*/
public function cacheFor()
{
// return now()->addMinutes(5);
}
/**
* Get the URI key for the metric.
*
* @return string
*/
public function uriKey()
{
return 'new-topices';
}
}
<?php
namespace App\Nova\Metrics;
use App\Models\User;
use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Metrics\Value;
class NewUsers extends Value
{
/**
* Calculate the value of the metric.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return mixed
*/
public function calculate(NovaRequest $request)
{
return $this->count($request, User::class);
}
/**
* Get the ranges available for the metric.
*
* @return array
*/
public function ranges()
{
return [
30 => '30 Days',
60 => '60 Days',
365 => '365 Days',
'TODAY' => 'Today',
'MTD' => 'Month To Date',
'QTD' => 'Quarter To Date',
'YTD' => 'Year To Date',
];
}
/**
* Determine for how many minutes the metric should be cached.
*
* @return \DateTimeInterface|\DateInterval|float|int
*/
public function cacheFor()
{
// return now()->addMinutes(5);
}
/**
* Get the URI key for the metric.
*
* @return string
*/
public function uriKey()
{
return 'new-users';
}
}
<?php
namespace App\Nova\Metrics;
use App\Models\Topic;
use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Metrics\Trend;
class TopicsPerDay extends Trend
{
/**
* Calculate the value of the metric.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return mixed
*/
public function calculate(NovaRequest $request)
{
return $this->countByDays($request, Topic::class);
}
/**
* Get the ranges available for the metric.
*
* @return array
*/
public function ranges()
{
return [
30 => '30 Days',
60 => '60 Days',
90 => '90 Days',
];
}
/**
* Determine for how many minutes the metric should be cached.
*
* @return \DateTimeInterface|\DateInterval|float|int
*/
public function cacheFor()
{
// return now()->addMinutes(5);
}
/**
* Get the URI key for the metric.
*
* @return string
*/
public function uriKey()
{
return 'topics-per-day';
}
}
<?php
namespace App\Nova\Metrics;
use App\Models\User;
use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Metrics\Trend;
class UsersPerDay extends Trend
{
public $name = '用户增长趋势';
/**
* Calculate the value of the metric.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return mixed
*/
public function calculate(NovaRequest $request)
{
return $this->countByDays($request, User::class);
}
/**
* Get the ranges available for the metric.
*
* @return array
*/
public function ranges()
{
return [
30 => '30 Days',
60 => '60 Days',
90 => '90 Days',
];
}
/**
* Determine for how many minutes the metric should be cached.
*
* @return \DateTimeInterface|\DateInterval|float|int
*/
public function cacheFor()
{
// return now()->addMinutes(5);
}
/**
* Get the URI key for the metric.
*
* @return string
*/
public function uriKey()
{
return 'users-per-day';
}
}
......@@ -8,10 +8,17 @@ use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Markdown;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;
use Titasgailius\SearchRelations\SearchesRelations;
class Reply extends Resource
{
use ReBuildAuthrizable;
use SearchesRelations;
public static $searchRelations = [
'user' => ['name'],
'topic' => ['title'],
];
public static $group = '内容管理';
/**
......@@ -34,9 +41,14 @@ class Reply extends Resource
* @var array
*/
public static $search = [
'id',
'id','content'
];
public static function label()
{
return '回复';
}
/**
* Get the fields displayed by the resource.
*
......@@ -47,9 +59,9 @@ class Reply extends Resource
{
return [