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

134 lines
3.2 KiB

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