审查视图

app/collect/controller/CollectController.php 1.6 KB
.  
lihan authored
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
<?php
/**
 * Created by PhpStorm.
 * User: yhbr
 * Date: 2018/9/12
 * Time: 15:17
 */
namespace app\collect\controller;
use cmf\controller\HomeBaseController;
use Think\Db;

/**
 * @title 收藏模块
 */
class CollectController extends HomeBaseController
{
    /**
     * @title 我的收藏列表
     * @description 接口说明
     * @author sᴏᴜʟ ᴏғ ᴄɪɴᴅᴇʀ
     * @url /collect/Collect/index
     * @method POST
     */
    public function index()
    {
        //收藏的活动
        $activity = Db::name('collect')->alias('c')
lihan authored
28
            ->field('a.id,a.name,a.thumb')
.  
lihan authored
29 30 31 32
            ->join('activity a', 'a.id=c.activity_id')
            ->where(['c.user_id' => session('user.id')])
            ->select();
        $news = Db::name('collect_news')->alias('c')
lihan authored
33
            ->field('p.id,p.post_title,p.more,p.post_hits')
.  
lihan authored
34 35 36 37 38 39 40 41 42 43 44 45 46
            ->join('portal_post p', 'p.id=c.post_id')
            ->where(['c.user_id' => session('user.id')])
            ->select();
        foreach ($news as $k => $v) {
            $temp = json_decode($v['more'], true);
            $v['thumb'] = cmf_get_image_url($temp['thumbnail']);
            unset($v['more']);
            $news[$k] = $v;
        }
        $data = [
            'activity' => $activity,
            'news' => $news
        ];
lihan authored
47 48 49 50 51 52 53 54 55 56 57 58 59
        if (request()->isPost()) {
            echo json_encode(['data' => $data]);
            exit();
        } else {
            if (request()->param('is_news') == 1) {
                $view = ':collect2';
            } else {
                $view = ':collect';
            }
            return $this->fetch($view, [
                'data' => $data
            ]);
        }
.  
lihan authored
60 61 62
    }

}