WithdrawReview.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace App\Admin\Actions\Form;
  3. use App\Models\User;
  4. use App\Models\UserWithdraw;
  5. use Carbon\Carbon;
  6. use Dcat\Admin\Contracts\LazyRenderable;
  7. use Dcat\Admin\Traits\LazyWidget;
  8. use Dcat\Admin\Widgets\Form;
  9. class WithdrawReview extends Form implements LazyRenderable
  10. {
  11. use LazyWidget;
  12. public function handle(array $input)
  13. {
  14. $status = $input['status'];
  15. try {
  16. $withdraw = UserWithdraw::find($input['id']);
  17. if ($status > 0) {
  18. $withdraw->status = $status;
  19. // 审核通过或者拒绝
  20. if (1 == $status || 3 == $status) {
  21. $withdraw->review_at = Carbon::now()->toDateTimeString();
  22. }
  23. if (2 == $status) {
  24. $withdraw->withdraw_at = Carbon::now()->toDateTimeString();
  25. }
  26. $withdraw->save();
  27. }
  28. // 驳回返还收益
  29. if (3 == $withdraw->status) {
  30. $user = User::find($withdraw->user_id);
  31. $user->income = $user->income + $withdraw->price;
  32. $user->save();
  33. }
  34. } catch (\Exception $exception) {
  35. return $this->response()->error($exception->getMessage());
  36. }
  37. return $this->response()->success('success')->refresh();
  38. }
  39. public function form()
  40. {
  41. $id = isset($this->payload['id']) ? $this->payload['id'] : 0;
  42. $this->hidden('id')->value($id);
  43. $this->radio('status', '审核结果')
  44. ->options(config('global.withdraw_status'))->default(1);
  45. $this->disableResetButton();
  46. }
  47. }