admin employee.store_id

main
panliang 2024-03-28 10:42:51 +08:00
parent 9305112e84
commit 308115f729
6 changed files with 40 additions and 15 deletions

View File

@ -1,7 +1,26 @@
# 彩票门店管理
composer install
php artisan g:k
php artisan storage:link
php artisan admin:install
php artisan db:seed
## Require
- php >= 8.1 && composer
- mysql >= 8.0
- nginx or apache
## Steup
- `git clone gitea@gitea.hmily.club:pdkj/store-manage.git`
- `cd store-manage`
- `composer install`
- `cp .env.example .env`
- `php artisan key:generate`
- `php artisan storage:link`
- `vim .env`
```
APP_URL=http://local.lottery.host
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=lottery
DB_USERNAME=root
DB_PASSWORD=123456
```
- `php artisan migrate --seed`

View File

@ -38,10 +38,10 @@ class EmployeeController extends AdminController
->columns([
amisMake()->TableColumn()->name('id')->label(__('employee.id')),
amisMake()->TableColumn()->name('store.title')->label(__('employee.store_id')),
amisMake()->TableColumn()->name('name')->label(__('store.employees')),
amisMake()->TableColumn()->name('name')->label(__('employee.name')),
amisMake()->TableColumn()->name('store.master_id')->label(__('store.master_id'))->set('type', 'tpl')->tpl('${store.master_id == id ? "店长" : "--"}'),
amisMake()->TableColumn()->name('phone')->label(__('employee.phone')),
$this->rowActions([
// $this->rowEditButton(true)->visible(Admin::user()->can('admin.store.employees.update')),
$this->rowDeleteButton()->visible(Admin::user()->can('admin.store.employees.delete')),
]),
]);
@ -58,7 +58,7 @@ class EmployeeController extends AdminController
->valueField('id')
->required(),
amisMake()->SelectControl()->name('employee_id')->label(__('store.employees'))
->source(admin_url('api/employees?_all=1&store_id=0&master_store_id=0&enable=1'))
->source(admin_url('api/employees?_all=1&store_id=0&enable=1'))
->labelField('name')
->valueField('id')
->multiple()

View File

@ -27,7 +27,13 @@ class StoreService extends BaseService
// 绑定店长
if (isset($data['master_id'])) {
Employee::where('id', $data['master_id'])->update(['master_store_id' => $model->id]);
// 还原以前的店长
if ($model && $model->master_id != $data['master_id']) {
Employee::where('id', $model->master_id)->update(['store_id' => 0]);
}
if ($model->master_id != $data['master_id']) {
Employee::where('id', $data['master_id'])->update(['store_id' => $model->id]);
}
}
return $data;

View File

@ -60,10 +60,10 @@ class Employee extends Model
}
// 管理的门店(店长)
public function masterStore()
{
return $this->belongsTo(Store::class, 'master_store_id');
}
// public function masterStore()
// {
// return $this->belongsTo(Store::class, 'master_store_id');
// }
public function scopeEnable($q)
{

View File

@ -39,7 +39,7 @@ class StoreFactory extends Factory
{
return $this->afterMaking(function (Store $model) {
})->afterCreating(function (Store $model) {
Employee::where('id', $model->master_id)->update(['master_store_id' => $model->id]);
Employee::where('id', $model->master_id)->update(['store_id' => $model->id]);
});
}
}

View File

@ -14,7 +14,7 @@ return new class extends Migration
Schema::create('employees', function (Blueprint $table) {
$table->id();
$table->foreignId('store_id')->default(0)->comment('所属门店, stores.id');
$table->foreignId('master_store_id')->default(0)->comment('管理的门店, stores.id');
// $table->foreignId('master_store_id')->default(0)->comment('管理的门店, stores.id');
$table->string('name')->comment('姓名');
$table->string('phone')->comment('电话');
$table->json('prize_images')->nullable()->comment('荣誉证书');