0 ? parent::detail($page_id) : parent::getHomePage(); // 页面diy元素 $items = $detail['page_data']['items']; // 页面顶部导航 isset($detail['page_data']['page']) && $items['page'] = $detail['page_data']['page']; // 获取动态数据 $model = new self; foreach ($items as $key => $item) { unset($items[$key]['defaultData']); if ($item['type'] === 'window') { $items[$key]['data'] = array_values($item['data']); } else if ($item['type'] === 'product') { $items[$key]['data'] = $model->getProductList($user, $item); } else if ($item['type'] === 'coupon') { $items[$key]['data'] = $model->getCouponList($user, $item); } else if ($item['type'] === 'article') { $items[$key]['data'] = $model->getArticleList($item); } else if ($item['type'] === 'special') { $items[$key]['data'] = $model->getSpecialList($item); } else if ($item['type'] === 'store') { $items[$key]['data'] = $model->getStoreList($item); } else if ($item['type'] === 'seckillProduct') { // 如果没有活动,则不显示 $item_data = $model->getSeckillList($item); if(empty($item_data)){ unset($items[$key]); }else{ $items[$key]['data'] = $item_data; } } else if ($item['type'] === 'assembleProduct') { // 如果没有活动,则不显示 $item_data = $model->getAssembleList($item); if(empty($item_data)){ unset($items[$key]); }else{ $items[$key]['data'] = $item_data; } } else if ($item['type'] === 'bargainProduct') { // 如果没有活动,则不显示 $item_data = $model->getBargainList($item); if(empty($item_data)){ unset($items[$key]); }else{ $items[$key]['data'] = $item_data; } } else if ($item['type'] === 'wxlive') { $items[$key]['data'] = $model->getWxLiveList($item); }else if ($item['type'] === 'banner') { $items[$key]['data'] = $model->getBannerList($item); } } return ['page' => $items['page'], 'items' => $items]; } /** * 商品组件:获取商品列表 */ private function getBannerList($item) { if(!empty($item['data'])){ $data = []; foreach ($item['data'] as $key => $val) { if(!empty($val['name']) && empty($val['linkUrl'])){ $val['linkUrl'] = $val['name']; } $data[] = $val; } return $data; }else{ return []; } } /** * 商品组件:获取商品列表 */ private function getProductList($user, $item) { // 获取商品数据 $model = new ProductModel; if ($item['params']['source'] === 'choice') { // 数据来源:手动 $productIds = array_column($item['data'], 'product_id'); $productList = $model->getListByIdsFromApi($productIds, $user); } else { // 数据来源:自动 $productList = $model->getList([ 'type' => 'sell', 'category_id' => $item['params']['auto']['category'], 'sortType' => $item['params']['auto']['productSort'], 'list_rows' => $item['params']['auto']['showNum'] ], $user); } if ($productList->isEmpty()) return []; // 格式化商品列表 $data = []; foreach ($productList as $product) { $show_sku = ProductModel::getShowSku($product); $data[] = [ 'product_id' => $product['product_id'], 'product_name' => $product['product_name'], 'selling_point' => $product['selling_point'], 'image' => $product['image'][0]['file_path'], 'product_image' => $product['image'][0]['file_path'], 'product_price' => $show_sku['product_price'], 'line_price' => $show_sku['line_price'], 'product_sales' => $product['product_sales'], ]; } return $data; } /** * 优惠券组件:获取优惠券列表 */ private function getCouponList($user, $item) { // 获取优惠券数据 return (new Coupon)->getList($user, $item['params']['limit'], true); } /** * 文章组件:获取文章列表 */ private function getArticleList($item) { // 获取文章数据 $model = new Article; $articleList = $model->getList($item['params']['auto']['category'], $item['params']['auto']['showNum']); return $articleList->isEmpty() ? [] : $articleList->toArray()['data']; } /** * 头条快报:获取头条列表 */ private function getSpecialList($item) { // 获取头条数据 $model = new Article; $articleList = $model->getList($item['params']['auto']['category'], $item['params']['auto']['showNum']); return $articleList->isEmpty() ? [] : $articleList->toArray()['data']; } /** * 线下门店组件:获取门店列表 */ private function getStoreList($item) { // 获取商品数据 $model = new StoreModel; if ($item['params']['source'] === 'choice') { // 数据来源:手动 $storeIds = array_column($item['data'], 'store_id'); $storeList = $model->getListByIds($storeIds); } else { // 数据来源:自动 $storeList = $model->getList(null, false, false, $item['params']['auto']['showNum']); } if ($storeList->isEmpty()) return []; // 格式化商品列表 $data = []; foreach ($storeList as $store) { $data[] = [ 'store_id' => $store['store_id'], 'store_name' => $store['store_name'], 'logo_image' => $store['logo']['file_path'], 'phone' => $store['phone'], 'region' => $store['region'], 'address' => $store['address'], ]; } return $data; } /** * 获取限时秒杀 */ private function getSeckillList($item) { // 获取秒杀数据 $seckill = SeckillActiveModel::getActive(); if($seckill){ $product_model = new SeckillProductModel; $seckill['product_list'] = $product_model->getProductList($seckill['seckill_activity_id'], $item['params']['showNum']); } return $seckill; } /** * 获取限时拼团 */ private function getAssembleList($item) { // 获取拼团数据 $assemble = AssembleActiveModel::getActive(); if($assemble){ $assemble->visible(['assemble_activity_id','title', 'start_time', 'end_time']); $product_model = new AssembleProductModel; $assemble['product_list'] = $product_model->getProductList($assemble['assemble_activity_id'], $item['params']['showNum']); } return $assemble; } /** * 获取限时砍价 */ private function getBargainList($item) { // 获取拼团数据 $bargain = BargainActiveModel::getActive(); if($bargain){ $bargain->visible(['bargain_activity_id','title', 'start_time', 'end_time']); $product_model = new BargainProductModel; $bargain['product_list'] = $product_model->getProductList($bargain['bargain_activity_id'], $item['params']['showNum']); } return $bargain; } /** * 微信直播 */ private function getWxLiveList($item) { // 获取头条数据 $model = new WxLive(); $liveList = $model->getList($item['params']['showNum']); return $liveList->isEmpty() ? [] : $liveList->toArray()['data']; } }