当前位置: 首页 > article >正文

悟空crm客户管理系统二次开发 单独新增表格字段

1,仪表盘(数据来源修改)

注意点:有层级关系,管理员账号可以看到全部数据,主管只能看到下属数据。
在这里插入图片描述

在这里插入图片描述

2、在客户管理菜单里面 增加一个时间筛选、额度汇总

在这里插入图片描述

    /**
     * 获取客户列表
     *
     * @param $type
     * @param $content
     * @return bool|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    private function getCustomerList($type, $content)
{
    # 默认条件
    $customerWhere = $this->getCustomerWhere();
    
    # 查询条件
    $searchWhere = $this->getSearchWhere($type, $content);
    
    # 查询字段
    $field = ['customer_id', 'name', 'create_time', 'owner_user_id', 'deal_time', 'telephone', 'mobile'];
    
    return db('crm_customer')->alias('customer')->field($field)->where($customerWhere)
        ->where($searchWhere)->limit(10)->order('update_time', 'desc')->select();
}

3,单独新增一个今日数据表格

(以表格的形式呈现出来)
需求:
3.1,需要关联部门和员工层级关系,比如:普通员工只填写自己的数据,部门领导客户看到下面人员所有数据,管理员可以看到所有部门数据。
3.2,条件筛选,时间筛选、部门筛选、员工筛选、全部
3.3,表格可以自定义增删改,自定义隐藏和开启字段
在这里插入图片描述

  public function getDataList($request)
    {
        $userModel = new \app\admin\model\User();
        $structureModel = new \app\admin\model\Structure();
        $fieldModel = new \app\admin\model\Field();
        $customerModel = new \app\crm\model\Customer();
        $search = $request['search'];
        $user_id = $request['user_id'];
        $scene_id = (int)$request['scene_id'];
        $is_excel = $request['is_excel']; //导出
        $order_field = $request['order_field'];
        $order_type = $request['order_type'];
        $pageType = $request['pageType'];
        $getCount = $request['getCount'];
        
        $cstart_time = $request['cstart_time'];
        $cend_time = $request['cend_time'];
        
        //需要过滤的参数
        $unsetRequest = [
            'scene_id', 'search', 'user_id', 'is_excel', 'action', 'order_field', 'order_type', 'is_remind', 'getCount', 'type', 'otherMap', 'business_id', 'check_status'
            ,'cstart_time','cend_time'
        ];
        foreach ($unsetRequest as $v) {
            unset($request[$v]);
        }
        
        $request = $this->fmtRequest($request);
        $requestMap = $request['map'] ?: [];
        
        $sceneModel = new \app\admin\model\Scene();
        if ($scene_id) {
            //自定义场景
            $sceneMap = $sceneModel->getDataById($scene_id, $user_id, 'todaydata') ?: [];
        } else {
            //默认场景
            $sceneMap = $sceneModel->getDefaultData('crm_todaydata', $user_id) ?: [];
        }
        $searchMap = [];
        if ($search || $search == '0') {
            //普通筛选
            $searchMap = function ($query) use ($search) {
                $query->where('todaydata.name', array('like', '%' . $search . '%'))
                    ->whereOr('todaydata.mobile', array('like', '%' . $search . '%'))
                    ->whereOr('todaydata.telephone', array('like', '%' . $search . '%'));
            };
        }
        $partMap = [];
        //优先级:普通筛选>高级筛选>场景
        $teamMap=$requestMap['team_id'];
        //团队成员 高级筛选
        if($teamMap){
            $partMap= advancedQueryFormatForTeam($teamMap,'todaydata','todaydata_id');
            unset($requestMap['team_id']);
            $map = $requestMap ? array_merge($sceneMap, $requestMap) : $sceneMap;
        } else {
            $map = $requestMap ? array_merge($sceneMap, $requestMap) : $sceneMap;
        }
        //高级筛选
        $map = advancedQuery($map, 'crm', 'todaydata', 'index');
        //权限

            $a = 'index';
            if ($is_excel) $a = 'excelExport';
            $authMap = [];
            $auth_user_ids = $userModel->getUserByPer('crm', 'todaydata', $a);
            if (isset($map['todaydata.owner_user_id'])) {
                if (!is_array($map['todaydata.owner_user_id'][1])) {
                    $map['todaydata.owner_user_id'][1] = [$map['todaydata.owner_user_id'][1]];
                }
                if (in_array($map['todaydata.owner_user_id'][0], ['neq', 'notin'])) {
                    $auth_user_ids = array_diff($auth_user_ids, $map['todaydata.owner_user_id'][1]) ?: [];    //取差集
                } else {
                    $auth_user_ids = array_intersect($map['todaydata.owner_user_id'][1], $auth_user_ids) ?: [];    //取交集
                }
                unset($map['todaydata.owner_user_id']);
                $auth_user_ids = array_merge(array_unique(array_filter($auth_user_ids))) ?: ['-1'];
                //负责人、相关团队
                $authMap['todaydata.owner_user_id'] = ['in', $auth_user_ids];
            } else {
                $authMapData = [];
                $authMapData['auth_user_ids'] = $auth_user_ids;
                $authMapData['user_id'] = $user_id;
                $authMap = function ($query) use ($authMapData) {
                    $query->where('todaydata.owner_user_id', array('in', $authMapData['auth_user_ids']));
                        // ->whereOr('todaydata.ro_user_id', array('like', '%,' . $authMapData['user_id'] . ',%'))
                        // ->whereOr('todaydata.rw_user_id', array('like', '%,' . $authMapData['user_id'] . ',%'));
                };
            }

        $timeWhere = '';
        if($cstart_time){
            $timeWhere .= 'todaydata.create_time>='.strtotime($cstart_time);
        }
        if($cend_time){
            if($timeWhere) $timeWhere .= ' and ';
            $timeWhere .= 'todaydata.create_time<'.strtotime('+1 day', strtotime($cend_time));
        }

        //列表展示字段
        $indexField = $fieldModel->getIndexField('crm_todaydata', $user_id, 1) ?: array('name');
        $userField = $fieldModel->getFieldByFormType('crm_todaydata', 'user'); //人员类型
        $structureField = $fieldModel->getFieldByFormType('crm_todaydata', 'structure');  //部门类型
        $datetimeField = $fieldModel->getFieldByFormType('crm_todaydata', 'datetime'); //日期时间类型
        $booleanField = $fieldModel->getFieldByFormType('crm_todaydata', 'boolean_value'); //布尔值
        $dateIntervalField = $fieldModel->getFieldByFormType('crm_todaydata', 'date_interval'); // 日期区间类型字段
        $positionField = $fieldModel->getFieldByFormType('crm_todaydata', 'position'); // 地址类型字段
        $handwritingField = $fieldModel->getFieldByFormType('crm_todaydata', 'handwriting_sign'); // 手写签名类型字段
        $locationField = $fieldModel->getFieldByFormType('crm_todaydata', 'location'); // 定位类型字段
        $boxField = $fieldModel->getFieldByFormType('crm_todaydata', 'checkbox'); // 多选类型字段
        $floatField = $fieldModel->getFieldByFormType('crm_todaydata', 'floatnumber'); // 货币类型字段
//        $fieldGrant = db('admin_field_mask')->where('types', 'todaydata')->select();
        # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段)
        $temporaryField = str_replace('_name', '', $order_field);
        if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) {
            $order_field = $temporaryField;
        }
        //排序
        if ($order_type && $order_field) {
            $order = $fieldModel->getOrderByFormtype('crm_todaydata', 'todaydata', $order_field, $order_type);
        } else {
            $order = 'todaydata.update_time desc';
        }
        $readAuthIds = $userModel->getUserByPer('crm', 'todaydata', 'read');
        $updateAuthIds = $userModel->getUserByPer('crm', 'todaydata', 'update');
        $deleteAuthIds = $userModel->getUserByPer('crm', 'todaydata', 'delete');
        $customerWhere = [];
        if ($pageType == !'all') {
            //非客户池条件
            // $customerWhere = $customerModel->getWhereByCustomer();
        }
        $dataCount = db('crm_todaydata')
            ->alias('todaydata')
            ->join('__CRM_CUSTOMER__ customer', 'todaydata.customer_id = customer.customer_id', 'LEFT')
            ->where($map)
            ->where($searchMap)
            ->where($authMap)
            ->where($partMap)
            ->where($customerWhere)
            ->where($timeWhere)
            ->count('todaydata_id');
        if ($getCount == 1) {
            $data['dataCount'] = $dataCount ?: 0;
            return $data;
        }
        
        $statisticsField = [
            'sum(jrxh) as total_jrxh',
            'sum(jrjfrs) as total_jrjfrs',
            'sum(zsy) as total_zsy',
            'sum(total_follow_buy) as total_total_follow_buy',
            'sum(yxkh) as total_yxkh',
            'sum(zgm) as total_zgm',
        ];
        if($dataCount > 0){
            $statisticsField[] = 'ROUND(sum(zhl) / '.$dataCount.', 2) as total_zhl';
        }else{
            $statisticsField[] = '0 as total_zhl';
        }
        $statistics = db('crm_todaydata')->alias('todaydata')
                                    ->field($statisticsField)
                        			->where($map)
                                    ->where($searchMap)
                                    ->where($partMap)
                                    ->where($authMap)
                                    ->where($customerWhere)
                                    ->where($timeWhere)
                        			->find();
        if(!$statistics){
            $statistics = [
                'total_jrxh' => 0,
                'total_jrjfrs' => 0,
                'total_zsy' => 0,
                'total_total_follow_buy' => 0,
                'total_yxkh' => 0,
                'total_zgm' => 0,
                'total_zhl' => 0,
            ];
        }

        $list = db('crm_todaydata')
            ->alias('todaydata')
            ->join('__CRM_CUSTOMER__ customer', 'todaydata.customer_id = customer.customer_id', 'LEFT')
            ->where($map)
            ->where($searchMap)
            ->where($partMap)
            ->where($authMap)
            ->where($customerWhere)
            ->where($timeWhere)
            ->limit($request['offset'], $request['length'])
            ->field('todaydata.*,customer.name as customer_name')
            ->orderRaw($order)
            ->select();
        # 扩展数据
        $extraData = [];
        $todaydata_id_list = !empty($list) ? array_column($list, 'todaydata_id') : [];
        $grantData = getFieldGrantData($user_id);
        foreach ($grantData['crm_todaydata'] as $key => $value) {
            foreach ($value as $ke => $va) {
                if($va['maskType']!=0){
                    $fieldGrant[$ke]['maskType'] = $va['maskType'];
                    $fieldGrant[$ke]['form_type'] = $va['form_type'];
                    $fieldGrant[$ke]['field'] = $va['field'];
                }
            }
        }
        foreach ($list as $k => $v) {
            $list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : [];
            $list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : [];
            $list[$k]['customer_id_info']['customer_id'] = $v['customer_id'] ?: '';
            $list[$k]['customer_id_info']['name'] = $v['customer_name'] ?: '';
            foreach ($userField as $key => $val) {
                $usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : [];
                $list[$k][$val] = implode($usernameField, ',');
            }
            foreach ($structureField as $key => $val) {
                $structureNameField = !empty($v[$val]) ? db('admin_structure')->whereIn('id', stringToArray($v[$val]))->column('name') : [];
                $list[$k][$val] = implode($structureNameField, ',');
            }
            foreach ($datetimeField as $key => $val) {
                $list[$k][$val] = !empty($v[$val]) ? date('Y-m-d H:i:s', $v[$val]) : null;
            }
            foreach ($booleanField as $key => $val) {
                $list[$k][$val] = !empty($v[$val]) ? (string)$v[$val] : '0';
            }
            // 处理日期区间类型字段的格式
            foreach ($dateIntervalField as $key => $val) {
                $list[$k][$val] = !empty($extraData[$v['todaydata_id']][$val]) ? json_decode($extraData[$v['todaydata_id']][$val], true) : null;
            }
            // 处理地址类型字段的格式
            foreach ($positionField as $key => $val) {
                $list[$k][$val] = !empty($extraData[$v['todaydata_id']][$val]) ? json_decode($extraData[$v['todaydata_id']][$val], true) : null;
            }
            // 手写签名类型字段
            foreach ($handwritingField as $key => $val) {
                $handwritingData = !empty($v[$val]) ? db('admin_file')->where('file_id', $v[$val])->value('file_path') : null;
                $list[$k][$val] = ['url' => !empty($handwritingData) ? getFullPath($handwritingData) : null];
            }
            // 定位类型字段
            foreach ($locationField AS $key => $val) {
                $list[$k][$val] = !empty($extraData[$v['todaydata_id']][$val]) ? json_decode($extraData[$v['todaydata_id']][$val], true) : null;
            }
            // 多选框类型字段
            foreach ($boxField AS $key => $val) {
                $list[$k][$val] = !empty($v[$val]) ? trim($v[$val], ',') : null;
            }
            // 货币类型字段
            foreach ($floatField AS $key => $val) {
                $list[$k][$val] = $v[$val]!='0.00' ? (string)$v[$val] : null;
            }
            //掩码相关类型字段
            foreach ($fieldGrant AS $key => $val){
                //掩码相关类型字段
                if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
                    $pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
                    $rs = preg_replace($pattern, "$1****$2", $v[$val['field']]);
                    $list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)$rs : null;
                } elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
                    $email_array = explode("@", $v[$val['field']]);
                    $prevfix = (strlen($email_array[0]) < 4) ? "" : substr($v[$val['field']], 0, 2); //邮箱前缀
                    $str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $v[$val['field']], -1, $count);
                    $rs = $prevfix . $str;
                    $list[$k][$val['field']] = !empty($v[$val['field']]) ?$rs: null;
                } elseif ($val['maskType']!=0 && in_array($val['form_type'],['position','floatnumber'])) {
                    $list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)substr_replace($v[$val['field']], '*****',0,strlen($v[$val['field']])) : null;
                }
            }
            //权限
            $permission = [];
            $is_read = 0;
            $is_update = 0;
            $is_delete = 0;
            if (in_array($v['owner_user_id'], $readAuthIds)) $is_read = 1;
            if (in_array($v['owner_user_id'], $updateAuthIds)) $is_update = 1;
            if (in_array($v['owner_user_id'], $deleteAuthIds)) $is_delete = 1;
            $permission['is_read'] = $is_read;
            $permission['is_update'] = $is_update;
            $permission['is_delete'] = $is_delete;
            $list[$k]['permission'] = $permission;
            
            # 关注
            $starWhere = ['user_id' => $user_id, 'target_id' => $v['todaydata_id'], 'type' => 'crm_todaydata'];
            $star = Db::name('crm_star')->where($starWhere)->value('star_id');
            $list[$k]['star'] = !empty($star) ? 1 : 0;
            # 日期
            // $list[$k]['create_time'] = !empty($v['create_time']) ? date('Y-m-d H:i:s', $v['create_time']) : null;
            $list[$k]['create_time'] = !empty($v['create_time']) ? date('Y-m-d', $v['create_time']) : null;
            $list[$k]['update_time'] = !empty($v['update_time']) ? date('Y-m-d H:i:s', $v['update_time']) : null;
            $list[$k]['last_time'] = !empty($v['last_time']) ? date('Y-m-d H:i:s', $v['last_time']) : null;
            # 创建人
            $list[$k]['create_user_name'] = !empty($list[$k]['create_user_id_info']['realname']) ? $list[$k]['create_user_id_info']['realname'] : '';
            # 负责人
            $list[$k]['owner_user_name'] = !empty($list[$k]['owner_user_id_info']['realname']) ? $list[$k]['owner_user_id_info']['realname'] : '';

            # 系统字段  负责人部门   zjf  20210726
            $list[$k]['owner_user_structure_name'] = $list[$k]['owner_user_id_info']['structure_name'];
        }
        $data = [];
        $data['list'] = $list;
        $data['dataCount'] = $dataCount ?: 0;
        $data['statistics'] = $statistics ?: [];
        return $data;
    }

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

二次开发增加的条件筛选:

时间筛选、部门筛选、员工筛选、全部
在这里插入图片描述

  /**
     * 获取查询条件
     *
     * @param $type
     * @param $content
     * @return array|\Closure
     */
    private function getSearchWhere($type, $content)
{
    $searchWhere = [];
    
    # 查询客户名称
    if ($type == 'name') {
        $searchWhere = function ($query) use ($content) {
            $query->where('name', 'like', '%' . $content . '%');
        };
    }
    
    # 查询手机或电话
    if ($type == 'phone') {
        $searchWhere = function ($query) use ($content) {
            $query->where(function ($query) use ($content) {
                $query->whereOr('telephone', $content);
                $query->whereOr('mobile', $content);
            });
        };
    }
    
    return $searchWhere;
}

悟空crm客户管理系统二次开发
在这里插入图片描述


http://www.kler.cn/a/304783.html

相关文章:

  • 计算机新手练级攻略——如何搜索问题
  • 讲讲关于SNMP与智能PDU插座
  • [CKS] Create/Read/Mount a Secret in K8S
  • Spring学习笔记(四)
  • <项目代码>YOLOv8 苹果腐烂识别<目标检测>
  • QML项目实战:自定义CheckBox
  • Kafka客户端核心参数详解
  • Java面试篇基础部分-Java注解详解
  • Visual Studio Code 高效开发 C/C++ 插件推荐
  • 开发游戏的学习规划
  • 基于扣子(Coze)打造第一个智能体——个性化对话机器人
  • 智能语音技术在人机交互中的应用与发展
  • 中国农业银行——轻量式云原生应用平台(轻云平台)
  • swiftUI结构体数组修改属性UI没更新
  • Go协程及并发锁应用指南
  • 深入理解Go语言的方法定义与使用
  • 深入理解Go语言中的接口定义与使用
  • 『功能项目』战士职业平A怪物掉血【44】
  • SVM——支持向量机的学习入门
  • 【运维监控】influxdb 2.0+grafana 监控java 虚拟机以及方法耗时情况(完整版)
  • GPS/LBS/Wi-Fi定位,全安排!—合宙Air201资产定位模组LuatOS快速入门04
  • Leetcode 每日一题:Decode String
  • LVS-DR
  • JMeter测试工具的简单了解
  • java和kotlin 可以同时运行吗
  • 高性能微服务架构:Spring Boot 集成 gRPC 实现用户与订单服务即时交互