generated from panliang/owl-admin-starter
user_rank
parent
2e1ad54186
commit
085eb92ca1
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Admin\Services\CateRankService;
|
||||
use App\Models\CateRank;
|
||||
use Slowlyo\OwlAdmin\Controllers\AdminController;
|
||||
use Slowlyo\OwlAdmin\Renderers\Page;
|
||||
|
||||
class CateRankController extends AdminController
|
||||
{
|
||||
protected string $serviceName = CateRankService::class;
|
||||
|
||||
protected $snOptions;
|
||||
|
||||
public function list(): Page
|
||||
{
|
||||
$crud = $this->baseCRUD()
|
||||
->filterTogglable(false)
|
||||
->columnsTogglable(false)
|
||||
->headerToolbar([])
|
||||
->footerToolbar([])
|
||||
->loadDataOnce()
|
||||
->initFetch(false)
|
||||
->filter($this->baseFilter()->actions()->body([
|
||||
amisMake()->SelectControl()->name('sn')->label(__('user_rank.sn'))->options($this->getSnOptions())->size('md'),
|
||||
amisMake()->Component()->setType('submit')->label(__('admin.search'))->level('primary'),
|
||||
]))
|
||||
->columns([
|
||||
amisMake()->TableColumn()->name('cate.name')->label(__('user_rank.cate_id')),
|
||||
amisMake()->TableColumn()->name('sort')->label(__('user_rank.sort'))->set('type', 'tpl')->tpl('${(start - 1) * size + index + 1}'),
|
||||
amisMake()->TableColumn()->name('score')->label(__('user_rank.score')),
|
||||
]);
|
||||
|
||||
return $this->baseList($crud);
|
||||
}
|
||||
|
||||
public function getSnOptions()
|
||||
{
|
||||
if (!$this->snOptions) {
|
||||
$this->snOptions = CateRank::select('sn')->groupBy('sn')->orderBy('sn', 'desc')->pluck('sn');
|
||||
}
|
||||
|
||||
return $this->snOptions;
|
||||
}
|
||||
}
|
||||
|
|
@ -14,8 +14,6 @@ class KeywordsController extends AdminController
|
|||
{
|
||||
protected string $serviceName = KeywordService::class;
|
||||
|
||||
protected string $pageTitle = '字典管理';
|
||||
|
||||
public function list(): Page
|
||||
{
|
||||
$crud = $this->baseCRUD()
|
||||
|
|
|
|||
|
|
@ -97,8 +97,8 @@ class PartyCateController extends AdminController
|
|||
{
|
||||
return $this->baseForm()->title('')->body([
|
||||
amisMake()->TextControl()->name('name')->label(__('party_cate.name'))->required(),
|
||||
amisMake()->SelectControl()->name('master_id')->label(__('party_cate.master_id'))->options($this->getUserOptions()),
|
||||
amisMake()->SelectControl()->name('plan_id')->label(__('party_cate.plan_id'))->options($this->getUserOptions()),
|
||||
amisMake()->SelectControl()->name('master_id')->label(__('party_cate.master_id'))->options($this->getUserOptions())->searchable(),
|
||||
amisMake()->SelectControl()->name('plan_id')->label(__('party_cate.plan_id'))->options($this->getUserOptions())->searchable(),
|
||||
amisMake()->TextControl()->name('remarks')->label(__('party_cate.remarks')),
|
||||
]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Admin\Services\UserRankService;
|
||||
use App\Models\UserRank;
|
||||
use Slowlyo\OwlAdmin\Controllers\AdminController;
|
||||
use Slowlyo\OwlAdmin\Renderers\Page;
|
||||
|
||||
/**
|
||||
* 党员排名
|
||||
*/
|
||||
class UserRankController extends AdminController
|
||||
{
|
||||
protected string $serviceName = UserRankService::class;
|
||||
|
||||
protected $snOptions;
|
||||
|
||||
public function list(): Page
|
||||
{
|
||||
$crud = $this->baseCRUD()
|
||||
->filterTogglable(false)
|
||||
->columnsTogglable(false)
|
||||
->loadDataOnce(true)
|
||||
->footerToolbar([])
|
||||
->headerToolbar([])
|
||||
->initFetch(false)
|
||||
->filter($this->baseFilter()->actions()->body([
|
||||
amisMake()->SelectControl()->name('sn')->label(__('user_rank.sn'))->options($this->getSnOptions())->size('md'),
|
||||
amisMake()->Component()->setType('submit')->label(__('admin.search'))->level('primary'),
|
||||
]))
|
||||
->columns([
|
||||
amisMake()->TableColumn()->name('cate.name')->label(__('user_rank.cate_id')),
|
||||
amisMake()->TableColumn()->name('user.name')->label(__('user_rank.user_id')),
|
||||
amisMake()->TableColumn()->name('sort')->label(__('user_rank.sort'))->set('type', 'tpl')->tpl('${(start - 1) * size + index + 1}'),
|
||||
amisMake()->TableColumn()->name('score')->label(__('user_rank.score')),
|
||||
]);
|
||||
|
||||
return $this->baseList($crud);
|
||||
}
|
||||
|
||||
public function getSnOptions()
|
||||
{
|
||||
if (!$this->snOptions) {
|
||||
$this->snOptions = UserRank::select('sn')->groupBy('sn')->orderBy('sn', 'desc')->pluck('sn');
|
||||
}
|
||||
|
||||
return $this->snOptions;
|
||||
}
|
||||
}
|
||||
|
|
@ -5,7 +5,6 @@ namespace App\Admin\Controllers;
|
|||
use App\Admin\Services\UserScoreService;
|
||||
use App\Enums\CheckStatus;
|
||||
use App\Exceptions\BaseException;
|
||||
use App\Models\Keyword;
|
||||
use App\Models\PartyUser;
|
||||
use App\Models\UserScore;
|
||||
use Illuminate\Http\Request;
|
||||
|
|
@ -31,9 +30,10 @@ class UserScoreController extends AdminController
|
|||
])
|
||||
->filter($this->baseFilter()->actions([])->body([
|
||||
amisMake()->SelectControl()->name('type_id')->label(__('user_score.type_id'))->options($this->getTypeOptions())->clearable()->size('md'),
|
||||
amisMake()->SelectControl()->name('user_id')->label(__('user_score.user_id'))->options($this->getUserOptions())->clearable()->size('md'),
|
||||
amisMake()->SelectControl()->name('user_id')->label(__('user_score.user_id'))->options($this->getUserOptions())->clearable()->searchable()->size('md'),
|
||||
amisMake()->TextControl()->name('title')->label(__('user_score.title'))->clearable()->size('md'),
|
||||
amisMake()->SelectControl()->name('check_status')->label(__('user_score.check_status'))->options(CheckStatus::options())->clearable()->size('md'),
|
||||
amisMake()->DateRangeControl()->name('created_range')->label(__('user_score.created_at'))->clearable()->size('md'),
|
||||
amisMake()->Component()->setType('submit')->label(__('admin.search'))->level('primary'),
|
||||
]))
|
||||
->columns([
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Services;
|
||||
|
||||
use App\ModelFilters\CateRankFilter;
|
||||
use App\Models\CateRank;
|
||||
|
||||
class CateRankService extends BaseService
|
||||
{
|
||||
protected array $withRelationships = ['cate'];
|
||||
|
||||
protected string $modelName = CateRank::class;
|
||||
|
||||
protected string $modelFilterName = CateRankFilter::class;
|
||||
|
||||
public function listQuery()
|
||||
{
|
||||
$filter = $this->getModelFilter();
|
||||
|
||||
$query = $this->query();
|
||||
if ($this->withRelationships) {
|
||||
$query->with($this->withRelationships);
|
||||
}
|
||||
|
||||
if ($filter) {
|
||||
$query->filter(request()->input(), $filter);
|
||||
}
|
||||
|
||||
return $query->sort();
|
||||
}
|
||||
|
||||
public function list()
|
||||
{
|
||||
$query = $this->listQuery();
|
||||
|
||||
$items = (clone $query)->get();
|
||||
|
||||
return compact('items');
|
||||
}
|
||||
}
|
||||
|
|
@ -3,8 +3,10 @@
|
|||
namespace App\Admin\Services;
|
||||
|
||||
use App\ModelFilters\PartyCateFilter;
|
||||
use App\Models\CateRank;
|
||||
use App\Models\PartyCate;
|
||||
use App\Models\PartyUser;
|
||||
use App\Models\UserRank;
|
||||
use App\Models\UserScore;
|
||||
use Slowlyo\OwlAdmin\Models\AdminPermission;
|
||||
use Slowlyo\OwlAdmin\Services\AdminPermissionService;
|
||||
|
|
@ -44,11 +46,14 @@ class PartyCateService extends BaseService
|
|||
|
||||
public function preDelete(array $ids)
|
||||
{
|
||||
$userIds = PartyUser::whereIn('cate_id', $ids)->pluck('id');
|
||||
// 删除支部下面的党员记录
|
||||
// 删除党员记录
|
||||
PartyUser::whereIn('cate_id', $ids)->delete();
|
||||
// 删除党员下面的审核记录
|
||||
UserScore::whereIn('user_id', $userIds)->delete();
|
||||
// 删除审核记录
|
||||
UserScore::whereIn('cate_id', $ids)->delete();
|
||||
// 删除支部排名记录
|
||||
CateRank::whereIn('cate_id', $ids)->delete();
|
||||
// 删除党员排名记录
|
||||
UserRank::whereIn('cate_id', $ids)->delete();
|
||||
// 删除权限
|
||||
AdminPermission::whereIn('slug', array_map(fn ($v) => 'party_cate_' . $v, $ids))->delete();
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ namespace App\Admin\Services;
|
|||
use App\ModelFilters\PartyUserFilter;
|
||||
use App\Models\Keyword;
|
||||
use App\Models\PartyUser;
|
||||
use App\Models\UserRank;
|
||||
use App\Models\UserScore;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
|
@ -17,6 +18,15 @@ class PartyUserService extends BaseService
|
|||
|
||||
protected string $modelFilterName = PartyUserFilter::class;
|
||||
|
||||
public function preDelete(array $ids)
|
||||
{
|
||||
// 删除审核记录
|
||||
UserScore::whereIn('user_id', $ids)->delete();
|
||||
// 删除党员排名记录
|
||||
UserRank::whereIn('user_id', $ids)->delete();
|
||||
return true;
|
||||
}
|
||||
|
||||
public function validate($data, $model = null)
|
||||
{
|
||||
$createRules = [
|
||||
|
|
@ -52,7 +62,15 @@ class PartyUserService extends BaseService
|
|||
return $data;
|
||||
}
|
||||
|
||||
public function incrementScore(PartyUser $user, $type, $score)
|
||||
/**
|
||||
* 增加党员得分
|
||||
*
|
||||
* @param PartyUser $user 党员
|
||||
* @param string $type 类型 keywords(score_cate).key
|
||||
* @param int $score 得分
|
||||
* @return void
|
||||
*/
|
||||
public function incrementScore(PartyUser $user, string $type, int $score)
|
||||
{
|
||||
$scores = $user->scores;
|
||||
if (isset($scores[$type])) {
|
||||
|
|
@ -63,6 +81,7 @@ class PartyUserService extends BaseService
|
|||
'scores' => $scores,
|
||||
]);
|
||||
|
||||
// 同时增加党支部的得分
|
||||
if ($user->cate) {
|
||||
PartyCateService::make()->incrementScore($user->cate, $type, $score);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Services;
|
||||
|
||||
use App\ModelFilters\UserRankFilter;
|
||||
use App\Models\UserRank;
|
||||
|
||||
class UserRankService extends BaseService
|
||||
{
|
||||
protected array $withRelationships = ['user', 'cate'];
|
||||
|
||||
protected string $modelName = UserRank::class;
|
||||
|
||||
protected string $modelFilterName = UserRankFilter::class;
|
||||
|
||||
public function listQuery()
|
||||
{
|
||||
$filter = $this->getModelFilter();
|
||||
|
||||
$query = $this->query();
|
||||
if ($this->withRelationships) {
|
||||
$query->with($this->withRelationships);
|
||||
}
|
||||
|
||||
if ($filter) {
|
||||
$query->filter(request()->input(), $filter);
|
||||
}
|
||||
|
||||
return $query->sort();
|
||||
}
|
||||
|
||||
public function list()
|
||||
{
|
||||
$query = $this->listQuery();
|
||||
|
||||
$items = (clone $query)->get();
|
||||
|
||||
return compact('items');
|
||||
}
|
||||
}
|
||||
|
|
@ -18,6 +18,22 @@ class UserScoreService extends BaseService
|
|||
|
||||
protected string $modelFilterName = UserScoreFilter::class;
|
||||
|
||||
public function listQuery()
|
||||
{
|
||||
$filter = $this->getModelFilter();
|
||||
|
||||
$query = $this->query();
|
||||
if ($this->withRelationships) {
|
||||
$query->with($this->withRelationships);
|
||||
}
|
||||
|
||||
if ($filter) {
|
||||
$query->filter(request()->input(), $filter);
|
||||
}
|
||||
|
||||
return $query->sort();
|
||||
}
|
||||
|
||||
public function check(UserScore $info, $options = [])
|
||||
{
|
||||
if ($info->check_status == CheckStatus::Success) {
|
||||
|
|
@ -47,6 +63,10 @@ class UserScoreService extends BaseService
|
|||
if (!$model) {
|
||||
$data['cate_id'] = PartyUser::where('id', $data['user_id'])->value('cate_id');
|
||||
}
|
||||
$images = data_get($data, 'images');
|
||||
if ($images && !is_array($images)) {
|
||||
$data['images'] = explode(',', $images);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
|
@ -69,4 +89,17 @@ class UserScoreService extends BaseService
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 统计时间段内党员得分
|
||||
*
|
||||
* @param $start
|
||||
* @param $end
|
||||
* @return void
|
||||
*/
|
||||
public static function userTotal($start, $end)
|
||||
{
|
||||
$list = UserScore::where('check_status', CheckStatus::Success)->whereBetween('check_at', [$start, $end])->get();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,4 +50,9 @@ Route::group([
|
|||
// 评议审核
|
||||
$router->post('user-score/{id}/check', [\App\Admin\Controllers\UserScoreController::class, 'check']);
|
||||
$router->resource('user-score', \App\Admin\Controllers\UserScoreController::class)->names('admin.user_score');
|
||||
|
||||
// 党员排名
|
||||
$router->resource('user-rank', \App\Admin\Controllers\UserRankController::class)->names('admin.user_rank');
|
||||
// 党支部排名
|
||||
$router->resource('cate-rank', \App\Admin\Controllers\CateRankController::class)->names('admin.cate_rank');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\UserScore;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CateRank extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'app:cate-rank';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '生成上一季度的党支部排名';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$now = now();
|
||||
$time = $now->copy()->subQuarter();
|
||||
$start = $time->copy()->startOfQuarter();
|
||||
$end = $time->copy()->endOfQuarter();
|
||||
$sn = $time->year . '-' . $time->quarter;
|
||||
$list = [];
|
||||
$scoreList = UserScore::query()
|
||||
->whereBetween('created_at', [$start, $end])
|
||||
->select('cate_id', DB::raw('sum(`score`) as `score`'))
|
||||
->groupBy('cate_id')
|
||||
->get();
|
||||
foreach ($scoreList as $item) {
|
||||
$list[] = [
|
||||
'sn' => $sn,
|
||||
'cate_id' => $item->cate_id,
|
||||
'score' => $item->score,
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
];
|
||||
}
|
||||
\App\Models\CateRank::insert($list);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\UserScore;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class UserRank extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'app:user-rank';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '生成上一季度的党支部排名';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$now = now();
|
||||
$time = $now->copy()->subQuarter();
|
||||
$start = $time->copy()->startOfQuarter();
|
||||
$end = $time->copy()->endOfQuarter();
|
||||
$sn = $time->year . '-' . $time->quarter;
|
||||
$list = [];
|
||||
|
||||
$scoreList = UserScore::with(['user'])
|
||||
->whereBetween('created_at', [$start, $end])
|
||||
->select('user_id', DB::raw('sum(`score`) as `score`'))
|
||||
->groupBy('user_id')
|
||||
->get();
|
||||
foreach ($scoreList as $item) {
|
||||
$list[] = [
|
||||
'sn' => $sn,
|
||||
'cate_id' => $item->user->cate_id,
|
||||
'user_id' => $item->user_id,
|
||||
'score' => $item->score,
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
];
|
||||
}
|
||||
\App\Models\UserRank::insert($list);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace App\ModelFilters;
|
||||
|
||||
use EloquentFilter\ModelFilter;
|
||||
|
||||
class CateRankFilter extends ModelFilter
|
||||
{
|
||||
/**
|
||||
* Related Models that have ModelFilters as well as the method on the ModelFilter
|
||||
* As [relationMethod => [input_key1, input_key2]].
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $relations = [];
|
||||
|
||||
public function cate($id)
|
||||
{
|
||||
$this->where('cate_id', $id);
|
||||
}
|
||||
|
||||
public function sn($sn)
|
||||
{
|
||||
$this->where('sn', $sn);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace App\ModelFilters;
|
||||
|
||||
use EloquentFilter\ModelFilter;
|
||||
|
||||
class UserRankFilter extends ModelFilter
|
||||
{
|
||||
/**
|
||||
* Related Models that have ModelFilters as well as the method on the ModelFilter
|
||||
* As [relationMethod => [input_key1, input_key2]].
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $relations = [];
|
||||
|
||||
public function user($id)
|
||||
{
|
||||
$this->where('user_id', $id);
|
||||
}
|
||||
|
||||
public function sn($sn)
|
||||
{
|
||||
$this->where('sn', $sn);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\ModelFilters;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use EloquentFilter\ModelFilter;
|
||||
|
||||
class UserScoreFilter extends ModelFilter
|
||||
|
|
@ -38,4 +39,12 @@ class UserScoreFilter extends ModelFilter
|
|||
{
|
||||
$this->whereLike('title', $key);
|
||||
}
|
||||
|
||||
public function createdRange($value)
|
||||
{
|
||||
$str = explode(',', $value);
|
||||
$start = Carbon::createFromTimestamp(data_get($str, 0))->startOfDay();
|
||||
$end = Carbon::createFromTimestamp(data_get($str, 1))->endOfDay();
|
||||
$this->whereBetween('created_at', [$start, $end]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use EloquentFilter\Filterable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Traits\HasDateTimeFormatter;
|
||||
|
||||
/**
|
||||
* 支部排名
|
||||
*/
|
||||
class CateRank extends Model
|
||||
{
|
||||
use HasDateTimeFormatter, Filterable;
|
||||
|
||||
protected $table = 'cate_rank';
|
||||
protected $fillable = ['sn', 'cate_id', 'score'];
|
||||
|
||||
public function cate()
|
||||
{
|
||||
return $this->belongsTo(PartyCate::class, 'cate_id');
|
||||
}
|
||||
|
||||
public function scopeSort($q)
|
||||
{
|
||||
return $q->orderBy('sn')->orderBy('score', 'desc');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Traits\HasDateTimeFormatter;
|
||||
use EloquentFilter\Filterable;
|
||||
|
||||
/**
|
||||
* 党员排名
|
||||
*/
|
||||
class UserRank extends Model
|
||||
{
|
||||
use HasDateTimeFormatter, Filterable;
|
||||
|
||||
protected $table = 'user_rank';
|
||||
protected $fillable = ['sn', 'user_id', 'cate_id', 'score'];
|
||||
|
||||
public function cate()
|
||||
{
|
||||
return $this->belongsTo(PartyCate::class, 'cate_id');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(PartyUser::class, 'user_id');
|
||||
}
|
||||
|
||||
public function scopeSort($q)
|
||||
{
|
||||
return $q->orderBy('score', 'desc');
|
||||
}
|
||||
}
|
||||
|
|
@ -9,13 +9,14 @@ use EloquentFilter\Filterable;
|
|||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Slowlyo\OwlAdmin\Models\AdminUser;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
/**
|
||||
* 党员审核记录
|
||||
*/
|
||||
class UserScore extends Model
|
||||
{
|
||||
use HasDateTimeFormatter, Filterable;
|
||||
use HasDateTimeFormatter, Filterable, HasFactory;
|
||||
|
||||
protected $fillable = ['type_id', 'cate_id', 'user_id', 'title', 'content', 'images', 'file', 'check_status', 'check_user_id', 'check_remarks', 'check_at', 'score'];
|
||||
|
||||
|
|
@ -66,6 +67,6 @@ class UserScore extends Model
|
|||
|
||||
public function scopeSort($q)
|
||||
{
|
||||
return $this->orderBy('check_status')->latest('id');
|
||||
return $this->orderBy('check_status')->latest('created_at');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ return [
|
|||
|
|
||||
*/
|
||||
|
||||
'faker_locale' => 'en_US',
|
||||
'faker_locale' => 'zh_CN',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\PartyCate;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\PartyCate>
|
||||
*/
|
||||
class PartyCateFactory extends Factory
|
||||
{
|
||||
protected $model = PartyCate::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
$faker = $this->faker;
|
||||
return [
|
||||
'name' => $faker->streetName,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\PartyCate;
|
||||
use App\Models\PartyUser;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\PartyUser>
|
||||
*/
|
||||
class PartyUserFactory extends Factory
|
||||
{
|
||||
protected $model = PartyUser::class;
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
$faker = $this->faker;
|
||||
do {
|
||||
$username = $faker->userName;
|
||||
} while (PartyUser::where('username', $username)->exists());
|
||||
return [
|
||||
'username' => $username,
|
||||
'password' => '123456',
|
||||
'name' => $faker->name,
|
||||
'avatar' => 'https://via.placeholder.com/64x64.png?text=' . $username,
|
||||
'cate_id' => PartyCate::query()->inRandomOrder()->value('id'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Admin\Services\PartyUserService;
|
||||
use App\Enums\CheckStatus;
|
||||
use App\Models\PartyUser;
|
||||
use App\Models\UserScore;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\UserScore>
|
||||
*/
|
||||
class UserScoreFactory extends Factory
|
||||
{
|
||||
protected $model = UserScore::class;
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
$type = UserScore::getTypeList()->random();
|
||||
$user = PartyUser::query()->inRandomOrder()->first();
|
||||
$time = $this->faker->dateTimeBetween('-3 years', 'now');
|
||||
return [
|
||||
'type_id' => $type->id,
|
||||
'cate_id' => $user->cate_id,
|
||||
'user_id' => $user->id,
|
||||
'title' => $this->faker->sentence,
|
||||
'content' => $this->faker->paragraph,
|
||||
'images' => ['https://via.placeholder.com/100x100.png', 'https://via.placeholder.com/100x100.png'],
|
||||
'file' => 'https://via.placeholder.com/100x100.png',
|
||||
'check_status' => CheckStatus::Success,
|
||||
'check_user_id' => 1,
|
||||
'check_at' => $time,
|
||||
'score' => $this->faker->numberBetween(10, 100),
|
||||
'created_at' => $time,
|
||||
];
|
||||
}
|
||||
|
||||
public function configure(): static
|
||||
{
|
||||
return $this->afterCreating(function (UserScore $userScore) {
|
||||
PartyUserService::make()->incrementScore($userScore->user, $userScore->type->key, $userScore->score);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('user_rank', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('sn')->comment('期数(第一期: 202301)');
|
||||
$table->unsignedBigInteger('cate_id')->comment('支部(party_cates.id)');
|
||||
$table->unsignedBigInteger('user_id')->comment('党员(party_users.id)');
|
||||
$table->unsignedInteger('score')->default(0)->comment('得分');
|
||||
$table->timestamps();
|
||||
|
||||
$table->comment('党员排名');
|
||||
});
|
||||
|
||||
Schema::create('cate_rank', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('sn')->comment('期数(第一期: 202301)');
|
||||
$table->unsignedBigInteger('cate_id')->comment('支部(party_cates.id)');
|
||||
$table->unsignedInteger('score')->default(0)->comment('得分');
|
||||
$table->timestamps();
|
||||
|
||||
$table->comment('支部排名');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('user_rank');
|
||||
Schema::dropIfExists('cate_rank');
|
||||
}
|
||||
};
|
||||
|
|
@ -26,6 +26,8 @@ class AdminMenuSeeder extends Seeder
|
|||
['title' => '审核评定', 'icon' => 'icon-park:internal-data', 'url' => '/user-score', 'permission' => ['user_score']],
|
||||
['title' => '信息管理', 'icon' => 'icon-park:web-page', 'url' => '/articles', 'permission' => ['article']],
|
||||
['title' => '广告管理', 'icon' => 'icon-park:picture-one', 'url' => '/banner', 'permission' => ['banner']],
|
||||
['title' => '支部排名', 'icon' => 'icon-park:sort-one', 'url' => '/cate-rank', 'permission' => ['cate-rank']],
|
||||
['title' => '个人排名', 'icon' => 'icon-park:sort-one', 'url' => '/user-rank', 'permission' => ['user-rank']],
|
||||
['title' => '系统管理', 'icon' => 'icon-park:setting', 'url' => '/system', 'permission' => ['system'], 'children' => [
|
||||
['title' => '用户管理', 'icon' => 'icon-park:people-plus', 'url' => '/system/admin_users', 'permission' => ['admin_user']],
|
||||
['title' => '角色管理', 'icon' => 'icon-park:people-plus-one', 'url' => '/system/admin_roles', 'permission' => ['admin_rule']],
|
||||
|
|
|
|||
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\UserScore;
|
||||
use Database\Factories\PartyCateFactory;
|
||||
use Database\Factories\PartyUserFactory;
|
||||
use Database\Factories\UserScoreFactory;
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
use App\Models\PartyCate;
|
||||
use App\Models\PartyUser;
|
||||
|
||||
class PartyUserSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// PartyCate::truncate();
|
||||
// PartyUser::truncate();
|
||||
// (new PartyCateFactory())->count(20)->create();
|
||||
// (new PartyUserFactory())->count(100)->create();
|
||||
|
||||
UserScore::truncate();
|
||||
UserScore::factory()->count(100)->create();
|
||||
}
|
||||
}
|
||||
|
|
@ -26,6 +26,8 @@ class PermissionSeeder extends Seeder
|
|||
['name' => '审核评定', 'slug' => 'user_score'],
|
||||
['name' => '信息管理', 'slug' => 'article'],
|
||||
['name' => '广告管理', 'slug' => 'banner'],
|
||||
['name' => '党员排名', 'slug' => 'user_rank'],
|
||||
['name' => '支部排名', 'slug' => 'cate_rank'],
|
||||
['name' => '系统管理', 'slug' => 'system', 'children' => [
|
||||
['name' => '用户管理', 'slug' => 'admin_user'],
|
||||
['name' => '角色管理', 'slug' => 'admin_role'],
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'created_at' => '创建时间',
|
||||
'updated_at' => '更新时间',
|
||||
|
||||
'sn' => '期数',
|
||||
'user_id' => '党员',
|
||||
'cate_id' => '支部',
|
||||
'score' => '得分',
|
||||
'sort' => '排名',
|
||||
];
|
||||
|
|
@ -4,6 +4,7 @@ namespace Tests\Feature;
|
|||
|
||||
// use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use App\Models\PartyUser;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Tests\TestCase;
|
||||
|
||||
|
|
@ -14,7 +15,8 @@ class ExampleTest extends TestCase
|
|||
*/
|
||||
public function test_the_application_returns_a_successful_response(): void
|
||||
{
|
||||
$user = PartyUser::find(1);
|
||||
dump($user->getRawOriginal('password'));
|
||||
$time = Carbon::parse('2024-01-01 00:00:00');
|
||||
$last = $time->subQuarter();
|
||||
dump($last->quarter, $last->copy()->startOfQuarter()->toDateString(), $last->copy()->endOfQuarter()->toDateString());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue