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

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