diff --git a/admin/controllers/receiver/OwnersTag.php b/admin/controllers/receiver/OwnersTag.php new file mode 100644 index 00000000..b7839119 --- /dev/null +++ b/admin/controllers/receiver/OwnersTag.php @@ -0,0 +1,202 @@ + ['title' => '客户标签', 'url' => '/receiver/tag'], 2 => ['title' => '车主标签', 'url' => '/receiver/ownersTag']]; + + public function __construct() + { + parent::__construct(); + $this->load->model('receiver/receiver_owners_tag_model', 'mdOwnersTag'); + } + + //首页信息 + 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'] = 2; + $statusAry = $this->mdOwnersTag->statusAry(); + $typeAry = $this->mdOwnersTag->typeAry(); + $lists = array(); + $where = ["status<>-1" => null, 'pid' => 0]; + if (strlen($params['status'])) { + $where['status'] = $params['status']; + } + if ($params['type']) { + $where['type'] = $params['type']; + } + $count = $this->mdOwnersTag->count($where); + if ($count) { + $res = $this->mdOwnersTag->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']]; + $options = ''; + $res_tag = $this->mdOwnersTag->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, '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/ownerstag/lists', true); + } + + public function get_options() + { + $id = intval($this->input->post('id')); + if (!$id) { + return $this->show_json(SYS_CODE_FAIL, '参数错误!'); + } + $res_tag = $this->mdOwnersTag->select(["status" => 1, 'pid' => $id], "sort desc,id desc", 0, 0, 'id,name,sort,status'); + $this->data['lists'] = $res_tag; + return $this->show_json(SYS_CODE_SUCCESS); + } + + //展示单条数据 + public function get() + { + $id = intval($this->input->get('id')); + if ($id) { + $url = "receiver/ownersTag/edit"; + $re = $this->mdOwnersTag->get(['id' => $id]); + if (!$re) { + return $this->show_json(SYS_CODE_FAIL, '车主标签不存在!'); + } + $name = $re['name']; + $sort = $re['sort']; + $type = $re['type']; + } else { + $url = "receiver/ownersTag/add"; + $name = ''; + $sort = 0; + $type = 'checkbox'; + } + $this->data['showInfo'] = ['id' => $id, 'name' => $name, 'sort' => $sort, 'type' => $type, + 'typeAry' => $this->mdOwnersTag->typeAry(), 'url' => $url]; + return $this->show_view('receiver/ownerstag/edit'); + } + + //添加单条数据 + public function add() + { + $params = $this->input->post(); + if (!$params['name']) { + return $this->show_json(SYS_CODE_FAIL, '标签名称不能为空!'); + } + $re = $this->mdOwnersTag->get(array('name' => $params['name'])); + if ($re) { + return $this->show_json(SYS_CODE_FAIL, '标签名称已存在了!'); + } + $id = $this->mdOwnersTag->add(['name' => $params['name'], 'sort' => $params['sort'], 'type' => $params['type']]); + 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->mdOwnersTag->get(array('name' => $params['name'], 'status' => 1)); + if ($re && $re['id'] != $params['id']) { + return $this->show_json(SYS_CODE_FAIL, '标签名称已存在了!'); + } + $this->mdOwnersTag->update(['name' => $params['name'], 'sort' => $params['sort'], 'type' => $params['type']], + ['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->mdOwnersTag->get(['id' => $id]); + if (!$re) { + return $this->show_json(SYS_CODE_FAIL, '标签不存在!'); + } + $this->mdOwnersTag->update(['status' => '-1'], ['id' => $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->mdOwnersTag->get(['id' => $pid]); + if (!$re) { + return $this->show_json(SYS_CODE_FAIL, '车主标签不存在!'); + } + $add_tag = $edit_tag = []; + foreach ($options as $key => $value) { + $sort = intval($value['sort']); + $data = ['name' => $value['name'], 'status' => $value['status'], 'sort' => $sort]; + if ($value['name']) { + if ($value['id']) {//修改 + $this->mdOwnersTag->update($data, ['id' => $value['id']]); + } else {//新增 + $add_tag[] = ['name' => $value['name'], 'order' => $sort]; + $data['pid'] = $pid; + $this->mdOwnersTag->add($data); + } + } + } + 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->mdOwnersTag->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/controllers/receiver/Tag.php b/admin/controllers/receiver/Tag.php index 6d39007b..bc7d60ab 100644 --- a/admin/controllers/receiver/Tag.php +++ b/admin/controllers/receiver/Tag.php @@ -4,6 +4,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); class Tag extends HD_Controller { + private $tabAry = [1 => ['title' => '客户标签', 'url' => '/receiver/tag'], 2 => ['title' => '车主标签', 'url' => '/receiver/ownersTag']]; public function __construct() { @@ -23,6 +24,7 @@ class Tag extends HD_Controller $params = $this->input->get(); $params['page'] = $params['page'] ? intval($params['page']) : 1; $params['size'] = $params['size'] ? intval($params['size']) : 20; + $params['tab'] = 1; $statusAry = $this->mdCustomerTag->statusAry(); $typeAry = $this->mdCustomerTag->typeAry(); $showAry = $this->mdCustomerTag->showAry(); @@ -58,7 +60,7 @@ class Tag extends HD_Controller } $this->data['lists'] = $lists; $this->data['params'] = $params; - $this->data['showInfo'] = ['statusAry' => $statusAry, 'typeAry' => $typeAry, 'showAry' => $showAry]; + $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); diff --git a/admin/views/receiver/ownerstag/edit.php b/admin/views/receiver/ownerstag/edit.php new file mode 100644 index 00000000..c73770c5 --- /dev/null +++ b/admin/views/receiver/ownerstag/edit.php @@ -0,0 +1,31 @@ +
\ No newline at end of file diff --git a/admin/views/receiver/ownerstag/lists.php b/admin/views/receiver/ownerstag/lists.php new file mode 100644 index 00000000..91133ad8 --- /dev/null +++ b/admin/views/receiver/ownerstag/lists.php @@ -0,0 +1,249 @@ +| 名称 | +标签选项 | +类型 | +排序 | +状态 | +
|---|---|---|---|---|
| = $v['name'] ?> | += $v['options'] ?> | += $v['type_name'] ?> | += $v['sort'] ?> | += $v['status_name'] ?> | +
| + ,'= $v['name'] ?>')" + class="am-btn am-btn-primary am-btn-xs">编辑选项 + 编辑标签 + if ($v['status'] == 1) { ?> + 关闭 + + } ?> + if ($v['status'] == 0) { ?> + 开启 + } ?> + 删除 + | +||||