编码风格

main
Jing Li 2024-03-23 19:59:59 +08:00
parent 7efc12327e
commit 970cef0c32
47 changed files with 976 additions and 948 deletions

View File

@ -6,12 +6,12 @@ use App\Models\Keyword;
use Slowlyo\OwlAdmin\Renderers\BaseRenderer;
use Slowlyo\OwlAdmin\Renderers\WangEditor;
class Components extends BaseRenderer {
class Components extends BaseRenderer
{
/**
* 父级选择器
*/
public function parentControl($apiUrl = null, $name ='parent_id', $label = null, $labelField = 'name', $valueField = 'id')
public function parentControl($apiUrl = null, $name = 'parent_id', $label = null, $labelField = 'name', $valueField = 'id')
{
return amisMake()->TreeSelectControl()->source($apiUrl)
->name($name)->label($label ?? __('admin.components.parent_select'))
@ -23,7 +23,8 @@ class Components extends BaseRenderer {
/**
* 排序字段
*/
public function sortControl($name ='sort', $label = null){
public function sortControl($name = 'sort', $label = null)
{
return amisMake()->NumberControl()
->name($name)->label($label ?? __('admin.components.order'))
->displayMode('enhance')
@ -34,7 +35,8 @@ class Components extends BaseRenderer {
/**
* 2位小数输入框
*/
public function decimalControl($name ='decimal', $label = null){
public function decimalControl($name = 'decimal', $label = null)
{
return amisMake()->NumberControl()
->name($name)->label($label ?? __('admin.components.decimal'))
->kilobitSeparator(true)
@ -47,7 +49,7 @@ class Components extends BaseRenderer {
/**
* 富文本编辑器
*/
public function fuEditorControl($name ='content', $label = null, $height = 530)
public function fuEditorControl($name = 'content', $label = null, $height = 530)
{
return WangEditor::make()
->name($name)->label($label ?? __('admin.components.content'))
@ -58,7 +60,8 @@ class Components extends BaseRenderer {
/**
* 开关
*/
public function enableControl($name = 'is_enable', $label= null, $mode = 'horizontal'){
public function enableControl($name = 'is_enable', $label = null, $mode = 'horizontal')
{
return amisMake()->SwitchControl()
->name($name)->label($label ?? __('admin.components.status'))
->mode($mode)
@ -68,39 +71,44 @@ class Components extends BaseRenderer {
/**
* 图片上传
*/
public function imageControl($name, $label){
public function imageControl($name, $label)
{
return amis()->ImageControl($name, $label)
->joinValues(false)
->autoUpload(true)->maxSize('5*1024*1024');//不能大于5M
->autoUpload(true)->maxSize('5*1024*1024'); //不能大于5M
}
/**
* 图片上传,带裁剪
*/
public function cropImageControl($name, $label, $aspectRatio = null){
public function cropImageControl($name, $label, $aspectRatio = null)
{
$cropImage = amis()->ImageControl($name, $label)->joinValues(false);
// if($aspectRatio){
$cropImage->crop([
'aspectRatio' => $aspectRatio ?? 1
'aspectRatio' => $aspectRatio ?? 1,
]);
// }
$cropImage->autoUpload(true);
return $cropImage;
}
/**
* 普通文件上传
*/
public function fileControl($name, $label, $accept = '.txt', $multiple = false){
public function fileControl($name, $label, $accept = '.txt', $multiple = false)
{
return amis()->FileControl($name, $label ?? __('admin.components.files'))
->multiple($multiple)
->joinValues(false)
->useChunk(false)
->maxSize(20*1024*1024)
->maxSize(20 * 1024 * 1024)
->accept($accept);
}
public function chunkFileControl($name, $label, $accept = '*', $multiple = false){
public function chunkFileControl($name, $label, $accept = '*', $multiple = false)
{
return amis()->FileControl($name, $label ?? __('admin.components.files'))
->multiple($multiple)
->joinValues(false)
@ -114,25 +122,28 @@ class Components extends BaseRenderer {
/**
* 标签选择
*/
public function keywordsTagControl($name = 'tags', $label= null, $pKey = null){
public function keywordsTagControl($name = 'tags', $label = null, $pKey = null)
{
return amisMake()->TagControl()
->name($name)->label($label ?? __('admin.components.tag'))
->maxTagLength(0)
->options(Keyword::where('parent_key', $pKey)->pluck('name', 'id')->toArray());
}
public function keywordsTag($label = null, $color = null){
if($color){
public function keywordsTag($label = null, $color = null)
{
if ($color) {
$tag = amisMake()->Tag()->label($label ?? __('admin.components.tag'))
->displayMode('rounded')->style([
'color' => '#fff',
'backgroundColor' =>$color,
'borderColor' => $color
'backgroundColor' => $color,
'borderColor' => $color,
]);
}else{
} else {
$tag = amisMake()->Tag()->label($label ?? __('admin.components.tag'))
->displayMode('rounded')->color('inactive');
}
return $tag;
}
@ -140,36 +151,37 @@ class Components extends BaseRenderer {
* 生成统计图config
* 折线图或者柱状图
*/
public function chartLineBarConfig($title = null, array $x , array $y){
public function chartLineBarConfig($title, array $x, array $y)
{
$yAxisData = [];
$seriesData = [];
$color = [];
if(!isset($y[0])){
if (! isset($y[0])) {
$_y = $y;
$y = [0=>$_y];
$y = [0 => $_y];
}
$i = 0;
$tips = '{b0}';
foreach($y as $item) {
foreach ($y as $item) {
//调色盘
$color[] = $item['color'];
//tips
$tips.= '<br/> {a'.$i.'}: {c'.$i.'}'.($item['unit'] ?? '');
$tips .= '<br/> {a'.$i.'}: {c'.$i.'}'.($item['unit'] ?? '');
//纵坐标
$yAxisData[] = [
'name'=>($item['unit'] ?? ''),
'type' =>'value',
'name' => ($item['unit'] ?? ''),
'type' => 'value',
'axisTick' => true,
'alignTicks' => true,
'axisLine' => [
'show' => true,
'lineStyle' => [
'color' => $item['color'] ?? ''
]
'color' => $item['color'] ?? '',
],
],
'axisLabel' => [
'formatter' => '{value} ',
],
'axisLabel'=> [
'formatter'=>'{value} '
]
];
//数据
$_series = [
@ -178,16 +190,16 @@ class Components extends BaseRenderer {
'type' => $item['type'] ?? 'line',
'yAxisIndex' => $i,
];
switch($item['type']){
switch ($item['type']) {
case 'line':
$_series = array_merge($_series, [
'smooth'=> true,
'symbol'=> 'none',
'smooth' => true,
'symbol' => 'none',
'lineStyle' => [
'color' => $item['color'] ?? ''
'color' => $item['color'] ?? '',
],
'areaStyle' => [
'color' => $item['color'] ?? ''
'color' => $item['color'] ?? '',
],
]);
break;
@ -205,10 +217,10 @@ class Components extends BaseRenderer {
'title' => [
'text' => $title,
],
"tooltip" => [//提示
'trigger'=>'axis',//坐标轴触发
'tooltip' => [//提示
'trigger' => 'axis', //坐标轴触发
'axisPointer' => [
'type' => 'cross'
'type' => 'cross',
],
// 'formatter' => $tips
],
@ -221,21 +233,22 @@ class Components extends BaseRenderer {
'data' => $x,
],
'yAxis' => $yAxisData,
'series' => $seriesData
'series' => $seriesData,
];
}
/**
* 散点图
*/
public function chartScatterConfig($title = null, array $x , array $y, array $yData = null){
public function chartScatterConfig($title, array $x, array $y, ?array $yData = null)
{
$yAxisData = [];
$seriesData = [];
$color = [];
if($yData){
if ($yData) {
$yAxisData = [
'type' =>'category',
'type' => 'category',
// 'splitLine'=>[
// 'show'=>true,
// 'lineStyle'=>[
@ -243,9 +256,9 @@ class Components extends BaseRenderer {
// ]
// ],
'axisTick' => [
'alignWithLabel'=>true
'alignWithLabel' => true,
],
'data'=> $yData
'data' => $yData,
];
}
@ -256,10 +269,10 @@ class Components extends BaseRenderer {
'title' => [
'text' => $title,
],
"tooltip" => [//提示
'trigger'=>'axis',//坐标轴触发
'tooltip' => [//提示
'trigger' => 'axis', //坐标轴触发
'axisPointer' => [
'type' => 'cross'
'type' => 'cross',
],
],
'xAxis' => [
@ -267,7 +280,7 @@ class Components extends BaseRenderer {
'data' => $x,
],
'yAxis' => $yAxisData,
'series' => $seriesData
'series' => $seriesData,
];
}
@ -275,7 +288,8 @@ class Components extends BaseRenderer {
* 生成饼状图config
* -todo
*/
public function chartPieConfig(){
return ;
public function chartPieConfig()
{
}
}

View File

@ -37,7 +37,7 @@ class AdController extends AdminController
Components::make()->parentControl(admin_url('api/keywords/tree-list?parent_name=banner_address&has_owner=0'), 'address', __('admin.ads.address'), 'name', 'key'),
amis()->SelectControl('enable', __('admin.ads.is_enable'))
->options([
1=>'开启',0=>'关闭'
1 => '开启', 0 => '关闭',
]),
]),
amis()->GroupControl()->mode('horizontal')->body([
@ -61,7 +61,7 @@ class AdController extends AdminController
Operation::make()->label(__('admin.actions'))->buttons([
$this->rowEditButton(),
$this->rowDeleteButton(),
])
]),
]);
return $this->baseList($crud);
@ -91,7 +91,7 @@ class AdController extends AdminController
return $this->baseDetail()->body([
amis()->TextControl('id', 'ID')->static(),
amis()->TextControl('created_at', __('admin.created_at'))->static(),
amis()->TextControl('updated_at', __('admin.updated_at'))->static()
amis()->TextControl('updated_at', __('admin.updated_at'))->static(),
]);
}
}

View File

@ -2,8 +2,8 @@
namespace App\Admin\Controllers;
use Slowlyo\OwlAdmin\Renderers\Page;
use Slowlyo\OwlAdmin\Controllers\AdminRoleController as AdminRoleBaseController;
use Slowlyo\OwlAdmin\Renderers\Page;
class AdminRoleController extends AdminRoleBaseController
{

View File

@ -83,8 +83,8 @@ class AdminUserController extends AdminController
amisMake()->Dialog()->title(__('admin.admin_user.edit_password'))->body([
amisMake()->Form()->title('')
->api([
'method'=>'PUT',
'url'=> admin_url('system/admin_users/$id')
'method' => 'PUT',
'url' => admin_url('system/admin_users/$id'),
])
->body([
amisMake()->TextControl('id')->value('${id}')->hidden(true),

View File

@ -4,7 +4,6 @@ namespace App\Admin\Controllers;
use App\Admin\Components;
use App\Admin\Services\ArticleService;
use App\Casts\Storage;
use App\Models\Keyword;
use App\Traits\CustomActionTrait;
use Slowlyo\OwlAdmin\Admin;
@ -15,9 +14,10 @@ use Slowlyo\OwlAdmin\Renderers\Page;
class ArticleController extends AdminController
{
use CustomActionTrait;
protected string $serviceName = ArticleService::class;
public function list():Page
public function list(): Page
{
$crud = $this->baseCRUD()->tableLayout('fixed')
->headerToolbar([
@ -37,12 +37,12 @@ class ArticleController extends AdminController
amis()->SelectControl('enable', __('admin.articles.is_enable'))
->columnRatio(3)
->options([
1=>'开启',0=>'关闭'
1 => '开启', 0 => '关闭',
]),
amis()->SelectControl('recommend', __('admin.articles.is_recommend'))
->columnRatio(3)
->options([
1=>'开启',0=>'关闭'
1 => '开启', 0 => '关闭',
]),
amis()->InputDatetimeRange()->label(__('admin.articles.published_at'))->name('published_at'),
]),
@ -56,7 +56,7 @@ class ArticleController extends AdminController
'position' => 'top-left',
'badgeLevel' => 'danger',
'visibleOn' => '${is_recommend > 0}',
'size' => 15
'size' => 15,
])
->columns([
amis()->TableColumn('id', __('admin.id'))->sortable(true),
@ -73,7 +73,7 @@ class ArticleController extends AdminController
amis()->Operation()->label(__('admin.actions'))->buttons([
$this->rowEditTypeButton('drawer', 'xl'),
$this->rowDeleteButton(),
])
]),
]);
return $this->baseList($crud);
@ -96,7 +96,7 @@ class ArticleController extends AdminController
])->md(4),
amis()->Wrapper()->body([
Components::make()->fuEditorControl('content', __('admin.articles.content')),
])->md(8)
])->md(8),
]),
]);
}
@ -105,5 +105,4 @@ class ArticleController extends AdminController
{
return $this->baseDetail()->body([]);
}
}

View File

@ -2,19 +2,19 @@
namespace App\Admin\Controllers;
use Slowlyo\OwlAdmin\Admin;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Symfony\Component\HttpFoundation\Response;
use Slowlyo\OwlAdmin\Controllers\AuthController as AdminAuthController;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Slowlyo\OwlAdmin\Admin;
use Slowlyo\OwlAdmin\Controllers\AuthController as AdminAuthController;
use Symfony\Component\HttpFoundation\Response;
class AuthController extends AdminAuthController
{
public function login(Request $request)
{
if (Admin::config('admin.auth.login_captcha')) {
if (!$request->has('captcha')) {
if (! $request->has('captcha')) {
return $this->response()->fail(__('admin.required', ['attribute' => __('admin.captcha')]));
}
@ -28,7 +28,7 @@ class AuthController extends AdminAuthController
'username' => 'required',
'password' => 'required',
], [
'username' . '.required' => __('admin.required', ['attribute' => __('admin.username')]),
'username'.'.required' => __('admin.required', ['attribute' => __('admin.username')]),
'password.required' => __('admin.required', ['attribute' => __('admin.password')]),
]);
@ -39,13 +39,14 @@ class AuthController extends AdminAuthController
$adminModel = Admin::adminUserModel();
$user = $adminModel::query()->where('username', $request->username)->first();
if($user && $user->lock){
if ($user && $user->lock) {
abort(Response::HTTP_BAD_REQUEST, '您的账号已被锁定,需要联系超级管理员解锁。');
}else{
} else {
if ($user && Hash::check($request->password, $user->password)) {
$module = Admin::currentModule(true);
$prefix = $module ? $module . '.' : '';
$token = $user->createToken($prefix . 'admin')->plainTextToken;
$prefix = $module ? $module.'.' : '';
$token = $user->createToken($prefix.'admin')->plainTextToken;
return $this->response()->success(compact('token'), __('admin.login_successful'));
}

View File

@ -3,17 +3,17 @@
namespace App\Admin\Controllers;
use Illuminate\Http\JsonResponse;
use Slowlyo\OwlAdmin\Renderers\Card;
use Slowlyo\OwlAdmin\Renderers\Flex;
use Slowlyo\OwlAdmin\Renderers\Html;
use Slowlyo\OwlAdmin\Renderers\Grid;
use Slowlyo\OwlAdmin\Renderers\Chart;
use Slowlyo\OwlAdmin\Renderers\Image;
use Slowlyo\OwlAdmin\Renderers\Action;
use Slowlyo\OwlAdmin\Renderers\Custom;
use Slowlyo\OwlAdmin\Renderers\Wrapper;
use Illuminate\Http\Resources\Json\JsonResource;
use Slowlyo\OwlAdmin\Controllers\AdminController;
use Slowlyo\OwlAdmin\Renderers\Action;
use Slowlyo\OwlAdmin\Renderers\Card;
use Slowlyo\OwlAdmin\Renderers\Chart;
use Slowlyo\OwlAdmin\Renderers\Custom;
use Slowlyo\OwlAdmin\Renderers\Flex;
use Slowlyo\OwlAdmin\Renderers\Grid;
use Slowlyo\OwlAdmin\Renderers\Html;
use Slowlyo\OwlAdmin\Renderers\Image;
use Slowlyo\OwlAdmin\Renderers\Wrapper;
class HomeController extends AdminController
{
@ -47,7 +47,7 @@ class HomeController extends AdminController
return Card::make()
->className('h-full clear-card-mb')
->body(
Custom::make()->html(<<<HTML
Custom::make()->html(<<<'HTML'
<div class="h-full flex flex-col mt-5 py-5 px-7">
<div></div>
<div class="flex flex-1 items-center w-full justify-center" id="hitokoto">
@ -64,12 +64,12 @@ class HomeController extends AdminController
</div>
HTML
)->onMount(<<<JS
)->onMount(<<<'JS'
fetch('https://v1.hitokoto.cn?c=i')
.then(response => response.json())
.then(data => {
const hitokoto = document.querySelector('#hitokoto_text')
hitokoto.href = `https://hitokoto.cn/?uuid=\${data.uuid}`
hitokoto.href = `https://hitokoto.cn/?uuid=${data.uuid}`
hitokoto.innerText = data.hitokoto
document.querySelector('#hitokoto_from_who').innerText = data.from_who
document.querySelector('#hitokoto_from').innerText = data.from
@ -88,7 +88,7 @@ JS
Custom::make()
->name('clock')
->html('<div id="clock" class="text-4xl"></div><div id="clock-date" class="mt-5"></div>')
->onMount(<<<JS
->onMount(<<<'JS'
const clock = document.getElementById('clock');
const tick = () => {
clock.innerHTML = (new Date()).toLocaleTimeString();
@ -176,7 +176,8 @@ JS
for ($i = 0; $i < 7; $i++) {
$_arr[] = random_int(10, 200);
}
return '[' . implode(',', $_arr) . ']';
return '['.implode(',', $_arr).']';
};
$random1 = $randArr();
@ -201,7 +202,7 @@ series: [
public function cube(): Card
{
return Card::make()->className('h-96 ml-4 w-8/12')->body(
Html::make()->html(<<<HTML
Html::make()->html(<<<'HTML'
<style>
.cube-box{ height: 300px; display: flex; align-items: center; justify-content: center; }
.cube { width: 100px; height: 100px; position: relative; transform-style: preserve-3d; animation: rotate 10s linear infinite; }

View File

@ -44,7 +44,7 @@ class EmployeeController extends AdminController
->level('link')
->icon('fa fa-sign-out')
->confirmText(__('employee.leave_confirm'))
->api('post:' . admin_url('hr/employees/${id}/leave')),
->api('post:'.admin_url('hr/employees/${id}/leave')),
]),
]);
@ -58,14 +58,14 @@ class EmployeeController extends AdminController
amisMake()->TextControl()->name('phone')->label(__('employee.phone'))->required(),
amisMake()->TagControl()->name('jobs')->label(__('employee.jobs'))
->source(admin_url('api/keywords/tree-list') . '?parent_key=' . Employee::JOB_KEY)
->source(admin_url('api/keywords/tree-list').'?parent_key='.Employee::JOB_KEY)
->labelField('name')
->valueField('key')
->joinValues(),
amisMake()->DateControl()->name('join_at')->label(__('employee.join_at'))->format('YYYY-MM-DD'),
amisMake()->TextControl()->name('username')->label(__('admin.username'))->value('${admin_user.username}')->required(!$edit),
amisMake()->TextControl()->name('password')->set('type', 'input-password')->label(__('admin.password'))->required(!$edit),
amisMake()->TextControl()->name('confirm_password')->set('type', 'input-password')->label(__('admin.confirm_password'))->required(!$edit),
amisMake()->TextControl()->name('username')->label(__('admin.username'))->value('${admin_user.username}')->required(! $edit),
amisMake()->TextControl()->name('password')->set('type', 'input-password')->label(__('admin.password'))->required(! $edit),
amisMake()->TextControl()->name('confirm_password')->set('type', 'input-password')->label(__('admin.confirm_password'))->required(! $edit),
]);
}

View File

@ -2,11 +2,10 @@
namespace App\Admin\Controllers;
use Slowlyo\OwlAdmin\Controllers\AdminController;
use App\Traits\UploadTrait;
use Slowlyo\OwlAdmin\Controllers\AdminController;
class IndexController extends AdminController
{
use UploadTrait;
}

View File

@ -33,7 +33,7 @@ class KeywordController extends AdminController
->placeholder(__('admin.keywords.search_name')),
amis()->TextControl('parent_name', __('admin.keywords.parent_keyword'))
->size('md')
->placeholder(__('admin.keywords.search_name'))
->placeholder(__('admin.keywords.search_name')),
]
))
->columns([
@ -63,7 +63,8 @@ class KeywordController extends AdminController
]);
}
public function getTreeList(Request $request){
public function getTreeList(Request $request)
{
return $this->service->getTree();
}
}

View File

@ -2,14 +2,11 @@
namespace App\Admin\Controllers;
use Illuminate\Support\Arr;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Slowlyo\OwlAdmin\Controllers\AdminController;
use Slowlyo\OwlAdmin\Renderers\Tab;
use Slowlyo\OwlAdmin\Renderers\Tabs;
use Slowlyo\OwlAdmin\Renderers\Alert;
use Slowlyo\OwlAdmin\Renderers\InputKV;
use Slowlyo\OwlAdmin\Renderers\TextControl;
use Slowlyo\OwlAdmin\Controllers\AdminController;
class SettingController extends AdminController
{
@ -32,7 +29,7 @@ class SettingController extends AdminController
Tabs::make()->tabs([
Tab::make()->title('上传设置')->body([
amis()->RadiosControl('upload_disk', '上传驱动')->options([
'public'=>'本地存储',
'public' => '本地存储',
'oss' => '阿里云OSS',
])->value('public')->required(true),
amis()->TextControl('oss_config.access_key_id', '阿里云AccessKeyId')->required(true)->size('lg')->visibleOn('${upload_disk == "oss"}'),
@ -50,34 +47,35 @@ class SettingController extends AdminController
{
$data = $request->only([
'upload_disk',
'oss_config'
'oss_config',
]);
//上传设置-修改env文件内配置
if(!empty($data['upload_disk'])){
if (! empty($data['upload_disk'])) {
$envData['FILESYSTEM_DISK'] = $data['upload_disk'];
if($envData['FILESYSTEM_DISK'] == 'oss'){//如果设置为OSS驱动则配置env变量
if ($envData['FILESYSTEM_DISK'] == 'oss') {//如果设置为OSS驱动则配置env变量
$envData['OSS_ACCESS_KEY_ID'] = Arr::get($data['oss_config'], 'access_key_id');
$envData['OSS_ACCESS_KEY_SECRET'] = Arr::get($data['oss_config'], 'access_key_secret');
$envData['OSS_BUCKET'] = Arr::get($data['oss_config'], 'bucket');
$envData['OSS_ENDPOINT'] = Arr::get($data['oss_config'], 'endpoint');
$envData['OSS_DOMAIN'] = Arr::get($data['oss_config'], 'domain');
if(!empty($envData['OSS_DOMAIN'])){
if (! empty($envData['OSS_DOMAIN'])) {
$envData['OSS_CNAME'] = 'true';
}else{
} else {
$envData['OSS_CNAME'] = 'false';
}
$envData['OSS_SSL'] = Arr::get($data['oss_config'], 'use_ssl') ? 'true':'false';
$envData['OSS_SSL'] = Arr::get($data['oss_config'], 'use_ssl') ? 'true' : 'false';
}
$envPath = base_path() . DIRECTORY_SEPARATOR . '.env';
$envPath = base_path().DIRECTORY_SEPARATOR.'.env';
$contentArray = collect(file($envPath, FILE_IGNORE_NEW_LINES));
$contentArray->transform(function ($item) use ($envData){
foreach ($envData as $key => $value){
if(str_contains($item, $key)){
$contentArray->transform(function ($item) use ($envData) {
foreach ($envData as $key => $value) {
if (str_contains($item, $key)) {
return $key . '=' . $value;
return $key.'='.$value;
}
}
return $item;
});
@ -85,7 +83,6 @@ class SettingController extends AdminController
\File::put($envPath, $content);
}
return settings()->adminSetMany($data);
}
}

View File

@ -45,7 +45,7 @@ class StoreController extends AdminController
->extractValue(false)
->clearable(),
amisMake()->SelectControl()->name('business_status')->label(__('store.business_status'))->columnRatio(3)->clearable(),
])
]),
]))
->columns([
amisMake()->TableColumn()->name('id')->label(__('store.id')),
@ -62,6 +62,7 @@ class StoreController extends AdminController
$this->rowDeleteButton(),
]),
]);
return $this->baseList($crud);
}

View File

@ -2,8 +2,8 @@
namespace App\Admin\Filters;
use Illuminate\Support\Arr;
use EloquentFilter\ModelFilter;
use Illuminate\Support\Arr;
class AdFilter extends ModelFilter
{
@ -14,12 +14,13 @@ class AdFilter extends ModelFilter
{
return $this->where('id', $id);
}
/**
* 备注
*/
public function remark($remark)
{
return $this->where('remark','like', '%'.$remark.'%');
return $this->where('remark', 'like', '%'.$remark.'%');
}
/**
@ -29,35 +30,41 @@ class AdFilter extends ModelFilter
{
return $this->where('address', $address);
}
public function publishedAt($publishedAt){
$publishedAt = explode(',',$publishedAt);
return $this->where(function($q) use ($publishedAt) {
public function publishedAt($publishedAt)
{
$publishedAt = explode(',', $publishedAt);
return $this->where(function ($q) use ($publishedAt) {
$startAt = Arr::get($publishedAt, 0) ?? null;
$endAt = Arr::get($publishedAt, 1) ?? null;
if(!empty($startAt)){
if (! empty($startAt)) {
$q->where('published_at', '>=', $startAt);
}
if(!empty($endAt)){
if (! empty($endAt)) {
$q->where('published_at', '<=', $endAt);
}
});
}
public function createdAt($createdAt){
$createdAt = explode(',',$createdAt);
return $this->where(function($q) use ($createdAt) {
public function createdAt($createdAt)
{
$createdAt = explode(',', $createdAt);
return $this->where(function ($q) use ($createdAt) {
$startAt = Arr::get($createdAt, 0) ?? null;
$endAt = Arr::get($createdAt, 1) ?? null;
if(!empty($startAt)){
if (! empty($startAt)) {
$q->where('created_at', '>=', $startAt);
}
if(!empty($endAt)){
if (! empty($endAt)) {
$q->where('created_at', '<=', $endAt);
}
});
}
public function enable($enable){
public function enable($enable)
{
return $this->where('is_enable', $enable);
}
}

View File

@ -14,12 +14,13 @@ class ArticleFilter extends ModelFilter
{
return $this->where('id', $id);
}
/**
* 标题
*/
public function title($title)
{
return $this->where('title','like', '%'.$title.'%');
return $this->where('title', 'like', '%'.$title.'%');
}
/**
@ -33,48 +34,56 @@ class ArticleFilter extends ModelFilter
/**
* 查询带有标签的文章
*/
public function tIds($tIds){
$tIds = explode(',',$tIds);
return $this->where(function($q) use ($tIds) {
public function tIds($tIds)
{
$tIds = explode(',', $tIds);
return $this->where(function ($q) use ($tIds) {
foreach ($tIds as $tId) {
$q->whereRaw("FIND_IN_SET('".$tId."',t_ids)");
}
});
}
public function publishedAt($publishedAt){
$publishedAt = explode(',',$publishedAt);
return $this->where(function($q) use ($publishedAt) {
public function publishedAt($publishedAt)
{
$publishedAt = explode(',', $publishedAt);
return $this->where(function ($q) use ($publishedAt) {
$startAt = Arr::get($publishedAt, 0) ?? null;
$endAt = Arr::get($publishedAt, 1) ?? null;
if(!empty($startAt)){
if (! empty($startAt)) {
$q->where('published_at', '>=', $startAt);
}
if(!empty($endAt)){
if (! empty($endAt)) {
$q->where('published_at', '<=', $endAt);
}
});
}
public function createdAt($createdAt){
$createdAt = explode(',',$createdAt);
return $this->where(function($q) use ($createdAt) {
public function createdAt($createdAt)
{
$createdAt = explode(',', $createdAt);
return $this->where(function ($q) use ($createdAt) {
$startAt = Arr::get($createdAt, 0) ?? null;
$endAt = Arr::get($createdAt, 1) ?? null;
if(!empty($startAt)){
if (! empty($startAt)) {
$q->where('created_at', '>=', $startAt);
}
if(!empty($endAt)){
if (! empty($endAt)) {
$q->where('created_at', '<=', $endAt);
}
});
}
public function enable($enable){
public function enable($enable)
{
return $this->where('is_enable', $enable);
}
public function recommend($recommend){
public function recommend($recommend)
{
return $this->where('is_recommend', $recommend);
}
}

View File

@ -9,7 +9,7 @@ class EmployeeFilter extends ModelFilter
public function search($key)
{
$condition = '%'.$key.'%';
$this->where(fn($q) => $q->where('name', 'like', $condition)->orWhere('phone', 'like', $condition));
$this->where(fn ($q) => $q->where('name', 'like', $condition)->orWhere('phone', 'like', $condition));
}
public function name($key)

View File

@ -2,8 +2,8 @@
namespace App\Admin\Filters;
use EloquentFilter\ModelFilter;
use App\Models\Keyword;
use EloquentFilter\ModelFilter;
class KeywordFilter extends ModelFilter
{
@ -12,21 +12,22 @@ class KeywordFilter extends ModelFilter
*/
public function name($name)
{
return $this->where('name','like', '%'.$name.'%')
->orWhere('key','like', '%'.$name.'%');
return $this->where('name', 'like', '%'.$name.'%')
->orWhere('key', 'like', '%'.$name.'%');
}
public function parentName($parent_name)
{
if(request('has_owner', 1)){
$this->where(function($q) use ($parent_name){
$q->where('name','like', '%'.$parent_name.'%')
->orWhere('key','like', '%'.$parent_name.'%');
if (request('has_owner', 1)) {
$this->where(function ($q) use ($parent_name) {
$q->where('name', 'like', '%'.$parent_name.'%')
->orWhere('key', 'like', '%'.$parent_name.'%');
});
}
return $this->orWhere('path','like', '%-'.
Keyword::where('name','like', '%'.$parent_name.'%')->orWhere('key','like', '%'.$parent_name.'%')->value('id')
. '-%' ?? '');
return $this->orWhere('path', 'like', '%-'.
Keyword::where('name', 'like', '%'.$parent_name.'%')->orWhere('key', 'like', '%'.$parent_name.'%')->value('id')
.'-%' ?? '');
}
public function parentKey($key)

View File

@ -12,7 +12,7 @@ class Menu
public function all()
{
$menus = $this->userMenus()
->push(...array_map(fn($item) => $this->formatItem($item), $this->menus))
->push(...array_map(fn ($item) => $this->formatItem($item), $this->menus))
->sortBy('order')
->values()
->toArray();
@ -35,7 +35,7 @@ class Menu
if ($item['parent_id'] == $parentId) {
$idStr = "[{$item['id']}]";
$_temp = [
'name' => $parentName ? $parentName . '-' . $idStr : $idStr,
'name' => $parentName ? $parentName.'-'.$idStr : $idStr,
'path' => $item['url'],
'component' => data_get($item, 'component') ?? 'amis',
'is_home' => $item['is_home'],
@ -49,20 +49,21 @@ class Menu
],
];
$children = $this->list2Menu($list, (int)$item['id'], $_temp['name']);
$children = $this->list2Menu($list, (int) $item['id'], $_temp['name']);
if (!empty($children)) {
if (! empty($children)) {
$_temp['component'] = 'amis';
$_temp['children'] = $children;
}
$data[] = $_temp;
if (!in_array($_temp['path'], Admin::config('admin.route.without_extra_routes'))) {
if (! in_array($_temp['path'], Admin::config('admin.route.without_extra_routes'))) {
array_push($data, ...$this->generateRoute($_temp));
}
unset($list[$key]);
}
}
return $data;
}
@ -71,18 +72,18 @@ class Menu
$url = $item['path'] ?? '';
$url = preg_replace('/\?.*/', '', $url);
if (!$url || array_key_exists('children', $item)) {
if (! $url || array_key_exists('children', $item)) {
return [];
}
$menu = fn($action, $path) => [
'name' => $item['name'] . '-' . $action,
'path' => $url . $path,
$menu = fn ($action, $path) => [
'name' => $item['name'].'-'.$action,
'path' => $url.$path,
'component' => 'amis',
'meta' => [
'hide' => true,
'icon' => Arr::get($item, 'meta.icon'),
'title' => Arr::get($item, 'meta.title') . ' - ' . __('admin.' . $action),
'title' => Arr::get($item, 'meta.title').' - '.__('admin.'.$action),
],
];

View File

@ -32,14 +32,14 @@ class AdService extends BaseService
$data['published_at'] = now();
}
if(isset($data['resource'])){
if (isset($data['resource'])) {
$data['resource'] = $this->saveImage('resource', 'ads/resource')[0];
}
//处理跳转配置
$jumpType = Arr::get($data, 'jump_type');
if($jumpType !== null){
switch($jumpType){
if ($jumpType !== null) {
switch ($jumpType) {
case Ad::TYPE_OFF:
$data['jump_config'] = null;
break;
@ -47,16 +47,16 @@ class AdService extends BaseService
$data['jump_config'] = Arr::only($data['jump_config'], 'web_link');
break;
case Ad::TYPE_APP:
$data['jump_config'] = Arr::only($data['jump_config'], 'app_link');;
$data['jump_config'] = Arr::only($data['jump_config'], 'app_link');
break;
case Ad::TYPE_MINI:
$data['jump_config'] = Arr::only($data['jump_config'], ['mini_id', 'mini_link']);;
$data['jump_config'] = Arr::only($data['jump_config'], ['mini_id', 'mini_link']);
break;
}
}
foreach ($data as $k => $v) {
if (!in_array($k, $columns)) {
if (! in_array($k, $columns)) {
continue;
}
@ -78,14 +78,14 @@ class AdService extends BaseService
$data['published_at'] = now();
}
if(isset($data['resource'])){
if (isset($data['resource'])) {
$data['resource'] = $this->saveImage('resource', 'ads/resource')[0];
}
//处理跳转配置
$jumpType = Arr::get($data, 'jump_type');
if($jumpType !== null){
switch($jumpType){
if ($jumpType !== null) {
switch ($jumpType) {
case Ad::TYPE_OFF:
$data['jump_config'] = null;
break;
@ -93,16 +93,16 @@ class AdService extends BaseService
$data['jump_config'] = Arr::only($data['jump_config'], 'web_link');
break;
case Ad::TYPE_APP:
$data['jump_config'] = Arr::only($data['jump_config'], 'app_link');;
$data['jump_config'] = Arr::only($data['jump_config'], 'app_link');
break;
case Ad::TYPE_MINI:
$data['jump_config'] = Arr::only($data['jump_config'], ['mini_id', 'mini_link']);;
$data['jump_config'] = Arr::only($data['jump_config'], ['mini_id', 'mini_link']);
break;
}
}
foreach ($data as $k => $v) {
if (!in_array($k, $columns)) {
if (! in_array($k, $columns)) {
continue;
}

View File

@ -2,12 +2,12 @@
namespace App\Admin\Services;
use Illuminate\Support\Arr;
use Slowlyo\OwlAdmin\Admin;
use Illuminate\Support\Facades\Hash;
use Slowlyo\OwlAdmin\Models\AdminUser;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Hash;
use Slowlyo\OwlAdmin\Admin;
use Slowlyo\OwlAdmin\Models\AdminUser;
/**
* @method AdminUser getModel()
@ -37,11 +37,11 @@ class AdminUserService extends BaseService
return $this->setError(__('admin.admin_user.username_already_exists'));
}
if (!data_get($data, 'password')) {
if (! data_get($data, 'password')) {
return $this->setError(__('admin.required', ['attribute' => __('admin.password')]));
}
if (!$this->passwordHandler($data)) {
if (! $this->passwordHandler($data)) {
return false;
}
@ -58,7 +58,7 @@ class AdminUserService extends BaseService
return $this->setError(__('admin.admin_user.username_already_exists'));
}
if (!$this->passwordHandler($data)) {
if (! $this->passwordHandler($data)) {
return false;
}
@ -73,13 +73,13 @@ class AdminUserService extends BaseService
{
return $this->query()
->where('username', $username)
->when($id, fn($query) => $query->where('id', '<>', $id))
->when($id, fn ($query) => $query->where('id', '<>', $id))
->exists();
}
public function updateUserSetting($primaryKey, $data): bool
{
if (!$this->passwordHandler($data, $primaryKey)) {
if (! $this->passwordHandler($data, $primaryKey)) {
return false;
}
@ -96,13 +96,13 @@ class AdminUserService extends BaseService
}
if ($id) {
if (!Arr::get($data, 'old_password')) {
if (! Arr::get($data, 'old_password')) {
return $this->setError(__('admin.admin_user.old_password_required'));
}
$oldPassword = $this->query()->where('id', $id)->value('password');
if (!Hash::check($data['old_password'], $oldPassword)) {
if (! Hash::check($data['old_password'], $oldPassword)) {
return $this->setError(__('admin.admin_user.old_password_error'));
}
}
@ -136,19 +136,12 @@ class AdminUserService extends BaseService
return compact('items', 'total');
}
/**
* @param $data
* @param array $columns
* @param AdminUser $model
*
* @return bool
*/
protected function saveData($data, array $columns, AdminUser $model): bool
{
$roles = Arr::pull($data, 'roles');
foreach ($data as $k => $v) {
if (!in_array($k, $columns)) {
if (! in_array($k, $columns)) {
continue;
}

View File

@ -36,7 +36,7 @@ class ArticleService extends BaseService
$data['appendixes'] = $this->saveFile('appendixes', 'articles/appendixes');
foreach ($data as $k => $v) {
if (!in_array($k, $columns)) {
if (! in_array($k, $columns)) {
continue;
}
@ -58,16 +58,16 @@ class ArticleService extends BaseService
$data['published_at'] = now();
}
if(isset($data['cover'])){
if (isset($data['cover'])) {
$data['cover'] = $this->saveImage('cover', 'articles/cover')[0] ?? '';
}
if(isset($data['appendixes'])){
if (isset($data['appendixes'])) {
$data['appendixes'] = $this->saveFile('appendixes', 'articles/appendixes');
}
foreach ($data as $k => $v) {
if (!in_array($k, $columns)) {
if (! in_array($k, $columns)) {
continue;
}

View File

@ -20,6 +20,7 @@ class BaseService extends AdminService
{
$list = $this->query()->orderByDesc('sort')->get();
$minNum = $list->min('parent_id');
return array2tree($list->toArray(), $minNum);
}
@ -34,7 +35,7 @@ class BaseService extends AdminService
$filter = $this->getModelFilter();
$query = $this->query();
if($this->withRelationships){
if ($this->withRelationships) {
$query->with($this->withRelationships);
}
@ -42,7 +43,7 @@ class BaseService extends AdminService
$query->filter(request()->input(), $filter);
}
if($this->modelSortAble){
if ($this->modelSortAble) {
$query->sort();
}
@ -63,6 +64,7 @@ class BaseService extends AdminService
$validate = $this->validate($data);
if ($validate !== true) {
$this->setError($validate);
return false;
}
@ -78,6 +80,7 @@ class BaseService extends AdminService
$validate = $this->validate($data, $model);
if ($validate !== true) {
$this->setError($validate);
return false;
}
@ -90,8 +93,10 @@ class BaseService extends AdminService
$result = $this->preDelete($id);
if ($result !== true) {
$this->setError($result);
return false;
}
return $this->query()->whereIn($this->primaryKey(), $id)->delete();
}

View File

@ -4,12 +4,12 @@ namespace App\Admin\Services;
use App\Admin\Filters\EmployeeFilter;
use App\Models\Employee;
use Illuminate\Support\Facades\Validator;
use Slowlyo\OwlAdmin\Services\AdminUserService;
use Slowlyo\OwlAdmin\Models\AdminUser;
use Illuminate\Support\Arr;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Validator;
use Slowlyo\OwlAdmin\Models\AdminUser;
use Slowlyo\OwlAdmin\Services\AdminUserService;
class EmployeeService extends BaseService
{
@ -26,6 +26,7 @@ class EmployeeService extends BaseService
$validate = $this->validate($data);
if ($validate !== true) {
$this->setError($validate);
return false;
}
@ -45,6 +46,7 @@ class EmployeeService extends BaseService
$validate = $this->validate($data, $model);
if ($validate !== true) {
$this->setError($validate);
return false;
}
@ -60,7 +62,7 @@ class EmployeeService extends BaseService
$model = $this->getModel();
$hidden = collect([$model->getCreatedAtColumn(), $model->getUpdatedAtColumn()])
->filter(fn($item) => $item !== null)
->filter(fn ($item) => $item !== null)
->toArray();
return $this->query()->with(['adminUser', 'jobs'])->find($id)->makeHidden($hidden);
@ -73,20 +75,23 @@ class EmployeeService extends BaseService
if ($model) {
// 修改管理员信息
if (Arr::hasAny($data, ['username', 'password', 'confirm_password'])) {
if (!$adminUserService->update($model->admin_user_id, Arr::only($data, ['username', 'password', 'confirm_password']))) {
if (! $adminUserService->update($model->admin_user_id, Arr::only($data, ['username', 'password', 'confirm_password']))) {
$this->setError($adminUserService->getError());
return false;
}
}
} else {
// 添加管理员信息
if (!$adminUserService->store(Arr::only($data, ['username', 'password', 'confirm_password']))) {
if (! $adminUserService->store(Arr::only($data, ['username', 'password', 'confirm_password']))) {
$this->setError($adminUserService->getError());
return false;
}
$adminUser = AdminUser::where('username', $data['username'])->first();
$data['admin_user_id'] = $adminUser->id;
}
return $data;
}
@ -107,6 +112,7 @@ class EmployeeService extends BaseService
$adminUserIds = Employee::whereIn('id', $ids)->pluck('admin_user_id')->implode(',');
$adminUserService = AdminUserService::make();
$adminUserService->delete($adminUserIds);
return true;
}
@ -118,12 +124,13 @@ class EmployeeService extends BaseService
];
$updateRules = [];
$validator = Validator::make($data, $model ? $updateRules : $createRules, [
'name.required' => __('employee.name') . '必填',
'phone.required' => __('employee.phone') . '必填',
'name.required' => __('employee.name').'必填',
'phone.required' => __('employee.phone').'必填',
]);
if ($validator->fails()) {
return $validator->errors()->first();
}
return true;
}
}

View File

@ -13,13 +13,15 @@ use Illuminate\Support\Arr;
class KeywordService extends BaseService
{
protected string $modelName = Keyword::class;
protected string $modelFilterName = KeywordFilter::class;
public function getTree()
{
$list = $this->query()->filter(request()->all(), $this->modelFilterName)->get();
$minNum = $list->min('parent_id');
return !$list->isEmpty() ? array2tree($list->toArray(), $minNum) :[];
return ! $list->isEmpty() ? array2tree($list->toArray(), $minNum) : [];
}
public function parentIsChild($id, $pid): bool
@ -53,7 +55,7 @@ class KeywordService extends BaseService
$model = $this->getModel();
foreach ($data as $k => $v) {
if (!in_array($k, $columns)) {
if (! in_array($k, $columns)) {
continue;
}
@ -75,6 +77,7 @@ class KeywordService extends BaseService
if ($pid != 0) {
if ($this->parentIsChild($primaryKey, $pid)) {
$this->setError('父级不允许设置为当前子权限');
return false;
}
}
@ -82,7 +85,7 @@ class KeywordService extends BaseService
$model = $this->query()->whereKey($primaryKey)->first();
foreach ($data as $k => $v) {
if (!in_array($k, $columns)) {
if (! in_array($k, $columns)) {
continue;
}
@ -94,10 +97,11 @@ class KeywordService extends BaseService
public function hasRepeated($data, $id = 0): bool
{
$query = $this->query()->when($id, fn($query) => $query->where('id', '<>', $id));
$query = $this->query()->when($id, fn ($query) => $query->where('id', '<>', $id));
if ((clone $query)->where('key', $data['key'])->exists()) {
$this->setError('KEY重复');
return true;
}
@ -107,7 +111,7 @@ class KeywordService extends BaseService
public function delete(string $ids): mixed
{
$ids = explode(',', $ids);
if(count($ids) == 1){
if (count($ids) == 1) {
$this->query()->where('path', 'like', '%-'.$ids[0].'-%')->delete();
}

View File

@ -3,8 +3,8 @@
namespace App\Admin\Services;
use App\Admin\Filters\StoreFilter;
use App\Models\Store;
use App\Enums\StoreRole;
use App\Models\Store;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
@ -23,6 +23,7 @@ class StoreService extends BaseService
$validate = $this->validate($data);
if ($validate !== true) {
$this->setError($validate);
return false;
}
@ -41,6 +42,7 @@ class StoreService extends BaseService
$validate = $this->validate($data, $model);
if ($validate !== true) {
$this->setError($validate);
return false;
}
@ -59,6 +61,7 @@ class StoreService extends BaseService
$data['lon'] = data_get($data['location'], 'lng');
$data['lat'] = data_get($data['location'], 'lat');
}
return $data;
}
@ -75,7 +78,7 @@ class StoreService extends BaseService
'lat' => ['required'],
];
$updateRules = [
'master_id' => [Rule::unique($model, 'master_id')]
'master_id' => [Rule::unique($model, 'master_id')],
];
$validator = Validator::make($data, $model ? $updateRules : $createRules, [
'master_id.unique' => '已经是店长了',
@ -83,6 +86,7 @@ class StoreService extends BaseService
if ($validator->fails()) {
return $validator->errors()->first();
}
return true;
}
}

View File

@ -2,10 +2,10 @@
namespace App\Casts;
use Slowlyo\OwlAdmin\Admin;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Storage as StorageFacades;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
use Illuminate\Support\Facades\Storage as StorageFacades;
use Illuminate\Support\Str;
use Slowlyo\OwlAdmin\Admin;
/**
* 转换文件存储路径

View File

@ -32,6 +32,7 @@ enum BusinessStatus: int
foreach (self::map() as $key => $value) {
array_push($list, ['label' => $value, 'value' => $key]);
}
return $list;
}

View File

@ -32,6 +32,7 @@ enum EmployeeStatus: int
foreach (self::map() as $key => $value) {
array_push($list, ['label' => $value, 'value' => $key]);
}
return $list;
}

View File

@ -24,6 +24,7 @@ enum StoreRole: int
foreach (self::map() as $key => $value) {
array_push($list, ['label' => $value, 'value' => $key]);
}
return $list;
}

View File

@ -2,20 +2,22 @@
namespace App\Models;
use EloquentFilter\Filterable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use EloquentFilter\Filterable;
use App\Casts\Storage;
class Ad extends Model
{
use HasFactory;
use Filterable;
use HasFactory;
public const TYPE_OFF = 0; //无跳转
public const TYPE_WEB = 1; //网页跳转
public const TYPE_APP = 2; //应用跳转
public const TYPE_MINI = 3;//小程序跳转
public const TYPE_MINI = 3; //小程序跳转
protected function serializeDate(\DateTimeInterface $date)
{
@ -41,7 +43,7 @@ class Ad extends Model
'jump_config',
];
public static function jumpTypeMap() :array
public static function jumpTypeMap(): array
{
return [
self::TYPE_WEB => '网页跳转',
@ -58,7 +60,7 @@ class Ad extends Model
self::TYPE_WEB => "<span class='label label-info'>网页跳转</span>",
self::TYPE_APP => "<span class='label label-warning'>应用跳转</span>",
self::TYPE_MINI => "<span class='label label-green'>小程序跳转</span>",
'*'=>'其他:${jump_type}'
'*' => '其他:${jump_type}',
];
}
@ -68,11 +70,12 @@ class Ad extends Model
self::TYPE_IN => "<span class='label label-info'>入住缴费</span>",
self::TYPE_CONTINUE => "<span class='label label-warning'>续住缴费</span>",
self::TYPE_EXIT => "<span class='label label-danger'>离开结算</span>",
'*'=>'其他:${live_in}'
'*' => '其他:${live_in}',
];
}
public function scopeShow(){
public function scopeShow()
{
$q->where('is_enable', true)->where('published_at', '>=', now());
}

View File

@ -46,7 +46,7 @@ class AdminUser extends Model
}
$parent = $allMenus->get($parent->parent_id);
};
}
}
unset($allMenus, $roleMenus);

View File

@ -2,16 +2,15 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
use EloquentFilter\Filterable;
use App\Casts\Storage;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Article extends Model
{
use HasFactory;
use Filterable;
use HasFactory;
protected function serializeDate(\DateTimeInterface $date)
{
@ -42,7 +41,8 @@ class Article extends Model
'appendixes',
];
public function scopeShow(){
public function scopeShow()
{
$q->where('is_enable', true)->where('published_at', '>=', now());
}
@ -54,10 +54,10 @@ class Article extends Model
->orderBy('created_at', 'desc');
}
protected function tags():Attribute
protected function tags(): Attribute
{
return Attribute::make(
get: fn($value) => $this->t_ids ? explode(',', $this->t_ids) : [],
get: fn ($value) => $this->t_ids ? explode(',', $this->t_ids) : [],
);
}
}

View File

@ -2,12 +2,12 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Enums\EmployeeStatus;
use Slowlyo\OwlAdmin\Models\AdminUser;
use Illuminate\Database\Eloquent\Casts\Attribute;
use EloquentFilter\Filterable;
use App\Traits\HasDateTimeFormatter;
use EloquentFilter\Filterable;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
use Slowlyo\OwlAdmin\Models\AdminUser;
/**
* 员工

View File

@ -11,8 +11,8 @@ use Illuminate\Support\Str;
class Keyword extends Model
{
use HasFactory;
use Filterable;
use HasFactory;
protected $fillable = ['name', 'key', 'value', 'parent_id', 'parent_key', 'path', 'sort', 'lv'];
@ -33,7 +33,7 @@ class Keyword extends Model
'lv' => 1,
]);
if((string) $keyword->key === ''){
if ((string) $keyword->key === '') {
$keyword->key = Str::random(16);
}
} else {
@ -43,8 +43,8 @@ class Keyword extends Model
'lv' => $parent->lv + 1,
]);
if((string) $keyword->key === ''){
$keyword->key = $parent->key . '_' . ($parent->children()->count() + 1);
if ((string) $keyword->key === '') {
$keyword->key = $parent->key.'_'.($parent->children()->count() + 1);
}
}
});
@ -62,17 +62,18 @@ class Keyword extends Model
public function scopeAllChildrenOfKey($q, $parentKey)
{
$q->where('path','like', '%-'.
$q->where('path', 'like', '%-'.
static::where('key', $parentKey)->value('id')
. '-%' ?? '');
.'-%' ?? '');
}
public static function tagsMap(String $key)
public static function tagsMap(string $key)
{
$mapArr = [];
self::query()->where('parent_key', $key)->get()->map(function($item) use (&$mapArr){
self::query()->where('parent_key', $key)->get()->map(function ($item) use (&$mapArr) {
$mapArr[$item->id] = Components::make()->keywordsTag($item->name, $item->value);
});
return $mapArr;
}

View File

@ -2,11 +2,11 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Enums\BusinessStatus;
use Illuminate\Database\Eloquent\Casts\Attribute;
use EloquentFilter\Filterable;
use App\Traits\HasDateTimeFormatter;
use EloquentFilter\Filterable;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
/**
* 门店

View File

@ -35,10 +35,6 @@ class QueryLoggerServiceProvider extends ServiceProvider
});
}
/**
* @param \Illuminate\Database\Events\QueryExecuted $query
* @return string
*/
protected function prepareSql(QueryExecuted $query): string
{
$sql = str_replace(['%', '?'], ['%%', '%s'], $query->sql);
@ -54,7 +50,6 @@ class QueryLoggerServiceProvider extends ServiceProvider
/**
* @param float $milliseconds
* @return string
*/
protected function formatDuration($milliseconds): string
{

View File

@ -2,23 +2,16 @@
namespace App\Traits;
use Slowlyo\OwlAdmin\Admin;
use Slowlyo\OwlAdmin\Renderers\Drawer;
use Slowlyo\OwlAdmin\Renderers\Dialog;
use Slowlyo\OwlAdmin\Renderers\DrawerAction;
use Slowlyo\OwlAdmin\Renderers\DialogAction;
use Slowlyo\OwlAdmin\Renderers\Drawer;
use Slowlyo\OwlAdmin\Renderers\DrawerAction;
use Slowlyo\OwlAdmin\Renderers\LinkAction;
trait CustomActionTrait
{
/**
* 新增按钮
*
* @param string $type
* @param string $size
* @param string $width
*
* @return DialogAction|DrawerAction|LinkAction
*/
protected function createTypeButton(string $type = '', string $size = '', string $width = ''): DialogAction|DrawerAction|LinkAction
{
@ -27,9 +20,9 @@ trait CustomActionTrait
$form = $this->form(false)->api($this->getStorePath())->onEvent([]);
$drawer = Drawer::make()->title(__('admin.create'))->body($form)->closeOnOutside();
if($width){
if ($width) {
$drawer->width($width);
}else{
} else {
$drawer->size($size);
}
$button = DrawerAction::make()->drawer($drawer);
@ -51,12 +44,6 @@ trait CustomActionTrait
/**
* 行编辑按钮
*
* @param string $type
* @param string $size
* @param string $width
*
* @return DialogAction|DrawerAction|LinkAction
*/
protected function rowEditTypeButton(string $type = '', string $size = '', string $width = ''): DialogAction|DrawerAction|LinkAction
{
@ -70,9 +57,9 @@ trait CustomActionTrait
$drawer = Drawer::make()->title(__('admin.edit'))->body($form)->closeOnOutside();
if($width){
if ($width) {
$drawer->width($width);
}else{
} else {
$drawer->size($size);
}
@ -99,12 +86,6 @@ trait CustomActionTrait
/**
* 行详情按钮
*
* @param string $type
* @param string $size
* @param string $width
*
* @return DialogAction|DrawerAction|LinkAction
*/
protected function rowShowTypeButton(string $type = '', string $size = '', string $width = ''): DialogAction|DrawerAction|LinkAction
{
@ -112,15 +93,15 @@ trait CustomActionTrait
case 'drawer':
$drawer = Drawer::make()->title(__('admin.show'))->name('detail_info')->body($this->detail('$id'))->closeOnOutside();
if($width){
if ($width) {
$drawer->width($width);
}else{
} else {
$drawer->size($size);
}
//补充详情操作按钮扩展
try{
try {
$actions = $this->detailActions();
}catch(\BadMethodCallException $e){
} catch (\BadMethodCallException $e) {
$actions = [];
}
$drawer->actions($actions);
@ -130,9 +111,9 @@ trait CustomActionTrait
case 'dialog':
//补充详情操作按钮扩展
$dialog = Dialog::make()->title(__('admin.show'))->name('detail_info')->body($this->detail('$id'))->size($size);
try{
try {
$actions = $this->detailActions();
}catch(\BadMethodCallException $e){
} catch (\BadMethodCallException $e) {
$actions = [];
}
$dialog->actions($actions);

View File

@ -2,10 +2,10 @@
namespace App\Traits;
use Slowlyo\OwlAdmin\Admin;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Slowlyo\OwlAdmin\Admin;
trait UploadTrait
{
@ -27,15 +27,15 @@ trait UploadTrait
$fromWangEditor = false;
$file = request()->file('file');
if (!$file) {
if (! $file) {
$fromWangEditor = true;
$file = request()->file('wangeditor-uploaded-image');
if (!$file) {
if (! $file) {
$file = request()->file('wangeditor-uploaded-video');
}
}
if (!$file) {
if (! $file) {
return $this->response()->additional(['errno' => 1])->fail(__('admin.upload_file_error'));
}
@ -57,16 +57,16 @@ trait UploadTrait
{
$file = request()->file('file');
if (!$file) {
if (! $file) {
return $this->response()->fail(__('admin.upload_file_error'));
}
$path = $file->store(Admin::config('admin.upload.tem_directory.' . $type).'/'.date('Y-m-d'), Admin::config('admin.upload.disk'));
$path = $file->store(Admin::config('admin.upload.tem_directory.'.$type).'/'.date('Y-m-d'), Admin::config('admin.upload.disk'));
return $this->response()->success(['value' => $path]);
}
public function saveImage($field = 'image', $path)
public function saveImage($field, $path)
{
return $this->saveFile($field, $path);
}
@ -74,42 +74,42 @@ trait UploadTrait
/**
* 表单提交时,转存实际目录,并保留上传时文件名称;文件保存全路径
*/
public function saveFile($field = 'file', $path)
public function saveFile($field, $path)
{
$file = request()->file($field);
if (!$file) {
if (! $file) {
$file = request()->get($field);
}
$fileArr = [];
//判断是否多个文件;
if(is_string($file) || isset($file['id'])){
if (is_string($file) || isset($file['id'])) {
$files = [$file];
}else{
} else {
$files = $file;
}
if($files){
foreach($files as $file){
if(is_array($file) && isset($file['state'])){
switch($file['state']){
if ($files) {
foreach ($files as $file) {
if (is_array($file) && isset($file['state'])) {
switch ($file['state']) {
case 'init':
if(strpos($file['value'], 'temporary') !== false){
if (strpos($file['value'], 'temporary') !== false) {
$filePath = $path.'/'.$file['name'];
Storage::disk(Admin::config('admin.upload.disk'))->move($file['value'], $filePath);
$fileArr[] = Storage::disk(Admin::config('admin.upload.disk'))->url($filePath);
}else{
} else {
$fileArr[] = $file['value'];
}
break;
case 'uploaded':
if(isset($file['name'])){
if (isset($file['name'])) {
$filePath = $path.'/'.$file['name'];
if(Str::startsWith($file['value'], ['http://', 'https://'])){
if (Str::startsWith($file['value'], ['http://', 'https://'])) {
$fileUrl = parse_url($file['value']);
$fileValue = ltrim($fileUrl['path'], '/');
}else{
} else {
$fileValue = $file['value'];
}
Storage::disk(Admin::config('admin.upload.disk'))->move($file['value'], $filePath);
@ -117,11 +117,12 @@ trait UploadTrait
}
break;
}
}else{
} else {
$fileArr[] = $file;
}
}
}
return $fileArr;
}
@ -135,8 +136,8 @@ trait UploadTrait
$uploadId = md5(time().$fileName);
//创建临时文件夹
if ( Storage::disk(Admin::config('admin.upload.disk'))->exists(Admin::config('admin.upload.tem_directory.' . $type).'/'.$uploadId) === false ) {
if ( Storage::disk(Admin::config('admin.upload.disk'))->makeDirectory(Admin::config('admin.upload.tem_directory.' . $type).'/'.$uploadId) === false ) {
if (Storage::disk(Admin::config('admin.upload.disk'))->exists(Admin::config('admin.upload.tem_directory.'.$type).'/'.$uploadId) === false) {
if (Storage::disk(Admin::config('admin.upload.disk'))->makeDirectory(Admin::config('admin.upload.tem_directory.'.$type).'/'.$uploadId) === false) {
return false;
}
}
@ -159,14 +160,15 @@ trait UploadTrait
$fileName = $file->getClientOriginalName();
//判断该分片是否已存在,
$dirPath = Admin::config('admin.upload.tem_directory.' . $type).'/'.$uploadId;
if(Storage::disk(Admin::config('admin.upload.disk'))->exists($dirPath . '/'.$fileName.'_'.$partNumber)){
$dirPath = Admin::config('admin.upload.tem_directory.'.$type).'/'.$uploadId;
if (Storage::disk(Admin::config('admin.upload.disk'))->exists($dirPath.'/'.$fileName.'_'.$partNumber)) {
return $this->response()->fail(__('admin.upload_file_error'));
}else{
} else {
//验证分片大小-todo
$path = $file->storeAs($dirPath, $fileName.'_'.$partNumber, Admin::config('admin.upload.disk'));
$realPath = Storage::disk(Admin::config('admin.upload.disk'))->url($path);
$eTag = md5_file($realPath);
return $this->response()->success(['eTag' => $eTag]);
}
}
@ -182,18 +184,18 @@ trait UploadTrait
$uploadId = request()->get('uploadId', '');
$partList = request()->get('partList', []);
$basePath = Admin::config('admin.upload.tem_directory.' . $type).'/'.$uploadId;
$basePath = Admin::config('admin.upload.tem_directory.'.$type).'/'.$uploadId;
$realPath = 'chunk/'.$fileName;
//获取分片列表中序号,查看分片是否都完成上传
$partNumberList = Arr::pluck($partList, 'partNumber');
if(max($partNumberList) === count($partNumberList)){
if (max($partNumberList) === count($partNumberList)) {
//判断是否已存在同名文件,进行删除
if(Storage::disk(Admin::config('admin.upload.disk'))->exists($realPath)){
if (Storage::disk(Admin::config('admin.upload.disk'))->exists($realPath)) {
$realPath = 'chunk/(1)'.$fileName;
}
for($i = 1; $i<=count($partNumberList); $i++){
for ($i = 1; $i <= count($partNumberList); $i++) {
$_file = Storage::disk(Admin::config('admin.upload.disk'))->get($basePath.'/'.$fileName.'_'.$i);
Storage::disk(Admin::config('admin.upload.disk'))->append($realPath, $_file, null);
}
@ -202,8 +204,8 @@ trait UploadTrait
$value = Storage::disk(Admin::config('admin.upload.disk'))->url($realPath);
return $this->response()->success(['value'=>$value]);
}else{
return $this->response()->success(['value' => $value]);
} else {
return $this->response()->fail(__('admin.upload_file_error'));
}
}

View File

@ -54,7 +54,7 @@ return [
],
'upload' => [
'disk' => env("FILESYSTEM_DISK", 'public'),
'disk' => env('FILESYSTEM_DISK', 'public'),
// 文件上传目录
'directory' => [
'image' => 'images',

View File

@ -56,21 +56,21 @@ return [
'throw' => false,
],
"oss" => [
"driver" => "oss",
"access_key_id" => env("OSS_ACCESS_KEY_ID"), // 必填, 阿里云的AccessKeyId
"access_key_secret" => env("OSS_ACCESS_KEY_SECRET"), // 必填, 阿里云的AccessKeySecret
"bucket" => env("OSS_BUCKET"), // 必填, 对象存储的Bucket, 示例: my-bucket
"endpoint" => env("OSS_ENDPOINT"), // 必填, 对象存储的Endpoint, 示例: oss-cn-shanghai.aliyuncs.com
"internal" => env("OSS_INTERNAL", null), // 选填, 内网上传地址,填写即启用 示例: oss-cn-shanghai-internal.aliyuncs.com
"domain" => env("OSS_DOMAIN", null), // 选填, 绑定域名,填写即启用 示例: oss.my-domain.com
"is_cname" => env("OSS_CNAME", false), // 选填, 若Endpoint为自定义域名此项要为truehttps://github.com/aliyun/aliyun-oss-php-sdk/blob/572d0f8e099e8630ae7139ed3fdedb926c7a760f/src/OSS/OssClient.php#L113C1-L122C78
"prefix" => env("OSS_PREFIX", ""), // 选填, 统一存储地址前缀
"use_ssl" => env("OSS_SSL", false), // 选填, 是否使用HTTPS
"reverse_proxy" => env("OSS_REVERSE_PROXY", false), // 选填, 域名是否使用NGINX代理绑定
"throw" => env("OSS_THROW", true), // 选填, 是否抛出引起错误的异常,默认出现错误时,不抛出异常仅返回false
"options" => [], // 选填, 添加全局配置参数, 示例: [\OSS\OssClient::OSS_CHECK_MD5 => false]
"macros" => [] // 选填, 添加自定义Macro, 示例: [\App\Macros\ListBuckets::class, \App\Macros\CreateBucket::class]
'oss' => [
'driver' => 'oss',
'access_key_id' => env('OSS_ACCESS_KEY_ID'), // 必填, 阿里云的AccessKeyId
'access_key_secret' => env('OSS_ACCESS_KEY_SECRET'), // 必填, 阿里云的AccessKeySecret
'bucket' => env('OSS_BUCKET'), // 必填, 对象存储的Bucket, 示例: my-bucket
'endpoint' => env('OSS_ENDPOINT'), // 必填, 对象存储的Endpoint, 示例: oss-cn-shanghai.aliyuncs.com
'internal' => env('OSS_INTERNAL', null), // 选填, 内网上传地址,填写即启用 示例: oss-cn-shanghai-internal.aliyuncs.com
'domain' => env('OSS_DOMAIN', null), // 选填, 绑定域名,填写即启用 示例: oss.my-domain.com
'is_cname' => env('OSS_CNAME', false), // 选填, 若Endpoint为自定义域名此项要为truehttps://github.com/aliyun/aliyun-oss-php-sdk/blob/572d0f8e099e8630ae7139ed3fdedb926c7a760f/src/OSS/OssClient.php#L113C1-L122C78
'prefix' => env('OSS_PREFIX', ''), // 选填, 统一存储地址前缀
'use_ssl' => env('OSS_SSL', false), // 选填, 是否使用HTTPS
'reverse_proxy' => env('OSS_REVERSE_PROXY', false), // 选填, 域名是否使用NGINX代理绑定
'throw' => env('OSS_THROW', true), // 选填, 是否抛出引起错误的异常,默认出现错误时,不抛出异常仅返回false
'options' => [], // 选填, 添加全局配置参数, 示例: [\OSS\OssClient::OSS_CHECK_MD5 => false]
'macros' => [], // 选填, 添加自定义Macro, 示例: [\App\Macros\ListBuckets::class, \App\Macros\CreateBucket::class]
],
],

View File

@ -2,10 +2,9 @@
namespace Database\Seeders;
use Slowlyo\OwlAdmin\Models\AdminMenu;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Slowlyo\OwlAdmin\Models\AdminMenu;
use Throwable;
class AdminMenuSeeder extends Seeder
@ -19,23 +18,23 @@ class AdminMenuSeeder extends Seeder
{
//
$menus = [
['title' => 'index', 'icon' => 'line-md:home-twotone-alt', 'url' => '/index', 'is_home'=>1, 'order'=>1],
['title' => 'admin_system', 'icon' => 'material-symbols:settings-outline', 'url' => '/system', 'order'=>2,
['title' => 'index', 'icon' => 'line-md:home-twotone-alt', 'url' => '/index', 'is_home' => 1, 'order' => 1],
['title' => 'admin_system', 'icon' => 'material-symbols:settings-outline', 'url' => '/system', 'order' => 2,
'children' => [
['title' => 'admin_users', 'icon' => 'ph:user-gear', 'url' => '/system/admin_users', 'order'=>1],
['title' => 'admin_roles', 'icon' => 'carbon:user-role', 'url' => '/system/admin_roles', 'order'=>2],
['title' => 'admin_permission', 'icon' => 'carbon:user-role', 'url' => '/system/admin_permissions', 'order'=>3],
['title' => 'admin_menu', 'icon' => 'fluent-mdl2:permissions', 'url' => '/system/admin_menus', 'order'=>4],
['title' => 'admin_setting', 'icon' => 'akar-icons:settings-horizontal', 'url' => '/system/settings', 'order'=>5],
['title' => 'keywords', 'icon' => 'ph:codesandbox-logo-light', 'url' => '/system/keywords', 'order'=>6]
['title' => 'admin_users', 'icon' => 'ph:user-gear', 'url' => '/system/admin_users', 'order' => 1],
['title' => 'admin_roles', 'icon' => 'carbon:user-role', 'url' => '/system/admin_roles', 'order' => 2],
['title' => 'admin_permission', 'icon' => 'carbon:user-role', 'url' => '/system/admin_permissions', 'order' => 3],
['title' => 'admin_menu', 'icon' => 'fluent-mdl2:permissions', 'url' => '/system/admin_menus', 'order' => 4],
['title' => 'admin_setting', 'icon' => 'akar-icons:settings-horizontal', 'url' => '/system/settings', 'order' => 5],
['title' => 'keywords', 'icon' => 'ph:codesandbox-logo-light', 'url' => '/system/keywords', 'order' => 6],
],
],
['title' => 'web_content', 'icon' => 'ic:outline-collections-bookmark', 'url' => '', 'order' => 3,
'children' => [
['title' => 'articles', 'icon' => 'ic:outline-article', 'url' => '/articles', 'order' => 1],
['title' => 'ads', 'icon' => 'lets-icons:img-box', 'url' => '/ads', 'order' => 2],
],
],
['title' => 'web_content', 'icon' => 'ic:outline-collections-bookmark', 'url' => '', 'order'=>3,
'children' =>[
['title'=>'articles', 'icon'=>'ic:outline-article','url'=>'/articles', 'order'=>1],
['title'=>'ads', 'icon'=>'lets-icons:img-box','url'=>'/ads', 'order'=>2],
]
]
];
DB::table('admin_menus')->truncate();
try {

View File

@ -121,7 +121,7 @@ class AdminPermissionSeeder extends Seeder
{
foreach ($data as $slug => $node) {
$permission = AdminPermission::updateOrCreate([
'slug' => ($parent->slug ?? 'admin') . '.' . $slug,
'slug' => ($parent->slug ?? 'admin').'.'.$slug,
], [
'parent_id' => $parent->id ?? 0,
'name' => is_array($node) ? $node['name'] : $node,
@ -143,7 +143,7 @@ class AdminPermissionSeeder extends Seeder
foreach ($resourceAbilities as $resourceAbility) {
AdminPermission::updateOrCreate([
'slug' => $permission->slug . '.' . $resourceAbility,
'slug' => $permission->slug.'.'.$resourceAbility,
], [
'parent_id' => $permission->id,
'name' => $this->resourceAbilityMap()[$resourceAbility],

View File

@ -34,7 +34,7 @@ class KeywordSeeder extends Seeder
[
'key' => 'job',
'name' => '职位',
'children' => ['普通员工', '小组长', '主管']
'children' => ['普通员工', '小组长', '主管'],
],
[
'key' => 'store_category',
@ -54,7 +54,7 @@ class KeywordSeeder extends Seeder
['name' => '电脑整机'],
['name' => '外设产品'],
['name' => '网络产品'],
]]
]],
],
],
[
@ -86,7 +86,7 @@ class KeywordSeeder extends Seeder
$item['sort'] = $i + 1;
}
$key = Arr::pull($item, 'key', $parent?->key . '_' . ($i + 1));
$key = Arr::pull($item, 'key', $parent?->key.'_'.($i + 1));
/** @var \App\Models\Keyword */
$keyword = Keyword::updateOrCreate(

View File

@ -129,7 +129,7 @@ return [
'fill' => '填充',
'save_current_config' => '保存当前配置',
'input_config_name' => '请填写配置名称',
'same_name_tips' => '相同名称的配置将会被覆盖'
'same_name_tips' => '相同名称的配置将会被覆盖',
],
'admin_users' => '管理员',