From 1a8ecd1a560800de3de8d3caedbb7abf7d63ccff Mon Sep 17 00:00:00 2001 From: lcc <1127794702@qq.com> Date: Mon, 3 Jun 2024 17:42:18 +0800 Subject: [PATCH] 20240603 --- admin/controllers/receiver/Tag.php | 275 ++++++++++++++++++++ admin/views/receiver/tag/edit.php | 43 +++ admin/views/receiver/tag/lists.php | 267 +++++++++++++++++++ api/controllers/wxapp/app/City.php | 19 +- api/controllers/wxapp/licheb/Cusorder.php | 3 + api/controllers/wxapp/licheb/Customers.php | 7 +- api/controllers/wxapp/licheb/User.php | 2 + common/helpers/comm_helper.php | 2 +- common/libraries/CarHome.php | 24 +- common/libraries/receiver/Orders_entity.php | 73 ++++++ 10 files changed, 697 insertions(+), 18 deletions(-) create mode 100644 admin/controllers/receiver/Tag.php create mode 100644 admin/views/receiver/tag/edit.php create mode 100644 admin/views/receiver/tag/lists.php create mode 100644 common/libraries/receiver/Orders_entity.php diff --git a/admin/controllers/receiver/Tag.php b/admin/controllers/receiver/Tag.php new file mode 100644 index 00000000..dd0ce3e1 --- /dev/null +++ b/admin/controllers/receiver/Tag.php @@ -0,0 +1,275 @@ + ['title' => '客户标签', 'url' => '/receiver/tag'], + 2 => ['title' => '车主标签', 'url' => '/receiver/ownersTag'], + 3 => ['title' => '战败标签', 'url' => '/receiver/tag?tag_type=1'], + 4 => ['title' => '意向标签', 'url' => '/receiver/tag?tag_type=2'] + ]; + + public function __construct() + { + parent::__construct(); + $this->load->model('receiver/receiver_customer_tag_model', 'mdCustomerTag'); + } + + //首页信息 + public function index() + { + return $this->lists(); + } + + //数据列表 + public function lists() + { + $params = $this->input->get(); + $params['page'] = $params['page'] ? intval($params['page']) : 1; + $params['size'] = $params['size'] ? intval($params['size']) : 20; + #$params['tab'] = $params['tag_type'] ? 3 : 1; + $params['tab'] = $params['tag_type'] ? $params['tag_type'] + 2 : 1; + $statusAry = $this->mdCustomerTag->statusAry(); + $typeAry = $this->mdCustomerTag->typeAry(); + $showAry = $this->mdCustomerTag->showAry(); + $lists = array(); + $where = ["status<>-1" => null, 'pid' => 0]; + $where['tag_type'] = $params['tag_type'] ? $params['tag_type'] : 0; + if (strlen($params['status'])) { + $where['status'] = $params['status']; + } + if (strlen($params['show'])) { + $where['show'] = $params['show']; + } + if ($params['type']) { + $where['type'] = $params['type']; + } + $count = $this->mdCustomerTag->count($where); + if ($count) { + $res = $this->mdCustomerTag->select($where, "sort desc,id desc", $params['page'], $params['size']); + foreach ($res as $key => $value) { + $setValue = array(); + $setValue['id'] = $value['id']; + $setValue['name'] = $value['name']; + $setValue['sort'] = $value['sort']; + $setValue['type_name'] = $typeAry[$value['type']]; + $setValue['status'] = $value['status']; + $setValue['status_name'] = $statusAry[$value['status']]; + $setValue['show_name'] = $showAry[$value['show']]; + $options = ''; + $res_tag = $this->mdCustomerTag->select(["status" => 1, 'pid' => $value['id']], "sort desc,id desc", 0, 0, 'id,name,sort'); + $res_tag && $options = implode(',', array_column($res_tag, 'name')); + $setValue['options'] = $options; + $lists[] = $setValue; + } + } + $this->data['lists'] = $lists; + $this->data['params'] = $params; + $this->data['showInfo'] = ['statusAry' => $statusAry, 'typeAry' => $typeAry, 'showAry' => $showAry, 'tabAry' => $this->tabAry]; + $this->data['_title'] = '客户标签列表'; + $this->data['pager'] = array('count' => ceil($count / $params['size']), 'curr' => $params['page'], 'totle' => $count); + return $this->show_view('/receiver/tag/lists', true); + } + + public function get_options() + { + $id = intval($this->input->post('id')); + if (!$id) { + return $this->show_json(SYS_CODE_FAIL, '参数错误!'); + } + $res_tag = $this->mdCustomerTag->select(["status" => 1, 'pid' => $id], "sort desc,id desc", 0, 0, 'id,name,sort,status,qy_id'); + $this->data['lists'] = $res_tag; + return $this->show_json(SYS_CODE_SUCCESS); + } + + //展示单条数据 + public function get() + { + $id = intval($this->input->get('id')); + $tag_type = $this->input->get('tag_type'); + !$tag_type && $tag_type = 0; + if ($id) { + $url = "/receiver/tag/edit"; + $re = $this->mdCustomerTag->get(['id' => $id]); + if (!$re) { + return $this->show_json(SYS_CODE_FAIL, '客户标签不存在!'); + } + $name = $re['name']; + $sort = $re['sort']; + $type = $re['type']; + $show = $re['show']; + } else { + $url = "/receiver/tag/add"; + $name = ''; + $sort = $show = 0; + $type = 'checkbox'; + } + $this->data['showInfo'] = ['id' => $id, 'name' => $name, 'sort' => $sort, 'type' => $type, 'show' => $show, + 'typeAry' => $this->mdCustomerTag->typeAry(), 'showAry' => $this->mdCustomerTag->showAry(), 'url' => $url,'tag_type'=>$tag_type]; + return $this->show_view('/receiver/tag/edit'); + } + + //添加单条数据 + public function add() + { + $params = $this->input->post(); + if (!$params['name']) { + return $this->show_json(SYS_CODE_FAIL, '标签名称不能为空!'); + } + $re = $this->mdCustomerTag->get(array('name' => $params['name'])); + if ($re) { + return $this->show_json(SYS_CODE_FAIL, '标签名称已存在了!'); + } + $add_data = [ + 'name' => $params['name'], + 'sort' => $params['sort'], + 'type' => $params['type'], + 'show' => $params['show'] + ]; + $params['tag_type'] && $add_data['tag_type'] = $params['tag_type']; + $id = $this->mdCustomerTag->add($add_data); + if (!$id) { + return $this->show_json(SYS_CODE_FAIL, '保存失败'); + } + return $this->show_json(SYS_CODE_SUCCESS, '保存成功'); + } + + //编辑单条数据 + public function edit() + { + $params = $this->input->post(); + if (!$params['id']) { + return $this->show_json(SYS_CODE_FAIL, '参数错误'); + } + if (!$params['name']) { + return $this->show_json(SYS_CODE_FAIL, '请输入标签名称'); + } + $re = $this->mdCustomerTag->get(array('name' => $params['name'], 'status' => 1)); + if ($re && $re['id'] != $params['id']) { + return $this->show_json(SYS_CODE_FAIL, '标签名称已存在了!'); + } + $re = $this->mdCustomerTag->get(['id' => $params['id']]); + if (false !== strpos($_SERVER['HTTP_HOST'], 'admin.liche.cn') && $re['qy_id']) {//正试才能修改企业标签 + $this->load->library('wx_qyapi', ['app' => 'lichene']); + $this->wx_qyapi->get_external_contact(['url' => 'edit_corp_tag', 'id' => $re['qy_id'] + , 'name' => $params['name'], 'order' => $params['sort']]); + } + $this->mdCustomerTag->update(['name' => $params['name'], 'sort' => $params['sort'], 'type' => $params['type'] + , 'show' => $params['show']], ['id' => $params['id']]); + return $this->show_json(SYS_CODE_SUCCESS, '保存成功'); + } + + //删除单条数据 + public function del() + { + $id = $this->input->post('id'); + if (!$id) { + $this->show_json(SYS_CODE_FAIL, '参数错误'); + } + $re = $this->mdCustomerTag->get(['id' => $id]); + if (!$re) { + return $this->show_json(SYS_CODE_FAIL, '标签不存在!'); + } + if ($re['tag_type'] == 2) { + return $this->show_json(SYS_CODE_FAIL, '该标签不能删除!'); + } + $this->mdCustomerTag->update(['status' => '-1'], ['id' => $id]); + if (false !== strpos($_SERVER['HTTP_HOST'], 'admin.liche.cn') && $re['qy_id']) {//正试才能修改企业标签 + $this->load->library('wx_qyapi', ['app' => 'lichene']); + $this->wx_qyapi->get_external_contact(['url' => 'del_corp_tag', 'group_id' => $re['qy_id']]); + } + return $this->show_json(SYS_CODE_SUCCESS, '操作成功'); + } + + //修改标签选项 + function edit_options() + { + $pid = $this->input->post('id'); + $options = $this->input->post('options'); + if (!$pid || !$options) { + return $this->show_json(SYS_CODE_FAIL, '参数错误!'); + } + $re = $this->mdCustomerTag->get(['id' => $pid]); + if (!$re) { + return $this->show_json(SYS_CODE_FAIL, '客户标签不存在!'); + } + $add_tag = $del_tag = $edit_tag = []; + foreach ($options as $key => $value) { + $sort = intval($value['sort']); + $data = ['name' => $value['name'], 'status' => $value['status'], 'sort' => $sort, 'tag_type' => $re['tag_type']]; + if ($value['status'] == -1 && $value['qy_id']) {//删除标签 + $del_tag[] = $value['qy_id']; + } + if ($value['name']) { + if ($value['id']) {//修改 + if ($value['status'] == 1 && $value['qy_id']) { + $edit_tag[] = ['id' => $value['qy_id'], 'name' => $value['name'], 'order' => $sort]; + } + $this->mdCustomerTag->update($data, ['id' => $value['id']]); + } else {//新增 + $add_tag[] = ['name' => $value['name'], 'order' => $sort]; + $data['pid'] = $pid; + $this->mdCustomerTag->add($data); + } + } + } + if (false !== strpos($_SERVER['HTTP_HOST'], 'admin.liche.cn') && !$re['tag_type']) {//正试才能修改企业标签 + $this->load->library('wx_qyapi', ['app' => 'lichene']); + if (count($add_tag)) {//新增标签 + if (!$re['qy_id']) { + $add_corp_tag = ['url' => 'add_corp_tag', 'group_id' => '', 'group_name' => $re['name'] + , 'order' => $re['sort'], 'tag' => $add_tag]; + } else { + $add_corp_tag = ['url' => 'add_corp_tag', 'group_id' => $re['qy_id'], 'tag' => $add_tag]; + } + $re_yq = $this->wx_qyapi->get_external_contact($add_corp_tag); + if ($re_yq['errcode'] == 0) { + if (!$re['qy_id'] && $re_yq['tag_group']['group_id']) {//更新企微标签组id + $this->mdCustomerTag->update(['qy_id' => $re_yq['tag_group']['group_id']], ['id' => $pid]); + } + foreach ($re_yq['tag_group']['tag'] as $key => $value) { + if ($value['id']) {//更新企微标签id + $this->mdCustomerTag->update(['qy_id' => $value['id']], ['pid' => $pid, 'name' => $value['name']]); + } + } + } + } else if (count($edit_tag)) {//编辑标签 + foreach ($edit_tag as $key => $value) { + $this->wx_qyapi->get_external_contact(['url' => 'edit_corp_tag', 'id' => $value['id'] + , 'name' => $value['name'], 'order' => $value['order']]); + } + } else if (count($del_tag)) {//删除标签 + foreach ($del_tag as $key => $value) { + $this->wx_qyapi->get_external_contact(['url' => 'del_corp_tag', 'tag_id' => $value]); + } + } + //$this->data = ['options' => $options, 'add_tag' => $add_tag, 'edit_tag' => $edit_tag, 'del_tag' => $del_tag]; + } + return $this->show_json(SYS_CODE_SUCCESS, '保存成功'); + } + + function edit_status() + { + $id = $this->input->post('id'); + $stauts = intval($this->input->post('status')); + if (!$id) { + $this->show_json(SYS_CODE_FAIL, '参数错误'); + } + $this->mdCustomerTag->update(['status' => $stauts], ['id' => $id]); + return $this->show_json(SYS_CODE_SUCCESS, '操作成功'); + } + + //批量操作(默认修改状态) + public function batch() + { + + } + + //导出数据列表 + public function export() + { + + } +} \ No newline at end of file diff --git a/admin/views/receiver/tag/edit.php b/admin/views/receiver/tag/edit.php new file mode 100644 index 00000000..bea5d10e --- /dev/null +++ b/admin/views/receiver/tag/edit.php @@ -0,0 +1,43 @@ +
\ No newline at end of file diff --git a/admin/views/receiver/tag/lists.php b/admin/views/receiver/tag/lists.php new file mode 100644 index 00000000..fa8336aa --- /dev/null +++ b/admin/views/receiver/tag/lists.php @@ -0,0 +1,267 @@ +| 名称 | +标签选项 | +类型 | +显示 | +排序 | +状态 | +
|---|---|---|---|---|---|
| = $v['name'] ?> | += $v['options'] ?> | += $v['type_name'] ?> | += $v['show_name'] ?> | += $v['sort'] ?> | += $v['status_name'] ?> | +
| + ,'= $v['name'] ?>')" + class="am-btn am-btn-primary am-btn-xs">编辑选项 + 编辑标签 + if ($v['status'] == 1 && $params['tag_type'] < 2) { ?> + 关闭 + + } ?> + if ($v['status'] == 0 && $params['tag_type'] < 2) { ?> + 开启 + } ?> + if ($params['tag_type'] < 2) { ?> + 删除 + } ?> + | +|||||