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.

134 lines
4.6 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 = [
4 years ago
0 => '财务待确认',
5 years ago
1 => '已收到',
2 => '已退款',
];
4 years ago
public function add($params)
{
$payWay = $params['pay_way'] ?? 0;
$payType = $params['pay_type'] ?? 0;
$promoteId = $params['id'] ?? 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;
$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()) {
throw new \Exception('无法操作记录');
}
if ($payType == 0) {
throw new \Exception('请选择押金付款方式');
}
if ($payType == 3) {
return $this->handleNoDeposit($promoteId);
}
if ($payType != 2 && $payWay == 0) {
throw new \Exception('请选择付款方式');
}
if (!$record) {
if ($amount !== '') {
if (!is_numeric($amount)) {
throw new \Exception('请输入正确金额');
}
if ($amount <= 0) {
throw new \Exception('金额必须大于0');
}
if ($amount > 100000000) {
throw new \Exception('金额过高');
}
}
$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;
$data['pay_account'] = $payAccount;
$data['amount'] = floatval($amount);
$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'=>'推广员-结算单管理-奖罚记录管理-新增会长押金']);
}
}
public function handleNoDeposit($promoteId)
{
$record = M('president_deposit', 'tab_')->where(['promote_id' => $promoteId])->find();
$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;
$data['promote_id'] = $promoteId;
if (!$record) {
M('president_deposit', 'tab_')->add($data);
} else {
M('president_deposit', 'tab_')->where(['promote_id' => $promoteId])->save($data);
}
$promoteData = M('promote', 'tab_')->field('account')->where(['id' => $promoteId])->find();
addOperationLog(['op_type'=>1,'key'=>$promoteData['account'],'op_name'=>'编辑无需押金','url'=>U('PresidentDeposit/records'),'menu'=>'推广员-结算单管理-会长押金管理-无需押金']);
}
5 years ago
}