Files
liche/market/controllers/api/sylive/GroupsUser.php
T
2022-11-25 17:56:47 +08:00

180 lines
5.7 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once APPPATH . 'controllers/api/BaseController.php';
/**
* Notes:私域直播_分组用户管理
* Created on: 2022/11/25 17:15
* Created by: dengbw
*/
class GroupsUser extends BaseController
{
public function __construct()
{
parent::__construct();
$this->load->model('market/Market_sylive_groups_user_model', 'mdSyliveGroupsUser');
}
/**
* 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->mdSyliveGroupsUser->count($where);
if ($count) {
$res = $this->mdSyliveGroupsUser->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/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->mdSyliveGroupsUser->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->mdSyliveGroupsUser->update($addDate, ['userId' => $re['userId']]);
$this->return_response([], '绑定用户成功');
} else {
$addDate['mobile'] = $mobile;
$addDate['createTime'] = date('Y-m-d H:i:s');
$id = $this->mdSyliveGroupsUser->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->mdSyliveGroupsUser->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->mdSyliveGroupsUser->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->mdSyliveGroupsUser->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->mdSyliveGroupsUser->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);
}
}