后台货币管理
This commit is contained in:
parent
c291b65583
commit
4445cd1f65
|
|
@ -20,7 +20,6 @@ class Kernel extends HttpKernel
|
|||
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||
\App\Http\Middleware\TrimStrings::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
/**
|
||||
* CurrencyController.php
|
||||
*
|
||||
* @copyright 2022 opencart.cn - All Rights Reserved
|
||||
* @link http://www.guangdawangluo.com
|
||||
* @author TL <mengwb@opencart.cn>
|
||||
* @created 2022-06-30 16:17:04
|
||||
* @modified 2022-06-30 16:17:04
|
||||
*/
|
||||
|
||||
namespace Beike\Admin\Http\Controllers;
|
||||
|
||||
use Beike\Admin\Http\Requests\CurrencyRequest;
|
||||
use Beike\Admin\Http\Resources\CustomerResource;
|
||||
use Beike\Models\Customer;
|
||||
use Beike\Repositories\CountryRepo;
|
||||
use Beike\Repositories\CurrencyRepo;
|
||||
use Beike\Repositories\CustomerGroupRepo;
|
||||
use Beike\Repositories\CustomerRepo;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CurrencyController extends Controller
|
||||
{
|
||||
protected string $defaultRoute = 'currencies.index';
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$currencies = CurrencyRepo::all();
|
||||
|
||||
$data = [
|
||||
'currencies' => $currencies,
|
||||
];
|
||||
|
||||
return view('admin::pages.currencies.index', $data);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('admin::pages.currencies.form');
|
||||
}
|
||||
|
||||
public function store(CurrencyRequest $request)
|
||||
{
|
||||
$data = [
|
||||
'name' => $request->get('name', ''),
|
||||
'code' => $request->get('code', ''),
|
||||
'symbol_left' => $request->get('symbol_left', ''),
|
||||
'symbol_right' => $request->get('symbol_right', ''),
|
||||
'decimal_place' => (float)$request->get('decimal_place', 0),
|
||||
'value' => (float)$request->get('value', 1),
|
||||
'status' => (int)$request->get('status', 0),
|
||||
];
|
||||
CurrencyRepo::create($data);
|
||||
|
||||
return redirect($this->getRedirect())->with('success', '货币创建成功!');
|
||||
}
|
||||
|
||||
public function edit(Request $request, int $currency)
|
||||
{
|
||||
$data = [
|
||||
'currency' => $currency,
|
||||
'_redirect' => $this->getRedirect(),
|
||||
];
|
||||
|
||||
return view('admin::pages.currencies.form', $data);
|
||||
}
|
||||
|
||||
public function update(CurrencyRequest $request, int $currencyId)
|
||||
{
|
||||
$data = [
|
||||
'name' => $request->get('name', ''),
|
||||
'code' => $request->get('code', ''),
|
||||
'symbol_left' => $request->get('symbol_left', ''),
|
||||
'symbol_right' => $request->get('symbol_right', ''),
|
||||
'decimal_place' => (float)$request->get('decimal_place', 0),
|
||||
'value' => (float)$request->get('value', 1),
|
||||
'status' => (int)$request->get('status', 0),
|
||||
];
|
||||
CurrencyRepo::update($currencyId, $data);
|
||||
|
||||
return redirect($this->getRedirect())->with('success', '货币更新成功!');
|
||||
}
|
||||
|
||||
public function destroy(Request $request, int $currencyId)
|
||||
{
|
||||
CurrencyRepo::delete($currencyId);
|
||||
|
||||
return json_success('删除成功!');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace Beike\Admin\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class CurrencyRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'name' => 'required|max:64',
|
||||
'code' => 'required|max:16',
|
||||
'symbol_left' => 'max:16',
|
||||
'symbol_right' => 'max:16',
|
||||
'value' => 'required',
|
||||
];
|
||||
}
|
||||
|
||||
public function attributes()
|
||||
{
|
||||
return [
|
||||
'name' => '名称',
|
||||
'code' => '编码',
|
||||
'symbol_left' => '左符号',
|
||||
'symbol_right' => '右符号',
|
||||
'value' => '汇率值',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -23,6 +23,7 @@ Route::prefix('admin')
|
|||
|
||||
Route::put('products/restore', [\Beike\Admin\Http\Controllers\ProductController::class, 'restore']);
|
||||
Route::resource('products', \Beike\Admin\Http\Controllers\ProductController::class);
|
||||
Route::resource('currencies', \Beike\Admin\Http\Controllers\CurrencyController::class);
|
||||
|
||||
Route::get('settings', [\Beike\Admin\Http\Controllers\SettingController::class, 'index'])->name('settings.index');
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
/**
|
||||
* Currency.php
|
||||
*
|
||||
* @copyright 2022 opencart.cn - All Rights Reserved
|
||||
* @link http://www.guangdawangluo.com
|
||||
* @author TL <mengwb@opencart.cn>
|
||||
* @created 2022-06-30 15:22:18
|
||||
* @modified 2022-06-30 15:22:18
|
||||
*/
|
||||
|
||||
namespace Beike\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
class Currency extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = ['name', 'code', 'symbol_left', 'symbol_right', 'decimal_place', 'value', 'status'];
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
/**
|
||||
* CurrencyRepo.php
|
||||
*
|
||||
* @copyright 2022 opencart.cn - All Rights Reserved
|
||||
* @link http://www.guangdawangluo.com
|
||||
* @author TL <mengwb@opencart.cn>
|
||||
* @created 2022-06-30 15:22:05
|
||||
* @modified 2022-06-30 15:22:05
|
||||
*/
|
||||
|
||||
namespace Beike\Repositories;
|
||||
|
||||
use Beike\Models\Country;
|
||||
use Beike\Models\Currency;
|
||||
|
||||
class CurrencyRepo
|
||||
{
|
||||
/**
|
||||
* 创建一个currency记录
|
||||
* @param $data
|
||||
* @return int
|
||||
*/
|
||||
public static function create($data)
|
||||
{
|
||||
return Currency::query()->create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @param $data
|
||||
* @return bool|int
|
||||
*/
|
||||
public static function update($id, $data)
|
||||
{
|
||||
$item = Currency::query()->find($id);
|
||||
if (!$item) {
|
||||
throw new \Exception("货币id {$id} 不存在");
|
||||
}
|
||||
$item->update($data);
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|null
|
||||
*/
|
||||
public static function find($id)
|
||||
{
|
||||
return Currency::query()->find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return void
|
||||
*/
|
||||
public static function delete($id)
|
||||
{
|
||||
$item = Currency::query()->find($id);
|
||||
if ($item) {
|
||||
$item->delete();
|
||||
}
|
||||
}
|
||||
|
||||
public static function all()
|
||||
{
|
||||
return Currency::query()->get();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
@extends('admin::layouts.master')
|
||||
|
||||
@section('title', '货币管理')
|
||||
|
||||
@section('content')
|
||||
<div id="currency-app-form" class="card">
|
||||
<div class="card-body">
|
||||
<form action="{{ admin_route('currencies.store') }}" method="post">
|
||||
@csrf
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label" id="name">名称</label>
|
||||
<input type="input" name="name" value="{{ old('name') }}" class="form-control" placeholder="名称">
|
||||
@error('name')
|
||||
<x-admin::form.error :message="$message" />
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label" id="code">编码</label>
|
||||
<input type="input" name="code" value="{{ old('code') }}" class="form-control" placeholder="编码">
|
||||
@error('code')
|
||||
<x-admin::form.error :message="$message" />
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label" id="symbol_left">左符号</label>
|
||||
<input type="input" name="symbol_left" value="{{ old('symbol_left') }}" class="form-control" placeholder="左符号">
|
||||
@error('symbol_left')
|
||||
<x-admin::form.error :message="$message" />
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label" id="symbol_right">右符号</label>
|
||||
<input type="input" name="symbol_right" value="{{ old('symbol_right') }}" class="form-control" placeholder="右符号">
|
||||
@error('symbol_right')
|
||||
<x-admin::form.error :message="$message" />
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label" id="decimal_place">小数位数</label>
|
||||
<input type="input" name="decimal_place" value="{{ old('decimal_place') }}" class="form-control" placeholder="小数位数">
|
||||
@error('decimal_place')
|
||||
<x-admin::form.error :message="$message" />
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label" id="value">汇率值</label>
|
||||
<input type="input" name="value" value="{{ old('value') }}" class="form-control" placeholder="汇率值">
|
||||
@error('value')
|
||||
<x-admin::form.error :message="$message" />
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label" id="status">状态</label>
|
||||
<input type="input" name="status" class="form-control" placeholder="状态">
|
||||
@error('status')
|
||||
<x-admin::form.error :message="$message" />
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
@if (session('error'))
|
||||
<div class="alert alert-success">
|
||||
{{ session('error') }}
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<button type="submit" class="btn btn-primary mb-4">确定</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
@extends('admin::layouts.master')
|
||||
|
||||
@section('title', '货币管理')
|
||||
|
||||
@section('content')
|
||||
<div id="customer-app" class="card">
|
||||
<div class="card-body">
|
||||
<div class="d-flex justify-content-between my-4">
|
||||
<a href="{{ admin_route('currencies.create') }}" class="btn btn-primary">创建</a>
|
||||
</div>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>名称</th>
|
||||
<th>编码</th>
|
||||
<th>货币左符号</th>
|
||||
<th>货币右符号</th>
|
||||
<th>小数位数</th>
|
||||
<th>汇率值</th>
|
||||
<th>状态</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($currencies as $currency)
|
||||
<tr>
|
||||
<td>{{ $currency['id'] }}</td>
|
||||
<td>{{ $currency['name'] }}</td>
|
||||
<td>{{ $currency['code'] }}</td>
|
||||
<td>{{ $currency['symbol_left'] }}</td>
|
||||
<td>{{ $currency['symbol_right'] }}</td>
|
||||
<td>{{ $currency['decimal_place'] }}</td>
|
||||
<td>{{ $currency['value'] }}</td>
|
||||
<td>{{ $currency['status'] }}</td>
|
||||
<td>
|
||||
<a class="btn btn-outline-secondary btn-sm" href="{{ admin_route('currencies.edit', [$currency['id']]) }}">编辑</a>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
|
@ -1,97 +0,0 @@
|
|||
@extends('admin::admin.layouts.master')
|
||||
|
||||
@section('title', '分类管理')
|
||||
|
||||
@push('header')
|
||||
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.27.2/axios.min.js"></script>
|
||||
@endpush
|
||||
|
||||
@section('content')
|
||||
<div id="app">
|
||||
<el-card class="box-card">
|
||||
<div slot="header" class="clearfix">
|
||||
<span>编辑分类</span>
|
||||
</div>
|
||||
|
||||
<el-form label-width="200px" size="small1">
|
||||
|
||||
<el-form-item label="分类名称">
|
||||
<div style="max-width: 400px">
|
||||
@foreach (locales() as $locale)
|
||||
<el-input class="mb-1">
|
||||
<template slot="append">{{ $locale['name'] }}</template>
|
||||
</el-input>
|
||||
@endforeach
|
||||
</div>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="分类描述">
|
||||
<div style="max-width: 400px">
|
||||
@foreach (locales() as $locale)
|
||||
<el-input v-model="form.descriptions['{{ $locale['code'] }}'].content" class="mb-1">
|
||||
<template slot="append">{{ $locale['name'] }}</template>
|
||||
</el-input>
|
||||
@endforeach
|
||||
</div>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="上级分类">
|
||||
<el-select v-model="form.parent_id" placeholder="请选择上级分类">
|
||||
@foreach ($categories as $_category)
|
||||
<el-option label="{{ $_category->name }}" value="{{ $_category->id }}"></el-option>
|
||||
@endforeach
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="状态">
|
||||
<el-radio-group v-model="form.active">
|
||||
<el-radio :label="1">启用</el-radio>
|
||||
<el-radio :label="0">禁用</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="save">立即创建</el-button>
|
||||
<el-button>取消</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('footer')
|
||||
<script>
|
||||
new Vue({
|
||||
el: '#app',
|
||||
data() {
|
||||
return {
|
||||
form: {
|
||||
parent_id: 0,
|
||||
active: 1,
|
||||
descriptions: {
|
||||
zh_cn: {
|
||||
name: '',
|
||||
content: '',
|
||||
},
|
||||
en: {
|
||||
name: '',
|
||||
content: '',
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
methods: {
|
||||
save() {
|
||||
axios.post(@json(admin_route('categories.store')), this.form).then(response => {
|
||||
this.loading = false;
|
||||
}).catch(error => {
|
||||
// this.$message.error(error.response.data.message);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
||||
@endpush
|
||||
Loading…
Reference in New Issue