# @Date: 2022-05-16T16:31:49+08:00 # @Email: fm453@lukegzs.com # @Last modified by: fm453 # @Last modified time: 2024-06-29T15:44:54+08:00 # @Copyright: www.hiluker.cn namespace backend\controllers; use Yii; use yii\data\Pagination; use yii\helpers\Url; 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 ]); } }