244 lines
8.5 KiB
PHP
244 lines
8.5 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
require_once APPPATH . 'controllers/api/BaseController.php';
|
|
|
|
/**
|
|
* Notes:私域直播_团队用户管理
|
|
* Created on: 2022/10/24 17:15
|
|
* Created by: dengbw
|
|
*/
|
|
class TeamUser extends BaseController
|
|
{
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('agent/admin/Market_sylive_user_model', 'mdSyliveUser');
|
|
$this->load->model('agent/admin/Market_sylive_team_model', 'mdSyliveTeam');
|
|
}
|
|
|
|
/**
|
|
* 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');
|
|
$teamId = intval($this->input_param('teamId'));
|
|
!$page && $page = 1;
|
|
!$limit && $limit = 10;
|
|
$sort_order = 'userId desc';
|
|
if ($sort && $order) {
|
|
$sort_order = $sort . ' ' . $order;
|
|
}
|
|
$list = [];
|
|
$where['status>='] = 0;
|
|
$teamId && $where['teamId'] = $teamId;
|
|
$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'] : '';
|
|
$list[] = [
|
|
'userId' => $v['userId'], 'uname' => $v['uname'], 'nickname' => $v['nickname'], 'mobile' => $v['mobile']
|
|
, 'teamId' => $teamId, 'status' => $status, 'createTime' => $createTime];
|
|
}
|
|
}
|
|
$date = ['list' => $list, 'count' => $count];
|
|
$this->return_response_list($date);
|
|
}
|
|
|
|
/**
|
|
* Notes:获取团队用户
|
|
* Created on: 2022/11/30 15:37
|
|
* Created by: dengbw
|
|
*/
|
|
public function list_post()
|
|
{
|
|
$this->load->model('agent/admin/Market_sylive_groups_user_model', 'mdSyliveGroupsUser');
|
|
$this->load->model('agent/admin/Market_sylive_groups_model', 'mdSyliveGroups');
|
|
$activityId = intval($this->input_param('activityId'));
|
|
$teamIds = $this->input_param('teamIds');
|
|
$keyword = trim($this->input_param('keyword'));
|
|
$where = ['status>=' => 0, 'teamId>' => 0];
|
|
if ($keyword) {
|
|
$where["(uname LIKE '%{$keyword}%' OR mobile LIKE '%{$keyword}%')"] = null;
|
|
} else if ($teamIds) {
|
|
$teamIds_str = implode(',', $teamIds);
|
|
$res_tea = $this->mdSyliveTeam->select(["parentId in({$teamIds_str})" => null], 'teamId desc', 0, 0, 'teamId');
|
|
foreach ($res_tea as $v) {
|
|
$teamIds[] = $v['teamId'];
|
|
}
|
|
$teamIds = implode(',', $teamIds);
|
|
$where["teamId in({$teamIds})"] = null;
|
|
}
|
|
$res = $this->mdSyliveUser->select($where, 'userId desc', 0, 0, 'userId,uname,mobile,teamId');
|
|
if ($keyword && $res) {
|
|
$teamIds = [];
|
|
foreach ($res as $v) {
|
|
$v['teamId'] && $teamIds[] = $v['teamId'];
|
|
}
|
|
$teamIds && $teamIds = implode(',', $teamIds);
|
|
}
|
|
$map_team = $map_team2 = [];
|
|
if ($teamIds) {
|
|
$map_team = $this->mdSyliveTeam->map('teamId', 'teamName,teamType', ["teamId in({$teamIds})" => null]);
|
|
}
|
|
$list = [];
|
|
foreach ($res as $v) {
|
|
$uname = $v['uname'] ? $v['uname'] : '-';
|
|
$team = $map_team[$v['teamId']];
|
|
$teamName = $team['teamName'] ? $team['teamName'] : '-';
|
|
$type = 2;
|
|
if ($team['teamType'] == 2) {
|
|
$type = 1;
|
|
} else if ($team['teamType'] == 3) {
|
|
$type = 0;
|
|
}
|
|
$groups = 0;
|
|
$re_gro_use = $this->mdSyliveGroupsUser->get(['activityId' => $activityId, 'userId' => $v['userId']
|
|
, 'status>=' => 0], 'groupsId,bizId');
|
|
if ($re_gro_use) {
|
|
$groups = 1;
|
|
$groupsId = $re_gro_use['bizId'] ? $re_gro_use['bizId'] : $re_gro_use['groupsId'];
|
|
$re_gro = $this->mdSyliveGroups->get(['activityId' => $activityId, 'groupsId' => $groupsId
|
|
, 'status>=' => 0], 'groupsName');
|
|
$re_gro['groupsName'] && $teamName .= "(分组-{$re_gro['groupsName']})";
|
|
}
|
|
$list[] = ['userId' => $v['userId'], 'uname' => $uname, 'mobile' => $v['mobile'], 'type' => $type
|
|
, 'groups' => $groups, 'teamName' => $teamName];
|
|
}
|
|
$this->return_response_list($list);
|
|
}
|
|
|
|
/**
|
|
* Notes:添加用户
|
|
* Created on: 2022/9/21 16:46
|
|
* Created by: dengbw
|
|
*/
|
|
public function index_post()
|
|
{
|
|
$mobile = $this->input_param('mobile');
|
|
$teamId = intval($this->input_param('teamId'));
|
|
$uname = $this->input_param('uname');
|
|
if (!$mobile) {
|
|
$this->return_json('请输入手机号');
|
|
}
|
|
if (!$teamId) {
|
|
$this->return_json('请选择所属团队');
|
|
}
|
|
if (!$uname) {
|
|
$this->return_json('请输入姓名');
|
|
}
|
|
$re = $this->mdSyliveUser->get(['mobile' => $mobile]);
|
|
if ($re && $re['status'] != -1) {
|
|
if ($re['teamId'] || $re['organizationId']) {
|
|
$this->return_json('手机号已存在');
|
|
}
|
|
}
|
|
$addDate = ['teamId' => $teamId, 'uname' => $uname, 'status' => 0, 'organizationId' => 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'));
|
|
$teamId = intval($this->input_param('teamId'));
|
|
$uname = $this->input_param('uname');
|
|
if (!$userId) {
|
|
$this->return_json('参数错误');
|
|
}
|
|
if (!$teamId) {
|
|
$this->return_json('请选择所属团队');
|
|
}
|
|
if (!$uname) {
|
|
$this->return_json('请输入姓名');
|
|
}
|
|
$upDate = ['teamId' => $teamId, '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');
|
|
$id = $this->input_param('id');
|
|
if (!$id) {
|
|
$where = [$field => $value, 'status<>' => -1];
|
|
$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);
|
|
}
|
|
|
|
} |