generated from liutk/owl-admin-base
Compare commits
No commits in common. "eb4475c88d167a115cd7f60bc432f873fc52b0d0" and "aaacc371f767ff87d7238f98ca05b888bb61d511" have entirely different histories.
eb4475c88d
...
aaacc371f7
|
|
@ -8,7 +8,6 @@ use Slowlyo\OwlAdmin\Renderers\Page;
|
||||||
use Slowlyo\OwlAdmin\Renderers\Form;
|
use Slowlyo\OwlAdmin\Renderers\Form;
|
||||||
use App\Enums\EmployeeStatus;
|
use App\Enums\EmployeeStatus;
|
||||||
use App\Models\Employee;
|
use App\Models\Employee;
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
class EmployeeController extends AdminController
|
class EmployeeController extends AdminController
|
||||||
{
|
{
|
||||||
|
|
@ -33,18 +32,15 @@ class EmployeeController extends AdminController
|
||||||
amisMake()->TableColumn()->name('id')->label(__('employee.id')),
|
amisMake()->TableColumn()->name('id')->label(__('employee.id')),
|
||||||
amisMake()->TableColumn()->name('name')->label(__('employee.name')),
|
amisMake()->TableColumn()->name('name')->label(__('employee.name')),
|
||||||
amisMake()->TableColumn()->name('phone')->label(__('employee.phone')),
|
amisMake()->TableColumn()->name('phone')->label(__('employee.phone')),
|
||||||
|
// amisMake()->TableColumn()->name('employee_status_text')->label(__('employee.employee_status')),
|
||||||
|
|
||||||
amisMake()->TableColumn()->name('employee_status_text')->label(__('employee.employee_status'))->set('type', 'tag')->set('color', '${employee_status_color}'),
|
amisMake()->TableColumn()->name('employee_status_text')->label(__('employee.employee_status'))->set('type', 'tag')->set('color', '${employee_status_color}'),
|
||||||
|
|
||||||
amisMake()->TableColumn()->name('created_at')->label(__('employee.created_at')),
|
amisMake()->TableColumn()->name('created_at')->label(__('employee.created_at')),
|
||||||
$this->rowActions([
|
$this->rowActions([
|
||||||
$this->rowShowButton(),
|
$this->rowShowButton(),
|
||||||
$this->rowEditButton(true),
|
$this->rowEditButton(true),
|
||||||
$this->rowDeleteButton(),
|
$this->rowDeleteButton(),
|
||||||
amisMake()->AjaxAction()
|
|
||||||
->label(__('employee.leave'))
|
|
||||||
->level('link')
|
|
||||||
->icon('fa fa-sign-out')
|
|
||||||
->confirmText(__('employee.leave_confirm'))
|
|
||||||
->api('post:' . admin_url('hr/employees/${id}/leave')),
|
|
||||||
]),
|
]),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
@ -62,7 +58,8 @@ class EmployeeController extends AdminController
|
||||||
->labelField('name')
|
->labelField('name')
|
||||||
->valueField('key')
|
->valueField('key')
|
||||||
->joinValues(),
|
->joinValues(),
|
||||||
amisMake()->DateControl()->name('join_at')->label(__('employee.join_at'))->format('YYYY-MM-DD'),
|
|
||||||
|
amisMake()->SelectControl()->name('employee_status')->label(__('employee.employee_status'))->options(EmployeeStatus::options()),
|
||||||
amisMake()->TextControl()->name('username')->label(__('admin.username'))->value('${admin_user.username}')->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('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('confirm_password')->set('type', 'input-password')->label(__('admin.confirm_password'))->required(!$edit),
|
||||||
|
|
@ -74,24 +71,10 @@ class EmployeeController extends AdminController
|
||||||
return $this->baseDetail()->title('')->body(amisMake()->Property()->items([
|
return $this->baseDetail()->title('')->body(amisMake()->Property()->items([
|
||||||
['label' => __('employee.name'), 'content' => '${name}'],
|
['label' => __('employee.name'), 'content' => '${name}'],
|
||||||
['label' => __('employee.phone'), 'content' => '${phone}'],
|
['label' => __('employee.phone'), 'content' => '${phone}'],
|
||||||
['label' => __('employee.jobs'), 'content' => amisMake()->Each()->name('jobs')->items(amisMake()->Tag()->label('${name}'))],
|
['label' => __('employee.jobs'), 'content' => amisMake()->TagControl()->size('full')->name('jobs')->labelField('name')->valueField('key')->joinValues()->static()],
|
||||||
|
|
||||||
['label' => __('admin.username'), 'content' => '${admin_user.username}'],
|
['label' => __('admin.username'), 'content' => '${admin_user.username}'],
|
||||||
['label' => __('employee.employee_status'), 'content' => amisMake()->Tag()->label('${employee_status_text}')->color('${employee_status_color}')],
|
['label' => __('employee.employee_status'), 'content' => amisMake()->Tag()->label('${employee_status_text}')->color('${employee_status_color}')],
|
||||||
['label' => __('employee.join_at'), 'content' => '${join_at}'],
|
|
||||||
['label' => __('employee.leave_at'), 'content' => '${leave_at}'],
|
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 员工离职
|
|
||||||
public function leave($id, Request $request)
|
|
||||||
{
|
|
||||||
$user = Employee::findOrFail($id);
|
|
||||||
$user->update([
|
|
||||||
'leave_at' => $request->input('leave_at', now()),
|
|
||||||
'employee_status' => EmployeeStatus::Offline,
|
|
||||||
]);
|
|
||||||
|
|
||||||
return $this->response()->success(null, '操作成功');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,109 +3,7 @@
|
||||||
namespace App\Admin\Controllers\Store;
|
namespace App\Admin\Controllers\Store;
|
||||||
|
|
||||||
use Slowlyo\OwlAdmin\Controllers\AdminController;
|
use Slowlyo\OwlAdmin\Controllers\AdminController;
|
||||||
use App\Services\Admin\StoreService;
|
|
||||||
use Slowlyo\OwlAdmin\Renderers\Page;
|
|
||||||
use Slowlyo\OwlAdmin\Renderers\Form;
|
|
||||||
|
|
||||||
class StoreController extends AdminController
|
class StoreController extends AdminController
|
||||||
{
|
{
|
||||||
protected string $serviceName = StoreService::class;
|
|
||||||
|
|
||||||
public function list(): Page
|
|
||||||
{
|
|
||||||
$crud = $this->baseCRUD()
|
|
||||||
->tableLayout('fixed')
|
|
||||||
->headerToolbar([
|
|
||||||
$this->createButton(),
|
|
||||||
...$this->baseHeaderToolBar(),
|
|
||||||
])
|
|
||||||
->filter($this->baseFilter()->body([
|
|
||||||
amis()->GroupControl()->mode('horizontal')->body([
|
|
||||||
amisMake()->TextControl()->name('title')->label(__('store.title'))->columnRatio(3)->clearable(),
|
|
||||||
amisMake()->SelectControl()->name('category_id')->label(__('store.category_id'))->columnRatio(3)
|
|
||||||
->source(admin_url('api/keywords/tree-list?parent_key=store_category'))
|
|
||||||
->labelField('name')
|
|
||||||
->valueField('key')
|
|
||||||
->onlyLeaf(true)
|
|
||||||
->clearable(),
|
|
||||||
amisMake()->SelectControl()->name('business_id')->label(__('store.business_id'))->columnRatio(3)
|
|
||||||
->source(admin_url('api/keywords/tree-list?parent_key=store_business'))
|
|
||||||
->labelField('name')
|
|
||||||
->valueField('key')
|
|
||||||
->clearable(),
|
|
||||||
]),
|
|
||||||
amisMake()->GroupControl()->mode('horizontal')->body([
|
|
||||||
amisMake()->SelectControl()->name('level_id')->label(__('store.level_id'))->columnRatio(3)
|
|
||||||
->source(admin_url('api/keywords/tree-list?parent_key=store_level'))
|
|
||||||
->labelField('name')
|
|
||||||
->valueField('key')
|
|
||||||
->clearable(),
|
|
||||||
amisMake()->InputCityControl()->name('region')->label(__('store.region'))->columnRatio(3)
|
|
||||||
->allowDistrict(false)
|
|
||||||
->extractValue(false)
|
|
||||||
->clearable(),
|
|
||||||
amisMake()->SelectControl()->name('business_status')->label(__('store.business_status'))->columnRatio(3)->clearable(),
|
|
||||||
])
|
|
||||||
]))
|
|
||||||
->columns([
|
|
||||||
amisMake()->TableColumn()->name('id')->label(__('store.id')),
|
|
||||||
amisMake()->TableColumn()->name('title')->label(__('store.title')),
|
|
||||||
amisMake()->TableColumn()->name('category.name')->label(__('store.category_id')),
|
|
||||||
amisMake()->TableColumn()->name('business.name')->label(__('store.business_id')),
|
|
||||||
amisMake()->TableColumn()->name('level.name')->label(__('store.level_id')),
|
|
||||||
amisMake()->TableColumn()->name('region')->label(__('store.region'))->set('type', 'tpl')->set('tpl', '${region.province}-${region.city}'),
|
|
||||||
amisMake()->TableColumn()->name('business_status_text')->label(__('store.business_status'))->set('type', 'tag')->set('color', '${business_status_color}'),
|
|
||||||
amisMake()->TableColumn()->name('created_at')->label(__('store.created_at')),
|
|
||||||
$this->rowActions([
|
|
||||||
$this->rowShowButton(),
|
|
||||||
$this->rowEditButton(),
|
|
||||||
$this->rowDeleteButton(),
|
|
||||||
]),
|
|
||||||
]);
|
|
||||||
return $this->baseList($crud);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function form($edit): Form
|
|
||||||
{
|
|
||||||
return $this->baseForm()->title('')->body([
|
|
||||||
amisMake()->TextControl()->name('title')->label(__('store.title'))->required(),
|
|
||||||
amisMake()->SelectControl()->name('master_id')->label(__('store.master_id'))
|
|
||||||
->source(admin_url('hr/employees?_action=getData'))
|
|
||||||
->labelField('name')
|
|
||||||
->valueField('id')
|
|
||||||
->required(),
|
|
||||||
amisMake()->TreeSelectControl()->name('category_id')->label(__('store.category_id'))
|
|
||||||
->source(admin_url('api/keywords/tree-list?parent_key=store_category'))
|
|
||||||
->labelField('name')
|
|
||||||
->valueField('key')
|
|
||||||
->onlyLeaf(true)
|
|
||||||
->required(),
|
|
||||||
amisMake()->SelectControl()->name('business_id')->label(__('store.business_id'))
|
|
||||||
->source(admin_url('api/keywords/tree-list?parent_key=store_business'))
|
|
||||||
->labelField('name')
|
|
||||||
->valueField('key')
|
|
||||||
->required(),
|
|
||||||
amisMake()->SelectControl()->name('level_id')->label(__('store.level_id'))
|
|
||||||
->source(admin_url('api/keywords/tree-list?parent_key=store_level'))
|
|
||||||
->labelField('name')
|
|
||||||
->valueField('key')
|
|
||||||
->required(),
|
|
||||||
amisMake()->InputCityControl()->name('region')->label(__('store.region'))->allowDistrict(false)->extractValue(false)->required(),
|
|
||||||
amisMake()->LocationControl()->name('location')->label(__('store.location'))->ak('Qa9sxstHlyBIDfb3SjrR3Uli39yRjB6X')->autoSelectCurrentLoc(),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function detail(): Form
|
|
||||||
{
|
|
||||||
return $this->baseDetail()->title('')->body(amisMake()->Property()->items([
|
|
||||||
['label' => __('store.title'), 'content' => '${title}'],
|
|
||||||
['label' => __('store.master_id'), 'content' => '${master.name}'],
|
|
||||||
['label' => __('store.business_status'), 'content' => amisMake()->Tag()->label('${business_status_text}')->color('${business_status_color}')],
|
|
||||||
['label' => __('store.category_id'), 'content' => '${category.name}'],
|
|
||||||
['label' => __('store.business_id'), 'content' => '${business.name}'],
|
|
||||||
['label' => __('store.level_id'), 'content' => '${level.name}'],
|
|
||||||
['label' => __('store.region'), 'content' => '${region.province}-${region.city}'],
|
|
||||||
['label' => __('store.profit_ratio'), 'content' => '${profit_ratio}%'],
|
|
||||||
]));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,6 @@ Route::group([
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
$router->resource('hr/employees', \App\Admin\Controllers\Hr\EmployeeController::class);
|
$router->resource('hr/employees', \App\Admin\Controllers\Hr\EmployeeController::class);
|
||||||
$router->post('hr/employees/{id}/leave', [\App\Admin\Controllers\Hr\EmployeeController::class, 'leave']);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -1,47 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Enums;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 营业状态
|
|
||||||
*/
|
|
||||||
enum BusinessStatus: int
|
|
||||||
{
|
|
||||||
case Open = 1;
|
|
||||||
case Close = 2;
|
|
||||||
|
|
||||||
public static function map()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
self::Open->value => '开业',
|
|
||||||
self::Close->value => '关闭',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function coplorMap()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
self::Open->value => 'success',
|
|
||||||
self::Close->value => 'warning',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function options()
|
|
||||||
{
|
|
||||||
$list = [];
|
|
||||||
foreach (self::map() as $key => $value) {
|
|
||||||
array_push($list, ['label' => $value, 'value' => $key]);
|
|
||||||
}
|
|
||||||
return $list;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function text()
|
|
||||||
{
|
|
||||||
return data_get(self::map(), $this->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function color()
|
|
||||||
{
|
|
||||||
return data_get(self::coplorMap(), $this->value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -2,9 +2,6 @@
|
||||||
|
|
||||||
namespace App\Enums;
|
namespace App\Enums;
|
||||||
|
|
||||||
/**
|
|
||||||
* 员工状态
|
|
||||||
*/
|
|
||||||
enum EmployeeStatus: int
|
enum EmployeeStatus: int
|
||||||
{
|
{
|
||||||
case Online = 1;
|
case Online = 1;
|
||||||
|
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Enums;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 店员身份
|
|
||||||
*/
|
|
||||||
enum StoreRole: int
|
|
||||||
{
|
|
||||||
case Master = 1;
|
|
||||||
case Employee = 2;
|
|
||||||
|
|
||||||
public static function map()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
self::Master->value => '店长',
|
|
||||||
self::Employee->value => '店员',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function options()
|
|
||||||
{
|
|
||||||
$list = [];
|
|
||||||
foreach (self::map() as $key => $value) {
|
|
||||||
array_push($list, ['label' => $value, 'value' => $key]);
|
|
||||||
}
|
|
||||||
return $list;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function text()
|
|
||||||
{
|
|
||||||
return data_get(self::map(), $this->value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -3,10 +3,10 @@
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use EloquentFilter\Filterable;
|
||||||
use App\Enums\EmployeeStatus;
|
use App\Enums\EmployeeStatus;
|
||||||
use Slowlyo\OwlAdmin\Models\AdminUser;
|
use Slowlyo\OwlAdmin\Models\AdminUser;
|
||||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||||
use EloquentFilter\Filterable;
|
|
||||||
use App\Traits\HasDateTimeFormatter;
|
use App\Traits\HasDateTimeFormatter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -18,14 +18,12 @@ class Employee extends Model
|
||||||
|
|
||||||
const JOB_KEY = 'job';
|
const JOB_KEY = 'job';
|
||||||
|
|
||||||
protected $fillable = ['name', 'phone', 'prize_images', 'skill_images', 'employee_status', 'admin_user_id', 'leave_at', 'join_at'];
|
protected $fillable = ['name', 'phone', 'prize_images', 'skill_images', 'employee_status', 'admin_user_id'];
|
||||||
|
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'employee_status' => EmployeeStatus::class,
|
'employee_status' => EmployeeStatus::class,
|
||||||
'prize_images' => 'json',
|
'prize_images' => 'json',
|
||||||
'skill_images' => 'json',
|
'skill_images' => 'json',
|
||||||
'leave_at' => 'datetime',
|
|
||||||
'join_at' => 'date:Y-m-d',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $attributes = [
|
protected $attributes = [
|
||||||
|
|
@ -47,13 +45,6 @@ class Employee extends Model
|
||||||
return $this->belongsTo(AdminUser::class, 'admin_user_id');
|
return $this->belongsTo(AdminUser::class, 'admin_user_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 关联的门店
|
|
||||||
public function stores()
|
|
||||||
{
|
|
||||||
// role(1: 店长, 2: 店员)
|
|
||||||
return $this->belongsToMany(Store::class, 'store_employees', 'employee_id', 'store_id')->withPivot(['role']);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function employeeStatusText(): Attribute
|
protected function employeeStatusText(): Attribute
|
||||||
{
|
{
|
||||||
return new Attribute(
|
return new Attribute(
|
||||||
|
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models\Filters;
|
|
||||||
|
|
||||||
use EloquentFilter\ModelFilter;
|
|
||||||
|
|
||||||
class StoreFilter extends ModelFilter
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
@ -1,72 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 门店
|
|
||||||
*/
|
|
||||||
class Store extends Model
|
|
||||||
{
|
|
||||||
use Filterable, HasDateTimeFormatter;
|
|
||||||
|
|
||||||
protected $fillable = ['title', 'master_id', 'category_id', 'business_id', 'level_id', 'region', 'lon', 'lat', 'profit_ratio', 'profit_money', 'business_status'];
|
|
||||||
|
|
||||||
protected $casts = [
|
|
||||||
// 地区 {province: 四川省, city: 成都市}
|
|
||||||
'region' => 'json',
|
|
||||||
'business_status' => BusinessStatus::class,
|
|
||||||
];
|
|
||||||
|
|
||||||
protected $appends = ['business_status_text', 'business_status_color'];
|
|
||||||
|
|
||||||
// 店长
|
|
||||||
public function master()
|
|
||||||
{
|
|
||||||
return $this->belongsTo(Employee::class, 'master_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 门店分类
|
|
||||||
public function category()
|
|
||||||
{
|
|
||||||
return $this->belongsTo(Keyword::class, 'category_id', 'key');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 经验分类
|
|
||||||
public function business()
|
|
||||||
{
|
|
||||||
return $this->belongsTo(Keyword::class, 'business_id', 'key');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 门店等级
|
|
||||||
public function level()
|
|
||||||
{
|
|
||||||
return $this->belongsTo(Keyword::class, 'level_id', 'key');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 门店员工
|
|
||||||
public function employees()
|
|
||||||
{
|
|
||||||
// role(1: 店长, 2: 店员)
|
|
||||||
return $this->belongsToMany(Employee::class, 'store_employees', 'store_id', 'employee_id')->withPivot(['role']);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function businessStatusText(): Attribute
|
|
||||||
{
|
|
||||||
return new Attribute(
|
|
||||||
get: fn () => $this->business_status ? $this->business_status->text() : '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function businessStatusColor(): Attribute
|
|
||||||
{
|
|
||||||
return new Attribute(
|
|
||||||
get: fn () => $this->business_status ? $this->business_status->color() : '',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -91,7 +91,7 @@ class EmployeeService extends BaseService
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理职位关联
|
* 处理职位
|
||||||
*
|
*
|
||||||
* @param Employee $model
|
* @param Employee $model
|
||||||
* @param array $jobs(字典表 key 组成的数组)
|
* @param array $jobs(字典表 key 组成的数组)
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ class KeywordService extends BaseService
|
||||||
|
|
||||||
public function getTree()
|
public function getTree()
|
||||||
{
|
{
|
||||||
$list = $this->query()->filter(request()->all(), $this->modelFilterName)->get();
|
$list = $this->query()->filter(request()->all(), $this->modelFilterName)->orderByDesc('sort')->get();
|
||||||
$minNum = $list->min('parent_id');
|
$minNum = $list->min('parent_id');
|
||||||
return !$list->isEmpty() ? array2tree($list->toArray(), $minNum) :[];
|
return !$list->isEmpty() ? array2tree($list->toArray(), $minNum) :[];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,88 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Services\Admin;
|
|
||||||
|
|
||||||
use App\Models\Store;
|
|
||||||
use App\Models\Filters\StoreFilter;
|
|
||||||
use App\Enums\StoreRole;
|
|
||||||
use Illuminate\Support\Facades\Validator;
|
|
||||||
use Illuminate\Validation\Rule;
|
|
||||||
|
|
||||||
class StoreService extends BaseService
|
|
||||||
{
|
|
||||||
protected array $withRelationships = ['category', 'level', 'business', 'master'];
|
|
||||||
|
|
||||||
protected string $modelName = Store::class;
|
|
||||||
|
|
||||||
protected string $modelFilterName = StoreFilter::class;
|
|
||||||
|
|
||||||
public function store($data): bool
|
|
||||||
{
|
|
||||||
$data = $this->resloveData($data);
|
|
||||||
|
|
||||||
$validate = $this->validate($data);
|
|
||||||
if ($validate !== true) {
|
|
||||||
$this->setError($validate);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$model = $this->modelName::create($data);
|
|
||||||
|
|
||||||
// 设置店长
|
|
||||||
$model->employees()->attach([$data['master_id'] => ['role' => StoreRole::Master]]);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function update($primaryKey, $data): bool
|
|
||||||
{
|
|
||||||
$model = $this->query()->whereKey($primaryKey)->firstOrFail();
|
|
||||||
$data = $this->resloveData($data, $model);
|
|
||||||
$validate = $this->validate($data, $model);
|
|
||||||
if ($validate !== true) {
|
|
||||||
$this->setError($validate);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 修改店长
|
|
||||||
if (isset($data['master_id']) && $data['master_id'] != $model->master_id) {
|
|
||||||
$store->employees()->detach($model->master_id);
|
|
||||||
$store->employees()->attach([$data['master_id'] => ['role' => StoreRole::Master]]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $model->update($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function resloveData($data, $model = null)
|
|
||||||
{
|
|
||||||
if (isset($data['location'])) {
|
|
||||||
$data['lon'] = data_get($data['location'], 'lng');
|
|
||||||
$data['lat'] = data_get($data['location'], 'lat');
|
|
||||||
}
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function validate($data, $model = null)
|
|
||||||
{
|
|
||||||
$createRules = [
|
|
||||||
'title' => ['required'],
|
|
||||||
'master_id' => ['required', Rule::unique('stores', 'master_id')],
|
|
||||||
'category_id' => ['required'],
|
|
||||||
'business_id' => ['required'],
|
|
||||||
'level_id' => ['required'],
|
|
||||||
'region' => ['required'],
|
|
||||||
'lon' => ['required'],
|
|
||||||
'lat' => ['required'],
|
|
||||||
];
|
|
||||||
$updateRules = [
|
|
||||||
'master_id' => [Rule::unique($model, 'master_id')]
|
|
||||||
];
|
|
||||||
$validator = Validator::make($data, $model ? $updateRules : $createRules, [
|
|
||||||
'master_id.unique' => '已经是店长了',
|
|
||||||
]);
|
|
||||||
if ($validator->fails()) {
|
|
||||||
return $validator->errors()->first();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -19,8 +19,6 @@ return new class extends Migration
|
||||||
$table->json('skill_images')->nullable()->comment('专业证书');
|
$table->json('skill_images')->nullable()->comment('专业证书');
|
||||||
$table->unsignedInteger('employee_status')->default(1)->comment('员工状态{1: 在职, 2: 离职}');
|
$table->unsignedInteger('employee_status')->default(1)->comment('员工状态{1: 在职, 2: 离职}');
|
||||||
$table->foreignId('admin_user_id')->comment('登录信息, 关联 admin_users.id');
|
$table->foreignId('admin_user_id')->comment('登录信息, 关联 admin_users.id');
|
||||||
$table->timestamp('join_at')->nullable()->comment('入职时间');
|
|
||||||
$table->timestamp('leave_at')->nullable()->comment('离职时间');
|
|
||||||
|
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,47 +0,0 @@
|
||||||
<?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('stores', function (Blueprint $table) {
|
|
||||||
$table->id();
|
|
||||||
$table->string('title')->comment('名称');
|
|
||||||
$table->foreignId('master_id')->comment('店长, employees.id');
|
|
||||||
$table->string('category_id')->comment('门店分类, keywords.store_category');
|
|
||||||
$table->string('business_id')->comment('经营分类, keywords.store_business');
|
|
||||||
$table->string('level_id')->comment('门店等级, keywords.store_level');
|
|
||||||
$table->json('region')->comment('地区{province,city}');
|
|
||||||
$table->string('lon')->comment('精度');
|
|
||||||
$table->string('lat')->comment('纬度');
|
|
||||||
$table->unsignedInteger('profit_ratio')->default(0)->comment('佣金比例(0-100)');
|
|
||||||
$table->decimal('profit_money')->default(0)->comment('累计佣金');
|
|
||||||
$table->string('business_status')->default(1)->comment('营业状态{1: 开业, 2: 关闭}');
|
|
||||||
$table->timestamps();
|
|
||||||
$table->comment('门店');
|
|
||||||
});
|
|
||||||
|
|
||||||
Schema::create('store_employees', function (Blueprint $table) {
|
|
||||||
$table->foreignId('store_id');
|
|
||||||
$table->foreignId('employee_id');
|
|
||||||
$table->unsignedInteger('role')->default(1)->comment('身份(1: 店长, 2: 店员)');
|
|
||||||
$table->comment('门店-店员');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*/
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
Schema::dropIfExists('stores');
|
|
||||||
Schema::dropIfExists('store_employees');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
@ -35,38 +35,7 @@ class KeywordSeeder extends Seeder
|
||||||
'key' => 'job',
|
'key' => 'job',
|
||||||
'name' => '职位',
|
'name' => '职位',
|
||||||
'children' => ['普通员工', '小组长', '主管']
|
'children' => ['普通员工', '小组长', '主管']
|
||||||
],
|
]
|
||||||
[
|
|
||||||
'key' => 'store_category',
|
|
||||||
'name' => '门店分类',
|
|
||||||
'children' => [
|
|
||||||
['name' => '家用电器', 'children' => [
|
|
||||||
['name' => '电视'],
|
|
||||||
['name' => '冰箱'],
|
|
||||||
['name' => '洗衣机'],
|
|
||||||
]],
|
|
||||||
['name' => '手机数码', 'children' => [
|
|
||||||
['name' => '手机'],
|
|
||||||
['name' => '手机配件'],
|
|
||||||
['name' => '摄影摄像'],
|
|
||||||
]],
|
|
||||||
['name' => '电脑办公', 'children' => [
|
|
||||||
['name' => '电脑整机'],
|
|
||||||
['name' => '外设产品'],
|
|
||||||
['name' => '网络产品'],
|
|
||||||
]]
|
|
||||||
],
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'key' => 'store_business',
|
|
||||||
'name' => '门店经营分类',
|
|
||||||
'children' => ['直营', '代理'],
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'key' => 'store_level',
|
|
||||||
'name' => '门店等级',
|
|
||||||
'children' => ['AAA', 'AA', 'A', 'B', 'C', '无'],
|
|
||||||
],
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->insertKeywors($keywords);
|
$this->insertKeywors($keywords);
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,4 @@ return [
|
||||||
'employee_status' => '状态',
|
'employee_status' => '状态',
|
||||||
'admin_user_id' => '关联账户',
|
'admin_user_id' => '关联账户',
|
||||||
'jobs' => '职位',
|
'jobs' => '职位',
|
||||||
'leave_at' => '离职时间',
|
|
||||||
'leave' => '离职',
|
|
||||||
'join_at' => '入职时间',
|
|
||||||
'leave_confirm' => '是否确定?',
|
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
return [
|
|
||||||
'id' => 'ID',
|
|
||||||
'created_at' => '创建时间',
|
|
||||||
'updated_at' => '更新时间',
|
|
||||||
'title' => '店名',
|
|
||||||
'master_id' => '店长',
|
|
||||||
'category_id' => '门店分类',
|
|
||||||
'business_id' => '经营分类',
|
|
||||||
'level_id' => '门店等级',
|
|
||||||
'region' => '地区',
|
|
||||||
'lon' => '经度',
|
|
||||||
'lat' => '维度',
|
|
||||||
'location' => '坐标',
|
|
||||||
'profit_ratio' => '佣金比例',
|
|
||||||
'profit_money' => '店长提成',
|
|
||||||
'business_status' => '状态',
|
|
||||||
];
|
|
||||||
Loading…
Reference in New Issue