generated from liutk/owl-admin-base
Compare commits
No commits in common. "98b13587c77f51a6a8d2dcacf7391302f7ff479b" and "495824eb8da84ef9a6cb665de688ba3e07329cee" have entirely different histories.
98b13587c7
...
495824eb8d
|
|
@ -6,7 +6,8 @@ use App\Admin\Services\EmployeeService;
|
||||||
use App\Enums\EmployeeStatus;
|
use App\Enums\EmployeeStatus;
|
||||||
use App\Models\Employee;
|
use App\Models\Employee;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Admin\Controllers\AdminController;
|
use Slowlyo\OwlAdmin\Admin;
|
||||||
|
use Slowlyo\OwlAdmin\Controllers\AdminController;
|
||||||
use Slowlyo\OwlAdmin\Renderers\Form;
|
use Slowlyo\OwlAdmin\Renderers\Form;
|
||||||
use Slowlyo\OwlAdmin\Renderers\Page;
|
use Slowlyo\OwlAdmin\Renderers\Page;
|
||||||
|
|
||||||
|
|
@ -34,17 +35,9 @@ 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')->label(__('employee.employee_status'))
|
amisMake()->TableColumn()->name('employee_status_text')->label(__('employee.employee_status'))->set('type', 'tag')->set('color', '${employee_status_color}'),
|
||||||
->type('switch')
|
|
||||||
->trueValue(EmployeeStatus::Online)
|
|
||||||
->falseValue(EmployeeStatus::Offline),
|
|
||||||
amisMake()->TableColumn()->name('created_at')->label(__('employee.created_at')),
|
amisMake()->TableColumn()->name('created_at')->label(__('employee.created_at')),
|
||||||
$this->rowActions([
|
$this->rowActions([
|
||||||
<<<<<<< HEAD
|
|
||||||
$this->rowShowButton(),
|
|
||||||
$this->rowEditButton(true),
|
|
||||||
$this->rowDeleteButton(),
|
|
||||||
=======
|
|
||||||
$this->rowShowButton()->visible(Admin::user()->can('admin.hr.employees.view')),
|
$this->rowShowButton()->visible(Admin::user()->can('admin.hr.employees.view')),
|
||||||
$this->rowEditButton(true)->visible(Admin::user()->can('admin.hr.employees.update')),
|
$this->rowEditButton(true)->visible(Admin::user()->can('admin.hr.employees.update')),
|
||||||
$this->rowDeleteButton()->visible(Admin::user()->can('admin.hr.employees.delete')),
|
$this->rowDeleteButton()->visible(Admin::user()->can('admin.hr.employees.delete')),
|
||||||
|
|
@ -55,7 +48,6 @@ class EmployeeController extends AdminController
|
||||||
->confirmText(__('employee.leave_confirm'))
|
->confirmText(__('employee.leave_confirm'))
|
||||||
->api('post:'.admin_url('hr/employees/${id}/leave'))
|
->api('post:'.admin_url('hr/employees/${id}/leave'))
|
||||||
->visible(Admin::user()->can('admin.hr.employees.leave')),
|
->visible(Admin::user()->can('admin.hr.employees.leave')),
|
||||||
>>>>>>> 495824eb8da84ef9a6cb665de688ba3e07329cee
|
|
||||||
]),
|
]),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
@ -68,26 +60,15 @@ class EmployeeController extends AdminController
|
||||||
amisMake()->TextControl()->name('name')->label(__('employee.name'))->required(),
|
amisMake()->TextControl()->name('name')->label(__('employee.name'))->required(),
|
||||||
amisMake()->TextControl()->name('phone')->label(__('employee.phone'))->required(),
|
amisMake()->TextControl()->name('phone')->label(__('employee.phone'))->required(),
|
||||||
|
|
||||||
amisMake()->SelectControl()->name('employee_status')->label(__('employee.employee_status'))->options(EmployeeStatus::options())->required(),
|
|
||||||
amisMake()->TagControl()->name('jobs')->label(__('employee.jobs'))
|
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')
|
->labelField('name')
|
||||||
->valueField('key')
|
->valueField('key')
|
||||||
->joinValues(),
|
->joinValues(),
|
||||||
amisMake()->DateControl()->name('join_at')->label(__('employee.join_at'))->format('YYYY-MM-DD'),
|
amisMake()->DateControl()->name('join_at')->label(__('employee.join_at'))->format('YYYY-MM-DD'),
|
||||||
amisMake()->ImageControl()->name('prize_images')->label(__('employee.prize_images'))
|
amisMake()->TextControl()->name('username')->label(__('admin.username'))->value('${admin_user.username}')->required(! $edit),
|
||||||
->multiple()
|
amisMake()->TextControl()->name('password')->set('type', 'input-password')->label(__('admin.password'))->required(! $edit),
|
||||||
->receiver($this->uploadImagePath() . '?full-url=1')
|
amisMake()->TextControl()->name('confirm_password')->set('type', 'input-password')->label(__('admin.confirm_password'))->required(! $edit),
|
||||||
->joinValues(false)
|
|
||||||
->extractValue(true),
|
|
||||||
amisMake()->ImageControl()->name('skill_images')->label(__('employee.skill_images'))
|
|
||||||
->multiple()
|
|
||||||
->receiver($this->uploadImagePath() . '?full-url=1')
|
|
||||||
->joinValues(false)
|
|
||||||
->extractValue(true),
|
|
||||||
amisMake()->TextControl()->name('username')->label(__('admin.username'))->value('${admin_user.username}')->visible(! $edit)->required(! $edit),
|
|
||||||
amisMake()->TextControl()->name('password')->set('type', 'input-password')->label(__('admin.password'))->visible(! $edit)->required(! $edit),
|
|
||||||
amisMake()->TextControl()->name('confirm_password')->set('type', 'input-password')->label(__('admin.confirm_password'))->visible(! $edit)->required(! $edit),
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -98,12 +79,22 @@ class EmployeeController extends AdminController
|
||||||
['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()->Each()->name('jobs')->items(amisMake()->Tag()->label('${name}'))],
|
||||||
|
|
||||||
|
['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.join_at'), 'content' => '${join_at}'],
|
||||||
['label' => __('employee.leave_at'), 'content' => '${leave_at}'],
|
['label' => __('employee.leave_at'), 'content' => '${leave_at}'],
|
||||||
['label' => __('admin.username'), 'content' => '${admin_user.username}', 'span' => 3],
|
|
||||||
['label' => __('employee.prize_images'), 'content' => amisMake()->Images()->source('${prize_images}')->enlargeAble(), 'span' => 3],
|
|
||||||
['label' => __('employee.skill_images'), 'content' => amisMake()->Images()->source('${skill_images}')->enlargeAble(), 'span' => 3],
|
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 员工离职
|
||||||
|
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, '操作成功');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,18 +2,12 @@
|
||||||
|
|
||||||
namespace App\Admin\Controllers\Store;
|
namespace App\Admin\Controllers\Store;
|
||||||
|
|
||||||
use App\Models\{Store, Employee};
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use App\Enums\{BusinessStatus, StoreRole};
|
|
||||||
use App\Admin\Services\StoreService;
|
use App\Admin\Services\StoreService;
|
||||||
|
use Slowlyo\OwlAdmin\Admin;
|
||||||
|
use Slowlyo\OwlAdmin\Controllers\AdminController;
|
||||||
use Slowlyo\OwlAdmin\Renderers\Form;
|
use Slowlyo\OwlAdmin\Renderers\Form;
|
||||||
use Slowlyo\OwlAdmin\Renderers\Page;
|
use Slowlyo\OwlAdmin\Renderers\Page;
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use App\Admin\Controllers\AdminController;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 门店管理
|
|
||||||
*/
|
|
||||||
class StoreController extends AdminController
|
class StoreController extends AdminController
|
||||||
{
|
{
|
||||||
protected string $serviceName = StoreService::class;
|
protected string $serviceName = StoreService::class;
|
||||||
|
|
@ -30,7 +24,7 @@ class StoreController extends AdminController
|
||||||
->filter($this->baseFilter()->body([
|
->filter($this->baseFilter()->body([
|
||||||
amis()->GroupControl()->mode('horizontal')->body([
|
amis()->GroupControl()->mode('horizontal')->body([
|
||||||
amisMake()->TextControl()->name('title')->label(__('store.title'))->columnRatio(3)->clearable(),
|
amisMake()->TextControl()->name('title')->label(__('store.title'))->columnRatio(3)->clearable(),
|
||||||
amisMake()->TreeSelectControl()->name('category_id')->label(__('store.category_id'))->columnRatio(3)
|
amisMake()->SelectControl()->name('category_id')->label(__('store.category_id'))->columnRatio(3)
|
||||||
->source(admin_url('api/keywords/tree-list?parent_key=store_category'))
|
->source(admin_url('api/keywords/tree-list?parent_key=store_category'))
|
||||||
->labelField('name')
|
->labelField('name')
|
||||||
->valueField('key')
|
->valueField('key')
|
||||||
|
|
@ -48,11 +42,11 @@ class StoreController extends AdminController
|
||||||
->labelField('name')
|
->labelField('name')
|
||||||
->valueField('key')
|
->valueField('key')
|
||||||
->clearable(),
|
->clearable(),
|
||||||
// amisMake()->InputCityControl()->name('region')->label(__('store.region'))->columnRatio(3)
|
amisMake()->InputCityControl()->name('region')->label(__('store.region'))->columnRatio(3)
|
||||||
// ->allowDistrict(false)
|
->allowDistrict(false)
|
||||||
// ->extractValue(false)
|
->extractValue(false)
|
||||||
// ->clearable(),
|
->clearable(),
|
||||||
amisMake()->SelectControl()->name('business_status')->label(__('store.business_status'))->options(BusinessStatus::options())->columnRatio(3)->clearable(),
|
amisMake()->SelectControl()->name('business_status')->label(__('store.business_status'))->columnRatio(3)->clearable(),
|
||||||
]),
|
]),
|
||||||
]))
|
]))
|
||||||
->columns([
|
->columns([
|
||||||
|
|
@ -62,7 +56,7 @@ class StoreController extends AdminController
|
||||||
amisMake()->TableColumn()->name('business.name')->label(__('store.business_id')),
|
amisMake()->TableColumn()->name('business.name')->label(__('store.business_id')),
|
||||||
amisMake()->TableColumn()->name('level.name')->label(__('store.level_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('region')->label(__('store.region'))->set('type', 'tpl')->set('tpl', '${region.province}-${region.city}'),
|
||||||
amisMake()->TableColumn()->name('business_status')->label(__('store.business_status'))->type('switch')->trueValue(BusinessStatus::Open)->falseValue(BusinessStatus::Close),
|
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')),
|
amisMake()->TableColumn()->name('created_at')->label(__('store.created_at')),
|
||||||
$this->rowActions([
|
$this->rowActions([
|
||||||
$this->rowShowButton()->visible(Admin::user()->can('admin.store.stores.view')),
|
$this->rowShowButton()->visible(Admin::user()->can('admin.store.stores.view')),
|
||||||
|
|
@ -106,7 +100,7 @@ class StoreController extends AdminController
|
||||||
|
|
||||||
public function detail(): Form
|
public function detail(): Form
|
||||||
{
|
{
|
||||||
$detail = amisMake()->Property()->items([
|
return $this->baseDetail()->title('')->body(amisMake()->Property()->items([
|
||||||
['label' => __('store.title'), 'content' => '${title}'],
|
['label' => __('store.title'), 'content' => '${title}'],
|
||||||
['label' => __('store.master_id'), 'content' => '${master.name}'],
|
['label' => __('store.master_id'), 'content' => '${master.name}'],
|
||||||
['label' => __('store.business_status'), 'content' => amisMake()->Tag()->label('${business_status_text}')->color('${business_status_color}')],
|
['label' => __('store.business_status'), 'content' => amisMake()->Tag()->label('${business_status_text}')->color('${business_status_color}')],
|
||||||
|
|
@ -114,103 +108,7 @@ class StoreController extends AdminController
|
||||||
['label' => __('store.business_id'), 'content' => '${business.name}'],
|
['label' => __('store.business_id'), 'content' => '${business.name}'],
|
||||||
['label' => __('store.level_id'), 'content' => '${level.name}'],
|
['label' => __('store.level_id'), 'content' => '${level.name}'],
|
||||||
['label' => __('store.region'), 'content' => '${region.province}-${region.city}'],
|
['label' => __('store.region'), 'content' => '${region.province}-${region.city}'],
|
||||||
['label' => __('store.address'), 'content' => '${region.address}', 'span' => 2],
|
['label' => __('store.profit_ratio'), 'content' => '${profit_ratio}%'],
|
||||||
['label' => __('store.profit_ratio'), 'content' => '${profit_ratio}%', 'span' => 3],
|
|
||||||
]);
|
|
||||||
|
|
||||||
// 员工列表
|
|
||||||
$sales = amisMake()->Service()->id('store-employees-table')->api(admin_url('store/stores/${id}/employees'))->initFetch(false)->body(amisMake()->Table()->columns([
|
|
||||||
amisMake()->TableColumn()->name('name')->label(__('employee.name')),
|
|
||||||
amisMake()->TableColumn()->name('phone')->label(__('employee.phone')),
|
|
||||||
])->itemActions([
|
|
||||||
amisMake()->AjaxAction()
|
|
||||||
->label(__('admin.delete'))
|
|
||||||
->level('link')
|
|
||||||
->confirmText(__('admin.confirm_delete'))
|
|
||||||
->api('delete:'.admin_url('store/stores/${id}/employees').'?employees=${id}')
|
|
||||||
->reload('store-employees-table')
|
|
||||||
]));
|
]));
|
||||||
return $this->baseDetail()->title('')->body([$detail, amisMake()->Divider()->title(__('store.employees')), $sales]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function show($id)
|
|
||||||
{
|
|
||||||
if ($this->actionOfGetData()) {
|
|
||||||
return $this->response()->success($this->service->getDetail($id));
|
|
||||||
}
|
|
||||||
|
|
||||||
$form = amisMake()->Form()
|
|
||||||
->labelWidth(0)
|
|
||||||
->api('post:' . admin_url('store/stores/'.$id.'/employees'))
|
|
||||||
->redirect('')
|
|
||||||
->onEvent([
|
|
||||||
'submitSucc' => [
|
|
||||||
'actions' => [
|
|
||||||
['actionType' => 'reload','componentId' => 'store-employees-table']
|
|
||||||
]
|
|
||||||
]
|
|
||||||
])
|
|
||||||
->body([
|
|
||||||
amisMake()->TransferControl()->name('employees')
|
|
||||||
->source(admin_url('store/stores/employee_options') . '?store_id='.$id)
|
|
||||||
->selectMode('table')
|
|
||||||
->resultListModeFollowSelect()
|
|
||||||
->joinValues(false)
|
|
||||||
->extractValue(true)
|
|
||||||
->columns([
|
|
||||||
amisMake()->Column()->name('label')->label(__('employee.name')),
|
|
||||||
amisMake()->Column()->name('phone')->label(__('employee.phone')),
|
|
||||||
]),
|
|
||||||
]);
|
|
||||||
$dialog = amisMake()->Dialog()->size('lg')->title('添加'.__('store.employees'))->body($form);
|
|
||||||
$detail = amis()
|
|
||||||
->Card()
|
|
||||||
->className('base-form')
|
|
||||||
->header(['title' => __('admin.detail')])
|
|
||||||
->body($this->detail())
|
|
||||||
->toolbar([
|
|
||||||
amisMake()->DialogAction()->label('添加'. __('store.employees'))->level('primary')->className('mr-1')->dialog($dialog),
|
|
||||||
$this->backButton(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$page = $this->basePage()->body($detail);
|
|
||||||
|
|
||||||
return $this->response()->success($page);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function employees($id)
|
|
||||||
{
|
|
||||||
$store = Store::findOrFail($id);
|
|
||||||
$list = $store->employees()->wherePivot('role', StoreRole::Employee)->get();
|
|
||||||
return $this->response()->success($list);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function employeeAdd($id, Request $request)
|
|
||||||
{
|
|
||||||
$employees = $request->input('employees');
|
|
||||||
$store = Store::findOrFail($id);
|
|
||||||
$service = $this->service;
|
|
||||||
if ($service->attachEmployee($store, $employees)) {
|
|
||||||
return $this->response()->success();
|
|
||||||
}
|
|
||||||
return $this->response()->fail($service->getError());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function employeeDestroy($id, Request $request)
|
|
||||||
{
|
|
||||||
$employees = $request->input('employees');
|
|
||||||
$store = Store::findOrFail($id);
|
|
||||||
$service = $this->service;
|
|
||||||
if ($service->destroyEmployee($store, is_array($employees) ? $employees : explode(',', $employees))) {
|
|
||||||
return $this->response()->success();
|
|
||||||
}
|
|
||||||
return $this->response()->fail($service->getError());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function employeeOptions()
|
|
||||||
{
|
|
||||||
$ignore = DB::table('store_employees')->pluck('employee_id');
|
|
||||||
$list = Employee::select(['name as label', 'id as value', 'phone'])->whereNotIn('id', $ignore)->get();
|
|
||||||
return $this->response()->success($list);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,28 +6,4 @@ use EloquentFilter\ModelFilter;
|
||||||
|
|
||||||
class StoreFilter extends ModelFilter
|
class StoreFilter extends ModelFilter
|
||||||
{
|
{
|
||||||
public function title($name)
|
|
||||||
{
|
|
||||||
$this->whereLike('title', $name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function category($key)
|
|
||||||
{
|
|
||||||
$this->where('category_id', $key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function business($key)
|
|
||||||
{
|
|
||||||
$this->where('business_id', $key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function level($key)
|
|
||||||
{
|
|
||||||
$this->where('level_id', $key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function businessStatus($key)
|
|
||||||
{
|
|
||||||
$this->where('business_status', $key);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use Slowlyo\OwlAdmin\Models\AdminUser;
|
use Slowlyo\OwlAdmin\Models\AdminUser;
|
||||||
use Slowlyo\OwlAdmin\Services\AdminUserService;
|
use Slowlyo\OwlAdmin\Services\AdminUserService;
|
||||||
|
|
||||||
|
|
@ -71,6 +70,7 @@ class EmployeeService extends BaseService
|
||||||
|
|
||||||
public function resloveData($data, $model = null)
|
public function resloveData($data, $model = null)
|
||||||
{
|
{
|
||||||
|
// 管理员信息
|
||||||
$adminUserService = AdminUserService::make();
|
$adminUserService = AdminUserService::make();
|
||||||
if ($model) {
|
if ($model) {
|
||||||
// 修改管理员信息
|
// 修改管理员信息
|
||||||
|
|
@ -108,19 +108,11 @@ class EmployeeService extends BaseService
|
||||||
|
|
||||||
public function preDelete(array $ids)
|
public function preDelete(array $ids)
|
||||||
{
|
{
|
||||||
// 店长关联
|
|
||||||
if (DB::table('store_employees')->whereIn('employee_id', $ids)->exists()) {
|
|
||||||
return '员工已关联门店, 请先从门店中删除';
|
|
||||||
}
|
|
||||||
|
|
||||||
// 删除管理员
|
// 删除管理员
|
||||||
$adminUserIds = Employee::whereIn('id', $ids)->pluck('admin_user_id')->implode(',');
|
$adminUserIds = Employee::whereIn('id', $ids)->pluck('admin_user_id')->implode(',');
|
||||||
$adminUserService = AdminUserService::make();
|
$adminUserService = AdminUserService::make();
|
||||||
$adminUserService->delete($adminUserIds);
|
$adminUserService->delete($adminUserIds);
|
||||||
|
|
||||||
// 删除职位关联
|
|
||||||
DB::table('employee_jobs')->whereIn('employee_id', $ids)->delete();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,11 @@
|
||||||
|
|
||||||
namespace App\Admin\Services;
|
namespace App\Admin\Services;
|
||||||
|
|
||||||
use App\Enums\StoreRole;
|
|
||||||
use Illuminate\Validation\Rule;
|
|
||||||
use App\Models\{Store, Employee};
|
|
||||||
use App\Admin\Filters\StoreFilter;
|
use App\Admin\Filters\StoreFilter;
|
||||||
use Illuminate\Support\Facades\DB;
|
use App\Enums\StoreRole;
|
||||||
|
use App\Models\Store;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
class StoreService extends BaseService
|
class StoreService extends BaseService
|
||||||
{
|
{
|
||||||
|
|
@ -49,44 +48,18 @@ class StoreService extends BaseService
|
||||||
|
|
||||||
// 修改店长
|
// 修改店长
|
||||||
if (isset($data['master_id']) && $data['master_id'] != $model->master_id) {
|
if (isset($data['master_id']) && $data['master_id'] != $model->master_id) {
|
||||||
$model->employees()->detach($model->master_id);
|
$store->employees()->detach($model->master_id);
|
||||||
$model->employees()->attach([$data['master_id'] => ['role' => StoreRole::Master]]);
|
$store->employees()->attach([$data['master_id'] => ['role' => StoreRole::Master]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $model->update($data);
|
return $model->update($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加员工
|
|
||||||
public function attachEmployee(Store $store, array $employeeIds)
|
|
||||||
{
|
|
||||||
$data = [];
|
|
||||||
$employees = Employee::whereIn('id', $employeeIds)->get();
|
|
||||||
// 每个员工只能有一个门店
|
|
||||||
foreach ($employees as $employee) {
|
|
||||||
if (DB::table('store_employees')->where('employee_id', $employee->id)->exists()) {
|
|
||||||
$this->setError($employee->name.' 已经是店员');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$data[$employee->id] = ['role' => StoreRole::Employee];
|
|
||||||
}
|
|
||||||
$store->employees()->attach($data);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 移除员工
|
|
||||||
public function destroyEmployee(Store $store, array $employeeIds)
|
|
||||||
{
|
|
||||||
$store->employees()->detach($employeeIds);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function resloveData($data, $model = null)
|
public function resloveData($data, $model = null)
|
||||||
{
|
{
|
||||||
if (isset($data['location'])) {
|
if (isset($data['location'])) {
|
||||||
$data['lon'] = data_get($data['location'], 'lng');
|
$data['lon'] = data_get($data['location'], 'lng');
|
||||||
$data['lat'] = data_get($data['location'], 'lat');
|
$data['lat'] = data_get($data['location'], 'lat');
|
||||||
$data['address'] = data_get($data['location'], 'address');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
|
|
@ -105,7 +78,7 @@ class StoreService extends BaseService
|
||||||
'lat' => ['required'],
|
'lat' => ['required'],
|
||||||
];
|
];
|
||||||
$updateRules = [
|
$updateRules = [
|
||||||
'master_id' => [Rule::unique('stores', 'master_id')->ignore($model, 'master_id')],
|
'master_id' => [Rule::unique($model, 'master_id')],
|
||||||
];
|
];
|
||||||
$validator = Validator::make($data, $model ? $updateRules : $createRules, [
|
$validator = Validator::make($data, $model ? $updateRules : $createRules, [
|
||||||
'master_id.unique' => '已经是店长了',
|
'master_id.unique' => '已经是店长了',
|
||||||
|
|
|
||||||
|
|
@ -29,14 +29,6 @@ Route::group([
|
||||||
'prefix' => 'store',
|
'prefix' => 'store',
|
||||||
'as' => 'store.',
|
'as' => 'store.',
|
||||||
], function (Router $router) {
|
], function (Router $router) {
|
||||||
// 店员列表
|
|
||||||
$router->get('stores/{id}/employees', [StoreController::class, 'employees']);
|
|
||||||
// 添加店员时, 可选的员工列表
|
|
||||||
$router->get('stores/employee_options', [StoreController::class, 'employeeOptions']);
|
|
||||||
// 添加店员
|
|
||||||
$router->post('stores/{id}/employees', [StoreController::class, 'employeeAdd']);
|
|
||||||
// 删除店员
|
|
||||||
$router->delete('stores/{id}/employees', [StoreController::class, 'employeeDestroy']);
|
|
||||||
// 门店管理
|
// 门店管理
|
||||||
$router->resource('stores', StoreController::class);
|
$router->resource('stores', StoreController::class);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use App\Casts\StorageJson;
|
|
||||||
use App\Enums\EmployeeStatus;
|
use App\Enums\EmployeeStatus;
|
||||||
use App\Traits\HasDateTimeFormatter;
|
use App\Traits\HasDateTimeFormatter;
|
||||||
use EloquentFilter\Filterable;
|
use EloquentFilter\Filterable;
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ class Store extends Model
|
||||||
{
|
{
|
||||||
use Filterable, HasDateTimeFormatter;
|
use Filterable, HasDateTimeFormatter;
|
||||||
|
|
||||||
protected $fillable = ['title', 'master_id', 'category_id', 'business_id', 'level_id', 'region', 'lon', 'lat', 'address', 'profit_ratio', 'profit_money', 'business_status'];
|
protected $fillable = ['title', 'master_id', 'category_id', 'business_id', 'level_id', 'region', 'lon', 'lat', 'profit_ratio', 'profit_money', 'business_status'];
|
||||||
|
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
// 地区 {province: 四川省, city: 成都市}
|
// 地区 {province: 四川省, city: 成都市}
|
||||||
|
|
|
||||||
|
|
@ -62,9 +62,6 @@ trait UploadTrait
|
||||||
}
|
}
|
||||||
|
|
||||||
$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'));
|
||||||
if (request()->has('full-url')) {
|
|
||||||
$path = Storage::disk(Admin::config('admin.upload.disk'))->url($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->response()->success(['value' => $path]);
|
return $this->response()->success(['value' => $path]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@ return new class extends Migration
|
||||||
$table->string('business_id')->comment('经营分类, keywords.store_business');
|
$table->string('business_id')->comment('经营分类, keywords.store_business');
|
||||||
$table->string('level_id')->comment('门店等级, keywords.store_level');
|
$table->string('level_id')->comment('门店等级, keywords.store_level');
|
||||||
$table->json('region')->comment('地区{province,city}');
|
$table->json('region')->comment('地区{province,city}');
|
||||||
$table->string('address')->nullable()->comment('详细地址');
|
|
||||||
$table->string('lon')->comment('精度');
|
$table->string('lon')->comment('精度');
|
||||||
$table->string('lat')->comment('纬度');
|
$table->string('lat')->comment('纬度');
|
||||||
$table->unsignedInteger('profit_ratio')->default(0)->comment('佣金比例(0-100)');
|
$table->unsignedInteger('profit_ratio')->default(0)->comment('佣金比例(0-100)');
|
||||||
|
|
@ -32,7 +31,7 @@ return new class extends Migration
|
||||||
Schema::create('store_employees', function (Blueprint $table) {
|
Schema::create('store_employees', function (Blueprint $table) {
|
||||||
$table->foreignId('store_id');
|
$table->foreignId('store_id');
|
||||||
$table->foreignId('employee_id');
|
$table->foreignId('employee_id');
|
||||||
$table->unsignedInteger('role')->default(2)->comment('身份(1: 店长, 2: 店员)');
|
$table->unsignedInteger('role')->default(1)->comment('身份(1: 店长, 2: 店员)');
|
||||||
$table->comment('门店-店员');
|
$table->comment('门店-店员');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,4 @@ return [
|
||||||
'profit_ratio' => '佣金比例',
|
'profit_ratio' => '佣金比例',
|
||||||
'profit_money' => '店长提成',
|
'profit_money' => '店长提成',
|
||||||
'business_status' => '状态',
|
'business_status' => '状态',
|
||||||
'role' => '身份',
|
|
||||||
'address' => '详细地址',
|
|
||||||
'employees' => '店员',
|
|
||||||
];
|
];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue