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

4 years ago
  1. <?php
  2. namespace App\AdminAgent\Controllers;
  3. use App\AdminAgent\Repositories\WithdrawalAlipay;
  4. use App\Models\Agent;
  5. use App\Models\Withdrawal;
  6. use App\Traits\DemandTraits;
  7. use App\Traits\WithdrawalTraits;
  8. use Dcat\Admin\Admin;
  9. use Dcat\Admin\Form;
  10. use Dcat\Admin\Grid;
  11. use Dcat\Admin\Show;
  12. use Dcat\Admin\Http\Controllers\AdminController;
  13. use Illuminate\Database\Eloquent\Model;
  14. use Illuminate\Support\Facades\DB;
  15. class WithdrawalAlipayController extends AdminController
  16. {
  17. /**
  18. * Make a form builder.
  19. *
  20. * @return Form
  21. */
  22. protected function form()
  23. {
  24. return Form::make(new WithdrawalAlipay(), function (Form $form) {
  25. $form->display('id');
  26. $form->decimal('price','提现金额')->required();
  27. $form->text('account')->required();
  28. $form->text('name')->required();
  29. $form->image('qrcode')->required();
  30. $form->hidden('withdrawal_id');
  31. $form->saving(function (Form $form) {
  32. $user = Agent::query()->where('id', Admin::user()->id)->lockForUpdate()->first();
  33. if ($form->price > $user->balance) {
  34. return $form->response()->error('余额不足,当前可用余额为'.$user->balance);
  35. }
  36. $user->balance = bcsub($user->balance,$form->price,6);
  37. $user->save();
  38. $withdrawal = new Withdrawal();
  39. $withdrawal->user_id = Admin::user()->id;
  40. $withdrawal->user_type = DemandTraits::$col[0];
  41. $withdrawal->price = request('price',0);
  42. //$withdrawal->pay_id = $form->getKey();
  43. $withdrawal->pay_type = WithdrawalTraits::$userType[0];
  44. $withdrawal->save();
  45. $form->withdrawal_id = $withdrawal->id;
  46. $form->deleteInput('price');
  47. });
  48. $form->saved(function (Form $form) {
  49. $withdrawal = Withdrawal::find($form->withdrawal_id);
  50. $withdrawal->pay_id = $form->getKey();
  51. $withdrawal->save();
  52. });
  53. });
  54. }
  55. }