123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?php
- namespace backend\controllers;
- use backend\base\CommonController;
- use backend\base\Help;
- use common\models\TestNumber;
- use Yii;
- class TestnumberController extends CommonController
- {
- /**
- * 测试号码 - 页面
- * @return string
- */
- public function actionIndex()
- {
- return $this->render($this->action->id);
- }
- /**
- * 测试号码 - 数据
- * @return mixed
- */
- public function actionIndexform()
- {
- $input = Yii::$app->request->post();
- $model = new TestNumber();
- $list = $model->getList($input);
- if ($list) {
- foreach ($list as &$val) {
- $val['create_at'] = date('Y-m-d H:i:s', $val['create_at']);
- }
- return Help::JsonData(0, '获取数据成功', $model->total($input), $list);
- }
- return Help::JsonCode(Help::ERROR, '获取数据失败');
- }
- /**
- * 测试号码 - 添加页面
- * @return string
- */
- public function actionAdd()
- {
- return $this->render($this->action->id);
- }
- /**
- * 测试号码 - 添加数据
- * @return mixed
- */
- public function actionAddform()
- {
- $input = Yii::$app->request->post();
- $model = new TestNumber();
- $model->scenario = 'add';
- if (is_object($model)) {
- if ($model->load($input, '') && $model->save()) return Help::JsonCode(Help::SUCCESS, '添加成功');
- }
- return Help::JsonCode(Help::ERROR, '添加失败', $model->errors);
- }
- /**
- * 测试号码 - 编辑页面
- * @return string
- */
- public function actionEdit()
- {
- $row = TestNumber::findOne(Yii::$app->request->get('id'));
- if ($row != null) {
- return $this->render($this->action->id, ['row' => $row]);
- }
- }
- /**
- * 测试号码 - 编辑数据
- * @return mixed
- */
- public function actionEditform()
- {
- $input = Yii::$app->request->post();
- $row = TestNumber::findOne($input['id']);
- $row->scenario = 'edit';
- if ($row != null) {
- $row->load($input, '');
- if ($row->save()) return Help::JsonCode(Help::SUCCESS, '修改成功');
- }
- return Help::JsonCode(Help::ERROR, '修改失败', $row->errors);
- }
- /**
- * 测试号码 - 审核&删除
- * @return mixed
- * @throws \Throwable
- * @throws \yii\db\StaleObjectException
- */
- public function actionSetnumber()
- {
- $input = Yii::$app->request->post();
- $row = TestNumber::findOne($input['id']);
- if ($row != null) {
- switch ($input['type']) {
- case 'show':
- if ($row->is_show == 1) {
- $row->is_show = 2;
- } else {
- $row->is_show = 1;
- }
- break;
- case 'del':
- if ($row->delete()) {
- return Help::JsonCode(Help::SUCCESS, '删除成功');
- }
- break;
- }
- if ($row->save(false)) return Help::JsonCode(Help::SUCCESS, '操作成功');
- }
- return Help::JsonCode(Help::ERROR, '操作失败');
- }
- }
|