188 lines
7.5 KiB
PHP
188 lines
7.5 KiB
PHP
<?php
|
||
/**
|
||
* Created by PhpStorm.
|
||
*
|
||
* User: king/QQ:995265288
|
||
* Date: 2018/7/27 上午11:14
|
||
* Email: livsyitian@163.com
|
||
*/
|
||
|
||
namespace app\backend\modules\withdraw\controllers;
|
||
|
||
|
||
use app\backend\models\Withdraw;
|
||
use app\common\components\BaseController;
|
||
use app\common\facades\Setting;
|
||
use app\common\models\Income;
|
||
use app\common\services\Session;
|
||
use app\common\models\WithdrawMergeServicetaxRate;
|
||
|
||
|
||
class DetailController extends BaseController
|
||
{
|
||
/**
|
||
* @var Withdraw
|
||
*/
|
||
private $withdrawModel;
|
||
|
||
/**
|
||
* 提现记录详情 接口
|
||
*
|
||
* @throws \Throwable
|
||
*/
|
||
public function index()
|
||
{
|
||
if (!$this->withdrawModel = $this->withdrawModel()) return $this->errorJson();
|
||
|
||
return request()->ajax() ? $this->jsonData() : view('withdraw.detail', $this->resultData());
|
||
}
|
||
|
||
private function jsonData()
|
||
{
|
||
return $this->successJson('ok', $this->resultData());
|
||
}
|
||
|
||
private function withdrawModel()
|
||
{
|
||
return Withdraw::with([
|
||
'member',
|
||
'bankCard',
|
||
'hasOneYzMember'
|
||
])->find($this->recordId());
|
||
}
|
||
|
||
/**
|
||
* @return int
|
||
*/
|
||
private function recordId()
|
||
{
|
||
return request()->input('id');
|
||
}
|
||
|
||
private function incomeModels()
|
||
{
|
||
$incomeModels = Income::uniacid()
|
||
->whereIn('yz_member_income.id', explode(',', $this->withdrawModel->type_id))
|
||
->select([
|
||
'yz_member_income.id',
|
||
'yz_member_income.member_id',
|
||
'yz_member_income.dividend_code',
|
||
'yz_member_income.incometable_type',
|
||
'yz_member_income.incometable_id',
|
||
'yz_member_income.type_name',
|
||
'yz_member_income.amount',
|
||
'yz_member_income.status',
|
||
'yz_member_income.pay_status',
|
||
'yz_member_income.created_at',
|
||
'yz_member_income.order_sn',
|
||
'yz_member_income.detail',
|
||
'yz_shareholder_dividend.team_level_name'
|
||
])
|
||
->with(['hasManyOrder' => function ($order) {
|
||
$order->select('id', 'order_sn', 'status', 'refund_id')
|
||
->with(['hasOneRefundApply' => function ($refundApply) {
|
||
$refundApply->select('id', 'status');
|
||
}]);
|
||
}])
|
||
->leftJoin('yz_shareholder_dividend', function ($join) {
|
||
$join->on('yz_shareholder_dividend.id', 'yz_member_income.incometable_id')->where('yz_member_income.dividend_code', 64);
|
||
})
|
||
->get();
|
||
|
||
//按照前段要求更改数据格式
|
||
$incomeModels->map(function ($incomeModel) {
|
||
if ($incomeModel->detail) {
|
||
|
||
$detail = json_decode($incomeModel->detail, 1);
|
||
|
||
if ($incomeModel->hasManyOrder && isset($detail['order'])) {
|
||
$detail['order']['data'][] = [
|
||
'title' => '订单状态',
|
||
'value' => $incomeModel->hasManyOrder->status_name
|
||
];
|
||
if ($incomeModel->hasManyOrder->hasOneRefundApply) {
|
||
$detail['order']['data'][] = [
|
||
'title' => '售后状态',
|
||
'value' => $incomeModel->hasManyOrder->hasOneRefundApply->status_name
|
||
];
|
||
}
|
||
}
|
||
|
||
$incomeModel->detail = collect($detail)->values()->toJson();
|
||
}
|
||
});
|
||
return $incomeModels;
|
||
}
|
||
|
||
private function resultData()
|
||
{
|
||
$result_data = $this->_resultData();
|
||
|
||
if ($this->withdrawModel->status == 0) { //为审核时,如果是合并提现,修改劳务费比例
|
||
$withdraw_set = \Setting::get('withdraw.income');
|
||
if ($this->withdrawModel->pay_way == 'balance' && $withdraw_set['balance_special']) {
|
||
$merge_percent = null;
|
||
} else {
|
||
$merge_percent = WithdrawMergeServicetaxRate::uniacid()->where('withdraw_id', $this->withdrawModel->id)->where('is_disabled', 0)->first();
|
||
}
|
||
if ($merge_percent) {
|
||
$this->withdrawModel->servicetax_rate = $merge_percent->servicetax_rate;
|
||
$base_amount = !$withdraw_set['service_tax_calculation'] ? bcsub($this->withdrawModel->amounts, $this->withdrawModel->poundage, 2) : $this->withdrawModel->amounts;
|
||
$this->withdrawModel->servicetax = bcmul($base_amount, bcdiv($this->withdrawModel->servicetax_rate, 100, 4), 2);
|
||
} elseif ($this->withdrawModel->pay_way != 'balance' || !$withdraw_set['balance_special']) {
|
||
if (!in_array($this->withdrawModel->type,["Yunshop\\StoreCashier\\common\\models\\CashierOrder","Yunshop\\StoreCashier\\common\\models\\StoreOrder","Yunshop\\StoreCashier\\common\\models\\BossOrder"])) {
|
||
$base_amount = !$withdraw_set['service_tax_calculation'] ? bcsub($this->withdrawModel->amounts, $this->withdrawModel->poundage, 2) : $this->withdrawModel->amounts;
|
||
$res = \app\common\services\finance\Withdraw::getWithdrawServicetaxPercent($base_amount,$this->withdrawModel);
|
||
$this->withdrawModel->servicetax_rate = $res['servicetax_percent'];
|
||
$this->withdrawModel->servicetax = $res['servicetax_amount'];
|
||
}
|
||
}
|
||
|
||
$this->withdrawModel->actual_amounts = bcsub(bcsub($this->withdrawModel->amounts, $this->withdrawModel->poundage, 2), $this->withdrawModel->servicetax, 2);
|
||
}
|
||
// 判断:当前时间是否可以进行审核
|
||
$incomeSet = \Setting::get('withdraw.income');
|
||
$withdraw_date_time_start = (int)$incomeSet['withdraw_date_time_start'];
|
||
$withdraw_date_time_end = (int)$incomeSet['withdraw_date_time_end'];
|
||
$startTime = strtotime(date("Y-m-d {$withdraw_date_time_start}:00:00"));
|
||
$startEnd = strtotime(date("Y-m-d {$withdraw_date_time_end}:00:00"));
|
||
$isAllowExamine = true;// 默认允许审核
|
||
if($withdraw_date_time_start > 0 && $withdraw_date_time_end > 0){
|
||
$isAllowExamine = ($startTime < time() && $startEnd > time());
|
||
}else if($withdraw_date_time_start > 0 && $withdraw_date_time_end == 0){
|
||
$isAllowExamine = $startTime < time();
|
||
}else if($withdraw_date_time_start == 0 && $withdraw_date_time_end > 0){
|
||
$isAllowExamine = $startEnd > time();
|
||
}
|
||
$result_data['is_allow_examine'] = $isAllowExamine;
|
||
|
||
return $result_data;
|
||
}
|
||
|
||
private function _resultData()
|
||
{
|
||
$set = Setting::getByGroup('pay_password') ?: [];
|
||
$incomeList = $this->incomeModels();
|
||
|
||
$this->withdrawModel->member->level_name = '';
|
||
if ($this->withdrawModel->member) {
|
||
$this->withdrawModel->member->level_name = $this->withdrawModel->member->levelName();
|
||
}
|
||
|
||
$lang = [
|
||
'special_service_tax' => \Setting::get('shop.lang.zh_cn.income.special_service_tax') ?: '劳务税',
|
||
];
|
||
|
||
return [
|
||
'withdraw' => $this->withdrawModel,
|
||
'income_list' => $incomeList,
|
||
'income_total' => $incomeList->count(),
|
||
'is_verify' => !empty($set['withdraw_verify']['is_phone_verify']) ? true : false,
|
||
'expire_time' => Session::get('withdraw_verify') ?: null,
|
||
'verify_phone' => $set['withdraw_verify']['phone'] ?: "",
|
||
'verify_expire' => $set['withdraw_verify']['verify_expire'] ? intval($set['withdraw_verify']['verify_expire']) : 10,
|
||
'lang' => $lang
|
||
];
|
||
}
|
||
}
|