Example #1
0
 public function find($id)
 {
     $row = parent::find($id);
     if ($row) {
         $content = M('ArticleContent')->getFieldByArticle_id($id, 'content');
         $row['content'] = $content;
     }
     return $row;
 }
Example #2
0
 /**
  * 覆盖find方法, 增强他的功能...
  * @param array|mixed $id
  * @return mixed
  */
 public function find($id)
 {
     //>>1.获取goods表中的一行数据, 该数据中不包含intro
     $row = parent::find($id);
     if (!$row) {
         return $row;
     }
     //>>2.从goods_intro表中查询出intro放到row中..
     $intro = M('GoodsIntro')->getFieldByGoods_id($id, 'intro');
     $row['intro'] = $intro;
     //>>2.从会员价格表中找到当前商品的会员价格
     $goodsMemberPrices = M('GoodsMemberPrice')->field('member_level_id,price')->where(array('goods_id' => $id))->select();
     if (!empty($goodsMemberPrices)) {
         /**
         * array(3) {
            [0] => array(2) {
            ["member_level_id"] => string(1) "1"
            ["price"] => string(5) "30.00"
            }
            [1] => array(2) {
            ["member_level_id"] => string(1) "2"
            ["price"] => string(5) "20.00"
            }
            [2] => array(2) {
            ["member_level_id"] => string(1) "3"
            ["price"] => string(5) "10.00"
         }
                     }
                     一个商品的级别id==>对应的价格
         
                     array('1'=>30,'2'=>20,'3'=>30)
         */
         $member_level_ids = array_column($goodsMemberPrices, 'member_level_id');
         $prices = array_column($goodsMemberPrices, 'price');
         $goodsMemberPrices = array_combine($member_level_ids, $prices);
         /**
         * ["goodsMemberPrices"] => array(3) {
            [1] => string(5) "30.00"
            [2] => string(5) "20.00"
            [3] => string(5) "10.00"
                     }
         */
         $row['goodsMemberPrices'] = $goodsMemberPrices;
     }
     //查询出商品的相册
     $goodsGalleryes = M('GoodsGallery')->field('id,path')->where(array('goods_id' => $id))->select();
     $row['goodsGalleryes'] = $goodsGalleryes;
     //找到当前商品对应的文章
     $goodsArticleModel = M('GoodsArticle');
     $goodsArticleModel->field('ga.article_id,a.name as article_name');
     $goodsArticleModel->alias('ga');
     $goodsArticleModel->where(' ga.goods_id = ' . $id);
     $articles = $goodsArticleModel->join('__ARTICLE__ as a on ga.article_id=a.id')->select();
     $row['articles'] = $articles;
     return $row;
 }