HousenumberController.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. namespace backend\controllers;
  3. use backend\base\CommonController;
  4. use backend\base\Help;
  5. use common\models\HouseNumber;
  6. use Yii;
  7. class HousenumberController 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. $model = new HouseNumber();
  24. $rows = $model->getList(Yii::$app->request->post());
  25. if (!empty($rows['data'])) {
  26. foreach ($rows['data'] as &$val) {
  27. $val['hids'] = implode(',', json_decode($val['hids'], true));
  28. $val['create_at'] = date('Y-m-d H:i:s', $val['create_at']);
  29. }
  30. return Help::JsonData(0, '成功', $rows['count'], $rows['data']);
  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. if (empty($input['hid'])) return Help::JsonCode(Help::ERROR, '请选择要添加的楼盘');
  50. $input['hids'] = json_encode($input['hid']);
  51. $model = new HouseNumber();
  52. if ($model->load($input, '') && $model->save()) {
  53. return Help::JsonCode(Help::SUCCESS, '添加成功');
  54. }
  55. return Help::JsonCode(Help::ERROR, '添加失败', $model->errors);
  56. }
  57. /**
  58. * 楼盘号码 - 编辑页面
  59. * @return string
  60. */
  61. public function actionEdit()
  62. {
  63. $model = new HouseNumber();
  64. $zid = Yii::$app->request->get('id');
  65. $row = $model::findOne($zid);
  66. if (!empty($row)) {
  67. $hmodel = new \common\models\House();
  68. $query = $hmodel::find();
  69. $hid = json_decode($row['hids'], true);
  70. $house = $query->select(['id', 'name'])->andWhere(['id' => $hid])->asArray()->all();
  71. }
  72. return $this->render($this->action->id, ['model' => $row, 'house' => $house]);
  73. }
  74. /**
  75. * 楼盘号码 - 编辑数据
  76. * @return mixed
  77. */
  78. public function actionEditform()
  79. {
  80. $model = new HouseNumber();
  81. $input = Yii::$app->request->post();
  82. $row = $model::findOne($input['id']);
  83. if (empty($input['hid'])) return Help::JsonCode(Help::ERROR, '请选择推送的楼盘');
  84. $input['hids'] = json_encode($input['hid']);
  85. if ($row->load($input, '') && $row->save()) {
  86. return Help::JsonCode(Help::SUCCESS, '修改成功');
  87. }
  88. return Help::JsonCode(Help::ERROR, '修改成功', $row->errors);
  89. }
  90. /**
  91. * 操作楼盘号码
  92. * @return mixed
  93. * @throws \Throwable
  94. * @throws \yii\db\StaleObjectException
  95. */
  96. public function actionSetnumber()
  97. {
  98. $input = Yii::$app->request->post();
  99. $row = HouseNumber::findOne($input['id']);
  100. if ($row != null) {
  101. switch ($input['type']) {
  102. case 'show':
  103. if ($row->is_show == 1) {
  104. $row->is_show = 2;
  105. } else if ($row->is_show == 2) {
  106. $row->is_show = 1;
  107. }
  108. break;
  109. case 'del':
  110. if ($row->delete()) return Help::JsonCode(Help::SUCCESS, '删除成功');
  111. break;
  112. }
  113. if ($row->save(false)) return Help::JsonCode(Help::SUCCESS, '操作成功');
  114. }
  115. return Help::JsonCode(Help::ERROR, '操作失败');
  116. }
  117. }