Commit a8d792a4 authored by hujun's avatar hujun

经纪人转勤

parent 7ce32b43
...@@ -15,6 +15,10 @@ use app\index\validate\AAgentValidate; ...@@ -15,6 +15,10 @@ use app\index\validate\AAgentValidate;
use app\model\AAgents; use app\model\AAgents;
use app\model\ABindingDevice; use app\model\ABindingDevice;
use app\model\ADistrict; use app\model\ADistrict;
use app\model\AOperatingRecords;
use app\model\GHousesToAgents;
use app\model\Users;
use think\Request;
class BrokerService class BrokerService
{ {
...@@ -34,6 +38,7 @@ class BrokerService ...@@ -34,6 +38,7 @@ class BrokerService
*/ */
public function saveAgentData(array $data, int $operation_id) public function saveAgentData(array $data, int $operation_id)
{ {
$change_old_id = 0;
$result['status'] = 'fail'; $result['status'] = 'fail';
$validate = new AAgentValidate(); $validate = new AAgentValidate();
$m_district = new ADistrict(); $m_district = new ADistrict();
...@@ -60,6 +65,19 @@ class BrokerService ...@@ -60,6 +65,19 @@ class BrokerService
return $result; return $result;
} }
$agent_old = $this->m_agent->getAgentById('id', ['phone' => $data['phone'], 'status' => 0]);
if (empty($data['confirm_old'])) {
if (!empty($agent_old)) {
$result['msg'] = '转勤';
return $result;
}
} else {
$num = $this->m_agent->updateData($agent_old['id'], ['status' => 3]); //更新原始账号状态
if ($num > 0) {
$change_old_id = $agent_old['id'];
}
}
$msg = '新增成功'; $msg = '新增成功';
$data['status'] = 0; $data['status'] = 0;
$data['level'] = 10; $data['level'] = 10;
...@@ -87,6 +105,47 @@ class BrokerService ...@@ -87,6 +105,47 @@ class BrokerService
$result['status'] = 'successful'; $result['status'] = 'successful';
$result['data'] = ['id' => $id]; $result['data'] = ['id' => $id];
$result['msg'] = $msg; $result['msg'] = $msg;
if ($change_old_id) {
$m_user = new Users();
$update_user = $update_house = [];
$user_id_arr = $m_user->getUserByWhereColumn(['agent_id' => $change_old_id], 'id');
foreach ($user_id_arr as $k=>$v) {
$update_user[$k]['id'] = $v;
$update_user[$k]['agent_id'] = $id;
}
$record_data['user_id'] = empty($user_id_arr) ? "" : explode(',', $user_id_arr);
$m_house = new GHousesToAgents();
$house_where['is_del'] = 0;
$house_where['agents_id'] = $change_old_id;
$house_where['type'] = ['in', '2,3'];
$house_id_arr = $m_house->getAgentHouseOne('houses_id', $house_where);
foreach ($house_id_arr as $k=>$v) {
$update_house[$k]['houses_id'] = $v;
$update_house[$k]['agents_id'] = $id;
}
$house_id_arr = array_unique($house_id_arr);
$record_data['house_id'] = empty($user_id_arr) ? "" : explode(',', $house_id_arr);
$m_records = new AOperatingRecords();
$record_data['remark'] = '经纪人转勤操作';
$record_data['type'] = 0;
$record_data['operation_id'] = $operation_id;
$record_data['agent_id'] = $id;
$m_records->insertData($data);
if (!empty($update_user)) {
$m_user->updateUserAll($update_user);
}
if (!empty($update_house)) {
$m_house->updateUserAll($update_house);
}
}
} else { } else {
$result['msg'] = '新增或编辑失败'; $result['msg'] = '新增或编辑失败';
} }
...@@ -123,7 +182,7 @@ class BrokerService ...@@ -123,7 +182,7 @@ class BrokerService
//同时修改设备绑定表 //同时修改设备绑定表
try { try {
$m_agent_device = new ABindingDevice(); $m_agent_device = new ABindingDevice();
$m_agent_device->updateDate(['is_forbidden' => $is_forbidden], ['agent_id' => $data['id']]); $m_agent_device->updateDate(['is_forbidden' => $is_forbidden], ['agent_id' => $data['id']]);
} catch (\Exception $e) { } catch (\Exception $e) {
$result['status'] = 'fail'; $result['status'] = 'fail';
$result['msg'] = '设备解绑失败'; $result['msg'] = '设备解绑失败';
...@@ -132,7 +191,7 @@ class BrokerService ...@@ -132,7 +191,7 @@ class BrokerService
if ($data['status'] != 0) { if ($data['status'] != 0) {
$where['a.id'] = $data['id']; $where['a.id'] = $data['id'];
$where['b.status'] = 1; $where['b.status'] = 1;
$agent_phone = $this->m_agent->getAgentCallPhone('b.phone_a,b.phone_b,c.phone_x', $where); $agent_phone = $this->m_agent->getAgentCallPhone('b.phone_a,b.phone_b,c.phone_x', $where);
...@@ -145,7 +204,7 @@ class BrokerService ...@@ -145,7 +204,7 @@ class BrokerService
$push = new PushMessageService(); $push = new PushMessageService();
$message_data['message'] = '你的账号被冻结。'; $message_data['message'] = '你的账号被冻结。';
$message_data['agent_id'] = $data['id']; $message_data['agent_id'] = $data['id'];
$push->record(4, 0, 0, $operation_id, $message_data); $push->record(4, 0, 0, $operation_id, $message_data);
} }
......
<?php
/**
* Created by PhpStorm.
* User: 43897
* Date: 2018/10/18
* Time: 16:16
*/
namespace app\model;
use think\Db;
class AOperatingRecords extends BaseModel
{
// 设置当前模型对应的完整数据表名称
protected $table = 'a_operating_records';
protected $db;
public function __construct()
{
$this->db = Db::table($this->table);
}
/**
* @param $data
* @return mixed
*/
public function insertData($data) {
$save_data['agent_id'] = $data['agent_id'];
$save_data['remark'] = $data['remark'];
$save_data['house_id'] = $data['house_id'];
$save_data['user_id'] = $data['user_id'];
$save_data['type'] = $data['type'];
$save_data['operation_id'] = $data['operation_id'];
return $this->inset($save_data);
}
}
\ No newline at end of file
...@@ -423,10 +423,7 @@ class GHousesToAgents extends BaseModel ...@@ -423,10 +423,7 @@ class GHousesToAgents extends BaseModel
* @param int $is_del * @param int $is_del
* @return array * @return array
*/ */
public function getAgentHouseOne($field, $type, $houses_id, $is_del = 0) { public function getAgentHouseOne($field, $where) {
$where['is_del'] = $is_del;
$where['type'] = $type;
$where['houses_id'] = $houses_id;
return $this->where($where) return $this->where($where)
->column($field); ->column($field);
} }
......
...@@ -55,6 +55,17 @@ class Users extends Model ...@@ -55,6 +55,17 @@ class Users extends Model
return $data; return $data;
} }
/**
* @param $param
* @param $fields
* @return array
*/
public function getUserByWhereColumn($param, $fields)
{
return $this->where($param)
->Column($fields);
}
/** /**
* 查询好友邀请记录-后期加分页 * 查询好友邀请记录-后期加分页
* @param $param * @param $param
......
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