2 changed files with 58 additions and 5 deletions
-
17app/AdminAgent/Controllers/OrderController.php
-
46app/AdminAgent/Extensions/Grid/ChangeOrderStatus.php
@ -0,0 +1,46 @@ |
|||
<?php |
|||
|
|||
namespace App\AdminAgent\Extensions\Grid; |
|||
use App\Common\OrderStatus; |
|||
use App\Models\Order; |
|||
use Dcat\Admin\Admin; |
|||
use Dcat\Admin\Grid\RowAction; |
|||
|
|||
/** |
|||
* 改变订单状态 |
|||
* Class ChangeOrderStatus |
|||
* @package App\AdminAgent\Extensions\Grid |
|||
*/ |
|||
class ChangeOrderStatus extends RowAction |
|||
{ |
|||
protected $title = '设为 [线下]已付款'; |
|||
|
|||
protected function html() |
|||
{ |
|||
$this->appendHtmlAttribute('class', 'btn btn-sm btn-success'); |
|||
$this->defaultHtmlAttribute('href', 'javascript:;'); |
|||
|
|||
return "<a {$this->formatHtmlAttributes()}>{$this->title}</a>"; |
|||
} |
|||
|
|||
public function handle() |
|||
{ |
|||
try { |
|||
$order = Order::firstWhere(['id' => $this->getKey(), 'agent_id' => Admin::user()->id, 'status' => OrderStatus::OFFLINE_UNPAID]); |
|||
if (!$order) { |
|||
return $this->response()->error("订单不存在或已处理过了")->refresh(); |
|||
} |
|||
$order->status = OrderStatus::OFFLINE_PAID; |
|||
$order->save(); |
|||
|
|||
return $this->response()->success("操作成功,已设置为“线下已付款”")->refresh(); |
|||
} catch (\Exception $e) { |
|||
return $this->response()->error($e->getMessage()); |
|||
} |
|||
} |
|||
|
|||
public function confirm() |
|||
{ |
|||
return ['确定要设置为已付款吗?', '']; |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue