Files
liche/market/controllers/api/institution/Team.php
T
2022-12-22 14:10:39 +08:00

164 lines
6.2 KiB
PHP

<?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();
}
}