123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?php
- namespace frontend\controllers;
- use common\models\UserHouse;
- use Yii;
- use yii\web\Controller;
- use yii\filters\AccessControl;
- /**
- * red controller
- */
- class MyhouseController extends BasewechatController
- {
- static $pagenum = 20;
- public function behaviors()
- {
- return [
- 'access' => [
- 'class' => AccessControl::className(),
- 'rules' => [
- [
- 'actions' => [],
- 'allow' => true,
- 'roles' => ['@'],
- ],
- ],
- ],
- ];
- }
- /**
- * 我的房屋
- */
- public function actionList()
- {
- $mod = UserHouse::findBySql("SELECT * FROM {{%user_house}} WHERE uid = :uid ORDER BY id DESC",[':uid'=>Yii::$app->user->id]);
- $list = $mod->all();
- Yii::$app->view->title="我的房屋";
- return $this->render('list',['datas'=>$list]);
- }
- /**
- * @return mixed|string
- * 添加房屋
- */
- public function actionAdd()
- {
- if(Yii::$app->request->isAjax)
- {
- $result=['sign'=>1,'msg'=>'ok'];
- $post = Yii::$app->request->post();
- $mod = new UserHouse();
- $mod->uid = Yii::$app->user->id;
- $mod->compound = $post['compound'];
- $mod->layout = $post['layout'];
- $mod->acreage = $post['acreage'];
- $mod->amount = $post['amount'];
- $mod->province = $post['province'];
- $mod->city = $post['city'];
- $mod->district = $post['district'];
- $mod->address = $post['address2'];
- $mod->created_at = time();
- $mod->status = 0;
- $mod->style = $post['style'];
- $mod->updated_at = time();
- if($mod->save()&&$mod->validate())
- {
- $result=['sign'=>1,'msg'=>'添加成功'];
- }else{
- $result=['sign'=>0,'msg'=>'添加失败'];
- }
- return json_encode($result);
- }
- Yii::$app->view->title="添加房屋";
- return $this->render('add');
- }
- /**
- *修改房屋
- */
- public function actionEdit()
- {
- if(Yii::$app->request->isAjax)
- {
- $result=['sign'=>1,'msg'=>'ok'];
- $post = Yii::$app->request->post();
- $mod = UserHouse::find()->where(['uid'=>Yii::$app->user->id,'id'=>$post['id']])->one();
- $mod->uid = Yii::$app->user->id;
- $mod->compound = $post['compound'];
- $mod->layout = $post['layout'];
- $mod->acreage = $post['acreage'];
- $mod->amount = $post['amount'];
- $mod->province = $post['province'];
- $mod->city = $post['city'];
- $mod->district = $post['district'];
- $mod->address = $post['address2'];
- $mod->style = $post['style'];
- if($mod->save()&&$mod->validate())
- {
- $result=['sign'=>1,'msg'=>'修改成功'];
- }else{
- $result=['sign'=>0,'msg'=>'修改失败'];
- }
- return json_encode($result);
- }
- Yii::$app->view->title="修改房屋";
- $id = Yii::$app->request->get('id');
- $info = UserHouse::find()->where(['id'=>$id,'uid'=>Yii::$app->user->id])->one();
- return $this->render('edit',['info'=>$info]);
- }
- }
|