瀏覽代碼

Merge branch 'goods' of 121.43.114.153:/home/git/repositories/shopnc into goods

Wan Xin 9 年之前
父節點
當前提交
709680d01f
共有 1 個文件被更改,包括 141 次插入114 次删除
  1. 141 114
      data/model/mb_special.model.php

+ 141 - 114
data/model/mb_special.model.php

@@ -8,6 +8,7 @@
  */
 
 defined('InShopNC') or exit('Access Invalid!');
+
 class mb_specialModel extends Model
 {
     //专题项目不可用状态
@@ -17,47 +18,51 @@ class mb_specialModel extends Model
     //首页特殊专题编号
     const INDEX_SPECIAL_ID = 0;
 
-    public function __construct() {
+    public function __construct()
+    {
         parent::__construct('mb_special');
     }
 
-	/**
-	 * 读取专题列表
-	 * @param array $condition
-	 *
-	 */
-	public function getMbSpecialList($condition, $page='', $order='special_id desc', $field='*') {
+    /**
+     * 读取专题列表
+     * @param array $condition
+     *
+     */
+    public function getMbSpecialList($condition, $page = '', $order = 'special_id desc', $field = '*')
+    {
         $list = $this->table('mb_special')->field($field)->where($condition)->page($page)->order($order)->select();
         return $list;
-	}
+    }
 
-	/*
-	 * 增加专题
-	 * @param array $param
-	 * @return bool
+    /*
+     * 增加专题
+     * @param array $param
+     * @return bool
      *
-	 */
-    public function addMbSpecial($param){
+     */
+    public function addMbSpecial($param)
+    {
         return $this->table('mb_special')->insert($param);
     }
 
-	/*
-	 * 更新专题
-	 * @param array $update
-	 * @param array $condition
-	 * @return bool
+    /*
+     * 更新专题
+     * @param array $update
+     * @param array $condition
+     * @return bool
      *
-	 */
-    public function editMbSpecial($update, $special_id) {
+     */
+    public function editMbSpecial($update, $special_id)
+    {
         $special_id = intval($special_id);
-        if($special_id <= 0) {
+        if ($special_id <= 0) {
             return false;
         }
 
         $condition = array();
         $condition['special_id'] = $special_id;
         $result = $this->table('mb_special')->where($condition)->update($update);
-        if($result) {
+        if ($result) {
             //删除缓存
             $this->_delMbSpecialCache($special_id);
             return $special_id;
@@ -66,15 +71,16 @@ class mb_specialModel extends Model
         }
     }
 
-	/*
-	 * 删除专题
-	 * @param int $special_id
-	 * @return bool
+    /*
+     * 删除专题
+     * @param int $special_id
+     * @return bool
      *
-	 */
-    public function delMbSpecialByID($special_id) {
+     */
+    public function delMbSpecialByID($special_id)
+    {
         $special_id = intval($special_id);
-        if($special_id <= 0) {
+        if ($special_id <= 0) {
             return false;
         }
 
@@ -88,10 +94,11 @@ class mb_specialModel extends Model
 
     /**
      * 专题项目列表(用于后台编辑显示所有项目)
-	 * @param int $special_id
+     * @param int $special_id
      *
      */
-    public function getMbSpecialItemListByID($special_id) {
+    public function getMbSpecialItemListByID($special_id)
+    {
         $condition = array();
         $condition['special_id'] = $special_id;
 
@@ -100,7 +107,7 @@ class mb_specialModel extends Model
 
     /**
      * 专题可用项目列表(用于前台显示仅显示可用项目)
-	 * @param int $special_id
+     * @param int $special_id
      *
      */
     public function getMbSpecialItemUsableListByIDEx($special_id)
@@ -108,7 +115,7 @@ class mb_specialModel extends Model
         $prefix = 'mb_special';
         $item_list = rcache($special_id, $prefix);
         //缓存有效
-        if(!empty($item_list)) {
+        if (!empty($item_list)) {
             return unserialize($item_list['special']);
         }
 
@@ -117,11 +124,9 @@ class mb_specialModel extends Model
         $condition['special_id'] = $special_id;
         $condition['item_usable'] = self::SPECIAL_ITEM_USABLE;
         $item_list = $this->_getMbSpecialItemList($condition);
-        if(!empty($item_list))
-        {
+        if (!empty($item_list)) {
             $pages = array();
-            foreach ($item_list as $value)
-            {
+            foreach ($item_list as $value) {
                 //处理图片
                 $items = array();
                 $items['item_id'] = $value['item_id'];
@@ -130,14 +135,23 @@ class mb_specialModel extends Model
                 $items['item_sort'] = $value['item_sort'];
                 $item_data = $this->_formatMbSpecialData($value['item_data'], $value['item_type']);
 
-//                if($value['item_type'] === 'adv_list') {
-//                    $items['item_data'] = $item_data['item'];
-//                } else {
-//                    $items['item_data'] = $item_data;
-//                }
+                // add goods_price
+                if ($value['item_type'] === 'goods') {
+
+                    foreach ($item_data['item'] as &$item) {
+
+                        $model_goods = Model('goods');
+                        $goods_detail = $model_goods->getGoodsInfo(array('goods_id' => $item['goods_id']), 'goods_price');
+                        if (!empty($goods_detail)) {
+                            $item['goods_price'] = $goods_detail['goods_price'];
+                        } else {
+                            $item['goods_price'] = 0.0;
+                        }
+                    }
+                }
 
                 $items['item_data'] = $item_data;
-                array_push($pages,$items);
+                array_push($pages, $items);
             }
             $item_list = $pages;
         }
@@ -152,7 +166,7 @@ class mb_specialModel extends Model
 
         $item_list = rcache($special_id, $prefix);
         //缓存有效
-        if(!empty($item_list)) {
+        if (!empty($item_list)) {
             return unserialize($item_list['special']);
         }
 
@@ -161,8 +175,7 @@ class mb_specialModel extends Model
         $condition['special_id'] = $special_id;
         $condition['item_usable'] = self::SPECIAL_ITEM_USABLE;
         $item_list = $this->_getMbSpecialItemList($condition);
-        if(!empty($item_list))
-        {
+        if (!empty($item_list)) {
             $new_item_list = array();
             foreach ($item_list as $value) {
                 //处理图片
@@ -179,7 +192,8 @@ class mb_specialModel extends Model
     /**
      * 首页专题
      */
-    public function getMbSpecialIndex() {
+    public function getMbSpecialIndex()
+    {
         return $this->getMbSpecialItemUsableListByID(self::INDEX_SPECIAL_ID);
     }
 
@@ -197,10 +211,10 @@ class mb_specialModel extends Model
                 $item_data['square_image'] = getMbSpecialImageUrl($item_data['square_image']);
                 $item_data['rectangle1_image'] = getMbSpecialImageUrl($item_data['rectangle1_image']);
                 $item_data['rectangle2_image'] = getMbSpecialImageUrl($item_data['rectangle2_image']);
-            break;
+                break;
             case 'goods':
                 $new_item = array();
-                foreach ((array) $item_data['item'] as $value) {
+                foreach ((array)$item_data['item'] as $value) {
                     $value['goods_image'] = cthumb($value['goods_image']);
                     $new_item[] = $value;
                 }
@@ -208,7 +222,7 @@ class mb_specialModel extends Model
                 break;
             default:
                 $new_item = array();
-                foreach ((array) $item_data['item'] as $key => $value) {
+                foreach ((array)$item_data['item'] as $key => $value) {
                     $value['image'] = getMbSpecialImageUrl($value['image']);
                     $new_item[] = $value;
                 }
@@ -225,7 +239,7 @@ class mb_specialModel extends Model
         $item_list = $this->table('mb_special_item')->where($condition)->order($order)->select();
         foreach ($item_list as $key => $value) {
             $item_list[$key]['item_data'] = $this->_initMbSpecialItemData($value['item_data'], $value['item_type']);
-            if($value['item_usable'] == self::SPECIAL_ITEM_USABLE) {
+            if ($value['item_usable'] == self::SPECIAL_ITEM_USABLE) {
                 $item_list[$key]['usable_class'] = 'usable';
                 $item_list[$key]['usable_text'] = '禁用';
             } else {
@@ -238,12 +252,13 @@ class mb_specialModel extends Model
 
     /**
      * 检查专题项目是否存在
-	 * @param array $condition
+     * @param array $condition
      *
      */
-    public function isMbSpecialItemExist($condition) {
+    public function isMbSpecialItemExist($condition)
+    {
         $item_list = $this->table('mb_special_item')->where($condition)->select();
-        if($item_list) {
+        if ($item_list) {
             return true;
         } else {
             return false;
@@ -255,9 +270,10 @@ class mb_specialModel extends Model
      * @param int $item_id
      *
      */
-    public function getMbSpecialItemInfoByID($item_id) {
+    public function getMbSpecialItemInfoByID($item_id)
+    {
         $item_id = intval($item_id);
-        if($item_id <= 0) {
+        if ($item_id <= 0) {
             return false;
         }
 
@@ -273,10 +289,11 @@ class mb_specialModel extends Model
      * 整理项目内容
      *
      */
-    private function _initMbSpecialItemData($item_data, $item_type) {
-        if(!empty($item_data)) {
+    private function _initMbSpecialItemData($item_data, $item_type)
+    {
+        if (!empty($item_data)) {
             $item_data = unserialize($item_data);
-            if($item_type == 'goods') {
+            if ($item_type == 'goods') {
                 $item_data = $this->_initMbSpecialItemGoodsData($item_data, $item_type);
             }
         } else {
@@ -289,9 +306,10 @@ class mb_specialModel extends Model
     /**
      * 处理goods类型内容
      */
-    private function _initMbSpecialItemGoodsData($item_data, $item_type) {
+    private function _initMbSpecialItemGoodsData($item_data, $item_type)
+    {
         $goods_id_string = '';
-        if(!empty($item_data['item'])) {
+        if (!empty($item_data['item'])) {
             foreach ($item_data['item'] as $value) {
                 $goods_id_string .= $value . ',';
             }
@@ -306,7 +324,7 @@ class mb_specialModel extends Model
             //整理商品数据
             $new_goods_list = array();
             foreach ($item_data['item'] as $value) {
-                if(!empty($goods_list[$value])) {
+                if (!empty($goods_list[$value])) {
                     $new_goods_list[] = $goods_list[$value];
                 }
             }
@@ -318,33 +336,34 @@ class mb_specialModel extends Model
     /**
      * 初始化空项目内容
      */
-    private function _initMbSpecialItemNullData($item_type) {
+    private function _initMbSpecialItemNullData($item_type)
+    {
         $item_data = array();
         switch ($item_type) {
-        case 'home1':
-            $item_data = array(
-                'title' => '',
-                'image' => '',
-                'type' => '',
-                'data' => '',
-            );
-            break;
-        case 'home2':
-        case 'home4':
-            $item_data= array(
-                'title' => '',
-                'square_image' => '',
-                'square_type' => '',
-                'square_data' => '',
-                'rectangle1_image' => '',
-                'rectangle1_type' => '',
-                'rectangle1_data' => '',
-                'rectangle2_image' => '',
-                'rectangle2_type' => '',
-                'rectangle2_data' => '',
-            );
-            break;
-        default:
+            case 'home1':
+                $item_data = array(
+                    'title' => '',
+                    'image' => '',
+                    'type' => '',
+                    'data' => '',
+                );
+                break;
+            case 'home2':
+            case 'home4':
+                $item_data = array(
+                    'title' => '',
+                    'square_image' => '',
+                    'square_type' => '',
+                    'square_data' => '',
+                    'rectangle1_image' => '',
+                    'rectangle1_type' => '',
+                    'rectangle1_data' => '',
+                    'rectangle2_image' => '',
+                    'rectangle2_type' => '',
+                    'rectangle2_data' => '',
+                );
+                break;
+            default:
         }
         return $item_data;
     }
@@ -355,12 +374,13 @@ class mb_specialModel extends Model
      * @return array $item_info
      *
      */
-    public function addMbSpecialItem($param) {
+    public function addMbSpecialItem($param)
+    {
         $param['item_usable'] = self::SPECIAL_ITEM_UNUSABLE;
         $param['item_sort'] = 255;
         $result = $this->table('mb_special_item')->insert($param);
         //删除缓存
-        if($result) {
+        if ($result) {
             //删除缓存
             $this->_delMbSpecialCache($param['special_id']);
             $param['item_id'] = $result;
@@ -378,8 +398,9 @@ class mb_specialModel extends Model
      * @return bool
      *
      */
-    public function editMbSpecialItemByID($update, $item_id, $special_id) {
-        if(isset($update['item_data'])) {
+    public function editMbSpecialItemByID($update, $item_id, $special_id)
+    {
+        if (isset($update['item_data'])) {
             $update['item_data'] = serialize($update['item_data']);
         }
         $condition = array();
@@ -398,9 +419,10 @@ class mb_specialModel extends Model
      * @param int $special_id
      *
      */
-    public function editMbSpecialItemUsableByID($usable, $item_id, $special_id) {
+    public function editMbSpecialItemUsableByID($usable, $item_id, $special_id)
+    {
         $update = array();
-        if($usable == 'usable') {
+        if ($usable == 'usable') {
             $update['item_usable'] = self::SPECIAL_ITEM_USABLE;
         } else {
             $update['item_usable'] = self::SPECIAL_ITEM_UNUSABLE;
@@ -408,13 +430,14 @@ class mb_specialModel extends Model
         return $this->editMbSpecialItemByID($update, $item_id, $special_id);
     }
 
-	/*
-	 * 删除
-	 * @param array $condition
-	 * @return bool
+    /*
+     * 删除
+     * @param array $condition
+     * @return bool
      *
-	 */
-    public function delMbSpecialItem($condition, $special_id) {
+     */
+    public function delMbSpecialItem($condition, $special_id)
+    {
         //删除缓存
         $this->_delMbSpecialCache($special_id);
 
@@ -423,19 +446,21 @@ class mb_specialModel extends Model
 
     /**
      * 获取专题URL地址
-	 * @param int $special_id
+     * @param int $special_id
      *
      */
-    public function getMbSpecialHtmlUrl($special_id) {
+    public function getMbSpecialHtmlUrl($special_id)
+    {
         return UPLOAD_SITE_URL . DS . ATTACH_MOBILE . DS . 'special_html' . DS . md5('special' . $special_id) . '.html';
     }
 
     /**
      * 获取专题静态文件路径
-	 * @param int $special_id
+     * @param int $special_id
      *
      */
-    public function getMbSpecialHtmlPath($special_id) {
+    public function getMbSpecialHtmlPath($special_id)
+    {
         return BASE_UPLOAD_PATH . DS . ATTACH_MOBILE . DS . 'special_html' . DS . md5('special' . $special_id) . '.html';
     }
 
@@ -444,28 +469,30 @@ class mb_specialModel extends Model
      * @return array
      *
      */
-    public function getMbSpecialModuleList() {
+    public function getMbSpecialModuleList()
+    {
         $module_list = array();
-        $module_list['adv_list'] = array('name' => 'adv_list' , 'desc' => '广告条版块');
-        $module_list['home1'] = array('name' => 'home1' , 'desc' => '模型版块布局A');
-        $module_list['home2'] = array('name' => 'home2' , 'desc' => '模型版块布局B');
-        $module_list['home3'] = array('name' => 'home3' , 'desc' => '模型版块布局C');
-        $module_list['home4'] = array('name' => 'home4' , 'desc' => '模型版块布局D');
-        $module_list['home5'] = array('name' => 'home5' , 'desc' => '模型版块布局E');
-        $module_list['goods'] = array('name' => 'goods' , 'desc' => '商品版块');
+        $module_list['adv_list'] = array('name' => 'adv_list', 'desc' => '广告条版块');
+        $module_list['home1'] = array('name' => 'home1', 'desc' => '模型版块布局A');
+        $module_list['home2'] = array('name' => 'home2', 'desc' => '模型版块布局B');
+        $module_list['home3'] = array('name' => 'home3', 'desc' => '模型版块布局C');
+        $module_list['home4'] = array('name' => 'home4', 'desc' => '模型版块布局D');
+        $module_list['home5'] = array('name' => 'home5', 'desc' => '模型版块布局E');
+        $module_list['goods'] = array('name' => 'goods', 'desc' => '商品版块');
         return $module_list;
     }
 
     /**
      * 清理缓存
      */
-    private function _delMbSpecialCache($special_id) {
+    private function _delMbSpecialCache($special_id)
+    {
         //清理缓存
         dcache($special_id, 'mb_special');
 
         //删除静态文件
         $html_path = $this->getMbSpecialHtmlPath($special_id);
-        if(is_file($html_path)) {
+        if (is_file($html_path)) {
             @unlink($html_path);
         }
     }