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.

267 lines
9.1 KiB
PHP

<?php
namespace Admin\Controller;
use User\Api\UserApi as UserApi;
use Base\Service\PresidentDepositService;
/**
* 会长押金管理
*/
class PresidentDepositController extends ThinkController
{
public function records()
{
$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)]);
}
$promotes = $query->select();
$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');
/*echo '<pre>';
var_dump($promotes);
echo '</pre>';
die();*/
$companyTypes = [
1 => '外团',
2 => '外团-分发联盟',
];
$this->assign('payWays', PresidentDepositService::$payWays);
$this->assign('payTypes', PresidentDepositService::$payTypes);
$this->assign('companyTypes', $companyTypes);
$this->assign('statusList', PresidentDepositService::$statusList);
$this->assign('promotes', $promotes);
$this->display();
}
private function mergeOneReletions($name, $records, $relationQuery, $selfColumn, $relationColumn = 'id')
{
$values = array_column($records, $selfColumn);
if (count($values) == 0) {
return [];
}
$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 = '编辑/查看会长押金';
$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('form');
}
public function save()
{
$payWay = I('pay_way', 0);
$payType = I('pay_type', 0);
$promoteId = I('id', 0);
$payAccount = I('pay_account', '');
$amount = floatval(I('amount', 0));
$payer = I('payer', '');
$record = M('president_deposit', 'tab_')->where(['promote_id' => $promoteId])->find();
if (!$record) {
if ($payType == 0) {
return $this->error('请选择押金付款方式');
}
if ($payWay == 0) {
return $this->error('请选择付款方式');
}
$data = [];
$data['pay_way'] = $payWay;
$data['pay_type'] = $payType;
$data['promote_id'] = $promoteId;
$data['pay_account'] = $payAccount;
$data['amount'] = $amount;
$data['payer'] = $payer;
$data['create_time'] = time();
$data['update_time'] = time();
M('president_deposit', 'tab_')->add($data);
return $this->success('保存成功', U('PresidentDeposit/records'));
}
if ($record['status'] != 0) {
return $this->error('该状态下不可编辑/修改');
}
if ($amount == 0) {
return $this->error('请输入金额');
}
if ($payer == '') {
return $this->error('请输入付款人');
}
if ($payAccount == '') {
return $this->error('请输入付款账号');
}
$data = [];
$data['pay_account'] = $payAccount;
$data['amount'] = $amount;
$data['payer'] = $payer;
$data['update_time'] = time();
M('president_deposit', 'tab_')->where(['promote_id' => $promoteId])->save($data);
return $this->success('保存成功');
}
public function delete()
{
$promoteId = I('id', 0);
M('president_deposit', 'tab_')->where(['promote_id' => $promoteId])->delete();
$this->ajaxReturn([
'status' => 1,
'message' => '删除成功'
]);
}
public function noDeposit()
{
$promoteId = I('id', 0);
$record = M('president_deposit', 'tab_')->where(['promote_id' => $promoteId])->find();
if (!$record) {
$data = [];
$data['pay_way'] = 0;
$data['pay_type'] = PresidentDepositService::PAY_TYPE_NONE;
$data['promote_id'] = $promoteId;
$data['pay_account'] = '';
$data['amount'] = 0;
$data['payer'] = '';
$data['create_time'] = time();
$data['update_time'] = time();
M('president_deposit', 'tab_')->add($data);
}
$this->ajaxReturn([
'status' => 1,
'message' => '操作成功'
]);
}
public function refund()
{
$promoteIds = I('ids', []);
if (count($promoteIds) == 0) {
$this->ajaxReturn([
'status' => 0,
'message' => '无选中项'
]);
}
$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' => '含有非已到账状态记录,不可批量操作'
]);
}
M('president_deposit', 'tab_')->where(['promote_id' => ['in', $promoteIds]])->save([
'status' => 2,
'refund_time' => time(),
'update_time' => time()
]);
$this->ajaxReturn([
'status' => 1,
'message' => '操作成功'
]);
}
public function payConfirm()
{
$promoteIds = I('ids', []);
if (count($promoteIds) == 0) {
$this->ajaxReturn([
'status' => 0,
'message' => '无选中项'
]);
}
$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' => '含有非待确认状态记录,不可批量操作'
]);
}
M('president_deposit', 'tab_')->where(['promote_id' => ['in', $promoteIds]])->save([
'status' => 1,
'pay_confirm_time' => time(),
'update_time' => time()
]);
$this->ajaxReturn([
'status' => 1,
'message' => '操作成功'
]);
}
}