254 lines
8.9 KiB
PHP
254 lines
8.9 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('market/Market_sylive_user_model', 'mdSyliveUser');
|
|
$this->load->model('market/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');
|
|
$nickname = $this->input_param('nickname');
|
|
$sort = $this->input_param('sort');
|
|
$order = $this->input_param('order');
|
|
$organizationId = intval($this->input_param('organizationId'));
|
|
$topOrgId = intval($this->input_param('topOrgId'));
|
|
$keyWord = $this->input_param('keyWord');
|
|
!$page && $page = 1;
|
|
!$limit && $limit = 10;
|
|
$sort_order = 'userId desc';
|
|
if ($sort && $order) {
|
|
$sort_order = $sort . ' ' . $order;
|
|
}
|
|
$list = $re_org = [];
|
|
$organizationType = 0;
|
|
$roleAry = $this->mdSyliveUser->roleAry();
|
|
$where['status>='] = 0;
|
|
if ($organizationId) {
|
|
$where['organizationId'] = $organizationId;
|
|
$re_org = $this->mdSyliveOrganization->get(['organizationId' => $organizationId]);
|
|
}
|
|
if ($topOrgId) {
|
|
$where['topOrgId'] = $topOrgId;
|
|
$re_org = $this->mdSyliveOrganization->get(['organizationId' => $topOrgId]);
|
|
}
|
|
$re_org && $organizationType = $re_org['organizationType'];
|
|
if ($keyWord) {
|
|
$where["(uname LIKE '%{$keyWord}%' OR mobile LIKE '%{$keyWord}%') OR nickname LIKE '%{$keyWord}%')"] = null;
|
|
} else {
|
|
$uname && $where['uname'] = $uname;
|
|
$nickname && $where['nickname'] = $nickname;
|
|
}
|
|
$count = $this->mdSyliveUser->count($where);
|
|
if ($count) {
|
|
$res = $this->mdSyliveUser->select($where, $sort_order, $page, $limit);
|
|
foreach ($res as $v) {
|
|
$status = intval($v['status']);
|
|
$createTime = $v['createTime'] != '0000-00-00 00:00:00' ? $v['createTime'] : '';
|
|
$roleName = $roleAry[$organizationType] ? $roleAry[$organizationType] : '客户';
|
|
$list[] = [
|
|
'userId' => $v['userId'], 'uname' => $v['uname'], 'nickname' => $v['nickname'], 'mobile' => $v['mobile']
|
|
, '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 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/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;
|
|
}
|
|
}
|
|
}
|
|
|
|
} |