update order statues
This commit is contained in:
parent
9e7ddd2ac0
commit
6aa541d761
|
|
@ -13,11 +13,18 @@ namespace Beike\Admin\Http\Controllers;
|
||||||
|
|
||||||
use Beike\Models\Order;
|
use Beike\Models\Order;
|
||||||
use Beike\Repositories\OrderRepo;
|
use Beike\Repositories\OrderRepo;
|
||||||
|
use Beike\Services\StateMachineService;
|
||||||
use Beike\Shop\Http\Resources\Account\OrderList;
|
use Beike\Shop\Http\Resources\Account\OrderList;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
class OrderController extends Controller
|
class OrderController extends Controller
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* 获取订单列表
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
$orders = OrderRepo::getListAll();
|
$orders = OrderRepo::getListAll();
|
||||||
|
|
@ -27,6 +34,14 @@ class OrderController extends Controller
|
||||||
return view('admin::pages.orders.index', $data);
|
return view('admin::pages.orders.index', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查看单个订单
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @param Order $order
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
public function show(Request $request, Order $order)
|
public function show(Request $request, Order $order)
|
||||||
{
|
{
|
||||||
$order->load(['orderTotals']);
|
$order->load(['orderTotals']);
|
||||||
|
|
@ -36,4 +51,23 @@ class OrderController extends Controller
|
||||||
|
|
||||||
return view('admin::pages.orders.form', $data);
|
return view('admin::pages.orders.form', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新订单状态,添加订单更新日志
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @param Order $order
|
||||||
|
* @return array
|
||||||
|
* @throws \Throwable
|
||||||
|
*/
|
||||||
|
public function updateStatus(Request $request, Order $order)
|
||||||
|
{
|
||||||
|
$status = $request->get('status');
|
||||||
|
$comment = $request->get('comment');
|
||||||
|
$notify = $request->get('notify');
|
||||||
|
$stateMachine = new StateMachineService($order);
|
||||||
|
$stateMachine->changeStatus($status, $comment, $notify);
|
||||||
|
return json_success('更新成功');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ class PermissionRepo
|
||||||
*/
|
*/
|
||||||
private function getOrderPermissions(): array
|
private function getOrderPermissions(): array
|
||||||
{
|
{
|
||||||
$routes = ['orders_index', 'orders_create', 'orders_show', 'orders_update', 'orders_delete'];
|
$routes = ['orders_index', 'orders_create', 'orders_show', 'orders_update', 'orders_delete', 'orders_update_status'];
|
||||||
$items = $this->getPermissionList('order', $routes);
|
$items = $this->getPermissionList('order', $routes);
|
||||||
return hook_filter('role.order_permissions', $items);
|
return hook_filter('role.order_permissions', $items);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,7 @@ Route::prefix($adminName)
|
||||||
// 订单
|
// 订单
|
||||||
Route::middleware('can:orders_index')->get('orders', [Controllers\OrderController::class, 'index'])->name('orders.index');
|
Route::middleware('can:orders_index')->get('orders', [Controllers\OrderController::class, 'index'])->name('orders.index');
|
||||||
Route::middleware('can:orders_show')->get('orders/{order}', [Controllers\OrderController::class, 'show'])->name('orders.show');
|
Route::middleware('can:orders_show')->get('orders/{order}', [Controllers\OrderController::class, 'show'])->name('orders.show');
|
||||||
|
Route::middleware('can:orders_update_status')->put('orders/{order}/status', [Controllers\OrderController::class, 'updateStatus'])->name('orders.update_status');
|
||||||
|
|
||||||
|
|
||||||
// 插件
|
// 插件
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* OrderHistory.php
|
||||||
|
*
|
||||||
|
* @copyright 2022 opencart.cn - All Rights Reserved
|
||||||
|
* @link http://www.guangdawangluo.com
|
||||||
|
* @author Edward Yang <yangjin@opencart.cn>
|
||||||
|
* @created 2022-08-08 17:53:53
|
||||||
|
* @modified 2022-08-08 17:53:53
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Beike\Models;
|
||||||
|
|
||||||
|
class OrderHistory extends Base
|
||||||
|
{
|
||||||
|
protected $fillable = [
|
||||||
|
'order_id', 'status', 'notify', 'comment'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,61 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* StateMachineService.php
|
||||||
|
*
|
||||||
|
* @copyright 2022 opencart.cn - All Rights Reserved
|
||||||
|
* @link http://www.guangdawangluo.com
|
||||||
|
* @author Edward Yang <yangjin@opencart.cn>
|
||||||
|
* @created 2022-08-08 18:21:47
|
||||||
|
* @modified 2022-08-08 18:21:47
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Beike\Services;
|
||||||
|
|
||||||
|
use Beike\Models\Order;
|
||||||
|
use Beike\Models\OrderHistory;
|
||||||
|
|
||||||
|
class StateMachineService
|
||||||
|
{
|
||||||
|
private Order $order;
|
||||||
|
private int $orderId;
|
||||||
|
|
||||||
|
public function __construct(Order $order)
|
||||||
|
{
|
||||||
|
$this->order = $order;
|
||||||
|
$this->orderId = $order->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $status
|
||||||
|
* @param string $comment
|
||||||
|
* @param false $notify
|
||||||
|
* @throws \Throwable
|
||||||
|
*/
|
||||||
|
public function changeStatus($status, string $comment = '', bool $notify = false)
|
||||||
|
{
|
||||||
|
$order = $this->order;
|
||||||
|
|
||||||
|
$this->createOrderHistory($status, $comment, $notify);
|
||||||
|
$order->status = $status;
|
||||||
|
$order->saveOrFail();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $status
|
||||||
|
* @param string $comment
|
||||||
|
* @param false $notify
|
||||||
|
* @throws \Throwable
|
||||||
|
*/
|
||||||
|
private function createOrderHistory($status, string $comment = '', bool $notify = false)
|
||||||
|
{
|
||||||
|
$history = new OrderHistory([
|
||||||
|
'order_id' => $this->orderId,
|
||||||
|
'status' => $status,
|
||||||
|
'comment' => $comment,
|
||||||
|
'notify' => $notify
|
||||||
|
]);
|
||||||
|
$history->saveOrFail();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration {
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('order_histories', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->integer('order_id');
|
||||||
|
$table->string('status');
|
||||||
|
$table->boolean('notify');
|
||||||
|
$table->text('comment');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
@ -51,6 +51,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@can('orders_update_status')
|
||||||
<div class="card mb-4">
|
<div class="card mb-4">
|
||||||
<div class="card-header"><h6 class="card-title">状态</h6></div>
|
<div class="card-header"><h6 class="card-title">状态</h6></div>
|
||||||
<div class="card-body" id="app">
|
<div class="card-body" id="app">
|
||||||
|
|
@ -82,6 +83,7 @@
|
||||||
</el-form>
|
</el-form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@endcan
|
||||||
|
|
||||||
<div class="card mb-4">
|
<div class="card mb-4">
|
||||||
<div class="card-header"><h6 class="card-title">商品信息</h6></div>
|
<div class="card-header"><h6 class="card-title">商品信息</h6></div>
|
||||||
|
|
@ -112,11 +114,10 @@
|
||||||
@endforeach
|
@endforeach
|
||||||
</tbody>
|
</tbody>
|
||||||
<tfoot>
|
<tfoot>
|
||||||
@foreach ($order->orderTotals as $order)
|
@foreach ($order->orderTotals as $orderTotal)
|
||||||
<tr>
|
<tr>
|
||||||
{{-- <td colspan="4" class="text-end">{{ $order->title }}: <span class="fw-bold">{{ $order->value }}</span></td> --}}
|
<td colspan="4" class="text-end">{{ $orderTotal->title }}</td>
|
||||||
<td colspan="4" class="text-end">{{ $order->title }}</td>
|
<td class="text-end"><span class="fw-bold">{{ $orderTotal->value }}</span></td>
|
||||||
<td class="text-end"><span class="fw-bold">{{ $order->value }}</span></td>
|
|
||||||
</tr>
|
</tr>
|
||||||
@endforeach
|
@endforeach
|
||||||
</tfoot>
|
</tfoot>
|
||||||
|
|
@ -133,7 +134,8 @@
|
||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
@push('footer')
|
@push('footer')
|
||||||
<script>
|
@can('orders_update_status')
|
||||||
|
<script>
|
||||||
new Vue({
|
new Vue({
|
||||||
el: '#app',
|
el: '#app',
|
||||||
|
|
||||||
|
|
@ -177,5 +179,6 @@
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
@endcan
|
||||||
@endpush
|
@endpush
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue