generated from panliang/owl-admin-starter
54 lines
1.4 KiB
PHP
54 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Services;
|
|
|
|
use App\ModelFilters\PartyCateFilter;
|
|
use App\Models\Keyword;
|
|
use App\Models\PartyCate;
|
|
use App\Models\PartyUser;
|
|
use App\Models\UserScore;
|
|
|
|
class PartyCateService extends BaseService
|
|
{
|
|
protected array $withRelationships = ['master', 'plan'];
|
|
|
|
protected string $modelName = PartyCate::class;
|
|
|
|
protected string $modelFilterName = PartyCateFilter::class;
|
|
|
|
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();
|
|
return true;
|
|
}
|
|
|
|
public function resloveData($data, $model = null)
|
|
{
|
|
if (!$model) {
|
|
$list = UserScore::getTypeList();
|
|
$scores = [];
|
|
foreach ($list as $item) {
|
|
$scores[$item->key] = 0;
|
|
}
|
|
$data['scores'] = $scores;
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
public function incrementScore(PartyCate $info, $type, $score)
|
|
{
|
|
$scores = $info->scores;
|
|
if (isset($scores[$type])) {
|
|
$scores[$type] += $score;
|
|
}
|
|
$info->update([
|
|
'score' => $info->score + $score,
|
|
'scores' => $scores,
|
|
]);
|
|
}
|
|
}
|