RoutinecommentController.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/10/30
  6. * Time: 9:51 AM
  7. * 楼盘评测
  8. */
  9. namespace backend\controllers;
  10. use backend\base\CommonController;
  11. use backend\base\Help;
  12. use Yii;
  13. use common\models\HouseComment;
  14. use common\models\HouseCommentreply;
  15. class RoutinecommentController extends CommonController
  16. {
  17. public function actionHome()
  18. {
  19. return $this->render('home');
  20. }
  21. /*
  22. * 点评楼盘统计列表
  23. */
  24. public function actionHomeform()
  25. {
  26. $model = new HouseComment();
  27. $rows = $model->getList(Yii::$app->request->post());
  28. if ($rows) {
  29. foreach ($rows as &$val) {
  30. $val['yes'] = HouseComment::find()->andWhere(['del' => 1])->andWhere(['read' => 2])->andWhere(['hid' => $val['hid']])->count();
  31. $val['no'] = HouseComment::find()->andWhere(['del' => 1])->andWhere(['read' => 1])->andWhere(['hid' => $val['hid']])->count();
  32. $val['create_at'] = date('Y-m-d H:i', $val['create_at']);
  33. if (isset(Yii::$app->params['houseCommentReadState'][$val['read']])) {
  34. $val['read'] = Yii::$app->params['houseCommentReadState'][$val['read']];
  35. }
  36. }
  37. return Help::JsonData(0, Yii::t('app', 'get_success'), $model->Total(), $rows);
  38. }
  39. return Help::JsonCode(Help::ERROR, Yii::t('app', 'get_error'));
  40. }
  41. //编辑点评列表
  42. public function actionOwnhome()
  43. {
  44. return $this->render('ownhome', ['type' => 1]);
  45. }
  46. //客户点评列表
  47. public function actionGuesthome()
  48. {
  49. return $this->render('ownhome', ['type' => 2]);
  50. }
  51. public function actionCreate()
  52. {
  53. $model = new \common\models\HouseComment();
  54. return $this->render('create', ['label' => $model->xuqiu]);
  55. }
  56. public function actionCreateform()
  57. {
  58. $input = Yii::$app->request->post();
  59. $model = new HouseComment();
  60. $input['ip'] = Yii::$app->request->userIP;
  61. $true = $model->Iplimit($input);
  62. if ($true === false) return Help::JsonCode(Help::ERROR, '一个楼盘最多只能点评2次');
  63. $input['initiator'] = 1;
  64. if ($model->load($input, '') && $model->save()) {
  65. return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'add_success'));
  66. }
  67. return Help::JsonCode(Help::ERROR, Yii::t('app', 'add_error'), $model->errors);
  68. }
  69. /*
  70. * 状态修改
  71. */
  72. public function actionDelandshow()
  73. {
  74. $input = Yii::$app->request->post();
  75. $model = new \common\models\HouseComment();
  76. $row = $model->FindById($input['id']);
  77. if (!empty($row)) {
  78. if ($row->load($input, '') && $row->save()) {
  79. return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
  80. }
  81. }
  82. return Help::JsonCode(Help::ERROR, Yii::t('app', 'edit_error'), $model->errors);
  83. }
  84. public function actionMorecomment()
  85. {
  86. $id = Yii::$app->request->get('hid');
  87. if (is_numeric($id)) {
  88. return $this->render('morecomment', ['hid' => $id]);
  89. }
  90. return $this->goBack();
  91. }
  92. public function actionMorecommentform()
  93. {
  94. $model = new HouseComment();
  95. $input = Yii::$app->request->post();
  96. $model->load($input, '');
  97. $rows = $model->MoregetList($input);
  98. if ($rows) {
  99. foreach ($rows as &$val) {
  100. // $val['yes'] = HouseComment::find()->andWhere(['read'=>2])->andWhere(['hid'=>$val['hid']])->count();
  101. // $val['no'] = HouseComment::find()->andWhere(['read'=>1])->andWhere(['hid'=>$val['hid']])->count();
  102. $val['create_at'] = date('Y-m-d H:i', $val['create_at']);
  103. $val['mobile'] = preg_replace("/(\d{3})\d\d(\d{2})/", "\$1****\$3", $val['mobile']);
  104. if (isset(Yii::$app->params['houseCommentReadState'][$val['read']])) {
  105. $val['read'] = Yii::$app->params['houseCommentReadState'][$val['read']];
  106. }
  107. if (isset($val['reply'])) {
  108. $val['reply'] = 2;
  109. } else {
  110. $val['reply'] = 1;
  111. }
  112. }
  113. return Help::JsonData(0, Yii::t('app', 'get_success'), $model->moreTotal(Yii::$app->request->post()), $rows);
  114. }
  115. return Help::JsonCode(Help::ERROR, Yii::t('app', 'get_error'));
  116. }
  117. //阅读点评的信息
  118. public function actionRead()
  119. {
  120. $model = new HouseComment();
  121. $row = $model->FindById(Yii::$app->request->get('id'));
  122. if (!empty($row)) {
  123. if ($row['read'] == 1) {
  124. $Transaction = Yii::$app->db->beginTransaction();
  125. $row->read = 2;
  126. if ($row->save() && $this->RecordUser(['id' => $row['id'], 'type' => 1])) {
  127. $Transaction->commit();
  128. } else {
  129. $Transaction->rollBack();
  130. return $this->goBack();
  131. }
  132. }
  133. if ($row['initiator'] == 2) {
  134. $row['mobile'] = $this->mobile($row['mobile']);
  135. }
  136. $replyModel = new HouseCommentreply();
  137. $replyData = $replyModel->FindById(['cid' => $row['id']]);
  138. // p($replyData);
  139. $row['demand'] = isset($model->xuqiu[$row['demand']]) ? $model->xuqiu[$row['demand']] : '';
  140. return $this->render('read', ['model' => $row, 'reply' => $replyData]);
  141. }
  142. }
  143. public function actionCreatereply()
  144. {
  145. $model = new \common\models\HouseCommentreply();
  146. $input = Yii::$app->request->post();
  147. $recordData = [];
  148. if (!empty($input['reply_id']) && is_numeric($input['reply_id'])) {
  149. $row = $model->FindById($input['reply_id']);
  150. if (is_object($row)) {
  151. if ($row->load($input, '') && $row->save()) {
  152. $recordData['id'] = $input['reply_id'];
  153. $recordData['type'] = 3;
  154. }
  155. }
  156. } else {
  157. if ($model->load($input, '') && $model->save()) {
  158. $recordData['id'] = $model->attributes['id'];
  159. $recordData['type'] = 2;
  160. }
  161. }
  162. if (!empty($recordData['id']) && !empty($recordData['type']) && $this->RecordUser($recordData)) {
  163. return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
  164. }
  165. return Help::JsonCode(Help::ERROR, Yii::t('app', 'edit_error'));
  166. }
  167. /*
  168. * 修改
  169. */
  170. public function actionEdit()
  171. {
  172. $model = new HouseComment();
  173. $row = $model->FindById(Yii::$app->request->get('id'));
  174. if ($row) {
  175. $house = (new \common\models\House())->FindById($row['hid']);
  176. return $this->render('edit', ['model' => $row, 'label' => $model->xuqiu, 'house' => $house]);
  177. }
  178. return $this->goBack();
  179. }
  180. /*
  181. * 修改数据
  182. */
  183. public function actionEditform()
  184. {
  185. $input = Yii::$app->request->post();
  186. $model = new HouseComment();
  187. $row = $model->FindById($input['id']);
  188. if ($row) {
  189. if ($row->load($input, '') && $row->save()) {
  190. return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
  191. }
  192. }
  193. return Help::JsonCode(Help::ERROR, Yii::t('app', 'edit_error'), isset($row->errors) ? $row->errors : null);
  194. }
  195. private function RecordUser($arr)
  196. {
  197. $m = new \common\models\HouseCommentreadrecord();
  198. $m->cid = $arr['id'];
  199. $m->uid = Yii::$app->session['user_info']['uid'];
  200. $m->ip = Yii::$app->request->userIP;
  201. $m->type = $arr['type'];
  202. return $m->save();
  203. }
  204. public function mobile($phone)
  205. {
  206. return preg_replace("/(\d{3})\d\d(\d{2})/", "\$1****\$3", $phone);
  207. }
  208. }