init
This commit is contained in:
56
app/vn/controller/Search.php
Executable file
56
app/vn/controller/Search.php
Executable file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace app\vn\controller;
|
||||
|
||||
use think\Loader;
|
||||
use think\Config;
|
||||
use think\Db;
|
||||
|
||||
class Search extends BaseController {
|
||||
|
||||
public function index() {
|
||||
$skeyword = $this->request->get('skeyword', '', 'urldecode,strval');
|
||||
|
||||
$search = [];
|
||||
$name_word = '';
|
||||
$brand_word = '';
|
||||
if ($skeyword != '') {
|
||||
$skeyword = trim($skeyword);
|
||||
$search['skeyword'] = $skeyword;
|
||||
|
||||
$pos = strpos($skeyword, '(');
|
||||
if ($pos === false) {
|
||||
$name_word = $brand_word = $skeyword;
|
||||
} else {
|
||||
$name_word = substr($skeyword, 0, $pos);
|
||||
$brand_word = substr($skeyword, $pos+1, -1);
|
||||
}
|
||||
|
||||
$arg_where = [
|
||||
'a.name|a.brand_id|a.keyword|b.sku' => ['like', '%' . $name_word . '%']
|
||||
];
|
||||
|
||||
Config::set('paginate.query', ['skeyword' => $skeyword]);
|
||||
}
|
||||
$arg_where['a.stat'] = 0;
|
||||
// $arg_where['b.stat'] = 0;
|
||||
$arg_where['a.country_code'] = $this->country_code;
|
||||
$arg_where['a.is_show'] = 0;
|
||||
|
||||
$field = ['a.id', 'a.name', 'a.description', 'a.list_bk_img' => 'picture', 'a.createtime','a.brand_id', 'b.sku', "'productdetail'" => 'link'];
|
||||
$dataObject = model('product')->alias('a')->join('product_sku b', 'a.brand_id=b.brand_id', 'LEFT')->field($field)->where($arg_where)->group('a.id')->paginate(12);
|
||||
|
||||
// echo \think\Db::table('product')->getlastSql();die;
|
||||
$value = [
|
||||
'list' => $dataObject->isEmpty() ? null : $dataObject->items(),
|
||||
'page' => $dataObject->render(),
|
||||
];
|
||||
$value['search'] = $search;
|
||||
$value['name_word'] = $name_word;
|
||||
$value['brand_word'] = $brand_word;
|
||||
$this->assign($value);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user