95 lines
3.2 KiB
PHP
95 lines
3.2 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
require_once APPPATH . 'controllers/api/BaseController.php';
|
|
|
|
class Cmmssn extends BaseController
|
|
{
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('agent/organization/Organization_model', 'mdOrganization');
|
|
$this->load->model('agent/organization/Organization_cmmssn_model', 'mdOrganizationCmmssn');
|
|
}
|
|
|
|
public function index_get()
|
|
{
|
|
$teamId = $this->input_param('teamId');
|
|
$where = [
|
|
'teamId' => $teamId
|
|
];
|
|
$res = $this->mdOrganizationCmmssn->get($where);
|
|
$teamLevel = $this->mdOrganization->getTeamLevel($teamId);
|
|
if (!$res) {
|
|
$res['teamId'] = $teamId;
|
|
}
|
|
$res['showLevel'] = $teamLevel;
|
|
$this->return_response($res);
|
|
}
|
|
|
|
public function index_put()
|
|
{
|
|
$params = $this->input_param();
|
|
$upData = [
|
|
'cluesLevel1' => $params['cluesLevel1'] ?: 0,
|
|
'cluesLevel2' => $params['cluesLevel2'] ?: 0,
|
|
'cluesLevel3' => $params['cluesLevel3'] ?: 0,
|
|
'cluesLevel4' => $params['cluesLevel4'] ?: 0,
|
|
'orderLevel1' => $params['orderLevel1'] ?: 0,
|
|
'orderLevel2' => $params['orderLevel2'] ?: 0,
|
|
'orderLevel3' => $params['orderLevel3'] ?: 0,
|
|
'orderLevel4' => $params['orderLevel4'] ?: 0,
|
|
];
|
|
if ($params['id']) {
|
|
$upData['createTime'] = date('Y-m-d H:i:s');
|
|
$this->mdOrganizationCmmssn->update($upData, ['id' => $params['id']]);
|
|
} else {
|
|
$upData['teamId'] = $params['teamId'];
|
|
$this->mdOrganizationCmmssn->add($upData);
|
|
}
|
|
|
|
$this->return_response();
|
|
}
|
|
|
|
public function index_post()
|
|
{
|
|
$parentId = intval($this->input_param('parentId'));
|
|
$title = $this->input_param('title');
|
|
if (!$title) {
|
|
$this->return_json('请输入名称');
|
|
}
|
|
$remark = $this->input_param('remark');
|
|
$imgs = getImageFromArray($this->input_param('logo'));
|
|
$level = 0;
|
|
if ($parentId) {
|
|
$level = $this->mdOrganization->getLevel($parentId);
|
|
$level += 1;
|
|
}
|
|
if ($level > 5) {
|
|
$this->return_json('最多只能添加4级');
|
|
}
|
|
if ($level > 1) {
|
|
if ($this->mdOrganization->get(['parentId' => $parentId, 'status' => 0])) {
|
|
$this->return_json('该节点下已有子节点');
|
|
}
|
|
}
|
|
$addData = ['parentId' => $parentId, 'title' => $title, 'level' => $level, 'createTime' => date('Y-m-d H:i:s')];
|
|
$remark && $addData['remark'] = $remark;
|
|
$imgs && $addData['logo'] = $imgs[0];
|
|
$id = $this->mdOrganization->add($addData);
|
|
if (!$id) {
|
|
$this->return_json('添加失败');
|
|
}
|
|
$this->return_response();
|
|
}
|
|
|
|
public function index_delete()
|
|
{
|
|
$id = intval($this->input_param('id'));
|
|
if (!$id) {
|
|
$this->return_json('参数错误');
|
|
}
|
|
$this->mdOrganization->update(['status' => -1], ['id' => $id]);
|
|
$this->return_response();
|
|
}
|
|
} |