163 lines
8.3 KiB
PHP
Executable File
163 lines
8.3 KiB
PHP
Executable File
<?php
|
|
|
|
namespace app\index\controller;
|
|
|
|
use think\Loader;
|
|
use think\Cookie;
|
|
use think\Config;
|
|
|
|
class Product extends BaseController {
|
|
|
|
public function lists($id = 0) {
|
|
// echo 'asdf';die;
|
|
$category = Loader::model('ProductCategory')->getRow(['stat' => 0, 'pid' => 0], null, ['id' => 'asc']);
|
|
if (empty($category)) {
|
|
return exception('数据有误,请检查后再操作');
|
|
}
|
|
$value = [
|
|
'category' => $category,
|
|
];
|
|
$value['seo_title'] = config('product_seo_title')? : config('website_seo_title');
|
|
$value['seo_keyword'] = config('product_seo_keyword')? : config('website_seo_keyword');
|
|
$value['seo_description'] = config('product_seo_description')? : config('website_seo_description');//print_r($category);die;
|
|
$this->assign($value);
|
|
return $this->fetch('catelists');
|
|
}
|
|
|
|
public function catelists($id = 0) {
|
|
// echo 'asdf';die;
|
|
$arg_where = ['a.siteid' => $this->siteid];
|
|
if ($id > 0) {
|
|
$arg_where['cid'] = $id;
|
|
$category = Loader::model('ProductCategory')->getRow($id);
|
|
}
|
|
if (empty($category)) {
|
|
return exception('数据有误,请检查后再操作');
|
|
}
|
|
switch ($category['classtype']) {
|
|
case 2:
|
|
$template = $category['templist'];
|
|
|
|
// $arg_order = ['a.id' => 'desc'];
|
|
// $arg_field = ['a.*', 'c.id' => 'categoryid', 'c.name' => 'categoryname'];
|
|
// $dataObject = Loader::model('Product')->getCateProductLists($arg_where, $arg_order, $arg_field, 12);
|
|
// $value = [
|
|
// 'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
|
|
// 'page' => $dataObject->render(),
|
|
// ];
|
|
break;
|
|
case 3:
|
|
header('location:' . $category['url']);
|
|
exit;
|
|
break;
|
|
default:
|
|
$template = $category['tempindex'];
|
|
break;
|
|
}
|
|
$value['category'] = $category;
|
|
$value['seo_title'] = $category['seo_title']? : config('website_seo_title');
|
|
$value['seo_keyword'] = $category['seo_keyword']? : config('website_seo_keyword');
|
|
$value['seo_description'] = $category['seo_description']? : config('website_seo_description');
|
|
$this->assign($value);
|
|
return $this->fetch($template);
|
|
}
|
|
|
|
public function subcatelists($id = 0) {
|
|
$arg_where = ['a.siteid' => $this->siteid];
|
|
if ($id > 0) {
|
|
$arg_where['cid'] = $id;
|
|
$category = Loader::model('ProductCategory')->getRow($id);
|
|
}
|
|
if (empty($category)) {
|
|
return exception('数据有误,请检查后再操作');
|
|
}
|
|
switch ($category['classtype']) {
|
|
case 2:
|
|
$template = $category['templist'];
|
|
$subproductCategory = $this->list_to_tree($this->categoryList, 'id', 'pid', 'child', $id);
|
|
$value = ['subproductCategory' => $subproductCategory];
|
|
break;
|
|
case 3:
|
|
header('location:' . $category['url']);
|
|
exit;
|
|
break;
|
|
default:
|
|
$template = $category['tempindex'];
|
|
break;
|
|
}
|
|
$value['category'] = $category;
|
|
$value['seo_title'] = $category['seo_title']? : config('website_seo_title');
|
|
$value['seo_keyword'] = $category['seo_keyword']? : config('website_seo_keyword');
|
|
$value['seo_description'] = $category['seo_description']? : config('website_seo_description');
|
|
$this->assign($value);
|
|
return $this->fetch($template);
|
|
}
|
|
|
|
public function detail($id = 0, $color = '') {
|
|
if ($id > 0) {
|
|
$detail = Loader::model('Product')->getRow($id);
|
|
if (empty($detail)) {
|
|
return exception('数据有误,请检查后再操作');
|
|
}
|
|
$addproduct = Loader::model('ProductAddition')->getRow(['aid' => $detail['id']]); //print_r($addproduct);exit;
|
|
$category = Loader::model('ProductCategory')->getRow($detail['cid']);
|
|
if (empty($category)) {
|
|
return exception('数据有误,请检查后再操作');
|
|
}
|
|
$template = $category['tempdetail'];
|
|
//$prev_detail = Loader::model('Product')->getRow(['id' => ['gt', $id], 'cid' => $category['id'], 'stat' => 0], ['id', 'name'], ['id' => 'asc']);
|
|
//$next_detail = Loader::model('Product')->getRow(['id' => ['lt', $id], 'cid' => $category['id'], 'stat' => 0], ['id', 'name'], ['id' => 'desc']);
|
|
$value = [
|
|
'detail' => $detail,
|
|
'addproduct' => $addproduct,
|
|
'category' => $category,
|
|
//'prev_detail' => $prev_detail,
|
|
//'next_detail' => $next_detail,
|
|
];
|
|
$value['product_images'] = Loader::model('ProductImage')->getList(array('product_id' => $detail['id']), ['image_sort' => 'asc', 'id' => 'asc'], ['id', 'product_id', 'image_url', 'image_sort', 'image_desc', 'image_color']);
|
|
$value['product_dls'] = Loader::model('ProductDl')->getList(array('product_id' => $detail['id']), ['dl_sort' => 'asc', 'id' => 'desc'], ['id', 'product_id', 'dl_url', 'dl_sort', 'dl_name', 'dl_type']);
|
|
$value['product_questions'] = Loader::model('Question')->getList(array('product' => $detail['id']), ['sort' => 'asc', 'id' => 'asc'], ['id', 'name', 'product', 'sort', 'headline', 'recommend', 'description', 'createtime']);
|
|
//$value['product_relates'] = Loader::model('Product')->getList(array('cid' => $detail['cid'], 'id' => ['neq', $detail['id']]), ['sort' => 'asc', 'id' => 'asc'], ['id', 'name', 'shortname', 'picture', 'sort', 'ishot', 'isnew', 'recommend', 'description', 'createtime']);
|
|
$value['product_attrs'] = Loader::model('ProductAttr')->getProductAttrLists(['product_id' => $detail['id']], ['id' => 'desc'], ['pa.id', 'pa.attribute_id', 'pa.value', 'pa.price', 'a.name', 'a.type'], 120);
|
|
$value['product_relateds'] = Loader::model('Product')->getRelatedProductList(array('pr.product_id' => $detail['id']), ['pr.related_sort' => 'asc', 'pr.id' => 'asc',], ['p.id', 'p.name', 'p.shortname', 'p.picture', 'p.sort', 'p.ishot', 'p.isnew', 'p.recommend', 'p.description', 'p.createtime', 'pr.id' => 'related_id', 'pr.related_product_id', 'pr.related_sort', 'pr.related_desc']);
|
|
$value['seo_title'] = $detail['seo_title']? : $detail['name'] . '-' . config('website_seo_title');
|
|
$value['seo_keyword'] = $detail['seo_keyword']? : config('website_seo_keyword');
|
|
$value['seo_description'] = $detail['seo_description']? : config('website_seo_description');
|
|
$value['color'] = $color;
|
|
$this->assign($value);
|
|
$this->viewcount($id);
|
|
return $this->fetch($template);
|
|
} else {
|
|
return exception('数据有误,请检查后再操作');
|
|
}
|
|
}
|
|
|
|
protected function viewcount($id) {
|
|
$view = Cookie::get('productview', 'history'); //print_r($history);exit;
|
|
if (empty($view) || $view != $id) {
|
|
Loader::model('Product')->where(['id' => $id])->setInc('viewcount');
|
|
Cookie::set('productview', $id, ['prefix' => 'history', 'expire' => 3600]);
|
|
}
|
|
}
|
|
|
|
protected function historyproduct($id) {
|
|
$product = Cookie::get('product', 'history'); //print_r($history);exit;
|
|
if (isset($product) && !empty($product)) {
|
|
$product_ids = explode(',', $product);
|
|
if ($product_ids[0] != $id) {
|
|
array_unshift($product_ids, $id);
|
|
$product_ids = array_unique($product_ids);
|
|
$num = Config::get('history_number') > 0 ? Config::get('history_number') : 10;
|
|
//$product_ids = array_slice($product_ids, 0, $num);
|
|
while (count($product_ids) > $num) {
|
|
array_pop($product_ids);
|
|
}
|
|
Cookie::set('product', implode(',', $product_ids), ['prefix' => 'history', 'setcookie' => true, 'expire' => 3600 * 24 * 30]);
|
|
}
|
|
} else {
|
|
Cookie::set('product', $id, ['prefix' => 'history', 'setcookie' => true, 'expire' => 3600 * 24 * 30]);
|
|
}
|
|
}
|
|
|
|
}
|