DetailController.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. *
  5. * User: king/QQ:995265288
  6. * Date: 2018/7/27 上午11:14
  7. * Email: livsyitian@163.com
  8. */
  9. namespace app\backend\modules\withdraw\controllers;
  10. use app\backend\models\Withdraw;
  11. use app\common\components\BaseController;
  12. use app\common\facades\Setting;
  13. use app\common\models\Income;
  14. use app\common\services\Session;
  15. use app\common\models\WithdrawMergeServicetaxRate;
  16. class DetailController extends BaseController
  17. {
  18. /**
  19. * @var Withdraw
  20. */
  21. private $withdrawModel;
  22. /**
  23. * 提现记录详情 接口
  24. *
  25. * @throws \Throwable
  26. */
  27. public function index()
  28. {
  29. if (!$this->withdrawModel = $this->withdrawModel()) return $this->errorJson();
  30. return request()->ajax() ? $this->jsonData() : view('withdraw.detail', $this->resultData());
  31. }
  32. private function jsonData()
  33. {
  34. return $this->successJson('ok', $this->resultData());
  35. }
  36. private function withdrawModel()
  37. {
  38. return Withdraw::with([
  39. 'member',
  40. 'bankCard',
  41. 'hasOneYzMember'
  42. ])->find($this->recordId());
  43. }
  44. /**
  45. * @return int
  46. */
  47. private function recordId()
  48. {
  49. return request()->input('id');
  50. }
  51. private function incomeModels()
  52. {
  53. $incomeModels = Income::getIncomeByIds($this->withdrawModel->type_id)
  54. ->select('id','member_id','dividend_code','incometable_type','incometable_id','type_name','amount',
  55. 'status','pay_status','created_at','order_sn','detail')
  56. ->with(['hasManyOrder'=>function($order) {
  57. $order->select('id','order_sn','status','refund_id')
  58. ->with(['hasOneRefundApply'=>function($refundApply) {
  59. $refundApply->select('id','status');
  60. }]);
  61. }])->get();
  62. //按照前段要求更改数据格式
  63. $incomeModels->map(function ($incomeModel) {
  64. if ($incomeModel->detail) {
  65. $detail = json_decode($incomeModel->detail, 1);
  66. if ($incomeModel->hasManyOrder && isset($detail['order'])) {
  67. $detail['order']['data'][] = [
  68. 'title' => '订单状态',
  69. 'value' => $incomeModel->hasManyOrder->status_name
  70. ];
  71. if ($incomeModel->hasManyOrder->hasOneRefundApply) {
  72. $detail['order']['data'][] = [
  73. 'title' => '售后状态',
  74. 'value' => $incomeModel->hasManyOrder->hasOneRefundApply->status_name
  75. ];
  76. }
  77. }
  78. $incomeModel->detail = collect($detail)->values()->toJson();
  79. }
  80. });
  81. return $incomeModels;
  82. }
  83. private function resultData()
  84. {
  85. $result_data = $this->_resultData();
  86. if ($this->withdrawModel->status == 0) { //为审核时,如果是合并提现,修改劳务费比例
  87. $withdraw_set = \Setting::get('withdraw.income');
  88. if ($this->withdrawModel->pay_way == 'balance' && $withdraw_set['balance_special']) {
  89. $merge_percent = null;
  90. } else {
  91. $merge_percent = WithdrawMergeServicetaxRate::uniacid()->where('withdraw_id', $this->withdrawModel->id)->where('is_disabled', 0)->first();
  92. }
  93. if ($merge_percent) {
  94. $this->withdrawModel->servicetax_rate = $merge_percent->servicetax_rate;
  95. $base_amount = !$withdraw_set['service_tax_calculation'] ? bcsub($this->withdrawModel->amounts, $this->withdrawModel->poundage, 2) : $this->withdrawModel->amounts;
  96. $this->withdrawModel->servicetax = bcmul($base_amount, bcdiv($this->withdrawModel->servicetax_rate, 100, 4), 2);
  97. } elseif ($this->withdrawModel->pay_way != 'balance' || !$withdraw_set['balance_special']) {
  98. $base_amount = !$withdraw_set['service_tax_calculation'] ? bcsub($this->withdrawModel->amounts, $this->withdrawModel->poundage, 2) : $this->withdrawModel->amounts;
  99. $res = \app\common\services\finance\Withdraw::getWithdrawServicetaxPercent($base_amount,$this->withdrawModel);
  100. $this->withdrawModel->servicetax_rate = $res['servicetax_percent'];
  101. $this->withdrawModel->servicetax = $res['servicetax_amount'];
  102. }
  103. $this->withdrawModel->actual_amounts = bcsub(bcsub($this->withdrawModel->amounts, $this->withdrawModel->poundage, 2), $this->withdrawModel->servicetax, 2);
  104. }
  105. return $result_data;
  106. }
  107. private function _resultData()
  108. {
  109. $set = Setting::getByGroup('pay_password') ?: [];
  110. $incomeList = $this->incomeModels();
  111. $this->withdrawModel->member->level_name = '';
  112. if ($this->withdrawModel->member) {
  113. $this->withdrawModel->member->level_name = $this->withdrawModel->member->levelName();
  114. }
  115. return [
  116. 'withdraw' => $this->withdrawModel,
  117. 'income_list' => $incomeList,
  118. 'income_total' => $incomeList->count(),
  119. 'is_verify' => !empty($set['withdraw_verify']['is_phone_verify']) ? true : false,
  120. 'expire_time' => Session::get('withdraw_verify') ?: null,
  121. 'verify_phone' => $set['withdraw_verify']['phone'] ?: "",
  122. 'verify_expire' => $set['withdraw_verify']['verify_expire'] ? intval($set['withdraw_verify']['verify_expire']) : 10
  123. ];
  124. }
  125. }