优化押金

master
ELF 5 years ago
parent 50755b89c5
commit 42547128d4

@ -17,154 +17,81 @@ class PresidentDepositController extends ThinkController
$companyType = I('company_type'); $companyType = I('company_type');
$payType = I('pay_type'); $payType = I('pay_type');
$status = I('status'); $status = I('status');
$promoteId = I('promote_id'); $companyId = I('company_id', 0);
$query = M('promote', 'tab_')->where(['level' => 1])->where(['company_belong' => ['in', [1, 2]]]); $where = [
'_string' => '1=1',
$idStrWhere = []; 'company_belong' => ['in', [1, 2]]
if ($promoteId !== '') { ];
$idStrWhere[] = 'id = ' . $promoteId; if ($companyId != '') {
$where['id'] = $companyId;
} }
if ($companyType !== '') { if ($companyType !== '') {
$query->where(['company_belong' => $companyType]); $where['_string'] .= ' and company_belong=' . $companyType;
} }
$promoteIds = []; $depositWhere = [];
$depositStrWhere = '1=1';
if ($status !== '') { if ($status !== '') {
if ($status == '-1') { // 市场待审核 if ($status == '-1') {
$tempPromoteIds = M('president_deposit', 'tab_')->getField('promote_id', true); $companyIds = M('president_deposit', 'tab_')->getField('company_id', true);
if (count($tempPromoteIds) > 0) { if (count($companyIds) > 0) {
$idStrWhere[] = 'id not in (' . implode(',', $tempPromoteIds) . ')'; $depositStrWhere .= ' and company_id not in (' . implode(',', $companyIds) . ')';
} }
} else { } else {
$tempPromoteIds = M('president_deposit', 'tab_')->where(['status' => $status])->getField('promote_id', true); $depositWhere['status'] = $status;
if (count($tempPromoteIds) > 0) {
$idStrWhere[] = 'id in (' . implode(',', $tempPromoteIds) . ')';
} else {
$idStrWhere[] = '1<>1';
}
} }
} }
if (!empty(I('pay_confirm_time_start')) && empty(I('pay_confirm_time_end'))) { if (I('pay_confirm_time_start', '') != '') {
$startTime = strtotime(I('pay_confirm_time_start')); $depositStrWhere .= ' and pay_confirm_time>=' . strtotime(I('pay_confirm_time_start') . ' 00:00:00');
$endTime = strtotime(I('pay_confirm_time_end')) + 86400;
$tempPromoteIds = M('president_deposit', 'tab_')->where("pay_confirm_time >= {$startTime}")->getField('promote_id', true);
if (count($tempPromoteIds) > 0) {
$idStrWhere[] = 'id in (' . implode(',', $tempPromoteIds) . ')';
} else {
$idStrWhere[] = '1<>1';
}
} else if (empty(I('pay_confirm_time_start')) && !empty(I('pay_confirm_time_end'))) {
$startTime = strtotime(I('pay_confirm_time_start'));
$endTime = strtotime(I('pay_confirm_time_end')) + 86400;
$tempPromoteIds = M('president_deposit', 'tab_')->where("pay_confirm_time <= {$endTime}")->getField('promote_id', true);
if (count($tempPromoteIds) > 0) {
$idStrWhere[] = 'id in (' . implode(',', $tempPromoteIds) . ')';
} else {
$idStrWhere[] = '1<>1';
}
} else if (!empty(I('pay_confirm_time_start')) && !empty(I('pay_confirm_time_end'))) {
$startTime = strtotime(I('pay_confirm_time_start'));
$endTime = strtotime(I('pay_confirm_time_end')) + 86400;
$tempPromoteIds = M('president_deposit', 'tab_')->where("pay_confirm_time >= {$startTime} and pay_confirm_time <= {$endTime}")->getField('promote_id', true);
if (count($tempPromoteIds) > 0) {
$idStrWhere[] = 'id in (' . implode(',', $tempPromoteIds) . ')';
} else {
$idStrWhere[] = '1<>1';
}
} }
if (I('pay_confirm_time_end', '') != '') {
if (!empty(I('refund_time_start')) && empty(I('refund_time_end'))) { $depositStrWhere .= ' and pay_confirm_time<=' . strtotime(I('pay_confirm_time_end') . ' 23:59:59');
$startTime = strtotime(I('refund_time_start'));
$endTime = strtotime(I('refund_time_end')) + 86400;
$tempPromoteIds = M('president_deposit', 'tab_')->where("refund_time >= {$startTime}")->getField('promote_id', true);
if (count($tempPromoteIds) > 0) {
$idStrWhere[] = 'id in (' . implode(',', $tempPromoteIds) . ')';
} else {
$idStrWhere[] = '1<>1';
}
} else if (empty(I('refund_time_start')) && !empty(I('refund_time_end'))) {
$startTime = strtotime(I('refund_time_start'));
$endTime = strtotime(I('refund_time_end'))+ 86400;
$tempPromoteIds = M('president_deposit', 'tab_')->where("refund_time <= {$endTime}")->getField('promote_id', true);
if (count($tempPromoteIds) > 0) {
$idStrWhere[] = 'id in (' . implode(',', $tempPromoteIds) . ')';
} else {
$idStrWhere[] = '1<>1';
}
} else if (!empty(I('refund_time_start')) && !empty(I('refund_time_end'))) {
$startTime = strtotime(I('refund_time_start'));
$endTime = strtotime(I('refund_time_end'))+ 86400;
$tempPromoteIds = M('president_deposit', 'tab_')->where("refund_time >= {$startTime} and refund_time <= {$endTime}")->getField('promote_id', true);
if (count($tempPromoteIds) > 0) {
$idStrWhere[] = 'id in (' . implode(',', $tempPromoteIds) . ')';
} else {
$idStrWhere[] = '1<>1';
}
} }
if (!empty(I('pay_accept_time_start')) && empty(I('pay_accept_time_end'))) { if (I('refund_time_start', '') != '') {
$startTime = strtotime(I('pay_accept_time_start')); $depositStrWhere .= ' and refund_time>=' . strtotime(I('refund_time_start') . ' 00:00:00');
$endTime = strtotime(I('pay_accept_time_end'))+ 86400; }
$tempPromoteIds = M('president_deposit', 'tab_')->where("pay_accept_time >= {$startTime}")->getField('promote_id', true); if (I('refund_time_end', '') != '') {
if (count($tempPromoteIds) > 0) { $depositStrWhere .= ' and refund_time<=' . strtotime(I('refund_time_end') . ' 23:59:59');
$idStrWhere[] = 'id in (' . implode(',', $tempPromoteIds) . ')';
} else {
$idStrWhere[] = '1<>1';
}
} else if (empty(I('pay_accept_time_start')) && !empty(I('pay_accept_time_end'))) {
$startTime = strtotime(I('pay_accept_time_start'));
$endTime = strtotime(I('pay_accept_time_end'))+ 86400;
$tempPromoteIds = M('president_deposit', 'tab_')->where("pay_accept_time <= {$endTime}")->getField('promote_id', true);
if (count($tempPromoteIds) > 0) {
$idStrWhere[] = 'id in (' . implode(',', $tempPromoteIds) . ')';
} else {
$idStrWhere[] = '1<>1';
}
} else if (!empty(I('pay_accept_time_start')) && !empty(I('pay_accept_time_end'))) {
$startTime = strtotime(I('pay_accept_time_start'));
$endTime = strtotime(I('pay_accept_time_end'))+ 86400;
$tempPromoteIds = M('president_deposit', 'tab_')->where("pay_accept_time >= {$startTime} and pay_accept_time <= {$endTime}")->getField('promote_id', true);
if (count($tempPromoteIds) > 0) {
$idStrWhere[] = 'id in (' . implode(',', $tempPromoteIds) . ')';
} else {
$idStrWhere[] = '1<>1';
}
} }
if (I('pay_accept_time_start', '') != '') {
$depositStrWhere .= ' and pay_accept_time>=' . strtotime(I('pay_accept_time_start') . ' 00:00:00');
}
if (I('pay_accept_time_end', '') != '') {
$depositStrWhere .= ' and pay_accept_time<=' . strtotime(I('pay_accept_time_end') . ' 23:59:59');
}
if ($payType !== '') { if ($payType !== '') {
$tempPromoteIds = M('president_deposit', 'tab_')->where(['pay_type' => $payType])->getField('promote_id', true); $depositWhere['pay_type'] = $payType;
if (count($tempPromoteIds) > 0) {
$idStrWhere[] = 'id in (' . implode(',', $tempPromoteIds) . ')';
} else {
$idStrWhere[] = '1<>1';
}
} }
$subSql = M('president_deposit', 'tab_')->field('company_id')->where($depositWhere)->select(false);
$where['_string'] .= ' and id in (' . $subSql . ')';
if (!empty(I('admin_id', 0))) { if (!empty(I('admin_id', 0))) {
$query->where(['admin_id' => I('admin_id', 0)]); $query->where(['admin_id' => I('admin_id', 0)]);
} }
if (count($idStrWhere) > 0) {
$query->where(['_string' => implode(' and ', array_unique($idStrWhere))]);
}
$promotes = []; $query = M('promote_company', 'tab_')->where($where);
$count = 0; $count = 0;
$totalQuery = clone $query; $totalQuery = clone $query;
$companies = [];
if (I('export', 0) == 1 || $row == 'all') { if (I('export', 0) == 1 || $row == 'all') {
$promotes = $query->select(); $companies = $query->select();
$count = count($promotes); $count = count($promotes);
} else { } else {
$countQuery = clone $query; $countQuery = clone $query;
$promotes = $query->page($page, $row)->select(); $companies = $query->page($page, $row)->select();
$count = $countQuery->count(); $count = $countQuery->count();
} }
// 汇总金额 // 汇总金额
if (count($promotes) > 0 || (isset($count) && $count > 0)) { if (count($companies) > 0 || (isset($count) && $count > 0)) {
$total = M('president_deposit', 'tab_')->where(['promote_id'=>['in', $totalQuery->getField('id', true)]])->field('sum(amount) as totalAmount, sum(if(status = 1, amount, 0)) as confirmedAmount, sum(if(status = 2, amount, 0)) as refundedAmount')->find(); $total = M('president_deposit', 'tab_')->where(['promote_id'=>['in', $totalQuery->getField('id', true)]])->field('sum(amount) as totalAmount, sum(if(status = 1, amount, 0)) as confirmedAmount, sum(if(status = 2, amount, 0)) as refundedAmount')->find();
$total = [ $total = [
'totalamount' => $total['totalamount'] ?? 0, 'confirmedamount' => $total['confirmedamount'] ?? 0, 'refundedamount' => $total['refundedamount'] ?? 0 'totalamount' => $total['totalamount'] ?? 0, 'confirmedamount' => $total['confirmedamount'] ?? 0, 'refundedamount' => $total['refundedamount'] ?? 0
@ -175,17 +102,9 @@ class PresidentDepositController extends ThinkController
]; ];
} }
$relationQuery = M('promote_company', 'tab_')->field(['id', 'company_name']);
$promotes = $this->mergeOneReletions('company', $promotes, $relationQuery, 'company_id', 'id');
$relationQuery = M('president_deposit', 'tab_'); $relationQuery = M('president_deposit', 'tab_');
$promotes = $this->mergeOneReletions('presidentDeposit', $promotes, $relationQuery, 'id', 'promote_id'); $companies = $this->mergeOneReletions('presidentDeposit', $companies, $relationQuery, 'id', 'company_id');
$relationQuery = M('promote_belong', 'tab_')->field(['verify_time', 'promote_id']);
$promotes = $this->mergeOneReletions('promoteBelong', $promotes, $relationQuery, 'id', 'promote_id');
/*echo '<pre>';
var_dump($promotes);
echo '</pre>';
die();*/
$companyTypes = [ $companyTypes = [
1 => '外团', 1 => '外团',
2 => '外团-分发联盟', 2 => '外团-分发联盟',
@ -195,17 +114,15 @@ class PresidentDepositController extends ThinkController
$statusList = PresidentDepositService::$statusList; $statusList = PresidentDepositService::$statusList;
$records = []; $records = [];
if (count($promotes) > 0) { if (count($companies) > 0) {
foreach ($promotes as $promote) { foreach ($companies as $company) {
$record = [ $record = [
'id' => $promote['id'], 'id' => $company['id'],
'company_name' => $promote['company'] ? $promote['company']['company_name'] : '', 'company_name' => $company['company_name'],
'account' => $promote['account'], 'company_belong_text' => $companyTypes[$company['company_belong']],
'company_belong_text' => $companyTypes[$promote['company_belong']],
]; ];
if ($promote['presidentDeposit']) { if ($promote['presidentDeposit']) {
$presidentDeposit = $promote['presidentDeposit']; $presidentDeposit = $promote['presidentDeposit'];
$promoteBelong = $promote['promoteBelong'];
if ($presidentDeposit['pay_type'] == PresidentDepositService::PAY_TYPE_NONE) { if ($presidentDeposit['pay_type'] == PresidentDepositService::PAY_TYPE_NONE) {
$record['payer'] = '--'; $record['payer'] = '--';
$record['pay_account'] = '--'; $record['pay_account'] = '--';
@ -218,7 +135,7 @@ class PresidentDepositController extends ThinkController
$record['pay_type_text'] = $payTypes[$presidentDeposit['pay_type']]; $record['pay_type_text'] = $payTypes[$presidentDeposit['pay_type']];
$record['pay_way_text'] = $payWays[$presidentDeposit['pay_way']] ?? '--'; $record['pay_way_text'] = $payWays[$presidentDeposit['pay_way']] ?? '--';
$record['create_time'] = $presidentDeposit['create_time'] == 0 ? '--' : date('Y-m-d H:i:s', $presidentDeposit['create_time']); $record['create_time'] = $presidentDeposit['create_time'] == 0 ? '--' : date('Y-m-d H:i:s', $presidentDeposit['create_time']);
$record['verify_time'] = $promoteBelong && $promoteBelong['verify_time'] != 0 ? date('Y-m-d H:i:s', $promoteBelong['verify_time']) : '--'; $record['verify_time'] = $company['create_time'] != 0 ? date('Y-m-d H:i:s', $company['create_time']) : '--';
$record['pay_confirm_time'] = $presidentDeposit['pay_confirm_time'] == 0 ? '--' : date('Y-m-d', $presidentDeposit['pay_confirm_time']); $record['pay_confirm_time'] = $presidentDeposit['pay_confirm_time'] == 0 ? '--' : date('Y-m-d', $presidentDeposit['pay_confirm_time']);
$record['refund_time'] = $presidentDeposit['refund_time'] == 0 ? '--' : date('Y-m-d', $presidentDeposit['refund_time']); $record['refund_time'] = $presidentDeposit['refund_time'] == 0 ? '--' : date('Y-m-d', $presidentDeposit['refund_time']);
$record['pay_accept_time'] = $presidentDeposit['pay_accept_time'] == 0 ? '--' : date('Y-m-d', $presidentDeposit['pay_accept_time']); $record['pay_accept_time'] = $presidentDeposit['pay_accept_time'] == 0 ? '--' : date('Y-m-d', $presidentDeposit['pay_accept_time']);
@ -271,10 +188,13 @@ class PresidentDepositController extends ThinkController
$this->checkListOrCountAuthRestMap($map,[]); $this->checkListOrCountAuthRestMap($map,[]);
$total['unconfirmedamount'] = $total['totalamount'] - $total['confirmedamount'] - $total['refundedamount']; $total['unconfirmedamount'] = $total['totalamount'] - $total['confirmedamount'] - $total['refundedamount'];
$page = set_pagination($count, $row == 'all' ? 99999999 : $row); $page = set_pagination($count, $row == 'all' ? 99999999 : $row);
//dd($row == 'all' ? 99999999 : $row);
$allCompanies = M('promote_company', 'tab_')->field(['id', 'company_name'])->where(['company_belong' => ['in', [1, 2]]])->select();
if($page) { if($page) {
$this->assign('_page', $page); $this->assign('_page', $page);
} }
$this->assign('allCompanies', $allCompanies);
$this->assign('total', $total); $this->assign('total', $total);
$this->assign('payWays', $payWays); $this->assign('payWays', $payWays);
$this->assign('payTypes', $payTypes); $this->assign('payTypes', $payTypes);

@ -67,10 +67,10 @@
</div> </div>
<div class="input-list input-list-promote search_label_rehab"> <div class="input-list input-list-promote search_label_rehab">
<select id="promote_id" name="promote_id" class="select_gallery" style="width:120px;"> <select id="promote_id" name="promote_id" class="select_gallery" style="width:120px;">
<option value="">会长账号</option> <option value="0">推广公司</option>
<volist name=":get_promote_list_by_id()" id="vo"> <?php foreach($allCompanies as $company):?>
<option value="{$vo.id}">{$vo.account}</option> <option value="<?=$company['id']?>"><?=$company['id']?></option>
</volist> <?php endforeach;?>
</select> </select>
</div> </div>
<div class="input-list input-list-promote search_label_rehab"> <div class="input-list input-list-promote search_label_rehab">
@ -92,7 +92,7 @@
</div> </div>
<div class="input-list input-list-promote search_label_rehab"> <div class="input-list input-list-promote search_label_rehab">
<select id="company_type" name="company_type" class="select_gallery" style="width:120px;"> <select id="company_type" name="company_type" class="select_gallery" style="width:120px;">
<option value="">会类型</option> <option value="">会类型</option>
<?php foreach($companyTypes as $key => $name):?> <?php foreach($companyTypes as $key => $name):?>
<option value="<?=$key?>"><?=$name?></option> <option value="<?=$key?>"><?=$name?></option>
<?php endforeach;?> <?php endforeach;?>
@ -155,9 +155,8 @@
<th> <th>
<input class="check-all" type="checkbox"> <input class="check-all" type="checkbox">
</th> </th>
<th>所属推广公司</th> <th>推广公司</th>
<th>会长账号</th> <th>公会类型</th>
<th>工会类型</th>
<th>退押金账户名</th> <th>退押金账户名</th>
<th>付款方式</th> <th>付款方式</th>
<th>退押金账号</th> <th>退押金账号</th>
@ -188,7 +187,6 @@
<?php endif;?> <?php endif;?>
</td> </td>
<td>{$data.company_name}</td> <td>{$data.company_name}</td>
<td>{$data.account}</td>
<td>{$data.company_belong_text}</td> <td>{$data.company_belong_text}</td>
<td>{$data.payer}</td> <td>{$data.payer}</td>
<td>{$data.pay_way_text}</td> <td>{$data.pay_way_text}</td>

@ -413,7 +413,7 @@
</td> </td>
</tr> </tr>
<tr> <tr>
<td class="l">是否有打款流程:</td> <td class="l">是否支付宝打款:</td>
<td class="r table_radio"> <td class="r table_radio">
<span class="form_radio table_btn"> <span class="form_radio table_btn">
<label> <label>

@ -417,7 +417,7 @@
</td> </td>
</tr> </tr>
<tr> <tr>
<td class="l">是否有打款流程:</td> <td class="l">是否支付宝打款:</td>
<td class="r table_radio"> <td class="r table_radio">
<span class="form_radio table_btn"> <span class="form_radio table_btn">
<label> <label>

@ -428,7 +428,7 @@
</td> </td>
</tr> </tr>
<tr> <tr>
<td class="l">是否有打款流程:</td> <td class="l">是否支付宝打款:</td>
<td class="r table_radio"> <td class="r table_radio">
<span class="form_radio table_btn"> <span class="form_radio table_btn">
<label> <label>

Loading…
Cancel
Save