Bläddra i källkod

add special tabs

stanley-king 7 år sedan
förälder
incheckning
7dc9c4ebc4

+ 32 - 3
admin/control/mb_special.php

@@ -25,9 +25,9 @@ require_once (BASE_ROOT_PATH . '/helper/activity_helper.php');
 class mb_specialControl extends SystemControl
 {
     const mb_home_tab_id = 123;
-    const def_item_bg_color = '#F7F7F7';
-    const def_item_bg_type  = 'color';
-    const def_divider_bg_img= '/mobile/defimg/divider_bg.png';
+    const def_item_bg_color     = '#F7F7F7';
+    const def_item_bg_type      = 'color';
+    const def_divider_bg_img    = '/mobile/defimg/divider_bg.png';
 
 	public function __construct()
     {
@@ -336,6 +336,35 @@ class mb_specialControl extends SystemControl
          }
      }
 
+     public function special_item_edit_tabOp()
+     {
+         $href = urlAdmin('mb_special', 'special_edit', array('special_id' => $_POST['special_id']));
+
+         $special_id  = intval($_POST['special_id']);
+         $tabs  = $_POST['tabs'];
+         if($special_id > 0)
+         {
+             if(!empty($tabs))
+             {
+                 $items = preg_split("/#/",$tabs);
+                 foreach ($items as $item)
+                 {
+                     $values = explode(":",$item);
+                     if(count($values) != 2 || intval($values[0]) <= 0) {
+                         showMessage(L('nc_common_save_fail'), $href);
+                         return;
+                     }
+                 }
+             }
+
+             $mod_special = Model('mb_special');
+             $mod_special->editMbSpecial(['tabs' => $tabs],$special_id);
+             showMessage(L('nc_common_save_succ'),$href);
+         } else {
+             showMessage(L('nc_common_save_fail'), $href);
+         }
+     }
+
     /**
      * 专题项目删除
      */

+ 5 - 4
admin/templates/default/mb_special_item.list.php

@@ -103,9 +103,10 @@
                     <input type="hidden" name="special_id" value="<?php echo $output['special_id']; ?>"><button type="submit">确定</button>
                 </div>
             </form>
-            <form action="index.php?act=mb_special&op=move_item" method="post" id="tabs_type">
+            <form action="index.php?act=mb_special&op=special_item_edit_tab" method="post" id="tabs_type">
                 <div style="margin-top: 10px;">
-                    <input type="text" name="tabs_type" style="width: 443px;margin-right: 10px;" placeholder="请输入tabs_type"><button type="submit" style="display: inline-block;">确定</button>
+                    <input type="hidden" name="special_id" value="<?php echo $output['special_id']; ?>">
+                    专题标签:<input type="text" name="tabs" style="width: 400px;margin-right: 10px;" placeholder="按ID:名称输入以;隔开"><button type="submit" style="display: inline-block;">确定</button>
                 </div>
             </form>
         </div>
@@ -119,8 +120,8 @@
 </script>
 <script type="text/javascript">
     var special_id = <?php echo $output['special_id'];?>;
-    var url_item_add = "<?php echo urlAdmin('mb_special', 'special_item_add');?>";
-    var url_item_del = "<?php echo urlAdmin('mb_special', 'special_item_del');?>";
+    var url_item_add  = "<?php echo urlAdmin('mb_special', 'special_item_add');?>";
+    var url_item_del  = "<?php echo urlAdmin('mb_special', 'special_item_del');?>";
     var url_item_edit = "<?php echo urlAdmin('mb_special', 'special_item_edit');?>";
     $(document).ready(function () {
         //添加模块

+ 44 - 4
data/model/mb_special.model.php

@@ -122,6 +122,29 @@ class mb_specialModel extends Model
         return $this->_getMbSpecialItemList($condition);
     }
 
+    private function gen_tabs($tab_words)
+    {
+        if(empty($tab_words)) return false;
+
+        $result = [];
+        $items = preg_split("/#/",$tab_words);
+        foreach ($items as $item)
+        {
+            $values = explode(":",$item);
+            $item_id = intval($values[0]);
+
+            if(count($values) != 2 || $item_id <= 0) {
+                continue;
+            } else {
+                $result[$item_id] = ['pos' => 0,'title' => trim($values[1])];
+            }
+        }
+
+        return empty($result) ? false : $result;
+    }
+    private function format_tabs($tabs) {
+
+    }
     public function getMbSpecialItemUsableListByID($special_id)
     {
         $prefix = 'mb_special';
@@ -137,22 +160,31 @@ class mb_specialModel extends Model
         $condition['item_usable'] = self::SPECIAL_ITEM_USABLE;
         $item_list = $this->_getMbSpecialItemList($condition);
 
-        $spinfo = $this->getMbSpecialByID($special_id,'from_user');
+        $spinfo = $this->getMbSpecialByID($special_id,'from_user,tabs');
         $from_user = $spinfo['from_user'] == 1 ? true : false;
+        $tabs = $this->gen_tabs($spinfo['tabs']);
 
+        $item_sort = 0;
         $blocks = [];
         foreach ($item_list as $value)
         {
             $block = [];
+
             $block['item_type'] = $value['item_type'];
             $block['bg_image']  = $value['bg_image'];
             $block['bg_type']   = $value['bg_type'];
             $block['bg_data']   = $value['bg_data'];
             $has_margin = intval($value['has_margin']);
             $block['has_margin']= $has_margin === 0 ? false : true;
+            $item_id = intval($value['item_id']);
 
-            $item_type = $value['item_type'];
+            if($tabs != false && array_key_exists($item_id,$tabs)) {
+                $tabs[$item_id]['pos'] = $item_sort;
+            }
+            $block['item_sort'] = $item_sort;
+            $item_sort++;
 
+            $item_type = $value['item_type'];
             if($item_type == 'divider') {
                 $blocks[] = $block;
                 continue;
@@ -183,8 +215,16 @@ class mb_specialModel extends Model
 
             $blocks[] = $block;
         }
-
-        $cache = array('blocks' => $blocks);
+        if($tabs == false) {
+            $tab_items = [];
+        }
+        else {
+            $tab_items = [];
+            foreach ($tabs as $key => $val) {
+                $tab_items[] = $val;
+            }
+        }
+        $cache = array('blocks' => $blocks,'tabs' => $tab_items);
         wcache($special_id, array('special' => serialize($cache)), $prefix);
         return $cache;
     }

+ 19 - 1
helper/special_helper.php

@@ -88,6 +88,7 @@ class special_formater
     private $goods_ids;
     private $special_info;
     private $sender_info;
+    private $tabs;
 
     private $old_version;
 
@@ -105,6 +106,9 @@ class special_formater
     public function sender_info() {
         return $this->sender_info;
     }
+    public function tabs() {
+        return $this->tabs;
+    }
 
     public static function def_divider()
     {
@@ -383,6 +387,11 @@ class special_formater
             Log::record("getMbSpecialItemUsableListByID is empty",Log::ERR);
         }
         $from_user = spid_helper::instance()->special($this->special_id)->from_user();
+        if(array_key_exists('tabs',$specials)) {
+            $this->tabs = $specials['tabs'];
+        } else {
+            $this->tabs = [];
+        }
 
         if(isset($specials["mobile_filter_data"]))
         {
@@ -962,7 +971,14 @@ class special_manager
 
         return self::$stInstance;
     }
-
+    public function tabs($special_id)
+    {
+        if (array_key_exists($special_id, $this->mContents)) {
+            return $this->mContents[$special_id]['tabs'];
+        } else {
+            return [];
+        }
+    }
     public function special($special_id,&$goods_ids,$pub=true)
     {
         if($pub)
@@ -985,6 +1001,8 @@ class special_manager
 
                 $this->mContents[$special_id]['data'] = $data;
                 $this->mContents[$special_id]['gids'] = $goods_ids;
+                $this->mContents[$special_id]['tabs'] = $formater->tabs();
+
                 return $data;
             }
         }

+ 1 - 0
mobile/control/special.php

@@ -111,6 +111,7 @@ class specialControl extends mobileHomeControl
             $goodsex = $helper->online_summary($goods_ids, $related_goods);
 
             return array('special_list' => $specials,
+                'tabs' => special_manager::instance()->tabs($special_id),
                 'summary'  => $goodsex['summary'],
                 'groupbuy' => $goodsex['groupbuy'],
                 'limitime' => $goodsex['limitime'],