@ -31,13 +31,109 @@ class PresidentDepositController extends ThinkController
$promoteIds = [];
if ($status !== '') {
$tempPromoteIds = M('president_deposit', 'tab_')->where(['status' => $status])->getField('promote_id', true);
if ($status == '-1') { // 市场待审核
$tempPromoteIds = M('president_deposit', 'tab_')->getField('promote_id', true);
if (count($tempPromoteIds) > 0) {
$idStrWhere[] = 'id not in (' . implode(',', $tempPromoteIds) . ')';
}
} else {
$tempPromoteIds = M('president_deposit', 'tab_')->where(['status' => $status])->getField('promote_id', true);
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'))) {
$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}")->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 (!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}")->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'))) {
$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}")->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 < = {$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 ($payType !== '') {
$tempPromoteIds = M('president_deposit', 'tab_')->where(['pay_type' => $payType])->getField('promote_id', true);
if (count($tempPromoteIds) > 0) {
@ -46,20 +142,40 @@ class PresidentDepositController extends ThinkController
$idStrWhere[] = '1< >1';
}
}
if (!empty(I('admin_id', 0))) {
$query->where(['admin_id' => I('admin_id', 0)]);
}
if (count($idStrWhere) > 0) {
$query->where(['_string' => implode(' and ', $idStrWhere)]);
$query->where(['_string' => implode(' and ', array_unique( $idStrWhere) )]);
}
$promotes = [];
$count = 0;
if (I('export', 0) == 1) {
$totalQuery = clone $query;
if (I('export', 0) == 1 || $row == 'all') {
$promotes = $query->select();
$count = count($promotes);
} else {
$countQuery = clone $query;
$promotes = $query->page($page, $row)->select();
$count = $countQuery->count();
}
// 汇总金额
if (count($promotes) > 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 = [
'totalamount' => $total['totalamount'] ?? 0, 'confirmedamount' => $total['confirmedamount'] ?? 0, 'refundedamount' => $total['refundedamount'] ?? 0
];
} else {
$total = [
'totalamount' => 0, 'confirmedamount' => 0, 'refundedamount' => 0
];
}
$relationQuery = M('promote_company', 'tab_')->field(['id', 'company_name']);
$promotes = $this->mergeOneReletions('company', $promotes, $relationQuery, 'company_id', 'id');
$relationQuery = M('president_deposit', 'tab_');
@ -90,10 +206,10 @@ class PresidentDepositController extends ThinkController
if ($promote['presidentDeposit']) {
$presidentDeposit = $promote['presidentDeposit'];
$promoteBelong = $promote['promoteBelong'];
if ($presidentDeposit['pay_type'] == 3 ) {
if ($presidentDeposit['pay_type'] == PresidentDepositService::PAY_TYPE_NONE ) {
$record['payer'] = '--';
$record['pay_account'] = '--';
$record['amount'] = '-- ';
$record['amount'] = '无 ';
} else {
$record['payer'] = $presidentDeposit['payer'];
$record['pay_account'] = $presidentDeposit['pay_account'];
@ -104,6 +220,8 @@ class PresidentDepositController extends ThinkController
$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['pay_confirm_time'] = $presidentDeposit['pay_confirm_time'] == 0 ? '--' : date('Y-m-d H:i:s', $presidentDeposit['pay_confirm_time']);
$record['refund_time'] = $presidentDeposit['refund_time'] == 0 ? '--' : date('Y-m-d H:i:s', $presidentDeposit['refund_time']);
$record['pay_accept_time'] = $presidentDeposit['pay_accept_time'] == 0 ? '--' : date('Y-m-d H:i:s', $presidentDeposit['pay_accept_time']);
$record['status_text'] = $statusList[$presidentDeposit['status']];
$record['has_record'] = true;
$record['status'] = $presidentDeposit['status'];
@ -117,7 +235,9 @@ class PresidentDepositController extends ThinkController
$record['create_time'] = '--';
$record['verify_time'] = '--';
$record['pay_confirm_time'] = '--';
$record['status_text'] = '--';
$record['refund_time'] = '--';
$record['pay_accept_time'] = '--';
$record['status_text'] = '市场待确认';
$record['has_record'] = false;
$record['status'] = 0;
$record['pay_type'] = 0;
@ -129,15 +249,17 @@ class PresidentDepositController extends ThinkController
'company_name' => '所属推广公司',
'account' => '会长账号',
'company_belong_text' => '工会类型',
'payer' => '付款人 ',
'payer' => '退押金账户名 ',
'pay_way_text' => '付款方式',
'pay_account' => '账号',
'pay_account' => '退押金 账号',
'pay_type_text' => '押金类型',
'create_time' => '审批时间',
'amount' => '押金金额',
'verify_time' => '会长申请时间',
'status_text' => '押金状态',
'pay_confirm_time' => '押金确认时间',
'refund_time' => '押金退款时间',
'pay_accept_time' => '押金收到时间',
];
addOperationLog(['op_type'=>3,'key'=>getNowDate(),'op_name'=>'导出会长押金记录','url'=>U('PresidentDeposit/records'),'menu'=>'推广员-结算管理-奖罚记录管理-导出会长押金记录']);
@ -146,13 +268,14 @@ class PresidentDepositController extends ThinkController
exit;
}
}
$this->checkListOrCountAuthRestMap($map,[]);
$page = set_pagination($count, $row);
$total['unconfirmedamount'] = $total['totalamount'] - $total['confirmedamount'] - $total['refundedamount'];
$page = set_pagination($count, $row == 'all' ? 99999999 : $row);
//dd($row == 'all' ? 99999999 : $row);
if($page) {
$this->assign('_page', $page);
}
$this->assign('total', $total);
$this->assign('payWays', $payWays);
$this->assign('payTypes', $payTypes);
$this->assign('companyTypes', $companyTypes);
@ -215,11 +338,20 @@ class PresidentDepositController extends ThinkController
$payAccount = I('pay_account', '');
$amount = I('amount', '');
$payer = I('payer', '');
$payAcceptTime = I('pay_accept_time', 0) ? strtotime(I('pay_accept_time')): 0;
$refundTime = I('refund_time', 0) ? strtotime(I('refund_time')): 0;
$record = M('president_deposit', 'tab_')->where(['promote_id' => $promoteId])->find();
$promoteData = M('promote', 'tab_')->field('account')->where(['id' => $promoteId])->find();
// 市场部门无法操作押金退款和收到时间
if ((($record['pay_accept_time'] != $payAcceptTime) || ($record['refund_time'] != $refundTime)) & & isMarketAdmin()) {
return $this->error('无法操作记录');
}
if ($payType == 0) {
return $this->error('请选择押金付款方式');
}
@ -245,6 +377,13 @@ class PresidentDepositController extends ThinkController
}
$data = [];
// 填写押金到账时间后自动变为押金已确认到账状态,并且状态在待确认时候
if ($record['pay_accept_time'] != $payAcceptTime & & $record['status'] == 0) {
$data = ['status' => 1,
'pay_confirm_time' => time()];
}
$data['pay_way'] = $payType == 2 ? 4 : $payWay;
$data['pay_type'] = $payType;
$data['promote_id'] = $promoteId;
@ -253,6 +392,9 @@ class PresidentDepositController extends ThinkController
$data['payer'] = $payer;
$data['create_time'] = time();
$data['update_time'] = time();
$data['pay_accept_time'] = $payAcceptTime;
$data['refund_time'] = $refundTime;
M('president_deposit', 'tab_')->add($data);
addOperationLog(['op_type'=>0,'key'=>$promoteData['account'].'/'.$amount,'op_name'=>'新增会长押金','url'=>U('PresidentDeposit/edit',['id'=>$promoteId]),'menu'=>'推广员-结算单管理-奖罚记录管理-新增会长押金']);
@ -283,12 +425,24 @@ class PresidentDepositController extends ThinkController
} */
$data = [];
// 切换类型
if ($payType != $record['pay_type']) {
$payStatus = 0;
$data['refund_time'] = $data['pay_accept_time'] = $data['pay_confirm_time'] = 0;
} else {
$data['pay_accept_time'] = $payAcceptTime;
$data['refund_time'] = $refundTime;
}
$data['pay_way'] = $payType == 2 ? 4 : $payWay;
$data['pay_type'] = $payType;
$data['pay_account'] = $payAccount;
$data['amount'] = floatval($amount);
$data['status'] = $payStatus ?? $record['status'];
$data['payer'] = $payer;
$data['update_time'] = time();
M('president_deposit', 'tab_')->where(['promote_id' => $promoteId])->save($data);
addOperationLog(['op_type'=>1,'key'=>$promoteData['account'].'/'.$amount,'op_name'=>'编辑会长押金','url'=>U('PresidentDeposit/edit',['id'=>$promoteId]),'menu'=>'推广员-结算单管理-会长押金管理-编辑会长押金']);
@ -298,6 +452,12 @@ class PresidentDepositController extends ThinkController
public function delete()
{
if (isMarketAdmin()) {
$this->ajaxReturn([
'status' => 0,
'message' => '无法操作记录'
]);
}
$promoteId = I('id', 0);
M('president_deposit', 'tab_')->where(['promote_id' => $promoteId])->delete();
@ -309,6 +469,9 @@ class PresidentDepositController extends ThinkController
]);
}
/**
* 处理无需押金
*/
public function handleNoDeposit($promoteId)
{
$record = M('president_deposit', 'tab_')->where(['promote_id' => $promoteId])->find();
@ -319,11 +482,15 @@ class PresidentDepositController extends ThinkController
$data['pay_account'] = '';
$data['amount'] = 0;
$data['payer'] = '';
$data['status'] = 1;
$data['pay_confirm_time'] = time();
$data['create_time'] = time();
$data['update_time'] = time();
$data['status'] = 1;
$data['pay_accept_time'] = $data['refund_time'] = 0;
$data['promote_id'] = $promoteId;
if (!$record) {
$data['promote_id'] = $promoteId;
M('president_deposit', 'tab_')->add($data);
} else {
M('president_deposit', 'tab_')->where(['promote_id' => $promoteId])->save($data);
@ -345,6 +512,9 @@ class PresidentDepositController extends ThinkController
public function refund()
{
if (isMarketAdmin()) {
return $this->error('无法操作记录');
}
$promoteIds = I('ids', []);
if (count($promoteIds) == 0) {
$this->ajaxReturn([
@ -386,7 +556,8 @@ class PresidentDepositController extends ThinkController
M('president_deposit', 'tab_')->where(['promote_id' => ['in', $promoteIds]])->save([
'status' => 2,
'refund_time' => time(),
'update_time' => time()
'update_time' => time(),
'pay_accept_time' => 0
]);
$this->ajaxReturn([
'status' => 1,
@ -396,6 +567,12 @@ class PresidentDepositController extends ThinkController
public function payConfirm()
{
if (isMarketAdmin()) {
$this->ajaxReturn([
'status' => 0,
'message' => '无权限操作记录'
]);
}
$promoteIds = I('ids', []);
if (count($promoteIds) == 0) {
$this->ajaxReturn([
@ -404,12 +581,19 @@ class PresidentDepositController extends ThinkController
]);
}
$checkStatus = true;
$records = M('president_deposit', 'tab_')->field(['id', 'status'])-> where(['promote_id' => ['in', $promoteIds]])->select();
$records = M('president_deposit', 'tab_')->where(['promote_id' => ['in', $promoteIds]])->select();
foreach ($records as $record) {
if ($record['status'] != 0) {
$checkStatus = false;
break;
}
// 如果不是无需押金,并且没有填写收到押金时间
// if ($record['pay_type'] != PresidentDepositService::PAY_TYPE_NONE & & empty($record['pay_accept_time'])) {
// $this->ajaxReturn([
// 'status' => 0,
// 'message' => '含有待确认收到押金时间记录,不可批量操作'
// ]);
// }
}
if (!$checkStatus) {
$this->ajaxReturn([
@ -436,7 +620,8 @@ class PresidentDepositController extends ThinkController
M('president_deposit', 'tab_')->where(['promote_id' => ['in', $promoteIds]])->save([
'status' => 1,
'pay_confirm_time' => time(),
'update_time' => time()
'update_time' => time(),
'pay_accept_time' => strtotime(I('accept_time'))
]);
$this->ajaxReturn([
'status' => 1,