TestnumberController.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. namespace backend\controllers;
  3. use backend\base\CommonController;
  4. use backend\base\Help;
  5. use common\models\TestNumber;
  6. use Yii;
  7. class TestnumberController extends CommonController
  8. {
  9. /**
  10. * 测试号码 - 页面
  11. * @return string
  12. */
  13. public function actionIndex()
  14. {
  15. return $this->render($this->action->id);
  16. }
  17. /**
  18. * 测试号码 - 数据
  19. * @return mixed
  20. */
  21. public function actionIndexform()
  22. {
  23. $input = Yii::$app->request->post();
  24. $model = new TestNumber();
  25. $list = $model->getList($input);
  26. if ($list) {
  27. foreach ($list as &$val) {
  28. $val['create_at'] = date('Y-m-d H:i:s', $val['create_at']);
  29. }
  30. return Help::JsonData(0, '获取数据成功', $model->total($input), $list);
  31. }
  32. return Help::JsonCode(Help::ERROR, '获取数据失败');
  33. }
  34. /**
  35. * 测试号码 - 添加页面
  36. * @return string
  37. */
  38. public function actionAdd()
  39. {
  40. return $this->render($this->action->id);
  41. }
  42. /**
  43. * 测试号码 - 添加数据
  44. * @return mixed
  45. */
  46. public function actionAddform()
  47. {
  48. $input = Yii::$app->request->post();
  49. $model = new TestNumber();
  50. $model->scenario = 'add';
  51. if (is_object($model)) {
  52. if ($model->load($input, '') && $model->save()) return Help::JsonCode(Help::SUCCESS, '添加成功');
  53. }
  54. return Help::JsonCode(Help::ERROR, '添加失败', $model->errors);
  55. }
  56. /**
  57. * 测试号码 - 编辑页面
  58. * @return string
  59. */
  60. public function actionEdit()
  61. {
  62. $row = TestNumber::findOne(Yii::$app->request->get('id'));
  63. if ($row != null) {
  64. return $this->render($this->action->id, ['row' => $row]);
  65. }
  66. }
  67. /**
  68. * 测试号码 - 编辑数据
  69. * @return mixed
  70. */
  71. public function actionEditform()
  72. {
  73. $input = Yii::$app->request->post();
  74. $row = TestNumber::findOne($input['id']);
  75. $row->scenario = 'edit';
  76. if ($row != null) {
  77. $row->load($input, '');
  78. if ($row->save()) return Help::JsonCode(Help::SUCCESS, '修改成功');
  79. }
  80. return Help::JsonCode(Help::ERROR, '修改失败', $row->errors);
  81. }
  82. /**
  83. * 测试号码 - 审核&删除
  84. * @return mixed
  85. * @throws \Throwable
  86. * @throws \yii\db\StaleObjectException
  87. */
  88. public function actionSetnumber()
  89. {
  90. $input = Yii::$app->request->post();
  91. $row = TestNumber::findOne($input['id']);
  92. if ($row != null) {
  93. switch ($input['type']) {
  94. case 'show':
  95. if ($row->is_show == 1) {
  96. $row->is_show = 2;
  97. } else {
  98. $row->is_show = 1;
  99. }
  100. break;
  101. case 'del':
  102. if ($row->delete()) {
  103. return Help::JsonCode(Help::SUCCESS, '删除成功');
  104. }
  105. break;
  106. }
  107. if ($row->save(false)) return Help::JsonCode(Help::SUCCESS, '操作成功');
  108. }
  109. return Help::JsonCode(Help::ERROR, '操作失败');
  110. }
  111. }