<?php
/**
* @author 龙虾 <15108148@qq.com>
* @version 2.0 2020-11-11
* @copyright 睿谷信息 <www.rgxx.com>
*/
namespace app\user\controller;

use app\common\model\Cmsmodels;
use app\common\model\User;
use Request;
use Db;

class Mylike extends Base
{
	protected function initialize()
    {
        parent::initialize();
        if(!isInstall('mylike')) $this->error('请先安装插件');
    }
	// 地址首页
	public function index($model='product')
	{
		$pagetitle = '我的赞踩';
		$config = get_addons_config('mylike',true);
		$mlist= Cmsmodels::whereType(1)->select();
		$modelinfo = $mlist->where('name','eq',$model)->shift();
		$modelname = $modelinfo['name'];
		$likeList = Db::name('mylike')->whereUserId(session('userid'))->whereCmsmodelsId($modelinfo['id'])->withAttr('cinfo',function($value,$data)use($modelinfo){
			$class = '\\app\\common\\model\\'.$modelinfo['classname'];
			return (new $class)->whereId($data['cid'])->find();
		})->order('create_time desc')->paginate(8,false,["type" => "rg\Page","var_page"  => "p","path" => "","query" => getparam()]);
		$page = $likeList->pageArray();
		$likeList = $likeList->toArray()["data"];
		return $this->fetch('',compact('pagetitle','likeList','modelname','mlist','config','page'));
	}
}