2019-09-06 23:53:10 +08:00

76 lines
2.3 KiB
PHP
Executable File

<?php
namespace wstmart\mobile\controller;
//use wstmart\common\model\Demo as M;
//use think\Loader;
//use think\Db;
//require_once(ROOT_PATH.'../php/lib/XS.php');
/**
* ============================================================================
* 地区控制器
*/
class Demo extends Base{
/**
* 列表查询
*/
public function index(){
//Loader::import ( 'php.lib.XS' );
$xs = new \XS('goods');
//$doc = new \XSDocument; // 自动使用 $prefix/sdk/php/app/demo.ini 作项目配置文件
$data = array(
'goodsId' => 6666667, // 此字段为主键,是进行文档替换的唯一标识
'goodsName' => '测鞋子的标题'
);
//$doc->setFields($data);
// $index = $xs->index; // 获取 索引对象
// //$index->del(array('6666666', '6666667')); // 同时删除主键值为 123, 789, 456 的记录
// //添加到索引数据库中
// $index->add($doc);
// // 创建文档对象
// $xs = new \XS('goods');
// $info = $xs->search->search('苹果');
// //echo $info->goodsName;
// //dump($info);
// foreach ($info as $key => $v) {
// $data[$key]['goodsId'] = $v['goodsId'];
// $data[$key]['goodsName'] = $v['goodsName'];
// }
//dump($data);
}
public function search(){
//'select * form hyh_ads a where a.adPositionId in (select positionId from hyh_ad_positions where positionCode='mo-ads-index' ) '
//$ads_list = Db::name('ads')->where(['adPositionId'=>291,'dataFlag'=>1])->order('adSort asc')->select();
//dump($ads_list);
//$m = new Demo();
//$brand_list = $m->getBrandList();
//dump($brand_list);
$keyword = input('keyword');
$shopId = (int)input('shopId');
//$xs = new \XS('goods');
$search = 'goodsName:'.$keyword;
if($shopId){
$search.=' goodsId:'.$shopId;
}
$info = $xs->search->getField('goodsId')->search($search);
//$info = $xs->search->search($keyword);
foreach ($info as $key => $v) {//把返回的数据转换为数组
$data[$key]['goodsId'] = $v['goodsId'];
$data[$key]['goodsName'] = $v['goodsName'];
}
if($data){
exit(jsonReturn('调用成功',1,$data));
}
exit(jsonReturn('调用失败',-1));
}
// public function getBrandList(){
// return Db::name('brands')->where('dataFlag=1')->select();
// }
}