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

64 lines
1.5 KiB

4 years ago
4 years ago
4 years ago
4 years ago
  1. <?php
  2. namespace App\Admin\Extensions\Grid;
  3. use App\Models\Guide;
  4. use App\Common\UserStatus;
  5. use Dcat\Admin\Admin;
  6. use Dcat\Admin\Grid\RowAction;
  7. use Illuminate\Http\Request;
  8. use Illuminate\Support\Facades\DB;
  9. /**
  10. * 供应商审核
  11. * Class AuditSupplier
  12. * @package App\Admin\Extensions\Grid
  13. */
  14. class AuditGuide extends RowAction
  15. {
  16. private $action;
  17. public function __construct($title = null, $action = 1)
  18. {
  19. parent::__construct($title);
  20. $this->action = $action; //$action:1=通过;2=拒绝
  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. try {
  33. $user = Guide::find($this->getKey());
  34. $user->status = $request->action == 1 ? UserStatus::NORMAL : UserStatus::REFUSE;
  35. $user->save();
  36. //插入权限表
  37. if ($user->status == UserStatus::NORMAL) {
  38. DB::table(config('admin-guide.database.role_users_table'))
  39. ->insertOrIgnore(['role_id' => 1, 'user_id' => $user->id]);
  40. }
  41. return $this->response()->success("审核成功")->refresh();
  42. } catch (\Exception $e) {
  43. return $this->response()->error($e->getMessage());
  44. }
  45. }
  46. public function confirm()
  47. {
  48. return ['确定要'.$this->title.'该用户吗?', ''];
  49. }
  50. public function parameters()
  51. {
  52. return ['action' => $this->action];
  53. }
  54. }