后台品牌管理
This commit is contained in:
parent
badabe39cb
commit
ef0d22ca93
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
/**
|
||||
* ManufacturerController.php
|
||||
*
|
||||
* @copyright 2022 opencart.cn - All Rights Reserved
|
||||
* @link http://www.guangdawangluo.com
|
||||
* @author TL <mengwb@opencart.cn>
|
||||
* @created 2022-07-27 21:17:04
|
||||
* @modified 2022-07-27 21:17:04
|
||||
*/
|
||||
|
||||
namespace Beike\Admin\Http\Controllers;
|
||||
|
||||
use Beike\Repositories\ManufacturerRepo;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ManufacturerController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$manufacturers = ManufacturerRepo::list($request->only('name', 'first', 'status'));
|
||||
$data = [
|
||||
'manufacturers' => $manufacturers,
|
||||
];
|
||||
|
||||
return view('admin::pages.manufacturers.index', $data);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$manufacturer = ManufacturerRepo::create($request->all());
|
||||
return json_success("创建成功", $manufacturer);
|
||||
}
|
||||
|
||||
public function update(Request $request, int $customerId, int $id)
|
||||
{
|
||||
$manufacturer = ManufacturerRepo::update($id, $request->all());
|
||||
|
||||
return json_success("成功修改", $manufacturer);
|
||||
}
|
||||
|
||||
public function destroy(Request $request, int $customerId, int $addressId)
|
||||
{
|
||||
AddressRepo::delete($addressId);
|
||||
|
||||
return json_success("已成功删除");
|
||||
}
|
||||
}
|
||||
|
|
@ -38,6 +38,7 @@ Route::prefix($adminName)
|
|||
Route::post('design/builder/preview', [Controllers\DesignController::class, 'preview'])->name('design.module.preview');
|
||||
|
||||
Route::resource('files', Controllers\FileController::class);
|
||||
Route::resource('manufacturers', Controllers\ManufacturerController::class);
|
||||
|
||||
Route::get('file_manager', [Controllers\FileManagerController::class, 'index'])->name('file_manager.index');
|
||||
Route::get('file_manager/files', [Controllers\FileManagerController::class, 'getFiles'])->name('file_manager.get_files');
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
/**
|
||||
* Manufacturer.php
|
||||
*
|
||||
* @copyright 2022 opencart.cn - All Rights Reserved
|
||||
* @link http://www.guangdawangluo.com
|
||||
* @author TL <mengwb@opencart.cn>
|
||||
* @created 2022-07-27 20:22:18
|
||||
* @modified 2022-07-27 20:22:18
|
||||
*/
|
||||
|
||||
namespace Beike\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Manufacturer extends Base
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = ['name', 'country_id', 'code', 'sort_order', 'status'];
|
||||
|
||||
public function zones(): HasMany
|
||||
{
|
||||
return $this->hasMany(Zone::class);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
<?php
|
||||
/**
|
||||
* ManufacturerRepo.php
|
||||
*
|
||||
* @copyright 2022 opencart.cn - All Rights Reserved
|
||||
* @link http://www.guangdawangluo.com
|
||||
* @author TL <mengwb@opencart.cn>
|
||||
* @created 2022-07-27 20:42:05
|
||||
* @modified 2022-07-27 20:42:05
|
||||
*/
|
||||
|
||||
namespace Beike\Repositories;
|
||||
|
||||
use Beike\Models\Manufacturer;
|
||||
|
||||
class ManufacturerRepo
|
||||
{
|
||||
/**
|
||||
* 创建一个记录
|
||||
* @param $data
|
||||
* @return int
|
||||
*/
|
||||
public static function create($data)
|
||||
{
|
||||
$manufacturer = Manufacturer::query()->create($data);
|
||||
return $manufacturer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $manufacturer
|
||||
* @param $data
|
||||
* @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function update($manufacturer, $data)
|
||||
{
|
||||
if (!$manufacturer instanceof Manufacturer) {
|
||||
$manufacturer = Manufacturer::query()->find($manufacturer);
|
||||
}
|
||||
if (!$manufacturer) {
|
||||
throw new \Exception("品牌id {$manufacturer} 不存在");
|
||||
}
|
||||
$manufacturer->update($data);
|
||||
return $manufacturer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 Manufacturer::query()->find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return void
|
||||
*/
|
||||
public static function delete($id)
|
||||
{
|
||||
$manufacturer = Manufacturer::query()->find($id);
|
||||
if ($manufacturer) {
|
||||
$manufacturer->delete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
|
||||
*/
|
||||
public static function list($data)
|
||||
{
|
||||
$builder = Manufacturer::query();
|
||||
|
||||
if (isset($data['name'])) {
|
||||
$builder->where('name', 'like', "%{$data['name']}%");
|
||||
}
|
||||
if (isset($data['first'])) {
|
||||
$builder->where('first', $data['email']);
|
||||
}
|
||||
if (isset($data['status'])) {
|
||||
$builder->where('status', $data['status']);
|
||||
}
|
||||
|
||||
return $builder->paginate(20)->withQueryString();
|
||||
}
|
||||
|
||||
public static function listGroupByFirst()
|
||||
{
|
||||
$manufacturers = Manufacturer::query()->where('status', true)->get();
|
||||
|
||||
$results = [];
|
||||
foreach ($manufacturers as $manufacturer) {
|
||||
$results[$manufacturer->first][] = $manufacturer;
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateManufacturers extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('manufacturers', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->char('first');
|
||||
$table->string('logo');
|
||||
$table->integer('sort_order');
|
||||
$table->integer('status');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('manufacturers');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
@extends('admin::layouts.master')
|
||||
|
||||
@section('title', '品牌管理')
|
||||
|
||||
@section('content')
|
||||
<div id="manufacturer-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>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($manufacturers as $manufacturer)
|
||||
<tr>
|
||||
<td>{{ $manufacturer['id'] }}</td>
|
||||
<td>{{ $manufacturer['name'] }}</td>
|
||||
<td>{{ $manufacturer['logo'] }}</td>
|
||||
<td>{{ $manufacturer['sort_order'] }}</td>
|
||||
<td>{{ $manufacturer['status'] }}</td>
|
||||
<td>
|
||||
<a class="btn btn-outline-secondary btn-sm"
|
||||
href="{{ admin_route('manufacturers.edit', [$manufacturer['id']]) }}">编辑</a>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
Loading…
Reference in New Issue