79 lines
2.0 KiB
PHP
79 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Agent\Controllers;
|
|
|
|
use App\Events\CardOrderSignined;
|
|
use App\Models\CardOrder;
|
|
use Auth;
|
|
|
|
class OrderController extends Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
view()->share('app_title', '我的订单');
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$orders = CardOrder::where('user_id', Auth::guard('agent')->id())
|
|
->orderBy('id', 'desc')
|
|
->get();
|
|
|
|
return view('Agent::orders.index', compact('orders'));
|
|
}
|
|
|
|
public function unpay()
|
|
{
|
|
$orders = CardOrder::where('status', 0)
|
|
->where('user_id', Auth::guard('agent')->id())
|
|
->orderBy('id', 'desc')
|
|
->get();
|
|
return view('Agent::orders.index', compact('orders'));
|
|
}
|
|
|
|
public function paid()
|
|
{
|
|
$orders = CardOrder::where('status', 1)
|
|
->where('user_id', Auth::guard('agent')->id())
|
|
->orderBy('id', 'desc')
|
|
->get();
|
|
return view('Agent::orders.index', compact('orders'));
|
|
}
|
|
|
|
public function delivered()
|
|
{
|
|
$orders = CardOrder::where('status', 2)
|
|
->where('user_id', Auth::guard('agent')->id())
|
|
->orderBy('id', 'desc')
|
|
->get();
|
|
return view('Agent::orders.index', compact('orders'));
|
|
}
|
|
|
|
public function signed()
|
|
{
|
|
$orders = CardOrder::where('status', 3)
|
|
->where('user_id', Auth::guard('agent')->id())
|
|
->orderBy('id', 'desc')
|
|
->get();
|
|
return view('Agent::orders.index', compact('orders'));
|
|
}
|
|
|
|
public function sign($orderid)
|
|
{
|
|
$order = CardOrder::where('order_id', $orderid)->firstOrFail();
|
|
try {
|
|
$order->express->update([
|
|
'receive_at' => now(),
|
|
]);
|
|
|
|
$order->status = 3;
|
|
$order->save();
|
|
event(new CardOrderSignined($order));
|
|
return $this->success('签收成功', route('Agent.orders.signed'));
|
|
} catch (\Exception $e) {
|
|
return $this->error('签收失败' . $e->getmessage());
|
|
}
|
|
}
|
|
|
|
}
|