123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- <?php
- /**
- * Created by PhpStorm.
- * User: xiaofeng
- * Date: 2018/10/30
- * Time: 9:51 AM
- * 楼盘评测
- */
- namespace backend\controllers;
- use backend\base\CommonController;
- use backend\base\Help;
- use Yii;
- use common\models\HouseComment;
- use common\models\HouseCommentreply;
- class RoutinecommentController extends CommonController
- {
- public function actionHome()
- {
- return $this->render('home');
- }
- /*
- * 点评楼盘统计列表
- */
- public function actionHomeform()
- {
- $model = new HouseComment();
- $rows = $model->getList(Yii::$app->request->post());
- if ($rows) {
- foreach ($rows as &$val) {
- $val['yes'] = HouseComment::find()->andWhere(['del' => 1])->andWhere(['read' => 2])->andWhere(['hid' => $val['hid']])->count();
- $val['no'] = HouseComment::find()->andWhere(['del' => 1])->andWhere(['read' => 1])->andWhere(['hid' => $val['hid']])->count();
- $val['create_at'] = date('Y-m-d H:i', $val['create_at']);
- if (isset(Yii::$app->params['houseCommentReadState'][$val['read']])) {
- $val['read'] = Yii::$app->params['houseCommentReadState'][$val['read']];
- }
- }
- return Help::JsonData(0, Yii::t('app', 'get_success'), $model->Total(), $rows);
- }
- return Help::JsonCode(Help::ERROR, Yii::t('app', 'get_error'));
- }
- //编辑点评列表
- public function actionOwnhome()
- {
- return $this->render('ownhome', ['type' => 1]);
- }
- //客户点评列表
- public function actionGuesthome()
- {
- return $this->render('ownhome', ['type' => 2]);
- }
- public function actionCreate()
- {
- $model = new \common\models\HouseComment();
- return $this->render('create', ['label' => $model->xuqiu]);
- }
- public function actionCreateform()
- {
- $input = Yii::$app->request->post();
- $model = new HouseComment();
- $input['ip'] = Yii::$app->request->userIP;
- $true = $model->Iplimit($input);
- if ($true === false) return Help::JsonCode(Help::ERROR, '一个楼盘最多只能点评2次');
- $input['initiator'] = 1;
- if ($model->load($input, '') && $model->save()) {
- return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'add_success'));
- }
- return Help::JsonCode(Help::ERROR, Yii::t('app', 'add_error'), $model->errors);
- }
- /*
- * 状态修改
- */
- public function actionDelandshow()
- {
- $input = Yii::$app->request->post();
- $model = new \common\models\HouseComment();
- $row = $model->FindById($input['id']);
- if (!empty($row)) {
- if ($row->load($input, '') && $row->save()) {
- return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
- }
- }
- return Help::JsonCode(Help::ERROR, Yii::t('app', 'edit_error'), $model->errors);
- }
- public function actionMorecomment()
- {
- $id = Yii::$app->request->get('hid');
- if (is_numeric($id)) {
- return $this->render('morecomment', ['hid' => $id]);
- }
- return $this->goBack();
- }
- public function actionMorecommentform()
- {
- $model = new HouseComment();
- $input = Yii::$app->request->post();
- $model->load($input, '');
- $rows = $model->MoregetList($input);
- if ($rows) {
- foreach ($rows as &$val) {
- // $val['yes'] = HouseComment::find()->andWhere(['read'=>2])->andWhere(['hid'=>$val['hid']])->count();
- // $val['no'] = HouseComment::find()->andWhere(['read'=>1])->andWhere(['hid'=>$val['hid']])->count();
- $val['create_at'] = date('Y-m-d H:i', $val['create_at']);
- $val['mobile'] = preg_replace("/(\d{3})\d\d(\d{2})/", "\$1****\$3", $val['mobile']);
- if (isset(Yii::$app->params['houseCommentReadState'][$val['read']])) {
- $val['read'] = Yii::$app->params['houseCommentReadState'][$val['read']];
- }
- if (isset($val['reply'])) {
- $val['reply'] = 2;
- } else {
- $val['reply'] = 1;
- }
- }
- return Help::JsonData(0, Yii::t('app', 'get_success'), $model->moreTotal(Yii::$app->request->post()), $rows);
- }
- return Help::JsonCode(Help::ERROR, Yii::t('app', 'get_error'));
- }
- //阅读点评的信息
- public function actionRead()
- {
- $model = new HouseComment();
- $row = $model->FindById(Yii::$app->request->get('id'));
- if (!empty($row)) {
- if ($row['read'] == 1) {
- $Transaction = Yii::$app->db->beginTransaction();
- $row->read = 2;
- if ($row->save() && $this->RecordUser(['id' => $row['id'], 'type' => 1])) {
- $Transaction->commit();
- } else {
- $Transaction->rollBack();
- return $this->goBack();
- }
- }
- if ($row['initiator'] == 2) {
- $row['mobile'] = $this->mobile($row['mobile']);
- }
- $replyModel = new HouseCommentreply();
- $replyData = $replyModel->FindById(['cid' => $row['id']]);
- // p($replyData);
- $row['demand'] = isset($model->xuqiu[$row['demand']]) ? $model->xuqiu[$row['demand']] : '';
- return $this->render('read', ['model' => $row, 'reply' => $replyData]);
- }
- }
- public function actionCreatereply()
- {
- $model = new \common\models\HouseCommentreply();
- $input = Yii::$app->request->post();
- $recordData = [];
- if (!empty($input['reply_id']) && is_numeric($input['reply_id'])) {
- $row = $model->FindById($input['reply_id']);
- if (is_object($row)) {
- if ($row->load($input, '') && $row->save()) {
- $recordData['id'] = $input['reply_id'];
- $recordData['type'] = 3;
- }
- }
- } else {
- if ($model->load($input, '') && $model->save()) {
- $recordData['id'] = $model->attributes['id'];
- $recordData['type'] = 2;
- }
- }
- if (!empty($recordData['id']) && !empty($recordData['type']) && $this->RecordUser($recordData)) {
- return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
- }
- return Help::JsonCode(Help::ERROR, Yii::t('app', 'edit_error'));
- }
- /*
- * 修改
- */
- public function actionEdit()
- {
- $model = new HouseComment();
- $row = $model->FindById(Yii::$app->request->get('id'));
- if ($row) {
- $house = (new \common\models\House())->FindById($row['hid']);
- return $this->render('edit', ['model' => $row, 'label' => $model->xuqiu, 'house' => $house]);
- }
- return $this->goBack();
- }
- /*
- * 修改数据
- */
- public function actionEditform()
- {
- $input = Yii::$app->request->post();
- $model = new HouseComment();
- $row = $model->FindById($input['id']);
- if ($row) {
- if ($row->load($input, '') && $row->save()) {
- return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
- }
- }
- return Help::JsonCode(Help::ERROR, Yii::t('app', 'edit_error'), isset($row->errors) ? $row->errors : null);
- }
- private function RecordUser($arr)
- {
- $m = new \common\models\HouseCommentreadrecord();
- $m->cid = $arr['id'];
- $m->uid = Yii::$app->session['user_info']['uid'];
- $m->ip = Yii::$app->request->userIP;
- $m->type = $arr['type'];
- return $m->save();
- }
- public function mobile($phone)
- {
- return preg_replace("/(\d{3})\d\d(\d{2})/", "\$1****\$3", $phone);
- }
- }
|