ctms/ctms-api/controllers/client/v1/StoreController.php
fm453 4b842ebf3d ADD:添加后台管理端接口;
DEL:删除不必要的头部注释;
FIX:修正若干已知错误;
2025-06-30 09:40:13 +08:00

87 lines
2.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace api\controllers\client\v1;
use Yii;
use yii\data\Pagination;
use addons\models\AcStore;
class StoreController extends Common
{
//主界面
public function actionIndex()
{
$apis = [
'list'=>'网点清单',
'detail'=>'网点详情'
];
$this->result('您正使用CMTS系统网点管理接口', $apis, 200);
}
public function actionList()
{
$pid = $this->pid;
$model = new AcStore();
$where = [];
$where['pid'] = $pid;
$citys = Yii::$app->params['citys'];
$post = $this->postdata;
$where['deleted'] = 0;
$where['status_code'] = 1;
$data = $model->find()->where($where);
$page = $this->page;
$pageSize = $this->pageSize;
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => $pageSize]);
$pages->setPage($page-1, true); //设置分页的当前页面值
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
if (!$res) {
$this->result('没有符合条件的结果');
}
$stores = [];
foreach ($res as $k=>$v) {
$stores[$v->id] = $v->toArray();
}
$return = [];
$return['data'] = [
'stores'=>$stores,
'citys'=>$citys,
];
$return['total'] = $data->count();
$return['page'] = $this->page;
$this->result('网点列表', $return, 200);
}
public function actionSelect()
{
$model = new AcStore();
$where = [];
$where['pid'] = Yii::$app->session->get('pid');
$citys = Yii::$app->params['citys'];
$post = Yii::$app->request->post();
$where['deleted'] = 0;
$where['status_code'] = 1;
$data = $model->find()->where($where);
$search = [];
$search['title'] = isset($post['title']) ? trim(htmlspecialchars_decode($post['title'])) : '';
if (!empty($search['title'])) {
$where2 = ['LIKE','title',$search['title']];
$data = $data->andwhere($where2);
}
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => '20']);
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
$status = ['0'=>'隐藏','1'=>'正常'];
$callback = !empty(Yii::$app->request->get('callback')) ? Yii::$app->request->get('callback') : 'store';
return $this->render('select', [
'stores'=>$res,
'pager' => $pages,
'citys'=>$citys,
'status'=>$status,
'search'=>$search,
'callback'=>$callback
]);
}
}