Browse Source

员工管理、团队管理、客户管理

yb 7 months ago
parent
commit
d794281229

+ 47 - 0
app/admin/controller/consultant/CustomController.php

@@ -0,0 +1,47 @@
+<?php
+
+
+namespace app\admin\controller\consultant;
+
+
+use app\admin\service\consultant\CustomService;
+use app\admin\validate\consultant\MarketCustomerValidate;
+use app\controller\Curd;
+use app\model\MarketCustomer;
+use support\Request;
+
+class CustomController extends Curd
+{
+    public function __construct()
+    {
+        $this->model = new MarketCustomer();
+        $this->validate = true;
+        $this->validateClass = new MarketCustomerValidate();
+    }
+
+    /**
+     * Notes: 获取选项配置信息
+     * User: yb
+     * Date: 2024/8/5
+     * Time: 15:35
+     */
+    public function getOptionConfig()
+    {
+        return json_success('请求成功', CustomService::config());
+    }
+
+    /**
+     * Notes: 新增客户
+     * User: yb
+     * Date: 2024/8/6
+     * Time: 11:19
+     */
+    public function addCustom(Request $request)
+    {
+        $params = $request->post();
+        if ($this->validate && !$this->validateClass->scene('add')->check($params)) {
+            return json_fail($this->validateClass->getError());
+        }
+        return CustomService::add($params);
+    }
+}

+ 99 - 0
app/admin/controller/consultant/IndexController.php

@@ -0,0 +1,99 @@
+<?php
+
+
+namespace app\admin\controller\consultant;
+
+
+use app\admin\service\consultant\ConsultantService;
+use app\admin\validate\consultant\IndexValidate;
+use app\controller\Curd;
+use app\model\Consultant;
+use support\Request;
+use support\Response;
+
+class IndexController extends Curd
+{
+    public function __construct()
+    {
+        $this->model = new Consultant();
+        $this->validate = true;
+        $this->validateClass = new IndexValidate();
+    }
+
+    public function select(Request $request): Response
+    {
+        return ConsultantService::index($request);
+    }
+
+    /**
+     * Notes: 添加员工
+     * User: yb
+     * Date: 2024/8/2
+     * Time: 10:59
+     * @param Request $request
+     */
+    public function addConsultant(Request $request)
+    {
+        $params = $request->post();
+        if (empty($params['name'])) {
+            return json_fail('请输入员工姓名');
+        }
+        if (empty($params['mobile'])) {
+            return json_fail('请输入员工手机号');
+        }
+        if (empty($params['dept_id'])) {
+            return json_fail('请选择所属团队');
+        }
+        return ConsultantService::add($params);
+    }
+
+    /**
+     * Notes: 更新员工信息
+     * User: yb
+     * Date: 2024/8/2
+     * Time: 13:31
+     * @param Request $request
+     * @return Response
+     */
+    public function updateConsultant(Request $request)
+    {
+        $params = $request->post();
+        if (empty($params['name'])) {
+            return json_fail('请输入员工姓名');
+        }
+        if (empty($params['mobile'])) {
+            return json_fail('请输入员工手机号');
+        }
+        return ConsultantService::update($params);
+    }
+
+    /**
+     * Notes: 删除员工
+     * User: yb
+     * Date: 2024/8/2
+     * Time: 13:34
+     * @param Request $request
+     * @return Response
+     */
+    public function deleteConsultant(Request $request)
+    {
+        $params = $request->post();
+        if (empty($params['ids'])) {
+            return json_fail('请选择要删除的数据');
+        }
+        return ConsultantService::delete($params['ids']);
+    }
+
+    /**
+     * Notes: 绑定后台用户
+     * User: yb
+     * Date: 2024/8/5
+     * Time: 10:51
+     */
+    public function getUserList()
+    {
+        return ConsultantService::userList();
+    }
+
+
+}

+ 131 - 0
app/admin/controller/consultant/TeamController.php

@@ -0,0 +1,131 @@
+<?php
+
+
+namespace app\admin\controller\consultant;
+
+use app\admin\service\consultant\TeamService;
+use app\common\Tree;
+use app\controller\Curd;
+use app\model\Consultant;
+use app\model\SysDept;
+use support\Request;
+use support\Response;
+
+class TeamController extends Curd
+{
+
+    public function __construct()
+    {
+        $this->model = new SysDept();
+    }
+
+    public function select(Request $request): Response
+    {
+        [$where, $format, $limit, $field, $order] = $this->selectInput($request);
+        $format = 'tree';
+        $order = $request->get('order', 'desc');
+        $field = $field ?? 'dept_addtimes';
+        $where['dept_category'] = '获客团队';
+        $query = $this->doSelect($where, $field, $order);
+        return $this->doFormat($query, $format, 1000);
+    }
+
+    protected function afterQuery($items)
+    {
+        foreach ($items as &$item) {
+            $item->nums = Consultant::where('dept_id',$item->dept_id)->orWhere('top_dept_id', $item->dept_id)->count();
+        }
+        return $items;
+    }
+
+    protected function formatTree($items): Response
+    {
+        $format_items = [];
+        foreach ($items as $item) {
+            $format_items[] = [
+                'name' => $item->dept_name,
+                'value' => (string)$item->dept_id,
+                'id' => $item->id ?? $item->dept_id,
+                'pid' => $item->pid ?? $item->dept_super_id,
+                'dept_id' => $item->dept_id,
+                'dept_name' => $item->dept_name,
+                'dept_super_id' => $item->dept_super_id,
+                'dept_status' => $item->dept_status,
+                'dept_category' => $item->dept_category,
+                'dept_code' => $item->dept_code,
+                'dept_telephone' => $item->dept_telephone,
+                'category_addtimes' => $item->category_addtimes,
+                'nums' => $item->nums
+            ];
+        }
+        $tree = new Tree($format_items);
+        return json_success('success', $tree->getTree());
+    }
+
+    /**
+     * Notes: 上级团队
+     * User: yb
+     * Date: 2024/8/1
+     * Time: 17:16
+     */
+    public function parentList()
+    {
+        return TeamService::parentList();
+    }
+
+    /**
+     * @Desc 部门详情
+     * @Author Gorden
+     * @Date 2024/2/21 10:35
+     *
+     * @param $id
+     * @return \support\Response
+     */
+    public function deptInfo($id)
+    {
+        return TeamService::deptInfo($id);
+    }
+
+    /**
+     * @Desc 创建部门
+     * @Author Gorden
+     * @Date 2024/2/21 9:22
+     *
+     * @param Request $request
+     * @return \support\Response
+     */
+    public function addDept(Request $request)
+    {
+        $params = $request->post();
+        if (empty($params['dept_name'])) {
+            return json_fail('团队名称不能为空');
+        }
+        return TeamService::insertDept($params);
+    }
+
+    /**
+     * @Desc 修改部门
+     * @Author Gorden
+     * @Date 2024/2/21 10:15
+     *
+     * @param $id
+     * @param Request $request
+     * @return \support\Response
+     */
+    public function updateDept(Request $request)
+    {
+        $params = $request->post();
+        if (empty($params['id'])) {
+            return json_fail('团队id不能为空');
+        }
+        if (empty($params['dept_name'])) {
+            return json_fail('团队名称不能为空');
+        }
+        return TeamService::updateDept($params);
+    }
+
+    public function delDept(Request $request)
+    {
+        return TeamService::delDept($request);
+    }
+}

+ 280 - 0
app/admin/service/consultant/ConsultantService.php

@@ -0,0 +1,280 @@
+<?php
+
+
+namespace app\admin\service\consultant;
+
+
+use app\model\Consultant;
+use app\model\SysDept;
+use app\model\SysUser;
+use support\Request;
+
+class ConsultantService
+{
+    public static function index(Request $request)
+    {
+        $format = $request->get('format', 'normal');
+        $limit = (int)$request->get('pageSize', $format === 'tree' ? 1000 : 10);
+        $limit = $limit <= 0 ? 10 : $limit;
+        $params = $request->get();
+        $page = (int)$request->get('page');
+        $page = $page > 0 ? $page : 1;
+        $where = [];
+        $whereDept = [];
+        $whereTopDept = [];
+        if (!empty($params['name'])) {
+            $where[] = ['name', 'like', "%{$params['name']}%"];
+        }
+        if (!empty($params['mobile'])) {
+            $where[] = ['mobile', 'like', "%{$params['mobile']}%"];
+        }
+        if (!empty($params['status'])) {
+            $where[] = ['status', '=', $params['status']];
+        }
+        if (!empty($params['dept_id'])) {
+            $deptId = end($params['dept_id']);
+            $whereDept[] = ['dept_id', '=', $deptId];
+            $whereTopDept[] = ['top_dept_id', '=', $deptId];
+        }
+        if (!empty($params['type'])) {
+            $where[] = ['type', '=', $params['type']];
+        }
+        $paginator = Consultant::where(function ($query) use ($whereDept, $whereTopDept) {
+                $query->orWhere($whereDept)
+                ->orWhere($whereTopDept);
+        })->where($where)->paginate($limit, '*', 'page', $page);
+        $total = $paginator->total();
+        $items = $paginator->items();
+        if (!empty($items)) {
+            $teamKeys = TeamService::getKeys();
+            foreach ($items as &$item) {
+                $teamName = [];
+                if (isset($teamKeys[$item->top_dept_id])) {
+                    $teamName[] = $teamKeys[$item->top_dept_id];
+                }
+                if (isset($teamKeys[$item->dept_id])) {
+                    $teamName[] = $teamKeys[$item->dept_id];
+                }
+                $item->team_name = !empty($teamName) ? implode('-', $teamName) : '';
+            }
+        }
+        $data = [
+            'total' => $total,
+            'rows' => $items
+        ];
+        return json_success('success', $data);
+    }
+
+    /**
+     * Notes: 添加员工
+     * User: yb
+     * Date: 2024/8/2
+     * Time: 11:03
+     * @param $params
+     */
+    public static function add($params)
+    {
+        if (!self::checkMobile($params['mobile'])) {
+            return json_fail('请输入正确的手机号');
+        }
+        //查询员工是否已被注册
+        if (Consultant::where('mobile', $params['mobile'])->exists()) {
+            return json_fail('手机号已存在,员工已被注册');
+        }
+        //校验密码规则
+        if (!empty($params['password'])) {
+            $passwordLen = strlen($params['password']);
+            if ($passwordLen > 20 || $passwordLen < 6) {
+                return json_fail('请输入6-20位密码');
+            }
+        }
+        //查询上级团队
+        $topDeptId = SysDept::where('dept_id', $params['dept_id'])->where('dept_category', TeamService::DEPT_CATEGORY)->value('dept_super_id');
+        if (!is_numeric($topDeptId)) {
+            return json_fail('团队不存在');
+        }
+        if (empty($params['password'])) {
+            $showPassword = substr($params['mobile'], 4);
+            $password = self::handlePassword($showPassword);
+        } else {
+            $password = self::handlePassword($params['password']);
+        }
+        $type = 2;
+        if (!empty($params['type'])) {
+            if (in_array($params['type'], [1,2])) {
+                $type = $params['type'];
+                if ($type == 2) {
+                    $params['relation_user_id'] = null;
+                }
+            }
+        }
+
+        $insertData = [
+            'name' => $params['name'],
+            'mobile' => $params['mobile'],
+            'dept_id' => $params['dept_id'],
+            'top_dept_id' => $topDeptId,
+            'gender' => $params['gender'] ?? 1,
+            'password' => $password,
+            'status' => $params['status'] ?? 1,
+            'relation_user_id' => $params['relation_user_id'] ?? null,
+            'type' => $type,
+            'created_at' => time()
+        ];
+        $result = Consultant::insert($insertData);
+        if ($result) {
+            return json_success('新增成功');
+        } else {
+            return json_fail('新增失败');
+        }
+    }
+
+    /**
+     * Notes: 更新员工信息
+     * User: yb
+     * Date: 2024/8/2
+     * Time: 11:54
+     * @param $params
+     */
+    public static function update($params)
+    {
+        if (empty($params['id'])) {
+            return json_fail('员工id不能为空');
+        }
+        //查找员工信息
+        $info = Consultant::find($params['id']);
+        if (empty($info)) {
+            return json_fail('员工不存在');
+        }
+        if (!self::checkMobile($params['mobile'])) {
+            return json_fail('请输入正确的手机号');
+        }
+        //查询员工是否已被注册
+        if (Consultant::where('mobile', $params['mobile'])->where('id', '<>', $params['id'])->exists()) {
+            return json_fail('手机号已存在,员工已被注册');
+        }
+        //校验密码规则
+        if (!empty($params['password'])) {
+            $passwordLen = strlen($params['password']);
+            if ($passwordLen > 20 || $passwordLen < 6) {
+                return json_fail('请输入6-20位密码');
+            }
+            $password = self::handlePassword($params['password']);
+        }
+        $type = 2;
+        if (!empty($params['type'])) {
+            if (in_array($params['type'], [1,2])) {
+                $type = $params['type'];
+                if ($type == 2) {
+                    $params['relation_user_id'] = null;
+                }
+            }
+        }
+        $updateData = [
+            'name' => $params['name'],
+            'mobile' => $params['mobile'],
+            'gender' => $params['gender'] ?? 1,
+            'status' => $params['status'] ?? 1,
+            'relation_user_id' => $params['relation_user_id'] ?? null,
+            'type' => $type,
+            'updated_at' => time()
+        ];
+        if (!empty($params['password'])) {
+            $updateData['password'] = $password;
+        }
+        $result = Consultant::where('id', $params['id'])->update($updateData);
+        if ($result) {
+            return json_success('更新成功');
+        } else {
+            return json_fail('更新失败');
+        }
+    }
+
+    /**
+     * Notes: 删除员工
+     * User: yb
+     * Date: 2024/8/2
+     * Time: 13:33
+     * @param $ids
+     * @return \support\Response
+     */
+    public static function delete($ids)
+    {
+        if (!$ids) {
+            return json_fail("数据错误");
+        }
+        if (!is_array($ids)) {
+            $ids = [$ids];
+        }
+        //查询员工下是否存在客户
+        try {
+            if (is_array($ids)) {
+                Consultant::whereIn('id', $ids)->delete();
+            } else {
+                Consultant::where('id', $ids)->delete();
+            }
+        } catch (\Exception $e) {
+            return json_fail('删除失败');
+        }
+
+        return json_success('删除成功');
+    }
+
+    /**
+     * Notes:
+     * User: yb
+     * Date: 2024/8/5
+     * Time: 10:52
+     */
+    public static function userList()
+    {
+        $deptIds = SysDept::where('dept_category', '=', '获客团队')->pluck('dept_id');
+        $deptIds = $deptIds->toArray();
+        $userList = SysUser::whereIn('join_user_dept_id', $deptIds)->select(['user_id', 'user_name', 'user_mobile'])->get();
+        return json_success('请求成功', $userList);
+    }
+
+    /**
+     * Notes:校验手机号
+     * User: yb
+     * Date: 2024/8/2
+     * Time: 11:12
+     * @param $mobile
+     * @return bool
+     */
+    protected static function checkMobile($mobile)
+    {
+        if (preg_match('/^1[0-9]\d{9}$/', $mobile)) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * Notes: 处理密码
+     * User: yb
+     * Date: 2024/8/2
+     * Time: 11:19
+     * @param $password
+     * @return mixed
+     */
+    protected static function handlePassword($password)
+    {
+        return md5(md5($password));
+    }
+
+    /**
+     * Notes: 处理出生日期
+     * User: yb
+     * Date: 2024/8/2
+     * Time: 11:28
+     * @param $birth
+     * @return false|string
+     */
+    protected static function handleBirth($birth)
+    {
+        return date('Y-m-d',strtotime($birth));
+    }
+
+}

+ 180 - 0
app/admin/service/consultant/CustomService.php

@@ -0,0 +1,180 @@
+<?php
+
+
+namespace app\admin\service\consultant;
+
+
+use app\model\Consultant;
+use app\model\MarketCustomer;
+use app\model\Member;
+use support\Db;
+use support\exception\BusinessException;
+
+class CustomService
+{
+    /**
+     * Notes: 处理参数
+     * User: yb
+     * Date: 2024/8/6
+     * Time: 11:43
+     * @param $data
+     * @return mixed
+     */
+    protected static function handleNumParams($data)
+    {
+        $setField = ['require_area', 'requirement', 'age_range', 'focus', 'region'];
+        foreach ($data as $k => $v) {
+            if (in_array($k, $setField)) {
+                if (is_numeric($v)) {
+                    $data[$k] = $v + 1;
+                } else {
+                    $data[$k] = null;
+                }
+            }
+        }
+        if ($data['type'] == 1) {
+            //来电
+            if (!empty($data['area'])) {
+                $area = $data['area'];
+                $requireArea = 1;
+                if ($area >= 40 && $area < 51) {
+                    $requireArea = 2;
+                } else if ($area >= 51 && $area < 61) {
+                    $requireArea = 3;
+                } else if ($area >= 61 && $area < 81) {
+                    $requireArea = 4;
+                } else if ($area >= 81 && $area < 101) {
+                    $requireArea = 5;
+                } else if ($area >= 101 && $area < 121) {
+                    $requireArea = 6;
+                } else if ($area >= 121 && $area < 151) {
+                    $requireArea = 7;
+                } else if ($area >= 151) {
+                    $requireArea = 8;
+                }
+                $data['require_area'] = $requireArea;
+                $data['age_range'] = null;
+            } else {
+                $data['area'] = null;
+            }
+        } else {
+            //来访
+            $data['area'] = null;
+        }
+        if (!empty($data['visit_time'])) {
+            $data['visit_time'] = strtotime($data['visit_time']);
+        }
+        if (empty($data['visit_type'])) {
+            $data['visit_type'] = null;
+        }
+        if (empty($data['level'])) {
+            $data['level'] = null;
+        }
+        if (empty($data['purpose'])) {
+            $data['purpose'] = null;
+        }
+        return $data;
+    }
+    /**
+     * Notes: 返回选项配置信息
+     * User: yb
+     * Date: 2024/8/5
+     * Time: 16:05
+     * @return array
+     */
+    public static function config()
+    {
+        $config = [
+            'requirement' => ['康养公寓', '颐养公寓', '商业', '其他'],
+            'require_area' => ['40㎡以下', '40㎡-50㎡', '51㎡-60㎡', '61㎡-80㎡', '81㎡-100㎡', '101㎡-120㎡', '121㎡-150㎡', '150㎡以上'],
+            'age_range' => ['40岁以下', '21岁-30岁', '31岁-40岁', '41岁-50岁', '51岁-60岁', '61岁-80岁', '80岁以上'],
+            'visit_type' => [
+                'common' => ['', '路过', '分销', '朋友介绍', '安居客、房天下', '微信朋友圈', '户外', '微信公众号', '工地围挡', '老带新', '圈层营销', '自拓'],
+                'type1' => ['100' => '派单', '101' => '城市展厅', '102' => '活动'],
+                'type2' => ['200' => '内渠', '201' => '自渠']
+            ],
+            'focus' => ['位置', '交通', '配套', '价格', '品牌', '适老化', '物业', '医疗', '运营'],
+            'region' => ['唐冶', '历城', '历下', '高新', '天桥', '槐荫', '市中', '其他'],
+            'purpose' => ['自买自用', '自买他用'],
+            'level' => ['A类', 'B类', 'C类', 'D类'],
+            'current_status' => ['首次到访', '已到访', '无效客户', '已成交'],
+        ];
+        //处理config中的visit_type
+        $visitType = [];
+        $visitTypeCommon = $config['visit_type']['common'];
+        $visitType1 = $config['visit_type']['type1'];
+        $visitType2 = $config['visit_type']['type2'];
+        foreach ($visitTypeCommon as $key => $item) {
+            if (!empty($item)) {
+                $visitType['type1']["{$key}"] = $item;
+                $visitType['type2']["{$key}"] = $item;
+            }
+        }
+        $visitType['type1'] += $visitType1;
+        $visitType['type2'] += $visitType2;
+        $config['visit_type'] = $visitType;
+        return $config;
+    }
+
+    /**
+     * Notes: 添加客户
+     * User: yb
+     * Date: 2024/8/6
+     * Time: 11:20
+     */
+    public static function add($params)
+    {
+        $params = self::handleNumParams($params);
+        $mobile = $params['mobile'];
+        //查询客户手机号是否已经存在
+        if (MarketCustomer::where('mobile', $mobile)->exists()) {
+            return json_fail('客户已经登记过了');
+        }
+        //查询顾问信息
+        $consultantId = $params['consultant_id'];
+        $consultantInfo = Consultant::firstWhere(['id' => $consultantId]);
+        if (empty($consultantInfo)) {
+            return json_fail('顾问信息不存在');
+        }
+        $deptId = $consultantInfo->dept_id;
+        $insertData = [
+            'name' => $params['name'],
+            'mobile' => $mobile,
+            'consultant_id' => $consultantId,
+            'dept_id' => $deptId,
+            'gender' => $params['gender'] ?? null,
+            'visit_type' => $params['visit_type'] ?? null,
+            'require_area' => $params['require_area'] ?? null,
+            'area' => $params['area'] ?? null,
+            'requirement' => $params['requirement'] ?? null,
+            'age_range' => $params['age_range'] ?? null,
+            'focus' => $params['focus'] ?? null,
+            'region' => $params['region'] ?? null,
+            'purpose' => $params['purpose'] ?? null,
+            'level' => $params['level'] ?? null,
+            'type' => $params['type'] ?? null,
+            'visit_time' => $params['visit_time'] ?? null,
+            'note' => $params['note'] ?? '',
+        ];
+
+        Db::beginTransaction();
+        try {
+            //查询会员表中是否存在该客户
+//            $memberId = Member::where('member_mobile', $insertData['mobile'])->value('member_id');
+//            if (empty($memberId)) {
+//                //新增会员信息
+//            }
+//            $insertData['member_id'] = $memberId;
+            $customId = MarketCustomer::insertGetId($insertData);
+            Db::commit();
+        }catch (BusinessException|\Exception $e){
+            Db::rollBack();
+            return json_fail($e->getMessage());
+        }
+        if ($customId) {
+            return json_success('添加成功');
+        } else {
+            return json_fail('添加失败');
+        }
+    }
+}

+ 244 - 0
app/admin/service/consultant/TeamService.php

@@ -0,0 +1,244 @@
+<?php
+
+namespace app\admin\service\consultant;
+
+use app\model\Consultant;
+use app\model\SysDept;
+use app\model\SysUser;
+use support\Db;
+use support\exception\BusinessException;
+use support\Request;
+
+class TeamService
+{
+    const DEPT_CATEGORY = '获客团队';
+
+    /**
+     * @Desc 营销团队详情
+     * @Author Gorden
+     * @Date 2024/2/21 10:35
+     *
+     * @param $id
+     * @return \support\Response
+     */
+    public static function deptInfo($id)
+    {
+        $dept = SysDept::find($id);
+        if (!$dept) {
+            return json_fail('营销团队不存在');
+        }
+
+        $dept = $dept->toArray();
+        return json_success('', $dept);
+    }
+
+    /**
+     * @Desc 创建营销团队
+     * @Author Gorden
+     * @Date 2024/2/21 9:22
+     *
+     * @param $params
+     * @return \support\Response
+     */
+    public static function insertDept($params)
+    {
+        Db::beginTransaction();
+        try {
+            $data = [
+                'dept_category' => self::DEPT_CATEGORY,
+                'dept_name' => $params['dept_name'],
+                'dept_super_id' => $params['dept_super_id'] ?? 0,
+                'dept_status' => $params['dept_status'] ?? 'ACTIVED',
+                'dept_sort' => $params['dept_sort'] ?? 1,
+                'dept_addtimes' => time()
+            ];
+            $where = [
+                ['dept_category', '=', $data['dept_category']],
+                ['dept_name', '=', $data['dept_name']],
+                ['dept_super_id', '=', $data['dept_super_id']],
+            ];
+            $isExist = SysDept::where($where)->first();
+            if ($isExist) {
+                throw new BusinessException('团队已存在');
+            }
+            $deptId = SysDept::insertGetId($data);
+            if (!$deptId) {
+                throw new BusinessException('创建团队失败');
+            }
+            // 获取上级部门path
+            $deptSuperPath = '/0/';
+            if ($params['dept_super_id'] != 0) {
+                $deptSuperPath = SysDept::where('dept_id', $params['dept_super_id'])->value('dept_super_path');
+            }
+            // 更新部门path
+            $path = $deptSuperPath . $deptId . '/';
+            if (!SysDept::where('dept_id', $deptId)->update(['dept_super_path' => $path])) {
+                throw new \Exception('创建团队失败');
+            }
+            Db::commit();
+        } catch (BusinessException|\Exception $e) {
+            Db::rollBack();
+            return json_fail($e->getMessage());
+        }
+
+        return json_success('团队创建成功');
+    }
+
+    /**
+     * @Desc 修改营销团队
+     * @Author Gorden
+     * @Date 2024/2/21 10:15
+     *
+     * @param $id
+     * @param $params
+     * @return \support\Response
+     */
+    public static function updateDept($params)
+    {
+        $id = $params['id'];
+        $dept = SysDept::where('dept_id', $id)->first();
+        if (!$dept) {
+            return json_fail('团队不存在');
+        }
+
+        try {
+            $data = [
+                'dept_name' => $params['dept_name'],
+                'dept_sort' => $params['dept_sort'] ?? 0,
+                'dept_status' => $params['dept_status'] ?? 'ACTIVED',
+            ];
+            $where = [
+                ['dept_category', '=', self::DEPT_CATEGORY],
+                ['dept_name', '=', $data['dept_name']],
+                ['dept_super_id', '=', $dept['dept_super_id']],
+                ['dept_id', '<>', $id],
+            ];
+            $isExist = SysDept::where($where)->first();
+            if ($isExist) {
+                throw new BusinessException('团队已存在');
+            }
+            // 修改失败,异常
+            SysDept::where('dept_id', $id)->update($data);
+
+        } catch (BusinessException|\Exception $e) {
+            return json_fail($e->getMessage());
+        }
+
+        return json_success('修改团队成功');
+    }
+
+    /**
+     * @Desc 修改营销团队状态
+     * @Author Gorden
+     * @Date 2024/2/21 10:41
+     *
+     * @param $id
+     * @param $status
+     * @return \support\Response
+     */
+    public static function updateStatus($id, $status)
+    {
+        try {
+            if (!SysDept::where('dept_id', $id)->update(['dept_status' => $status])) {
+                throw new \Exception('营销团队状态修改失败');
+            }
+        } catch (\Exception $e) {
+            return json_fail('营销团队状态修改失败');
+        }
+
+        return json_success('营销团队状态修改成功');
+    }
+
+    /**
+     * @Desc 删除营销团队
+     * @Author Gorden
+     * @Date 2024/2/21 10:48
+     *
+     * @param $id
+     * @return \support\Response
+     */
+    public static function delDept(Request $request)
+    {
+        $ids = $request->post('dept_id');
+        if (!$ids) {
+            return json_fail("数据错误");
+        }
+        if (!is_array($ids)) {
+            $ids = [$ids];
+        }
+        //查询团队下是否存在员工
+        $nums = Consultant::whereIn('dept_id', $ids)->count();
+        if ($nums > 0) {
+            return json_fail('请清除团队下员工后删除团队');
+        }
+        //查询团队下是否存在管理账号
+        $nums = SysUser::whereIn('join_user_dept_id', $ids)->count();
+        if ($nums > 0) {
+            return json_fail('请清除团队下管理账号后删除团队');
+        }
+        try {
+            if (is_array($ids)) {
+                SysDept::whereIn('dept_id', $ids)->delete();
+            } else {
+                SysDept::where('dept_id', $ids)->delete();
+            }
+        } catch (\Exception $e) {
+            return json_fail('删除团队失败');
+        }
+
+        return json_success('删除团队成功');
+    }
+
+    /**
+     * @Desc 检查营销团队是否存在
+     * @Author Gorden
+     * @Date 2024/2/21 13:37
+     *
+     * @param $deptId
+     * @return bool
+     */
+    public static function checkDeptExist($deptId)
+    {
+        return SysDept::where('dept_id', $deptId)->exists();
+    }
+
+    /**
+     * Notes: 上级团队列表
+     * User: yb
+     * Date: 2024/8/1
+     * Time: 17:17
+     */
+    public static function parentList()
+    {
+        $list = SysDept::where(['dept_category' => self::DEPT_CATEGORY, 'dept_super_id' => 0])->select(['dept_id','dept_name'])->get();
+        $result = $list->toArray();
+        $result[] = [
+            'dept_id' => 0,
+            'dept_name' => '顶级团队',
+        ];
+        return json_success('请求成功', $result);
+    }
+
+    /**
+     * Notes: 获取团队信息
+     * User: yb
+     * Date: 2024/8/2
+     * Time: 10:00
+     * @return array
+     */
+    public static function getKeys()
+    {
+        $where = [
+            ['dept_category', '=', self::DEPT_CATEGORY]
+        ];
+        $data = SysDept::where($where)->select(['dept_id', 'dept_super_id', 'dept_super_path', 'dept_name'])->get();
+        $keys = [];
+        if (!empty($data)) {
+            $array = $data->toArray();
+            foreach ($array as $item) {
+                $keys[$item['dept_id']] = $item['dept_name'];
+            }
+        }
+        return $keys;
+    }
+}

+ 25 - 0
app/admin/validate/consultant/IndexValidate.php

@@ -0,0 +1,25 @@
+<?php
+
+
+namespace app\admin\validate\consultant;
+
+
+use support\Validate;
+
+class IndexValidate extends Validate
+{
+    protected $rule = [
+        'id|ID' => 'require|integer',
+        'mobile|手机号' => 'require|mobile',
+        'name|姓名' => 'require',
+        'password|密码' => 'require',
+        'dept_id|团队' => 'require'
+    ];
+
+    protected $message = [];
+
+    protected $scene = [
+        'add' => ['mobile', 'name', 'password', 'dept_id'],
+        'update' => ['id', 'mobile', 'name', 'dept_id']
+    ];
+}

+ 26 - 0
app/admin/validate/consultant/MarketCustomerValidate.php

@@ -0,0 +1,26 @@
+<?php
+
+
+namespace app\admin\validate\consultant;
+
+
+use support\Validate;
+
+class MarketCustomerValidate extends Validate
+{
+    protected $rule = [
+        'id|ID' => 'require|integer',
+        'mobile|联系电话' => 'require|mobile',
+        'name|客户姓名' => 'require',
+        'consultant_id|所属顾问' => 'require',
+        'visit_time|访问时间' => 'require',
+        'current_status|当前状态' => 'require'
+    ];
+
+    protected $message = [];
+
+    protected $scene = [
+        'add' => ['mobile', 'name', 'consultant_id', 'visit_time', 'current_status'],
+        'update' => ['id', 'mobile', 'name', 'visit_time', 'current_status']
+    ];
+}

+ 23 - 0
app/model/Consultant.php

@@ -0,0 +1,23 @@
+<?php
+
+
+namespace app\model;
+
+
+use DateTimeInterface;
+use Illuminate\Database\Eloquent\SoftDeletes;
+use support\Model;
+
+class Consultant extends Model
+{
+    use SoftDeletes;
+    protected $table = 'consultant';
+
+    protected $dateFormat = 'U';
+
+
+    public function serializeDate(DateTimeInterface $date)
+    {
+        return $date->format('Y-m-d H:i:s');
+    }
+}

+ 23 - 0
app/model/MarketCustomer.php

@@ -0,0 +1,23 @@
+<?php
+
+
+namespace app\model;
+
+
+use DateTimeInterface;
+use Illuminate\Database\Eloquent\SoftDeletes;
+use support\Model;
+
+class MarketCustomer extends Model
+{
+    use SoftDeletes;
+    protected $table = 'market_customer';
+
+    protected $dateFormat = 'U';
+
+
+    public function serializeDate(DateTimeInterface $date)
+    {
+        return $date->format('Y-m-d H:i:s');
+    }
+}

+ 24 - 0
route/admin.php

@@ -605,6 +605,30 @@ Route::group('/admin', function () {
             \app\middleware\AdminAuthCheck::class
             \app\middleware\AdminAuthCheck::class
         ]);
         ]);
     });
     });
+    /* 营销团队管理 */
+    Route::group('/market', function () {
+        /* 团队管理 */
+        Route::group('/team', function (){
+            Route::get('/list', [\app\admin\controller\consultant\TeamController::class, 'select']);
+            Route::post('/add', [\app\admin\controller\consultant\TeamController::class, 'addDept']);
+            Route::post('/update', [\app\admin\controller\consultant\TeamController::class, 'updateDept']);
+            Route::delete('/delete', [\app\admin\controller\consultant\TeamController::class, 'delDept']);
+            Route::get('/parent', [\app\admin\controller\consultant\TeamController::class, 'parentList']);
+        });
+        /* 员工管理 */
+        Route::group('/consultant', function (){
+            Route::get('/list', [\app\admin\controller\consultant\IndexController::class, 'select']);
+            Route::post('/add', [\app\admin\controller\consultant\IndexController::class, 'addConsultant']);
+            Route::post('/update', [\app\admin\controller\consultant\IndexController::class, 'updateConsultant']);
+            Route::delete('/delete', [\app\admin\controller\consultant\IndexController::class, 'deleteConsultant']);
+            Route::get('/user', [\app\admin\controller\consultant\IndexController::class, 'getUserList']);
+        });
+        /* 客户管理 */
+        Route::group('/custom', function (){
+            Route::get('/config', [\app\admin\controller\consultant\CustomController::class, 'getOptionConfig']);
+            Route::post('/add', [\app\admin\controller\consultant\CustomController::class, 'addCustom']);
+        });
+    });
     Route::group('/customer', function () {
     Route::group('/customer', function () {
         Route::get('/selectList', [\app\admin\controller\customer\IndexController::class, 'selectList']);
         Route::get('/selectList', [\app\admin\controller\customer\IndexController::class, 'selectList']);
         Route::get('/list', [\app\admin\controller\customer\IndexController::class, 'select']);
         Route::get('/list', [\app\admin\controller\customer\IndexController::class, 'select']);