| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- <?php
- namespace app\api\model\page;
- use app\api\model\plus\live\WxLive;
- use app\api\model\product\Product as ProductModel;
- use app\api\model\plus\article\Article;
- use app\api\model\store\Store as StoreModel;
- use app\common\model\page\Page as PageModel;
- use app\api\model\plus\coupon\Coupon;
- use app\api\model\plus\seckill\Product as SeckillProductModel;
- use app\api\model\plus\seckill\Active as SeckillActiveModel;
- use app\api\model\plus\assemble\Product as AssembleProductModel;
- use app\api\model\plus\assemble\Active as AssembleActiveModel;
- use app\api\model\plus\bargain\Product as BargainProductModel;
- use app\api\model\plus\bargain\Active as BargainActiveModel;
- /**
- * 首页模型
- */
- class Page extends PageModel
- {
- /**
- * 隐藏字段
- */
- protected $hidden = [
- 'app_id',
- 'create_time',
- 'update_time'
- ];
- /**
- * DIY页面详情
- */
- public static function getPageData($user, $page_id = null)
- {
- // 页面详情
- $detail = $page_id > 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'];
- }
- }
|