123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <?php
- namespace backend\controllers;
- use backend\base\CommonController;
- use backend\base\Help;
- use common\models\HouseNumber;
- use Yii;
- class HousenumberController extends CommonController
- {
- /**
- * 楼盘号码 - 页面
- * @return string
- */
- public function actionIndex()
- {
- return $this->render($this->action->id);
- }
- /**
- * 楼盘号码 - 数据
- * @return mixed
- */
- public function actionIndexform()
- {
- $model = new HouseNumber();
- $rows = $model->getList(Yii::$app->request->post());
- if (!empty($rows['data'])) {
- foreach ($rows['data'] as &$val) {
- $val['hids'] = implode(',', json_decode($val['hids'], true));
- $val['create_at'] = date('Y-m-d H:i:s', $val['create_at']);
- }
- return Help::JsonData(0, '成功', $rows['count'], $rows['data']);
- }
- 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();
- if (empty($input['hid'])) return Help::JsonCode(Help::ERROR, '请选择要添加的楼盘');
- $input['hids'] = json_encode($input['hid']);
- $model = new HouseNumber();
- if ($model->load($input, '') && $model->save()) {
- return Help::JsonCode(Help::SUCCESS, '添加成功');
- }
- return Help::JsonCode(Help::ERROR, '添加失败', $model->errors);
- }
- /**
- * 楼盘号码 - 编辑页面
- * @return string
- */
- public function actionEdit()
- {
- $model = new HouseNumber();
- $zid = Yii::$app->request->get('id');
- $row = $model::findOne($zid);
- if (!empty($row)) {
- $hmodel = new \common\models\House();
- $query = $hmodel::find();
- $hid = json_decode($row['hids'], true);
- $house = $query->select(['id', 'name'])->andWhere(['id' => $hid])->asArray()->all();
- }
- return $this->render($this->action->id, ['model' => $row, 'house' => $house]);
- }
- /**
- * 楼盘号码 - 编辑数据
- * @return mixed
- */
- public function actionEditform()
- {
- $model = new HouseNumber();
- $input = Yii::$app->request->post();
- $row = $model::findOne($input['id']);
- if (empty($input['hid'])) return Help::JsonCode(Help::ERROR, '请选择推送的楼盘');
- $input['hids'] = json_encode($input['hid']);
- if ($row->load($input, '') && $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 = HouseNumber::findOne($input['id']);
- if ($row != null) {
- switch ($input['type']) {
- case 'show':
- if ($row->is_show == 1) {
- $row->is_show = 2;
- } else if ($row->is_show == 2) {
- $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, '操作失败');
- }
- }
|