320 lines
12 KiB
PHP
320 lines
12 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
require_once APPPATH . 'controllers/api/BaseController.php';
|
|
|
|
/**
|
|
* Notes:私域直播_用户管理
|
|
* Created on: 2022/9/19 17:15
|
|
* Created by: dengbw
|
|
*/
|
|
class Members extends BaseController
|
|
{
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('agent/admin/Market_sylive_user_model', 'mdSyliveUser');
|
|
$this->load->model('agent/admin/Market_sylive_organization_model', 'mdSyliveOrganization');
|
|
}
|
|
|
|
/**
|
|
* Notes:用户管理列表
|
|
* Created on: 2022/9/20 14:48
|
|
* Created by: dengbw
|
|
*/
|
|
public function page_get()
|
|
{
|
|
$page = $this->input_param('page');
|
|
$limit = $this->input_param('limit');
|
|
$uname = $this->input_param('uname');
|
|
$mobile = $this->input_param('mobile');
|
|
$sort = $this->input_param('sort');
|
|
$order = $this->input_param('order');
|
|
$topOrgId = intval($this->input_param('topOrgId'));
|
|
$keywords = $this->input_param('keywords');
|
|
!$page && $page = 1;
|
|
!$limit && $limit = 10;
|
|
$sort_order = 'userId desc';
|
|
if ($sort && $order) {
|
|
$sort_order = $sort . ' ' . $order;
|
|
}
|
|
$list = $re_org = [];
|
|
$roleAry = $this->mdSyliveUser->roleAry();
|
|
$where['status>='] = 0;
|
|
$topOrgId && $where['topOrgId'] = $topOrgId;
|
|
$re_org && $organizationType = $re_org['organizationType'];
|
|
if ($keywords) {
|
|
$where["(uname LIKE '%{$keywords}%' OR mobile LIKE '%{$keywords}%' OR nickname LIKE '%{$keywords}%')"] = null;
|
|
} else {
|
|
$uname && $where["uname LIKE '%{$uname}%'"] = null;
|
|
$mobile && $where["mobile LIKE '%{$mobile}%'"] = null;
|
|
}
|
|
$count = $this->mdSyliveUser->count($where);
|
|
if ($count) {
|
|
$res = $this->mdSyliveUser->select($where, $sort_order, $page, $limit);
|
|
$maJiaIds = $organizationIds = $map_maJia = $map_organization = [];
|
|
foreach ($res as $v) {
|
|
$v['maJiaId'] && !in_array($v['maJiaId'], $maJiaIds) && $maJiaIds[] = $v['maJiaId'];
|
|
$v['organizationId'] && !in_array($v['organizationId'], $organizationIds) && $organizationIds[] = $v['organizationId'];
|
|
$v['bizId'] && !in_array($v['bizId'], $organizationIds) && $organizationIds[] = $v['bizId'];
|
|
$v['topOrgId'] && !in_array($v['topOrgId'], $organizationIds) && $organizationIds[] = $v['topOrgId'];
|
|
}
|
|
if ($maJiaIds) {
|
|
$str_maJiaIds = implode(",", $maJiaIds);
|
|
$map_maJia = $this->mdSyliveUser->map('userId', 'uname,nickname,mobile', ["userId in({$str_maJiaIds})" => null]);
|
|
}
|
|
if ($organizationIds) {
|
|
$str_organizationIds = implode(",", $organizationIds);
|
|
$map_organization = $this->mdSyliveOrganization->map('organizationId', 'organizationName,organizationType'
|
|
, ["organizationId in({$str_organizationIds})" => null]);
|
|
}
|
|
foreach ($res as $v) {
|
|
$maJia = $maJiaId = $maJiaName = $maJiaShow = $organizationName = '';
|
|
$roleName = '客户';
|
|
$userId = intval($v['userId']);
|
|
$status = intval($v['status']);
|
|
$organizationId = $v['organizationId'] ? intval($v['organizationId']) : '';
|
|
$createTime = $v['createTime'] != '0000-00-00 00:00:00' ? $v['createTime'] : '';
|
|
if ($map_organization[$organizationId]) {
|
|
$organizationType = $map_organization[$organizationId]['organizationType'];
|
|
$roleName = $roleAry[$organizationType] ? $roleAry[$organizationType] : '客户';
|
|
}
|
|
$organizationName = $map_organization[$v['topOrgId']]['organizationName'];
|
|
if ($map_organization[$v['bizId']]['organizationName']) {
|
|
$organizationName = $organizationName ? $organizationName . '-' . $map_organization[$v['bizId']]['organizationName'] :
|
|
$map_organization[$v['bizId']]['organizationName'];
|
|
} elseif ($map_organization[$v['organizationId']]['organizationName']) {
|
|
$organizationName = $organizationName ? $organizationName . '-' . $map_organization[$v['organizationId']]['organizationName'] :
|
|
$map_organization[$v['organizationId']]['organizationName'];
|
|
}
|
|
if ($_SESSION['roleCode'] == 'admin') { //角色标识是admin才显示
|
|
$maJia = 1;
|
|
if ($v['maJiaId']) {
|
|
$maJiaId = intval($v['maJiaId']);
|
|
$maJiaName = $map_maJia[$maJiaId]['uname'] ? $map_maJia[$maJiaId]['uname'] : $map_maJia[$maJiaId]['nickname'];
|
|
$maJiaName = $maJiaName ? $maJiaName . '(' . $map_maJia[$maJiaId]['mobile'] . ')' : $map_maJia[$maJiaId]['mobile'];
|
|
}
|
|
$maJiaShow = $v['uname'] ? $v['uname'] : $v['nickname'];
|
|
$maJiaShow = $maJiaShow ? $maJiaShow . '(' . $v['mobile'] . ')' : $v['mobile'];
|
|
}
|
|
$list[] = ['userId' => $userId, 'maJia' => $maJia, 'maJiaId' => $maJiaId, 'maJiaName' => $maJiaName, 'maJiaShow' => $maJiaShow,
|
|
'uname' => $v['uname'], 'nickname' => $v['nickname'], 'mobile' => $v['mobile'], 'organizationName' => $organizationName,
|
|
'roleName' => $roleName, 'organizationId' => $organizationId, 'status' => $status, 'createTime' => $createTime];
|
|
}
|
|
}
|
|
$date = ['list' => $list, 'count' => $count];
|
|
$this->return_response_list($date);
|
|
}
|
|
|
|
|
|
/**
|
|
* Notes:添加用户
|
|
* Created on: 2022/9/21 16:46
|
|
* Created by: dengbw
|
|
*/
|
|
public function index_post()
|
|
{
|
|
$mobile = $this->input_param('mobile');
|
|
$organizationId = intval($this->input_param('organizationId'));
|
|
$uname = $this->input_param('uname');
|
|
if (!$mobile) {
|
|
$this->return_json('请输入手机号');
|
|
}
|
|
if (!$organizationId) {
|
|
$this->return_json('请选择所属机构');
|
|
}
|
|
if (!$uname) {
|
|
$this->return_json('请输入姓名');
|
|
}
|
|
$topOrgId = $this->getTopOrgId($organizationId);
|
|
$re = $this->mdSyliveUser->get(['mobile' => $mobile, 'topOrgId' => $topOrgId]);
|
|
if ($re && $re['status'] != -1) {
|
|
if ($re['teamId'] || $re['organizationId']) {
|
|
$this->return_json('手机号已存在当前机构');
|
|
}
|
|
}
|
|
$bizId = 0;
|
|
$re_org = $this->mdSyliveOrganization->get(['organizationId' => $organizationId]);
|
|
if ($re_org) {
|
|
if ($re_org['organizationType'] == 4 && $re_org['parentId']) {
|
|
$bizId = $re_org['parentId'];
|
|
} else if ($re_org['organizationType'] == 3) {
|
|
$bizId = $re_org['organizationId'];
|
|
}
|
|
}
|
|
$addDate = ['topOrgId' => $topOrgId, 'organizationId' => $organizationId, 'uname' => $uname,
|
|
'bizId' => $bizId, 'status' => 0, 'teamId' => 0];
|
|
if ($re['userId']) {
|
|
$this->mdSyliveUser->update($addDate, ['userId' => $re['userId']]);
|
|
$this->return_response([], '绑定用户成功');
|
|
} else {
|
|
$addDate['mobile'] = $mobile;
|
|
$addDate['createTime'] = date('Y-m-d H:i:s');
|
|
$id = $this->mdSyliveUser->add($addDate);
|
|
if (!$id) {
|
|
$this->return_json('添加用户失败');
|
|
}
|
|
$this->return_response();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Notes:修改用户
|
|
* Created on: 2022/9/21 14:48
|
|
* Created by: dengbw
|
|
*/
|
|
public function index_put()
|
|
{
|
|
$userId = intval($this->input_param('userId'));
|
|
$organizationId = intval($this->input_param('organizationId'));
|
|
$uname = $this->input_param('uname');
|
|
if (!$userId) {
|
|
$this->return_json('参数错误');
|
|
}
|
|
if (!$organizationId) {
|
|
$this->return_json('请选择所属机构');
|
|
}
|
|
if (!$uname) {
|
|
$this->return_json('请输入姓名');
|
|
}
|
|
$re = $this->mdSyliveUser->get(['userId' => $userId]);
|
|
if (!$re) {
|
|
$this->return_json('无此用户');
|
|
}
|
|
$topOrgId = $re['topOrgId'];
|
|
if ($re['organizationId'] != $organizationId) {
|
|
$topOrgId = $this->getTopOrgId($organizationId);
|
|
if ($re['topOrgId'] && $re['topOrgId'] != $topOrgId) {
|
|
$this->return_json('不可修改顶级机构');
|
|
}
|
|
}
|
|
$bizId = 0;
|
|
$re_org = $this->mdSyliveOrganization->get(['organizationId' => $organizationId]);
|
|
if ($re_org) {
|
|
if ($re_org['organizationType'] == 4 && $re_org['parentId']) {
|
|
$bizId = $re_org['parentId'];
|
|
} else if ($re_org['organizationType'] == 3) {
|
|
$bizId = $re_org['organizationId'];
|
|
}
|
|
}
|
|
$upDate = ['topOrgId' => $topOrgId, 'organizationId' => $organizationId, 'bizId' => $bizId, 'teamId' => 0, 'uname' => $uname];
|
|
$this->mdSyliveUser->update($upDate, ['userId' => $userId]);
|
|
$this->return_response();
|
|
}
|
|
|
|
/**
|
|
* Notes:修改马甲
|
|
* Created on: 2022/9/21 14:48
|
|
* Created by: dengbw
|
|
*/
|
|
public function majia_put()
|
|
{
|
|
$userId = intval($this->input_param('userId'));
|
|
$maJiaId = intval($this->input_param('maJiaId'));
|
|
if (!$userId) {
|
|
$this->return_json('参数错误');
|
|
}
|
|
$this->mdSyliveUser->update(['maJiaId' => $maJiaId], ['userId' => $userId]);
|
|
$this->return_response();
|
|
}
|
|
|
|
/**
|
|
* Notes:修改状态
|
|
* Created on: 2022/9/21 16:10
|
|
* Created by: dengbw
|
|
*/
|
|
public function status_put()
|
|
{
|
|
$userId = $this->input_param('userId');
|
|
$status = $this->input_param('status');
|
|
if (!$userId) {
|
|
$this->return_json('参数错误');
|
|
}
|
|
$this->mdSyliveUser->update(['status' => $status], ['userId' => $userId]);
|
|
$this->return_response();
|
|
}
|
|
|
|
/**
|
|
* Notes:删除用户
|
|
* Created on: 2022/9/21 16:10
|
|
* Created by: dengbw
|
|
* @param null $userId
|
|
*/
|
|
public function index_delete($userId = null)
|
|
{
|
|
if (!$userId) {
|
|
$this->return_json('参数错误');
|
|
}
|
|
$this->mdSyliveUser->update(['status' => -1], ['userId' => $userId]);
|
|
$this->return_response();
|
|
}
|
|
|
|
/**
|
|
* Notes:批量删除用户
|
|
* Created on: 2022/9/19 15:35
|
|
* Created by: dengbw
|
|
*/
|
|
public function batch_delete()
|
|
{
|
|
$ids = $this->input_param('ids');
|
|
if (!$ids) {
|
|
$this->return_json('参数错误');
|
|
}
|
|
$str_ids = implode(',', $ids);
|
|
if ($str_ids) {
|
|
$this->mdSyliveUser->update(['status' => -1], ["userId in($str_ids)" => null]);
|
|
}
|
|
$this->return_response();
|
|
}
|
|
|
|
/**
|
|
* Notes:栓验字段
|
|
* Created on: 2022/9/21 15:52
|
|
* Created by: dengbw
|
|
*/
|
|
public function existence_get()
|
|
{
|
|
$field = $this->input_param('field');
|
|
$value = $this->input_param('value');
|
|
$organizationId = intval($this->input_param('organizationId'));
|
|
if ($organizationId) {
|
|
$topOrgId = $this->getTopOrgId($organizationId);
|
|
$where = [$field => $value, 'topOrgId' => $topOrgId, 'status>=' => 0];
|
|
$re = $this->mdSyliveUser->get($where);
|
|
if ($re) {
|
|
if ($field == 'mobile') {
|
|
if ($re['teamId'] || $re['organizationId']) {
|
|
$this->return_json('已存在', 0);
|
|
}
|
|
} else {
|
|
$this->return_json('已存在', 0);
|
|
}
|
|
}
|
|
}
|
|
$this->return_json('不存在', 1);
|
|
}
|
|
|
|
/**
|
|
* Notes:获取顶级机构id
|
|
* Created on: 2022/12/8 14:39
|
|
* Created by: dengbw
|
|
* @param $organizationId
|
|
* @param $topOrgId
|
|
* @return mixed
|
|
*/
|
|
private function getTopOrgId($organizationId, $topOrgId = 0)
|
|
{
|
|
$re = $this->mdSyliveOrganization->get(['organizationId' => $organizationId], 'organizationId,parentId');
|
|
if (!$re) {
|
|
return $topOrgId;
|
|
} else {
|
|
$topOrgId = $re['organizationId'];
|
|
if ($re['parentId']) {
|
|
return $this->getTopOrgId($re['parentId'], $topOrgId);
|
|
} else {
|
|
return $topOrgId;
|
|
}
|
|
}
|
|
}
|
|
|
|
} |