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

66 lines
1.6 KiB

4 years ago
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\IndustryProduct;
  5. use Dcat\Admin\Form;
  6. use Dcat\Admin\Grid\RowAction;
  7. use Illuminate\Http\Request;
  8. use Illuminate\Support\Facades\DB;
  9. /**
  10. * 行业产品审核
  11. * Class AuditAgentProduct
  12. * @package App\Admin\Extensions\Grid
  13. */
  14. class AuditIndustryProduct extends RowAction
  15. {
  16. private $action;
  17. public function __construct($title = null, $action = 1)
  18. {
  19. parent::__construct($title);
  20. $this->action = $action;
  21. $this->title = $action == 1 ? '通过' : '拒绝';
  22. }
  23. protected function html()
  24. {
  25. $class = $this->action == 1 ? 'btn btn-sm btn-success' : 'btn btn-sm btn-danger';
  26. $this->appendHtmlAttribute('class', $class);
  27. $this->defaultHtmlAttribute('href', 'javascript:;');
  28. return "<a {$this->formatHtmlAttributes()}>{$this->title}</a>";
  29. }
  30. public function handle(Request $request)
  31. {
  32. $status = $request->action == 1 ? ProductStatus::ON_SALE : ProductStatus::REFUSE;
  33. try {
  34. //修改产品状态
  35. $industry = IndustryProduct::find($this->getKey());
  36. if ($status == ProductStatus::ON_SALE && $industry->single_deposit <= 0) {
  37. throw new \Exception('请先设置交易金单价!');
  38. }
  39. $industry->status = $status;
  40. $industry->single_deposit = 0;
  41. $industry->save();
  42. return $this->response()->success("审核成功")->refresh();
  43. } catch (\Exception $e) {
  44. return $this->response()->error($e->getMessage());
  45. }
  46. }
  47. public function confirm()
  48. {
  49. return ['确定要'.$this->title.'该产品吗?', ''];
  50. }
  51. public function parameters()
  52. {
  53. return ['action' => $this->action];
  54. }
  55. }