quanwei
2 days ago 73b874c72ad55eb9eef21c36160ac0de58f0189e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
<?php
 
namespace app\api\model\page;
 
use app\api\model\product\Product as ProductModel;
use app\api\model\plus\article\Article;
use app\api\model\supplier\Category;
use app\common\enum\supplier\SupplierType;
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;
use app\api\model\plus\live\Room as RoomModel;
use app\api\model\plus\release\Project;
use app\api\model\supplier\Supplier as SupplierModel;
/**
 * 首页模型
 */
class Page extends PageModel
{
    /**
     * 隐藏字段
     */
    protected $hidden = [
        'app_id',
        'create_time',
        'update_time'
    ];
 
    /**
     * DIY页面详情
     */
    public static function getPageData($user, $page_id = null,$city_supplier_ids='',$latitude=0,$longitude=0)
    {
        // 页面详情
        $detail = $page_id > 0 ? parent::detail($page_id) : parent::getDefault();
 
        // 页面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,$city_supplier_ids);
            } else if ($item['type'] === 'coupon') {
                $items[$key]['data'] = $model->getCouponList($user, $item, true, 1);
            } else if ($item['type'] === 'article') {
                $items[$key]['data'] = $model->getArticleList($item);
            }else if ($item['type'] === 'hdzq') {
                $items[$key]['data'] = $model->getReleaseList($item,$user);
            }else if ($item['type'] === 'gxpp') {
                $items[$key]['data'] = $model->getReleaseList($item,$user);
            } else if ($item['type'] === 'special') {
                $items[$key]['data'] = $model->getSpecialList($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'] === 'live') {
                $items[$key]['data'] = $model->getLiveList($item);
            } else if ($item['type'] === 'previewProduct') {
                $items[$key]['data'] = $model->getPreviewList($user, $item);
            } else if ($item['type'] === 'groupBuy') {
                // 团购组件
                //$items[$key]['data'] = $model->getGroupBuyList($user, $item, $city_supplier_ids, $latitude, $longitude);
                $items[$key]['style']['server_score_image']=$items[$key]['style']['server_score_image']==self::$base_url . 'image/diy/product/01.png'?'':$items[$key]['style']['server_score_image'];
                //$items[$key]['category']=(new Category())->getALL(['category_type'=>SupplierType::GROUPBUYING]);
            }
        }
        return ['page' => $items['page'], 'items' => $items];
    }
 
    /**
     * 商品组件:获取商品列表
     */
    private function getProductList($user, $item,$city_supplier_ids='')
    {
        // 获取商品数据
        $model = new ProductModel;
        if ($item['params']['source'] === 'choice') {
            // 数据来源:手动
            $productIds = array_column($item['data'], 'product_id');
            $productList = $model->getListByIdsFromApi($productIds, $user);
        } else {
            $list = [];
            // 数据来源:自动
            $productList = $model->getList([
                'type' => 'sell',
                'category_id' => $item['params']['auto']['category'],
                'sortType' => $item['params']['auto']['productSort'],
                'list_rows' => $item['params']['auto']['showNum'],
                'audit_status' => 10,
                'city_supplier_ids' => $city_supplier_ids,
            ], $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'],
                'shop_supplier_id'=>$product['shop_supplier_id'],
            ];
        }
        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 getReleaseList($item,$user=[])
    {
        // 获取数据
        $model = new Project;
        $list = $model->getIndexList($user,$item['params']['auto']['showNum']);
        return $list->isEmpty() ? [] : $list->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 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 getLiveList($item)
    {
        // 获取直播数据
        $model = new RoomModel();
        $liveList = $model->getDiyList($item['params']['showNum']);
        return $liveList->isEmpty() ? [] : $liveList->toArray();
    }
 
    /**
     * 获取限时秒杀
     */
    private function getPreviewList($user, $item)
    {
        // 获取商品数据
        $model = new ProductModel;
        // 数据来源:自动
        $productList = $model->getList([
            'type' => 'preview',
            'list_rows' => $item['params']['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'],
                'preview_time' => $product['preview_time'],
                'is_preview' => $product['is_preview'],
            ];
        }
        return $data;
    }
    public function getSupplierList($item)
    {
        $model = new SupplierModel();
        $list = $model->getList([
            'list_rows' => $item['params']['showNum']
        ]);
        return $list->isEmpty() ? [] : $list->toArray()['data'];
    }
 
    /**
     * 团购组件:获取团购商户列表
     */
    private function getGroupBuyList($user, $item, $city_supplier_ids = '', $latitude = 0, $longitude = 0)
    {
        // 获取团购数据
        $model = new SupplierModel();
        $params = [
            'list_rows' => isset($item['params']['showNum']) ? $item['params']['showNum'] : 10,
            'sortType' => isset($item['params']['merchantSort']) ? $item['params']['merchantSort'] : 'all',
            'product_num' => isset($item['params']['product_num']) ? $item['params']['product_num'] : 3,
            'city_supplier_ids' => $city_supplier_ids,
            'latitude' => $latitude,
            'longitude' => $longitude,
        ];
        
        // 如果有分类筛选
        if (isset($item['params']['category_id']) && $item['params']['category_id']) {
            $params['category_id'] = $item['params']['category_id'];
        }
        
        $list = $model->getGroupBuyList($params);
        return empty($list['data']) ? [] : $list['data'];
    }
}