PushaController.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace backend\controllers;
  3. use backend\base\CommonController;
  4. use backend\base\Help;
  5. use common\models\PushDiscount;
  6. use Yii;
  7. class PushaController extends CommonController
  8. {
  9. /**
  10. * PC列表页-优惠推荐&品质美宅
  11. * @return string
  12. */
  13. public function actionIndex()
  14. {
  15. return $this->render($this->action->id, ['type' => \Yii::$app->request->get('type')]);
  16. }
  17. /**
  18. * PC列表页-优惠推荐&品质美宅
  19. * @return mixed
  20. */
  21. public function actionIndexform()
  22. {
  23. $post = Yii::$app->request->post();
  24. $model = new PushDiscount();
  25. $list = $model->getList($post);
  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->countList($post), $list);
  31. }
  32. return Help::JsonCode(Help::ERROR, '获取数据失败');
  33. }
  34. /**
  35. * 添加&编辑页面
  36. * @return string
  37. */
  38. public function actionEdit()
  39. {
  40. if (!empty(Yii::$app->request->get('status')) && Yii::$app->request->get('status') == 'edit') {
  41. $row = PushDiscount::findOne(Yii::$app->request->get('id'));
  42. if ($row) {
  43. return $this->render($this->action->id, ['row' => $row]);
  44. }
  45. }
  46. return $this->render($this->action->id);
  47. }
  48. /**
  49. * 添加&编辑数据
  50. * @return mixed
  51. */
  52. public function actionEditform()
  53. {
  54. $post = Yii::$app->request->post();
  55. if (!empty($post) && empty($post['id'])) {
  56. $model = new PushDiscount();
  57. if ($model->load($post, '') && $model->save()) {
  58. return Help::JsonCode(Help::SUCCESS, '添加成功');
  59. }
  60. return Help::JsonCode(Help::ERROR, '添加失败', $model->errors);
  61. } else if (!empty($post) && !empty($post['id'])) {
  62. $row = PushDiscount::findOne($post['id']);
  63. if ($row->load($post, '') && $row->save()) {
  64. return Help::JsonCode(Help::SUCCESS, '修改成功');
  65. }
  66. return Help::JsonCode(Help::ERROR, '修改失败', $row->errors);
  67. }
  68. }
  69. /**
  70. * 排序&审核&删除-数据
  71. * @return mixed
  72. * @throws \Throwable
  73. * @throws \yii\db\StaleObjectException
  74. */
  75. public function actionSetrow()
  76. {
  77. $input = Yii::$app->request->post();
  78. $row = PushDiscount::findOne($input['id']);
  79. if ($row != null) {
  80. switch ($input['type']) {
  81. case 'del':
  82. if ($row->delete()) return Help::JsonCode(Help::SUCCESS, '删除成功');
  83. break;
  84. case 'sort':
  85. if (is_numeric($input['sort'])) {
  86. $row->sort = $input['sort'];
  87. }
  88. break;
  89. case 'show':
  90. if ($row['is_show'] == 1) {
  91. $row->is_show = 2;
  92. } else if ($row['is_show'] == 2) {
  93. $row->is_show = 1;
  94. }
  95. break;
  96. }
  97. if ($row->save(false)) return Help::JsonCode(Help::SUCCESS, '操作成功');
  98. }
  99. return Help::JsonCode(Help::ERROR, '操作失败', $row->errors);
  100. }
  101. }