Commit fc2accb5 authored by clone's avatar clone

Merge branch 'test-hujun1.15' of https://gitee.com/zwyjjc/tl_estate into test-hujun1.15

parents dfd27c45 f1a16b2b
......@@ -12,6 +12,7 @@ namespace app\index\controller;
use app\index\extend\Basic;
use app\model\AAgents;
use app\model\Agents;
use app\model\GHousesToAgents;
class Broker extends Basic
{
......@@ -80,4 +81,92 @@ class Broker extends Basic
return $this->response($data['status'], $data['msg'], $data['data']);
}
/**
* 添加经纪人与楼盘关系
*
* @return \think\Response
* @throws \Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function AddHousesAgents() {
$data['status'] = 200;
$data['data'] = '';
$data['msg'] = '';
$params = $this->request->param();
if ($params['houses_id']) {
$hg = new GHousesToAgents();
switch ($params['type']) {
case 1:
$res = $hg->addAgents($params['phone'], $params['houses_id'], $params['type']);break;
case 2:
$res = $hg->addAgents($params['phone'], $params['houses_id'], $params['type']);break;
default :
$data['status'] = 101;
$data['msg'] = 'type is null';
}
if (!count($res) > 0) {
$data['status'] = 200;
$data['msg'] = 'Data already exists';
}
} else {
$data['status'] = 101;
$data['msg'] = 'houses_id is null';
}
return $this->response($data['status'], $data['msg'], $data['data']);
}
/**
* 解除经纪人和楼盘关系
*
* @return \think\Response
*/
public function delTohouses() {
$data['status'] = 200;
$data['data'] = '';
$data['msg'] = '';
$params = $this->request->param();
if ($params['id']) {
$hg = new GHousesToAgents();
$hg->del($params['id']);
} else {
$data['status'] = 101;
$data['msg'] = 'id is null';
}
return $this->response($data['status'], $data['msg'], $data['data']);
}
/**
* 获取经纪人和楼盘关系信息
*
* @return \think\Response
*/
public function getAgentsTohouses() {
$data['status'] = 200;
$data['data'] = '';
$data['msg'] = '';
$params = $this->request->param();
if ($params['houses_id']) {
$pageNo = empty($params['pageNo']) ? 1 : $params['pageNo'];
$pageSize = empty($params['pageSize']) ? 10 : $params['pageSize'];
$hg = new GHousesToAgents();
$fields = 'a.id,b.name,b.phone';
$where['a.is_del'] = ['=',0];
$where['b.status'] = ['=',0];
$where['a.type'] = $params['type'];
$where['a.houses_id'] = $params['houses_id'];
$data['data'] = $hg->getAgentsHousesList($pageNo, $pageSize, 'id DESC', $fields, $where);
} else {
$data['status'] = 101;
$data['msg'] = 'houses_id is null';
}
return $this->response($data['status'], $data['msg'], $data['data']);
}
}
\ No newline at end of file
<?php
namespace app\model;
use think\Model;
class GHousesToAgents extends BaseModel
{
protected $table = 'g_houses_to_agents';
protected $date = '';
public function __construct()
{
$this->date = date('Y-m-d H:i:s');
}
/**
* @param $data
* @param $houses_id
* @param $type 案场权限人:0,盘方:1,独家:2
* @return array|false|int
* @throws \Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function addAgents($data, $houses_id, $type){
$agent_arr = array();
$data = array_unique($data);
foreach ($data as $k=>$v) {
$arr = explode('-',$v);
if (count($arr) == 3) {
$check = $this->where([
'houses_id' => $houses_id,
'agents_id' => $arr['0'],
'is_del' => 0 ,
'type' => $type
])->find();
if ($check) {
continue;
}
$agent_arr[$k]['agents_id'] = $arr['0'];
$agent_arr[$k]['houses_id'] = $houses_id;
$agent_arr[$k]['type'] = $type;
$agent_arr[$k]['create_time'] = $this->date;
$agent_arr[$k]['update_time'] = $this->date;
}
}
$res = $this->saveAll($agent_arr);
return $res;
}
/**
* 解除经纪人和楼盘关系
*
* @param $id
* @return bool|false|int
*/
public function del($id) {
if ($id) {
$res = $this->save(['is_del' => 1],['id'=>$id]);
} else {
$res = false;
}
return $res;
}
public function getAgentsHousesList($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field = '', $params = '') {
return $this->field($field)
->alias('a')
->join('a_agents b', 'a.agents_id = b.id','left')
->where($params)
->order($order_)
->limit($pageSize)
->page($pageNo)
->select();
}
}
......@@ -67,6 +67,9 @@ Route::group('index', [
//查询经纪人
'getBroker' => ['index/broker/getBroker',['method'=>'get']],
'getBroker_new' => ['index/broker/getBroker_new',['method'=>'get']],
'addHousesAgents' => ['index/broker/AddHousesAgents', ['method' => 'POST']], //新增楼盘与经纪人关系
'delTohouses' => ['index/broker/delTohouses', ['method' => 'POST']], //解除经纪人和楼盘关系
'getAgentsTohouses' => ['index/broker/getAgentsTohouses', ['method' => 'GET']], //获取经纪人和楼盘关系信息
//版本管理
'version' => ['index/version/index',['method'=>'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