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

63 lines
1.5 KiB

4 years ago
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\Grid\RowAction;
  6. use Illuminate\Http\Request;
  7. use Illuminate\Support\Facades\DB;
  8. /**
  9. * 行业产品审核
  10. * Class AuditAgentProduct
  11. * @package App\Admin\Extensions\Grid
  12. */
  13. class AuditIndustryProduct 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. DB::beginTransaction();
  32. try {
  33. //修改产品状态
  34. $industry = IndustryProduct::find($this->getKey());
  35. $industry->status = $request->action == 1 ? ProductStatus::ON_SALE : ProductStatus::REFUSE;
  36. $industry->save();
  37. //如果是拒绝,返还冻结金额
  38. DB::commit();
  39. return $this->response()->success("审核成功")->refresh();
  40. } catch (\Exception $e) {
  41. DB::rollBack();
  42. return $this->response()->error($e->getMessage());
  43. }
  44. }
  45. public function confirm()
  46. {
  47. return ['确定要'.$this->title.'该产品吗?', ''];
  48. }
  49. public function parameters()
  50. {
  51. return ['action' => $this->action];
  52. }
  53. }