market_groups_1125

This commit is contained in:
dengbw
2022-12-07 17:35:53 +08:00
committed by lccsw
parent 0685cb840e
commit 7bb9402879
9 changed files with 1084 additions and 206 deletions
+56
View File
@@ -16,6 +16,62 @@ class Temp extends HD_Controller
$this->log_file = 'temp.log';
}
/**
* Notes:更新私域直播_用户门店
* Created on: 2022/3/09 11:58
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/plan/temp/market_sylive_user
* https://api.liche.cn/plan/temp/market_sylive_user
*/
public function market_sylive_user()
{
$this->load->model('market/Market_sylive_user_model', 'mdSyliveUser');
$this->load->model('market/Market_sylive_organization_model', 'mdSyliveOrganization');
$param = $this->input->get();
$param['page'] = intval($param['page']);
$param['size'] = intval($param['size']);
!$param['size'] && $param['size'] = 100;
!$param['page'] && $param['page'] = 1;
$counts = intval($param['counts']);
ob_start(); //打开缓冲区
$where = ["organizationId>" => 0];
$res = $this->mdSyliveUser->select($where, 'userId ASC', $param['page'], $param['size'], 'userId,organizationId');
if (!$res) {
echo '<br>本次更新用户门店完成了:';
echo '<br><br>成功更新 <span style="color: red;">' . $counts . '</span> 条';
echo '<br><br><a href="/plan/temp/market_sylive_user">点击将再次更新用户门店>>></a>';
exit;
}
$log = [];
foreach ($res as $key => $v) {
$re = $this->mdSyliveOrganization->get(['organizationId' => $v['organizationId']]
, 'organizationId,organizationType,parentId');
$bizId = 0;
if ($re) {
if ($re['organizationType'] == 4 && $re['parentId']) {
$bizId = $re['parentId'];
} else if ($re['organizationType'] == 3) {
$bizId = $re['organizationId'];
}
}
if ($bizId) {
$ret = $this->mdSyliveUser->update(['bizId' => $bizId], ['userId' => $v['userId']]);
if ($ret) {
$log[] = ['userId' => $v['userId'], 'bizId' => $bizId];
$counts++;
}
}
}
echo '<br>成功更新:';
if ($log) {
echo json_encode($log, JSON_UNESCAPED_UNICODE);
}
echo '<br><br>数据库获取:';
echo json_encode($res, JSON_UNESCAPED_UNICODE);
header('refresh:3;url=/plan/temp/market_sylive_user?counts=' . $counts . '&size=' . $param['size'] . '&page=' . ($param['page'] + 1));
ob_end_flush();//输出全部内容到浏览器
}
/**
* Notes:更新门店日志
* Created on: 2022/3/09 11:58
+56 -129
View File
@@ -18,6 +18,7 @@ class Activity extends BaseController
$this->load->model('market/Market_sylive_organization_model', 'mdSyliveOrganization');
$this->load->model('market/Market_sylive_team_model', 'mdSyliveTeam');
$this->load->model('market/Market_sylive_activity_team_model', 'mdSyliveActivityTeam');
$this->load->model('market/Market_sylive_groups_model', 'mdSyliveGroups');
}
/**
@@ -44,10 +45,9 @@ class Activity extends BaseController
if ($_SESSION['brandName']) {//品牌机构
$re_org = $this->mdSyliveOrganization->get(['organizationName' => $_SESSION['brandName'], 'parentId' => 0, 'status' => 0]);
if ($re_org['organizationId']) {
$organizationIds = ",{$re_org['organizationId']},";
$where['organizationIds LIKE "%' . $organizationIds . '%"'] = null;
$where['organizationId'] = $re_org['organizationId'];
} else {
$where['organizationIds'] = '-1';
$where['organizationId'] = -1;
}
}
$count = $this->mdSyliveActivity->count($where);
@@ -58,7 +58,7 @@ class Activity extends BaseController
$dateRange = [$v['timeStart'], $v['timeEnd']];
$status = intval($v['status']);
$activityId = intval($v['activityId']);
$bgImg = $channelImg = $banner = $sharePhoto = $shareImg = $shareTitle = $bizIds = $teamIds = $pay = [];
$bgImg = $channelImg = $banner = $sharePhoto = $shareImg = $shareTitle = $pay = $bottoms = [];
$item = ['activityId' => $activityId, 'itemImg' => [], 'title' => '', 'introduction' => '', 'price' => '', 'stock' => '', 'dateRange' => ''];
$coupon = ['activityId' => $activityId, 'img' => [], 'title' => '', 'rules' => '', 'price' => '', 'dateRange' => ''];
$pay = ['way' => 1, 'price' => '', 'img' => []];
@@ -121,27 +121,30 @@ class Activity extends BaseController
$shareImg[] = ['uid' => $k2, 'fileUrl' => $v2, 'url' => build_qiniu_image_url($v2), 'status' => 'done'];
}
}
$res_biz = $this->mdSyliveActivityBiz->select(['activityId' => $activityId, 'status' => 0], 'id desc', 0, 0, 'bizId');
if ($res_biz) {
foreach ($res_biz as $k2 => $v2) {
$bizIds[] = intval($v2['bizId']);
}
}
$res_team = $this->mdSyliveActivityTeam->select(['activityId' => $activityId, 'status' => 0], 'id desc', 0, 0, 'teamId2');
if ($res_team) {
foreach ($res_team as $k2 => $v2) {
$teamIds[] = intval($v2['teamId2']);
if ($jsondata['bottoms']) {
foreach ($jsondata['bottoms'] as $k2 => $v2) {
$icon = [];
if ($v2['icon']) {
$icon[] = ['uid' => $k2, 'fileUrl' => $v2['icon'], 'url' => build_qiniu_image_url($v2['icon']), 'status' => 'done'];
}
$v2['icon'] = $icon;
$bottoms[] = $v2;
}
}
$skey = $this->myencryption->base64url_encode("a_id=" . $activityId);
$url = http_host_com('home') . "/h5/market/sylive?skey=" . $skey;//活动连接
$serviceLink = $jsondata['serviceLink'] ? $jsondata['serviceLink'] : '';
$activityStart = $v['activityStart'] != '0000-00-00 00:00:00' ? $v['activityStart'] : '';
$organizationId = $v['organizationId'] ? intval($v['organizationId']) : '';
$groups = 0;
$re_gro = $this->mdSyliveGroups->get(['activityId' => $activityId, 'parentId' => 0, 'status>=' => 0]);
$re_gro && $groups = 1;
$list[] = [
'activityId' => $activityId, 'title' => $v['title'], 'channelId' => $v['channelId'], 'bizIds' => $bizIds, 'teamIds' => $teamIds, 'pay' => $pay,
'introduction' => $v['introduction'], 'shareTitle' => $shareTitle, 'dateRange' => $dateRange, 'coupon' => $coupon, 'drawCode' => $v['drawCode'],
'activityId' => $activityId, 'title' => $v['title'], 'channelId' => $v['channelId'], 'pay' => $pay, 'organizationId' => $organizationId,
'activityStart' => $activityStart, 'shareTitle' => $shareTitle, 'dateRange' => $dateRange, 'coupon' => $coupon, 'drawCode' => $v['drawCode'],
'bgImg' => $bgImg, 'channelImg' => $channelImg, 'banner' => $banner, 'sharePhoto' => $sharePhoto, 'shareImg' => $shareImg, 'item' => $item, 'url' => $url,
'mchId' => $v['mchId'], 'protocolTitle' => $v['protocolTitle'], 'protocol' => $v['protocol'], 'serviceLink' => $serviceLink
, 's_time' => $v['timeStart'], 'e_time' => $v['timeEnd'], 'status' => $status, 'createTime' => $v['createTime']];
'mchId' => $v['mchId'], 'protocolTitle' => $v['protocolTitle'], 'protocol' => $v['protocol'], 'serviceLink' => $serviceLink, 'bottoms' => $bottoms
, 's_time' => $v['timeStart'], 'e_time' => $v['timeEnd'], 'status' => $status, 'groups' => $groups, 'createTime' => $v['createTime']];
}
}
$date = ['list' => $list, 'count' => $count];
@@ -158,14 +161,12 @@ class Activity extends BaseController
$title = $this->input_param('title');
$channelId = $this->input_param('channelId');
$dateRange = $this->input_param('dateRange');
$introduction = $this->input_param('introduction');
$shareTitle = $this->input_param('shareTitle');
$shareImg = $this->input_param('shareImg');
$bgImg = $this->input_param('bgImg');
$channelImg = $this->input_param('channelImg');
$sharePhoto = $this->input_param('sharePhoto');
$bizIds = $this->input_param('bizIds');
$teamIds = $this->input_param('teamIds');
$organizationId = intval($this->input_param('organizationId'));
$pay = $this->input_param('pay');
$drawCode = $this->input_param('drawCode');
$banner = $this->input_param('banner');
@@ -173,6 +174,8 @@ class Activity extends BaseController
$protocolTitle = $this->input_param('protocolTitle');
$protocol = $this->input_param('protocol');
$serviceLink = $this->input_param('serviceLink');
$activityStart = $this->input_param('activityStart');
$bottoms = $this->input_param('bottoms');
if (!$title) {
$this->return_json('请输入活动标题');
}
@@ -191,9 +194,6 @@ class Activity extends BaseController
$this->return_json('抽奖码已存在');
}
}
// if (!$introduction) {
// $this->return_json('请输入活动简介');
// }
$bgImg = $bgImg[0]['fileUrl'];
$sharePhoto = $sharePhoto ? $sharePhoto[0]['fileUrl'] : '';
$channelImg = $channelImg ? $channelImg[0]['fileUrl'] : '';
@@ -214,59 +214,32 @@ class Activity extends BaseController
$jsondata['pay'] = $pay;
$jsondata['banner'] = $banner;
$jsondata['serviceLink'] = $serviceLink;
$setBottoms = [];
foreach ($bottoms as $v) {
if ($v['urlType'] == 'link') {
$v['miniProgramId'] = '';
}
$v['icon'] = $v['icon'][0]['fileUrl'] ? $v['icon'][0]['fileUrl'] : '';
$setBottoms[] = $v;
}
$jsondata['bottoms'] = $setBottoms;
$jsondata = json_encode($jsondata, JSON_UNESCAPED_UNICODE);
$createTime = date('Y-m-d H:i:s');
$addDate = ['title' => $title, 'bgImg' => $bgImg, 'channelImg' => $channelImg, 'channelId' => $channelId, 'jsondata' => $jsondata
, 'introduction' => $introduction, 'shareTitle' => $shareTitle, 'sharePhoto' => $sharePhoto, 'shareImg' => $setShareImg
, 'drawCode' => $drawCode, 'mchId' => $mchId, 'protocolTitle' => $protocolTitle, 'protocol' => $protocol
, 'timeStart' => $dateRange[0], 'timeEnd' => $dateRange[1], 'status' => 1, 'createTime' => date('Y-m-d H:i:s')];
, 'shareTitle' => $shareTitle, 'sharePhoto' => $sharePhoto, 'shareImg' => $setShareImg, 'organizationId' => $organizationId
, 'drawCode' => $drawCode, 'mchId' => $mchId, 'protocolTitle' => $protocolTitle, 'protocol' => $protocol, 'activityStart' => $activityStart
, 'timeStart' => $dateRange[0], 'timeEnd' => $dateRange[1], 'status' => 1, 'createTime' => $createTime];
$activityId = $this->mdSyliveActivity->add($addDate);
if (!$activityId) {
$this->return_json('添加活动失败');
}
$organizationIds = $add_biz = $add_team = [];
if ($bizIds) {
$bizIds = implode(',', $bizIds);
$res_org = $this->mdSyliveOrganization->select(["organizationId in({$bizIds})" => null, 'organizationType' => 3]
, 'organizationId desc', 0, 0, 'organizationId,parentId');
if ($res_org) {
$this->mdSyliveActivityBiz->update(['status' => -1], ["bizId not in({$bizIds})" => null, 'activityId' => $activityId, 'status' => 0]);
foreach ($res_org as $v) {
$add_biz[] = ['activityId' => $activityId, 'areaId' => $v['parentId']
, 'bizId' => $v['organizationId'], 'createTime' => date('Y-m-d H:i:s')];
if ($v['parentId']) {
$re_org = $this->mdSyliveOrganization->get(["organizationId" => $v['parentId']]);
if ($re_org['parentId'] && !in_array($re_org['parentId'], $organizationIds)) {
$organizationIds[] = $re_org['parentId'];//所属机构
}
}
}
//增加活动商家
$add_biz && $this->mdSyliveActivityBiz->add_batch($add_biz);
if ($organizationId) {
$re = $this->mdSyliveOrganization->get(['organizationId' => $organizationId, 'status' => 0]);
if ($re['organizationName']) {//加顶级分组
$this->mdSyliveGroups->add(['groupsName' => $re['organizationName'], 'activityId' => $activityId,
'statisticsType' => 4, 'createTime' => $createTime]);
}
}
if ($teamIds) {
$teamIds = implode(',', $teamIds);
$res_org = $this->mdSyliveTeam->select(["teamId in({$teamIds})" => null, 'teamType' => 2], 'teamId desc', 0, 0, 'teamId,parentId');
if ($res_org) {
$this->mdSyliveActivityTeam->update(['status' => -1], ["teamId2 not in({$teamIds})" => null, 'activityId' => $activityId, 'status' => 0]);
foreach ($res_org as $v) {
$add_team[] = ['activityId' => $activityId, 'teamId1' => $v['parentId']
, 'teamId2' => $v['teamId'], 'createTime' => date('Y-m-d H:i:s')];
if ($v['parentId']) {
$re_team = $this->mdSyliveTeam->get(["teamId" => $v['parentId']]);
if ($re_team['organizationId'] && !in_array($re_team['organizationId'], $organizationIds)) {
$organizationIds[] = $re_team['organizationId'];
}
}
}
//增加活动商家
$add_team && $this->mdSyliveActivityTeam->add_batch($add_team);
}
}
if ($organizationIds) {//所属机构
$organizationIds = ',' . implode(',', $organizationIds) . ',';
$this->mdSyliveActivity->update(['organizationIds' => $organizationIds], ['activityId' => $activityId]);
}
$this->return_response();
}
@@ -299,14 +272,11 @@ class Activity extends BaseController
$title = $this->input_param('title');
$channelId = $this->input_param('channelId');
$dateRange = $this->input_param('dateRange');
$introduction = $this->input_param('introduction');
$shareTitle = $this->input_param('shareTitle');
$shareImg = $this->input_param('shareImg');
$bgImg = $this->input_param('bgImg');
$channelImg = $this->input_param('channelImg');
$sharePhoto = $this->input_param('sharePhoto');
$bizIds = $this->input_param('bizIds');
$teamIds = $this->input_param('teamIds');
$pay = $this->input_param('pay');
$drawCode = $this->input_param('drawCode');
$banner = $this->input_param('banner');
@@ -314,6 +284,9 @@ class Activity extends BaseController
$protocolTitle = $this->input_param('protocolTitle');
$protocol = $this->input_param('protocol');
$serviceLink = $this->input_param('serviceLink');
$organizationId = intval($this->input_param('organizationId'));
$activityStart = $this->input_param('activityStart');
$bottoms = $this->input_param('bottoms');
if (!$activityId) {
$this->return_json('参数错误');
}
@@ -341,60 +314,6 @@ class Activity extends BaseController
}
}
}
$organizationIds = $add_biz = $add_team = [];
if ($bizIds) {
$bizIds = implode(',', $bizIds);
$res_org = $this->mdSyliveOrganization->select(["organizationId in({$bizIds})" => null, 'organizationType' => 3]
, 'organizationId desc', 0, 0, 'organizationId,parentId');
if ($res_org) {
$this->mdSyliveActivityBiz->update(['status' => -1], ["bizId not in({$bizIds})" => null, 'activityId' => $activityId, 'status' => 0]);
foreach ($res_org as $v) {
$re_org = $this->mdSyliveActivityBiz->get(['activityId' => $activityId, 'bizId' => $v['organizationId']]);
if (!$re_org) {
$add_biz[] = ['activityId' => $activityId, 'areaId' => $v['parentId']
, 'bizId' => $v['organizationId'], 'createTime' => date('Y-m-d H:i:s')];
} else if ($re_org['status'] == -1) {
$this->mdSyliveActivityBiz->update(['status' => 0], ['id' => $re_org['id']]);
}
if ($v['parentId']) {
$re_org = $this->mdSyliveOrganization->get(["organizationId" => $v['parentId']]);
if ($re_org['parentId'] && !in_array($re_org['parentId'], $organizationIds)) {
$organizationIds[] = $re_org['parentId'];//所属机构
}
}
}
//增加活动商家
$add_biz && $this->mdSyliveActivityBiz->add_batch($add_biz);
}
} else {
$this->mdSyliveActivityBiz->update(['status' => -1], ['activityId' => $activityId, 'status' => 0]);
}
if ($teamIds) {
$teamIds = implode(',', $teamIds);
$res_org = $this->mdSyliveTeam->select(["teamId in({$teamIds})" => null, 'teamType' => 2], 'teamId desc', 0, 0, 'teamId,parentId');
if ($res_org) {
$this->mdSyliveActivityTeam->update(['status' => -1], ["teamId2 not in({$teamIds})" => null, 'activityId' => $activityId, 'status' => 0]);
foreach ($res_org as $v) {
$re_org = $this->mdSyliveActivityTeam->get(['activityId' => $activityId, 'teamId2' => $v['teamId']]);
if (!$re_org) {
$add_team[] = ['activityId' => $activityId, 'teamId1' => $v['parentId']
, 'teamId2' => $v['teamId'], 'createTime' => date('Y-m-d H:i:s')];
} else if ($re_org['status'] == -1) {
$this->mdSyliveActivityTeam->update(['status' => 0], ['id' => $re_org['id']]);
}
if ($v['parentId']) {
$re_team = $this->mdSyliveTeam->get(["teamId" => $v['parentId']]);
if ($re_team['organizationId'] && !in_array($re_team['organizationId'], $organizationIds)) {
$organizationIds[] = $re_team['organizationId'];
}
}
}
//增加活动商家
$add_team && $this->mdSyliveActivityTeam->add_batch($add_team);
}
} else {
$this->mdSyliveActivityTeam->update(['status' => -1], ['activityId' => $activityId, 'status' => 0]);
}
$bgImg = $bgImg[0]['fileUrl'];
$sharePhoto = $sharePhoto ? $sharePhoto[0]['fileUrl'] : '';
$channelImg = $channelImg ? $channelImg[0]['fileUrl'] : '';
@@ -416,12 +335,20 @@ class Activity extends BaseController
$jsondata['pay'] = $pay;
$jsondata['banner'] = $banner;
$jsondata['serviceLink'] = $serviceLink;
$setBottoms = [];
foreach ($bottoms as $v) {
if ($v['urlType'] == 'link') {
$v['miniProgramId'] = '';
}
$v['icon'] = $v['icon'][0]['fileUrl'] ? $v['icon'][0]['fileUrl'] : '';
$setBottoms[] = $v;
}
$jsondata['bottoms'] = $setBottoms;
$jsondata = json_encode($jsondata, JSON_UNESCAPED_UNICODE);
$organizationIds = $organizationIds ? ',' . implode(',', $organizationIds) . ',' : '';
$upDate = ['title' => $title, 'bgImg' => $bgImg, 'channelImg' => $channelImg, 'channelId' => $channelId, 'introduction' => $introduction,
$upDate = ['title' => $title, 'bgImg' => $bgImg, 'channelImg' => $channelImg, 'channelId' => $channelId, 'activityStart' => $activityStart,
'shareTitle' => $shareTitle, 'sharePhoto' => $sharePhoto, 'shareImg' => $setShareImg, 'jsondata' => $jsondata,
'drawCode' => $drawCode, 'mchId' => $mchId, 'protocolTitle' => $protocolTitle, 'protocol' => $protocol,
'timeStart' => $dateRange[0], 'timeEnd' => $dateRange[1], 'organizationIds' => $organizationIds];
'timeStart' => $dateRange[0], 'timeEnd' => $dateRange[1], 'organizationId' => $organizationId];
$this->mdSyliveActivity->update($upDate, ['activityId' => $activityId]);
$this->return_response();
}
+40 -24
View File
@@ -27,16 +27,18 @@ class Groups extends BaseController
$unGroupsType = $this->input_param('unGroupsType');
$where['status>='] = 0;
$activityId && $where['activityId'] = $activityId;
$unGroupsType && $where['groupsType<>'] = $unGroupsType;
$unGroupsType && $where['groupsLevel<>'] = $unGroupsType;
$sort_order = 'sortNumber asc,groupsId desc';
$fileds = 'activityId,groupsId,parentId,sortNumber,userFrom,groupsName,groupsType';
$fileds = 'activityId,groupsId,parentId,sortNumber,userFrom,groupsName,ifBiz,statisticsType';
$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]['userFrom'] = intval($v['userFrom']);
$res[$k]['ifBiz'] = intval($v['ifBiz']);
$res[$k]['statisticsType'] = $v['statisticsType'] ? intval($v['statisticsType']) : '';
}
$this->return_response_list($res);
}
@@ -66,28 +68,31 @@ class Groups extends BaseController
$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'));
$ifBiz = intval($this->input_param('ifBiz'));
$statisticsType = intval($this->input_param('statisticsType'));
if (!$groupsName) {
$this->return_json('请输入分组名称');
}
if (!$groupsType) {
$this->return_json('请选择分组类型');
}
if ($parentId) {//判断上级分组是不是门店类型
$groupsLevel = 0;
if ($parentId) {//判断上级分组
$re_org = $this->mdSyliveGroups->get(['groupsId' => $parentId]);
if ($re_org['groupsType'] == 4) {
$this->return_json('选择的上级分组不能保存,请重新选择');
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('请选择上级分组');
}
}
$addDate = ['activityId' => $activityId, 'parentId' => $parentId, 'groupsName' => $groupsName, 'groupsType' => $groupsType, 'userFrom' => $userFrom,
'sortNumber' => $sortNumber, 'createTime' => date('Y-m-d H:i:s')];
$addDate = ['activityId' => $activityId, 'parentId' => $parentId, 'groupsName' => $groupsName, 'groupsLevel' => $groupsLevel,
'statisticsType' => $statisticsType, 'userFrom' => $userFrom, 'ifBiz' => $ifBiz, 'sortNumber' => $sortNumber
, 'createTime' => date('Y-m-d H:i:s')];
$id = $this->mdSyliveGroups->add($addDate);
if (!$id) {
$this->return_json('添加分组失败');
@@ -102,34 +107,45 @@ class Groups extends BaseController
*/
public function index_put()
{
$activityId = intval($this->input_param('activityId'));
$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');
$userFrom = intval($this->input_param('userFrom'));
$sortNumber = intval($this->input_param('sortNumber'));
$ifBiz = intval($this->input_param('ifBiz'));
$statisticsType = intval($this->input_param('statisticsType'));
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('选择的上级分组不能保存,请重新选择');
$re_gro = $this->mdSyliveGroups->get(['groupsId' => $groupsId]);
if ($re_gro && $re_gro['parentId'] != $parentId) {
$this->load->model('market/Market_sylive_groups_user_model', 'mdSyliveGroupsUser');
$re_user = $this->mdSyliveGroupsUser->get(['groupsId' => $groupsId, 'activityId' => $re_gro['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]);
$re_org = $this->mdSyliveGroups->get(['parentId' => $parentId, 'activityId' => $activityId]);
if ($re_org && $groupsId != $re_org['groupsId']) {
$this->return_json('请选择上级分组');
}
}
$upDate = ['parentId' => $parentId, 'groupsName' => $groupsName, 'groupsType' => $groupsType,
'userFrom' => $userFrom, 'sortNumber' => $sortNumber];
$upDate = ['parentId' => $parentId, 'groupsName' => $groupsName, 'groupsLevel' => $groupsLevel,
'statisticsType' => $statisticsType, 'userFrom' => $userFrom, 'ifBiz' => $ifBiz, 'sortNumber' => $sortNumber];
$this->mdSyliveGroups->update($upDate, ['groupsId' => $groupsId]);
$this->return_response();
}
@@ -0,0 +1,682 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once APPPATH . 'controllers/api/BaseController.php';
/**
* Notes:私域直播_分组数据统计
* Created on: 2022/12/05 17:15
* Created by: dengbw
*/
class GroupsStatistics 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');
$this->load->model('market/Market_sylive_activity_kpidata_model', 'mdSyliveActivityKpidata');
$this->load->model('market/Market_sylive_activity_model', 'mdSyliveActivity');
$this->load->model('market/Market_sylive_order_model', 'mdSyliveOrder');
$this->load->model('market/Market_sylive_items_model', 'mdSyliveItems');
$this->load->model('market/Market_sylive_viewlog_model', 'mdSyliveViewlog');
$this->load->model('live/Live_polyv_session_model', 'mdPolyvSession');
}
/**
* Notes:分组数据统计主页
* Created on: 2022/12/05 14:48
* Created by: dengbw
*/
public function index_get($activityId = null)
{
$activityId = intval($activityId);
if (!$activityId) {
$this->return_json('参数错误');
}
$title = '';
$activityData1 = $activityData2 = $areaAry = $funnel = $allOrganizationIds = $levelData = [];
$days[] = ['name' => '全部日期', 'value' => ''];
$goods[] = ['name' => '全部订单', 'value' => ''];
$re = $this->mdSyliveActivity->get(['activityId' => $activityId]);
if ($re) {
$res_item = $this->mdSyliveItems->select(['status>=' => 0, 'activityId' => $activityId], 'sort asc,itemId desc'
, 0, 0, 'itemId,title');
foreach ($res_item as $k => $v) {
$goods[] = ['name' => $v['title'], 'value' => intval($v['itemId'])];
}
if ($re['timeEnd'] != '0000-00-00 00:00:00') {
$timeEnd = date("Y-m-d", strtotime($re['timeEnd']));
for ($i = 6; $i >= 0; $i--) {
$day = date("Y-m-d", strtotime("$timeEnd -{$i} day"));
$days[] = ['name' => $day, 'value' => $day];
}
}
$title = $re['title'];
$channelId = $re['channelId'];
$browse = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'kpi' => 'browse']);
$subscribe = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'kpi' => 'subscribe']);
$watch = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'kpi' => 'watch']);
$order = $this->mdSyliveOrder->count(['activityId' => $activityId, 'status' => 1]);
$duration_min = $livePV = $liveUV = $watchDuration = $watchDuration = $pvDuration = 0;
if ($channelId) {
$re_duration = $this->mdPolyvSession->sum('duration', ['channelId' => $channelId]);
if ($re_duration['duration']) {
$re_livePV = $this->mdPolyvSession->sum('livePV', ['channelId' => $channelId]);
$re_liveUV = $this->mdPolyvSession->sum('liveUV', ['channelId' => $channelId]);
$livePV = $re_livePV['livePV'];
$liveUV = $re_liveUV['liveUV'];
$re_totalPlayDuration = $this->mdPolyvSession->sum('totalPlayDuration', ['channelId' => $channelId]);
$duration_min = round($re_duration['duration'] / 60);
$totalPlayDuration_min = round($re_totalPlayDuration['totalPlayDuration'] / 60);
$watchDuration = round($totalPlayDuration_min / $liveUV);
$pvDuration = round($livePV / $liveUV, 1);
}
}
$consultant = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId], 'cfUserId');
$allConsultant = $this->mdSyliveGroupsUser->count(['activityId' => $activityId, 'status>=' => 0]);
$consultant > $allConsultant && $allConsultant = $consultant;
$bizs = $this->mdSyliveGroups->count(['activityId' => $activityId, 'ifBiz' => 1, 'status>=' => 0]);
$activityData1 = [['name' => '参与门店数', 'value' => $bizs]
, ['name' => '参与/全部顾问数', 'value' => $consultant . '/' . $allConsultant]];
$watch_un = 0;
if ($liveUV) {
$watch_un = $watch - $liveUV;
$watch_un < 0 && $watch_un = 0;
}
$activityData2 = [['name' => '浏览数(人)', 'value' => $browse, 'url' => ''], ['name' => '预约数(人)', 'value' => $subscribe, 'url' => '']
, ['name' => '订单数(单)', 'value' => $order, 'url' => ''], ['name' => '有效观看(人)', 'value' => $liveUV, 'url' => ''], ['name' => '无效观看(人)', 'value' => $watch_un, 'url' => '']
, ['name' => '直播时长(分)', 'value' => $duration_min, 'url' => ''], ['name' => '观看数(人次)', 'value' => $livePV, 'url' => '']
, ['name' => '人均观看(分)', 'value' => $watchDuration, 'url' => ''], ['name' => '人均观看(次)', 'value' => $pvDuration, 'url' => '']];
}
$re_gro = $this->mdSyliveGroups->get(['activityId' => $activityId, 'parentId' => 0, 'status>=' => 0]);
if ($re_gro['statisticsType']) {
$this->load->model('market/Market_sys_dictionary_data_model', 'mdSysDictionaryData');
$res_dit = $this->mdSysDictionaryData->select(['status>=' => 0, 'dictId' => $re_gro['statisticsType']], 'sortNumber asc,dictDataId desc'
, 0, 0, 'dictDataCode,dictDataName');
foreach ($res_dit as $k => $v) {
$groupsLevel = intval($v['dictDataCode']);
$re_gro = $this->mdSyliveGroups->get(['activityId' => $activityId, 'groupsLevel' => $groupsLevel, 'status>=' => 0]);
if ($re_gro) {
$levelData[] = ['title' => $v['dictDataName'].'统计', 'value' => $groupsLevel];
}
}
}
$data = ['activityId' => $activityId, 'title' => $title, 'activityData1' => ['list' => $activityData1, 'style' => 'width: 50%']
, 'activityData2' => ['list' => $activityData2, 'style' => 'width: 11.1%'], 'tableData' => ['days' => $days, 'goods' => $goods]
, 'levelData' => $levelData
];
$this->return_response($data);
}
/**
* Notes:分组等级数据统计
* Created on: 2022/12/5 17:50
* Created by: dengbw
*/
public function level_get()
{
$activityId = intval($this->input_param('activityId'));
$sort = $this->input_param('sort');
$order = $this->input_param('order');
$day = $this->input_param('day');//日期
$itemId = intval($this->input_param('itemId'));//商品
$groupsLevel = intval($this->input_param('level'));//等级
$levelId = "levelId" . $groupsLevel;
$list = [];
$count = 0;
$page = 1;
$limit = 50;
$re = $this->mdSyliveActivity->get(['activityId' => $activityId]);
if ($re) {
$channelId = intval($re['channelId']);
!$sort && $sort = 'browse';
!$order && $order = 'desc';
if ($sort == 'order' && !$day) {
$sort_order = 'orderTotal ' . $order;
} else {
$sort_order = $sort . ' ' . $order;
}
if ($day) {//按天搜索
$createTimeStart = strtotime($day . ' 00:00:00');
$createTimeEnd = strtotime($day . ' 23:59:59');
$where = $where_order = $where_sort = ['activityId' => $activityId, 'day' => $day, "$levelId>" => 0, 'kpi' => $sort];
if ($sort == 'order') {
$itemId && $where['itemId'] = $itemId;
}
$count = $this->mdSyliveActivityKpidata->count($where, $levelId);
if ($count) {
$res = $this->mdSyliveActivityKpidata->select_groupby($levelId, $where, "total {$order},id desc", $page, $limit, "$levelId,count(id) as total");
foreach ($res as $v) {
$groupsId = intval($v[$levelId]);
$re_gro = $this->mdSyliveGroups->get(['groupsId' => $groupsId, 'activityId' => $activityId, 'status>=' => 0]);
$groupsName = $re_gro ? $re_gro['groupsName'] : '-';
$where_sort[$levelId] = $groupsId;
if ($sort == 'browse') {
$browse = $v['total'];
} else {
$where_sort['kpi'] = 'browse';
$browse = $this->mdSyliveActivityKpidata->count($where_sort);
}
if ($sort == 'subscribe') {
$subscribe = $v['total'];
} else {
$where_sort['kpi'] = 'subscribe';
$subscribe = $this->mdSyliveActivityKpidata->count($where_sort);
}
if ($sort == 'watch') {
$watch = $v['total'];
} else {
$where_sort['kpi'] = 'watch';
$watch = $this->mdSyliveActivityKpidata->count($where_sort);
}
if ($sort == 'order') {
$orderTotal = $v['total'];
} else {
$where_order['kpi'] = 'order';
$where_order[$levelId] = $groupsId;
$itemId && $where_order['itemId'] = $itemId;
$orderTotal = $this->mdSyliveActivityKpidata->count($where_order);
}
$consultant = $this->mdSyliveActivityKpidata->count([$levelId => $groupsId, 'activityId' => $activityId], 'cfUserId');
$allConsultant = $this->mdSyliveGroupsUser->count([$levelId => $groupsId, 'activityId' => $activityId, 'status>=' => 0]);
$consultant > $allConsultant && $allConsultant = $consultant;
$livePV = $watchDuration = 0;
if ($channelId) {
$livePV = $this->mdSyliveViewlog->count([$levelId => $groupsId, 'activityId' => $activityId
, 'createTime>=' => $createTimeStart, 'createTime<=' => $createTimeEnd]);
$re_sum = $this->mdSyliveViewlog->sum('playDuration', [$levelId => $groupsId, 'activityId' => $activityId
, 'createTime>=' => $createTimeStart, 'createTime<=' => $createTimeEnd]);
if ($re_sum['playDuration']) {
$playDuration = ceil($re_sum['playDuration'] / 60);
$watchDuration = round($playDuration / $livePV);
}
}
$biz = $this->getBiz($groupsId);
$list[] = [
'groupsName' => $groupsName, 'biz' => $biz, 'consultant' => $consultant, 'allConsultant' => $allConsultant, 'browse' => $browse, 'subscribe' => $subscribe
, 'watch' => $watch, 'order' => $orderTotal, 'livePV' => $livePV, 'watchDuration' => $watchDuration];
}
}
} else {
if ($sort == 'order' && $itemId) {//有订单排序与商品id,区分订单搜索
$where = ['activityId' => $activityId, 'itemId' => $itemId, "$levelId>" => 0, 'kpi' => $sort];
$count = $this->mdSyliveActivityKpidata->count($where, 'bizId');
} else {
$where = ['activityId' => $activityId, 'status>=' => 0, 'groupsLevel' => $groupsLevel];
$count = $this->mdSyliveGroups->count($where);
}
if ($count) {
if ($sort == 'order' && $itemId) {//有订单排序与商品id,区分订单搜索
$res = $this->mdSyliveActivityKpidata->select_groupby($levelId, $where, "orderTotal {$order},id desc"
, $page, $limit, "$levelId,count(id) as orderTotal");
} else {
$res = $this->mdSyliveGroups->select($where, "{$sort_order},groupsId desc", $page, $limit,
'groupsId,groupsName,browse,subscribe,watch,orderTotal');
}
foreach ($res as $v) {
if ($sort == 'order' && $itemId) {//只改变订单数值,其它不变
$groupsId = intval($v[$levelId]);
$re_gro = $this->mdSyliveGroups->get(['groupsId' => $groupsId, 'activityId' => $activityId, 'status>=' => 0]);
$groupsName = $re_gro ? $re_gro['groupsName'] : '-';
$v['browse'] = intval($re_gro['browse']);
$v['subscribe'] = intval($re_gro['subscribe']);
$v['watch'] = intval($re_gro['watch']);
} else {
$groupsId = intval($v['groupsId']);
$groupsName = $v['groupsName'] ? $v['groupsName'] : '-';
}
$consultant = $this->mdSyliveActivityKpidata->count([$levelId => $groupsId, 'activityId' => $activityId], 'cfUserId');
$allConsultant = $this->mdSyliveGroupsUser->count([$levelId => $groupsId, 'activityId' => $activityId, 'status>=' => 0]);
$consultant > $allConsultant && $allConsultant = $consultant;
$livePV = $watchDuration = 0;
if ($channelId) {
$livePV = $this->mdSyliveViewlog->count([$levelId => $groupsId, 'activityId' => $activityId]);
$re_sum = $this->mdSyliveViewlog->sum('playDuration', [$levelId => $groupsId, 'activityId' => $activityId]);
if ($re_sum['playDuration']) {
$playDuration = ceil($re_sum['playDuration'] / 60);
$watchDuration = round($playDuration / $livePV);
}
}
if ($sort != 'order' && $itemId) {//有商品id,区分订单
$order = $this->mdSyliveActivityKpidata->count(['kpi' => 'order', $levelId => $groupsId, 'itemId' => $itemId, 'activityId' => $activityId]);
} else {
$order = $v['orderTotal'];
}
$biz = $this->getBiz($groupsId);
$list[] = [
'groupsName' => $groupsName, 'biz' => $biz, 'consultant' => $consultant, 'allConsultant' => $allConsultant, 'browse' => $v['browse'], 'subscribe' => $v['subscribe']
, 'watch' => $v['watch'], 'order' => $order, 'livePV' => $livePV, 'watchDuration' => $watchDuration];
}
}
}
}
$date = ['list' => $list, 'count' => $count];
$this->return_response_list($date);
}
/**
* Notes:分组门店统计
* Created on: 2022/12/05 14:48
* Created by: dengbw
*/
public function biz_get()
{
$activityId = intval($this->input_param('activityId'));
$page = $this->input_param('page');
$limit = $this->input_param('limit');
$sort = $this->input_param('sort');
$order = $this->input_param('order');
$day = $this->input_param('day');
$itemId = intval($this->input_param('itemId'));//商品
!$page && $page = 1;
!$limit && $limit = 10;
$list = [];
$count = 0;
$re = $this->mdSyliveActivity->get(['activityId' => $activityId]);
if ($re) {
$channelId = intval($re['channelId']);
!$sort && $sort = 'browse';
!$order && $order = 'desc';
if ($sort == 'order' && !$day) {
$sort_order = 'orderTotal ' . $order;
} else {
$sort_order = $sort . ' ' . $order;
}
if ($day) {//按天搜索
$createTimeStart = strtotime($day . ' 00:00:00');
$createTimeEnd = strtotime($day . ' 23:59:59');
$where = $where_order = $where_sort = ['activityId' => $activityId, 'day' => $day, 'bizId>' => 0, 'kpi' => $sort];
if ($sort == 'order') {
$itemId && $where['itemId'] = $itemId;
}
$count = $this->mdSyliveActivityKpidata->count($where, 'bizId');
if ($count) {
$res = $this->mdSyliveActivityKpidata->select_groupby('bizId', $where, "total {$order},id desc", $page, $limit, "bizId,count(id) as total");
foreach ($res as $v) {
$bizId = intval($v['bizId']);
$re_biz = $this->mdSyliveGroups->get(['groupsId' => $bizId, 'activityId' => $activityId, 'status>=' => 0]);
$bizName = $re_biz ? $re_biz['groupsName'] : '-';
$where_sort['bizId'] = $bizId;
if ($sort == 'browse') {
$browse = $v['total'];
} else {
$where_sort['kpi'] = 'browse';
$browse = $this->mdSyliveActivityKpidata->count($where_sort);
}
if ($sort == 'subscribe') {
$subscribe = $v['total'];
} else {
$where_sort['kpi'] = 'subscribe';
$subscribe = $this->mdSyliveActivityKpidata->count($where_sort);
}
if ($sort == 'watch') {
$watch = $v['total'];
} else {
$where_sort['kpi'] = 'watch';
$watch = $this->mdSyliveActivityKpidata->count($where_sort);
}
if ($sort == 'order') {
$orderTotal = $v['total'];
} else {
$where_order['kpi'] = 'order';
$where_order['bizId'] = $bizId;
$itemId && $where_order['itemId'] = $itemId;
$orderTotal = $this->mdSyliveActivityKpidata->count($where_order);
}
$consultant = $this->mdSyliveActivityKpidata->count(['bizId' => $bizId, 'activityId' => $activityId], 'cfUserId');
$allConsultant = $this->mdSyliveGroupsUser->count(['bizId' => $bizId, 'activityId' => $activityId, 'status>=' => 0]);
$consultant > $allConsultant && $allConsultant = $consultant;
$livePV = $watchDuration = 0;
if ($channelId) {
$livePV = $this->mdSyliveViewlog->count(['bizId' => $bizId, 'activityId' => $activityId
, 'createTime>=' => $createTimeStart, 'createTime<=' => $createTimeEnd]);
$re_sum = $this->mdSyliveViewlog->sum('playDuration', ['bizId' => $bizId, 'activityId' => $activityId
, 'createTime>=' => $createTimeStart, 'createTime<=' => $createTimeEnd]);
if ($re_sum['playDuration']) {
$playDuration = ceil($re_sum['playDuration'] / 60);
$watchDuration = round($playDuration / $livePV);
}
}
$list[] = [
'bizName' => $bizName, 'consultant' => $consultant, 'allConsultant' => $allConsultant, 'browse' => $browse, 'subscribe' => $subscribe
, 'watch' => $watch, 'order' => $orderTotal, 'livePV' => $livePV, 'watchDuration' => $watchDuration];
}
}
} else {
if ($sort == 'order' && $itemId) {//有订单排序与商品id,区分订单搜索
$where = ['activityId' => $activityId, 'itemId' => $itemId, 'bizId>' => 0, 'kpi' => $sort];
$count = $this->mdSyliveActivityKpidata->count($where, 'bizId');
} else {
$where = ['activityId' => $activityId, 'status>=' => 0, 'ifBiz' => 1];
$count = $this->mdSyliveGroups->count($where);
}
if ($count) {
if ($sort == 'order' && $itemId) {//有订单排序与商品id,区分订单搜索
$res = $this->mdSyliveActivityKpidata->select_groupby('bizId', $where, "orderTotal {$order},id desc"
, $page, $limit, "bizId,count(id) as orderTotal");
} else {
$res = $this->mdSyliveGroups->select($where, "{$sort_order},groupsId desc", $page, $limit,
'groupsId,groupsName,browse,subscribe,watch,orderTotal');
}
foreach ($res as $v) {
if ($sort == 'order' && $itemId) {
$bizId = intval($v['bizId']);
$re_biz = $this->mdSyliveGroups->get(['groupsId' => $bizId, 'activityId' => $activityId, 'status>=' => 0]);
$bizName = $re_biz ? $re_biz['groupsName'] : '-';
} else {
$bizId = intval($v['groupsId']);
$bizName = $v['groupsName'] ? $v['groupsName'] : '-';
}
$consultant = $this->mdSyliveActivityKpidata->count(['bizId' => $bizId, 'activityId' => $activityId], 'cfUserId');
$allConsultant = $this->mdSyliveGroupsUser->count(['bizId' => $bizId, 'activityId' => $activityId, 'status>=' => 0]);
$consultant > $allConsultant && $allConsultant = $consultant;
$livePV = $watchDuration = 0;
if ($channelId) {
$livePV = $this->mdSyliveViewlog->count(['bizId' => $bizId, 'activityId' => $activityId]);
$re_sum = $this->mdSyliveViewlog->sum('playDuration', ['bizId' => $bizId, 'activityId' => $activityId]);
if ($re_sum['playDuration']) {
$playDuration = ceil($re_sum['playDuration'] / 60);
$watchDuration = round($playDuration / $livePV);
}
}
if ($sort != 'order' && $itemId) {//有商品id,区分订单
$order = $this->mdSyliveActivityKpidata->count(['kpi' => 'order', 'bizId' => $bizId, 'itemId' => $itemId, 'activityId' => $activityId]);
} else {
$order = $v['orderTotal'];
}
if ($sort == 'order' && $itemId) {//只改变订单数值,其它不变
$re = $this->mdSyliveGroups->get(['groupsId' => $bizId, 'activityId' => $activityId, 'status>=' => 0], 'browse,subscribe,watch');
$v['browse'] = intval($re['browse']);
$v['subscribe'] = intval($re['subscribe']);
$v['watch'] = intval($re['watch']);
}
$list[] = [
'bizName' => $bizName, 'consultant' => $consultant, 'allConsultant' => $allConsultant, 'browse' => $v['browse'], 'subscribe' => $v['subscribe']
, 'watch' => $v['watch'], 'order' => $order, 'livePV' => $livePV, 'watchDuration' => $watchDuration];
}
}
}
}
$date = ['list' => $list, 'count' => $count];
$this->return_response_list($date);
}
/**
* Notes:分组顾问统计
* Created on: 2022/12/05 14:48
* Created by: dengbw
*/
public function consultant_get()
{
$activityId = intval($this->input_param('activityId'));
$page = $this->input_param('page');
$limit = $this->input_param('limit');
$sort = $this->input_param('sort');
$order = $this->input_param('order');
$day = $this->input_param('day');
$itemId = intval($this->input_param('itemId'));//商品
!$page && $page = 1;
!$limit && $limit = 10;
$list = [];
$count = 0;
$re = $this->mdSyliveActivity->get(['activityId' => $activityId]);
if ($re) {
$channelId = intval($re['channelId']);
!$sort && $sort = 'browse';
!$order && $order = 'desc';
if ($sort == 'order' && !$day) {
$sort_order = 'orderTotal ' . $order;
} else {
$sort_order = $sort . ' ' . $order;
}
if ($day) {
$createTimeStart = strtotime($day . ' 00:00:00');
$createTimeEnd = strtotime($day . ' 23:59:59');
$where = $where_order = $where_sort = ['activityId' => $activityId, 'day' => $day, 'cfUserId>' => 0, 'kpi' => $sort];
if ($sort == 'order') {
$itemId && $where['itemId'] = $itemId;
}
$count = $this->mdSyliveActivityKpidata->count($where, 'cfUserId');
if ($count) {
$res = $this->mdSyliveActivityKpidata->select_groupby('cfUserId', $where, "total {$order},id desc", $page, $limit, "bizId as groupsId,cfUserId,count(id) as total");
foreach ($res as $v) {
$cfUserId = intval($v['cfUserId']);
$re_org = $this->mdSyliveGroups->get(['groupsId' => $v['groupsId'], 'status>=' => 0]);
$bizName = $re_org['groupsName'] ? $re_org['groupsName'] : '-';
$re_user = $this->mdSyliveUser->get(['userId' => $cfUserId, 'status>=' => 0]);
$uname = $re_user['uname'] ? $re_user['uname'] : $re_user['nickname'];
$consultantName = $bizName . ' ' . $uname;
$where_sort['cfUserId'] = $cfUserId;
if ($sort == 'browse') {
$browse = $v['total'];
} else {
$where_sort['kpi'] = 'browse';
$browse = $this->mdSyliveActivityKpidata->count($where_sort);
}
if ($sort == 'subscribe') {
$subscribe = $v['total'];
} else {
$where_sort['kpi'] = 'subscribe';
$subscribe = $this->mdSyliveActivityKpidata->count($where_sort);
}
if ($sort == 'watch') {
$watch = $v['total'];
} else {
$where_sort['kpi'] = 'watch';
$watch = $this->mdSyliveActivityKpidata->count($where_sort);
}
if ($sort == 'order') {
$order = $v['total'];
} else {
$where_order['kpi'] = 'order';
$where_order['cfUserId'] = $cfUserId;
$itemId && $where_order['itemId'] = $itemId;
$order = $this->mdSyliveActivityKpidata->count($where_order);
}
$livePV = $watchDuration = 0;
if ($channelId) {
$livePV = $this->mdSyliveViewlog->count(['cfUserId' => $cfUserId, 'activityId' => $activityId
, 'createTime>=' => $createTimeStart, 'createTime<=' => $createTimeEnd]);
$re_sum = $this->mdSyliveViewlog->sum('playDuration', ['cfUserId' => $cfUserId, 'activityId' => $activityId
, 'createTime>=' => $createTimeStart, 'createTime<=' => $createTimeEnd]);
if ($re_sum['playDuration']) {
$playDuration = ceil($re_sum['playDuration'] / 60);
$watchDuration = round($playDuration / $livePV);
}
}
$list[] = ['consultantName' => $consultantName, 'browse' => $browse, 'subscribe' => $subscribe
, 'watch' => $watch, 'order' => $order, 'livePV' => $livePV, 'watchDuration' => $watchDuration];
}
}
} else {
if ($sort == 'order' && $itemId) {//有订单排序与商品id,区分订单搜索
$where = ['activityId' => $activityId, 'itemId' => $itemId, 'cfUserId>' => 0, 'kpi' => $sort];
$count = $this->mdSyliveActivityKpidata->count($where, 'cfUserId');
} else {
$where = ['activityId' => $activityId, 'status>=' => 0];
$count = $this->mdSyliveGroupsUser->count($where);
}
if ($count) {
if ($sort == 'order' && $itemId) {//有订单排序与商品id,区分订单搜索
$res = $this->mdSyliveActivityKpidata->select_groupby('cfUserId', $where, "orderTotal {$order},id desc"
, $page, $limit, "cfUserId as userId,bizId as groupsId,count(id) as orderTotal");
} else {
$res = $this->mdSyliveGroupsUser->select($where, "{$sort_order},groupsUserId desc", $page, $limit,
'userId,groupsId,browse,subscribe,orderTotal,watch');
}
foreach ($res as $v) {
$userId = intval($v['userId']);
$re_org = $this->mdSyliveGroups->get(['groupsId' => $v['groupsId'], 'status>=' => 0]);
$bizName = $re_org['groupsName'] ? $re_org['groupsName'] : '-';
$re_user = $this->mdSyliveUser->get(['userId' => $userId, 'status>=' => 0]);
$uname = $re_user['uname'] ? $re_user['uname'] : $re_user['nickname'];
$consultantName = $bizName . ' ' . $uname;
$livePV = $watchDuration = 0;
if ($channelId) {
$livePV = $this->mdSyliveViewlog->count(['cfUserId' => $userId, 'activityId' => $activityId]);
$re_sum = $this->mdSyliveViewlog->sum('playDuration', ['cfUserId' => $userId, 'activityId' => $activityId]);
if ($re_sum['playDuration']) {
$playDuration = ceil($re_sum['playDuration'] / 60);
$watchDuration = round($playDuration / $livePV);
}
}
if ($sort != 'order' && $itemId) {//有商品id,区分订单
$order = $this->mdSyliveActivityKpidata->count(['kpi' => 'order', 'cfUserId' => $userId, 'itemId' => $itemId, 'activityId' => $activityId]);
} else {
$order = $v['orderTotal'];
}
if ($sort == 'order' && $itemId) {//只改变订单数值,其它不变
$re = $this->mdSyliveGroupsUser->get(['userId' => $userId, 'activityId' => $activityId], 'browse,subscribe,watch');
$v['browse'] = intval($re['browse']);
$v['subscribe'] = intval($re['subscribe']);
$v['watch'] = intval($re['watch']);
}
$list[] = ['consultantName' => $consultantName, 'browse' => $v['browse'], 'subscribe' => $v['subscribe'], 'watch' => $v['watch']
, 'order' => $order, 'livePV' => $livePV, 'watchDuration' => $watchDuration];
}
}
}
}
$date = ['list' => $list, 'count' => $count];
$this->return_response_list($date);
}
/**
* Notes:漏头数据
* Created on: 2022/12/05 14:17
* Created by: dengbw
*/
public function funnel_get()
{
$activityId = intval($this->input_param('activityId'));
$itemId = intval($this->input_param('itemId'));//商品
$show = $this->input_param('show');
$funnel_preheating = $funnel_live = [];
$timeStart = 0;
$re = $this->mdSyliveActivity->get(['activityId' => $activityId]);
$re['timeStart'] && $timeStart = strtotime($re['timeStart']);
if ($show == 'left' || !$show) {//预热阶段
$left_browse_where = "userId in(select userId from lc_market_sylive_activity_kpidata where activityId = {$activityId} AND kpi = 'browse' AND createTime < {$timeStart})";
$left_browse = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'kpi' => 'browse', 'createTime<' => $timeStart]);
$left_subscribe = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'kpi' => 'subscribe', 'createTime<' => $timeStart]);
$left_watch = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'kpi' => 'watch', $left_browse_where => null]);
if ($itemId) {
$left_order = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'itemId' => $itemId, 'kpi' => 'order', $left_browse_where => null]);
} else {
$left_order = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'kpi' => 'order', $left_browse_where => null]);
}
$left_subscribe_per = number_format_com($left_subscribe / $left_browse * 100, 1, '');
$left_watch_per = number_format_com($left_watch / $left_subscribe * 100, 1, '');
$left_order_per = number_format_com($left_order / $left_watch * 100, 1, '');
$left_expected_data = [['name' => "浏览人数100%", 'value' => 100], ['name' => "预约人数({$left_subscribe_per}%)", 'value' => 75]
, ['name' => "观看人数({$left_watch_per}%)", 'value' => 50], ['name' => "订单数({$left_order_per}%)", 'value' => 25]];
$left_actual_data = [['name' => '浏览人数', 'value' => $left_browse], ['name' => '预约人数', 'value' => $left_subscribe]
, ['name' => '观看人数', 'value' => $left_watch], ['name' => '订单数', 'value' => $left_order]];
$funnel_preheating = ['title' => '浏览转化漏斗((预热阶段)', 'expectedData' => $left_expected_data, 'actualData' => $left_actual_data];
}
if ($show == 'right' || !$show) {//直播阶段
$right_browse_where = "userId in(select userId from lc_market_sylive_activity_kpidata where activityId = {$activityId} AND kpi = 'browse' AND createTime >= {$timeStart})";
$right_browse = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'kpi' => 'browse', 'createTime>=' => $timeStart]);
$right_watch = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'kpi' => 'watch', $right_browse_where => null]);
if ($itemId) {
$right_order = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'itemId' => $itemId, 'kpi' => 'order', $right_browse_where => null]);
} else {
$right_order = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'kpi' => 'order', $right_browse_where => null]);
}
$right_watch_per = number_format_com($right_watch / $right_browse * 100, 1, '');
$right_order_per = number_format_com($right_order / $right_watch * 100, 1, '');
$right_expected_data = [['name' => "浏览人数100%", 'value' => 100], ['name' => "观看人数({$right_watch_per}%)", 'value' => 66.7], ['name' => "订单数({$right_order_per}%)", 'value' => 33.3]];
$right_actual_data = [['name' => '浏览人数_' . $right_browse, 'value' => $right_browse], ['name' => '观看人数', 'value' => $right_watch], ['name' => '订单数', 'value' => $right_order]];
$funnel_live = ['title' => '浏览转化漏斗(直播阶段)', 'expectedData' => $right_expected_data, 'actualData' => $right_actual_data];
}
$data['funnelPreheating'] = $funnel_preheating;
$data['funnelLive'] = $funnel_live;
$this->return_response($data);
}
/**
* Notes:获取观看数/订单数区域折线图数据
* Created on: 2022/12/06 10:54
* Created by: dengbw
*/
public function stacked_watchOrder_get()
{
$activityId = intval($this->input_param('activityId'));
$re = $this->mdSyliveActivity->get(['activityId' => $activityId]);
$times = $legendData = $yAxisSeries = $xAxisData = [];
if ($re) {
$timeStart = $re['timeStart'];
$timeEnd = $re['timeEnd'];
if ($timeStart != '0000-00-00 00:00:00' && (date('Y-m-d H:i:s') > $timeStart)) {
$start_Time = strtotime($timeStart);
$end_Time = strtotime($timeEnd);
$legend_data = [['name' => date('Y-m-d', $start_Time) . '的观看数', 'value' => 'watch'],
['name' => date('Y-m-d', $start_Time) . '的订单数', 'value' => 'order']];
$add_time = '+1 hour';
$diff = abs($start_Time - $end_Time); // 获取时间差
$hour = ceil($diff / 3600); // 获取相差小时数
$hour < 6 && $add_time = '+30 minute';//转分钟显示
$ii = 0;
while ($start_Time < $end_Time) {
$start = date('Y-m-d H:i:s', $start_Time);
$ii > 0 && $start = date('Y-m-d H:i:s', $start_Time + 60);
$name_start = date('H:i', $start_Time);
$start_Time = strtotime($add_time, $start_Time);
$name = $name_start . '-' . date('H:i', $start_Time);
$end = date('Y-m-d H:i:s', $start_Time + 59);
$times[] = ['name' => $name, 'start' => $start, 'end' => $end];
$xAxisData[] = $name;
$ii++;
}
foreach ($legend_data as $v) {
$legendData[] = $v['name'];
$counts = [];
foreach ($times as $v2) {
$start = strtotime($v2['start']);
$end = strtotime($v2['end']);
$counts[] = $this->mdSyliveActivityKpidata->count(['kpi' => $v['value'], 'createTime >=' => $start,
'createTime <=' => $end, 'activityId' => $activityId]);
}
$yAxisSeries[] = ['name' => $v['name'], 'type' => 'line', 'data' => $counts];
}
}
}
$date = ['legendData' => $legendData, 'xAxisData' => $xAxisData, 'yAxisSeries' => $yAxisSeries];
$this->return_response_list($date);
}
/**
* Notes:获取门店数
* Created on: 2022/12/6 14:48
* Created by: dengbw
* @param $groupsId
* @return int
*/
private function getBiz($groupsId)
{
$groupsIds = '';
$res1 = $this->mdSyliveGroups->select(['parentId' => $groupsId, 'status>=' => 0], "groupsId desc", 0, 0, 'groupsId');
if ($res1) {
$groupsIds = implode(',', array_column($res1, 'groupsId'));
$res2 = $this->mdSyliveGroups->select(["parentId in({$groupsIds})" => null, 'status>=' => 0]
, "groupsId desc", 0, 0, 'groupsId');
if ($res2) {
$groupsIds = implode(',', array_column($res2, 'groupsId'));
$res3 = $this->mdSyliveGroups->select(["parentId in({$groupsIds})" => null, 'status>=' => 0]
, "groupsId desc", 0, 0, 'groupsId');
if ($res3) {
$groupsIds = implode(',', array_column($res3, 'groupsId'));
}
}
}
$biz = 0;
if ($groupsIds) {
$biz = $this->mdSyliveGroups->count(["groupsId in({$groupsIds})" => null, 'status>=' => 0]);
}
return $biz;
}
}
+84 -43
View File
@@ -14,6 +14,8 @@ class GroupsUser extends BaseController
{
parent::__construct();
$this->load->model('market/Market_sylive_groups_user_model', 'mdSyliveGroupsUser');
$this->load->model('market/Market_sylive_groups_model', 'mdSyliveGroups');
$this->load->model('market/Market_sylive_user_model', 'mdSyliveUser');
}
/**
@@ -27,29 +29,44 @@ class GroupsUser extends BaseController
$limit = $this->input_param('limit');
$uname = $this->input_param('uname');
$nickname = $this->input_param('nickname');
$sort = $this->input_param('sort');
$order = $this->input_param('order');
$teamId = intval($this->input_param('teamId'));
$activityId = intval($this->input_param('activityId'));
$groupsId = intval($this->input_param('groupsId'));
!$page && $page = 1;
!$limit && $limit = 10;
$sort_order = 'userId desc';
if ($sort && $order) {
$sort_order = $sort . ' ' . $order;
}
$sort_order = 'type desc,groupsUserId desc';
$list = [];
$where['status>='] = 0;
$teamId && $where['teamId'] = $teamId;
$uname && $where['uname'] = $uname;
$nickname && $where['nickname'] = $nickname;
$groupsId && $where['groupsId'] = $groupsId;
$activityId && $where['activityId'] = $activityId;
if ($uname || $nickname) {
$where_user = $uname ? "(uname LIKE '%{$uname}%')" : "(nickname LIKE '%{$nickname}%')";
$where["userId in (select userId from lc_market_sylive_user where {$where_user})"] = null;
}
$count = $this->mdSyliveGroupsUser->count($where);
if ($count) {
$res = $this->mdSyliveGroupsUser->select($where, $sort_order, $page, $limit);
$user_ids = implode(",", array_column($res, 'userId'));
$map_user = $this->mdSyliveUser->map('userId', 'uname,nickname,mobile', ["userId in({$user_ids})" => null]);
foreach ($res as $v) {
$uname = $nickname = $mobile = '';
$user = $map_user[$v['userId']];
if ($user) {
$uname = $user['uname'];
$nickname = $user['nickname'];
$mobile = $user['mobile'];
}
$status = intval($v['status']);
$createTime = $v['createTime'] != '0000-00-00 00:00:00' ? $v['createTime'] : '';
if ($v['type'] == 0) {
$roleName = '销售';
} else if ($v['type'] == 1) {
$roleName = $v['userFrom'] == 0 ? '店长' : '团长';
} else {
$roleName = '管理员';
}
$list[] = [
'userId' => $v['userId'], 'uname' => $v['uname'], 'nickname' => $v['nickname'], 'mobile' => $v['mobile']
, 'teamId' => $teamId, 'status' => $status, 'createTime' => $createTime];
'groupsUserId' => $v['groupsUserId'], 'uname' => $uname, 'nickname' => $nickname, 'mobile' => $mobile
, 'groupsId' => $groupsId, 'roleName' => $roleName, 'status' => $status, 'createTime' => $createTime];
}
}
$date = ['list' => $list, 'count' => $count];
@@ -63,36 +80,60 @@ class GroupsUser extends BaseController
*/
public function index_post()
{
$mobile = $this->input_param('mobile');
$teamId = intval($this->input_param('teamId'));
$uname = $this->input_param('uname');
if (!$mobile) {
$this->return_json('请输入手机号');
$activityId = intval($this->input_param('activityId'));
$groupsId = intval($this->input_param('groupsId'));
$userFrom = intval($this->input_param('userFrom'));
$chooseUsers = $this->input_param('chooseUsers');
if (!$groupsId) {
$this->return_json('未选择分组');
}
if (!$teamId) {
$this->return_json('选择所属团队');
if (!$chooseUsers) {
$this->return_json('选择用户');
}
if (!$uname) {
$this->return_json('请输入姓名');
}
$re = $this->mdSyliveGroupsUser->get(['mobile' => $mobile]);
if ($re && $re['status'] != -1) {
if ($re['teamId'] || $re['organizationId']) {
$this->return_json('手机号已存在');
$addData = [];
$levelAry = $this->getLevelAry($groupsId);
$re_gro = $this->mdSyliveGroups->get(['groupsId' => $groupsId], 'ifBiz');
$ifBiz = intval($re_gro['ifBiz']);//是否门店
foreach ($chooseUsers as $v) {
$re = $this->mdSyliveGroupsUser->get(['activityId' => $activityId, 'userId' => $v['userId'], 'status>=' => 0]);
if (!$re) {
$type = $ifBiz ? $v['type'] : 2;
$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);
$addData[] = $data;
}
}
$addDate = ['teamId' => $teamId, 'uname' => $uname, 'status' => 0, 'organizationId' => 0];
if ($re['userId']) {
$this->mdSyliveGroupsUser->update($addDate, ['userId' => $re['userId']]);
$this->return_response([], '绑定用户成功');
$addData && $this->mdSyliveGroupsUser->add_batch($addData);
$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 {
$addDate['mobile'] = $mobile;
$addDate['createTime'] = date('Y-m-d H:i:s');
$id = $this->mdSyliveGroupsUser->add($addDate);
if (!$id) {
$this->return_json('添加用户失败');
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;
}
$this->return_response();
}
}
@@ -127,12 +168,12 @@ class GroupsUser extends BaseController
*/
public function status_put()
{
$userId = $this->input_param('userId');
$groupsUserId = $this->input_param('groupsUserId');
$status = $this->input_param('status');
if (!$userId) {
if (!$groupsUserId) {
$this->return_json('参数错误');
}
$this->mdSyliveGroupsUser->update(['status' => $status], ['userId' => $userId]);
$this->mdSyliveGroupsUser->update(['status' => $status], ['groupsUserId' => $groupsUserId]);
$this->return_response();
}
@@ -140,14 +181,14 @@ class GroupsUser extends BaseController
* Notes:删除用户
* Created on: 2022/9/21 16:10
* Created by: dengbw
* @param null $userId
* @param null $groupsUserId
*/
public function index_delete($userId = null)
public function index_delete($groupsUserId = null)
{
if (!$userId) {
if (!$groupsUserId) {
$this->return_json('参数错误');
}
$this->mdSyliveGroupsUser->update(['status' => -1], ['userId' => $userId]);
$this->mdSyliveGroupsUser->update(['status' => -1], ['groupsUserId' => $groupsUserId]);
$this->return_response();
}
+18 -8
View File
@@ -23,12 +23,19 @@ class Organization extends BaseController
*/
public function index_get()
{
$unOrganizationType = $this->input_param('unOrganizationType');
$unOrganizationType = intval($this->input_param('unOrganizationType'));
$activityId = intval($this->input_param('activityId'));
$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 ($_SESSION['brandName'] || $activityId) {//只找该品牌机构
if ($activityId) {
$this->load->model('market/Market_sylive_activity_model', 'mdSyliveActivity');
$re_act = $this->mdSyliveActivity->get(['activityId' => $activityId]);
$re_org['organizationId'] = intval($re_act['organizationId']);
} else {
$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');
@@ -70,20 +77,23 @@ class Organization extends BaseController
*/
public function parent_get()
{
$res = [];
$list = [];
if ($_SESSION['brandName']) {//只找该品牌机构
$re_org = $this->mdSyliveOrganization->get(['organizationName' => $_SESSION['brandName'], 'parentId' => 0, 'status' => 0]);
$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']];
$list[] = ['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');
$res = $this->mdSyliveOrganization->select($where, $sort_order, 0, 0, 'organizationId,organizationName');
foreach ($res as $k => $v) {
$list[] = ['organizationId' => intval($v['organizationId']), 'organizationName' => $v['organizationName']];
}
}
$this->return_response_list($res);
$this->return_response_list($list);
}
/**
@@ -14,6 +14,7 @@ class TeamUser extends BaseController
{
parent::__construct();
$this->load->model('market/Market_sylive_user_model', 'mdSyliveUser');
$this->load->model('market/Market_sylive_team_model', 'mdSyliveTeam');
}
/**
@@ -56,6 +57,69 @@ class TeamUser extends BaseController
$this->return_response_list($date);
}
/**
* Notes:获取团队用户
* Created on: 2022/11/30 15:37
* Created by: dengbw
*/
public function list_post()
{
$this->load->model('market/Market_sylive_groups_user_model', 'mdSyliveGroupsUser');
$this->load->model('market/Market_sylive_groups_model', 'mdSyliveGroups');
$activityId = intval($this->input_param('activityId'));
$teamIds = $this->input_param('teamIds');
$keyword = trim($this->input_param('keyword'));
$where = ['status>=' => 0, 'teamId>' => 0];
if ($keyword) {
$where["(uname LIKE '%{$keyword}%' OR mobile LIKE '%{$keyword}%')"] = null;
} else if ($teamIds) {
$teamIds_str = implode(',', $teamIds);
$res_tea = $this->mdSyliveTeam->select(["parentId in({$teamIds_str})" => null], 'teamId desc', 0, 0, 'teamId');
foreach ($res_tea as $v) {
$teamIds[] = $v['teamId'];
}
$teamIds = implode(',', $teamIds);
$where["teamId in({$teamIds})"] = null;
}
$res = $this->mdSyliveUser->select($where, 'userId desc', 0, 0, 'userId,uname,mobile,teamId');
if ($keyword && $res) {
$teamIds = [];
foreach ($res as $v) {
$v['teamId'] && $teamIds[] = $v['teamId'];
}
$teamIds && $teamIds = implode(',', $teamIds);
}
$map_team = $map_team2 = [];
if ($teamIds) {
$map_team = $this->mdSyliveTeam->map('teamId', 'teamName,teamType', ["teamId in({$teamIds})" => null]);
}
$list = [];
foreach ($res as $v) {
$uname = $v['uname'] ? $v['uname'] : '-';
$team = $map_team[$v['teamId']];
$teamName = $team['teamName'] ? $team['teamName'] : '-';
$type = 2;
if ($team['teamType'] == 2) {
$type = 1;
} else if ($team['teamType'] == 3) {
$type = 0;
}
$groups = 0;
$re_gro_use = $this->mdSyliveGroupsUser->get(['activityId' => $activityId, 'userId' => $v['userId']
, 'status>=' => 0], 'groupsId,bizId');
if ($re_gro_use) {
$groups = 1;
$groupsId = $re_gro_use['bizId'] ? $re_gro_use['bizId'] : $re_gro_use['groupsId'];
$re_gro = $this->mdSyliveGroups->get(['activityId' => $activityId, 'groupsId' => $groupsId
, 'status>=' => 0], 'groupsName');
$re_gro['groupsName'] && $teamName .= "(分组-{$re_gro['groupsName']})";
}
$list[] = ['userId' => $v['userId'], 'uname' => $uname, 'mobile' => $v['mobile'], 'type' => $type
, 'groups' => $groups, 'teamName' => $teamName];
}
$this->return_response_list($list);
}
/**
* Notes:添加用户
* Created on: 2022/9/21 16:46
+82 -2
View File
@@ -14,6 +14,7 @@ class User extends BaseController
{
parent::__construct();
$this->load->model('market/Market_sylive_user_model', 'mdSyliveUser');
$this->load->model('market/Market_sylive_organization_model', 'mdSyliveOrganization');
}
/**
@@ -61,6 +62,67 @@ class User extends BaseController
$this->return_response_list($date);
}
/**
* Notes:获取机构用户
* Created on: 2022/11/29 11:08
* Created by: dengbw
*/
public function list_post()
{
$this->load->model('market/Market_sylive_groups_user_model', 'mdSyliveGroupsUser');
$this->load->model('market/Market_sylive_groups_model', 'mdSyliveGroups');
$activityId = intval($this->input_param('activityId'));
$organizationIds = $this->input_param('organizationIds');
$keyword = trim($this->input_param('keyword'));
$where = ['status>=' => 0, 'organizationId>' => 0];
if ($keyword) {
$where["(uname LIKE '%{$keyword}%' OR mobile LIKE '%{$keyword}%')"] = null;
} else if ($organizationIds) {
$organizationIds = implode(',', $organizationIds);
$where["organizationId in({$organizationIds}) or bizId in({$organizationIds})"] = null;
}
$res = $this->mdSyliveUser->select($where, 'userId desc', 0, 0, 'userId,uname,mobile,organizationId,bizId');
if ($keyword && $res) {
$organizationIds = [];
foreach ($res as $v) {
$v['bizId'] && $organizationIds[] = $v['bizId'];
$v['organizationId'] && $organizationIds[] = $v['organizationId'];
}
$organizationIds && $organizationIds = implode(',', $organizationIds);
}
$map_organization = [];
if ($organizationIds) {
$map_organization = $this->mdSyliveOrganization->map('organizationId', 'organizationName,organizationType'
, ["organizationId in({$organizationIds})" => null]);
}
$list = [];
foreach ($res as $v) {
$uname = $v['uname'] ? $v['uname'] : '-';
$organization = $map_organization[$v['bizId']];
if (!$organization) {
$organization = $map_organization[$v['organizationId']];
}
$organizationName = $organization['organizationName'] ? $organization['organizationName'] : '-';
$type = 2;
if ($v['bizId']) {
$type = $v['bizId'] == $v['organizationId'] ? 1 : 0;
}
$groups = 0;
$re_gro_use = $this->mdSyliveGroupsUser->get(['activityId' => $activityId, 'userId' => $v['userId']
, 'status>=' => 0], 'groupsId,bizId');
if ($re_gro_use) {
$groups = 1;
$groupsId = $re_gro_use['bizId'] ? $re_gro_use['bizId'] : $re_gro_use['groupsId'];
$re_gro = $this->mdSyliveGroups->get(['activityId' => $activityId, 'groupsId' => $groupsId
, 'status>=' => 0], 'groupsName');
$re_gro['groupsName'] && $organizationName .= "(分组-{$re_gro['groupsName']})";
}
$list[] = ['userId' => $v['userId'], 'uname' => $uname, 'mobile' => $v['mobile'], 'type' => $type
, 'groups' => $groups, 'organizationName' => $organizationName];
}
$this->return_response_list($list);
}
/**
* Notes:添加用户
* Created on: 2022/9/21 16:46
@@ -86,7 +148,16 @@ class User extends BaseController
$this->return_json('手机号已存在');
}
}
$addDate = ['organizationId' => $organizationId, 'uname' => $uname, 'status' => 0, 'teamId' => 0];
$bizId = 0;
$re_org = $this->mdSyliveOrganization->get(['organizationId' => $organizationId]);
if ($re_org) {
if ($re_org['organizationType'] == 4 && $re_org['parentId']) {
$bizId = $re_org['parentId'];
} else if ($re_org['organizationType'] == 3) {
$bizId = $re_org['organizationId'];
}
}
$addDate = ['organizationId' => $organizationId, 'uname' => $uname, 'bizId' => $bizId, 'status' => 0, 'teamId' => 0];
if ($re['userId']) {
$this->mdSyliveUser->update($addDate, ['userId' => $re['userId']]);
$this->return_response([], '绑定用户成功');
@@ -120,7 +191,16 @@ class User extends BaseController
if (!$uname) {
$this->return_json('请输入姓名');
}
$upDate = ['organizationId' => $organizationId, 'uname' => $uname];
$bizId = 0;
$re_org = $this->mdSyliveOrganization->get(['organizationId' => $organizationId]);
if ($re_org) {
if ($re_org['organizationType'] == 4 && $re_org['parentId']) {
$bizId = $re_org['parentId'];
} else if ($re_org['organizationType'] == 3) {
$bizId = $re_org['organizationId'];
}
}
$upDate = ['organizationId' => $organizationId, 'bizId' => $bizId, 'teamId' => 0, 'uname' => $uname];
$this->mdSyliveUser->update($upDate, ['userId' => $userId]);
$this->return_response();
}
@@ -23,7 +23,9 @@ class Dictionary extends BaseController
*/
public function index_get()
{
$dictCode = $this->input_param('dictCode');
$where['status>='] = 0;
$dictCode && $where['dictCode like "%' . $dictCode . '%"'] = null;
$sort_order = 'sortNumber asc,dictId desc';
$res = $this->mdSysDictionary->select($where, $sort_order);
foreach ($res as $k => $v) {