public function actionLoadGoods($id, $category = 'all', $q = '')
{
$offset = (int) Yii::$app->request->post('offset');
Yii::$app->response->format = Response::FORMAT_JSON;
/* @var $model Store */
$model = Store::findOne(['id' => $id, 'status' => [Store::STATUS_ACTIVE, Store::STATUS_REST]]);
if (!$model) {
throw new NotFoundHttpException('未找到该营业点!');
}
if ($q !== '') {
$query = $model->getGoods()->andWhere(['or', ['like', 'name', $q], ['like', 'description', $q]]);
} else {
$modelCate = $category === 'all' ? null : Category::findOne(['slug' => $category]);
if ($modelCate) {
$query = $model->getGoods($modelCate->id);
} else {
$query = $model->getGoods();
}
}
$limit = 8;
$goodsList = $query->offset($offset)->limit($limit)->all();
$output = ['status' => 'ok', 'html' => '', 'length' => count($goodsList)];
$output['end'] = $output['length'] < $limit;
foreach ($goodsList as $goods) {
$output['html'] .= $this->renderPartial('_item', ['goods' => $goods, 'lazy' => false]);
}
return $output;
}