WithdrawReview.php 1.6 KB

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