513 lines
20 KiB
PHP
513 lines
20 KiB
PHP
<?php
|
|
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
class Member extends HD_Controller
|
|
{
|
|
|
|
private $groups;
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('app/licheb/App_licheb_users_model', 'userM');
|
|
$this->load->model('app/licheb/App_licheb_channel_biz_model', 'mdChannelBiz');
|
|
$this->load->model("biz/biz_model");
|
|
$this->groups = $this->userM->get_group();
|
|
}
|
|
|
|
//首页信息
|
|
public function index()
|
|
{
|
|
$this->lists();
|
|
}
|
|
|
|
//数据列表
|
|
public function lists($where = array())
|
|
{
|
|
$params = $this->input->get();
|
|
$page = $params['page'];
|
|
$size = $params['size'];
|
|
!$page && $page = 1;
|
|
!$size && $size = 20;
|
|
if ($params['name']) {
|
|
$where['uname like "%' . $params['name'] . '%"'] = null;
|
|
$this->data['name'] = $params['name'];
|
|
}
|
|
if ($params['mobile']) {
|
|
$where['mobile'] = $params['mobile'];
|
|
$this->data['mobile'] = $params['mobile'];
|
|
}
|
|
if ($params['group_id']) {
|
|
$where['group_id'] = $params['group_id'];
|
|
$this->data['group_id'] = $params['group_id'];
|
|
}
|
|
if ($params['biz_id']) {
|
|
$where['biz_id'] = $params['biz_id'];
|
|
} else {
|
|
$params['biz_id'] = '';
|
|
$params['province_id'] ? $where['province_id'] = $params['province_id'] : $params['province_id'] = '';
|
|
$params['city_id'] ? $where['city_id'] = $params['city_id'] : $params['city_id'] = '';
|
|
!$params['county_id'] && $params['county_id'] = '';
|
|
}
|
|
|
|
if (strlen($params['status'])) {
|
|
$where['status'] = $params['status'];
|
|
}
|
|
|
|
$where['group_id >'] = 0;
|
|
$count = $this->userM->count($where);
|
|
$lists = $this->userM->select($where, 'id desc', $page, $size);
|
|
foreach ($lists as $key => $val) {
|
|
$biz_name = '';
|
|
if ($val['group_id'] == 4) {
|
|
$biz_name = ' <a href="javascript:void(0)" data-open="/app/licheb/channel/lists_biz?uid=' . $val['id'] . '">门店列表</a>';
|
|
} else if ($val['biz_id']) {
|
|
$re_biz = $this->biz_model->get(['id' => $val['biz_id']], 'biz_name');
|
|
$re_biz && $biz_name = $re_biz['biz_name'];
|
|
}
|
|
$lists[$key]['biz_name'] = $biz_name;
|
|
$lists[$key]['group_name'] = $this->groups[$val['group_id']];
|
|
|
|
$biz_name = '';
|
|
if ($val['group_id1'] == 4) {
|
|
$biz_name = ' <a href="javascript:void(0)" data-open="/app/licheb/channel/lists_biz?group_id1=1&uid=' . $val['id'] . '">门店列表</a>';
|
|
} else if ($val['biz_id1']) {
|
|
$re_biz = $this->biz_model->get(['id' => $val['biz_id1']], 'biz_name');
|
|
$re_biz && $biz_name = $re_biz['biz_name'];
|
|
}
|
|
$lists[$key]['biz_name1'] = $biz_name;
|
|
$lists[$key]['group_name1'] = $this->groups[$val['group_id1']];
|
|
|
|
if (SUPER_ADMIN == $this->role) {//超级管理员才允许操作用户的披上超级马甲
|
|
$majia = array();
|
|
if ($val['jsondata']) {
|
|
$json = json_decode($val['jsondata'], true);
|
|
$majia = $json['majia'] ? $json['majia'] : array();
|
|
}
|
|
$lists[$key]['umajia'] = $majia;
|
|
}
|
|
}
|
|
|
|
$this->data['provinces'] = $this->province_ary();
|
|
$this->data['app_id'] = 2;
|
|
$this->data['params'] = $params;
|
|
$this->data['lists'] = $lists;
|
|
$this->data['groupAry'] = $this->groups;
|
|
$this->data['_title'] = '用户列表';
|
|
$this->data['pager'] = array('count' => ceil($count / $size), 'curr' => $page, 'totle' => $count);
|
|
|
|
return $this->show_view('/app/licheb/member/lists', true);
|
|
}
|
|
|
|
//展示单条数据
|
|
public function get()
|
|
{
|
|
$this->load->model("sys/sys_city_model", 'mdSysCity');
|
|
$id = $this->input->get('id');
|
|
$row = $this->userM->get(['id' => $id]);
|
|
$selectedBrands = [];
|
|
$selectedBrands1 = [];
|
|
if ($id) {
|
|
$info = array(
|
|
'id' => $row['id'],
|
|
'uname' => $row['uname'],
|
|
'mobile' => $row['mobile'],
|
|
'group_id' => $row['group_id'],
|
|
'biz_id' => $row['biz_id'],
|
|
'city_id' => $row['city_id'],
|
|
'group_id1' => $row['group_id1'],
|
|
'biz_id1' => $row['biz_id1'],
|
|
'city_id1' => $row['city_id1'],
|
|
);
|
|
if ($row['group_id'] == 4) {
|
|
$user = $this->userM->get(['id' => $id]);
|
|
if ($user['biz_id']) {
|
|
$ids = $user['biz_id'];
|
|
$selectedBrands = $this->biz_model->select(["id in ($ids)" => null, 'status' => 1], '', 0, 0, 'id as biz_id,biz_name as name');
|
|
}
|
|
} else if ($row['biz_id']) {
|
|
$re_biz = $this->biz_model->get(["id" => $row['biz_id'], 'status' => 1], 'id ,biz_name');
|
|
if ($re_biz) {
|
|
$selectedBrands[] = ['biz_id' => $re_biz['id'], 'name' => $re_biz['biz_name']];
|
|
}
|
|
}
|
|
# group_id1
|
|
if ($row['group_id1'] == 4) {
|
|
|
|
$user = $this->userM->get(['id' => $id]);
|
|
if ($user['biz_id1']) {
|
|
$ids = $user['biz_id1'];
|
|
$selectedBrands1 = $this->biz_model->select(["id in ($ids)" => null, 'status' => 1], '', 0, 0, 'id as biz_id,biz_name as name');
|
|
}
|
|
} else if ($row['biz_id1']) {
|
|
$re_biz = $this->biz_model->get(["id" => $row['biz_id1'], 'status' => 1], 'id ,biz_name');
|
|
if ($re_biz) {
|
|
$selectedBrands1[] = ['biz_id' => $re_biz['id'], 'name' => $re_biz['biz_name']];
|
|
}
|
|
}
|
|
$action = '/app/licheb/member/edit';
|
|
$_title = '编辑用户';
|
|
} else {
|
|
$info = array('biz_id' => '', 'group_id' => '', 'city_id' => 0, 'biz_id1' => '', 'group_id1' => 0, 'city_id1' => 0);
|
|
$action = '/app/licheb/member/add';
|
|
$_title = '添加用户';
|
|
}
|
|
|
|
$this->data['provinces'] = $this->province_ary();
|
|
$show_info['cityList'] = $this->mdSysCity->select(['status' => 1], 'id desc', 0, 0, 'city_id,name');
|
|
$this->data['selectedBrands'] = $selectedBrands;
|
|
$this->data['selectedBrands1'] = $selectedBrands1;
|
|
$this->data['show_info'] = $show_info;
|
|
$this->data['info'] = $info;
|
|
$this->data['groups'] = $this->groups;
|
|
$this->data['action'] = $action;
|
|
$this->data['_title'] = $_title;
|
|
return $this->show_view('app/licheb/member/get', true);
|
|
}
|
|
|
|
//添加单条数据
|
|
public function add()
|
|
{
|
|
$info = $this->input->post('info');
|
|
$uname = $info['uname'];
|
|
$mobile = $info['mobile'];
|
|
$group_id = $info['group_id'];
|
|
$bizs = $info['bizs'];
|
|
$province_id = $info['province_id'];
|
|
$city_id = $info['city_id'];
|
|
$bizs && $biz_id_arr = array_column($bizs, 'biz_id');
|
|
$group_id1 = $info['group_id1'];
|
|
$bizs1 = $info['bizs1'];
|
|
$province_id1 = $info['province_id1'];
|
|
$city_id1 = $info['city_id1'];
|
|
$biz_id_arr1 = is_array($bizs1) ? array_column($bizs1, 'biz_id') : '';
|
|
|
|
if (!mobile_valid($mobile)) {
|
|
return $this->show_json(SYS_CODE_FAIL, '输入正确手机号');
|
|
}
|
|
if (!$uname) {
|
|
return $this->show_json(SYS_CODE_FAIL, '请输入姓名');
|
|
}
|
|
|
|
$exist = $this->userM->get(array('mobile' => $mobile, 'status in (0, 1)' => null));
|
|
if ($exist) {
|
|
return $this->show_json(SYS_CODE_FAIL, '手机号用户已存在');
|
|
}
|
|
|
|
$add = array(
|
|
'mobile' => $mobile,
|
|
'uname' => $uname,
|
|
'province_id' => $province_id,
|
|
'province_id1' => $province_id1,
|
|
'city_id' => $city_id,
|
|
'city_id1' => $city_id1,
|
|
'status' => 1,
|
|
'c_time' => time(),
|
|
);
|
|
$group_id && $add['group_id'] = $group_id;
|
|
$biz_id_arr && $add['biz_id'] = implode(',', $biz_id_arr);
|
|
$add['group_id1'] = $group_id1 ? $group_id1 : 0;
|
|
$biz_id_arr1 && $add['biz_id1'] = implode(',', $biz_id_arr1);
|
|
|
|
$id = $this->userM->add($add);
|
|
if ($id && $group_id == 4 && $biz_id_arr) {//加理车宝渠道门店
|
|
$this->channel_biz(["uid" => $id, 'biz_id_arr' => $biz_id_arr]);
|
|
}
|
|
if ($id && $group_id1 == 4 && $biz_id_arr1) {//加理车宝渠道门店 group_id1
|
|
$this->channel_biz(["uid" => $id, 'biz_id_arr' => $biz_id_arr1, 'edit' => 1, 'group_id1' => true]);
|
|
}
|
|
return $this->show_json(SYS_CODE_SUCCESS, '操作成功', '/app/licheb/member');
|
|
}
|
|
|
|
//编辑单条数据
|
|
public function edit()
|
|
{
|
|
$info = $this->input->post('info');
|
|
$id = $info['id'];
|
|
$uname = $info['uname'];
|
|
$nickname = $info['nickname'];
|
|
$mobile = $info['mobile'];
|
|
$province_id = $info['province_id'];
|
|
$city_id = $info['city_id'];
|
|
$group_id = $info['group_id'];
|
|
$bizs = $info['bizs'];
|
|
$biz_id_arr = is_array($bizs) ? array_column($bizs, 'biz_id') : '';
|
|
$province_id1 = $info['province_id1'];
|
|
$city_id1 = $info['city_id1'];
|
|
$group_id1 = $info['group_id1'];
|
|
$bizs1 = $info['bizs1'];
|
|
$biz_id_arr1 = is_array($bizs1) ? array_column($bizs1, 'biz_id') : '';
|
|
|
|
if (!mobile_valid($mobile)) {
|
|
return $this->show_json(SYS_CODE_FAIL, '输入正确手机号');
|
|
}
|
|
if (!$uname) {
|
|
return $this->show_json(SYS_CODE_FAIL, '请输入姓名');
|
|
}
|
|
|
|
$upd = array(
|
|
'mobile' => $mobile,
|
|
'province_id' => $province_id,
|
|
'province_id1' => $province_id1,
|
|
'city_id' => $city_id,
|
|
'city_id1' => $city_id1,
|
|
);
|
|
|
|
$upd['group_id'] = $group_id ? $group_id : 0;
|
|
$upd['biz_id'] = $biz_id_arr ? implode(',', $biz_id_arr) : 0;
|
|
$upd['group_id1'] = $group_id1 ? $group_id1 : 0;
|
|
$upd['biz_id1'] = $biz_id_arr1 ? implode(',', $biz_id_arr1) : 0;
|
|
|
|
$nickname && $upd['nickname'] = $nickname;
|
|
$uname && $upd['uname'] = $uname;
|
|
|
|
$this->userM->update($upd, array('id' => $id));
|
|
if ($id && $group_id == 4) {//加理车宝渠道门店
|
|
$this->channel_biz(["uid" => $id, 'biz_id_arr' => $biz_id_arr, 'edit' => 1]);
|
|
}
|
|
if ($id && $group_id1 == 4) {//加理车宝渠道门店 group_id1
|
|
$this->channel_biz(["uid" => $id, 'biz_id_arr' => $biz_id_arr1, 'edit' => 1, 'group_id1' => true]);
|
|
}
|
|
return $this->show_json(SYS_CODE_SUCCESS, '操作成功');
|
|
}
|
|
|
|
//删除单条数据
|
|
public function del()
|
|
{
|
|
|
|
}
|
|
|
|
//批量操作(默认修改状态)
|
|
public function batch()
|
|
{
|
|
$field = $this->input->post('field');
|
|
if ($field === 'ifcheck') {
|
|
$status = intval($this->input->post('value'));
|
|
$ids = $this->input->post('id');
|
|
$ids = explode(',', $ids);
|
|
if (!$ids || count($ids) < 1) {
|
|
$this->show_json(0, '请选择要操作的选项');
|
|
}
|
|
$where = array('id in(' . implode(',', $ids) . ')' => null);
|
|
} else {
|
|
$id = intval($this->input->post('id'));
|
|
$status = intval($this->input->post('value'));
|
|
if (!$id) {
|
|
$this->show_json(0, '参数错误');
|
|
}
|
|
$where['id'] = $id;
|
|
}
|
|
$data['status'] = $status;
|
|
$this->userM->update($data, $where);
|
|
return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
|
|
}
|
|
|
|
//导出数据列表
|
|
public function export()
|
|
{
|
|
|
|
}
|
|
|
|
function json_lists()
|
|
{
|
|
$biz_id = $this->input->post('biz_id');
|
|
$status = $this->input->post('status');
|
|
$page = $this->input->post('page');
|
|
$size = $this->input->post('size');
|
|
$type = intval($this->input->post('type'));
|
|
$if_mobile = intval($this->input->post('if_mobile'));
|
|
|
|
$where = array();
|
|
if (strlen($status) > 0) {
|
|
$where['status'] = $status;
|
|
} else {
|
|
$whre['status > -1'] = null;
|
|
}
|
|
$biz_id && $where['biz_id'] = $biz_id;
|
|
$total = $this->userM->count($where);
|
|
$lists = $uids = array();
|
|
if ($total) {
|
|
$select = $if_mobile ? 'id,uname,mobile' : 'id,uname';
|
|
$rows = $this->userM->select($where, 'id desc', $page, $size, $select);
|
|
foreach ($rows as $v) {
|
|
$uids[$v['id']] = $v['id'];
|
|
$title = $if_mobile ? $v['uname'] . "({$v['mobile']})" : $v['uname'];
|
|
$lists[] = array(
|
|
'id' => $v['id'],
|
|
'title' => $title,
|
|
);
|
|
}
|
|
}
|
|
if ($type == 1) {//查找客户成功经理
|
|
$where2 = ['status' => 1, 'group_id' => 4];
|
|
$where2["id in(select uid from lc_app_licheb_channel_biz where biz_id = {$biz_id})"] = null;
|
|
$total2 = $this->userM->count($where2);
|
|
if ($total2) {
|
|
$rows2 = $this->userM->select($where2, 'id desc', $page, $size, 'id,uname,mobile');
|
|
foreach ($rows2 as $v) {
|
|
if (!$uids[$v['id']]) {
|
|
$title = $if_mobile ? $v['uname'] . "({$v['mobile']}渠道)" : $v['uname'] . '(渠道)';
|
|
$lists[] = array(
|
|
'id' => $v['id'],
|
|
'title' => $title,
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$this->data = array('total' => $total, 'list' => $lists, 'list2' => $rows2);
|
|
return $this->show_json(SYS_CODE_SUCCESS);
|
|
}
|
|
|
|
/**
|
|
* Notes:加理车宝渠道门店
|
|
* Created on: 2021/11/12 14:54
|
|
* Created by: dengbw
|
|
* @param array $json
|
|
*/
|
|
function channel_biz($json = [])
|
|
{
|
|
$biz_ids = $json['biz_id_arr'] ? implode(',', $json['biz_id_arr']) : 0;
|
|
$group_id1 = $json['group_id1'] ? true : false;
|
|
if ($json['edit'] == 1) {//编辑删除未添加的
|
|
$where_d['uid'] = $json['uid'];
|
|
$biz_ids && $where_d["biz_id not in({$biz_ids})"] = null;
|
|
!$group_id1 && $this->mdChannelBiz->delete($where_d);
|
|
$group_id1 && $this->mdChannelBiz1->delete($where_d);
|
|
}
|
|
if (!$biz_ids) {
|
|
return;
|
|
}
|
|
$res_b = $this->biz_model->select(["id in({$biz_ids})" => null], '', 0, 0, 'id as biz_id');
|
|
foreach ($res_b as $key => $value) {
|
|
$where = ["uid" => $json['uid'], 'biz_id' => $value['biz_id']];
|
|
!$group_id1 && $re_cb = $this->mdChannelBiz->get($where);
|
|
$group_id1 && $re_cb = $this->mdChannelBiz1->get($where);
|
|
if (!$re_cb) {
|
|
$where['c_time'] = time();
|
|
!$group_id1 && $this->mdChannelBiz->add($where);
|
|
$group_id1 && $this->mdChannelBiz1->add($where);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Notes:获取门店客户成功经理
|
|
* Created on: 2021/11/15 11:31
|
|
* Created by: dengbw
|
|
* @return bool
|
|
*/
|
|
function get_channel_uid()
|
|
{
|
|
$biz_id = $this->input->get('biz_id');
|
|
if (!$biz_id) {
|
|
return $this->show_json(SYS_CODE_FAIL, '参数错误');
|
|
}
|
|
$res_b = $this->mdChannelBiz->select(["biz_id" => $biz_id], '', 0, 0, 'uid');
|
|
$this->data = $res_b ? array_column($res_b, 'uid') : [];
|
|
return $this->show_json(SYS_CODE_SUCCESS);
|
|
}
|
|
|
|
/**
|
|
* Notes:保存渠道管理员
|
|
* Created on: 2021/11/15 15:54
|
|
* Created by: dengbw
|
|
* @return bool
|
|
*/
|
|
function edit_channel_uid()
|
|
{
|
|
$biz_id = $this->input->post('biz_id');
|
|
$channel_uid = $this->input->post('channel_uid');
|
|
if (!$biz_id) {
|
|
return $this->show_json(SYS_CODE_FAIL, '参数错误');
|
|
}
|
|
$re_biz = $this->biz_model->get(['id' => $biz_id]);
|
|
if (!$re_biz) {
|
|
return $this->show_json(SYS_CODE_FAIL, '店铺不存在!');
|
|
}
|
|
$where_del['biz_id'] = $biz_id;
|
|
if ($channel_uid) {
|
|
$channel_uid_str = implode(',', $channel_uid);
|
|
$where_del["uid not in({$channel_uid_str})"] = null;
|
|
}
|
|
$res_b = $this->mdChannelBiz->select($where_del, '', 0, 0, 'uid'); //临时
|
|
$this->mdChannelBiz->delete($where_del);
|
|
//临时
|
|
foreach ($res_b as $key => $value) {
|
|
$res_b2 = $this->mdChannelBiz->select(['uid' => $value['uid']], '', 0, 0, 'biz_id');
|
|
$biz_id_up = $res_b2 ? array_unique(array_column($res_b2, 'biz_id')) : 0;
|
|
$biz_id_up && $biz_id_up = implode(',', $biz_id_up);
|
|
$this->userM->update(['biz_id' => $biz_id_up], ['id' => $value['uid']]);
|
|
}
|
|
//临时
|
|
if ($channel_uid) {
|
|
foreach ($channel_uid as $key => $value) {
|
|
$uid = $value;
|
|
$where = ["uid" => $uid, 'biz_id' => $biz_id];
|
|
$re_cb = $this->mdChannelBiz->get($where);
|
|
if (!$re_cb) {
|
|
$where['c_time'] = time();
|
|
$this->mdChannelBiz->add($where);
|
|
//临时
|
|
$res_b2 = $this->mdChannelBiz->select(['uid' => $uid], '', 0, 0, 'biz_id');
|
|
$biz_id_up = $res_b2 ? array_unique(array_column($res_b2, 'biz_id')) : 0;
|
|
$biz_id_up && $biz_id_up = implode(',', $biz_id_up);
|
|
$this->userM->update(['biz_id' => $biz_id_up], ['id' => $uid]);
|
|
//临时
|
|
}
|
|
}
|
|
}
|
|
return $this->show_json(SYS_CODE_SUCCESS, '操作成功');
|
|
}
|
|
|
|
/**
|
|
* Notes:获取门店管理员
|
|
* Created on: 2021/11/15 17:33
|
|
* Created by: dengbw
|
|
* @return bool
|
|
*/
|
|
function get_users_group()
|
|
{
|
|
$group_id = $this->input->get('group_id');
|
|
$biz_id = $this->input->get('biz_id');
|
|
$admin_name = $this->input->get('admin_name');
|
|
if (!$group_id || !$biz_id) {
|
|
return $this->show_json(SYS_CODE_FAIL, '参数错误');
|
|
}
|
|
$where = ["group_id" => $group_id, 'status >' => -1];
|
|
$admin_name && $where['uname like "%' . $admin_name . '%"'] = null;
|
|
$res_u = $this->userM->select($where, '', 0, 0, 'id,uname as name');
|
|
$res_u2 = $this->userM->select(array_merge($where, ['biz_id' => $biz_id]), '', 0, 0, 'id');
|
|
$this->data['admins'] = $res_u ? $res_u : [];
|
|
$this->data['admin_id'] = $res_u2 ? array_column($res_u2, 'id') : [];
|
|
return $this->show_json(SYS_CODE_SUCCESS);
|
|
}
|
|
|
|
/**
|
|
* Notes:保存门店管理员
|
|
* Created on: 2021/11/15 17:33
|
|
* Created by: dengbw
|
|
* @return bool
|
|
*/
|
|
function edit_users_group()
|
|
{
|
|
$biz_manage = $this->input->post('biz_manage');
|
|
if (!$biz_manage['biz_id']) {
|
|
return $this->show_json(SYS_CODE_FAIL, '参数错误');
|
|
}
|
|
if (!$biz_manage['admin_name']) {
|
|
$where_del = ['biz_id' => $biz_manage['biz_id'], 'group_id' => $biz_manage['group_id']];
|
|
if ($biz_manage['admin_id']) {
|
|
$admin_id_str = implode(',', $biz_manage['admin_id']);
|
|
$where_del["id not in({$admin_id_str})"] = null;
|
|
}
|
|
$this->userM->update(["biz_id" => 0], $where_del);
|
|
}
|
|
foreach ($biz_manage['admin_id'] as $key => $value) {
|
|
$this->userM->update(["biz_id" => $biz_manage['biz_id']], ['id' => $value]);
|
|
}
|
|
return $this->show_json(SYS_CODE_SUCCESS, '操作成功');
|
|
}
|
|
}
|