陈家兴
4 years ago
1 changed files with 97 additions and 0 deletions
@ -0,0 +1,97 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* @author Administrator |
||||
|
* @date 2021/2/25 10:15 |
||||
|
*/ |
||||
|
|
||||
|
|
||||
|
namespace Api\Controller; |
||||
|
|
||||
|
use Api\Model\CatalogModel; |
||||
|
use Api\Model\ItemModel; |
||||
|
use Api\Model\PageModel; |
||||
|
|
||||
|
/** |
||||
|
* 智能场馆帮助中心 |
||||
|
* Class HelpController |
||||
|
* @package Api\Controller |
||||
|
*/ |
||||
|
class HelpController extends BaseController |
||||
|
{ |
||||
|
/** |
||||
|
* 获取所有公开项目 |
||||
|
*/ |
||||
|
public function getItemList() |
||||
|
{ |
||||
|
$w = array("password" => "", 'is_del' => 0); |
||||
|
$items = D("item")->where($w) |
||||
|
->order("addtime desc") |
||||
|
->field(array( |
||||
|
'item_id', |
||||
|
'item_name', |
||||
|
'item_description', |
||||
|
'addtime', |
||||
|
'item_type', |
||||
|
'is_del', |
||||
|
)) |
||||
|
->select(); |
||||
|
$total = D("item")->where($w)->count(); |
||||
|
$this->sendResult(array("items" => $items, "total" => $total)); |
||||
|
} |
||||
|
|
||||
|
//展示 页面列表
|
||||
|
public function search($keyword = "") |
||||
|
{ |
||||
|
//获取公开的项目id
|
||||
|
$item_model = D("item"); |
||||
|
// $item_ids = $item_model->where(array("password" => "", "is_del" => 0))->getField("item_id", true);
|
||||
|
$item_data = $this->getItems(); |
||||
|
$item_ids = array_keys($item_data); |
||||
|
|
||||
|
if (count($item_ids) <= 0) { |
||||
|
$this->sendResult(array("items" => null, "total" => 0)); |
||||
|
} |
||||
|
|
||||
|
$w = array("item_id" => array("in", $item_ids), 'is_del' => 0); |
||||
|
|
||||
|
if (trim($keyword)) { |
||||
|
$w["page_title|page_content"] = array("like", "%{$keyword}%"); |
||||
|
} |
||||
|
|
||||
|
$page_m = D("page"); |
||||
|
$t = $page_m->where($w)->field("page_id,page_title,item_id"); |
||||
|
$page = $_REQUEST['page']; |
||||
|
$page_size = $_REQUEST['page_size']; |
||||
|
if ($page > 0 && $page_size > 0) { |
||||
|
$t->page($page, $page_size); |
||||
|
} |
||||
|
$list = $t->order("addtime desc")->select(); |
||||
|
$total = $page_m->where($w)->count(); |
||||
|
|
||||
|
|
||||
|
foreach ($list as &$item) { |
||||
|
//项目数据
|
||||
|
$item['item_data'] = $item_data[$item['item_id']]; |
||||
|
$item['item_cat'] = $item['item_data']['item_cat']; |
||||
|
} |
||||
|
$this->sendResult(array("items" => $list, "total" => $total)); |
||||
|
} |
||||
|
|
||||
|
protected function getItems() |
||||
|
{ |
||||
|
$item_data = D('item')->where(array('is_del' => 0, 'password' => ''))->getField('item_id,item_name,is_del'); |
||||
|
foreach ($item_data as &$item) { |
||||
|
$cat_arr = D('catalog') |
||||
|
->where(array('item_id' => $item['item_id'])) |
||||
|
->order("level asc,addtime asc") |
||||
|
->getField('cat_name', true); |
||||
|
if (count($cat_arr) > 0) { |
||||
|
$item['item_cat'] = $item['item_name'] . '-' . implode('-', $cat_arr); |
||||
|
} else { |
||||
|
$item['item_cat'] = $item['item_name']; |
||||
|
} |
||||
|
} |
||||
|
return $item_data; |
||||
|
} |
||||
|
} |
||||
|
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue