审查视图

application/home/controller/Collect.php 1.8 KB
王晓刚 authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/10/24
 * Time: 8:44
 */

namespace app\home\controller;


use app\common\controller\WechatBase;
use think\Db;

class Collect extends WechatBase
{
    protected $user_id;
    function _initialize()
    {
        parent::_initialize();
        //判断是否授权
        $user_id = get_current_user_id();
        if(empty($user_id)){
王晓刚 authored
24 25
            $target_url = rawurlencode(url('',false,true));
            $this->redirect('user/authorization_view',array('target_url'=>$target_url));
王晓刚 authored
26 27 28
        }
        $this->user_id = $user_id;
    }
王晓刚 authored
29
王晓刚 authored
30 31 32
    public function index(){
        $data = Db::name('collect')
            ->alias('c')
王晓刚 authored
33
            ->field('g.*,c.id as c_id')
王晓刚 authored
34 35
            ->join('fa_goods g','g.id = c.goods_id')
            ->where(['c.user_id'=>$this->user_id])->order('c.id desc')->page(1,5)->select();
王晓刚 authored
36 37 38
        foreach($data as $key => $vo){
            $data[$key]['end_time'] = date('Y-m-d',$vo['end_time']);
        }
王晓刚 authored
39 40 41 42
        $this->assign('data',$data);
        $this->assign('title','我的收藏');
        return $this->fetch();
    }
王晓刚 authored
43 44 45 46 47 48 49 50 51 52 53 54
    public function more(){
        $user_id = $this->request->param('user_id',0,'intval');
        $page = $this->request->param('page',1,'intval');
        $pageNum = $this->request->param('pageNum',5,'intval');
        if(empty($user_id)){
            $this->error('缺少必要参数');
        }
        $data = Db::name('collect')
            ->alias('c')
            ->field('g.*,c.id as c_id')
            ->join('fa_goods g','g.id = c.goods_id')
            ->where(['c.user_id'=>$user_id])->order('c.id desc')->page($page,$pageNum)->select();
王晓刚 authored
55 56 57
        foreach($data as $key => $vo){
            $data[$key]['end_time'] = date('Y-m-d',$vo['end_time']);
        }
王晓刚 authored
58 59
        $this->success('SUCCESS','',$data);
    }
王晓刚 authored
60
}