Files
liche/market/controllers/api/sylive/Groups.php
T
2022-11-25 17:56:47 +08:00

153 lines
5.5 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once APPPATH . 'controllers/api/BaseController.php';
/**
* Notes:私域直播_分组管理
* Created on: 2022/11/24 17:15
* Created by: dengbw
*/
class Groups extends BaseController
{
public function __construct()
{
parent::__construct();
$this->load->model('market/Market_sylive_groups_model', 'mdSyliveGroups');
}
/**
* Notes:获取分组
* Created on: 2022/9/16 11:11
* Created by: dengbw
*/
public function index_get()
{
$activityId = intval($this->input_param('activityId'));
$unGroupsType = $this->input_param('unGroupsType');
$where['status>='] = 0;
$activityId && $where['activityId'] = $activityId;
$unGroupsType && $where['groupsType<>'] = $unGroupsType;
$sort_order = 'sortNumber asc,groupsId desc';
$fileds = 'activityId,groupsId,parentId,sortNumber,userFrom,groupsName,groupsType';
$res = $this->mdSyliveGroups->select($where, $sort_order, 0, 0, $fileds);
foreach ($res as $k => $v) {
$res[$k]['activityId'] = intval($v['activityId']);
$res[$k]['groupsId'] = intval($v['groupsId']);
$res[$k]['parentId'] = intval($v['parentId']);
$res[$k]['sortNumber'] = intval($v['sortNumber']);
$res[$k]['userFrom'] = intval($v['userFrom']);
}
$this->return_response_list($res);
}
/**
* Notes:查找上级分组
* Created on: 2022/10/24 15:24
* Created by: dengbw
*/
public function parent_get()
{
$parentId = intval($this->input_param('parentId'));
$sort_order = 'sortNumber asc,groupsId desc';
$where['status>='] = 0;
$where['parentId'] = $parentId;
$res = $this->mdSyliveGroups->select($where, $sort_order, 0, 0, 'groupsId,groupsName');
$this->return_response_list($res);
}
/**
* Notes:添加分组
* Created on: 2022/9/19 16:43
* Created by: dengbw
*/
public function index_post()
{
$activityId = intval($this->input_param('activityId'));
$parentId = intval($this->input_param('parentId'));
$groupsName = $this->input_param('groupsName');
$groupsType = $this->input_param('groupsType');
$userFrom = intval($this->input_param('userFrom'));
$sortNumber = intval($this->input_param('sortNumber'));
if (!$groupsName) {
$this->return_json('请输入分组名称');
}
if (!$groupsType) {
$this->return_json('请选择分组类型');
}
if ($parentId) {//判断上级分组是不是门店类型
$re_org = $this->mdSyliveGroups->get(['groupsId' => $parentId]);
if ($re_org['groupsType'] == 4) {
$this->return_json('选择的上级分组不能保存,请重新选择');
}
} else {
$re_org = $this->mdSyliveGroups->get(['parentId' => $parentId]);
if ($re_org) {
$this->return_json('请选择上级分组');
}
}
$addDate = ['activityId' => $activityId, 'parentId' => $parentId, 'groupsName' => $groupsName, 'groupsType' => $groupsType, 'userFrom' => $userFrom,
'sortNumber' => $sortNumber, 'createTime' => date('Y-m-d H:i:s')];
$id = $this->mdSyliveGroups->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()
{
$groupsId = intval($this->input_param('groupsId'));
$parentId = intval($this->input_param('parentId'));
$groupsName = $this->input_param('groupsName');
$groupsType = $this->input_param('groupsType');
$userFrom = $this->input_param('userFrom');
$sortNumber = intval($this->input_param('sortNumber'));
if (!$groupsId) {
$this->return_json('参数错误');
}
if (!$groupsName) {
$this->return_json('请输入分组名称');
}
if (!$groupsType) {
$this->return_json('请选择分组类型');
}
if ($parentId) {//判断上级分组是不是门店类型
$re_org = $this->mdSyliveGroups->get(['groupsId' => $parentId]);
if ($re_org['groupsType'] == 4) {
$this->return_json('选择的上级分组不能保存,请重新选择');
}
} else {
$re_org = $this->mdSyliveGroups->get(['parentId' => $parentId]);
if ($re_org && $groupsId != $re_org['groupsId']) {
$this->return_json('请选择上级分组');
}
}
$upDate = ['parentId' => $parentId, 'groupsName' => $groupsName, 'groupsType' => $groupsType,
'userFrom' => $userFrom, 'sortNumber' => $sortNumber];
$this->mdSyliveGroups->update($upDate, ['groupsId' => $groupsId]);
$this->return_response();
}
/**
* Notes:删除分组
* Created on: 2022/9/19 11:08
* Created by: dengbw
* @param null $groupsId
*/
public function index_delete($groupsId = null)
{
$groupsId = intval($groupsId);
if (!$groupsId) {
$this->return_json('参数错误');
}
$this->mdSyliveGroups->update(['status' => -1], ['groupsId' => $groupsId]);
$this->return_response();
}
}