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.

247 lines
8.7 KiB
PHTML

5 years ago
<?php
namespace Base\Service;
use Base\Model\PromoteModel;
use Base\Model\UserPlayInfoModel;
use Base\Model\UserPlayModel;
use Base\Model\UserModel;
use Think\Model;
class PresidentDepositService
{
const PAY_TYPE_CASH = 1;
const PAY_TYPE_DIVIDE = 2;
const PAY_TYPE_NONE = 3;
public static $payWays = [
1 => '银行转账',
2 => '支付宝转账',
3 => '微信转账',
4 => '分成款扣除',
5 years ago
];
public static $payTypes = [
self::PAY_TYPE_CASH => '线下转账',
self::PAY_TYPE_DIVIDE => '分成款扣除',
self::PAY_TYPE_NONE => '无需押金',
];
public static $statusList = [
5 years ago
0 => '财务待确认',
5 years ago
1 => '已收到',
2 => '已退款',
];
4 years ago
public function checkBeforeSave($params, $record = null)
{
if ($params['pay_type'] == 0) {
throw new \Exception('请选择押金付款方式');
4 years ago
} elseif ($params['pay_type'] == 3) {
return;
4 years ago
}
if ($params['pay_type'] != 2 && $params['pay_way'] == 0) {
4 years ago
throw new \Exception('请选择押金支付方式');
4 years ago
}
if ($record && $params['amount'] === '') {
4 years ago
throw new \Exception('请输入押金金额');
4 years ago
}
4 years ago
4 years ago
if ($params['amount'] !== '') {
if (!is_numeric($params['amount'])) {
4 years ago
throw new \Exception('请输入正确押金金额');
4 years ago
}
if ($params['amount'] <= 0) {
4 years ago
throw new \Exception('押金金额必须大于0');
4 years ago
}
if ($params['amount'] > 100000000) {
4 years ago
throw new \Exception('押金金额过高');
4 years ago
}
}
}
4 years ago
public function save($params, $company = null)
4 years ago
{
4 years ago
if (empty($params)) {
throw new \Exception('参数不能为空');
}
4 years ago
$companyId = $params['company_id'] ?? 0;
4 years ago
$payWay = $params['pay_way'] ?? 0;
$payType = $params['pay_type'] ?? 0;
$payAccount = $params['pay_account'] ?? '';
$amount = $params['amount'] ?? '';
$payer = $params['payer'] ?? '';
$payAcceptTime = $params['pay_accept_time'] ?? '';
$refundTime = $params['refund_time'] ?? '';
$payAcceptTime = $payAcceptTime ? strtotime($payAcceptTime) : 0;
$refundTime = $refundTime ? strtotime($refundTime) : 0;
4 years ago
if (is_null($company)) {
$company = M('promote_company', 'tab_')->where(['id' => $companyId, 'company_belong' => ['in', [1, 2]]])->find();
if (is_null($company)) {
throw new \Exception('推广公司不存在');
}
}
4 years ago
$record = M('president_deposit', 'tab_')->where(['company_id' => $company['id']])->find();
4 years ago
$this->checkBeforeSave($params, $record);
4 years ago
4 years ago
if ($params['pay_type'] == 3) {
return $this->handleNoDeposit($company, $record);
}
if ($record) {
4 years ago
$this->update($params, $company, $record);
4 years ago
addOperationLog(['op_type'=>1,'key'=>$company['company_name'].'/'.$params['amount'],'op_name'=>'编辑会长押金','url'=>U('PresidentDeposit/edit',['id'=>$company['id']]),'menu'=>'推广员-结算单管理-会长押金管理-编辑会长押金']);
} else {
4 years ago
$this->add($params, $company);
4 years ago
addOperationLog(['op_type'=>0,'key'=>$company['company_name'].'/'.$params['amount'],'op_name'=>'新增会长押金','url'=>U('PresidentDeposit/edit',['id'=>$company['id']]),'menu'=>'推广员-结算单管理-奖罚记录管理-新增会长押金']);
}
}
4 years ago
4 years ago
private function add($params, $company)
{
$data = [];
$data['pay_way'] = $params['pay_type'] == 2 ? 4 : $params['pay_way'];
$data['pay_type'] = $params['pay_type'];
$data['company_id'] = $company['id'];
$data['pay_account'] = $params['pay_account'];
$data['amount'] = floatval($params['amount']);
$data['payer'] = $params['payer'];
$data['create_time'] = time();
$data['update_time'] = time();
M('president_deposit', 'tab_')->add($data);
}
4 years ago
4 years ago
private function update($params, $company, $record)
{
4 years ago
$payType = $params['pay_type'] ?? 0;
4 years ago
$payAcceptTime = $params['pay_accept_time'] == '' ? 0 : strtotime($params['pay_accept_time']);
$refundTime = $params['refund_time'] == '' ? 0 : strtotime($params['pay_accept_time']);
4 years ago
4 years ago
$data = [];
4 years ago
4 years ago
$status = null;
if ($payType != $record['pay_type']) {
$status = 0;
$data['refund_time'] = $data['pay_accept_time'] = $data['pay_confirm_time'] = 0;
} else {
4 years ago
$data['pay_accept_time'] = $payAcceptTime;
$data['refund_time'] = $refundTime;
4 years ago
}
4 years ago
4 years ago
4 years ago
$data['pay_way'] = $params['pay_type'] == 2 ? 4 : $params['pay_way'];
$data['pay_type'] = $params['pay_type'];
$data['pay_account'] = $params['pay_account'];
$data['amount'] = floatval($params['amount']);
$data['payer'] = $params['payer'];
$data['status'] = $status ?? $record['status'];
$data['update_time'] = time();
M('president_deposit', 'tab_')->where(['id' => $record['id']])->save($data);
4 years ago
}
4 years ago
public function handleNoDeposit($company, $record = null)
{
4 years ago
$data = [];
$data['pay_way'] = 0;
$data['pay_type'] = self::PAY_TYPE_NONE;
$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;
if (!$record) {
4 years ago
$data['company_id'] = $company['id'];
4 years ago
M('president_deposit', 'tab_')->add($data);
} else {
4 years ago
M('president_deposit', 'tab_')->where(['company_id' => $company['id']])->save($data);
}
addOperationLog(['op_type'=>1,'key'=>$company['company_name'],'op_name'=>'编辑无需押金','url'=>U('PresidentDeposit/records'),'menu'=>'推广员-结算单管理-会长押金管理-无需押金']);
}
public function batchRefund(array $companyIds)
{
if (isMarketAdmin()) {
throw new \Exception('无法操作记录');
}
$companyIds = I('ids', []);
if (count($companyIds) == 0) {
throw new \Exception('无选中项');
}
$checkStatus = true;
$records = M('president_deposit', 'tab_')->where(['company_id' => ['in', $companyIds]])->select();
foreach ($records as $record) {
if ($record['status'] != 1) {
$checkStatus = false;
break;
}
}
if (!$checkStatus) {
throw new \Exception('含有非已到账状态记录,不可批量操作');
}
M('president_deposit', 'tab_')->where(['company_id' => ['in', $companyIds]])->save([
'status' => 2,
'refund_time' => time(),
'update_time' => time(),
'pay_accept_time' => 0
]);
$companies = M('promote_company', 'tab_')->field(['company_name', 'id'])->where(['id' => ['in', $companyIds]])->select();
$companies = index_by_column('id', $companies);
foreach ($records as $record) {
$company = $companies[$record['company_id']] ?? null;
if ($record['amount']) {
addOperationLog(['op_type'=>1,'key'=>$company['company_name'].'/'.$record['amount'],'op_name'=>'编辑押金已退款','url'=>U('PresidentDeposit/records'),'menu'=>'推广员-结算单管理-会长押金管理-押金已退款']);
}
}
}
4 years ago
public function batchPayConfirm(array $companyIds, $acceptTime)
4 years ago
{
if (isMarketAdmin()) {
throw new \Exception('无法操作记录');
}
if (count($companyIds) == 0) {
throw new \Exception('无选中项');
}
$checkStatus = true;
4 years ago
$records = M('president_deposit', 'tab_')->where(['company_id' => ['in', $companyIds]])->select();
4 years ago
foreach ($records as $record) {
if ($record['status'] != 0) {
$checkStatus = false;
break;
}
}
if (!$checkStatus) {
throw new \Exception('含有非待确认状态记录,不可批量操作');
}
4 years ago
M('president_deposit', 'tab_')->where(['company_id' => ['in', $companyIds]])->save([
4 years ago
'status' => 1,
'pay_confirm_time' => time(),
'update_time' => time(),
4 years ago
'pay_accept_time' => strtotime($acceptTime)
4 years ago
]);
$companies = M('promote_company', 'tab_')->field(['company_name', 'id'])->where(['id' => ['in', $companyIds]])->select();
$companies = index_by_column('id', $companies);
foreach ($records as $record) {
$company = $companies[$record['company_id']] ?? null;
if ($record['amount']) {
addOperationLog(['op_type'=>1,'key'=>$company['company_name'].'/'.$record['amount'],'op_name'=>'编辑确认押金到账','url'=>U('PresidentDeposit/records'),'menu'=>'推广员-结算单管理-会长押金管理-确认押金到账']);
}
4 years ago
}
}
5 years ago
}