generated from liutk/owl-admin-base
佣金比例日志
parent
a3502f1b0f
commit
70d8392a0b
|
|
@ -0,0 +1,46 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Controllers\Store;
|
||||||
|
|
||||||
|
use App\Admin\Controllers\AdminController;
|
||||||
|
use App\Admin\Services\StoreProfitRatioLogService;
|
||||||
|
use Slowlyo\OwlAdmin\Admin;
|
||||||
|
use Slowlyo\OwlAdmin\Renderers\Page;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 彩票机管理
|
||||||
|
*/
|
||||||
|
class StoreProfitRatioLogController extends AdminController
|
||||||
|
{
|
||||||
|
protected string $serviceName = StoreProfitRatioLogService::class;
|
||||||
|
|
||||||
|
public function list(): Page
|
||||||
|
{
|
||||||
|
$crud = $this->baseCRUD()
|
||||||
|
->headerToolbar([
|
||||||
|
...$this->baseHeaderToolBar(),
|
||||||
|
])
|
||||||
|
->bulkActions([])
|
||||||
|
->filter($this->baseFilter()->body([
|
||||||
|
amis()->GroupControl()->mode('horizontal')->body([
|
||||||
|
amis()->SelectControl()->name('store_id')->label(__('store_profit_ratio_log.store'))
|
||||||
|
->source(admin_url('api/stores?_all=1'))
|
||||||
|
->labelField('title')
|
||||||
|
->valueField('id')
|
||||||
|
->columnRatio(3)
|
||||||
|
->clearable(),
|
||||||
|
amis()->TextControl()->name('employee_name')->label(__('store_profit_ratio_log.employee'))->columnRatio(3)->clearable(),
|
||||||
|
]),
|
||||||
|
]))
|
||||||
|
->columns([
|
||||||
|
amis()->TableColumn()->name('id')->label(__('store_profit_ratio_log.id')),
|
||||||
|
amis()->TableColumn()->name('store.title')->label(__('store_profit_ratio_log.store')),
|
||||||
|
amis()->TableColumn()->name('employee.name')->label(__('store_profit_ratio_log.employee')),
|
||||||
|
amis()->TableColumn()->name('before')->label(__('store_profit_ratio_log.before'))->type('tpl')->set('tpl', '${before}%'),
|
||||||
|
amis()->TableColumn()->name('after')->label(__('store_profit_ratio_log.after'))->type('tpl')->set('tpl', '${after}%'),
|
||||||
|
amis()->TableColumn()->name('created_at')->label(__('store_profit_ratio_log.created_at')),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $this->baseList($crud);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Filters;
|
||||||
|
|
||||||
|
use EloquentFilter\ModelFilter;
|
||||||
|
|
||||||
|
class StoreProfitRatioLogFilter extends ModelFilter
|
||||||
|
{
|
||||||
|
public function store($id)
|
||||||
|
{
|
||||||
|
$this->where('store_id', $id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function employeeName($name)
|
||||||
|
{
|
||||||
|
$this->related('employee', fn ($query) => $query->where('name', 'like', "%{$name}%"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Services;
|
||||||
|
|
||||||
|
use App\Admin\Filters\StoreProfitRatioLogFilter;
|
||||||
|
use App\Models\StoreProfitRatioLog;
|
||||||
|
|
||||||
|
class StoreProfitRatioLogService extends BaseService
|
||||||
|
{
|
||||||
|
protected array $withRelationships = ['store', 'employee'];
|
||||||
|
|
||||||
|
protected string $modelName = StoreProfitRatioLog::class;
|
||||||
|
|
||||||
|
protected string $modelFilterName = StoreProfitRatioLogFilter::class;
|
||||||
|
}
|
||||||
|
|
@ -5,8 +5,10 @@ namespace App\Admin\Services;
|
||||||
use App\Admin\Filters\StoreFilter;
|
use App\Admin\Filters\StoreFilter;
|
||||||
use App\Models\Employee;
|
use App\Models\Employee;
|
||||||
use App\Models\Store;
|
use App\Models\Store;
|
||||||
|
use App\Models\StoreProfitRatioLog;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
|
use Slowlyo\OwlAdmin\Admin;
|
||||||
|
|
||||||
class StoreService extends BaseService
|
class StoreService extends BaseService
|
||||||
{
|
{
|
||||||
|
|
@ -27,8 +29,27 @@ class StoreService extends BaseService
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$beforeProfitRatio = 0;
|
||||||
|
|
||||||
$model = $this->modelName::create($data);
|
$model = $this->modelName::create($data);
|
||||||
|
|
||||||
|
$afterProfitRatio = $model->profit_ratio;
|
||||||
|
|
||||||
|
if (bccomp($beforeProfitRatio, $afterProfitRatio, 2) !== 0) {
|
||||||
|
$employee = Employee::where('admin_user_id', Admin::user()->id)->first();
|
||||||
|
|
||||||
|
if (is_null($employee)) {
|
||||||
|
admin_abort('账号未找到员工信息');
|
||||||
|
}
|
||||||
|
|
||||||
|
StoreProfitRatioLog::create([
|
||||||
|
'store_id' => $model->id,
|
||||||
|
'employee_id' => $employee->id,
|
||||||
|
'before' => $beforeProfitRatio ,
|
||||||
|
'after' => $afterProfitRatio,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
// 绑定店长
|
// 绑定店长
|
||||||
Employee::where('id', $data['master_id'])->update(['store_id' => $model->id]);
|
Employee::where('id', $data['master_id'])->update(['store_id' => $model->id]);
|
||||||
|
|
||||||
|
|
@ -51,6 +72,27 @@ class StoreService extends BaseService
|
||||||
Employee::where('id', $model->master_id)->update(['store_id' => 0]);
|
Employee::where('id', $model->master_id)->update(['store_id' => 0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$beforeProfitRatio = $model->profit_ratio;
|
||||||
|
|
||||||
|
$model->update($data);
|
||||||
|
|
||||||
|
$afterProfitRatio = $model->profit_ratio;
|
||||||
|
|
||||||
|
if (bccomp($beforeProfitRatio, $afterProfitRatio, 2) !== 0) {
|
||||||
|
$employee = Employee::where('admin_user_id', Admin::user()->id)->first();
|
||||||
|
|
||||||
|
if (is_null($employee)) {
|
||||||
|
admin_abort('账号未找到员工信息');
|
||||||
|
}
|
||||||
|
|
||||||
|
StoreProfitRatioLog::create([
|
||||||
|
'store_id' => $model->id,
|
||||||
|
'employee_id' => $employee->id,
|
||||||
|
'before' => $beforeProfitRatio ,
|
||||||
|
'after' => $afterProfitRatio,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
return $model->update($data);
|
return $model->update($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -80,10 +122,26 @@ class StoreService extends BaseService
|
||||||
];
|
];
|
||||||
$updateRules = [
|
$updateRules = [
|
||||||
'master_id' => [Rule::unique('stores', 'master_id')->ignore($model, 'master_id')],
|
'master_id' => [Rule::unique('stores', 'master_id')->ignore($model, 'master_id')],
|
||||||
|
'profit_ratio' => ['filled', 'numeric', 'min:0', 'max:100'],
|
||||||
];
|
];
|
||||||
$validator = Validator::make($data, $model ? $updateRules : $createRules, [
|
$validator = Validator::make(
|
||||||
'master_id.unique' => '已经是店长了',
|
$data,
|
||||||
]);
|
$model ? $updateRules : $createRules,
|
||||||
|
[
|
||||||
|
'master_id.unique' => '已经是店长了',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'title' => __('store.title'),
|
||||||
|
'master_id' => __('store.master_id'),
|
||||||
|
'category_id' => __('store.category_id'),
|
||||||
|
'business_id' => __('store.business_id'),
|
||||||
|
'level_id' => __('store.level_id'),
|
||||||
|
'region' => __('store.region'),
|
||||||
|
'lon' => __('store.lon'),
|
||||||
|
'lat' => __('store.lat'),
|
||||||
|
'profit_ratio' => __('store.profit_ratio'),
|
||||||
|
]
|
||||||
|
);
|
||||||
if ($validator->fails()) {
|
if ($validator->fails()) {
|
||||||
return $validator->errors()->first();
|
return $validator->errors()->first();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ use App\Admin\Controllers\Plan\TaskController;
|
||||||
use App\Admin\Controllers\Store\DeviceController;
|
use App\Admin\Controllers\Store\DeviceController;
|
||||||
use App\Admin\Controllers\Store\EmployeeController as StoreEmployeeController;
|
use App\Admin\Controllers\Store\EmployeeController as StoreEmployeeController;
|
||||||
use App\Admin\Controllers\Store\StoreController;
|
use App\Admin\Controllers\Store\StoreController;
|
||||||
|
use App\Admin\Controllers\Store\StoreProfitRatioLogController;
|
||||||
use App\Admin\Controllers\System\AdminMenuController;
|
use App\Admin\Controllers\System\AdminMenuController;
|
||||||
use App\Admin\Controllers\System\AdminPermissionController;
|
use App\Admin\Controllers\System\AdminPermissionController;
|
||||||
use App\Admin\Controllers\System\AdminRoleController;
|
use App\Admin\Controllers\System\AdminRoleController;
|
||||||
|
|
@ -69,6 +70,8 @@ Route::group([
|
||||||
$router->resource('business', BaseKeywordController::class);
|
$router->resource('business', BaseKeywordController::class);
|
||||||
// 彩种类型
|
// 彩种类型
|
||||||
$router->resource('lottery-types', BaseKeywordController::class);
|
$router->resource('lottery-types', BaseKeywordController::class);
|
||||||
|
//
|
||||||
|
$router->resource('store-profit-ratio-logs', StoreProfitRatioLogController::class);
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,10 @@ class Store extends Model
|
||||||
{
|
{
|
||||||
use Filterable, HasDateTimeFormatter, HasFactory;
|
use Filterable, HasDateTimeFormatter, HasFactory;
|
||||||
|
|
||||||
|
protected $attributes = [
|
||||||
|
'profit_ratio' => 0,
|
||||||
|
];
|
||||||
|
|
||||||
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', 'address', 'profit_ratio', 'profit_money', 'business_status'];
|
||||||
|
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Traits\HasDateTimeFormatter;
|
||||||
|
use EloquentFilter\Filterable;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
|
class StoreProfitRatioLog extends Model
|
||||||
|
{
|
||||||
|
use Filterable, HasFactory, HasDateTimeFormatter;
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'store_id',
|
||||||
|
'employee_id',
|
||||||
|
'before',
|
||||||
|
'after',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function store(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Store::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function employee(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Employee::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?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('store_profit_ratio_logs', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('store_id')->comment('门店ID');
|
||||||
|
$table->foreignId('employee_id')->comment('员工ID');
|
||||||
|
$table->decimal('before')->default(0)->comment('变更前的佣金比例');
|
||||||
|
$table->decimal('after')->default(0)->comment('变更后的佣金比例');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('store_profit_ratio_logs');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
@ -93,6 +93,13 @@ class AdminPermissionSeeder extends Seeder
|
||||||
'resource' => true,
|
'resource' => true,
|
||||||
'order' => 7,
|
'order' => 7,
|
||||||
],
|
],
|
||||||
|
'store-profit-ratio-logs' => [
|
||||||
|
'name' => '佣金比例日志',
|
||||||
|
'icon' => 'mingcute:sunflower-line',
|
||||||
|
'uri' => '/store/store-profit-ratio-logs',
|
||||||
|
'resource' => ['list'],
|
||||||
|
'order' => 9,
|
||||||
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
'id' => 'ID',
|
||||||
|
'created_at' => '创建时间',
|
||||||
|
'updated_at' => '更新时间',
|
||||||
|
'store' => '门店',
|
||||||
|
'before' => '变更前',
|
||||||
|
'after' => '变更后',
|
||||||
|
'employee' => '操作人',
|
||||||
|
];
|
||||||
Loading…
Reference in New Issue