Commit c9a6357c authored by hujun's avatar hujun

成交报告列表优化

parent df9fbd84
......@@ -16,6 +16,7 @@ use app\index\untils\ExportExcelUntil;
use app\model\AAgents;
use app\model\OBargainLogModel;
use app\model\OBargainModel;
use app\model\OMarchInModel;
use app\model\ORealIncome;
use app\model\OTaxes;
use app\model\OFinancialAudit;
......@@ -74,7 +75,7 @@ class Finance extends Basic
$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,b.user_phone,b.user_name,d.internal_title,
$fields = 'a.id,a.create_time,a.trade_type,d.internal_title,
d.internal_address,a.commission,a.practical_fee,a.scale_fee,a.order_no,
a.order_id,content,house_number,a.is_open,a.agent_id,a.submit_agent_name,
a.price,a.audit_level,';
......@@ -189,30 +190,45 @@ class Finance extends Basic
try {
if (!empty($this->params['district_id'])) {
$agent_where['a.district_id'] = $this->params['district_id'];
$agent_where['b.district_id'] = $this->params['district_id'];
}
if (!empty($this->params['store_id'])) {
$agent_where['a.store_id'] = $this->params['store_id'];
$agent_where['b.store_id'] = $this->params['store_id'];
}
if (!empty($this->params['agent_phone'])) {
$agent_where['a.phone'] = [ 'LIKE', '%' . $this->params['agent_phone'] . '%' ];
$agent_where['b.phone'] = [ 'LIKE', '%' . $this->params['agent_phone'] . '%' ];
}
if (!empty($this->params['agent_name'])) {
$agent_where['a.name'] = [ 'LIKE', '%' . $this->params['agent_name'] . '%' ];
$agent_where['b.name'] = [ 'LIKE', '%' . $this->params['agent_name'] . '%' ];
}
if (!empty($agent_where)) {
$m_agent = new AAgents();
$where_bargain_id = $m_agent->getAgentReportBargain('a.id,c.father_id', $agent_where);
if (!empty($this->params['create_time']) && empty($this->params['end_time'])) {
$agent_where['a.create_time'] = [ '> time', $this->params['create_time'] . ' 00:00:00' ];
}
if (empty($where_bargain_id)) {
return $this->response(200, '');
if (!empty($this->params['end_time']) && empty($this->params['create_time'])) {
$agent_where['a.create_time'] = [ '< time', $this->params['end_time'] . ' 23:59:59' ];
}
if (!empty($this->params['end_time']) && !empty($this->params['create_time'])) {
$agent_where['a.create_time'] = [ 'between time', [ $this->params['create_time'] . ' 00:00:00', $this->params['end_time'] . ' 23:59:59' ] ];
}
if (!empty($agent_where)) {
$m_agent = new OMarchInModel();
$agent_where['c.id'] = ['>', 0];
$march_bargain_id = $m_agent->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 ($where_bargain_id as $k => $v) {
foreach ($march_bargain_id['data'] as $k => $v) {
if ($v['father_id'] == 0) {
$where_id[] = $v['id'];
} else {
......@@ -225,8 +241,7 @@ class Finance extends Basic
//分佣方姓名
if (!empty($this->params['partial_id'])) {
$m_agent = new AAgents();
$where_bargain_id = $m_agent->agentBargainAll('b.id,b.father_id', [ 'a.id' => $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, '');
......
......@@ -1199,24 +1199,6 @@ class AAgents extends BaseModel
return $data;
}
/**
* @param $field
* @param $where
* @return array|false|\PDOStatement|string|\think\Collection
*/
public function agentBargainAll($field, $where) {
try {
$data = $this->alias('a')
->field($field)
->join('o_bargain b', 'a.id = b.agent_id', 'left')
->where($where)
->select();
} catch (\Exception $e) {
$data = [];
}
return $data;
}
/**
* 获取绑定号码
*
......@@ -1277,25 +1259,6 @@ class AAgents extends BaseModel
}
/**
* 带看(报备)经纪人
*
* @param $filed
* @param $where
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAgentReportBargain($filed, $where) {
return $this->alias('a')
->field($filed)
->join('o_report b', 'a.id = b.report_agent_id', 'left')
->join('o_bargain c', 'b.id = c.report_id', 'left')
->where($where)
->select();
}
/**
* @param $params
* @return int|string
......
......@@ -357,12 +357,11 @@ class OBargainModel extends Model
*/
public function getBargainList($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field = '', $params = '')
{
return $this->field($field)->alias('a')
->join('o_report b', 'a.report_id = b.id', 'left')
return $this->db_->field($field)->alias('a')
// ->join('o_report b', 'a.report_id = b.id', 'left')
->join('o_order c', 'a.order_id = c.id', 'left')
->join('g_houses d', 'c.house_id = d.id', 'left')
->join('o_partial_commission e', 'e.bargain_id = a.id', 'left')
->where($params)
->group('a.id')
->order($order_)
......@@ -378,7 +377,7 @@ class OBargainModel extends Model
*/
public function getBargainListSum($field = '', $params = '')
{
return $this->alias('a')
return $this->db_->alias('a')
->join('o_report b', 'a.report_id = b.id', 'left')
->join('o_order c', 'a.order_id = c.id', 'left')
->join('g_houses d', 'c.house_id = d.id', 'left')
......@@ -393,14 +392,14 @@ class OBargainModel extends Model
* @param array $params
* @return int
*/
public function getBargainTotal(array $params = []): int
public function getBargainTotal(array $params = [])
{
return $this->alias('a')
->join('o_report b', 'a.report_id = b.id', 'left')
return $this->db_->alias('a')
->join('o_order c', 'a.order_id = c.id', 'left')
->join('g_houses d', 'c.house_id = d.id', 'left')
->join('o_partial_commission e', 'e.bargain_id = a.id', 'left')
->where($params)
->group('a.id')
// ->group('a.id')
->count();
}
......@@ -1545,4 +1544,22 @@ class OBargainModel extends Model
->group('a.id')
->sum($field);
}
/**
* @param $field
* @param $where
* @return array|false|\PDOStatement|string|\think\Collection
*/
public function agentBargainAll($field, $where) {
try {
$data = $this->db_->alias('a')
->field($field)
->join('a_agents b', 'a.agent_id = b.id', 'left')
->where($where)
->select();
} catch (\Exception $e) {
$data = [];
}
return $data;
}
}
\ No newline at end of file
......@@ -445,4 +445,28 @@ class OMarchInModel extends Model
->where($where_)
->find();
}
/**
* 带看经纪人
*
* @param $field
* @param $where
* @return mixed
*/
public function getAgentMarchIn($field, $where) {
try {
$data['data'] = $this->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')
->where($where)
->select();
$data['status'] = 'successful';
} catch (\Exception $e) {
$data['status'] = 'fail';
$data['msg'] = $e->getMessage();
}
return $data;
}
}
\ No newline at end of file
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