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.

362 lines
14 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');
4 years ago
$companyId = I('company_id', 0);
5 years ago
4 years ago
$where = [
'_string' => '1=1',
'company_belong' => ['in', [1, 2]]
];
4 years ago
if ($companyId != 0) {
4 years ago
$where['id'] = $companyId;
5 years ago
}
if ($companyType !== '') {
4 years ago
$where['_string'] .= ' and company_belong=' . $companyType;
5 years ago
}
4 years ago
$depositWhere = [];
$depositStrWhere = '1=1';
5 years ago
if ($status !== '') {
4 years ago
if ($status == '-1') {
$companyIds = M('president_deposit', 'tab_')->getField('company_id', true);
if (count($companyIds) > 0) {
$depositStrWhere .= ' and company_id not in (' . implode(',', $companyIds) . ')';
4 years ago
}
5 years ago
} else {
4 years ago
$depositWhere['status'] = $status;
5 years ago
}
}
if(I('amount_start', '') != '') {
$depositStrWhere .= ' and amount >= ' . I('amount_start', '');
}
if (I('amount_end', '') != '') {
$depositStrWhere .= ' and amount <= ' . I('amount_end', '');
}
4 years ago
if (I('pay_confirm_time_start', '') != '') {
$depositStrWhere .= ' and pay_confirm_time>=' . strtotime(I('pay_confirm_time_start') . ' 00:00:00');
4 years ago
}
4 years ago
if (I('pay_confirm_time_end', '') != '') {
$depositStrWhere .= ' and pay_confirm_time<=' . strtotime(I('pay_confirm_time_end') . ' 23:59:59');
4 years ago
}
4 years ago
if (I('refund_time_start', '') != '') {
$depositStrWhere .= ' and refund_time>=' . strtotime(I('refund_time_start') . ' 00:00:00');
}
if (I('refund_time_end', '') != '') {
$depositStrWhere .= ' and refund_time<=' . strtotime(I('refund_time_end') . ' 23:59:59');
4 years ago
}
4 years ago
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');
}
4 years ago
4 years ago
$depositWhere['_string'] = $depositStrWhere;
5 years ago
if ($payType !== '') {
4 years ago
$depositWhere['pay_type'] = $payType;
5 years ago
}
4 years ago
4 years ago
$subSql = M('president_deposit', 'tab_')->field('company_id')->where($depositWhere)->select(false);
$where['_string'] .= ' and id in (' . $subSql . ')';
4 years ago
$query = M('promote_company', 'tab_');
4 years ago
if (!empty(I('admin_id', 0))) {
4 years ago
$query->where(['uid' => I('admin_id', 0)]);
4 years ago
}
5 years ago
4 years ago
$query = $query->where($where);
4 years ago
5 years ago
$count = 0;
4 years ago
$totalQuery = clone $query;
4 years ago
$companies = [];
4 years ago
if (I('export', 0) == 1 || $row == 'all') {
4 years ago
$companies = $query->select();
4 years ago
$count = count($companies);
5 years ago
} else {
$countQuery = clone $query;
4 years ago
$companies = $query->page($page, $row)->select();
5 years ago
$count = $countQuery->count();
}
4 years ago
// 汇总金额
4 years ago
if (count($companies) > 0 || (isset($count) && $count > 0)) {
4 years ago
$total = M('president_deposit', 'tab_')
->field('sum(amount) as totalAmount, sum(if(status = 1, amount, 0)) as confirmedAmount, sum(if(status = 2, amount, 0)) as refundedAmount')
->where(['company_id'=>['in', $totalQuery->getField('id', true)]])
->find();
4 years ago
$total = [
'totalamount' => $total['totalamount'] ?? 0, 'confirmedamount' => $total['confirmedamount'] ?? 0, 'refundedamount' => $total['refundedamount'] ?? 0
];
4 years ago
} else {
$total = [
'totalamount' => 0, 'confirmedamount' => 0, 'refundedamount' => 0
];
}
5 years ago
$relationQuery = M('president_deposit', 'tab_');
4 years ago
$companies = $this->mergeOneReletions('presidentDeposit', $companies, $relationQuery, 'id', 'company_id');
5 years ago
$companyTypes = [
1 => '外团',
2 => '外团-分发联盟',
];
5 years ago
$payWays = PresidentDepositService::$payWays;
$payTypes = PresidentDepositService::$payTypes;
$statusList = PresidentDepositService::$statusList;
$records = [];
4 years ago
if (count($companies) > 0) {
foreach ($companies as $company) {
5 years ago
$record = [
4 years ago
'id' => $company['id'],
'company_name' => $company['company_name'],
'company_belong_text' => $companyTypes[$company['company_belong']],
5 years ago
];
4 years ago
if ($company['presidentDeposit']) {
$presidentDeposit = $company['presidentDeposit'];
4 years ago
if ($presidentDeposit['pay_type'] == PresidentDepositService::PAY_TYPE_NONE) {
5 years ago
$record['payer'] = '--';
$record['pay_account'] = '--';
4 years ago
$record['amount'] = '无';
5 years ago
} 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']);
4 years ago
$record['verify_time'] = $company['create_time'] != 0 ? date('Y-m-d H:i:s', $company['create_time']) : '--';
4 years ago
$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['pay_accept_time'] = $presidentDeposit['pay_accept_time'] == 0 ? '--' : date('Y-m-d', $presidentDeposit['pay_accept_time']);
5 years ago
$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'] = '--';
4 years ago
$record['refund_time'] = '--';
$record['pay_accept_time'] = '--';
4 years ago
$record['status_text'] = '市场待确认';
5 years ago
$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' => '工会类型',
4 years ago
'payer' => '退押金账户名',
5 years ago
'pay_way_text' => '付款方式',
4 years ago
'pay_account' => '退押金账号',
5 years ago
'pay_type_text' => '押金类型',
'create_time' => '审批时间',
'amount' => '押金金额',
'verify_time' => '会长申请时间',
'status_text' => '押金状态',
'pay_confirm_time' => '押金确认时间',
4 years ago
'refund_time' => '押金退款时间',
'pay_accept_time' => '押金收到时间',
5 years ago
];
addOperationLog(['op_type'=>3,'key'=>getNowDate(),'op_name'=>'导出会长押金记录','url'=>U('PresidentDeposit/records'),'menu'=>'推广员-结算管理-奖罚记录管理-导出会长押金记录']);
5 years ago
data2csv($records, '会长押金记录', $field);
exit;
}
}
$this->checkListOrCountAuthRestMap($map,[]);
4 years ago
$total['unconfirmedamount'] = $total['totalamount'] - $total['confirmedamount'] - $total['refundedamount'];
4 years ago
$page = set_pagination($count, $row == 'all' ? 99999999 : $row);
4 years ago
$allCompanies = M('promote_company', 'tab_')->field(['id', 'company_name'])->where(['company_belong' => ['in', [1, 2]]])->select();
5 years ago
if($page) {
$this->assign('_page', $page);
}
4 years ago
$this->assign('allCompanies', $allCompanies);
4 years ago
$this->assign('total', $total);
5 years ago
$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);
4 years ago
$company = M('promote_company', 'tab_')->field(['company_name', 'id'])->where(['id' => $id])->find();
$record = M('president_deposit', 'tab_')->where(['company_id' => $id])->find();
5 years ago
$this->assign('payWays', PresidentDepositService::$payWays);
$this->assign('payTypes', PresidentDepositService::$payTypes);
4 years ago
$this->assign('company', $company);
5 years ago
$this->assign('record', $record);
5 years ago
$this->display('form');
}
public function show()
{
$this->meta_title = '查看会长押金';
$id = I('id', 0);
4 years ago
$company = M('promote_company', 'tab_')->field(['company_name', 'id'])->where(['id' => $id])->find();
$record = M('president_deposit', 'tab_')->where(['company_id' => $id])->find();
$this->assign('payWays', PresidentDepositService::$payWays);
$this->assign('payTypes', PresidentDepositService::$payTypes);
4 years ago
$this->assign('company', $company);
$this->assign('record', $record);
$this->display('show');
}
5 years ago
public function save()
{
4 years ago
$params = I('post.');
try {
$record = M('president_deposit', 'tab_')->where(['company_id' => $id])->find();
$service = new PresidentDepositService();
$service->save($params);
$this->success('保存成功');
} catch (\Exception $e) {
$this->error($e->getMessage());
4 years ago
}
5 years ago
}
public function delete()
{
4 years ago
if (isMarketAdmin()) {
$this->ajaxReturn([
'status' => 0,
'message' => '无法操作记录'
]);
}
5 years ago
$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 noDeposit()
{
4 years ago
$id = I('id', 0);
$company = M('promote_company', 'tab_')->where(['id' => $id])->find();
if (is_null($company)) {
5 years ago
$this->ajaxReturn([
'status' => 0,
4 years ago
'message' => '推广公司不存在'
5 years ago
]);
}
4 years ago
try {
$record = M('president_deposit', 'tab_')->where(['company_id' => $id])->find();
$service = new PresidentDepositService();
$service->handleNoDeposit($company, $record);
$this->ajaxReturn([
'status' => 1,
'message' => '操作成功'
]);
} catch (\Exception $e) {
5 years ago
$this->ajaxReturn([
'status' => 0,
4 years ago
'message' => $e->getMessage()
5 years ago
]);
}
5 years ago
}
4 years ago
public function refund()
5 years ago
{
4 years ago
$ids = I('ids', []);
try {
$service = new PresidentDepositService();
$service->batchRefund($ids);
4 years ago
$this->ajaxReturn([
4 years ago
'status' => 1,
'message' => '操作成功'
4 years ago
]);
4 years ago
} catch (\Exception $e) {
5 years ago
$this->ajaxReturn([
'status' => 0,
4 years ago
'message' => $e->getMessage()
5 years ago
]);
}
4 years ago
}
public function payConfirm()
{
$ids = I('ids', []);
4 years ago
$acceptTime = I('accept_time', date('Y-m-d'));
4 years ago
try {
$service = new PresidentDepositService();
4 years ago
$service->batchPayConfirm($ids, $acceptTime);
4 years ago
$this->ajaxReturn([
'status' => 1,
'message' => '操作成功'
]);
} catch (\Exception $e) {
5 years ago
$this->ajaxReturn([
'status' => 0,
4 years ago
'message' => $e->getMessage()
5 years ago
]);
}
5 years ago
}
}