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'); } /** * Notes:用户管理列表 * Created on: 2022/9/20 14:48 * Created by: dengbw */ public function page_get() { $page = $this->input_param('page'); $limit = $this->input_param('limit'); $uname = $this->input_param('uname'); $nickname = $this->input_param('nickname'); $activityId = intval($this->input_param('activityId')); $groupsId = intval($this->input_param('groupsId')); !$page && $page = 1; !$limit && $limit = 10; $sort_order = 'type desc,groupsUserId desc'; $list = []; $where['status>='] = 0; $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[] = [ 'groupsUserId' => $v['groupsUserId'], 'userId' => $v['userId'],'uname' => $uname, 'nickname' => $nickname, 'mobile' => $mobile , 'groupsId' => $groupsId, 'roleName' => $roleName, 'status' => $status, 'createTime' => $createTime]; } } $date = ['list' => $list, 'count' => $count]; $this->return_response_list($date); } /** * Notes:添加用户 * Created on: 2022/9/21 16:46 * Created by: dengbw */ public function index_post() { $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 (!$chooseUsers) { $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; } } $addData && $this->mdSyliveGroupsUser->add_batch($addData); $this->return_response(); } /** * Notes:同步原始门店用户 * Created on: 2022/12/9 12:21 * Created by: dengbw */ public function synchronous_get() { $groupsId = intval($this->input_param('groupsId')); if (!$groupsId) { $this->return_json('参数错误'); } $re_gro = $this->mdSyliveGroups->get(['groupsId' => $groupsId]); if (!$re_gro) { $this->return_json('分组不存在'); } $originalBizId = intval($re_gro['originalBizId']); if (!$originalBizId) { $this->return_json('未关连原始门店'); } $activityId = intval($re_gro['activityId']); $userFrom = intval($re_gro['userFrom']); $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:获取分组等级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; } } } /** * Notes:修改用户 * Created on: 2022/9/21 14:48 * Created by: dengbw */ public function index_put() { $userId = intval($this->input_param('userId')); $teamId = intval($this->input_param('teamId')); $uname = $this->input_param('uname'); if (!$userId) { $this->return_json('参数错误'); } if (!$teamId) { $this->return_json('请选择所属团队'); } if (!$uname) { $this->return_json('请输入姓名'); } $upDate = ['teamId' => $teamId, 'uname' => $uname]; $this->mdSyliveGroupsUser->update($upDate, ['userId' => $userId]); $this->return_response(); } /** * Notes:修改状态 * Created on: 2022/9/21 16:10 * Created by: dengbw */ public function status_put() { $groupsUserId = $this->input_param('groupsUserId'); $status = $this->input_param('status'); if (!$groupsUserId) { $this->return_json('参数错误'); } $this->mdSyliveGroupsUser->update(['status' => $status], ['groupsUserId' => $groupsUserId]); $this->return_response(); } /** * Notes:删除用户 * Created on: 2022/9/21 16:10 * Created by: dengbw * @param null $groupsUserId */ public function index_delete($groupsUserId = null) { if (!$groupsUserId) { $this->return_json('参数错误'); } $this->mdSyliveGroupsUser->update(['status' => -1], ['groupsUserId' => $groupsUserId]); $this->return_response(); } /** * Notes:删除用户 * Created on: 2022/10/21 17:11 * Created by: dengbw */ public function batch_delete() { $ids = $this->input_param('ids'); if (!$ids) { $this->return_json('参数错误'); } $str_ids = implode(',', $ids); if ($str_ids) { $this->mdSyliveGroupsUser->update(['status' => -1], ["groupsUserId in($str_ids)" => null]); } $this->return_response(); } /** * Notes:栓验字段 * Created on: 2022/9/21 15:52 * Created by: dengbw */ public function existence_get() { $field = $this->input_param('field'); $value = $this->input_param('value'); $id = $this->input_param('id'); if (!$id) { $where = [$field => $value, 'status<>' => -1]; $re = $this->mdSyliveGroupsUser->get($where); if ($re) { if ($field == 'mobile') { if ($re['teamId'] || $re['organizationId']) { $this->return_json('已存在', 0); } } else { $this->return_json('已存在', 0); } } } $this->return_json('不存在', 1); } }