Exemplo n.º 1
0
 /**
  * 自营店铺列表
  */
 public function listOp()
 {
     require_once BASE_DATA_PATH . DS . 'cache' . DS . 'area_cache.php';
     $lang = Language::getLangContent();
     $model_store = Model('store');
     $model_area = Model('area');
     $model_store_area = Model('store_area');
     if (chksubmit()) {
         //删除
         if ($_POST['submit_type'] == 'set') {
             $set_areas = $_POST['set_areas'];
             $set_areas = htmlspecialchars_decode($set_areas, ENT_QUOTES);
             $new_list = json_decode($set_areas, TRUE);
             $store_id = $_POST['store_id'];
             if (!empty($new_list)) {
                 $state = 1;
                 if ($store['store_state'] == 0 || $store['store_state'] == 2) {
                     $state = 2;
                 }
                 $old_list = $model_store_area->getStoreAreaList();
                 //更新的
                 $update_array = array();
                 //新的
                 $insert_array = array();
                 foreach ($new_list as $key => $val) {
                     $new = 0;
                     foreach ($old_list as $k => $v) {
                         if ($v['area_id'] == $val['area_id'] && $v['store_id'] == $val['store_id']) {
                             if ($v['area_level'] != $val['area_level'] || $v['state'] != $val['state']) {
                                 $new_arr = array();
                                 $new_arr = $val;
                                 $new_arr['store_area_id'] = $v['store_area_id'];
                                 $update_array[] = $new_arr;
                             }
                             $new = 1;
                             break;
                         }
                     }
                     if ($new == 0) {
                         $insert_array[] = $val;
                     }
                 }
                 $model_store_area->addStoreAreaAll($insert_array);
                 foreach ($update_array as $k => $v) {
                     $update_arr = array();
                     $update_arr['store_id'] = $v['store_id'];
                     $update_arr['area_id'] = $v['area_id'];
                     $update_arr['area_level'] = $v['area_level'];
                     $update_arr['state'] = $v['state'];
                     $result = $model_store_area->editStoreArea($update_arr, array('store_area_id' => $v['store_area_id']));
                 }
                 showMessage($lang['nc_common_save_succ']);
             } else {
                 $this->log(L('nc_delete,area_index_class') . '[ID:' . $set_areas . ']', 0);
                 showMessage($lang['nc_common_save_fail']);
             }
         }
     }
     //父ID
     $parent_id = $_GET['area_parent_id'] ? intval($_GET['area_parent_id']) : 0;
     //获取上级ID的深度
     if ($parent_id == 0) {
         $deep = 0;
     } else {
         $area = $model_area->getAreaInfo(array('area_id' => $parent_id));
         $deep = $area['area_deep'];
     }
     //获取当前深度的所有当前地区
     $deep = "" . (intval($deep) + 1);
     $all_list = area_cache::getCache('area', array('deep' => $deep));
     //获取所有子地区
     $deep = "" . (intval($deep) + 1);
     $cache_data = area_cache::getCache('area', array('deep' => $deep));
     //判断所有当前地区是否有子地区,有的则添加变量have_child=1
     if (is_array($cache_data)) {
         foreach ($cache_data as $k => $v) {
             foreach ($all_list as $key => $val) {
                 if ($v['area_parent_id'] == $val['area_id']) {
                     $all_list[$key]['have_child'] = 1;
                 }
             }
         }
     }
     //筛选出当前父ID的所有相关地区
     $area_list = array();
     foreach ($all_list as $val) {
         if ($val['area_parent_id'] == $parent_id) {
             $area_list[] = $val;
         }
     }
     //获取所有自营店关联的地区
     $store_area_list = $model_store_area->getStoreAreaList();
     foreach ($area_list as $key => $val) {
         $area_list[$key]['store'] = array();
         foreach ($store_area_list as $v) {
             if ($val['area_id'] == $v['area_id']) {
                 $area_list[$key]['store'][$v['store_id']]['area_level'] = $v['area_level'];
                 $area_list[$key]['store'][$v['store_id']]['state'] = $v['state'];
             }
         }
     }
     //获取所有自营店
     $condition = array('is_own_shop' => 1);
     $store_own_list = $model_store->getStoreList($condition);
     if ($_GET['ajax'] == '1') {
         //转码
         if (strtoupper(CHARSET) == 'GBK') {
             $area_list = Language::getUTF8($area_list);
         }
         $output = json_encode($area_list);
         print_r($output);
         exit;
     } else {
         Tpl::output('area_list', $area_list);
         Tpl::output('top_link', $this->sublink($this->links, 'area'));
         Tpl::output('store_list', $store_own_list);
         Tpl::showpage('store_area.index2');
     }
 }
Exemplo n.º 2
0
 /**
  * 地区管理
  */
 public function areaOp()
 {
     require_once BASE_DATA_PATH . DS . 'cache' . DS . 'area_cache.php';
     $lang = Language::getLangContent();
     /**
      * 实例化模型
      */
     $model_area = Model('area');
     if (chksubmit()) {
         //删除
         if ($_POST['submit_type'] == 'del') {
             $area_ids = implode(',', $_POST['check_area_id']);
             if (!empty($_POST['check_area_id'])) {
                 if (!is_array($_POST['check_area_id'])) {
                     $this->log(L('nc_delete,area_index') . '[ID:' . $area_ids . ']', 0);
                     showMessage($lang['nc_common_del_fail']);
                 }
                 //获取要删除的所有ID
                 $delid_arr = array();
                 foreach ($_POST['check_area_id'] as $val) {
                     $delid_arr[$val] = $val;
                     $id_temp_array = $model_area->getChildsByPid($val);
                     foreach ($id_temp_array as $v) {
                         $delid_arr[$v] = $v;
                     }
                 }
                 //同时删除关联的store_area表
                 $model_store_area->delStoreArea(array('area_id' => array('in', $delid_arr)));
                 //删除地区
                 $model_area->delArea(array('area_id' => array('in', $delid_arr)));
                 //更新缓存操作
                 area_cache::deleteCacheFile();
                 area_cache::updateAreaArrayJs();
                 area_cache::updateAreaPhp();
                 $this->log(L('nc_delete,area_index_class') . '[ID:' . $area_ids . ']', 1);
                 showMessage($lang['nc_common_del_succ']);
             } else {
                 $this->log(L('nc_delete,area_index_class') . '[ID:' . $area_ids . ']', 0);
                 showMessage($lang['nc_common_del_fail']);
             }
         }
     }
     //父ID
     $parent_id = $_GET['area_parent_id'] ? intval($_GET['area_parent_id']) : 0;
     if ($parent_id == 0) {
         $deep = 0;
     } else {
         $area = $model_area->getAreaInfo(array('area_id' => $parent_id));
         $deep = $area['area_deep'];
     }
     //获取所有子地区y
     $deep = "" . (intval($deep) + 1);
     $all_list = area_cache::getCache('area', array('deep' => $deep));
     //获取所有子地区
     $deep = "" . (intval($deep) + 1);
     $cache_data = area_cache::getCache('area', array('deep' => $deep));
     if (is_array($cache_data)) {
         foreach ($cache_data as $k => $v) {
             foreach ($all_list as $key => $val) {
                 if ($v['area_parent_id'] == $val['area_id']) {
                     $all_list[$key]['have_child'] = 1;
                 }
             }
         }
     }
     foreach ($all_list as $val) {
         if ($val['area_parent_id'] == $parent_id) {
             $area_list[] = $val;
         }
     }
     if ($_GET['ajax'] == '1') {
         //转码
         if (strtoupper(CHARSET) == 'GBK') {
             $area_list = Language::getUTF8($area_list);
         }
         $output = json_encode($area_list);
         print_r($output);
         exit;
     } else {
         Tpl::output('area_list', $area_list);
         Tpl::output('top_link', $this->sublink($this->links, 'area'));
         Tpl::showpage('area.index');
     }
 }