BuildingController.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2017/7/24
  6. * Time: 11:37
  7. */
  8. namespace company\modules\manage\controllers;
  9. use common\models\UserCompany;
  10. use yii\base\Controller;
  11. use company\modules\manage\controllers\LoginverifyController;
  12. use yii;
  13. use yii\filters\AccessControl;
  14. use common\models\Building;
  15. use yii\data\Pagination;
  16. use common\models\Manager;
  17. use common\models\Designer;
  18. use common\library\LMUploadFile;
  19. use yii\web\UploadedFile;
  20. use common\models\ImageSource;
  21. use common\models\Appointment;
  22. use company\controllers\BuildingController as companybuilding;
  23. class BuildingController extends LoginverifyController{
  24. public $layout = 'iframe';
  25. const PAGESIZE =10;// 分页条数
  26. public static $stage_arr = [1=>'开工大吉',2=>'拆改',3=>'水电',4=>'泥水',5=>'木工',6=>'油漆',7=>'验收'];
  27. public static $layout_arr = [1=>'一房',2=>'二房',3=>'三房',4=>'四房',5=>'五房',6=>'复式',7=>'楼中楼',8=>'别墅',9=>'办公室',10=>'店面',11=>'单身公寓',12=>'自建房',13=>'跃层式'];
  28. public static $style_arr = [1=>'北欧',2=>'欧式',3=>'现代简约',4=>'中式',5=>'新中式',6=>'美式乡村',7=>'田园',8=>'地中海',9=>'东南亚',10=>'时尚混搭',11=>'简欧',12=>'新古典',13=>'雅致主义',14=>'日韩式',15=>'工业风',16=>'港式'];
  29. public static $pattern_arr = [1=>'清包',2=>'半包',3=>'全包'];
  30. public static $type_arr = [1=>'工地',2=>'样板房'];
  31. public function behaviors()
  32. {
  33. return [
  34. 'access' => [
  35. 'class' => AccessControl::className(),
  36. 'rules' => [
  37. [
  38. 'actions' => [],
  39. 'allow' => true,
  40. 'roles' => ['@'],
  41. ],
  42. ],
  43. ],
  44. ];
  45. }
  46. public function actionIndex(){
  47. $models = Building::find()->where('uid=:uid and posted!=:posted',[':uid'=>Yii::$app->user->id,':posted'=>Building::POSTED_DELETE]);
  48. $pages=new Pagination(["totalCount"=>$models->count(),"pageSize"=>self::PAGESIZE]);
  49. $models=$models->offset($pages->offset)->limit($pages->limit)->orderBy('created_at desc')->all();
  50. $conduct = Yii::$app->request->get('conduct');
  51. $id = Yii::$app->request->get('id');
  52. switch($conduct){
  53. case "add":
  54. return companybuilding::add_building();
  55. break;
  56. case "update":
  57. return companybuilding::update_building($id);
  58. break;
  59. case "delete":
  60. return companybuilding::delede_building($id);
  61. case "posted":
  62. return companybuilding::delede_posted($id);
  63. case "stop":
  64. return companybuilding::stop_posted($id);
  65. default:
  66. return $this->render('index',
  67. [
  68. 'models'=>$models,
  69. 'pages'=>$pages,
  70. 'stage_arr'=>self::$stage_arr,
  71. 'layout_arr'=>self::$layout_arr,
  72. 'style_arr'=>self::$style_arr,
  73. 'pattern_arr'=>self::$pattern_arr,
  74. ]);
  75. break;
  76. }
  77. }
  78. //新加板样房、 工地1
  79. public function actionAddbuilding(){
  80. $picture_form = new LMUploadFile();
  81. $model_manager = Manager::find()->where('company=:company and status=:status',[':company'=>Yii::$app->user->id,':status'=>Designer::STATUS_YES])->all();
  82. $model_designer = Designer::find()->where('company=:company and status=:status',[':company'=>Yii::$app->user->id,':status'=>Designer::STATUS_YES])->all();
  83. return $this->render('add_building',['model_manager'=>$model_manager,'model_designer'=>$model_designer,'picture_form'=>$picture_form]);
  84. }
  85. //更新板样房、 工地2
  86. public function actionUpdatebuilding(){
  87. $id = Yii::$app->request->get('id');
  88. $model = Building::find()->where('id=:id',[':id'=>$id])->one();
  89. $picture_form = new LMUploadFile();
  90. $model_manager = Manager::find()->where('company=:company and status=:status',[':company'=>Yii::$app->user->id,':status'=>Designer::STATUS_YES])->all();
  91. $model_designer = Designer::find()->where('company=:company and status=:status',[':company'=>Yii::$app->user->id,':status'=>Designer::STATUS_YES])->all();
  92. return $this->render('add_building',['model'=>$model,'model_manager'=>$model_manager,'model_designer'=>$model_designer,'picture_form'=>$picture_form]);
  93. }
  94. //上传客厅 主卧 布局 平面 等图片
  95. public function actionImgurl()
  96. {
  97. if (Yii::$app->request->isPost) {
  98. $type = Yii::$app->request->post('type_image');
  99. $picture_form = new LMUploadFile();
  100. $picture_form->imageFile = UploadedFile::getInstance($picture_form, 'imageFile');
  101. if ($picture_form->upload('product_picture',true,160,160)) {
  102. return "<script language='JavaScript'>window.parent.callback('上传成功!',1,'" . $picture_form->filepath . "','" . $type . "');</script>";
  103. } else {
  104. if(isset($picture_form->getErrors()['imageFile'][0])){
  105. $error = $picture_form->getErrors()['imageFile'][0];
  106. }else{
  107. $error = '图片上传失败';
  108. }
  109. return "<script language='JavaScript'>window.parent.callback('上传失败!',0,'" . $error . "');</script>";
  110. }
  111. }
  112. }
  113. //预约管理
  114. public function actionSubscribe(){
  115. $models = Appointment::find()
  116. ->joinWith('building')->where('{{%building}}.uid=:userid',[':userid'=>Yii::$app->user->id]);
  117. $pages=new Pagination(["totalCount"=>$models->count(),"pageSize"=>self::PAGESIZE]);
  118. $models=$models->offset($pages->offset)->limit($pages->limit)->orderBy('{{%appointment}}.created_at desc')->all();
  119. $member = UserCompany::find()->where(['uid'=>Yii::$app->user->id])->select('member')->one();
  120. return $this->render('subscribe',['models'=>$models,'pages'=>$pages,'member'=>$member->member]);
  121. }
  122. public function actionDispose(){
  123. $id = Yii::$app->request->get('id');
  124. $model = Appointment::find()->where('id=:id',[':id'=>$id])->one();
  125. $model->state = Appointment::STATE_YES;
  126. $model->updated_at = time();
  127. if($model->validate()&&$model->save()){
  128. $result=['sign'=>1,'msg'=>'已处理'];
  129. }else{
  130. $result=['sign'=>4000,'msg'=>'处理失败'];
  131. }
  132. return json_encode($result);
  133. }
  134. }