OrderCancel.php 814 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace App\Community\Actions\Clinc;
  3. use App\Models\Order;
  4. use Encore\Admin\Actions\RowAction;
  5. use Illuminate\Database\Eloquent\Model;
  6. use Illuminate\Support\Facades\DB;
  7. class OrderCancel extends RowAction
  8. {
  9. public $name = '取消订单';
  10. public function handle(Model $model)
  11. {
  12. $id = $this->row->id;
  13. DB::beginTransaction();
  14. try {
  15. //退还余额
  16. $res = Order::orderCancel($id);
  17. DB::commit();
  18. } catch ( \Exception $e){
  19. dd($e->getMessage());
  20. DB::rollBack();
  21. return $this->response()->error('操作失败!');
  22. }
  23. if($res){
  24. return $this->response()->success('操作成功!')->refresh();
  25. }
  26. return $this->response()->error('操作失败!');
  27. }
  28. }