You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

447 lines
18 KiB
PHTML

5 years ago
<?php
namespace Admin\Controller;
use User\Api\UserApi as UserApi;
use Base\Service\PresidentDepositService;
/**
* 会长押金管理
*/
class PresidentDepositController extends ThinkController
{
5 years ago
public function records()
{
5 years ago
$page = I('p', 1);
$row = I('row', 10);
5 years ago
$companyType = I('company_type');
$payType = I('pay_type');
$status = I('status');
$promoteId = I('promote_id');
$query = M('promote', 'tab_')->where(['level' => 1])->where(['company_belong' => ['in', [1, 2]]]);
$idStrWhere = [];
if ($promoteId !== '') {
$idStrWhere[] = 'id = ' . $promoteId;
}
if ($companyType !== '') {
$query->where(['company_belong' => $companyType]);
}
$promoteIds = [];
if ($status !== '') {
$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 ($payType !== '') {
$tempPromoteIds = M('president_deposit', 'tab_')->where(['pay_type' => $payType])->getField('promote_id', true);
if (count($tempPromoteIds) > 0) {
$idStrWhere[] = 'id in (' . implode(',', $tempPromoteIds) . ')';
} else {
$idStrWhere[] = '1<>1';
}
}
if (count($idStrWhere) > 0) {
$query->where(['_string' => implode(' and ', $idStrWhere)]);
}
5 years ago
$promotes = [];
$count = 0;
if (I('export', 0) == 1) {
$promotes = $query->select();
} else {
$countQuery = clone $query;
$promotes = $query->page($page, $row)->select();
$count = $countQuery->count();
}
5 years ago
$relationQuery = M('promote_company', 'tab_')->field(['id', 'company_name']);
$promotes = $this->mergeOneReletions('company', $promotes, $relationQuery, 'company_id', 'id');
$relationQuery = M('president_deposit', 'tab_');
$promotes = $this->mergeOneReletions('presidentDeposit', $promotes, $relationQuery, 'id', 'promote_id');
$relationQuery = M('promote_belong', 'tab_')->field(['verify_time', 'promote_id']);
$promotes = $this->mergeOneReletions('promoteBelong', $promotes, $relationQuery, 'id', 'promote_id');
5 years ago
/*echo '<pre>';
var_dump($promotes);
echo '</pre>';
die();*/
5 years ago
$companyTypes = [
1 => '外团',
2 => '外团-分发联盟',
];
5 years ago
$payWays = PresidentDepositService::$payWays;
$payTypes = PresidentDepositService::$payTypes;
$statusList = PresidentDepositService::$statusList;
$records = [];
if (count($promotes) > 0) {
foreach ($promotes as $promote) {
$record = [
'id' => $promote['id'],
'company_name' => $promote['company'] ? $promote['company']['company_name'] : '',
'account' => $promote['account'],
'company_belong_text' => $companyTypes[$promote['company_belong']],
];
if ($promote['presidentDeposit']) {
$presidentDeposit = $promote['presidentDeposit'];
$promoteBelong = $promote['promoteBelong'];
if ($presidentDeposit['pay_type'] == 3) {
$record['payer'] = '--';
$record['pay_account'] = '--';
$record['amount'] = '--';
} else {
$record['payer'] = $presidentDeposit['payer'];
$record['pay_account'] = $presidentDeposit['pay_account'];
$record['amount'] = $presidentDeposit['amount'];
}
$record['pay_type_text'] = $payTypes[$presidentDeposit['pay_type']];
$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['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['status_text'] = $statusList[$presidentDeposit['status']];
$record['has_record'] = true;
$record['status'] = $presidentDeposit['status'];
$record['pay_type'] = $presidentDeposit['pay_type'];
} else {
$record['payer'] = '--';
$record['pay_account'] = '--';
$record['amount'] = '--';
$record['pay_type_text'] = '--';
$record['pay_way_text'] = '--';
$record['create_time'] = '--';
$record['verify_time'] = '--';
$record['pay_confirm_time'] = '--';
$record['status_text'] = '--';
$record['has_record'] = false;
$record['status'] = 0;
$record['pay_type'] = 0;
}
$records[] = $record;
}
if (I('export', 0) == 1) {
$field = [
'company_name' => '所属推广公司',
'account' => '会长账号',
'company_belong_text' => '工会类型',
'payer' => '付款人',
'pay_way_text' => '付款方式',
'pay_account' => '账号',
'pay_type_text' => '押金类型',
'create_time' => '审批时间',
'amount' => '押金金额',
'verify_time' => '会长申请时间',
'status_text' => '押金状态',
'pay_confirm_time' => '押金确认时间',
];
addOperationLog(['op_type'=>3,'key'=>getNowDate(),'op_name'=>'导出会长押金记录','url'=>U('PresidentDeposit/records'),'menu'=>'推广员-结算管理-奖罚记录管理-导出会长押金记录']);
5 years ago
data2csv($records, '会长押金记录', $field);
exit;
}
}
$this->checkListOrCountAuthRestMap($map,[]);
5 years ago
$page = set_pagination($count, $row);
if($page) {
$this->assign('_page', $page);
}
$this->assign('payWays', $payWays);
$this->assign('payTypes', $payTypes);
5 years ago
$this->assign('companyTypes', $companyTypes);
5 years ago
$this->assign('statusList', $statusList);
$this->assign('records', $records);
5 years ago
$this->display();
}
private function mergeOneReletions($name, $records, $relationQuery, $selfColumn, $relationColumn = 'id')
{
$values = array_column($records, $selfColumn);
5 years ago
if (count($values) == 0) {
return [];
}
5 years ago
$rows = $relationQuery->where([$relationColumn => ['in', $values]])->select();
foreach ($records as &$record) {
$record[$name] = null;
}
foreach ($records as &$record) {
foreach ($rows as $row) {
if ($record[$selfColumn] == $row[$relationColumn]) {
$record[$name] = $row;
}
}
}
return $records;
}
public function edit()
{
$this->meta_title = '编辑会长押金';
5 years ago
$id = I('id', 0);
$promote = M('promote', 'tab_')->field(['account', 'id'])->where(['id' => $id])->find();
5 years ago
$record = M('president_deposit', 'tab_')->where(['promote_id' => $id])->find();
5 years ago
$this->assign('payWays', PresidentDepositService::$payWays);
$this->assign('payTypes', PresidentDepositService::$payTypes);
$this->assign('promote', $promote);
5 years ago
$this->assign('record', $record);
5 years ago
$this->display('form');
}
public function show()
{
$this->meta_title = '查看会长押金';
$id = I('id', 0);
$promote = M('promote', 'tab_')->field(['account', 'id'])->where(['id' => $id])->find();
$record = M('president_deposit', 'tab_')->where(['promote_id' => $id])->find();
$this->assign('payWays', PresidentDepositService::$payWays);
$this->assign('payTypes', PresidentDepositService::$payTypes);
$this->assign('promote', $promote);
$this->assign('record', $record);
$this->display('show');
}
5 years ago
public function save()
{
$payWay = I('pay_way', 0);
$payType = I('pay_type', 0);
$promoteId = I('id', 0);
5 years ago
$payAccount = I('pay_account', '');
5 years ago
$amount = I('amount', '');
5 years ago
$payer = I('payer', '');
5 years ago
$record = M('president_deposit', 'tab_')->where(['promote_id' => $promoteId])->find();
$promoteData = M('promote', 'tab_')->field('account')->where(['id' => $promoteId])->find();
5 years ago
if ($payType == 0) {
return $this->error('请选择押金付款方式');
}
if ($payType == 3) {
$this->handleNoDeposit($promoteId);
return $this->success('保存成功', U('records'));
}
if ($payType != 2 && $payWay == 0) {
return $this->error('请选择付款方式');
}
5 years ago
5 years ago
if (!$record) {
5 years ago
if ($amount !== '') {
if (!is_numeric($amount)) {
return $this->error('请输入正确金额');
}
if ($amount <= 0) {
return $this->error('金额必须大于0');
}
if ($amount > 100000000) {
return $this->error('金额过高');
}
}
5 years ago
5 years ago
$data = [];
$data['pay_way'] = $payType == 2 ? 4 : $payWay;
5 years ago
$data['pay_type'] = $payType;
$data['promote_id'] = $promoteId;
$data['pay_account'] = $payAccount;
5 years ago
$data['amount'] = floatval($amount);
5 years ago
$data['payer'] = $payer;
5 years ago
$data['create_time'] = time();
$data['update_time'] = time();
5 years ago
M('president_deposit', 'tab_')->add($data);
addOperationLog(['op_type'=>0,'key'=>$promoteData['account'].'/'.$amount,'op_name'=>'新增会长押金','url'=>U('PresidentDeposit/edit',['id'=>$promoteId]),'menu'=>'推广员-结算单管理-奖罚记录管理-新增会长押金']);
5 years ago
return $this->success('保存成功', U('records'));
5 years ago
}
/* if ($record['status'] != 0) {
5 years ago
return $this->error('该状态下不可编辑/修改');
} */
5 years ago
5 years ago
if ($amount === '') {
5 years ago
return $this->error('请输入金额');
}
5 years ago
if (!is_numeric($amount)) {
return $this->error('请输入正确金额');
}
if ($amount <= 0) {
return $this->error('金额必须大于0');
}
if ($amount > 100000000) {
return $this->error('金额过高');
}
/* if ($payer == '') {
5 years ago
return $this->error('请输入付款人');
}
if ($payAccount == '') {
return $this->error('请输入付款账号');
} */
5 years ago
$data = [];
5 years ago
$data['pay_way'] = $payType == 2 ? 4 : $payWay;
$data['pay_type'] = $payType;
5 years ago
$data['pay_account'] = $payAccount;
5 years ago
$data['amount'] = floatval($amount);
5 years ago
$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'=>'推广员-结算单管理-会长押金管理-编辑会长押金']);
5 years ago
return $this->success('保存成功', U('records'));
5 years ago
}
public function delete()
{
$promoteId = I('id', 0);
M('president_deposit', 'tab_')->where(['promote_id' => $promoteId])->delete();
addOperationLog(['op_type'=>2,'key'=>$promoteId,'op_name'=>'删除会长押金记录','url'=>U('PresidentDeposit/records',['id'=>$promoteId]),'menu'=>'推广员-结算单管理-奖罚记录管理-删除会长押金记录']);
5 years ago
$this->ajaxReturn([
'status' => 1,
'message' => '删除成功'
]);
}
5 years ago
public function handleNoDeposit($promoteId)
5 years ago
{
$record = M('president_deposit', 'tab_')->where(['promote_id' => $promoteId])->find();
5 years ago
$data = [];
$data['pay_way'] = 0;
$data['pay_type'] = PresidentDepositService::PAY_TYPE_NONE;
$data['pay_account'] = '';
$data['amount'] = 0;
$data['payer'] = '';
$data['create_time'] = time();
$data['update_time'] = time();
5 years ago
if (!$record) {
$data['promote_id'] = $promoteId;
M('president_deposit', 'tab_')->add($data);
5 years ago
} else {
M('president_deposit', 'tab_')->where(['promote_id' => $promoteId])->save($data);
5 years ago
}
5 years ago
$promoteData = M('promote', 'tab_')->field('account')->where(['id' => $promoteId])->find();
addOperationLog(['op_type'=>1,'key'=>$promoteData['account'],'op_name'=>'编辑无需押金','url'=>U('PresidentDeposit/records'),'menu'=>'推广员-结算单管理-会长押金管理-无需押金']);
}
public function noDeposit()
{
$promoteId = I('id', 0);
$this->handleNoDeposit($promoteId);
5 years ago
$this->ajaxReturn([
'status' => 1,
'message' => '操作成功'
]);
}
public function refund()
{
$promoteIds = I('ids', []);
if (count($promoteIds) == 0) {
$this->ajaxReturn([
'status' => 0,
'message' => '无选中项'
]);
}
5 years ago
$checkStatus = true;
$records = M('president_deposit', 'tab_')->field(['id', 'status'])->where(['promote_id' => ['in', $promoteIds]])->select();
foreach ($records as $record) {
if ($record['status'] != 1) {
$checkStatus = false;
break;
}
}
if (!$checkStatus) {
$this->ajaxReturn([
'status' => 0,
'message' => '含有非已到账状态记录,不可批量操作'
]);
}
$promoteData = M('promote','tab_')
->field('account,amount')
->join('left join tab_president_deposit on tab_president_deposit.promote_id=tab_promote.id')
->where(['tab_promote.id'=>['in', $promoteIds]])
->select();
// dump($promoteData);die();
foreach ($promoteData as $key => $value) {
if ($value['amount']) {
addOperationLog(['op_type'=>1,'key'=>$value['account'].'/'.$value['amount'],'op_name'=>'编辑押金已退款','url'=>U('PresidentDeposit/records'),'menu'=>'推广员-结算单管理-会长押金管理-押金已退款']);
}
}
5 years ago
M('president_deposit', 'tab_')->where(['promote_id' => ['in', $promoteIds]])->save([
'status' => 2,
'refund_time' => time(),
'update_time' => time()
5 years ago
]);
$this->ajaxReturn([
'status' => 1,
'message' => '操作成功'
]);
}
public function payConfirm()
{
$promoteIds = I('ids', []);
if (count($promoteIds) == 0) {
$this->ajaxReturn([
'status' => 0,
'message' => '无选中项'
]);
}
5 years ago
$checkStatus = true;
$records = M('president_deposit', 'tab_')->field(['id', 'status'])->where(['promote_id' => ['in', $promoteIds]])->select();
foreach ($records as $record) {
if ($record['status'] != 0) {
$checkStatus = false;
break;
}
}
if (!$checkStatus) {
$this->ajaxReturn([
'status' => 0,
'message' => '含有非待确认状态记录,不可批量操作'
]);
}
$promoteData = M('promote','tab_')
->field('account,amount')
->join('left join tab_president_deposit on tab_president_deposit.promote_id=tab_promote.id')
->where(['tab_promote.id'=>['in', $promoteIds]])
->select();
// dump($promoteData);die();
foreach ($promoteData as $key => $value) {
if ($value['amount']) {
addOperationLog(['op_type'=>1,'key'=>$value['account'].'/'.$value['amount'],'op_name'=>'编辑确认押金到账','url'=>U('PresidentDeposit/records'),'menu'=>'推广员-结算单管理-会长押金管理-确认押金到账']);
}
}
5 years ago
M('president_deposit', 'tab_')->where(['promote_id' => ['in', $promoteIds]])->save([
'status' => 1,
'pay_confirm_time' => time(),
'update_time' => time()
5 years ago
]);
$this->ajaxReturn([
'status' => 1,
'message' => '操作成功'
]);
}
}