Index.php 1.6 KB
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/10/18
 * Time: 11:19
 */
namespace app\home\controller;

use app\common\controller\Frontend;
use think\Controller;
use think\Db;

class Index extends Controller
{
    public function login(){
        $title = "登录";
        $this->assign('title',$title);
        return $this->fetch();
    }
    public function login_verify(){
        $param = $this->request->param();
        if(empty($param['password'])){
            $this->error('404');
        }
        /*$password = Db::name('password')->where(['id'=>1])->value('password');
        if($param['password'] != $password){
            $this->error('密码错误');
        }*/
        $data = Db::name('goods')->where(['password'=>$param['password']])->order('id desc')->find();
        if(empty($data)){
            $this->error('密码错误');
        }
        session("status_$data[id]",1);
        $this->success('SUCCESS','',$data);
    }
    public function index(){
        $goods_id = $this->request->param('goods_id',0,'intval');
        if(empty($goods_id)){
            $this->error('404');
        }
        if(empty(session("status_$goods_id"))){
            $this->redirect('login');
        }
        $data = Db::name('goods')->where(['id'=>$goods_id])->find();
        $data = collection($data)->toArray();
        $images = explode(',',$data['images']);
        foreach($images as $key => $i){
            $images[$key] = request()->domain().$i;
        }
        $data['images'] = $images;
        $this->assign('title',$data['title']);
        $this->assign('data',$data);
        return $this->fetch();
    }
}