Commit a8d792a4 authored by hujun's avatar hujun

经纪人转勤

parent 7ce32b43
......@@ -15,6 +15,10 @@ use app\index\validate\AAgentValidate;
use app\model\AAgents;
use app\model\ABindingDevice;
use app\model\ADistrict;
use app\model\AOperatingRecords;
use app\model\GHousesToAgents;
use app\model\Users;
use think\Request;
class BrokerService
{
......@@ -34,6 +38,7 @@ class BrokerService
*/
public function saveAgentData(array $data, int $operation_id)
{
$change_old_id = 0;
$result['status'] = 'fail';
$validate = new AAgentValidate();
$m_district = new ADistrict();
......@@ -60,6 +65,19 @@ class BrokerService
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 = '新增成功';
$data['status'] = 0;
$data['level'] = 10;
......@@ -87,6 +105,47 @@ class BrokerService
$result['status'] = 'successful';
$result['data'] = ['id' => $id];
$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 {
$result['msg'] = '新增或编辑失败';
}
......
<?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
* @param int $is_del
* @return array
*/
public function getAgentHouseOne($field, $type, $houses_id, $is_del = 0) {
$where['is_del'] = $is_del;
$where['type'] = $type;
$where['houses_id'] = $houses_id;
public function getAgentHouseOne($field, $where) {
return $this->where($where)
->column($field);
}
......
......@@ -55,6 +55,17 @@ class Users extends Model
return $data;
}
/**
* @param $param
* @param $fields
* @return array
*/
public function getUserByWhereColumn($param, $fields)
{
return $this->where($param)
->Column($fields);
}
/**
* 查询好友邀请记录-后期加分页
* @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