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

113 lines
2.6 KiB

4 years ago
  1. <?php
  2. namespace App\Admin\Extensions\Grid;
  3. use App\Common\ProductStatus;
  4. use App\Models\Agent;
  5. use App\Models\Guide;
  6. use App\Models\Product;
  7. use App\Models\Supplier;
  8. use App\Traits\DemandTraits;
  9. use App\Traits\WithdrawalTraits;
  10. use Dcat\Admin\Admin;
  11. use Dcat\Admin\Grid\RowAction;
  12. use Illuminate\Http\Request;
  13. /**
  14. * 供应商审核
  15. * Class AuditProduct
  16. * @package App\Admin\Extensions\Grid
  17. */
  18. class Withdrawal extends RowAction
  19. {
  20. private $action;
  21. public function __construct($title = null, $action = 1)
  22. {
  23. parent::__construct($title);
  24. $this->action = $action; //$action:1=通过;2=拒绝
  25. switch ($action) {
  26. case 1:
  27. $this->title = '通过';
  28. break;
  29. case 2:
  30. $this->title = '拒绝';
  31. break;
  32. case 3:
  33. $this->title = '确认打款';
  34. break;
  35. default:
  36. $this->title = '通过';
  37. }
  38. }
  39. protected function html()
  40. {
  41. switch ($this->action) {
  42. case 1:
  43. $class = 'btn btn-sm btn-success';
  44. break;
  45. case 2:
  46. $class = 'btn btn-sm btn-danger';
  47. break;
  48. case 3:
  49. $class = 'btn btn-sm btn-info';
  50. break;
  51. default:
  52. $class = 'btn btn-sm btn-success';
  53. }
  54. $this->appendHtmlAttribute('class', $class);
  55. $this->defaultHtmlAttribute('href', 'javascript:;');
  56. return "<a {$this->formatHtmlAttributes()}>{$this->title}</a>";
  57. }
  58. public function handle(Request $request)
  59. {
  60. try {
  61. if ($request->action == 1) {
  62. //同意打款
  63. $withdrawal = \App\Models\Withdrawal::find($this->getKey());
  64. $withdrawal->status = WithdrawalTraits::$state[2];
  65. } elseif ($request->action == 2) {
  66. //拒绝打款
  67. $withdrawal = \App\Models\Withdrawal::find($this->getKey());
  68. $withdrawal->status = WithdrawalTraits::$state[1];
  69. //退回余额
  70. if ($withdrawal->user_type == DemandTraits::$col[0]) {
  71. $user = Agent::query();
  72. } elseif($withdrawal->user_type == DemandTraits::$col[1]) {
  73. $user = Supplier::query();
  74. } elseif($withdrawal->user_type == DemandTraits::$col[2]) {
  75. $user = Guide::query();
  76. }
  77. $user = $user->where('id', $withdrawal->user_id)->lockForUpdate()->first();
  78. $user->balance = bcadd($user->balance,$withdrawal->price,6);
  79. $user->save();
  80. } elseif ($request->action == 3) {
  81. //确认打款
  82. $withdrawal = \App\Models\Withdrawal::find($this->getKey());
  83. $withdrawal->status = WithdrawalTraits::$state[3];
  84. }
  85. $withdrawal->save();
  86. return $this->response()->success("操作成功")->refresh();
  87. } catch (\Exception $e) {
  88. return $this->response()->error($e->getMessage());
  89. }
  90. }
  91. public function confirm()
  92. {
  93. return ['确定要'.$this->title.'本次提现吗?', ''];
  94. }
  95. public function parameters()
  96. {
  97. return ['action' => $this->action];
  98. }
  99. }