Commit d8b07dd4 authored by hujun's avatar hujun

盘方编辑优化

parent 3860777b
......@@ -163,22 +163,6 @@ function tranTime($time_inpute)
return $str;
}
/**
* 删除数组中已经存在的值
*
* @param string $string
* @param array $array_str
* @return array
*/
function del_array_string($string = '', $array_str = []) {
foreach ($array_str as $k=>$v) {
if ($v == $string) {
unset($array_str[$k]);
}
}
return $array_str;
}
/**
* 独立记录日志文件
* @param $content
......
......@@ -172,7 +172,7 @@ class Broker extends Basic
$data['data'] = '';
$data['msg'] = '';
if ($this->params['houses_id']) {
if ($this->params['houses_id'] && $this->params['agents_id'] && $this->params['type']) {
$hg = new GHousesToAgents();
switch ($this->params['type']) {
case 1:
......
......@@ -67,7 +67,7 @@ class Houses extends Basic
$sublet_data['agents_id'] = $this->userId;
$m_sublet->editData($sublet_data, $this->params['sublet_id']);
}
$return = $this->response($result['code'], $result['msg'], [ 'id'=>$house_data['house_id'] ]);
$return = $this->response($result['code'], $result['msg'], [ 'id'=>$house_data['data']['house_id'] ]);
} else {
$return = $this->response(101, $house_data['msg']);
}
......@@ -535,34 +535,11 @@ class Houses extends Basic
*/
public function editExclusive()
{
if ($this->params['houses_id']) {
$this->data = $this->house->exclusive($this->params, $this->params['houses_id'], $this->userId, $this->siteId);
} else {
$this->code = 101;
$this->msg = 'houses_id is null';
}
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
*/
public function addExclusive()
{
if ($this->params['houses_id']) {
$this->data = $this->house->exclusive($this->params, $this->params['houses_id'], $this->userId);
} else {
$this->code = 101;
$this->msg = 'houses_id is null';
if (empty($this->params['house_id']) || empty($this->params['exclusive_id'])) {
return $this->response(101, '参数错误');
}
$this->data = $this->house->exclusive($this->params, $this->params['houses_id'], $this->userId, $this->siteId);
return $this->response($this->code, $this->msg, $this->data);
}
......
......@@ -188,8 +188,7 @@ class HouseService
//案场权限人
if (isset($data['agent_data'])) {
$result_agent_data = $this->releaseRelationship($data['agent_data'], $house_id, 1, $agent_id, $data['internal_title'], $site_id);
$result_agent_data = $this->releaseRelationshipV2($data['agent_data'], $house_id, 1, $agent_id, $data['internal_title'], $site_id);
if ($result_agent_data['status'] == 'fail') {
$result['status'] = 'fail';
$result['msg'] = '新增或编辑案场权限人失败,' . $result_agent_data['msg'];
......@@ -199,7 +198,7 @@ class HouseService
//盘方
if (isset($data['agent_dish'])) {
$result_agent_dish = $this->releaseRelationship($data['agent_dish'], $house_id, 2, $agent_id, $data['internal_title'], $site_id);
$result_agent_dish = $this->releaseRelationshipV2($data['agent_dish'], $house_id, 2, $agent_id, $data['internal_title'], $site_id);
if ($result_agent_dish['status'] == 'fail') {
$result['status'] = 'fail';
$result['msg'] = '新增或编辑盘方失败,' . $result_agent_dish['msg'];
......@@ -209,7 +208,7 @@ class HouseService
//独家方
if (isset($data['exclusive_ids'])) {
$result_exclusive_ids = $this->releaseRelationship($data['exclusive_ids'], $house_id, 3, $agent_id, $data['internal_title'], $site_id);
$result_exclusive_ids = $this->releaseRelationshipV2($data['exclusive_ids'], $house_id, 3, $agent_id, $data['internal_title'], $site_id);
if ($result_exclusive_ids['status'] == 'fail') {
$result['status'] = 'fail';
$result['msg'] = '新增或编辑独家方失败,' . $result_exclusive_ids['msg'];
......@@ -380,6 +379,101 @@ class HouseService
return $result;
}
/**
* 处理楼盘与经纪人关系
*
* @param $agent_id_string
* @param $house_id
* @param $type
* @param $operation_id
* @param $house_title
* @param $site_id
* @return mixed
*/
public function releaseRelationshipV2($agent_id_string, $house_id, $type, $operation_id, $house_title, $site_id)
{
if (empty($agent_id_string)) {
$result['status'] = 'fail';
$result['msg'] = '经纪人id字符串为空';
return $result;
}
try {
$records = new GOperatingRecords();
$sum = new ResultsSummaryNewTask();
$count = 0;
$save_data = $del_agent_name = $del_agent_id = [];
$agent_id_arr = array_unique(explode(',', $agent_id_string));
$agent_house_where['a.is_del'] = 0;
$agent_house_where['a.houses_id'] = $house_id;
$agent_house_where['a.type'] = $type;
$agent_data_old = $this->agent_house->getAgentsByHouseId('a.id,a.agents_id,a.houses_id,b.name', $agent_house_where);
foreach ($agent_data_old as $v) {
if (in_array($v['agents_id'], $agent_id_arr)) {
$key = array_search($v['agents_id'], $agent_id_arr);
if ($key !== false) {
unset($agent_id_arr[$key]);
}
} else {
$save_data[$count]['id'] = $v['id'];
$save_data[$count]['is_del'] = 1;
$count++;
$del_agent_name[] = $v['name'];
$del_agent_id[] = $v['agents_id'];
}
}
foreach ($agent_id_arr as $val) {
$save_data[$count]['agents_id'] = $val;
$save_data[$count]['houses_id'] = $house_id;
$save_data[$count]['type'] = $type;
$count++;
}
$this->agent_house->updateUserAll($save_data);
if ($type == 2) {
//记录
$remark = '';
if ($del_agent_name) {
$remark .= '删除盘方:' . implode(',', $del_agent_name) . ',';
}
if ($agent_id_arr) {
$agent_name = $this->agent->getAgentsByWhereColumn(['id' => ['in', $agent_id_arr]], 'name');
$remark .= '新增盘方:' . implode(',', $agent_name);
//推送记录
$operation_name = $this->agent->getAgentsById($operation_id, 'name');
$data['message'] = '你的【' . $house_title . '】商铺,盘方被【' . $operation_name . '】修改为:' . implode(',', $agent_name);
$this->push->record(3, $house_id, $del_agent_id, $operation_id, $data);
$date = date('Y-m-d');
foreach ($agent_id_arr as $v3) {
$agent_data = $this->agent->verifyUser('id,store_id,district_id,name', '', ['id' => $v3]); //新增人信息
$sum->updateTotalByAgentId($agent_data['id'], $agent_data['store_id'], $agent_data['district_id'], $date, $site_id);
}
foreach ($del_agent_id as $v4) {
$agent_data = $this->agent->verifyUser('id,store_id,district_id,name', '', ['id' => $v4]); //被删除人信息
$sum->updateTotalByAgentId($agent_data['id'], $agent_data['store_id'], $agent_data['district_id'], $date, $site_id);
}
}
if (!empty($remark)) {
$records->record($operation_id, 2, $remark, $house_id);
}
}
$result['status'] = 'successful';
}catch (\Exception $e) {
$result['status'] = 'fail';
$result['msg'] = '经纪人id字符串为空';
}
return $result;
}
/**
* 商铺修改日志
*s
......
......@@ -791,7 +791,7 @@ class GHouses extends BaseModel
}
}
return $house_id;
return (int)$house_id;
}
/**
......
......@@ -375,13 +375,13 @@ class GHousesToAgents extends BaseModel
*/
public function updateUserAll($data)
{
try {
// try {
$data['data'] = $this->saveAll($data);
$data['status'] = 'successful';
} catch (\Exception $e) {
$data['status'] = 'fail';
$data['msg'] = $e->getMessage();
}
// } catch (\Exception $e) {
// $data['status'] = 'fail';
// $data['msg'] = $e->getMessage();
// }
return $data;
}
......
......@@ -183,7 +183,7 @@ Route::group('index', [
'getHouseList' => ['index/houses/getHouseList', ['method' => 'get']], //楼盘列表
'carefullyChosen' => ['index/houses/carefullyChosen', ['method' => 'post']], //设置精选楼盘
'editExclusive' => ['index/houses/editExclusive', ['method' => 'post']], //添加和编辑楼盘独家
'addExclusive' => ['index/houses/addExclusive', ['method' => 'post']], //添加楼盘独家
'addExclusive' => ['index/houses/editExclusive', ['method' => 'post']], //添加楼盘独家
'getExclusive' => ['index/houses/getExclusive', ['method' => 'get']], //获取楼盘独家
'getRecords' => ['index/houses/getRecords', ['method' => 'get']], //操作记录
'delHouseFile' => ['index/houses/delHouseFile', ['method' => 'post']], //操作记录
......
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