Files
ntonpower/app/index/controller/Goods.php
2026-10-14 14:00:29 +08:00

105 lines
3.6 KiB
PHP

<?php
declare(strict_types = 1);
namespace app\index\controller;
use think\facade\Lang;
use think\facade\View;
class Goods extends Base
{
public function initialize()
{
parent::initialize();
$this->model = new \app\index\model\Goods();
}
/**
* 显示资源列表
*/
public function index()
{
$inputData = $this->request->param();
$resource = [];
$query = [];
if (isset($inputData['model_number']) && $inputData['model_number'] != '') {
$query['model_number'] = $inputData['model_number'];
}
//分类
$resource['category'] = $this->model->getFirstLeveCategory($inputData);
$resource['checked1'] = 0;
$resource['url'] = explode('.html', $this->request->query())[0];
if (isset($inputData['cate1']) && $inputData['cate1'] != '') {
$categoryTwo = $this->model->getSecondLevelCategory($inputData);
$resource['category_two'] = $categoryTwo;
$resource['checked2'] = $inputData['cate2']??0;
}
if (isset($inputData['cate2']) && $inputData['cate2'] != '') {
$categoryThree = $this->model->getThreeLevelCategory($inputData);
$resource['category_three'] = $categoryThree;
$resource['checked3'] = $inputData['cate3']??0;
}
$forth = [
'is_all','is_recommend','is_hot','is_new'
];
//
$url = 'index/goods/index?';
for ($i=1;$i<=3;$i++) {
$cate = 'cate'.$i;
if (isset($inputData[$cate]) && $inputData[$cate] != '') {
$url .= http_build_query([$cate =>$inputData[$cate]])."&";
$resource['checked'.$i] = $inputData[$cate];
$resource['url'.$i] = rtrim($url, '&');
$query['cate'.$i] = $inputData[$cate];
}
$resource['url'] = rtrim($url, '&');
}
$resource['checked4'] = '';
foreach ($forth as $fort) {
if (isset($inputData[$fort]) && $inputData[$fort] != '') {
if ($inputData[$fort] == 1) {
$resource['checked4'] = $fort;
$query[$fort] = $inputData[$fort];
}
}
}
// 查询对应的
$goodsPaginate = $this->model->getGoodsList($query, $resource['url']);
//dump($goodsPaginate);
$resource['page'] = $goodsPaginate->render();
$resource['list'] = $goodsPaginate->toArray();
// dump($this->model->getLastSql());
// 增加标签显示
$metaTitle = $this->model->getMetaTitle($this->languageId,'goods_list');
View::assign('meta',$metaTitle);
View::assign('resource', $resource);
return View::fetch(Lang::getLangSet().DIRECTORY_SEPARATOR.'goods/list');
}
/**
* 显示资源列表
*/
public function detail()
{
$inputData = $this->request->param();
$resource = [];
if (isset($inputData['id']) && $inputData['id'] > 0) {
$resource['bread'] = $this->model->getCategoryToParent($inputData['id']);
// dump($resource);
$goodsInfo = $this->model->getInfo($inputData);
$goodsInfo['details'] = htmlspecialchars_decode($goodsInfo['details']);
// dump($goodsInfo);
if (empty($goodsInfo) || $goodsInfo['status'] == 1) {
View::fetch(Lang::getLangSet().DIRECTORY_SEPARATOR.'goods/404');
}
}
$resource['goodsInfo'] = $goodsInfo;
// dump($goodsInfo);
View::assign('resource', $resource);
return View::fetch(Lang::getLangSet().DIRECTORY_SEPARATOR.'goods/detail');
}
}