63 行
1.6 KiB
PHP
63 行
1.6 KiB
PHP
<?php
|
|
|
|
namespace app\admin\controller\service;
|
|
|
|
use app\common\controller\Backend;
|
|
use think\Db;
|
|
|
|
/**
|
|
* 服务类目
|
|
*
|
|
* @icon fa fa-th-large
|
|
*/
|
|
class Cat extends Backend
|
|
{
|
|
/**
|
|
* Cat模型对象
|
|
* @var \app\admin\model\service\Cat
|
|
*/
|
|
protected $model = null;
|
|
|
|
public function _initialize()
|
|
{
|
|
parent::_initialize();
|
|
$this->model = new \app\admin\model\service\Cat;
|
|
$this->view->assign("statusList", $this->model->getStatusList());
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$this->request->filter(['strip_tags', 'trim']);
|
|
if (false === $this->request->isAjax()) {
|
|
return $this->view->fetch();
|
|
}
|
|
if ($this->request->request('keyField')) {
|
|
return $this->selectpage();
|
|
}
|
|
[$where, $sort, $order, $offset, $limit] = $this->buildparams();
|
|
$list = $this->model
|
|
->where($where)
|
|
->order($sort, $order)
|
|
->paginate($limit);
|
|
|
|
$rows = $list->items();
|
|
if (!empty($rows)) {
|
|
$catCountRows = Db::name('service')
|
|
->field('cat_id, count(id) as cnt')
|
|
->group('cat_id')
|
|
->select();
|
|
$catCounts = [];
|
|
foreach ($catCountRows as $cr) {
|
|
$catCounts[(int)$cr['cat_id']] = (int)$cr['cnt'];
|
|
}
|
|
foreach ($rows as &$r) {
|
|
$cid = (int)$r['id'];
|
|
$r['goods_count'] = isset($catCounts[$cid]) ? (int)$catCounts[$cid] : 0;
|
|
}
|
|
unset($r);
|
|
}
|
|
|
|
return json(['total' => $list->total(), 'rows' => $rows]);
|
|
}
|
|
}
|