market_groups_export

This commit is contained in:
dengbw
2023-05-06 17:31:51 +08:00
committed by lccsw
parent 305d90273d
commit e6c053b889
+92
View File
@@ -209,6 +209,98 @@ class Groups extends BaseController
$this->return_response();
}
/**
* Notes:导出分组所有顾问
* Created on: 2023/5/6 14:56
* Created by: dengbw
*/
public function consultant_export_get()
{
$activityId = $this->inputs['activityId'];
if (!$activityId) {
$this->return_json('参数错误');
}
$where = ["activityId" => $activityId, "status" => 0];
$count = $this->mdSyliveGroupsUser->count($where);
if ($count > 10000) {
$this->return_json('导出失败,每次导出不能超出10000条数据');
}
if ($count == 0) {
$this->return_json('导出失败,无数据');
}
$levels = [];
$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) {
$levels[] = ['label' => $v['dictDataName'], 'prop' => "levelId{$groupsLevel}"];
}
}
}
$res = $this->mdSyliveGroupsUser->select($where, "levelId1 asc,bizId asc,groupsUserId asc", 0, 0
, 'userId,type,userFrom,levelId1,levelId2,levelId3,bizId');
$list = $userIds = $groupsIds = [];
foreach ($res as $v) {
if ($v['levelId1'] && !in_array($v['levelId1'], $groupsIds)) {
$groupsIds[] = $v['levelId1'];
}
if ($v['levelId2'] && !in_array($v['levelId2'], $groupsIds)) {
$groupsIds[] = $v['levelId2'];
}
if ($v['levelId3'] && !in_array($v['levelId3'], $groupsIds)) {
$groupsIds[] = $v['levelId3'];
}
if ($v['bizId'] && !in_array($v['bizId'], $groupsIds)) {
$groupsIds[] = $v['bizId'];
}
if ($v['userId'] && !in_array($v['userId'], $userIds)) {
$userIds[] = $v['userId'];
}
}
$userIds = $userIds ? implode(",", $userIds) : -1;
$map_user = $this->mdSyliveUser->map('userId', 'uname,nickname,mobile', ["userId in({$userIds})" => null]);
$groupsIds = $groupsIds ? implode(',', $groupsIds) : -1;
$map_groups = $this->mdSyliveGroups->map('groupsId', 'groupsName', ["groupsId in({$groupsIds})" => null, 'activityId' => $activityId]);
foreach ($res as $v) {
$uname = $nickname = $mobile = '';
$user = $map_user[$v['userId']];
if ($user) {
$uname = $user['uname'];
$nickname = $user['nickname'];
$mobile = $user['mobile'];
}
if ($v['type'] == 0) {
$roleName = '销售';
} else if ($v['type'] == 1) {
$roleName = $v['userFrom'] == 0 ? '店长' : '团长';
} else {
$roleName = '管理员';
}
$list1 = ['uname' => $uname, 'nickname' => $nickname, 'mobile' => $mobile, 'roleName' => $roleName];
$list2 = [];
foreach ($levels as $k2 => $v2) {
$levelId = $v[$v2['prop']];
$list2[$v2['prop']] = $map_groups[$levelId] ? $map_groups[$levelId] : '';
}
$item = count($list2) ? array_merge($list1, $list2) : $list1;
$item['stores'] = $map_groups[$v['bizId']] ? $map_groups[$v['bizId']] : '';
$list[] = $item;
}
$columns1 = ['姓名', '微信昵称', '手机号', '角色'];
$columns2 = [];
foreach ($levels as $k => $v) {
$columns2[] = $v['label'];
}
$columns3 = count($columns2) ? array_merge($columns1, $columns2) : $columns1;
$columns = array_merge($columns3, ['门店']);
$this->return_response_list(['list' => $list, 'columns' => $columns]);
}
/**
* Notes:获取分组等级ID
* Created on: 2022/11/30 14:30