海南旅游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.

56 lines
1.3 KiB

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