Blame view

yohobuy/m.yohobuy.com/application/modules/Product/controllers/Recom.php 5.49 KB
1 2 3 4
<?php

use Action\AbstractAction;
use LibModels\Wap\Product\RecomData;
hf authored
5
use Plugin\Helpers;
6 7

/**
hf authored
8
 * 推荐相关的控制器
9 10 11 12 13
 */
class RecomController extends AbstractAction
{

    /**
hf authored
14
     * 你可能喜欢的BOYS或GIRLS的商品列表
15
     * 
hf authored
16 17 18
     * @param string gender 1,3表示男, 2,3表示女
     * @param int page 分页的页码
     * @return html
19 20 21
     */
    public function maylikeAction()
    {
hf authored
22
        do {
hf authored
23 24 25 26
            /* 判断是否是AJAX请求 */
            if (!$this->isAjax()) {
                break;
            }
hf authored
27 28 29 30 31 32 33 34 35

            /* 判断分页参数是否有效 */
            $page = $this->get('page', 1);
            if (!is_numeric($page)) {
                break;
            }

            /* 取可能喜欢的数据 */
            $recom = array();
36
            $gender = $this->get('gender', '1,3');
hf authored
37 38
            // 女
            if ($gender === '2,3') {
hf authored
39
                $recom = RecomData::mayLike('2,3', 2, $page);
hf authored
40 41 42
            }
            // 男
            else {
hf authored
43
                $recom = RecomData::mayLike('1,3', 1, $page);
hf authored
44 45 46 47 48 49
            }

            /* 判断是否有内容返回 */
            if (empty($recom['data']['product_list'])) {
                break;
            }
50 51

            /* 判断是否已没有数据 */
hf authored
52 53 54
            if (intval($page) > intval($recom['data']['page_total'])) {
                break;
            }
hf authored
55 56 57 58

            /* 构建商品数据 */
            $data = array();
            foreach ($recom['data']['product_list'] as $value) {
hf authored
59
                $data['goods'][] = Helpers::formatProduct($value, true, true, true, 276, 366);
hf authored
60
            }
hf authored
61
        } while (false);
hf authored
62
63 64 65 66 67
        if (isset($data)) {
            $this->_view->display('maylike', $data);
        } else {
            echo ' ';
        }
hf authored
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
    }

    /**
     * 你可能喜欢的潮童的商品列表
     * 
     * @param int page 分页的页码
     * @return html
     */
    public function maylikeKidsAction()
    {
        do {
            /* 判断是否是AJAX请求 */
            if (!$this->isAjax()) {
                break;
            }

            /* 判断分页参数是否有效 */
            $page = $this->get('page', 1);
            if (!is_numeric($page)) {
                break;
            }

            /* 取可能喜欢的数据 */
hf authored
91
            $recom = RecomData::mayLikeKids($page);
hf authored
92 93 94 95
            if (empty($recom['data']['product_list'])) {
                break;
            }
hf authored
96 97 98 99 100
            /* 判断是否已没有数据 */
            if (intval($page) > intval($recom['data']['page_total'])) {
                break;
            }
hf authored
101 102 103 104 105
            /* 构建模板需要的商品数据 */
            $data = array();
            foreach ($recom['data']['product_list'] as $value) {
                $data['goods'][] = Helpers::formatProduct($value, true);
            }
hf authored
106
        } while (false);
hf authored
107
108 109 110 111 112
        if (isset($data)) {
            $this->_view->display('maylike', $data);
        } else {
            echo ' ';
        }
113 114
    }
hf authored
115 116 117 118 119 120 121 122 123 124 125 126
    /**
     * 你可能喜欢的创意生活的新品到着和人气单品列表
     * 
     * @return html
     */
    public function maylikeLifeAction()
    {
        do {
            /* 判断是否是AJAX请求 */
            if (!$this->isAjax()) {
                break;
            }
127
128 129 130 131
            /* 创意生活只有一页数据 */
            $page = $this->get('page', 1);
            if (intval($page) > 1) {
                break;
132
            }
hf authored
133 134 135

            /* 取可能喜欢的数据 */
            $recom = RecomData::mayLikeLifestyle();
136
137 138
            /* 构建人气单品数据 */
            if (empty($recom['top']['data']['product_list'])) {
hf authored
139 140
                break;
            }
141
hf authored
142 143
            $data = array();
            $build = array();
144 145 146
            $build['show'] = true;
            foreach ($recom['top']['data']['product_list'] as $value) {
                $build['goods'][] = Helpers::formatProduct($value, true, false, false);
hf authored
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
            $data['goodsContainer'][] = $build;

            /* 构建新品到着数据 */
            if (empty($recom['new']['data']['product_list'])) {
                break;
            }
            $build = array();
            $build['show'] = true;
            foreach ($recom['new']['data']['product_list'] as $value) {
                $build['goods'][] = Helpers::formatProduct($value, true, false, false);
            }
            $data['goodsContainer'][] = $build;

//            if (empty($recom['data']['product_list'])) {
//                break;
//            }
//
//            /* 构建模板需要的商品数据 */
//            $data = array();
//            $build = array();
//            if (!empty($recom['data']['product_list']['top'])) {
//                $build = array();
//                $build['show'] = true;
//                foreach ($recom['data']['product_list']['top'] as $value) {
//                    $build['goods'][] = Helpers::formatProduct($value, true);
//                }
//                $data['goodsContainer'][] = $build;
//            }
//            if (!empty($recom['data']['product_list']['new'])) {
//                $build = array();
//                foreach ($recom['data']['product_list']['new'] as $value) {
//                    $build['show'] = false;
//                    $build['goods'][] = Helpers::formatProduct($value, true);
//                }
//                $data['goodsContainer'][] = $build;
//            }
hf authored
184
        } while (false);
hf authored
185
186 187 188 189 190
        if (isset($data)) {
            $this->_view->display('maylikelife', $data);
        } else {
            echo ' ';
        }
hf authored
191 192
    }
193
}