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/MarketingStrategyController...

107 lines
3.0 KiB

<?php
namespace frontend\controllers;
use common\models\ZhongjiYingxiao;
use yii\web\Response;
use Yii;
class MarketingStrategyController extends UserBaseController
{
public $enableCsrfValidation = false;
public $layout = 'blue-main';
public function actionIndex() {
return $this->render('index');
}
public function actionIndexJson() {
Yii::$app->response->format = Response::FORMAT_JSON;
$request = Yii::$app->request;
$offset = $request->get('offset',0);
$limit = $request->get('limit', 10);
$query = ZhongjiYingxiao::find()
->where('is_delete=0')
->orderBy('id desc');
$total = $query->count();
$query = $query->offset($offset)->limit($limit);
$items = $query->all();
$data = [];
$data['total'] = $total;
$data['rows'] = [];
foreach($items as $item) {
$row = $item->toArray();
$data['rows'][] = $row;
}
return $data;
}
public function actionAdd() {
return $this->render('add');
}
public function actionEdit() {
$request = Yii::$app->request;
$id = $request->get('id');
$info = ZhongjiYingxiao::findOne(['id'=>$id]);
return $this->render('edit', [
'info' => $info
]);
}
public function actionSave() {
Yii::$app->response->format = Response::FORMAT_JSON;
$request = Yii::$app->request;
$result = array();
$result['success'] = false;
$result['msg'] = '保存失败';
if($request->isPost) {
$op = $request->post('op', 'add');
$name = $request->post('name');
$begin_date = $request->post('begin_date');
$begin_time = $request->post('begin_time');
$end_date = $request->post('end_date');
$end_time = $request->post('end_time');
$remark = $request->post('remark');
if($op == 'add') {
$item = new ZhongjiYingxiao();
$item->celuo_name = $name;
$item->begin_date = $begin_date.' '.$begin_time.':00';
$item->end_date = $end_date.' '.$end_time.':00';
$item->is_delete = 0;
$item->remark = $remark;
$item->save();
$result['success'] = true;
$result['msg'] = '保存成功';
return $result;
} else {
$id = $request->post('id');
$item = ZhongjiYingxiao::findOne(['id'=>$id]);
if($item) {
$item->celuo_name = $name;
$item->begin_date = $begin_date.' '.$begin_time.':00';
$item->end_date = $end_date.' '.$end_time.':00';
$item->remark = $remark;
$item->save();
$result['success'] = true;
$result['msg'] = '保存成功';
return $result;
}
}
}
return $result;
}
}