204 lines
8.3 KiB
PHP
204 lines
8.3 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 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 = $this->input_param('unOrganizationType');
|
|
$where['status>='] = 0;
|
|
$unOrganizationType && $where['organizationType<>'] = $unOrganizationType;
|
|
$sort_order = 'sortNumber asc,organizationId desc';
|
|
if ($_SESSION['brandName']) {//只找该品牌机构
|
|
$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()
|
|
{
|
|
$res = [];
|
|
if ($_SESSION['brandName']) {//只找该品牌机构
|
|
$re_org = $this->mdSyliveOrganization->get(['organizationName' => $_SESSION['brandName'], 'parentId' => 0, 'status' => 0]);
|
|
if ($re_org['organizationId']) {
|
|
$res[] = ['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');
|
|
}
|
|
$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'));
|
|
$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();
|
|
}
|
|
|
|
} |