252 lines
7.8 KiB
PHP
Executable File
252 lines
7.8 KiB
PHP
Executable File
<?php
|
|
|
|
/**
|
|
* @Author: fm453
|
|
* @Date: 2018-08-17 19:39:41
|
|
* @Last Modified by: fm453
|
|
* @Last Modified time: 2021-09-11 07:42:08
|
|
* @Email: fm453@lukegzs.com
|
|
*/
|
|
namespace backend\controllers;
|
|
|
|
use Yii;
|
|
use yii\data\Pagination;
|
|
use yii\helpers\Url;
|
|
use addons\models\AcStore;
|
|
|
|
class StoreController extends \yii\web\Controller
|
|
{
|
|
//替代常规的_construct 析构函数;其他方法调用前执行
|
|
public function init()
|
|
{
|
|
parent::init();
|
|
$session = Yii::$app->session;
|
|
if(isset($_GET['pid']) && (int)$_GET['pid']>0){
|
|
$session->set('pid',(int)$_GET['pid']);
|
|
}
|
|
$pid = $session->get('pid');
|
|
if(!$pid){
|
|
return Yii::$app->response->redirect(['index/index']);
|
|
}
|
|
}
|
|
//主界面
|
|
public function actionIndex()
|
|
{
|
|
return $this->render('../layouts/dev',[]);
|
|
}
|
|
|
|
public function actionList()
|
|
{
|
|
$model = new AcStore();
|
|
$where = [];
|
|
$where['pid'] = Yii::$app->session->get('pid');
|
|
$citys = Yii::$app->params['citys'];
|
|
$post = Yii::$app->request->post();
|
|
|
|
$where['deleted'] = 0;
|
|
$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)->orderby('order_by DESC,id ASC')->all();
|
|
$status = Yii::$app->params['CommonStatus'];
|
|
return $this->render('list',[
|
|
'stores'=>$res,
|
|
'pager' => $pages,
|
|
'citys'=>$citys,
|
|
'status'=>$status,
|
|
'search'=>$search
|
|
]);
|
|
}
|
|
|
|
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)->orderby('order_by DESC,id ASC')->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
|
|
]);
|
|
}
|
|
|
|
public function actionNew()
|
|
{
|
|
return $this->render('modify',[]);
|
|
}
|
|
|
|
public function actionEdit()
|
|
{
|
|
$model = new AcStore();
|
|
$id = Yii::$app->request->get('id');
|
|
$res = $model->find()->where(['id' => $id])->one();
|
|
if($res){
|
|
$res = $res->toArray();
|
|
}
|
|
$citys = Yii::$app->params['citys'];
|
|
$res['city_title'] = isset($citys[$res['city']]['name']) ? $citys[$res['city']]['name'] : '';
|
|
|
|
return $this->render('modify',['detail'=>$res]);
|
|
}
|
|
|
|
public function actionSave()
|
|
{
|
|
$post = Yii::$app->request->post();
|
|
$data = [];
|
|
$data['pid'] = Yii::$app->session->get('pid');
|
|
$id = $post['id'];
|
|
//目标键=》POST键
|
|
$cols = ['title'=>'title','longt'=>'lng','lat'=>'lat','addr'=>'addr'];
|
|
foreach($cols as $col=>$key){
|
|
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
|
|
}
|
|
$cols = ['city'=>'city','order_by'=>'order_by','deleted'=>'deleted'];
|
|
foreach($cols as $col=>$key){
|
|
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
|
|
}
|
|
$data['update_at'] = time();
|
|
$data['create_at'] = time();
|
|
$data['status_code'] = 1;
|
|
|
|
$model = new AcStore();
|
|
foreach($data as $key=>$val){
|
|
$model->$key = $val;
|
|
}
|
|
if($id){
|
|
$model->id = $id;
|
|
$res = $model->updateAll($data,['id'=>$id]);
|
|
}else{
|
|
$res = $model->save();
|
|
$id = $model->attributes['id']; //获取插入后id
|
|
}
|
|
|
|
if($res){
|
|
\Yii::$app->getSession()->setFlash('success', '门店网点保存成功!');
|
|
return $this->redirect(['edit','id'=>$id]);
|
|
}else{
|
|
\Yii::$app->getSession()->setFlash('warning', '门店网点保存失败!');
|
|
return $this->goBack();
|
|
}
|
|
}
|
|
|
|
public function actionDelete()
|
|
{
|
|
$get = Yii::$app->request->get();
|
|
$post = Yii::$app->request->post();
|
|
$id = (int)$get['id'];
|
|
$data = $where = [];
|
|
$where['pid'] = Yii::$app->session->get('pid');
|
|
$where['id'] = $id;
|
|
$data['update_at'] = time();
|
|
$data['deleted'] = 1;
|
|
|
|
$model = new AcStore();
|
|
foreach($data as $key=>$val){
|
|
$model->$key = $val;
|
|
}
|
|
|
|
$model->id = $id;
|
|
$res = $model->updateAll($data,$where);
|
|
|
|
$return = [];
|
|
$return['url'] = Url::toRoute('store/list');
|
|
$return['timeout'] = 3; //3秒后自动跳转
|
|
$return['status'] = 0;
|
|
if($res){
|
|
$return['msg'] = '门店删除成功';
|
|
$return['errorcode'] = 200;
|
|
$return['data'] = $id;
|
|
}else{
|
|
$return['msg'] = '门店删除失败';
|
|
$return['errorcode'] = 0;
|
|
}
|
|
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
|
|
}
|
|
|
|
public function actionAjax()
|
|
{
|
|
$get = Yii::$app->request->get();
|
|
$post = Yii::$app->request->post();
|
|
$id = (int)$get['id'];
|
|
$data = $where = [];
|
|
$where['pid'] = Yii::$app->session->get('pid');
|
|
$where['id'] = $id;
|
|
$data['update_at'] = time();
|
|
|
|
$model = new AcStore();
|
|
$res = $model->find()->where(['id' => $id])->one();
|
|
$return = [];
|
|
$return['timeout'] = 1; //3秒后自动跳转
|
|
$return['status'] = 0;
|
|
$return['ajax'] = 1;
|
|
if($res){
|
|
$res = $res->toArray();
|
|
}else{
|
|
$return['msg'] = '门店数据不存在';
|
|
$return['errorcode'] = 404;
|
|
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
|
|
}
|
|
|
|
switch($get['do'])
|
|
{
|
|
case 'hide':
|
|
$data['status_code'] = 0;
|
|
$model->id = $id;
|
|
$res = $model->updateAll($data,$where);
|
|
if($res){
|
|
$return['msg'] = '门店隐藏成功';
|
|
$return['errorcode'] = 200;
|
|
$return['data'] = ['css'=>'info'];
|
|
}else{
|
|
$return['msg'] = '门店隐藏失败';
|
|
$return['errorcode'] = 0;
|
|
}
|
|
break;
|
|
case 'show':
|
|
$data['status_code'] = 1;
|
|
$model->id = $id;
|
|
$res = $model->updateAll($data,$where);
|
|
if($res){
|
|
$return['msg'] = '门店显示成功';
|
|
$return['errorcode'] = 200;
|
|
$return['data'] = ['css'=>'default'];
|
|
}else{
|
|
$return['msg'] = '门店显示失败';
|
|
$return['errorcode'] = 0;
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
exit(json_encode($return,JSON_UNESCAPED_UNICODE));
|
|
}
|
|
|
|
}
|