market_institution_1223

This commit is contained in:
dengbw
2022-12-23 14:17:59 +08:00
committed by lccsw
parent d2f7a366c2
commit 1b1ff0bc49
6 changed files with 5 additions and 950 deletions
+1 -1
View File
@@ -55,7 +55,7 @@ class Team extends BaseController
$res = $this->mdSyliveTeam->select($where, $sort_order);
foreach ($res as $k => $v) {
$res[$k]['teamId'] = intval($v['teamId']);
$res[$k]['parentId'] = intval($v['parentId']);
$res[$k]['parentId'] = $v['parentId'] ? intval($v['parentId']) : '';
$res[$k]['sortNumber'] = intval($v['sortNumber']);
$res[$k]['organizationId'] = $v['organizationId'] ? intval($v['organizationId']) : '';
$city = $logo = [];
@@ -1,230 +0,0 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once APPPATH . 'controllers/api/BaseController.php';
/**
* Notes:私域直播_机构管理
* Created on: 2022/9/16 17:15
* Created by: dengbw
*/
class Organization extends BaseController
{
public function __construct()
{
parent::__construct();
$this->load->model('market/Market_sylive_organization_model', 'mdSyliveOrganization');
}
/**
* Notes:获取机构
* Created on: 2022/9/16 11:11
* Created by: dengbw
*/
public function index_get()
{
$unOrganizationType = intval($this->input_param('unOrganizationType'));
$activityId = intval($this->input_param('activityId'));
$where['status>='] = 0;
$unOrganizationType && $where['organizationType<>'] = $unOrganizationType;
$sort_order = 'sortNumber asc,organizationId desc';
if ($_SESSION['brandName'] || $activityId) {//只找该品牌机构
if ($activityId) {
$this->load->model('market/Market_sylive_activity_model', 'mdSyliveActivity');
$re_act = $this->mdSyliveActivity->get(['activityId' => $activityId]);
$re_org['organizationId'] = intval($re_act['organizationId']);
} else {
$re_org = $this->mdSyliveOrganization->get(['organizationName' => $_SESSION['brandName'], 'parentId' => 0, 'status' => 0]);
}
if ($re_org['organizationId']) {
$organizationIds[] = $re_org['organizationId'];
$res_all = $this->mdSyliveOrganization->select($where, 'organizationType asc,parentId asc', 0, 0, 'organizationId,parentId');
foreach ($res_all as $k => $v) {
if (in_array($v['parentId'], $organizationIds)) {
$organizationIds[] = $v['organizationId'];
}
}
$str_organizationIds = implode(',', array_unique($organizationIds));
$where["organizationId in({$str_organizationIds})"] = null;
} else {
$where['organizationId'] = -1;
}
}
$res = $this->mdSyliveOrganization->select($where, $sort_order);
foreach ($res as $k => $v) {
$res[$k]['organizationId'] = intval($v['organizationId']);
$res[$k]['parentId'] = intval($v['parentId']);
$res[$k]['sortNumber'] = intval($v['sortNumber']);
$city = $logo = [];
if ($v['countyId']) {
$city[] = $v['provinceId'];
$city[] = $v['cityId'];
$city[] = $v['countyId'];
}
$res[$k]['city'] = $city;
if ($v['logo']) {
$logo[] = ['uid' => 1, 'fileUrl' => $v['logo'], 'url' => build_qiniu_image_url($v['logo']), 'status' => 'done'];
}
$res[$k]['logo'] = $logo;
}
$this->return_response_list($res);
}
/**
* Notes:查找上级机构
* Created on: 2022/10/24 15:24
* Created by: dengbw
*/
public function parent_get()
{
$list = [];
if ($_SESSION['brandName']) {//只找该品牌机构
$re_org = $this->mdSyliveOrganization->get(['organizationName' => $_SESSION['brandName'], 'parentId' => 0, 'status>=' => 0]);
if ($re_org['organizationId']) {
$list[] = ['organizationId' => intval($re_org['organizationId']), 'organizationName' => $re_org['organizationName']];
}
} else {
$parentId = intval($this->input_param('parentId'));
$sort_order = 'sortNumber asc,organizationId desc';
$where['status>='] = 0;
$where['parentId'] = $parentId;
$res = $this->mdSyliveOrganization->select($where, $sort_order, 0, 0, 'organizationId,organizationName');
foreach ($res as $k => $v) {
$list[] = ['organizationId' => intval($v['organizationId']), 'organizationName' => $v['organizationName']];
}
}
$this->return_response_list($list);
}
/**
* Notes:添加机构
* Created on: 2022/9/19 16:43
* Created by: dengbw
*/
public function index_post()
{
$parentId = intval($this->input_param('parentId'));
$organizationName = $this->input_param('organizationName');
$organizationFullName = $this->input_param('organizationFullName');
$organizationType = $this->input_param('organizationType');
$sortNumber = intval($this->input_param('sortNumber'));
$comments = $this->input_param('comments');
$city = $this->input_param('city');
$logo = $this->input_param('logo');
if ($_SESSION['brandName'] && !$parentId) {//品牌机构必顺选择上级机构
$this->return_json('请选择上级机构');
}
if (!$organizationName) {
$this->return_json('请输入机构名称');
}
if (!$organizationType) {
$this->return_json('请选择机构类型');
}
if ($parentId) {//判断上级机构是不是员工类型
$re_org = $this->mdSyliveOrganization->get(['organizationId' => $parentId]);
if ($re_org['organizationType'] == 4) {
$this->return_json('选择的上级机构不能保存,请重新选择');
}
}
!$comments && $comments = '';
$logo = $logo[0]['fileUrl'] ? $logo[0]['fileUrl'] : '';
$addDate = ['parentId' => $parentId, 'organizationName' => $organizationName, 'organizationFullName' => $organizationFullName
, 'organizationType' => $organizationType, 'sortNumber' => $sortNumber, 'comments' => $comments, 'logo' => $logo
, 'createTime' => date('Y-m-d H:i:s')];
if ($city) {
$addDate['provinceId'] = intval($city[0]);
$addDate['cityId'] = intval($city[1]);
$addDate['countyId'] = intval($city[2]);
}
$id = $this->mdSyliveOrganization->add($addDate);
if (!$id) {
$this->return_json('添加机构失败');
}
$this->return_response();
}
/**
* Notes:修改机构
* Created on: 2022/9/19 17:29
* Created by: dengbw
*/
public function index_put()
{
$organizationId = intval($this->input_param('organizationId'));
$parentId = intval($this->input_param('parentId'));
$organizationName = $this->input_param('organizationName');
$organizationFullName = $this->input_param('organizationFullName');
$organizationType = $this->input_param('organizationType');
$sortNumber = intval($this->input_param('sortNumber'));
$comments = $this->input_param('comments');
$city = $this->input_param('city');
$logo = $this->input_param('logo');
if ($_SESSION['brandName']) {//品牌机构
$re_org = $this->mdSyliveOrganization->get(['organizationId' => $organizationId]);
if ($re_org && $re_org['parentId'] == 0) {//一级品牌不可修改字段
$parentId = 0;
$organizationType = 1;
$organizationName = $re_org['organizationName'];
}
}
if (!$organizationId) {
$this->return_json('参数错误');
}
if (!$organizationName) {
$this->return_json('请输入机构名称');
}
if (!$organizationType) {
$this->return_json('请选择机构类型');
}
if ($parentId) {//判断上级机构是不是员工类型
$re_org = $this->mdSyliveOrganization->get(['organizationId' => $parentId]);
if ($re_org['organizationType'] == 4) {
$this->return_json('选择的上级机构不能保存,请重新选择');
}
}
!$comments && $comments = '';
$logo = $logo ? $logo[0]['fileUrl'] : '';
$upDate = ['parentId' => $parentId, 'organizationName' => $organizationName, 'organizationFullName' => $organizationFullName
, 'organizationType' => $organizationType, 'sortNumber' => $sortNumber, 'comments' => $comments, 'logo' => $logo];
if ($city) {
$upDate['provinceId'] = intval($city[0]);
$upDate['cityId'] = intval($city[1]);
$upDate['countyId'] = intval($city[2]);
}
$this->mdSyliveOrganization->update($upDate, ['organizationId' => $organizationId]);
$this->return_response();
}
/**
* Notes:删除机构
* Created on: 2022/9/19 11:08
* Created by: dengbw
* @param null $organizationId
*/
public function index_delete($organizationId = null)
{
$organizationId = intval($organizationId);
if (!$organizationId) {
$this->return_json('参数错误');
}
$this->mdSyliveOrganization->update(['status' => -1], ['organizationId' => $organizationId]);
$this->return_response();
}
/**
* Notes:机构详情
* Created on: 2022/12/09 10:37
* Created by: dengbw
* @param null $organizationId
*/
public function info_get($organizationId = null)
{
$organizationId = intval($organizationId);
if (!$organizationId) {
$this->return_json('参数错误');
}
$re = $this->mdSyliveOrganization->get(['organizationId' => $organizationId]);
$this->return_response($re);
}
}
-164
View File
@@ -1,164 +0,0 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once APPPATH . 'controllers/api/BaseController.php';
/**
* Notes:私域直播_团队管理
* Created on: 2022/9/16 17:15
* Created by: dengbw
*/
class Team extends BaseController
{
public function __construct()
{
parent::__construct();
$this->load->model('market/Market_sylive_team_model', 'mdSyliveTeam');
}
/**
* Notes:获取团队
* Created on: 2022/9/16 11:11
* Created by: dengbw
*/
public function index_get()
{
$unTeamType = $this->input_param('unTeamType');
$where['status>='] = 0;
$unTeamType && $where['teamType<>'] = $unTeamType;
$sort_order = 'sortNumber asc,teamId desc';
if ($_SESSION['brandName']) {//只找该品牌机构
$this->load->model('market/Market_sylive_organization_model', 'mdSyliveOrganization');
$re_org = $this->mdSyliveOrganization->get(['organizationName' => $_SESSION['brandName'], 'parentId' => 0, 'status' => 0]);
if ($re_org['organizationId']) {
$res_team = $this->mdSyliveTeam->select(['status>=' => 0, 'organizationId' => $re_org['organizationId']], 'parentId asc,sortNumber asc', 0, 0, 'teamId');
if ($res_team) {
$teamIds = [];
foreach ($res_team as $k => $v) {
$teamIds[] = $v['teamId'];
}
$res_all = $this->mdSyliveTeam->select($where, 'parentId asc,sortNumber asc', 0, 0, 'teamId,parentId');
foreach ($res_all as $k => $v) {
if (in_array($v['parentId'], $teamIds)) {
$teamIds[] = $v['teamId'];
}
}
$str_teamIds = implode(',', array_unique($teamIds));
$where["teamId in({$str_teamIds})"] = null;
} else {
$where['teamId'] = -1;
}
} else {
$where['teamId'] = -1;
}
}
$res = $this->mdSyliveTeam->select($where, $sort_order);
foreach ($res as $k => $v) {
$res[$k]['teamId'] = intval($v['teamId']);
$res[$k]['parentId'] = intval($v['parentId']);
$res[$k]['sortNumber'] = intval($v['sortNumber']);
$res[$k]['organizationId'] = $v['organizationId'] ? intval($v['organizationId']) : '';
$city = $logo = [];
if ($v['cityId']) {
$city[] = $v['provinceId'];
$city[] = $v['cityId'];
}
$res[$k]['city'] = $city;
if ($v['logo']) {
$logo[] = ['uid' => 1, 'fileUrl' => $v['logo'], 'url' => build_qiniu_image_url($v['logo']), 'status' => 'done'];
}
$res[$k]['logo'] = $logo;
}
$this->return_response_list($res);
}
/**
* Notes:添加团队
* Created on: 2022/9/19 16:43
* Created by: dengbw
*/
public function index_post()
{
$parentId = intval($this->input_param('parentId'));
$teamName = $this->input_param('teamName');
$sortNumber = intval($this->input_param('sortNumber'));
$comments = $this->input_param('comments');
$city = $this->input_param('city');
$teamType = $this->input_param('teamType');
$organizationId = intval($this->input_param('organizationId'));
$logo = $this->input_param('logo');
if (!$teamName) {
$this->return_json('请输入团队名称');
}
if (!$parentId && !$organizationId) {
$this->return_json('请选择所属团队');
}
!$comments && $comments = '';
$logo = $logo ? $logo[0]['fileUrl'] : '';
$addDate = ['parentId' => $parentId, 'teamName' => $teamName, 'sortNumber' => $sortNumber, 'comments' => $comments
, 'teamType' => $teamType, 'organizationId' => $organizationId, 'logo' => $logo, 'createTime' => date('Y-m-d H:i:s')];
if ($city) {
$addDate['provinceId'] = intval($city[0]);
$addDate['cityId'] = intval($city[1]);
}
$id = $this->mdSyliveTeam->add($addDate);
if (!$id) {
$this->return_json('添加团队失败');
}
$this->return_response();
}
/**
* Notes:修改团队
* Created on: 2022/9/19 17:29
* Created by: dengbw
*/
public function index_put()
{
$teamId = intval($this->input_param('teamId'));
$parentId = intval($this->input_param('parentId'));
$teamName = $this->input_param('teamName');
$sortNumber = intval($this->input_param('sortNumber'));
$comments = $this->input_param('comments');
$city = $this->input_param('city');
$teamType = $this->input_param('teamType');
$organizationId = intval($this->input_param('organizationId'));
$logo = $this->input_param('logo');
if (!$teamId) {
$this->return_json('参数错误');
}
if (!$teamName) {
$this->return_json('请输入团队名称');
}
if (!$parentId && !$organizationId) {
$this->return_json('请选择所属团队');
}
!$comments && $comments = '';
$logo = $logo ? $logo[0]['fileUrl'] : '';
$upDate = ['parentId' => $parentId, 'teamName' => $teamName, 'sortNumber' => $sortNumber, 'comments' => $comments
, 'teamType' => $teamType, 'organizationId' => $organizationId, 'logo' => $logo];
if ($city) {
$upDate['provinceId'] = intval($city[0]);
$upDate['cityId'] = intval($city[1]);
}
$this->mdSyliveTeam->update($upDate, ['teamId' => $teamId]);
$this->return_response();
}
/**
* Notes:删除团队
* Created on: 2022/9/19 11:08
* Created by: dengbw
* @param null $teamId
*/
public function index_delete($teamId = null)
{
$teamId = intval($teamId);
if (!$teamId) {
$this->return_json('参数错误');
}
$this->mdSyliveTeam->update(['status' => -1], ['teamId' => $teamId]);
$this->return_response();
}
}
-244
View File
@@ -1,244 +0,0 @@
<?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('market/Market_sylive_user_model', 'mdSyliveUser');
$this->load->model('market/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('market/Market_sylive_groups_user_model', 'mdSyliveGroupsUser');
$this->load->model('market/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);
}
}
-307
View File
@@ -1,307 +0,0 @@
<?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 User 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'));
!$page && $page = 1;
!$limit && $limit = 10;
$sort_order = 'userId desc';
if ($sort && $order) {
$sort_order = $sort . ' ' . $order;
}
$list = [];
$where['status>='] = 0;
$organizationId && $where['organizationId'] = $organizationId;
$uname && $where['uname'] = $uname;
$nickname && $where['nickname'] = $nickname;
$this->load->model('market/Market_sylive_organization_model', 'mdSyliveOrganization');
$organizationType = 0;
$re_org = $this->mdSyliveOrganization->get(['organizationId' => $organizationId]);
$re_org && $organizationType = $re_org['organizationType'];
$roleName = $this->mdSyliveUser->roleAry($organizationType);
$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']
, 'roleName' => $roleName, 'organizationId' => $organizationId, 'status' => $status, 'createTime' => $createTime];
}
}
$date = ['list' => $list, 'count' => $count];
$this->return_response_list($date);
}
/**
* Notes:获取机构用户
* Created on: 2022/11/29 11:08
* Created by: dengbw
*/
public function list_post()
{
$this->load->model('market/Market_sylive_groups_user_model', 'mdSyliveGroupsUser');
$this->load->model('market/Market_sylive_groups_model', 'mdSyliveGroups');
$activityId = intval($this->input_param('activityId'));
$organizationIds = $this->input_param('organizationIds');
$keyword = trim($this->input_param('keyword'));
$where = ['status>=' => 0, 'organizationId>' => 0];
if ($keyword) {
$this->load->model('market/Market_sylive_activity_model', 'mdSyliveActivity');
$where["(uname LIKE '%{$keyword}%' OR mobile LIKE '%{$keyword}%')"] = null;
$re = $this->mdSyliveActivity->get(['activityId' => $activityId]);
if ($re['organizationId']) {//找当前顶级机构用户
$where["topOrgId"] = $re['organizationId'];
}
} else if ($organizationIds) {
$organizationIds = implode(',', $organizationIds);
$where["organizationId in({$organizationIds}) or bizId in({$organizationIds})"] = null;
}
$res = $this->mdSyliveUser->select($where, 'userId desc', 0, 0, 'userId,uname,mobile,organizationId,bizId');
if ($keyword && $res) {
$organizationIds = [];
foreach ($res as $v) {
$v['bizId'] && $organizationIds[] = $v['bizId'];
$v['organizationId'] && $organizationIds[] = $v['organizationId'];
}
$organizationIds && $organizationIds = implode(',', $organizationIds);
}
$map_organization = [];
if ($organizationIds) {
$map_organization = $this->mdSyliveOrganization->map('organizationId', 'organizationName,organizationType'
, ["organizationId in({$organizationIds})" => null]);
}
$list = [];
foreach ($res as $v) {
$uname = $v['uname'] ? $v['uname'] : '-';
$organization = $map_organization[$v['bizId']];
if (!$organization) {
$organization = $map_organization[$v['organizationId']];
}
$organizationName = $organization['organizationName'] ? $organization['organizationName'] : '-';
$type = 2;
if ($v['bizId']) {
$type = $v['bizId'] == $v['organizationId'] ? 1 : 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'] && $organizationName .= "(分组-{$re_gro['groupsName']})";
}
$list[] = ['userId' => $v['userId'], 'uname' => $uname, 'mobile' => $v['mobile'], 'type' => $type
, 'groups' => $groups, 'organizationName' => $organizationName];
}
$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');
$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;
}
}
}
}
+4 -4
View File
@@ -86,10 +86,10 @@ class ApiAuthHook
$authority = 'system:role:' . $authority_set;
} else if (strstr($route, '/dictionaryData')) {//字典项权限
$authority = 'system:dictionary:' . $authority_set;
} else if (strstr($route, '/sylive/user')) {//机构用户权限
$authority = 'sylive:organization:' . $authority_set;
} else if (strstr($route, '/sylive/teamUser')) {//团队用户权限
$authority = 'sylive:team:' . $authority_set;
} else if (strstr($route, '/institution/organizationUser')) {//机构用户权限
$authority = 'institution:organization:' . $authority_set;
} else if (strstr($route, '/institution/teamUser')) {//团队用户权限
$authority = 'institution:team:' . $authority_set;
} else if (strstr($route, '/sylive/groupsUser')) {//分组用户权限
$authority = 'sylive:groups:' . $authority_set;
}