123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599 |
- <?php
- /**
- * 手机专题
- *
- *
- *
- *
- */
- defined('InShopNC') or exit('Access Invalid!');
- require_once (BASE_ROOT_PATH . '/helper/util_helper.php');
- require_once (BASE_ROOT_PATH . '/helper/special/block_filter.php');
- require_once (BASE_ROOT_PATH . '/helper/special/upgrade_helper.php');
- class mb_specialControl extends SystemControl
- {
- const mb_home_tab_id = 123;
- const def_item_bg_color = '#F2F2F2';
- const def_item_bg_type = 'color';
- public function __construct()
- {
- parent::__construct();
- }
- //升级专题数据
- public function upgradeOp()
- {
- $mod_mb_special = Model('mb_special');
- //$items = Model()->table('mb_special_item')->where(array('item_type' => 'home7','special_id' => array('gt',10)))->order('special_id desc')->field('*')->limit(2)->select();
- $items = Model()->table('mb_special_item')->field('*')->limit(false)->select();
- foreach ($items as $item)
- {
- $filter = new upgrade_helper($item['item_type'],$item['special_id'],unserialize($item['item_data']));
- $item_data = $filter->filter();
- if($item_data == false) continue;
- $result = $mod_mb_special->editMbSpecialItemByID(array('item_data' => $item_data), $item['item_id'], $item['special_id']);
- if($result == false) {
- echo "upgrade error special_id={$item['special_id']} item_id={$item['item_id']}</br>";
- } else {
- echo "upgrade success special_id={$item['special_id']} item_id={$item['item_id']}</br>";
- }
- }
- }
- /**
- * 专题列表
- */
- public function special_listOp()
- {
- $model_mb_special = Model('mb_special');
- $mb_special_list = $model_mb_special->getMbSpecialList($array, 10);
- Tpl::output('list', $mb_special_list);
- Tpl::output('page', $model_mb_special->showpage(2));
- $this->show_menu('special_list');
- Tpl::showpage('mb_special.list');
- }
- public function tab_listOp()
- {
- $mod_webcode = Model('web_code');
- $tabs = $mod_webcode->get_nocache(self::mb_home_tab_id);
- $this->show_menu('tab_list');
- Tpl::output('tabs', $tabs);
- Tpl::showpage('mb_special.tab');
- }
- /**
- * 保存专题
- */
- public function special_saveOp()
- {
- $model_mb_special = Model('mb_special');
- $param = array();
- $param['special_desc'] = $_POST['special_desc'];
- $result = $model_mb_special->addMbSpecial($param);
- if($result) {
- $this->log('添加手机专题' . '[ID:' . $result. ']', 1);
- showMessage(L('nc_common_save_succ'), urlAdmin('mb_special', 'special_list'));
- } else {
- $this->log('添加手机专题' . '[ID:' . $result. ']', 0);
- showMessage(L('nc_common_save_fail'), urlAdmin('mb_special', 'special_list'));
- }
- }
- /**
- * 编辑专题描述
- */
- public function update_special_descOp() {
- $model_mb_special = Model('mb_special');
- $param = array();
- $param['special_desc'] = $_GET['value'];
- $result = $model_mb_special->editMbSpecial($param, $_GET['id']);
- $data = array();
- if($result) {
- $this->log('保存手机专题' . '[ID:' . $result. ']', 1);
- $data['result'] = true;
- } else {
- $this->log('保存手机专题' . '[ID:' . $result. ']', 0);
- $data['result'] = false;
- $data['message'] = '保存失败';
- }
- echo json_encode($data);die;
- }
- /**
- * 删除专题
- */
- public function special_delOp()
- {
- $model_mb_special = Model('mb_special');
- $result = $model_mb_special->delMbSpecialByID($_POST['special_id']);
- if($result) {
- $this->log('删除手机专题' . '[ID:' . $_POST['special_id'] . ']', 1);
- showMessage(L('nc_common_del_succ'), urlAdmin('mb_special', 'special_list'));
- } else {
- $this->log('删除手机专题' . '[ID:' . $_POST['special_id'] . ']', 0);
- showMessage(L('nc_common_del_fail'), urlAdmin('mb_special', 'special_list'));
- }
- }
- /**
- * 编辑首页
- */
- public function index_editOp()
- {
- $model_mb_special = Model('mb_special');
- $special_item_list = $model_mb_special->getMbSpecialItemListByID($model_mb_special::INDEX_SPECIAL_ID);
- Tpl::output('list', $special_item_list);
- Tpl::output('page', $model_mb_special->showpage(2));
- Tpl::output('module_list', $model_mb_special->getMbSpecialModuleList());
- Tpl::output('special_id', $model_mb_special::INDEX_SPECIAL_ID);
- $this->show_menu('index_edit');
- Tpl::showpage('mb_special_item.list');
- }
- /**
- * 编辑专题
- */
- public function special_editOp() {
-
- $model_mb_special = Model('mb_special');
- $special_item_list = $model_mb_special->getMbSpecialItemListByID($_GET['special_id']);
- Tpl::output('list', $special_item_list);
- Tpl::output('page', $model_mb_special->showpage(2));
- Tpl::output('module_list', $model_mb_special->getMbSpecialModuleList());
- Tpl::output('special_id', $_GET['special_id']);
- $this->show_menu('special_item_list');
- Tpl::showpage('mb_special_item.list');
- }
- /**
- * 专题项目添加
- */
- public function special_item_addOp()
- {
- $item_info = $this->add_item($_POST['special_id'],$_POST['item_type']);
- if($item_info) {
- echo json_encode($item_info);die;
- } else {
- echo json_encode(array('error' => '添加失败'));die;
- }
- }
- private function add_item($special_id,$item_type)
- {
- $model_mb_special = Model('mb_special');
- $param = array();
- $param['special_id'] = $special_id;
- $param['item_type'] = $item_type;
- $param['bg_image'] = '';
- $param['bg_type'] = self::def_item_bg_type;
- $param['bg_data'] = self::def_item_bg_color;
- $param['has_margin'] = 0;
- $item_info = $model_mb_special->addMbSpecialItem($param);
- return $item_info;
- }
- //专题项目插入分割线
- public function add_frontOp()
- {
- $item_type = $_POST['item_type'];
- $special_id = intval($_POST['special_id']);
- $item_info = $this->add_item($special_id,$item_type);
- if($item_info == false) {
- echo json_encode(array('error' => '添加失败'));die;
- }
- $sel_item_id = intval($_POST['sel_item_id']);
- $insert_item_id = intval($item_info['item_id']);
- $model_mb_special = Model('mb_special');
- $special_item_list = $model_mb_special->getMbSpecialItemListByID($special_id);
- $item_ids = [];
- foreach ($special_item_list as $item)
- {
- $item_id = intval($item['item_id']);
- if($item_id == $sel_item_id) {
- $item_ids[] = $insert_item_id;
- $item_ids[] = $item_id;
- }
- elseif($item_id == $insert_item_id) {
- continue;
- }
- else {
- $item_ids[] = $item_id;
- }
- }
- $index = 0;
- foreach ($item_ids as $item_id) {
- $result = $model_mb_special->editMbSpecialItemByID(array('item_sort' => $index), $item_id, $special_id);
- $index++;
- }
- $data = array();
- $data['message'] = '操作成功';
- echo json_encode($data);
- }
- public function move_itemOp()
- {
- $special_id = intval($_POST['special_id']);
- $src_id = intval($_POST['src_id']);
- $desc_id = intval($_POST['dest_id']);
- $href = urlAdmin('mb_special', 'special_edit', array('special_id' => $_POST['special_id']));
- if($src_id == $desc_id || $src_id <= 0 || $desc_id <= 0) {
- showMessage(L('nc_common_save_fail'), $href);
- }
- else
- {
- $model_mb_special = Model('mb_special');
- $special_item_list = $model_mb_special->getMbSpecialItemListByID($special_id);
- $nfind = 0;
- $item_ids = [];
- foreach ($special_item_list as $item)
- {
- $item_id = intval($item['item_id']);
- if($item_id == $desc_id) {
- $item_ids[] = $src_id;
- $item_ids[] = $desc_id;
- $nfind += 1;
- }
- elseif($item_id == $src_id) {
- $nfind += 1;
- continue;
- }
- else {
- $item_ids[] = $item_id;
- }
- }
- if($nfind == 2)
- {
- $index = 0;
- foreach ($item_ids as $item_id) {
- $result = $model_mb_special->editMbSpecialItemByID(array('item_sort' => $index), $item_id, $special_id);
- $index++;
- }
- showMessage(L('nc_common_save_succ'),$href);
- }
- else {
- showMessage(L('nc_common_save_fail'), $href);
- }
- }
- }
- /**
- * 专题项目删除
- */
- public function special_item_delOp() {
- $model_mb_special = Model('mb_special');
- $condition = array();
- $condition['item_id'] = $_POST['item_id'];
- $result = $model_mb_special->delMbSpecialItem($condition, $_POST['special_id']);
- if($result) {
- echo json_encode(array('message' => '删除成功'));die;
- } else {
- echo json_encode(array('error' => '删除失败'));die;
- }
- }
- /**
- * 专题项目编辑
- */
- public function special_item_editOp()
- {
- $model_mb_special = Model('mb_special');
- $item_info = $model_mb_special->getMbSpecialItemInfoByID($_GET['item_id']);
- if($item_info['has_margin'] == 1) {
- $item_info['has_margin'] = 'true';
- } else {
- $item_info['has_margin'] = 'false';
- }
- Tpl::output('item_info', $item_info);
- if($item_info['special_id'] == 0) {
- $this->show_menu('index_edit');
- } else {
- $this->show_menu('special_item_list');
- }
- Tpl::showpage('mb_special_item.edit');
- }
- /**
- * 专题项目保存
- */
- public function special_item_saveOp()
- {
- $model_mb_special = Model('mb_special');
- $bg_type = $_POST['bg_type'];
- if($bg_type == 'image') {
- $bg_data = $_POST['bg_image_name'];
- } else {
- $bg_data = $_POST['bg_data'];
- if(empty($bg_data)) $bg_data = self::def_item_bg_color;
- }
- if($_POST['has_margin'] == "true") {
- $has_margin = 1;
- } else {
- $has_margin = 0;
- }
- $filter = new block_filter($_POST['item_type'],$_POST['special_id'],$_POST['item_data']);
- $item_data = $filter->filter();
- if($item_data == false) $item_data = $_POST['item_data'];
- $updata = array('item_data' => $item_data,'bg_type' => $bg_type,'bg_data' => $bg_data,'bg_image' => $_POST['bg_image_name'],'has_margin' => $has_margin);
- $result = $model_mb_special->editMbSpecialItemByID($updata, $_POST['item_id'], $_POST['special_id']);
- if($result) {
- if($_POST['special_id'] == $model_mb_special::INDEX_SPECIAL_ID) {
- showMessage(L('nc_common_save_succ'), urlAdmin('mb_special', 'index_edit'));
- } else {
- showMessage(L('nc_common_save_succ'), urlAdmin('mb_special', 'special_edit', array('special_id' => $_POST['special_id'])));
- }
- } else {
- showMessage(L('nc_common_save_succ'), '');
- }
- }
- /**
- * 图片上传
- */
- public function special_image_uploadOp() {
- $data = array();
- if(!empty($_FILES['special_image']['name'])) {
- $prefix = 's' . $_POST['special_id'];
- $upload = new UploadFile();
- $upload->set('default_dir', ATTACH_MOBILE . DS . 'special' . DS . $prefix);
- $upload->set('fprefix', $prefix);
- $upload->set('allow_type', array('gif', 'jpg', 'jpeg', 'png'));
- $result = $upload->upfile('special_image');
- if(!$result) {
- $data['error'] = $upload->error;
- }
- $data['image_name'] = $upload->file_name;
- $data['image_url'] = getMbSpecialImageUrl($data['image_name']);
- }
- echo json_encode($data);
- }
- /**
- * 商品列表
- */
- public function goods_listOp() {
- $model_goods = Model('goods');
- $condition = array();
- $condition['goods_name'] = array('like', '%' . $_REQUEST['keyword'] . '%');
- $goods_list = $model_goods->getGoodsOnlineList($condition, 'goods_id,goods_name,goods_promotion_price,goods_image,goods_storage', 10);
- Tpl::output('goods_list', $goods_list);
- Tpl::output('keyword', $_REQUEST['keyword']);
- Tpl::output('show_page', $model_goods->showpage());
- Tpl::showpage('mb_special_widget.goods', 'null_layout');
- }
- /**
- * 更新项目排序
- */
- public function update_item_sortOp() {
- $item_id_string = $_POST['item_id_string'];
- $special_id = $_POST['special_id'];
- if(!empty($item_id_string)) {
- $model_mb_special = Model('mb_special');
- $item_id_array = explode(',', $item_id_string);
- $index = 0;
- foreach ($item_id_array as $item_id) {
- $result = $model_mb_special->editMbSpecialItemByID(array('item_sort' => $index), $item_id, $special_id);
- $index++;
- }
- }
- $data = array();
- $data['message'] = '操作成功';
- echo json_encode($data);
- }
- /**
- * 更新项目启用状态
- */
- public function update_item_usableOp() {
- $model_mb_special = Model('mb_special');
- $result = $model_mb_special->editMbSpecialItemUsableByID($_POST['usable'], $_POST['item_id'], $_POST['special_id']);
- $data = array();
- if($result) {
- $data['message'] = '操作成功';
- } else {
- $data['error'] = '操作失败';
- }
- echo json_encode($data);
- }
- public function add_tabOp()
- {
- $tab_name = $_POST['tab_name'];
- $special_id = intval($_POST['special_id']);
- $sort = intval($_POST['tab_sort']);
- $result = true;
- if ($special_id >= 0 && !empty($tab_name) && $sort > 0)
- {
- $mod_webcode = Model('web_code');
- $tabs = $mod_webcode->get_nocache(self::mb_home_tab_id);
- foreach ($tabs as $tab)
- {
- if($tab['special_id'] == $special_id) {
- $result = false;
- break;
- }
- }
- if($result == true) {
- $tabs[] = array('special_id' => $special_id, 'name' => $tab_name, 'sort' => $sort);
- $mod_webcode->edit(self::mb_home_tab_id,serialize($tabs));
- } else {
- $result = false;
- }
- }
- else {
- $result = false;
- }
- if($result) {
- $this->log('添加首页标签' . '[ID:' . $result. ']', 1);
- showMessage(L('nc_common_save_succ'), urlAdmin('mb_special', 'tab_list'));
- } else {
- $this->log('添加首页标签' . '[ID:' . $result. ']', 0);
- showMessage(L('nc_common_save_fail'), urlAdmin('mb_special', 'tab_list'));
- }
- }
- public function del_tabOp()
- {
- $special_id = $_POST['special_id'];
- $result = false;
- if ($special_id >= 0)
- {
- $mod_webcode = Model('web_code');
- $tabs = $mod_webcode->get_nocache(self::mb_home_tab_id);
- $tabs_new = [];
- foreach ($tabs as $key => $val)
- {
- if($val['special_id'] != $special_id) {
- $tabs_new[] = $val;
- } else {
- $result = true;
- }
- }
- if($result == true) {
- $mod_webcode->edit(self::mb_home_tab_id,serialize($tabs_new));
- }
- }
- if($result) {
- $this->log('删除首页标签' . '[ID:' . $_POST['special_id'] . ']', 1);
- showMessage(L('nc_common_del_succ'), urlAdmin('mb_special', 'tab_list'));
- } else {
- $this->log('删除首页标签' . '[ID:' . $_POST['special_id'] . ']', 0);
- showMessage(L('nc_common_del_fail'), urlAdmin('mb_special', 'tab_list'));
- }
- }
- public function update_tab_nameOp()
- {
- $tab_name = $_GET['value'];
- $special_id = intval($_GET['id']);
- $data = array();
- $data['result'] = false;
- if ($special_id >= 0 && !empty($tab_name))
- {
- $mod_webcode = Model('web_code');
- $tabs = $mod_webcode->get_nocache(self::mb_home_tab_id);
- foreach ($tabs as &$tab)
- {
- if($tab['special_id'] == $special_id) {
- $tab['name'] = $tab_name;
- $data['result'] = true;
- break;
- }
- }
- if($data['result'] == true) {
- $mod_webcode->edit(self::mb_home_tab_id,serialize($tabs));
- }
- }
- if($data['result'] == true) {
- $data['message'] = '操作成功';
- } else {
- $data['error'] = '操作失败';
- }
- echo json_encode($data);die;
- }
- public function update_tab_sortOp()
- {
- $tab_sort = $_GET['value'];
- $special_id = intval($_GET['id']);
- $data = array();
- $data['result'] = false;
- if ($special_id >= 0 && $tab_sort > 0)
- {
- $mod_webcode = Model('web_code');
- $tabs = $mod_webcode->get_nocache(self::mb_home_tab_id);
- foreach ($tabs as &$tab)
- {
- if($tab['special_id'] == $special_id) {
- $tab['sort'] = $tab_sort;
- $data['result'] = true;
- break;
- }
- }
- if($data['result'] == true) {
- $mod_webcode->edit(self::mb_home_tab_id,serialize($tabs));
- }
- }
- if($data['result'] == true) {
- $data['message'] = '操作成功';
- } else {
- $data['error'] = '操作失败';
- }
- echo json_encode($data);die;
- }
- /**
- * 页面内导航菜单
- * @param string $menu_key 当前导航的menu_key
- * @param array $array 附加菜单
- * @return
- */
- private function show_menu($menu_key='') {
- $menu_array = array();
- if($menu_key == 'index_edit') {
- $menu_array[] = array('menu_key'=>'index_edit', 'menu_name'=>'编辑', 'menu_url'=>'javascript:;');
- } else {
- $menu_array[] = array('menu_key'=>'special_list','menu_name'=>'列表', 'menu_url'=>urlAdmin('mb_special', 'special_list'));
- $menu_array[] = array('menu_key'=>'tab_list','menu_name'=>'首页标签', 'menu_url'=>urlAdmin('mb_special', 'tab_list'));
- }
- if($menu_key == 'special_item_list') {
- $menu_array[] = array('menu_key'=>'special_item_list', 'menu_name'=>'编辑专题', 'menu_url'=>'javascript:;');
- }
- if($menu_key == 'index_edit') {
- tpl::output('item_title', '首页编辑');
- } else {
- tpl::output('item_title', '专题设置');
- }
- Tpl::output('menu', $menu_array);
- Tpl::output('menu_key', $menu_key);
- }
- }
|