Commit 12e465f1 authored by agping's avatar agping

财务修改

parent d82f3a13
<?php
/**
* Created by PhpStorm.
* User: hu jun
* Date: 2018/3/13
* Time: 15:48
*/
namespace app\index\controller;
use app\api_broker\service\OrderLogService;
use app\index\extend\Basic;
use app\index\untils\ExportExcelUntil;
use app\model\AAgents;
use app\model\AStore;
use app\model\OBargainModel;
use app\model\ORealIncome;
use app\model\OTaxes;
use app\model\OFinancialAudit;
use app\model\OPartialCommission;
use app\model\OPayLogModel;
use app\model\ORefundModel;
class Finance extends Basic
{
/**
* 成交报告
*
* @return \think\Response|\think\response\View
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function reportList()
{
if (!$this->request->isAjax()) {
$result = '';
switch ($this->params['check_status']) {
case 1 :
//未结单
$result = view('finance/account_statement');
break;
case 4 :
//已结单
$result = view('finance/statement');
break;
case 5 :
//待撤销
$result = view('finance/wait_backOut');
break;
case 6 :
//已撤销
$result = view('finance/statement_backOut');
break;
}
return $result;
}
$data['code'] = 200;
$data['msg'] = "";
$data['data'] = [];
$pageNo = empty($this->params['pageNo']) ? 1 : $this->params['pageNo'];
$pageSize = empty($this->params['pageSize']) ? 15 : $this->params['pageSize'];
$fields = 'a.id,a.create_time,b.user_phone,b.user_name,d.internal_title,d.internal_address,a.commission,a.practical_fee,a.scale_fee,a.order_no,content,house_number';
$where['a.father_id'] = 0;
$where['c.is_del'] = 0;
$where['a.status'] = 10;
$order = 'e.id desc';
if (!empty($this->params['create_time']) && empty($this->params['end_time'])) {
$where['e.create_time'] = [ '> time', $this->params['create_time'] . ' 00:00:00' ];
}
if (!empty($this->params['end_time']) && empty($this->params['create_time'])) {
$where['e.create_time'] = [ '< time', $this->params['create_time'] . ' 23:59:59' ];
}
if (!empty($this->params['end_time']) && !empty($this->params['create_time'])) {
$where['e.create_time'] = [ 'between time', [ $this->params['create_time'] . ' 00:00:00', $this->params['create_time'] . ' 23:59:59' ] ];
}
if (!empty($this->params['internal_address'])) {
$where['d.internal_address'] = [ 'like', '%' . $this->params['internal_address'] . '%' ];
}
if (!empty($this->params['user_phone'])) {
$where['b.user_phone'] = [ 'like', '%' . $this->params['user_phone'] . '%' ];
}
if (!empty($this->params['house_number'])) {
$where['a.house_number'] = [ 'like', '%' . $this->params['house_number'] . '%' ];
}
switch ($this->params['check_status']) {
case 2 :
//成交报告列表-第二级审核
$where['e.audit_level'] = 0;
break;
case 3 :
//成交报告列表-第三级审核
$where['e.audit_level'] = 1;
break;
case 4 :
//成交报告列表-已结单
$where['a.account_statement'] = 1;
$where['a.status'] = 11;
break;
/* case 5 :
//成交报告列表-待撤销
$where['a.status'] = 20;
break;
case 6 :
//成交报告列表-已撤销
$where['a.status'] = 21;
break;*/
default :
//成交报告列表-第一级审核
$where['e.audit_level'] = NULL;
$order = 'a.id DESC';
}
if (!empty($this->params['status'])) {
$where['a.status'] = 20;
}
$bargain = new OBargainModel();
$data['data']['list'] = $bargain->getBargain($pageNo, $pageSize, $order, $fields, $where);
$data['data']['total'] = $bargain->getBargainTotal($where);
$data['data']['step'] = $this->params['check_status'];
return $this->response($data['code'], $data['msg'], $data['data']);
}
/**
* 成交报告审核
*
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function checkReport()
{
$data['code'] = 200;
$data['msg'] = "";
$data['data'] = [];
$bargain = new OBargainModel();
if (empty($this->params['id']) || empty($this->params['source']) || empty($this->params['status'])) {
$data['code'] = 101;
$data['msg'] = 'Id is null';
} else {
$params['audit_id'] = $this->userId;
$params['audit_name'] = $this->userName;
$params['audit_id'] = $this->userId;
$params['audit_level'] = $this->params['check_status'];
$params['remark'] = $this->params['remark'];
$status = $bargain->addCheckBargain($this->params['id'], $params, $this->params['source'], $this->params['status']);
if (empty($status)) {
$data['code'] = 101;
$data['msg'] = '审核失败';
}
}
return $this->response($data['code'], $data['msg'], $data['data']);
}
/**
* 通过id获取成交报告详情
*
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function bargainInfo()
{
$data['code'] = 200;
$data['msg'] = "";
$data['data'] = [];
if (empty($this->params['id'])) {
$data['code'] = 101;
$data['msg'] = 'Id is null.';
} else {
$bargain = new OBargainModel();
$fields = 'a.id,a.create_time,b.user_phone,b.user_name,d.internal_title,d.internal_address,a.is_open,a.order_id,';
$fields .= 'a.trade_type,a.house_number,a.commission,a.content,d.shop_type';
$where['a.id'] = $this->params['id'];
$data['data'] = $bargain->getBargainInfo($fields, $where);
}
return $this->response($data['code'], $data['msg'], $data['data']);
}
/**
* 修改成交报告中佣金和备注
*
* @return \think\Response
* @throws \Exception
*/
public function editBargainInfo()
{
$data['code'] = 200;
$data['msg'] = "";
$data['data'] = [];
if (empty($this->params['id'])) {
$data['code'] = 101;
$data['msg'] = 'Id is null.';
} elseif (count($this->params['practical_fee']) > 5) {
$data['code'] = 101;
$data['msg'] = '实收佣金最多5条记录';
} else {
$update_data = [];
//实收佣金
if (count($this->params['practical_fee']) > 5) {
return $this->response('101', '实收佣金数量超过限制');
}
//应收总佣金
if (!empty($this->params['commission'])) {
$update_data['commission'] = $this->params['commission'];
}
if (!empty($this->params['content'])) {
$update_data['content'] = $this->params['content'];
}
//是否开业
if (isset($this->params['is_open'])) {
$update_data['is_open'] = $this->params['is_open'];
}
//成交类型 10出租 20 增佣 30 代理 40 好处费
if (!empty($this->params['trade_type'])) {
$update_data['trade_type'] = $this->params['trade_type'];
}
$m_bargain = new OBargainModel();
$m_real = new ORealIncome();
$data['data'] = $m_bargain->updateBargainById($this->params['id'], $update_data);
if ($data['data'] == 1) {
//新增实收佣金 array 5 todo feel_id 大于0 的表示新增 否则修改
// $m_real->addRealIncome($this->params['practical_fee'], $this->params['id'], $this->userId);
$practical_fee_arr = $this->params["practical_fee"];
$bargain_id = $this->params["id"];
$add_real_arr = $update_real_arr = [];
$i = $j = 0;
foreach ($practical_fee_arr as $item) {
if(!$item['fee'] || !$item['operation_date']){
continue;
}
if ($item["fee_id"] > 0 ) {
$update_real_arr[$i]['id'] = $item['fee_id'];
$update_real_arr[$i]['bargain_id'] = $bargain_id;
$update_real_arr[$i]['operation_id'] = $this->userId;
$update_real_arr[$i]['money'] = $item['fee'];
$update_real_arr[$i]['income_time'] = $item['operation_date'];
$i++;
}else{
$add_real_arr[$j]['bargain_id'] = $bargain_id;
$add_real_arr[$j]['operation_id'] = $this->userId;
$add_real_arr[$j]['money'] = $item['fee'];
$add_real_arr[$j]['income_time'] = $item['operation_date'];
$j++;
}
}
if($i > 0 ){
$m_real->addRealIncome($update_real_arr);
}
if($j > 0){
$m_real->addRealIncome($add_real_arr);
}
} else {
$data['code'] = 101;
$data['msg'] = 'Modify the failure.';
}
}
return $this->response($data['code'], $data['msg'], $data['data']);
}
/**
* 新增分佣提成
*
* @return \think\Response
* @throws \think\exception\DbException
*/
public function addBargain()
{
$data['code'] = 200;
$data['msg'] = "";
$data['data'] = [];
if (empty($this->params['id']) || empty($this->params['agent_id'])) {
$data['code'] = 101;
$data['msg'] = '提交信息错误!';
} else {
$bargain = new OBargainModel();
$data['data'] = $bargain->addBargainCommission($this->params['id'], $this->userId, $this->params['agent_id'],
$this->params['role'], $this->params['scale_fee'], $this->params['scale']);
if ($data['data'] == 0) {
$data['code'] = 101;
$data['msg'] = 'Add the failure.';
}
}
return $this->response($data['code'], $data['msg'], $data['data']);
}
/**
* 成交报告详情-分佣提成
*
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function commissionList()
{
$data['code'] = 200;
$data['msg'] = "";
$data['data'] = [];
if (empty($this->params['id'])) {
$data['code'] = 101;
$data['msg'] = 'Id is null.';
} else {
$m_comm = new OBargainModel();
$fields = 'a.id,a.role,a.agent_id,a.scale,a.scale_fee';
$where[0] = [ 'EXP', "a.id = {$this->params['id']} or a.father_id = {$this->params['id']}" ];
$data['data'] = $m_comm->getBargainPartial(1, 100, 'a.id desc', $fields, $where);
}
return $this->response($data['code'], $data['msg'], $data['data']);
}
/**
* 收款记录
*
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function payLogList()
{
$data['code'] = 200;
$data['msg'] = "";
$data['data'] = [];
if (empty($this->params['id'])) {
$data['code'] = 101;
$data['msg'] = 'Id is null.';
} else {
$bargain = new OPayLogModel();
$fields = 'create_time,money,type,pay_type,agent_id';
$where = "report_id = {$this->params['id']}";
$data['data'] = $bargain->selectPayLogByOrderNo($fields, $where);
$agent = new AAgents();
foreach ($data['data'] as $k => $v) {
$data['data'][$k]['agent_name'] = $agent->getAgentsById($v['agent_id'], 'name');
}
}
return $this->response($data['code'], $data['msg'], $data['data']);
}
/**
* 报备时间轴
*
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectReportAll()
{
header('Access-Control-Allow-Origin:*');
$params = $this->params;
if (!isset($params["order_id"])) {
return $this->response("101", "请求参数错误");
}
$service_ = new OrderLogService();
$data = $service_->selectListByOrderNo($params["order_id"]);
return $this->response("200", "request success", $data);
}
/**
* 退款驳回
*
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
public function overRule()
{
if (empty($this->params['id'])) {
return $this->response("101", "请求参数错误");
}
$bargain = new OBargainModel();
$is = $bargain->ifBargainNumByOrderId([ 'id' => $this->params['id'] ]);
if ($is < 1) {
return $this->response("101", "没有成交报告信息");
}
$bargain->updateBargainById($this->params['id'], [ 'status' => 12 ]);
$params['audit_id'] = $this->userId;
$params['audit_name'] = $this->userName;
$params['audit_id'] = $this->userId;
$params['audit_level'] = $this->params['check_status'];
$params['remark'] = $this->params['remark'];
$status = $bargain->addCheckBargain($this->params['id'], $params, 2, 2);
if ($status) {
$data['code'] = 200;
$data['msg'] = '驳回成功';
} else {
$data['code'] = 101;
$data['msg'] = '驳回失败';
}
return $this->response($data['code'], $data['msg']);
}
/**
* 退款列表
*
* @return \think\Response|\think\response\View
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function refundList()
{
//显示视图
if (!$this->request->isAjax()) {
return view('refundList');
}
$data['code'] = 200;
$data['msg'] = "";
$data['data'] = [];
$pageNo = empty($this->params['pageNo']) ? 1 : $this->params['pageNo'];
$pageSize = empty($this->params['pageSize']) ? 15 : $this->params['pageSize'];
$check_status = [ 0, 1, 2, 3 ];
if (in_array($this->params['check_status'], $check_status)) {
switch ($this->params['check_status']) {
case 1 :
//退款列表-经理审核
$where['e.audit_level'] = 0;
break;
case 2 :
//退款列表-总监审核
$where['e.audit_level'] = 1;
break;
case 3 :
//退款列表-出纳审核
$where['e.audit_level'] = 2;
break;
default :
//退款列表-专员审核
$where['e.audit_level'] = [ 'NULL' ];
}
} else {
$where['e.audit_level'] = [ 'NULL' ];
}
$where['a.status'] = 1;
$refund = new ORefundModel();
$fields = 'a.id,a.agent_name,a.name,a.bank,a.card_no,a.create_time,a.refund_money,b.report_agent_name,b.user_name,a.order_id';
$data['data']['list'] = $refund->getCheckRefundList($pageNo, $pageSize, 'a.id DESC', $fields, $where);
$data['data']['total'] = $refund->getCheckRefundListTotal($where);
return $this->response($data['code'], $data['msg'], $data['data']);
}
/**
* 已退款列表
*
* @return \think\Response|\think\response\View
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function refundOrderList()
{
if (!$this->request->isAjax()) {
return view('refund_order_list');
}
$pageNo = empty($this->params['pageNo']) ? 1 : $this->params['pageNo'];
$pageSize = empty($this->params['pageSize']) ? 15 : $this->params['pageSize'];
$where = [];
$refund = new ORefundModel();
$field = 'a.id,a.agent_name,a.name,a.bank,a.card_no,a.create_time,a.refund_money,b.report_agent_name,b.user_name';
$where['status'] = 2; //退款成功
$data['data']['list'] = $refund->selectRefundByOrderNoPage($pageNo, $pageSize, 'id desc', $field, $where);
$data['data']['total'] = $refund->selectRefundByOrderNoPageTotal($where);
return $this->response("200", "request success", $data);
}
/**
* 分佣提成明细表
*
* @return \think\Response|\think\response\View
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function partialCommissionList()
{
if (!$this->request->isAjax()) {
return view('commission');
}
$pageNo = empty($this->params['pageNo']) ? 1 : $this->params['pageNo'];
$pageSize = empty($this->params['pageSize']) ? 15 : $this->params['pageSize'];
$where = [];
$where['a.confirm_status'] = 1;
$where['a.is_del'] = 0;
if (!empty($this->params['create_time']) && empty($this->params['end_time'])) {
$where['a.confirm_date'] = [ '>= time', $this->params['create_time'] . ' 00:00:00' ];
}
if (!empty($this->params['end_time']) && empty($this->params['create_time'])) {
$where['a.confirm_date'] = [ '<= time', $this->params['create_time'] . ' 23:59:59' ];
}
if (!empty($this->params['end_time']) && !empty($this->params['create_time'])) {
$where['a.confirm_date'] = [ 'between time', [ $this->params['create_time'] . ' 00:00:00', $this->params['create_time'] . ' 23:59:59' ] ];
}
if (!empty($this->params['internal_address'])) {
$where['d.internal_address'] = [ 'like', '%' . $this->params['internal_address'] . '%' ];
}
if (!empty($this->params['phone'])) {
$where['e.phone'] = [ 'like', '%' . $this->params['phone'] . '%' ];
}
if (!empty($this->params['name'])) {
$where['e.name'] = [ 'like', '%' . $this->params['name'] . '%' ];
}
if (!empty($this->params['house_number'])) {
$where['b.house_number'] = [ 'like', '%' . $this->params['house_number'] . '%' ];
}
$field = 'a.id,b.id as bargain_id,a.confirm_date,a.practical_fee,b.scale_fee,d.internal_address,b.agent_id,b.house_number';
$m_commission = new OPartialCommission();
$data['data']['list'] = $m_commission->getCommissionBargainList($pageNo, $pageSize, 'a.id desc', $field, $where);
$data['data']['total'] = $m_commission->getCommissionBargainListTotal($where);
return $this->response("200", "request success", $data);
}
/**
* 导出分佣提成明细表
*
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function exportExcel()
{
$pageNo = 1;
$pageSize = 250000;
$where = [];
$where['a.confirm_status'] = 1;
$where['a.is_del'] = 0;
if (!empty($this->params['create_time']) && empty($this->params['end_time'])) {
$where['a.confirm_date'] = [ '>= time', $this->params['create_time'] . ' 00:00:00' ];
}
if (!empty($this->params['end_time']) && empty($this->params['create_time'])) {
$where['a.confirm_date'] = [ '<= time', $this->params['create_time'] . ' 23:59:59' ];
}
if (!empty($this->params['end_time']) && !empty($this->params['create_time'])) {
$where['a.confirm_date'] = [ 'between time', [ $this->params['create_time'] . ' 00:00:00', $this->params['create_time'] . ' 23:59:59' ] ];
}
if (!empty($this->params['internal_address'])) {
$where['d.internal_address'] = [ 'like', '%' . $this->params['internal_address'] . '%' ];
}
if (!empty($this->params['phone'])) {
$where['e.phone'] = [ 'like', '%' . $this->params['phone'] . '%' ];
}
if (!empty($this->params['name'])) {
$where['e.name'] = [ 'like', '%' . $this->params['name'] . '%' ];
}
if (!empty($this->params['house_number'])) {
$where['b.house_number'] = [ 'like', '%' . $this->params['house_number'] . '%' ];
}
$field = 'a.id,a.confirm_date,a.practical_fee,b.scale_fee,d.internal_address,b.agent_id,cash,service_charge,charity_fund,real_fee';
$m_commission = new OPartialCommission();
$data = $m_commission->getCommissionBargainColumn($pageNo, $pageSize, 'a.id desc', $field, $where);
$export = new ExportExcelUntil();
$title = [ '收佣日期', '所属部门/门店', '业务员', '应分佣金(元)', '实分佣金(元)', '手续费(元)', '慈善基金(元)', '现金奖(元)', '实收佣金(元)' ];
$export->exportTable('分佣提成明细', $data, 8, '分佣提成明细表', $title);
return;
}
/**
* 增加实收佣金
*
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function addRealIncome()
{
if (empty($this->params['bargain_id'])) {
return $this->response(101, '新增实收参数错误');
}
$m_bargain = new OBargainModel();
$bargain_data = $m_bargain->getCheckBargain('id,agent_id,role', $this->params['bargain_id']);
//排除成交报告其它状态
if (empty($bargain_data['id'])) {
return $this->response(101, '新增失败,成交报告数据异常');
}
$m_partial = new OPartialCommission();
$insert_data = $this->params;
$insert_data['role'] = $bargain_data['role'];
$insert_data['agent_id'] = $bargain_data['agent_id'];
$data = $m_partial->addCommission($this->params, $this->userId);
return $this->response("200", "request success", $data);
}
/**
* 开票税费查询
*
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getTallAge()
{
if (empty($this->params['bargain_id'])) {
return $this->response(101, '查询开票税费参数错误!');
}
$m_fee = new OTaxes();
$field = 'a.id,a.total_fee,a.operation_date,a.bargain_id';
$data = $m_fee->getBargainFeeDetail($this->params['bargain_id'], $field);
return $this->response("200", "request success", $data);
}
/**
* 新增开票
*
* @return \think\Response
* @throws \Exception
*/
public function addTallAge()
{
if (empty($this->params['bargain_id'])) {
return $this->response(101, '新增实收参数错误');
}
if (empty($this->params['total_fee'])) {
return $this->response(101, '开票金额为空');
}
if (empty($this->params['operation_date'])) {
return $this->response(101, '开票日期为空');
}
$tax = $this->params['tax'];
if (empty($tax[0]['agent_id'])) {
return $this->response(101, '分佣方为空');
}
if (empty($tax[0]['role'])) {
return $this->response(101, '分佣方角色为空');
}
$m_bargain = new OBargainModel();
$bargain_data = $m_bargain->getCheckBargain('id', $this->params['bargain_id']);
//排除成交报告其它状态
if (empty($bargain_data['id'])) {
return $this->response(101, '成交报告数据异常!');
}
$bargain_id = $this->params['bargain_id'];
$operation_date = $this->params['operation_date'];
$insert_data['bargain_id'] = $bargain_id;
$insert_data['total_fee'] = $this->params['total_fee']; //开票金额
$insert_data['father_id'] = 0;
$insert_data['operation_id'] = $this->userId; //操作人
$insert_data['operation_date'] = $operation_date; //开票日期
$m_fee = new OTaxes();
$m_fee->editData($insert_data, $this->params['id']); //开票新增和编辑
$father_id = 0;
if($this->params['id'] && $this->params['id'] > 0 ){ //编辑
$father_id = $this->params['id'];
}else{
$father_id = $m_fee->id;
}
$m_agent = new AAgents();
foreach ($tax as $k => $v) {
$tax[$k]['agent_name'] = $m_agent->getAgentsById($v['agent_id'], 'name');
}
$data = $m_fee->addTaxes($tax, $bargain_id, $this->userId, $father_id, $this->params['total_fee'], $operation_date);
return $this->response("200", "request success", $data);
}
/**
* 成交报告经纪人查询
* 1盘方,2客方,3反签,4独家,5合作方
*
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function searchBargainAgents()
{
if (empty($this->params['bargain_id'])) {
return $this->response(101, '请求参数错误!');
}
$bargain = new OBargainModel();
$data = $bargain->getAgentTypeByBargainId($this->params['bargain_id']);
return $this->response(200, "", $data);
}
/**
* 编辑开票税费查询某一条记录
*
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getTaxesById()
{
if (empty($this->params['taxes_id'])) {
return $this->response(101, '查询开票税费参数错误!');
}
$m_fee = new OTaxes();
$field = 'id,bargain_id,fee,total_fee,father_id,operation_id,operation_date,agent_id,agent_name,role,scale,is_del';
$data = $m_fee->getTaxesId($this->params['taxes_id'], $field);
return $this->response("200", "request success", $data);
}
/**
* 税费承担明细表
*
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getTalllAgeList()
{
if (!$this->request->isAjax()) {
return view('tax');
}
$data['code'] = 200;
$data['msg'] = "";
$data['data'] = [];
$pageNo = empty($this->params['pageNo']) ? 1 : $this->params['pageNo'];
$pageSize = empty($this->params['pageSize']) ? 15 : $this->params['pageSize'];
$fields = 'a.id,a.create_time,e.name,e.phone,a.fee,b.house_number,d.internal_address,b.agent_id';
$where['c.is_del'] = 0;
$where['b.status'] = [ 'in', 10, 11 ]; //10已提交 11审核成功
if (!empty($this->params['create_time']) && empty($this->params['end_time'])) {
$where['a.create_time'] = [ '> time', $this->params['create_time'] . ' 00:00:00' ];
}
if (!empty($this->params['end_time']) && empty($this->params['create_time'])) {
$where['a.create_time'] = [ '< time', $this->params['create_time'] . ' 23:59:59' ];
}
if (!empty($this->params['end_time']) && !empty($this->params['create_time'])) {
$where['a.create_time'] = [ 'between time', [ $this->params['create_time'] . ' 00:00:00', $this->params['create_time'] . ' 23:59:59' ] ];
}
if (!empty($this->params['internal_address'])) {
$where['d.internal_address'] = [ 'like', '%' . $this->params['internal_address'] . '%' ];
}
if (!empty($this->params['phone'])) {
$where['e.phone'] = [ 'like', '%' . $this->params['phone'] . '%' ];
}
if (!empty($this->params['name'])) {
$where['e.name'] = [ 'like', '%' . $this->params['name'] . '%' ];
}
if (!empty($this->params['house_number'])) {
$where['b.house_number'] = [ 'like', '%' . $this->params['house_number'] . '%' ];
}
$m_fee = new OTaxes();
$data['data']['list'] = $m_fee->getTaxesList($pageNo, $pageSize, 'a.id desc', $fields, $where);
$data['data']['total'] = $m_fee->getTaxesListTotal($where);
return $this->response($data['code'], $data['msg'], $data['data']);
}
/**
* 分佣提成汇总表
*
* @return \think\Response|\think\response\View
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getCommissionTotalList()
{
if (!$this->request->isAjax() && $this->params['excel'] != 1) {
return view('commission_total');
}
$data['code'] = 200;
$data['msg'] = "";
$data['data'] = [];
$whereOr = [];
$pageNo = empty($this->params['pageNo']) ? 1 : $this->params['pageNo'];
$pageSize = empty($this->params['pageSize']) ? 15 : $this->params['pageSize'];
$where['c.is_del'] = 0; //订单状态
// $where['a.status'] = ['in', '10,11']; //10已提交 11审核成功
// $where['b.father_id'] = ['<>', 0]; //去除税费总佣金
// $where['c.confirm_status'] = 1; //确认分佣
/**收佣日期 start**/
if (!empty($this->params['commission_start_date']) && empty($this->params['commission_end_date'])) {
$where['b.operatiof.income_time'] = [ '> time', $this->params['commission_start_time'] ];
}
if (!empty($this->params['commission_end_date']) && empty($this->params['commission_start_date'])) {
$where['f.income_time'] = [ '< time', $this->params['commission_end_time'] ];
}
if (!empty($this->params['commission_start_date']) && !empty($this->params['commission_end_date'])) {
$where['f.income_time'] = [ 'between time', [ $this->params['commission_start_date'], $this->params['commission_end_date'] ] ];
}
/**收佣日期 end**/
/**提交成交报告日期 start**/
if (!empty($this->params['deal_start_date']) && empty($this->params['deal_end_date'])) {
$where['a.create_time'] = [ '> time', $this->params['deal_start_date'] ] . ' 00:00:00';
}
if (!empty($this->params['deal_end_date']) && empty($this->params['deal_start_date'])) {
$where['a.create_time'] = [ '< time', $this->params['deal_end_date'] ] . '23:59:59';
}
if (!empty($this->params['deal_start_date']) && !empty($this->params['deal_end_date'])) {
$where['a.create_time'] = [ 'between time', [ $this->params['deal_start_date'] . ' 00:00:00', $this->params['deal_end_date'] . '23:59:59' ] ];
}
/**提交成交报告日期 end**/
/**开票日期 start**/
if (!empty($this->params['operation_start_date']) && empty($this->params['operation_end_date'])) {
$where_fee['b.operation_date'] = [ '> time', $this->params['operation_start_date'] ];
}
if (!empty($this->params['operation_end_date']) && empty($this->params['operation_start_date'])) {
$where_fee['b.operation_date'] = [ '> time', $this->params['operation_start_date'] ];
}
if (!empty($this->params['operation_start_date']) && !empty($this->params['operation_end_date'])) {
$where_fee['b.operation_date'] = [ 'between time', [ $this->params['operation_start_date'], $this->params['operation_end_date'] ] ];
}
/**开票日期 end**/
/**经纪人手机号**/
if (!empty($this->params['phone'])) {
$where['b.phone'] = [ 'like', '%' . $this->params['phone'] . '%' ];
}
/**经纪人姓名**/
if (!empty($this->params['name'])) {
$where['d.name'] = [ 'like', '%' . $this->params['name'] . '%' ];
}
/**部门id**/
if (!empty($this->params['district_id'])) {
$where['d.district_id'] = $this->params['district_id'];
}
/**门店名**/
if (!empty($this->params['store_name'])) {
$m_store = new AStore();
$store_id = $m_store->findStore('id', [ 'store_name' => [ 'like', '%' . $this->params['store_name'] . '%' ] ]);
$where['d.store_id'] = $store_id['id'];
}
$m_bargain = new OBargainModel();
if (empty($this->params['excel']) && $this->params['excel'] != 1) {
$fields = 'f.income_time,a.create_time,a.id,a.agent_id,sum(b.fee) as fee,sum(c.practical_fee) as practical_fee,sum(c.cash) as cash,';
$fields .= 'sum(c.service_charge) as service_charge,sum(b.fee) as fee,sum(c.real_fee) as real_fee,';
$fields .= 'd.name,d.phone';
$data['data']['list'] = $m_bargain->getCommissionTotalList($pageNo, $pageSize, 'a.id desc', $fields, $where, $whereOr);
$data['data']['total'] = $m_bargain->getCommissionTotalListTotal($where, $whereOr);
} else {
//导出Excel
$fields = 'f.income_time,a.create_time,sum(b.fee) as fee,sum(f.money) as money,sum(c.cash) as cash,';
$fields .= 'sum(c.service_charge) as service_charge,';
$fields .= 'd.name,d.phone,sum(c.charity_fund) as charity_fund, sum(should_commission) as should_commission';
$pageSize = 25000;
$data = $m_bargain->getCommissionTotalList($pageNo, $pageSize, 'a.id desc', $fields, $where, $whereOr);
foreach ($data as $k => $v) {
$excel_data[$k]['income_time'] = $v['income_time']; //收佣日期
$excel_data[$k]['create_time'] = $v['create_time']; //成交日期
$excel_data[$k]['district_store'] = $v['district_store']; //所属部门/门店
$excel_data[$k]['name'] = $v['name'] . '-' . $v['phone']; //业务员
$excel_data[$k]['should_commission'] = $v['should_commission']; //应分佣金
$excel_data[$k]['service_charge'] = $v['service_charge']; //手续费
$excel_data[$k]['cash'] = $v['cash']; //现金奖
$excel_data[$k]['charity_fund'] = $v['charity_fund']; //慈善基金
$excel_data[$k]['money'] = $v['money']; //实收佣金
$excel_data[$k]['fee'] = $v['fee']; //税费
$excel_data[$k]['over_fee'] = $v['real_fee'] - $v['charity_fund'];
}
$num = count($excel_data) + 1;
$excel_data[$num]['income_time'] = '合计'; //收佣日期
$excel_data[$num]['create_time'] = ''; //成交日期
$excel_data[$num]['district_store'] = ''; //所属部门/门店
$excel_data[$num]['name'] = ''; //业务员
$excel_data[$num]['should_commission'] = "=SUM(E3:E{$num})"; //应分佣金
$excel_data[$num]['service_charge'] = "=SUM(F3:F{$num})"; //手续费
$excel_data[$num]['cash'] = "=SUM(G3:G{$num})"; //现金奖
$excel_data[$num]['charity_fund'] = "=SUM(H3:H{$num})"; //慈善基金
$excel_data[$num]['money'] = "=SUM(I3:I{$num})"; //实收佣金
$excel_data[$num]['fee'] = "=SUM(J3:J{$num})"; //税费
$excel_data[$num]['over_fee'] = "=SUM(K3:K{$num})";
$export = new ExportExcelUntil();
$title = [ '收佣日期/开票日期', '成交日期/开票日期', '所属部门/门店', '业务员', '应分佣金(元)', '手续费(元)', '现金奖(元)', '慈善基金(元)', '实收佣金(元)', '税费(元)', '最终实收(元)' ];
$export->exportTable('分佣提成汇总表', $excel_data, 11, '分佣提成汇总表', $title);
return;
}
return $this->response($data['code'], $data['msg'], $data['data']);
}
/**
* 回到一级审核
*
* @return \think\Response
*/
public function toReportListOne()
{
if (empty($this->params['bargain_id'])) {
return $this->response(101, '参数错误');
}
$m_financial = new OFinancialAudit();
$data['status'] = 3;
$data = $m_financial->editData($data, $this->params['bargain_id'], 'bargain_id');
$msg = '';
if ($data > 0) {
$code = 200;
} else {
$code = 101;
$msg = '操作失败!';
}
return $this->response($code, $msg);
}
/**
* 财务结单
*
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
public function checkOver()
{
if (empty($this->params['bargain_id'])) {
return $this->response(101, '参数错误');
}
$m_bargain = new OBargainModel();
$insert_data['audit_id'] = $this->userId;
$insert_data['audit_name'] = $this->userName;
$insert_data['audit_level'] = 3;
$data = $m_bargain->addCheckBargain($this->params['bargain_id'], $insert_data, 1, 10);
$code = 200;
$msg = "";
if (!$data) {
$code = 101;
$msg = '参数错误结单失败!';
}
return $this->response($code, $msg);
}
}
......@@ -219,7 +219,7 @@ Route::group('index', [
'getTallAge' => [ 'index/Finance/getTallAge', [ 'method' => 'GET' ] ], //开票税费查询
'addTallAge' => [ 'index/Finance/addTallAge', [ 'method' => 'POST' ] ], //新增和编辑开票税费
'searchBargainAgents' => [ 'index/Finance/searchBargainAgents', [ 'method' => 'GET' ] ], //获取盘方,客方,反签,独家,合作方
'getTallAgeList' => [ 'index/Finance/getTallAgeList', [ 'method' => 'GET' ] ], //税费承担明细表
'getTallAgeList' => [ 'index/Finance/getTalllAgeList', [ 'method' => 'GET' ] ], //税费承担明细表
'getCommissionTotalList' => [ 'index/Finance/getCommissionTotalList', [ 'method' => 'GET' ] ], //分佣提成汇总表
'test123' => [ 'index/WatchShop/test123', [ 'method' => 'get|post' ] ], //时间轴
'agent_zhuan_aagent' => [ 'index/agent/agent_zhuan_aagent', [ 'method' => 'post|get' ] ],//经纪人
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment