CollectController.php 1.6 KB
<?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')
            ->field('a.id,a.name,a.thumb')
            ->join('activity a', 'a.id=c.activity_id')
            ->where(['c.user_id' => session('user.id')])
            ->select();
        $news = Db::name('collect_news')->alias('c')
            ->field('p.id,p.post_title,p.more,p.post_hits')
            ->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
        ];
        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
            ]);
        }
    }

}