Commit 3de68c80 authored by hujun's avatar hujun

楼盘与经纪人关系编辑

parent dc3e66dc
...@@ -245,8 +245,11 @@ class GHouses extends BaseModel ...@@ -245,8 +245,11 @@ class GHouses extends BaseModel
/***保存图片 hujun 2018.1.19 end***/ /***保存图片 hujun 2018.1.19 end***/
$agents = new GHousesToAgents(); $agents = new GHousesToAgents();
//权限人
$agents->addAgents($params['agent_data'], $house_id,1); $agents->addAgents($params['agent_data'], $house_id,1);
//盘方
$agents->addAgents($params['agent_dish'], $house_id,2); $agents->addAgents($params['agent_dish'], $house_id,2);
//独家方
$agents->addAgents($params['exclusive_ids'], $house_id,3); $agents->addAgents($params['exclusive_ids'], $house_id,3);
return $house_id; return $house_id;
} }
......
...@@ -25,28 +25,48 @@ class GHousesToAgents extends BaseModel ...@@ -25,28 +25,48 @@ class GHousesToAgents extends BaseModel
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function addAgents($agents_id, $houses_id, $type){ public function addAgents($agents_id, $houses_id, $type){
$agent_arr = array(); $agent_arr = array();
$date = date('Y-m-d H:i:s');
$agents_id = array_unique(explode(',',$agents_id));
$agents_id = array_unique(explode(',',$agents_id)); $where['type'] = $type;
$where['houses_id'] = $houses_id;
$where['is_del'] = 0;
//为空全部伪删除
if (empty($agents_id[0])) {
$res = $this->where($where)->setField('is_del',1);
} else {
$houses_data = $this->where($where)->select();
$key = 0;
foreach ($houses_data as $k=>$v) {
if (!in_array($v['agents_id'], $agents_id) && $type == $v['type']) {
$agent_arr[$key]['id'] = $v['id'];
$agent_arr[$key]['is_del'] = 1;
$agent_arr[$key]['update_time'] = $date;
$key++;
}
}
foreach ($agents_id as $k=>$v) { foreach ($agents_id as $k=>$v) {
$check = $this->where([ $check = $this->where([
'houses_id' => $houses_id, 'houses_id' => $houses_id,
'agents_id' => $v, 'agents_id' => $v,
'is_del' => 0 , 'is_del' => 0 ,
'type' => $type 'type' => $type
])->find(); ])->find();
if ($check) { if ($check) {
continue; continue;
}
$agent_arr[$key]['agents_id'] = $v;
$agent_arr[$key]['houses_id'] = $houses_id;
$agent_arr[$key]['type'] = $type;
$agent_arr[$key]['create_time'] = $this->date;
$agent_arr[$key]['update_time'] = $this->date;
$key++;
} }
$agent_arr[$k]['agents_id'] = $v; $res = $this->saveAll($agent_arr);
$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; return $res;
} }
......
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