diff --git a/app/Admin/Controllers/ArticleController.php b/app/Admin/Controllers/ArticleController.php index ab5c502..7de5cc8 100644 --- a/app/Admin/Controllers/ArticleController.php +++ b/app/Admin/Controllers/ArticleController.php @@ -51,8 +51,8 @@ class ArticleController extends AdminController amisMake()->TextControl()->name('title')->label(__('article.title'))->required(true), amisMake()->SelectControl()->name('category_id')->label(__('article.category_id'))->options($this->getCategoryOptions())->required(), amisMake()->SelectControl()->name('party_cate_id')->label(__('article.party_cate_id'))->options($this->getPartyCateOptions())->searchable(), - amisMake()->ImageControl()->name('cover')->label(__('article.cover'))->autoUpload(true), - Components::make()->sortControl('sort', __('article.sort')), + // amisMake()->ImageControl()->name('cover')->label(__('article.cover'))->autoUpload(true), + // Components::make()->sortControl('sort', __('article.sort')), amisMake()->DateTimeControl()->name('published_at')->label(__('article.published_at'))->value(now())->format('YYYY-MM-DD HH:mm:ss')->description('*不填写则默认为创建时间'), Components::make()->switchControl('form')->name('is_enable')->label(__('article.is_enable'))->value(true), Components::make()->fuEditorControl('content', __('article.content')), diff --git a/app/Admin/Controllers/PartyUserController.php b/app/Admin/Controllers/PartyUserController.php index e97abb1..beb979d 100644 --- a/app/Admin/Controllers/PartyUserController.php +++ b/app/Admin/Controllers/PartyUserController.php @@ -3,7 +3,7 @@ namespace App\Admin\Controllers; use App\Admin\Services\{PartyUserService, PartyCateService}; -use App\Models\PartyCate; +use App\Models\{PartyCate, PartyUser, Keyword}; use Slowlyo\OwlAdmin\Controllers\AdminController; use Slowlyo\OwlAdmin\Renderers\Form; use Slowlyo\OwlAdmin\Renderers\Page; @@ -87,12 +87,21 @@ class PartyUserController extends AdminController amisMake()->TextControl()->name('avatar')->label(__('party_user.avatar'))->static()->staticSchema(amisMake()->Image()), amisMake()->TextControl()->name('current_score')->label(__('party_cate.current_score'))->static(), amisMake()->TextControl()->name('score')->label(__('party_cate.score'))->static(), - amisMake()->TextControl()->name('scores')->label(__('party_cate.scores'))->static()->staticSchema(amisMake()->Json()), + amisMake()->TextControl()->name('scores')->label(__('party_cate.scores'))->static()->staticSchema( + amisMake()->Chart()->width('400px')->height('300px')->initFetch(false)->api(admin_url('/party-user/${id}/chart-option')) + ), amisMake()->TextControl()->name('remarks')->label(__('party_cate.remarks'))->static(), amisMake()->TextControl()->name('created_at')->label(__('party_user.created_at'))->static(), ]); } + public function chartOption($id) + { + $user = PartyUser::findOrFail($id); + $option = $this->service->getChartOption($user); + return $this->response()->success($option); + } + public function getCateOptions() { if (!$this->cateOptions) { diff --git a/app/Admin/Services/ArticleService.php b/app/Admin/Services/ArticleService.php index 51a70d5..592b288 100644 --- a/app/Admin/Services/ArticleService.php +++ b/app/Admin/Services/ArticleService.php @@ -38,7 +38,7 @@ class ArticleService extends BaseService if ($cid && $category = Keyword::find($cid)) { $data['category_path'] = $category->path.$category->id.'-'; } - if (! data_get($data, 'published_at')) { + if (! data_get($data, 'published_at') && !$model) { $data['published_at'] = now(); } diff --git a/app/Admin/Services/PartyUserService.php b/app/Admin/Services/PartyUserService.php index 12c7604..17c2ac9 100644 --- a/app/Admin/Services/PartyUserService.php +++ b/app/Admin/Services/PartyUserService.php @@ -87,4 +87,35 @@ class PartyUserService extends BaseService PartyCateService::make()->incrementScore($user->cate, $type, $score); } } + + /** + * 五星维度配置 + * Echarts 雷达图 echarts.apache.org + * + * @param PartyUser $user 党员 + * + * @return array + */ + public function getChartOption(PartyUser $user) + { + $typeList = Keyword::filter(['key' => 'score_cate_'])->sort()->get(); + $scores = $user->scores ?: []; + $values = $typeList->map(fn($item) => data_get($scores, $item->key, 0))->all(); + $max = max($values); + $options = [ + 'radar' => [ + 'indicator' => $typeList->map(fn($item) => ['name' => $item->name, 'max' => $max])->all(), + ], + 'series' => [ + [ + 'type' => 'radar', + 'data' => [ + ['value' => $values] + ], + 'label' => ['show' => true] + ] + ] + ]; + return $options; + } } diff --git a/app/Admin/routes.php b/app/Admin/routes.php index 0452706..0b7b1f0 100644 --- a/app/Admin/routes.php +++ b/app/Admin/routes.php @@ -50,6 +50,7 @@ Route::group([ $router->get('party-cate/{id}/rank', [\App\Admin\Controllers\PartyCateController::class, 'rankList']); // 党员 $router->resource('party-user', \App\Admin\Controllers\PartyUserController::class)->names('admin.party_user'); + $router->get('party-user/{id}/chart-option', [\App\Admin\Controllers\PartyUserController::class, 'chartOption']); // 评议审核 $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'); diff --git a/app/Http/Controllers/Api/AccountController.php b/app/Http/Controllers/Api/AccountController.php index 55fcace..70cae0a 100644 --- a/app/Http/Controllers/Api/AccountController.php +++ b/app/Http/Controllers/Api/AccountController.php @@ -24,6 +24,14 @@ class AccountController extends Controller ]); } + public function chartOption() + { + $user = auth('api')->user(); + $option = PartyUserService::make()->getChartOption($user); + + return $this->response()->success($option); + } + public function update(Request $request) { $user = auth('api')->user(); diff --git a/app/Models/PartyUser.php b/app/Models/PartyUser.php index a5e8827..a9453e2 100644 --- a/app/Models/PartyUser.php +++ b/app/Models/PartyUser.php @@ -7,6 +7,7 @@ use Laravel\Sanctum\HasApiTokens; use Illuminate\Foundation\Auth\User as Authenticatable; use EloquentFilter\Filterable; use App\Casts\StorageFile; +use Illuminate\Database\Eloquent\Casts\Attribute; /** * 党员 @@ -24,7 +25,7 @@ class PartyUser extends Authenticatable 'avatar' => StorageFile::class, 'scores' => 'array', ]; - + public function cate() { return $this->belongsTo(PartyCate::class, 'cate_id'); diff --git a/public/h5/index.html b/public/h5/index.html index f6130cb..d960f39 100644 --- a/public/h5/index.html +++ b/public/h5/index.html @@ -1,2 +1,2 @@