221 lines
7.7 KiB
PHP
221 lines
7.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');
|
|
$this->load->model('market/Market_sylive_groups_model', 'mdSyliveGroups');
|
|
$this->load->model('market/Market_sylive_user_model', 'mdSyliveUser');
|
|
}
|
|
|
|
/**
|
|
* 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');
|
|
$activityId = intval($this->input_param('activityId'));
|
|
$groupsId = intval($this->input_param('groupsId'));
|
|
!$page && $page = 1;
|
|
!$limit && $limit = 10;
|
|
$sort_order = 'type desc,groupsUserId desc';
|
|
$list = [];
|
|
$where['status>='] = 0;
|
|
$groupsId && $where['groupsId'] = $groupsId;
|
|
$activityId && $where['activityId'] = $activityId;
|
|
if ($uname || $nickname) {
|
|
$where_user = $uname ? "(uname LIKE '%{$uname}%')" : "(nickname LIKE '%{$nickname}%')";
|
|
$where["userId in (select userId from lc_market_sylive_user where {$where_user})"] = null;
|
|
}
|
|
$count = $this->mdSyliveGroupsUser->count($where);
|
|
if ($count) {
|
|
$res = $this->mdSyliveGroupsUser->select($where, $sort_order, $page, $limit);
|
|
$user_ids = implode(",", array_column($res, 'userId'));
|
|
$map_user = $this->mdSyliveUser->map('userId', 'uname,nickname,mobile', ["userId in({$user_ids})" => null]);
|
|
foreach ($res as $v) {
|
|
$uname = $nickname = $mobile = '';
|
|
$user = $map_user[$v['userId']];
|
|
if ($user) {
|
|
$uname = $user['uname'];
|
|
$nickname = $user['nickname'];
|
|
$mobile = $user['mobile'];
|
|
}
|
|
$status = intval($v['status']);
|
|
$createTime = $v['createTime'] != '0000-00-00 00:00:00' ? $v['createTime'] : '';
|
|
if ($v['type'] == 0) {
|
|
$roleName = '销售';
|
|
} else if ($v['type'] == 1) {
|
|
$roleName = $v['userFrom'] == 0 ? '店长' : '团长';
|
|
} else {
|
|
$roleName = '管理员';
|
|
}
|
|
$list[] = [
|
|
'groupsUserId' => $v['groupsUserId'], 'uname' => $uname, 'nickname' => $nickname, 'mobile' => $mobile
|
|
, 'groupsId' => $groupsId, 'roleName' => $roleName, '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()
|
|
{
|
|
$activityId = intval($this->input_param('activityId'));
|
|
$groupsId = intval($this->input_param('groupsId'));
|
|
$userFrom = intval($this->input_param('userFrom'));
|
|
$chooseUsers = $this->input_param('chooseUsers');
|
|
if (!$groupsId) {
|
|
$this->return_json('未选择分组');
|
|
}
|
|
if (!$chooseUsers) {
|
|
$this->return_json('未选择用户');
|
|
}
|
|
$addData = [];
|
|
$levelAry = $this->getLevelAry($groupsId);
|
|
$re_gro = $this->mdSyliveGroups->get(['groupsId' => $groupsId], 'ifBiz');
|
|
$ifBiz = intval($re_gro['ifBiz']);//是否门店
|
|
foreach ($chooseUsers as $v) {
|
|
$re = $this->mdSyliveGroupsUser->get(['activityId' => $activityId, 'userId' => $v['userId'], 'status>=' => 0]);
|
|
if (!$re) {
|
|
$type = $ifBiz ? $v['type'] : 2;
|
|
$value = ['userId' => $v['userId'], 'type' => $type, 'activityId' => $activityId
|
|
, 'groupsId' => $groupsId, 'userFrom' => $userFrom, 'createTime' => date('Y-m-d H:i:s')];
|
|
$data = array_merge($value, $levelAry);
|
|
$addData[] = $data;
|
|
}
|
|
}
|
|
$addData && $this->mdSyliveGroupsUser->add_batch($addData);
|
|
$this->return_response();
|
|
}
|
|
|
|
/**
|
|
* Notes:获取分组等级ID
|
|
* Created on: 2022/11/30 14:30
|
|
* Created by: dengbw
|
|
* @param $groupsId
|
|
* @param array $data
|
|
* @return array
|
|
*/
|
|
private function getLevelAry($groupsId, $data = [])
|
|
{
|
|
$re = $this->mdSyliveGroups->get(['groupsId' => $groupsId], 'groupsId,parentId,groupsLevel,ifBiz');
|
|
if (!$re) {
|
|
return $data;
|
|
} else {
|
|
if ($re['groupsLevel']) {//分类id
|
|
$levelId = "levelId" . $re['groupsLevel'];
|
|
$data[$levelId] = $re['groupsId'];
|
|
}
|
|
if ($re['ifBiz']) {//门店id
|
|
$data['bizId'] = $re['groupsId'];
|
|
}
|
|
if ($re['parentId']) {
|
|
return $this->getLevelAry($re['parentId'], $data);
|
|
} else {
|
|
return $data;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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()
|
|
{
|
|
$groupsUserId = $this->input_param('groupsUserId');
|
|
$status = $this->input_param('status');
|
|
if (!$groupsUserId) {
|
|
$this->return_json('参数错误');
|
|
}
|
|
$this->mdSyliveGroupsUser->update(['status' => $status], ['groupsUserId' => $groupsUserId]);
|
|
$this->return_response();
|
|
}
|
|
|
|
/**
|
|
* Notes:删除用户
|
|
* Created on: 2022/9/21 16:10
|
|
* Created by: dengbw
|
|
* @param null $groupsUserId
|
|
*/
|
|
public function index_delete($groupsUserId = null)
|
|
{
|
|
if (!$groupsUserId) {
|
|
$this->return_json('参数错误');
|
|
}
|
|
$this->mdSyliveGroupsUser->update(['status' => -1], ['groupsUserId' => $groupsUserId]);
|
|
$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);
|
|
}
|
|
|
|
} |