Commit bde568a4 authored by hujun's avatar hujun

根据是否进场判断是否使用原始经济人id

parent 1155b989
......@@ -16,7 +16,9 @@ use app\model\AAgents;
use app\model\ABindingDevice;
use app\model\ADistrict;
use app\model\AOperatingRecords;
use app\model\ASite;
use app\model\GHousesToAgents;
use app\model\OMarchInModel;
use app\model\Users;
use think\Request;
......@@ -42,6 +44,7 @@ class BrokerService
public function saveAgentData(array $data, int $operation_id)
{
$change_old_id = 0;
$is_new_id = 1;
$result['status'] = 'fail';
$validate = new AAgentValidate();
$m_district = new ADistrict();
......@@ -57,11 +60,11 @@ class BrokerService
$result['msg'] = $validate->getError();
return $result;
}
$field = 'id,name,phone,sex,img,status,inviter_id,admin_off,quit_time,password,site_id,district_id,store_id,auth_group_id,level';
if (empty($data['id'])) {
$where['phone'] = $data['phone'];
$where['site_id'] = $data['site_id'];
$agent_data = $this->m_agent->verifyUser('id,phone,password,site_id,district_id', '', $where);
$agent_data = $this->m_agent->verifyUser($field, '', $where);
if (!empty($agent_data['status']) && $agent_data['status'] == 3) {
$result['msg'] = '该用户已转勤';
......@@ -70,18 +73,19 @@ class BrokerService
$result['msg'] = '该用户已存在';
return $result;
}
$agent_old = $this->m_agent->getAgentById('id', ['phone' => $data['phone'], 'status' => 0]);
if (empty($data['confirm_old'])) {
if (!empty($agent_old[0]['id'])) {
$result['msg'] = '转勤';
return $result;
}
} else {
$result['msg'] = '操作失败';
$agent_old = $this->m_agent->getAgentById($field, ['phone' => $data['phone'], 'status' => 0]);
if (empty($data['confirm_old']) && !empty($agent_old[0]['id'])) {
$result['msg'] = '转勤';
return $result;
$num = $this->m_agent->updateData($agent_old[0]['id'], ['status' => 3]); //更新原始账号状态
if ($num > 0) {
$change_old_id = $agent_old[0]['id'];
} else {
$agent_num = count($agent_old);
if ($agent_num > 0) {
//根据是否带看过判断是否换id
$m_march_in = new OMarchInModel();
$march_data = $m_march_in->selectMarchInOne('a.id', ['a.reception_id'=>$agent_old['id'],'b.site_id'=>$data['site_id']]);
if ($march_data['id']) {
$is_new_id = 0;
}
}
}
......@@ -94,7 +98,7 @@ class BrokerService
}
} else {
$where['id'] = $data['id'];
$agent_data = $this->m_agent->verifyUser('id,phone,password,site_id,district_id', '', $where);
$agent_data = $this->m_agent->verifyUser($field, '', $where);
if (empty($agent_data)) {
$result['msg'] = '没有该用户';
......@@ -115,7 +119,30 @@ class BrokerService
}
}
$id = $this->m_agent->saveAgent($data);
if ($is_new_id) {
$id = $this->m_agent->saveAgent($data);
} else {
//将原来的id作为新的
$data['id'] = $agent_old[0]['id'];
$id = $this->m_agent->saveAgent($data);
//新增一条转勤状态
$new_agent['name'] = $agent_old[0]['name'];
$new_agent['phone'] = $agent_old[0]['phone'];
$new_agent['sex'] = $agent_old[0]['sex'];
$new_agent['img'] = $agent_old[0]['img'];
$new_agent['status'] = 3;
$new_agent['inviter_id'] = $agent_old[0]['inviter_id'];
$new_agent['admin_off'] = $agent_old[0]['admin_off'];
$new_agent['quit_time'] = $agent_old[0]['quit_time'];
$new_agent['password'] = $agent_old[0]['password'];
$new_agent['site_id'] = $agent_old[0]['site_id'];
$new_agent['district_id'] = $agent_old[0]['district_id'];
$new_agent['store_id'] = $agent_old[0]['store_id'];
$new_agent['auth_group_id'] = $agent_old[0]['auth_group_id'];
$new_agent['level'] = $agent_old[0]['level'];
$this->m_agent->saveAgent($new_agent);
}
if ($id > 0) {
$result['status'] = 'successful';
$result['data'] = ['id' => $id];
......
......@@ -413,4 +413,36 @@ class OMarchInModel extends Model
->group('a.reception_id ')
->find();
}
/**
* @param $filed
* @param $params
* @return array|false|\PDOStatement|string|Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectMarchInOne($filed, $params)
{
$where_ = [];
if (isset($params["id"])) {
$where_["a.id"] = $params["id"];
}
if (isset($params["reception_id"])) {
$where_["a.reception_id"] = $params["reception_id"];
}
if (isset($params["reception_name"])) {
$where_["a.reception_name"] = $params["reception_name"];
}
if (isset($params["site_id"])) {
$where_["b.site_id"] = $params["site_id"];
}
return $this->db_model
->alias('a')
->field($filed)
->join('a_agents b', 'a.reception_id = b.id', 'left')
->where($where_)
->find();
}
}
\ No newline at end of file
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