221 lines
9.1 KiB
PHP
221 lines
9.1 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');
|
|
$this->load->model('market/Market_sylive_groups_user_model', 'mdSyliveGroupsUser');
|
|
$this->load->model('market/Market_sylive_user_model', 'mdSyliveUser');
|
|
}
|
|
|
|
/**
|
|
* 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['groupsLevel<>'] = $unGroupsType;
|
|
$sort_order = 'sortNumber asc,groupsId desc';
|
|
$fileds = 'activityId,groupsId,parentId,sortNumber,userFrom,groupsName,ifBiz,statisticsType,originalBizId';
|
|
$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]['userFrom'] = intval($v['userFrom']);
|
|
$res[$k]['parentId'] = intval($v['parentId']);
|
|
$res[$k]['sortNumber'] = intval($v['sortNumber']);
|
|
$res[$k]['ifBiz'] = intval($v['ifBiz']);
|
|
$res[$k]['statisticsType'] = $v['statisticsType'] ? intval($v['statisticsType']) : '';
|
|
$res[$k]['originalBizId'] = $v['originalBizId'] ? intval($v['originalBizId']) : '';
|
|
}
|
|
$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');
|
|
$userFrom = intval($this->input_param('userFrom'));
|
|
$sortNumber = intval($this->input_param('sortNumber'));
|
|
$ifBiz = intval($this->input_param('ifBiz'));
|
|
$statisticsType = intval($this->input_param('statisticsType'));
|
|
$originalBizId = intval($this->input_param('originalBizId'));
|
|
if (!$groupsName) {
|
|
$this->return_json('请输入分组名称');
|
|
}
|
|
$groupsLevel = 0;
|
|
if ($parentId) {//判断上级分组
|
|
$re_org = $this->mdSyliveGroups->get(['groupsId' => $parentId]);
|
|
if ($re_org['ifBiz']) {
|
|
$userFrom = $re_org['userFrom'] == 0 ? '门店' : '团队';
|
|
$this->return_json("选择的上级分组{$userFrom}不能保存,请重新选择");
|
|
}
|
|
$re_org['groupsLevel'] == 3 && $ifBiz = 1;//如果上级等级3级,当前分组设为门店
|
|
!$ifBiz && $groupsLevel = $re_org['groupsLevel'] + 1;
|
|
} else {
|
|
$re_org = $this->mdSyliveGroups->get(['parentId' => $parentId]);
|
|
if ($re_org) {
|
|
$this->return_json('请选择上级分组');
|
|
}
|
|
}
|
|
$originalBizId = $ifBiz ? $originalBizId : 0;
|
|
$addDate = ['activityId' => $activityId, 'parentId' => $parentId, 'originalBizId' => $originalBizId, 'groupsName' => $groupsName
|
|
, 'groupsLevel' => $groupsLevel, 'statisticsType' => $statisticsType, 'userFrom' => $userFrom, 'ifBiz' => $ifBiz
|
|
, 'sortNumber' => $sortNumber, 'createTime' => date('Y-m-d H:i:s')];
|
|
$groupsId = $this->mdSyliveGroups->add($addDate);
|
|
if (!$groupsId) {
|
|
$this->return_json('添加分组失败');
|
|
}
|
|
if ($originalBizId) {
|
|
$levelAry = $this->getLevelAry($groupsId);
|
|
$res = $this->mdSyliveUser->select(['bizId' => $originalBizId, 'status>=' => 0], 'userId asc', 0, 0
|
|
, 'userId,organizationId,bizId');
|
|
$addUser = [];
|
|
foreach ($res as $v) {
|
|
$re_user = $this->mdSyliveGroupsUser->get(['activityId' => $activityId, 'userId' => $v['userId'], 'status>=' => 0]);
|
|
if (!$re_user) {
|
|
$type = $v['bizId'] == $v['organizationId'] ? 1 : 0;
|
|
$value = ['userId' => $v['userId'], 'type' => $type, 'activityId' => $activityId
|
|
, 'groupsId' => $groupsId, 'userFrom' => $userFrom, 'createTime' => date('Y-m-d H:i:s')];
|
|
$data = array_merge($value, $levelAry);
|
|
$addUser[] = $data;
|
|
}
|
|
}
|
|
$addUser && $this->mdSyliveGroupsUser->add_batch($addUser);
|
|
}
|
|
$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');
|
|
$userFrom = intval($this->input_param('userFrom'));
|
|
$sortNumber = intval($this->input_param('sortNumber'));
|
|
$ifBiz = intval($this->input_param('ifBiz'));
|
|
$statisticsType = intval($this->input_param('statisticsType'));
|
|
$originalBizId = intval($this->input_param('originalBizId'));
|
|
if (!$groupsId) {
|
|
$this->return_json('参数错误');
|
|
}
|
|
if (!$groupsName) {
|
|
$this->return_json('请输入分组名称');
|
|
}
|
|
$re_gro = $this->mdSyliveGroups->get(['groupsId' => $groupsId]);
|
|
$activityId = intval($re_gro['activityId']);
|
|
if ($re_gro && $re_gro['parentId'] != $parentId) {
|
|
$re_user = $this->mdSyliveGroupsUser->get(['groupsId' => $groupsId, 'activityId' => $activityId]);
|
|
if ($re_user) {
|
|
$this->return_json('此分组已有用户,不能修改上级分组');
|
|
}
|
|
}
|
|
$groupsLevel = 0;
|
|
if ($parentId) {//判断上级分组
|
|
$re_org = $this->mdSyliveGroups->get(['groupsId' => $parentId]);
|
|
if ($re_org['ifBiz']) {
|
|
$userFrom = $re_org['userFrom'] == 0 ? '门店' : '团队';
|
|
$this->return_json("选择的上级分组{$userFrom}不能保存,请重新选择");
|
|
}
|
|
$re_org['groupsLevel'] == 3 && $ifBiz = 1;//如果上级等级3级,当前分组设为门店
|
|
!$ifBiz && $groupsLevel = $re_org['groupsLevel'] + 1;
|
|
} else {
|
|
$re_org = $this->mdSyliveGroups->get(['parentId' => $parentId, 'activityId' => $activityId]);
|
|
if ($re_org && $groupsId != $re_org['groupsId']) {
|
|
$this->return_json('请选择上级分组');
|
|
}
|
|
}
|
|
$originalBizId = $ifBiz ? $originalBizId : 0;
|
|
$upDate = ['parentId' => $parentId, 'originalBizId' => $originalBizId, 'groupsName' => $groupsName, 'groupsLevel' => $groupsLevel,
|
|
'statisticsType' => $statisticsType, 'userFrom' => $userFrom, 'ifBiz' => $ifBiz, '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();
|
|
}
|
|
|
|
/**
|
|
* Notes:获取分组等级ID
|
|
* Created on: 2022/11/30 14:30
|
|
* Created by: dengbw
|
|
* @param $groupsId
|
|
* @param array $data
|
|
* @return array
|
|
*/
|
|
private function getLevelAry($groupsId, $data = [])
|
|
{
|
|
$re = $this->mdSyliveGroups->get(['groupsId' => $groupsId], 'groupsId,parentId,groupsLevel,ifBiz');
|
|
if (!$re) {
|
|
return $data;
|
|
} else {
|
|
if ($re['groupsLevel']) {//分类id
|
|
$levelId = "levelId" . $re['groupsLevel'];
|
|
$data[$levelId] = $re['groupsId'];
|
|
}
|
|
if ($re['ifBiz']) {//门店id
|
|
$data['bizId'] = $re['groupsId'];
|
|
}
|
|
if ($re['parentId']) {
|
|
return $this->getLevelAry($re['parentId'], $data);
|
|
} else {
|
|
return $data;
|
|
}
|
|
}
|
|
}
|
|
|
|
} |