CollectController.php 1.3 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.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.post_title,p.more')
            ->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
        ];
        echo json_encode(['data' => $data]);
        exit();
    }

}