'银行转账', 2 => '支付宝转账', 3 => '微信转账', 4 => '分成款扣除', ]; public static $payTypes = [ self::PAY_TYPE_CASH => '线下转账', self::PAY_TYPE_DIVIDE => '分成款扣除', self::PAY_TYPE_NONE => '无需押金', ]; public static $statusList = [ 0 => '财务待确认', 1 => '已收到', 2 => '已退款', ]; public function checkBeforeSave($params, $record = null) { if ($params['pay_type'] == 0) { throw new \Exception('请选择押金付款方式'); } elseif ($params['pay_type'] == 3) { return; } if ($params['pay_type'] != 2 && $params['pay_way'] == 0) { throw new \Exception('请选择押金支付方式'); } if ($record && $params['amount'] === '') { throw new \Exception('请输入押金金额'); } if ($params['amount'] !== '') { if (!is_numeric($params['amount'])) { throw new \Exception('请输入正确押金金额'); } if ($params['amount'] <= 0) { throw new \Exception('押金金额必须大于0'); } if ($params['amount'] > 100000000) { throw new \Exception('押金金额过高'); } } } public function save($params, $company) { $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; $record = M('president_deposit', 'tab_')->where(['company_id' => $company['id']])->find(); if ($params['pay_type'] == 3) { return $this->handleNoDeposit($company, $record); } if ($record) { $this->update(); addOperationLog(['op_type'=>1,'key'=>$company['company_name'].'/'.$params['amount'],'op_name'=>'编辑会长押金','url'=>U('PresidentDeposit/edit',['id'=>$company['id']]),'menu'=>'推广员-结算单管理-会长押金管理-编辑会长押金']); } else { $this->add(); addOperationLog(['op_type'=>0,'key'=>$company['company_name'].'/'.$params['amount'],'op_name'=>'新增会长押金','url'=>U('PresidentDeposit/edit',['id'=>$company['id']]),'menu'=>'推广员-结算单管理-奖罚记录管理-新增会长押金']); } } 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); } private function update($params, $company, $record) { $payAcceptTime = $params['pay_accept_time'] == '' ? 0 : strtotime($params['pay_accept_time']); $refundTime = $params['refund_time'] == '' ? 0 : strtotime($params['pay_accept_time']); $data = []; $status = null; if ($payType != $record['pay_type']) { $status = 0; $data['refund_time'] = $data['pay_accept_time'] = $data['pay_confirm_time'] = 0; } else { $data['pay_accept_time'] = $payAcceptTime; $data['refund_time'] = $refundTime; } $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); } public function handleNoDeposit($company, $record = null) { $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) { $data['company_id'] = $company['id']; M('president_deposit', 'tab_')->add($data); } else { 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'=>'推广员-结算单管理-会长押金管理-押金已退款']); } } } public function batchPayConfirm(array $companyIds) { if (isMarketAdmin()) { throw new \Exception('无法操作记录'); } if (count($companyIds) == 0) { throw new \Exception('无选中项'); } $checkStatus = true; $records = M('president_deposit', 'tab_')->where(['promote_id' => ['in', $promoteIds]])->select(); foreach ($records as $record) { if ($record['status'] != 0) { $checkStatus = false; break; } } if (!$checkStatus) { throw new \Exception('含有非待确认状态记录,不可批量操作'); } M('president_deposit', 'tab_')->where(['promote_id' => ['in', $promoteIds]])->save([ 'status' => 1, 'pay_confirm_time' => time(), 'update_time' => time(), 'pay_accept_time' => strtotime(I('accept_time')) ]); $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'=>'推广员-结算单管理-会长押金管理-确认押金到账']); } } } }