Commit 8d7b4b43 authored by hujun's avatar hujun

批量修改独家方

parent 8ccd4a14
......@@ -13,6 +13,7 @@ use app\api\controller\Sublet;
use app\index\extend\Basic;
use app\model\AAgents;
use app\model\GHouses;
use app\model\GHousesToAgents;
use app\model\SubletModel;
use think\Request;
......@@ -306,4 +307,42 @@ class Houses extends Basic
return $this->response($this->code, $this->msg, $this->data);
}
/**
* 批量修改独家方
*
* @return \think\Response
* @throws \Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
public function batchChangDish() {
if (empty($this->params['old_agents_id']) || empty($this->params['agents_id'])) {
return $this->response(101, '盘方信息错误');
}
$agent = new GHousesToAgents();
$agent->startTrans();
$agent->lock(true);
$where['type'] = 2;
$where['b.id'] = $this->params['old_agents_id'];
$agent_house = $agent->getHouseAgent('a.id', $where);
$agent_data_arr = [];
if (count($agent_house) > 0) {
$agent_data_arr = [];
foreach ($agent_house as $k=>$v) {
$agent_data_arr[$k]['id'] = $v['id'];
$agent_data_arr[$k]['agents_id'] = $this->params['agents_id'];
}
}
$total = $agent->updateUserAll($agent_data_arr);
$agent->commit();
return $this->response(200, '', ['total'=>count($total)]);
}
}
\ No newline at end of file
......@@ -236,4 +236,31 @@ class GHousesToAgents extends BaseModel
->where('type', $type)
->select();
}
/**
* 获取楼盘与经纪人关系
*
* @param string $field
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getHouseAgent(string $field = '', array $where = []) : array {
return $this->alias('a')
->field($field)
->join('a_agents b', 'a.agents_id=b.id', 'left')
->where($where)
->select();
}
/**
* @param $data
* @return array|false
* @throws \Exception
*/
public function updateUserAll($data) {
return $this->saveAll($data);
}
}
......@@ -98,6 +98,7 @@ Route::group('index', [
'addHousesAgentsExclusive' => ['index/broker/AddHousesAgents', ['method' => 'POST']], //新增楼盘与经纪人关系(独家)
'delTohouses' => ['index/broker/delTohouses', ['method' => 'POST']], //解除经纪人和楼盘关系
'getAgentsTohouses' => ['index/broker/getAgentsTohouses', ['method' => 'GET']], //获取经纪人和楼盘关系信息
'batchChangDish' => [ 'index/houses/batchChangDish', [ 'method' => 'post' ] ],//批量修改盘方
//版本管理
'version' => ['index/version/index',['method'=>'get']],
......@@ -209,6 +210,7 @@ Route::group('index', [
'shop_a_store' => [ 'index/agent/shop_a_store', [ 'method' => 'post|get' ] ],//经纪人
'getCollection' => [ 'index/Collection/getCollection', [ '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