customer回收站功能
This commit is contained in:
parent
4a98a53b99
commit
6109d7c5c4
|
|
@ -16,7 +16,6 @@ use Beike\Admin\Http\Resources\AddressResource;
|
|||
use Beike\Admin\Http\Resources\CustomerGroupDetail;
|
||||
use Beike\Admin\Http\Resources\CustomerResource;
|
||||
use Beike\Admin\Services\CustomerService;
|
||||
use Beike\Models\Customer;
|
||||
use Beike\Repositories\AddressRepo;
|
||||
use Beike\Repositories\CountryRepo;
|
||||
use Beike\Repositories\CustomerGroupRepo;
|
||||
|
|
@ -42,6 +41,23 @@ class CustomerController extends Controller
|
|||
return view('admin::pages.customers.index', $data);
|
||||
}
|
||||
|
||||
public function trashed(Request $request)
|
||||
{
|
||||
$customers = CustomerRepo::list(array_merge($request->only(['name', 'email', 'status', 'from', 'customer_group_id']), ['only_trashed' => true]));
|
||||
|
||||
$data = [
|
||||
'customers' => $customers,
|
||||
'customers_format' => CustomerResource::collection($customers)->jsonSerialize(),
|
||||
'customer_groups' => CustomerGroupDetail::collection(CustomerGroupRepo::list())->jsonSerialize(),
|
||||
];
|
||||
|
||||
if ($request->expectsJson()) {
|
||||
return json_success(trans('success'), $data);
|
||||
}
|
||||
|
||||
return view('admin::pages.customers.trashed', $data);
|
||||
}
|
||||
|
||||
public function store(CustomerRequest $request)
|
||||
{
|
||||
$data = $request->only(['email', 'name', 'password', 'status', 'customer_group_id']);
|
||||
|
|
@ -90,4 +106,18 @@ class CustomerController extends Controller
|
|||
|
||||
return json_success(trans('common.restored_success'));
|
||||
}
|
||||
|
||||
public function forceDelete(Request $request, int $customerId)
|
||||
{
|
||||
$customer = CustomerRepo::forceDelete($customerId);
|
||||
|
||||
return json_success(trans('common.success'));
|
||||
}
|
||||
|
||||
public function forceDeleteAll(Request $request)
|
||||
{
|
||||
$customer = CustomerRepo::forceDeleteAll();
|
||||
|
||||
return json_success(trans('common.success'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,11 +56,15 @@ Route::prefix($adminName)
|
|||
|
||||
|
||||
// 客户
|
||||
Route::middleware('can:customers_index')->get('customers/trashed', [Controllers\CustomerController::class, 'trashed'])->name('customers.trashed');
|
||||
Route::middleware('can:customers_index')->get('customers', [Controllers\CustomerController::class, 'index'])->name('customers.index');
|
||||
Route::middleware('can:customers_create')->post('customers', [Controllers\CustomerController::class, 'store'])->name('customers.store');
|
||||
Route::middleware('can:customers_show')->get('customers/{id}/edit', [Controllers\CustomerController::class, 'edit'])->name('customers.edit');
|
||||
Route::middleware('can:customers_update')->put('customers/{id}', [Controllers\CustomerController::class, 'update'])->name('customers.update');
|
||||
Route::middleware('can:customers_create')->delete('customers/{id}/restore', [Controllers\CustomerController::class, 'restore'])->name('customers.restore');
|
||||
Route::middleware('can:customers_delete')->delete('customers/{id}', [Controllers\CustomerController::class, 'destroy'])->name('customers.destroy');
|
||||
Route::middleware('can:customers_delete')->delete('customers/{id}/force', [Controllers\CustomerController::class, 'forceDelete'])->name('customers.force_delete');
|
||||
Route::middleware('can:customers_delete')->post('customers/force_delete_all', [Controllers\CustomerController::class, 'forceDeleteAll'])->name('customers.force_delete_all');
|
||||
|
||||
|
||||
// 客户地址
|
||||
|
|
|
|||
|
|
@ -110,6 +110,9 @@ class CustomerRepo
|
|||
if (isset($filters['customer_group_id'])) {
|
||||
$builder->where('customers.customer_group_id', $filters['customer_group_id']);
|
||||
}
|
||||
if (isset($filters['only_trashed']) && $filters['only_trashed']) {
|
||||
$builder->onlyTrashed();
|
||||
}
|
||||
|
||||
$start = $filters['start'] ?? null;
|
||||
if ($start) {
|
||||
|
|
@ -129,6 +132,15 @@ class CustomerRepo
|
|||
Customer::withTrashed()->find($id)->restore();
|
||||
}
|
||||
|
||||
public static function forceDelete($id)
|
||||
{
|
||||
Customer::withTrashed()->find($id)->forceDelete();
|
||||
}
|
||||
|
||||
public static function forceDeleteAll() {
|
||||
Customer::withTrashed()->forceDelete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $customer , Customer对象或id
|
||||
* @param $productId
|
||||
|
|
|
|||
|
|
@ -0,0 +1,250 @@
|
|||
@extends('admin::layouts.master')
|
||||
|
||||
@section('title', __('admin/common.customer'))
|
||||
|
||||
@section('content')
|
||||
<div id="customer-app" class="card" v-cloak>
|
||||
<div class="card-body">
|
||||
<div class="bg-light p-4 mb-3">
|
||||
<el-form :inline="true" :model="filter" class="demo-form-inline" label-width="100px">
|
||||
<div>
|
||||
<el-form-item label="{{ __('customer.name') }}">
|
||||
<el-input @keyup.enter.native="search" v-model="filter.name" size="small" placeholder="{{ __('customer.name') }}"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="{{ __('customer.email') }}">
|
||||
<el-input @keyup.enter.native="search" v-model="filter.email" size="small" placeholder="{{ __('customer.email') }}"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="{{ __('customer.customer_group') }}">
|
||||
<el-select size="small" v-model="filter.customer_group_id" placeholder="{{ __('common.please_choose') }}">
|
||||
<el-option v-for="item in source.customer_group" :key="item.id" :label="item.name"
|
||||
:value="item.id + ''">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="{{ __('common.status') }}">
|
||||
<el-select size="small" v-model="filter.status" placeholder="{{ __('common.please_choose') }}">
|
||||
<el-option label="{{ __('common.all') }}" value=""></el-option>
|
||||
<el-option label="{{ __('common.enabled') }}" value="1"></el-option>
|
||||
<el-option label="{{ __('common.disabled') }}" value="0"></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</div>
|
||||
</el-form>
|
||||
|
||||
<div class="row">
|
||||
<label class="wp-100"></label>
|
||||
<div class="col-auto">
|
||||
<button type="button" @click="search" class="btn btn-outline-primary btn-sm">{{ __('common.filter') }}</button>
|
||||
<button type="button" @click="resetSearch" class="btn btn-outline-secondary btn-sm ms-1">{{ __('common.reset') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="d-flex justify-content-between mb-4">
|
||||
<button type="button" class="btn btn-primary" @click="checkedCustomersCreate">{{ __('admin/customer.customers_create') }}</button>
|
||||
</div>
|
||||
<div class="table-push">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ __('common.id') }}</th>
|
||||
<th>{{ __('customer.email') }}</th>
|
||||
<th>{{ __('customer.name') }}</th>
|
||||
<th>{{ __('customer.from') }}</th>
|
||||
<th>{{ __('customer.customer_group') }}</th>
|
||||
<th>{{ __('common.status') }}</th>
|
||||
<th>{{ __('common.created_at') }}</th>
|
||||
<th>{{ __('common.action') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody v-if="customers.data.length">
|
||||
<tr v-for="customer, index in customers.data" :key="index">
|
||||
<td>@{{ customer.id }}</td>
|
||||
<td>@{{ customer.email }}</td>
|
||||
<td>
|
||||
<div class="d-flex align-items-center">
|
||||
{{-- <img src="@{{ customer.avatar }}" class="img-fluid rounded-circle me-2" style="width: 40px;"> --}}
|
||||
<div>@{{ customer.name }}</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>@{{ customer.from }}</td>
|
||||
<td>@{{ customer.customer_group_name }}</td>
|
||||
<td>
|
||||
<span v-if="customer.status" class="text-success">{{ __('common.enable') }}</span>
|
||||
<span v-else class="text-secondary">{{ __('common.disable') }}</span>
|
||||
</td>
|
||||
<td>@{{ customer.created_at }}</td>
|
||||
<td>
|
||||
<a class="btn btn-outline-secondary btn-sm" :href="customer.edit">{{ __('common.edit') }}</a>
|
||||
<button class="btn btn-outline-danger btn-sm ml-1" type="button" @click="deleteCustomer(customer.delete, index)">{{ __('common.delete') }}</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<tbody v-else><tr><td colspan="9" class="border-0"><x-admin-no-data /></td></tr></tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<el-pagination v-if="customers.data.length" layout="prev, pager, next" background :page-size="customers.per_page" :current-page.sync="page"
|
||||
:total="customers.total"></el-pagination>
|
||||
</div>
|
||||
|
||||
<el-dialog title="{{ __('admin/customer.customers_create') }}" :visible.sync="dialogCustomers.show" width="670px"
|
||||
@close="closeCustomersDialog('form')" :close-on-click-modal="false">
|
||||
<el-form ref="form" :rules="rules" :model="dialogCustomers.form" label-width="120px">
|
||||
<el-form-item label="{{ __('admin/customer.user_name') }}" prop="name">
|
||||
<el-input v-model="dialogCustomers.form.name" placeholder="{{ __('admin/customer.user_name') }}"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="{{ __('customer.email') }}" prop="email">
|
||||
<el-input v-model="dialogCustomers.form.email" placeholder="{{ __('customer.email') }}"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="{{ __('shop/login.password') }}" prop="password">
|
||||
<el-input v-model="dialogCustomers.form.password" placeholder="{{ __('shop/login.password') }}"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="{{ __('customer.customer_group') }}">
|
||||
<el-select v-model="dialogCustomers.form.customer_group_id" placeholder="">
|
||||
<el-option v-for="item in source.customer_group" :key="item.id" :label="item.name"
|
||||
:value="item.id">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="{{ __('common.status') }}" prop="status">
|
||||
<el-switch v-model="dialogCustomers.form.status" :active-value="1" :inactive-value="0"></el-switch>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="addCustomersFormSubmit('form')">{{ __('common.save') }}</el-button>
|
||||
<el-button @click="closeCustomersDialog('form')">{{ __('common.cancel') }}</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-dialog>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('footer')
|
||||
<script>
|
||||
new Vue({
|
||||
el: '#customer-app',
|
||||
|
||||
data: {
|
||||
page: 1,
|
||||
customers: @json($customers ?? []),
|
||||
|
||||
source: {
|
||||
customer_group: @json($customer_groups ?? []),
|
||||
},
|
||||
|
||||
dialogCustomers: {
|
||||
show: false,
|
||||
form: {
|
||||
id: null,
|
||||
name: '',
|
||||
email: '',
|
||||
password: '',
|
||||
customer_group_id: @json($customer_groups[0]['id'] ?? ''),
|
||||
status: 1,
|
||||
},
|
||||
},
|
||||
|
||||
rules: {
|
||||
name: [{required: true,message: '{{ __('common.error_required', ['name' => __('admin/customer.user_name')] ) }}', trigger: 'blur'}, ],
|
||||
email: [
|
||||
{required: true, message: '{{ __('common.error_required', ['name' => __('common.email')] ) }}', trigger: 'blur'},
|
||||
{type: 'email', message: '{{ __('admin/customer.error_email') }}' ,trigger: 'blur'},
|
||||
],
|
||||
password: [{required: true,message: '{{ __('common.error_required', ['name' => __('shop/login.password')] ) }}',trigger: 'blur'}, ],
|
||||
},
|
||||
|
||||
url: @json(admin_route('customers.index')),
|
||||
|
||||
filter: {
|
||||
email: bk.getQueryString('email'),
|
||||
name: bk.getQueryString('name'),
|
||||
customer_group_id: bk.getQueryString('customer_group_id'),
|
||||
status: bk.getQueryString('status'),
|
||||
},
|
||||
},
|
||||
|
||||
mounted () {
|
||||
},
|
||||
|
||||
watch: {
|
||||
page: function() {
|
||||
this.loadData();
|
||||
},
|
||||
},
|
||||
|
||||
computed: {
|
||||
query() {
|
||||
let query = '';
|
||||
const filter = Object.keys(this.filter)
|
||||
.filter(key => this.filter[key])
|
||||
.map(key => key + '=' + this.filter[key])
|
||||
.join('&');
|
||||
|
||||
if (filter) {
|
||||
query += '?' + filter;
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
loadData() {
|
||||
$http.get(`customers?page=${this.page}`).then((res) => {
|
||||
this.customers = res.data.customers;
|
||||
})
|
||||
},
|
||||
|
||||
checkedCustomersCreate() {
|
||||
this.dialogCustomers.show = true
|
||||
},
|
||||
|
||||
addCustomersFormSubmit(form) {
|
||||
const self = this;
|
||||
|
||||
this.$refs[form].validate((valid) => {
|
||||
if (!valid) {
|
||||
this.$message.error('{{ __('common.error_form') }}');
|
||||
return;
|
||||
}
|
||||
|
||||
$http.post('customers', this.dialogCustomers.form).then((res) => {
|
||||
this.$message.success(res.message);
|
||||
this.loadData();// this.customers.data.push(res.data);
|
||||
this.dialogCustomers.show = false
|
||||
})
|
||||
});
|
||||
},
|
||||
|
||||
deleteCustomer(url, index) {
|
||||
const self = this;
|
||||
this.$confirm('{{ __('common.confirm_delete') }}', '{{ __('common.text_hint') }}', {
|
||||
confirmButtonText: '{{ __('common.confirm') }}',
|
||||
cancelButtonText: '{{ __('common.cancel') }}',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
$http.delete(url).then((res) => {
|
||||
self.$message.success(res.message);
|
||||
window.location.reload();
|
||||
// self.customers.splice(index, 1)
|
||||
})
|
||||
}).catch(()=>{})
|
||||
},
|
||||
|
||||
closeCustomersDialog(form) {
|
||||
this.$refs[form].resetFields();
|
||||
this.dialogCustomers.show = false
|
||||
},
|
||||
|
||||
search() {
|
||||
location = this.url + this.query
|
||||
},
|
||||
|
||||
resetSearch() {
|
||||
Object.keys(this.filter).forEach(key => this.filter[key] = '')
|
||||
location = this.url + this.query
|
||||
},
|
||||
}
|
||||
})
|
||||
</script>
|
||||
@endpush
|
||||
Loading…
Reference in New Issue