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\Repositories\OrderRepo;
|
||||
use Beike\Services\StateMachineService;
|
||||
use Beike\Shop\Http\Resources\Account\OrderList;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class OrderController extends Controller
|
||||
{
|
||||
/**
|
||||
* 获取订单列表
|
||||
*
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$orders = OrderRepo::getListAll();
|
||||
|
|
@ -27,6 +34,14 @@ class OrderController extends Controller
|
|||
return view('admin::pages.orders.index', $data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查看单个订单
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Order $order
|
||||
* @return mixed
|
||||
*/
|
||||
public function show(Request $request, Order $order)
|
||||
{
|
||||
$order->load(['orderTotals']);
|
||||
|
|
@ -36,4 +51,23 @@ class OrderController extends Controller
|
|||
|
||||
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
|
||||
{
|
||||
$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);
|
||||
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_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>
|
||||
|
||||
@can('orders_update_status')
|
||||
<div class="card mb-4">
|
||||
<div class="card-header"><h6 class="card-title">状态</h6></div>
|
||||
<div class="card-body" id="app">
|
||||
|
|
@ -82,6 +83,7 @@
|
|||
</el-form>
|
||||
</div>
|
||||
</div>
|
||||
@endcan
|
||||
|
||||
<div class="card mb-4">
|
||||
<div class="card-header"><h6 class="card-title">商品信息</h6></div>
|
||||
|
|
@ -112,11 +114,10 @@
|
|||
@endforeach
|
||||
</tbody>
|
||||
<tfoot>
|
||||
@foreach ($order->orderTotals as $order)
|
||||
@foreach ($order->orderTotals as $orderTotal)
|
||||
<tr>
|
||||
{{-- <td colspan="4" class="text-end">{{ $order->title }}: <span class="fw-bold">{{ $order->value }}</span></td> --}}
|
||||
<td colspan="4" class="text-end">{{ $order->title }}</td>
|
||||
<td class="text-end"><span class="fw-bold">{{ $order->value }}</span></td>
|
||||
<td colspan="4" class="text-end">{{ $orderTotal->title }}</td>
|
||||
<td class="text-end"><span class="fw-bold">{{ $orderTotal->value }}</span></td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tfoot>
|
||||
|
|
@ -133,7 +134,8 @@
|
|||
@endsection
|
||||
|
||||
@push('footer')
|
||||
<script>
|
||||
@can('orders_update_status')
|
||||
<script>
|
||||
new Vue({
|
||||
el: '#app',
|
||||
|
||||
|
|
@ -177,5 +179,6 @@
|
|||
}
|
||||
})
|
||||
</script>
|
||||
@endcan
|
||||
@endpush
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue