You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
simple-yewu/frontend/controllers/WorkDayController.php

106 lines
2.4 KiB

5 years ago
<?php
namespace frontend\controllers;
use common\libs\MyLib;
use common\models\WorkDayT;
use Yii;
use yii\web\Controller;
use yii\data\Pagination;
use yii\web\Response;
class WorkDayController extends Controller
{
public $result = [
'success' => false,
'msg' => '操作失败'
];
public function actionIndex()
{
$request = Yii::$app->request;
$page = $request->get('page', 1);
$date = $request->get('date');
$query = WorkDayT::find();
if($date != '')
$query = $query->andWhere(['date' => $date]);
$query = $query->orderBy('date DESC');
$total = $query->count();
$pagination = new Pagination(['totalCount' => $total,'pageSize'=>20]);
$pagination->setPage($page-1);
$query = $query->offset($pagination->offset)->limit($pagination->limit);
$items = $query->all();
$page_info = MyLib::getPageInfo($pagination);
return $this->render('index',[
'page' => $page,
'items' => $items,
'page_info' => $page_info
]);
}
/**
* 添加 保存
* xzz
* 2018-01-03
*/
public function actionEdit()
{
$request = Yii::$app->request;
$id = $request->get('id', 0);
$back_params = $request->get('back_params');
if($id > 0)
$query = WorkDayT::findOne(['id' => $id]);
else
$query = new WorkDayT();
return $this->render('edit', [
'back_params' => $back_params,
'info' => $query,
'id' => $id
]);
}
/**
* 保存修改
* xzz
* 2018-01-03
*/
public function actionSave()
{
Yii::$app->response->format = Response::FORMAT_JSON;
$request = Yii::$app->request;
$id = $request->post('id', 0);
$date = $request->post('date');
$double_break = $request->post('double_break');
$single_break = $request->post('single_break');
if($id > 0)
$query = WorkDayT::findOne(['id' => $id]);
else
$query = new WorkDayT();
$query->date = $date;
$query->double_break = $double_break;
$query->single_break = $single_break;
if($query->save()){
$this->result = [
'success' => true,
'msg' => '操作成功'
];
}
return $this->result;
}
}