海南旅游SAAS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.4 KiB

4 years ago
4 years ago
4 years ago
  1. <?php
  2. namespace App\Admin\Extensions\Grid;
  3. use App\Common\ProductStatus;
  4. use App\Models\DemandProduct;
  5. use App\Models\Product;
  6. use Dcat\Admin\Grid\RowAction;
  7. use Illuminate\Http\Request;
  8. /**
  9. * 供应商审核
  10. * Class AuditDemandProduct
  11. * @package App\Admin\Extensions\Grid
  12. */
  13. class AuditDemandProduct extends RowAction
  14. {
  15. private $action;
  16. public function __construct($title = null, $action = 1)
  17. {
  18. parent::__construct($title);
  19. $this->action = $action; //$action:1=通过;2=拒绝
  20. $this->title = $action == 1 ? '通过' : '拒绝';
  21. }
  22. protected function html()
  23. {
  24. $class = $this->action == 1 ? 'btn btn-sm btn-success' : 'btn btn-sm btn-danger';
  25. $this->appendHtmlAttribute('class', $class);
  26. $this->defaultHtmlAttribute('href', 'javascript:;');
  27. return "<a {$this->formatHtmlAttributes()}>{$this->title}</a>";
  28. }
  29. public function handle(Request $request)
  30. {
  31. try {
  32. $product = DemandProduct::find($this->getKey());
  33. $product->status = $request->action == 1 ? ProductStatus::ON_SALE : ProductStatus::REFUSE;
  34. $product->save();
  35. return $this->response()->success("审核成功")->refresh();
  36. } catch (\Exception $e) {
  37. return $this->response()->error($e->getMessage());
  38. }
  39. }
  40. public function confirm()
  41. {
  42. return ['确定要'.$this->title.'该产品吗?', ''];
  43. }
  44. public function parameters()
  45. {
  46. return ['action' => $this->action];
  47. }
  48. }