Commit 104ede14 authored by hujun's avatar hujun

办公楼成功报告

parent 023d25f0
<?php
namespace app\index\controller;
use app\index\extend\Basic;
use app\index\untils\ExportExcelUntil;
use app\model\OfficeOBargainModel;
use app\model\OfficeOMarchInModel;
use app\model\OfficeORealIncome;
use think\Request;
class OfficeBargain extends Basic
{
private $m_bargain;
public function __construct(Request $request = null)
{
parent::__construct($request);
$this->m_bargain = new OfficeOBargainModel();
}
/**
* 成交报告
*
* @return \think\Response
*/
public function reportList()
{
// if (!$this->request->isAjax() && empty($this->params['excel'])) {
// $result = '';
//
// switch ($this->params['check_status']) {
// case 10 :
// //未结单
// $result = view('finance/account_statement');
// break;
// case 4 :
// //已结单
// $result = view('finance/statement');
// break;
// case 5 :
// //待撤销
// $result = view('finance/wait_back_out');
// 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'];
$check_status = $this->params['check_status'];
$fields = 'a.id,a.create_time,a.trade_type,f.title,
f.address,a.commission,a.practical_fee,a.scale_fee,a.order_no,
a.order_id,content,a.house_number,a.is_open,a.agent_id,a.submit_agent_name,
a.price,a.audit_level,e.id as partial_commission_id,b.user_phone,b.user_name,a.report_id';
$where['a.father_id'] = 0;
$where['a.status'] = 11;
$order = 'a.id desc';
$is_show = 0;
if (!empty($this->params['create_time']) && empty($this->params['end_time'])) {
$where['a.create_time'] = [ '> time', $this->params['create_time'] . ' 00:00:00' ];
$is_show = 1;
}
if (!empty($this->params['end_time']) && empty($this->params['create_time'])) {
$where['a.create_time'] = [ '< time', $this->params['end_time'] . ' 23:59:59' ];
$is_show = 1;
}
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['end_time'] . ' 23:59:59' ] ];
$is_show = 1;
}
if (!empty($this->params['internal_address'])) {
$where['f.address'] = [ 'like', '%' . $this->params['internal_address'] . '%' ];
$is_show = 1;
}
if (!empty($this->params['user_phone'])) {
$where['b.user_phone'] = [ 'like', '%' . $this->params['user_phone'] . '%' ];
$is_show = 1;
}
if (!empty($this->params['house_number'])) {
$where['a.house_number'] = [ 'like', '%' . $this->params['house_number'] . '%' ];
$is_show = 1;
}
//商铺类型(0商场,1街铺)
// if (isset($this->params['shop_type']) && $this->params['shop_type'] != -1) {
// $where['d.shop_type'] = $this->params['shop_type'];
// $is_show = 1;
// }
if (!empty($this->params['bargain_id'])) {
$where['a.id'] = $this->params['bargain_id'];
$is_show = 1;
}
/* if (!empty($this->params['is_pay_log'])) {
if ($this->params['is_pay_log'] == 1) {
$where[] = ['EXP', 'f.id is not null'];
} else {
$where[] = ['EXP', 'f.id is null'];
}
$is_show = 1;
}*/
$excel_title = '成交报告';
switch ($check_status) {
case 2 :
//成交报告列表-第二级审核
$where['a.audit_level'] = 1;
$where['a.status'] = 11;
$excel_title .= '-第二级审核';
break;
case 3 :
//成交报告列表-第三级审核
$where['a.audit_level'] = 2;
$where['a.status'] = 11;
$excel_title .= '-第三级审核';
break;
case 4 :
//成交报告列表-已结单
$where['a.account_statement'] = 1;
$where['a.status'] = 13;
$where['a.audit_level'] = 3;
$excel_title .= '-已结单';
break;
case 5 :
//成交报告列表-待撤销
$where['a.status'] = 20;
$where['a.audit_level'] = 0;
$is_show = 0;
break;
case 6 :
//成交报告列表-已撤销
$where['a.status'] = 21;
$is_show = 0;
break;
case 7 :
//成交报告列表-待撤销-第一级审核
$where['a.status'] = 20;
$where['a.audit_level'] = 1;
$is_show = 0;
break;
case 8 :
//成交报告列表-待撤销-第二级审核
$where['a.status'] = 20;
$where['a.audit_level'] = 2;
$is_show = 0;
break;
case 9 :
//成交报告列表-待撤销-第三级审核
$where['a.status'] = 20;
$where['a.audit_level'] = 3;
$is_show = 0;
break;
case 10 :
//成交报告列表-全部
$where['a.status'] = ['IN','10,11,13'];
$excel_title .= '-全部';
break;
default :
//成交报告列表-第一级审核
$order = 'a.id DESC';
$where['a.status'] = 10;
$where['a.audit_level'] = 0;
$excel_title .= '-第三级审核';
}
if (!empty($this->params['status'])) {
$where['a.status'] = 20;
}
try {
if (!empty($this->params['district_id'])) {
$agent_where['b.district_id'] = $this->params['district_id'];
}
if (!empty($this->params['store_id'])) {
$agent_where['b.store_id'] = $this->params['store_id'];
}
if (!empty($this->params['agent_phone'])) {
$agent_where['b.phone'] = [ 'LIKE', '%' . $this->params['agent_phone'] . '%' ];
}
if (!empty($this->params['agent_name'])) {
$agent_where['b.name'] = [ 'LIKE', '%' . $this->params['agent_name'] . '%' ];
}
if (!empty($agent_where)) {
$m_agent_march = new OfficeOMarchInModel();
$agent_where['c.id'] = ['>', 0];
$march_bargain_id = $m_agent_march->getAgentMarchIn('c.id,c.father_id', $agent_where);
if ($march_bargain_id['status'] == 'fail') {
return $this->response(101, '约带查询错误:'.$march_bargain_id['msg']);
} elseif (empty($march_bargain_id['status'])) {
return $this->response(200, "");
} else {
$where_id = [];
foreach ($march_bargain_id['data'] as $k => $v) {
if ($v['father_id'] == 0) {
$where_id[] = $v['id'];
} else {
$where_id[] = $v['father_id'];
}
}
if (empty($where_id)) {
return $this->response(200, "");
}
if (!empty($where['a.id'])) {
$where_id[] = $where['a.id'];
}
$where['a.id'] = [ 'in', array_unique($where_id) ];
}
$is_show = 1;
}
//分佣方姓名
if (!empty($this->params['partial_id'])) {
$where_bargain_id = $this->m_bargain->agentBargainAll('a.id,a.father_id', [ 'b.id' => $this->params['partial_id'] ]);
if (empty($where_bargain_id)) {
return $this->response(200, '');
} else {
$where_id = [];
foreach ($where_bargain_id as $k => $v) {
if ($v['father_id'] == 0) {
$where_id[] = $v['id'];
} else {
$where_id[] = $v['father_id'];
}
}
if (!empty($this->params['bargain_id'])) {
$where_id[] = $this->params['bargain_id'];
}
$where['a.id'] = [ 'in', array_unique($where_id) ];
}
$is_show = 1;
}
if (!empty($this->params['user_id'])) {
$where['b.user_id'] = $this->params['user_id'];
$is_show = 1;
}
if (empty($this->params['excel'])) {
$list_data = $this->m_bargain->getBargainList($pageNo, $pageSize, $order, $fields, $where);
$m_real = new OfficeORealIncome();
foreach ($list_data as $k=>$v) {
$list_data[$k]['income_money'] = $m_real->sumField('money',['bargain_id'=>$v['id'], 'is_del'=>0]);
$list_data[$k]['user_phone'] = substr_replace($list_data[$k]['user_phone'], '****', 3, 4);
}
$data['data']['list'] = $list_data;
$data['data']['total'] = $this->m_bargain->getBargainTotal($where);
$data['data']['step'] = $check_status;
if ($is_show) {
$data['data']['total_commission'] = $this->m_bargain->getBargainListSum('commission', $where);
$data['data']['total_income_money'] = $m_real->getIncomeListSum('e.money', $where);
} else {
$data['data']['total_commission'] = 0;
$data['data']['total_income_money'] = 0;
}
} else {
$list_data = $this->m_bargain->getBargainList(1, 50000, $order, $fields, $where);
if (!empty($list_data)) {
$excel_data = [];
$m_real = new OfficeORealIncome();
$trade_type_arr = [
10=>'出租 ',20=>'增佣',30=>'代理',40=>'好处费'
];
foreach ($list_data as $k=>$v) {
$excel_data[$k]['id'] = $v['id'];
$excel_data[$k]['create_time'] = $v['create_time'];
// $excel_data[$k]['is_open'] = $v['is_open'] ? '是':'否';
$excel_data[$k]['internal_address'] = $v['internal_address'];
$excel_data[$k]['house_number'] = $v['house_number'];
$excel_data[$k]['price'] = $v['price'];
$excel_data[$k]['submit_agent_name'] = $v['submit_agent_name'];
$excel_data[$k]['trade_type'] = array_key_exists($v['trade_type'], $trade_type_arr) ? $trade_type_arr[$v['labels_id']] : '其他';
$excel_data[$k]['commission'] = $v['commission'];
$excel_data[$k]['income_money'] = $m_real->sumField('money',['bargain_id'=>$v['id'], 'is_del'=>0]);
$excel_data[$k]['subtract'] = $v['commission'] - $excel_data[$k]['income_money'];
}
$export = new ExportExcelUntil();
$title = [ 'ID', '提交时间', '商铺地址', '商铺号', '成交价', '提交人', '成交类型', '应收佣金(元)','已收佣金(元)','未收佣金(元)' ];
$export->exportTable($excel_title, $excel_data, 11, $excel_title, $title);
}
}
} catch (\Exception $e) {
return $this->response(101, '内部错误,获取列表失败!请联系运营。' . $e->getMessage());
}
return $this->response($data['code'], $data['msg'], $data['data']);
}
}
\ No newline at end of file
......@@ -1630,4 +1630,69 @@ class OfficeOBargainModel extends Model
->where($where)
->find();
}
/**
* 成交报告列表
*
* @param int $pageNo
* @param int $pageSize
* @param string $order_
* @param string $field
* @param string $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getBargainList($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field = '', $params = '')
{
return $this->db_->field($field)->alias('a')
->join('office_o_report b', 'a.report_id = b.id', 'left')
->join('office_o_order c', 'a.order_id = c.id', 'left')
->join('office_g_room d', 'c.house_id = d.id', 'left')
->join('office_o_partial_commission e', 'a.id = e.bargain_id', 'left')
->join('office_g_building f', 'd.building_id=f.id','left')
->where($params)
->order($order_)
->limit($pageSize)
->page($pageNo)
->group('a.id')
->select();
}
/**
* 成交报告总数
*
* @param array $params
* @return int
*/
public function getBargainTotal(array $params = [])
{
return $this->db_->alias('a')
->join('office_o_report b', 'a.report_id = b.id', 'left')
->join('office_o_order c', 'a.order_id = c.id', 'left')
->join('office_g_room d', 'c.house_id = d.id', 'left')
->join('office_o_partial_commission e', 'a.id = e.bargain_id', 'left')
->join('office_g_building f', 'd.building_id=f.id','left')
->where($params)
->group('a.id')
->count();
}
/**
* @param string $field
* @param string $params
* @return float|int
*/
public function getBargainListSum($field = '', $params = '')
{
return $this->db_->alias('a')
->join('office_o_report b', 'a.report_id = b.id', 'left')
->join('office_o_order c', 'a.order_id = c.id', 'left')
->join('office_g_room d', 'c.house_id = d.id', 'left')
->join('office_o_partial_commission e', 'a.id = e.bargain_id', 'left')
->join('office_g_building f', 'd.building_id=f.id','left')
->where($params)
->sum($field);
}
}
\ No newline at end of file
......@@ -460,7 +460,7 @@ class OfficeOMarchInModel extends Model
$data['data'] = $this->db_model->field($field)
->alias('a')
->join('a_agents b', 'a.reception_id = b.id', 'left')
->join('o_bargain c', 'a.order_id = c.order_id', 'left')
->join('office_o_bargain c', 'a.order_id = c.order_id', 'left')
->where($where)
->select();
$data['status'] = 'successful';
......
<?php
/**
* Created by PhpStorm.
* User: hu jun
* Date: 2018/5/18
* Time: 10:26
*/
namespace app\model;
use think\Exception;
class OfficeOPartialCommission extends BaseModel
{
protected $table = "office_o_partial_commission";
/**
* 成交报告分佣表
*
* @param $pageNo
* @param $pageSize
* @param string $order_
* @param $fields
* @param $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getCommissionBargainList($pageNo, $pageSize, $order_ = 'id desc', $fields, $where)
{
$data = $this->field($fields)
->alias('a')
->join('o_bargain b', 'a.bargain_id = b.id', 'left')
->join('o_order c', 'b.order_id = c.id', 'left')
->join('g_houses d', 'c.house_id = d.id', 'left')
->join('a_agents e', 'b.agent_id = e.id', 'left')
->join('o_real_income f', 'a.real_income_id = f.id', 'left')
->where($where)
->order($order_)
->limit($pageSize)
->page($pageNo)
->select();
$m_agent = new AAgents();
$fields_str = 'a.id,a.name,a.phone,b.store_name';
foreach ($data as $k => $v) {
//分佣ID
$data[$k]['commission_id'] = $v["bargain_id"] ;
if (isset($v['agent_id'])) {
$agent_data = $m_agent->getStoreDistrict($fields_str, [ 'a.id' => $v['agent_id'] ]);
$data[$k]['agent'] = $agent_data['name'] . '-' . $agent_data['phone'];
$data[$k]['district_store'] = $agent_data['store_name'];
}
if ($v['father_id'] != 0) {
$data[$k]['bargain_id'] = $v['father_id'];
}
}
return $data;
}
/**
* @param $where
* @return float|int
*/
public function totalMoney($where) {
return $this->alias('a')
->join('o_bargain b', 'a.bargain_id = b.id', 'left')
->join('o_order c', 'b.order_id = c.id', 'left')
->join('g_houses d', 'c.house_id = d.id', 'left')
->join('a_agents e', 'b.agent_id = e.id', 'left')
->join('o_real_income f', 'a.real_income_id = f.id', 'left')
->where($where)
->sum('a.practical_fee');
}
/**
* 导出列表
*
* @param $pageNo
* @param $pageSize
* @param string $order_
* @param $fields
* @param $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
/**
* @param $pageNo
* @param $pageSize
* @param string $order_
* @param $fields
* @param $where
* @return array
*/
public function getCommissionBargainColumn($pageNo, $pageSize, $order_ = 'id desc', $fields, $where)
{
$data = $this->alias('a')
->join('o_bargain b', 'a.bargain_id = b.id', 'left')
->join('o_order c', 'b.order_id = c.id', 'left')
->join('g_houses d', 'c.house_id = d.id', 'left')
->join('a_agents e', 'b.agent_id = e.id', 'left')
->join('o_real_income f', 'a.real_income_id = f.id', 'left')
->where($where)
->order($order_)
->limit($pageSize)
->page($pageNo)
->column($fields);
return $data;
}
/**
* @param $where
* @return int|string
*/
public function getCommissionBargainListTotal($where)
{
return $this->alias('a')
->join('o_bargain b', 'a.bargain_id = b.id', 'left')
->join('o_order c', 'b.order_id = c.id', 'left')
->join('g_houses d', 'c.house_id = d.id', 'left')
->join('a_agents e', 'b.agent_id = e.id', 'left')
->join('o_real_income f', 'a.real_income_id = f.id', 'left')
->where($where)
->count();
}
/**
* 增加和编辑实收佣金
*
* @param $data
* @return array|false
* @throws \Exception
*/
public function addCommission($data)
{
/* $insert_data['id'] = $data['id'];
$insert_data['bargain_id'] = $data['bargain_id']; //成交报告id
$insert_data['practical_fee'] = $data['practical_fee']; //实收佣金
$insert_data['cash'] = $data['cash']; //现金奖
$insert_data['service_charge'] = $data['service_charge']; //手续费
$insert_data['charity_fund'] = $data['charity_fund']; //慈善基金
$insert_data['real_fee'] = $data['real_fee']; //实分佣金
$insert_data['operation_id'] = $agent_id; //操作人id
$insert_data['should_commission'] = $data['should_commission']; //应分佣金
$insert_data['scale'] = $data['scale']; //分佣比例
$insert_data['role'] = $data['role']; //分佣方 1盘方 2客方 3 反签 4独家 5合作方
$insert_data['agent_id'] = $data['agent_id']; //分佣方经纪人
//确认分佣加时间 否则 只是保存分佣数据
if ($data['confirm_date']) {
$insert_data['confirm_date'] = $data['confirm_date'];
$insert_data['confirm_status'] = 1;
}
if (empty($insert_data['id'])) {
return $this->insert($insert_data);
} else {
return $this->update($insert_data);
}*/
return $this->saveAll($data);
}
/**
* 获取我的交易的分佣明细
*
* @param $field
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getCommissionListByBargainId($field, $params)
{
$params["a.is_del"] = 0;
$result = $this->field($field)
->alias("a")
->join("a_agents b", "a.agent_id=b.id", "left")
->join("o_bargain c", "a.bargain_id=c.id or a.bargain_id = c.father_id", "left")
->where($params)
->order("a.create_time desc")
->select();
//echo $this->getLastSql();
return $result;
}
/**
*获取最后一次分佣比例用到新增税费开票
*
* @param int $bargain_id
* @return mixed
* @throws \think\db\exception\BindParamException
* @throws \think\exception\PDOException
*/
public function getBragainScale(int $bargain_id)
{
$sql = 'SELECT a.bargain_id,a.scale,b.scale_fee,a.agent_id,a.role,substring_index(group_concat(a.id ORDER BY a.id DESC),",",1) AS id
FROM o_partial_commission a LEFT JOIN o_bargain b on a.bargain_id=b.id WHERE a.is_del = 0 and (a.bargain_id = ' . $bargain_id . '
and b.id= ' . $bargain_id . ' OR b.father_id=' . $bargain_id . ') GROUP BY role';
return $this->query($sql);
}
/**
* @param int $pageNo
* @param int $pageSize
* @param string $field
* @param string $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getCommissionTotalList($pageNo = 1, $pageSize = 15, $field = '', $params = '')
{
return $this->alias('a')
->field($field)
->join('o_real_income b', 'a.real_income_id = b.id', 'left')
->join('a_agents d', 'a.agent_id = d.id', 'left')
->join('o_bargain e', 'a.bargain_id = e.id', 'left')
->where($params)
->limit($pageSize)
->page($pageNo)
->group('a.agent_id')
->select();
}
public function getSumMoney($field, $where) {
return $this->alias('a')
->field($field)
->join('o_bargain b', 'a.bargain_id = b.id', 'left')
->join('o_real_income c', ' a.real_income_id = c.id', 'left')
->where($where)
->find();
}
/**
* @param $field
* @param $where
* @return float|int
*/
public function getCommissionTotalInfo($field, $where) {
return $this->alias('a')
->field('distinct a.id')
->join('o_real_income b', 'a.real_income_id = b.id', 'left')
->join('a_agents d', 'a.agent_id = d.id', 'left')
->join('o_bargain e', 'a.bargain_id = e.id', 'left')
->where($where)
->sum($field);
}
/**
* 分佣提成汇总表
*
* @param int $pageNo
* @param int $pageSize
* @param string $order_
* @param string $field
* @param string $params
* @param $operation_start_data
* @param $operation_end_data
* @return mixed
*/
public function getCommissionTotalListV2($pageNo = 1, $pageSize = 15, $order_ = 'a.id desc', $field = '', $params = '', $operation_start_data, $operation_end_data)
{
try {
$data = $this->alias('a')
->field($field)
->join('a_agents b', 'a.agent_id = b.id', 'left')
->join('o_bargain c', 'a.bargain_id = c.id', 'left')
->join('o_real_income d', 'a.real_income_id = d.id', 'left')
->join('o_taxes f', 'a.bargain_id = f.bargain_id', 'left')
->where($params)
->order($order_)
->limit($pageSize)
->page($pageNo)
->group('b.id')
->select();
$m_agent = new AAgents();
$m_tax = new OTaxes();
foreach ($data as $k => $v) {
if (isset($v['agent_id'])) {
$district_store = $m_agent->getStoreDistrict('store_name,district_name', [ 'a.id' => $v['agent_id'] ]);
$data[$k]['district_store'] = $district_store['district_name'] . '-' . $district_store['store_name'];
// //去除多次应分佣金
// $should_commission = $this->where('confirm_date', 'between time', [ $operation_start_data, $operation_end_data ])
// ->where('agent_id', $v['agent_id'])
// ->where('confirm_status', 1)
// ->where('is_del', 0)
// ->group('bargain_id')
// ->column('should_commission');
//
// $data[$k]['should_commission'] = 0;
// foreach ($should_commission as $kk => $vv) {
// $data[$k]['should_commission'] += $vv;
// }
}
}
$result['status'] = 'successful';
$result['data'] = $data;
} catch (\Exception $e) {
$result['status'] = 'fail';
$result['msg'] = $e->getMessage();
}
return $result;
}
public function getCommissionTotalField($filed, $params) {
return $this->alias('a')
->join('a_agents b', 'a.agent_id = b.id', 'left')
->join('o_bargain c', 'a.bargain_id = c.id', 'left')
->join('o_real_income d', 'a.real_income_id = d.id', 'left')
->join('o_taxes f', 'a.bargain_id = f.bargain_id', 'left')
->where($params)
->group('b.id')
->sum($filed);
}
/**
* @param $params
* @return int|string
*/
/**
* @param $params
* @return mixed
* @throws \think\db\exception\BindParamException
* @throws \think\exception\PDOException
*/
public function getCommissionTotalListTotal($params)
{
return $this->alias('a')
->join('o_real_income b', 'a.real_income_id = b.id', 'left')
->join('o_taxes c', 'a.agent_id = c.agent_id', 'left')
->join('a_agents d', 'a.agent_id = d.id', 'left')
->join('o_bargain e', 'a.bargain_id = e.id', 'left')
->where($params)
->group('a.agent_id')
->count();
}
/**
* @param $params
* @return int|string
*/
public function getCommissionTotalListTotalV2($params)
{
return $this->alias('a')
->join('a_agents b', 'a.agent_id = b.id', 'left')
->join('o_bargain c', 'a.bargain_id = c.id', 'left')
->join('o_real_income d', 'a.real_income_id = d.id', 'left')
->join('o_taxes f', 'a.bargain_id = f.bargain_id', 'left')
->where($params)
->group('a.agent_id')
->count();
}
/**
* 检查是否有未结单分佣
*
* @param $bargain_id
* @return int 0 无 1 有
*/
public function checkConfirmStatus($bargain_id) {
$result = 0;
try {
$data = $this->field('confirm_status')
->alias('a')
->join('o_bargain b', 'a.bargain_id = b.id', 'left')
->where('EXP', 'a.id ='.$bargain_id . ' or b.father_id = '. $bargain_id)
->where('b.status', '<>', 30)
->where('a.is_del', 0)
->select();
if (empty($data[0]['confirm_status'])) {
$result = 1;
} else {
foreach ($data as $k=>$v) {
if ($v['confirm_status'] == 0) {
$result = 1;
break;
}
}
}
} catch (Exception $e) {
$result = 0;
}
return $result;
}
/**
* @param $field
* @param $where
* @return array|false|\PDOStatement|string|\think\Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getPartialDetail($field, $where) {
return $this->field($field)
->where($where)
->find();
}
/**
* 查询实收数据
*/
public function getPracticalFee($bargain_id)
{
$params['bargain_id'] = $bargain_id;
$field ='practical_fee';
$result = $this->field($field)
->where($params)
->select();
//dump($this->getLastSql());
return $result;
}
/**
* @param $data
* @param $where
* @return OPartialCommission
*/
public function updateData($data, $where)
{
return $this->where($where)->update($data);
}
/**
* @param $field
* @param $where
* @return mixed
*/
public function getFieldValue($field, $where) {
return $this->where($where)->value($field);
}
/**
* @param $field
* @param $where
* @return array|false|\PDOStatement|string|\think\Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function sumCommission($field, $where)
{
$where['a.is_del'] = 0;
$where['b.is_del'] = 0;
return $partial_commission = $this->field($field)
->alias('a')
->join('o_real_income b', 'a.real_income_id = b.id', 'left')
->where($where)
->find();
}
/**
* @param $fields
* @param $where
* @param string $group
* @return int
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function sumFieldsGroup($fields, $where, $group = 'bargain_id') {
$where['is_del'] = $num = 0;
$data = $this->field($fields)
->where($where)
->group($group)
->select();
foreach ($data as $k=>$v) {
if (!empty($v[$fields])) {
$num += $v[$fields];
}
}
return $num;
}
/**
* @param string $field
* @param array $where
* @param string $order
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getPartialList(string $field, array $where, $order = 'id asc') {
return $this->field($field)
->where($where)
->order($order)
->select();
}
/**
* 计算实收
* @param $params
* @return false|\PDOStatement|string|\think\Collection
*/
public function getReceived($params)
{
$where_ = [];
$field = "sum(a.practical_fee) as num";
if (isset($params["agent_id"])) {
$where_["a.agent_id"] = $params["agent_id"];
}
if (isset($params["create_time"])) {
$where_["b.income_time "] = $params["create_time"];
}
$where_["a.is_del"] = 0;
$where_["a.confirm_status"] = 1;
// $where_["a.status"] = array( "in", '10,11,13');
$date = $this
->field($field)
->alias("a")
->join("o_real_income b", "a.real_income_id = b.id", "left")
->where($where_)
->select();
return $date;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: fuju
* Date: 2018/5/23
* Time: 17:46
*/
namespace app\model;
class OfficeORealIncome extends BaseModel
{
/**
* 增加实收佣金
*
* @param $insert_data
* @return array|false
* @throws \Exception
*/
public function addRealIncome($insert_data) {
return $this->saveAll($insert_data);
}
/**
* @param int $bargain_id
* @param string $field
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getBargainTaxes(int $bargain_id, $field = 'id as fee_id,money,income_time') {
return $this->field($field)
->where('bargain_id', $bargain_id)
->where('is_del', 0)
->select();
}
/**
* @param int $bargain_id
* @param string $field
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getBargainIncome(int $bargain_id, $field = 'id as fee_id,money,income_time') {
return $this->field($field)
->where('bargain_id', $bargain_id)
->where('is_del', 0)
->find();
}
/**
* @param int $bargain_id
* @param string $field
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getIncome($where, $field = 'id as fee_id,money,income_time') {
$where['is_del'] = 0;
return $this->field($field)
->where($where)
->find();
}
/**
* @param int $field
* @param array $where
* @return array
*/
public function getBargainTaxesColumn($field, array $where) {
return $this->field($field)
->where($where)
->column($field);
}
/**
* @param string $field
* @param $where
* @return mixed
*/
public function getRealIncomeBargain($field = 'id as fee_id,money,income_time', $where) {
try {
$where['is_del'] = 0;
$result['data'] = $this->field($field)
->where($where)
->select();
$result['status'] = 'successful';
} catch (\Exception $e) {
$result['status'] = 'fail';
$result['msg'] = $e->getMessage();
}
return $result;
}
/**
* @param $field
* @param $where
* @return float|int
*/
public function sumField($field, $where) {
return $this->where($where)
->sum($field);
}
/**
* @param string $field
* @param string $params
* @return float|int
*/
public function getIncomeListSum($field = '', $params = '')
{
return $this->alias('e')
->join('office_o_report b', 'a.report_id = b.id', 'left')
->join('office_o_order c', 'a.order_id = c.id', 'left')
->join('office_g_room d', 'c.house_id = d.id', 'left')
->join('office_o_partial_commission e', 'a.id = e.bargain_id', 'left')
->join('office_g_building f', 'd.building_id=f.id','left')
->where($params)
->sum($field);
}
/**
* @param $field
* @param $where
* @return mixed
*/
public function getFieldValue($field, $where) {
return $this->where($where)->value($field);
}
}
\ No newline at end of file
......@@ -1071,6 +1071,11 @@ Route::group('office_index', [
'getDistance' => ['index/OfficeManage/getDistance', ['method' => 'GET']], //获取两个经纬度距离
'getHouseAddress' => ['index/OfficeRoom/checkRepetition', ['method' => 'get']], //搜索楼号/栋/座+楼层+房号
'marchInList' => ['index/officeMarchIn/marchInList', ['method' => 'POST|GET']], //进场记录列表 朱伟 2018-06-13
'reportListOne/:check_status' => ['index/OfficeBargain/reportList', ['method' => 'get'], ['check_status' => 1]], //财务 成交报告-未结单-第一级审核
'reportListTwo/:check_status' => ['index/OfficeBargain/reportList', ['method' => 'get'], ['check_status' => 2]], //财务 成交报告-未结单-第二级审核
'reportListThree/:check_status' => ['index/OfficeBargain/reportList', ['method' => 'get'], ['check_status' => 3]], //财务 成交报告-未结单-第三级审核
'reportListStatement/:check_status' => ['index/OfficeBargain/reportList', ['method' => 'get'], ['check_status' => 4]], //财务 成交报告-已结单
'reportListAll/:check_status' => ['index/OfficeBargain/reportList', ['method' => 'get'], ['check_status' => 10]], //财务 成交报告-全部
]);
Route::group('office_api', [
......
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