BuildingController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2017/7/24
  6. * Time: 11:37
  7. */
  8. namespace company\modules\wechat\controllers;
  9. use common\models\Comment;
  10. use yii\base\Controller;
  11. use yii;
  12. use company\modules\wechat\controllers\LoginverifyController;
  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 = 'main';
  25. const PAGESIZE =20;// 分页条数
  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. //新建样板房
  47. public function actionAddroom(){
  48. $model_manager = Manager::find()->where('company=:company and status=:status',[':company'=>Yii::$app->user->id,':status'=>Designer::STATUS_YES])->all();
  49. $model_designer = Designer::find()->where('company=:company and status=:status',[':company'=>Yii::$app->user->id,':status'=>Designer::STATUS_YES])->all();
  50. if(Yii::$app->request->get()){
  51. return companybuilding::add_building();
  52. }else{
  53. return $this->render('add_room',
  54. [
  55. 'layout_arr'=>self::$layout_arr,
  56. 'style_arr'=>self::$style_arr,
  57. 'pattern_arr'=>self::$pattern_arr,
  58. 'model_manager'=>$model_manager,
  59. 'model_designer'=>$model_designer,
  60. ]);
  61. }
  62. }
  63. //新建工地
  64. public function actionAddwork(){
  65. $model_manager = Manager::find()->where('company=:company and status=:status',[':company'=>Yii::$app->user->id,':status'=>Designer::STATUS_YES])->all();
  66. $model_designer = Designer::find()->where('company=:company and status=:status',[':company'=>Yii::$app->user->id,':status'=>Designer::STATUS_YES])->all();
  67. if(Yii::$app->request->get()){
  68. return companybuilding::add_building();
  69. }else{
  70. return $this->render('add_work',
  71. [
  72. 'stage_arr'=>self::$stage_arr,
  73. 'layout_arr'=>self::$layout_arr,
  74. 'style_arr'=>self::$style_arr,
  75. 'pattern_arr'=>self::$pattern_arr,
  76. 'model_manager'=>$model_manager,
  77. 'model_designer'=>$model_designer,
  78. ]);
  79. }
  80. }
  81. /**
  82. * 编辑工地
  83. */
  84. public function actionEditwork()
  85. {
  86. $id = Yii::$app->request->get('id');
  87. $model_manager = Manager::find()->where('company=:company and status=:status',[':company'=>Yii::$app->user->id,':status'=>Designer::STATUS_YES])->all();
  88. $model_designer = Designer::find()->where('company=:company and status=:status',[':company'=>Yii::$app->user->id,':status'=>Designer::STATUS_YES])->all();
  89. $model = Building::find()->where(['id'=>$id,'uid'=>Yii::$app->user->id])->one();
  90. if(empty($model))
  91. {
  92. exit("找不到该工地");
  93. }
  94. if(Yii::$app->request->get('typeModel')=='edit')
  95. {
  96. return companybuilding::update_building($id);
  97. }
  98. return $this->render('add_work',
  99. [
  100. 'stage_arr'=>self::$stage_arr,
  101. 'layout_arr'=>self::$layout_arr,
  102. 'style_arr'=>self::$style_arr,
  103. 'pattern_arr'=>self::$pattern_arr,
  104. 'model_manager'=>$model_manager,
  105. 'model_designer'=>$model_designer,
  106. 'model' => $model,
  107. ]);
  108. }
  109. /**
  110. * 编辑样板房
  111. */
  112. public function actionEditroom()
  113. {
  114. $id = Yii::$app->request->get('id');
  115. $model_manager = Manager::find()->where('company=:company and status=:status',[':company'=>Yii::$app->user->id,':status'=>Designer::STATUS_YES])->all();
  116. $model_designer = Designer::find()->where('company=:company and status=:status',[':company'=>Yii::$app->user->id,':status'=>Designer::STATUS_YES])->all();
  117. $model = Building::find()->where(['id'=>$id,'uid'=>Yii::$app->user->id])->one();
  118. if(empty($model))
  119. {
  120. exit("找不到该样板房");
  121. }
  122. if(Yii::$app->request->get('typeModel')=='edit')
  123. {
  124. return companybuilding::update_building($id);
  125. }
  126. return $this->render('add_room',
  127. [
  128. 'stage_arr'=>self::$stage_arr,
  129. 'layout_arr'=>self::$layout_arr,
  130. 'style_arr'=>self::$style_arr,
  131. 'pattern_arr'=>self::$pattern_arr,
  132. 'model_manager'=>$model_manager,
  133. 'model_designer'=>$model_designer,
  134. 'model' => $model,
  135. ]);
  136. }
  137. //验证名字
  138. public function actionVerifyname(){
  139. $name = Yii::$app->request->get('name');
  140. $model = Building::find()->where('name=:name',[':name'=>$name])->one();
  141. if(!empty($model)){
  142. $result=['sign'=>4000,'msg'=>'名字已经被占用'];
  143. }else{
  144. $result=['sign'=>1,'msg'=>'名字可用'];
  145. }
  146. return json_encode($result);
  147. }
  148. //样板房列表
  149. public function actionIndex(){
  150. $models = Building::find()->where('uid=:uid and posted!=:posted and type=:type',[':uid'=>Yii::$app->user->id,':posted'=>Building::POSTED_DELETE,':type'=>Building::TYPE_HOUSE]);
  151. $pages = $models->count();
  152. $pages = ceil($pages/self::PAGESIZE);
  153. $models = $models->orderBy('created_at desc')->limit(self::PAGESIZE)->all();
  154. return $this->render('index',
  155. [
  156. 'models'=>$models,
  157. 'pages'=>$pages,
  158. 'layout_arr'=>self::$layout_arr,
  159. 'style_arr'=>self::$style_arr,
  160. ]);
  161. }
  162. //样板房分页
  163. public function actionIndexpage(){
  164. $page = \Yii::$app->request->post('page');
  165. $models = Building::find()->where('uid=:uid and posted!=:posted and type=:type',[':uid'=>Yii::$app->user->id,':posted'=>Building::POSTED_DELETE,':type'=>Building::TYPE_HOUSE]);
  166. $models = $models->orderBy('created_at desc')->offset(self::PAGESIZE*$page)->limit(self::PAGESIZE)->all();
  167. return $this->renderPartial('indexpage',['models'=>$models]);
  168. }
  169. //样板房详情
  170. public function actionTemplatelist(){
  171. $id = Yii::$app->request->get('id');
  172. $model = Building::find()->where('id=:id and type=:type',[':id'=>$id,':type'=>Building::TYPE_HOUSE])->one();
  173. $comment = Comment::find()->where('pid=:pid and type=:type',[':pid'=>$id,':type'=>Comment::TYPE_HOUSE])->all();
  174. return $this->render('templatelist',
  175. [
  176. 'model'=>$model,
  177. 'comment'=>$comment,
  178. ]);
  179. }
  180. //工地列表
  181. public function actionWork(){
  182. $models = Building::find()->where('uid=:uid and posted!=:posted and type=:type',[':uid'=>Yii::$app->user->id,':posted'=>Building::POSTED_DELETE,':type'=>Building::TYPE_SITE]);
  183. $pages = $models->count();
  184. $pages = ceil($pages/self::PAGESIZE);
  185. $models = $models->orderBy('created_at desc')->limit(self::PAGESIZE)->all();
  186. return $this->render('work',
  187. [
  188. 'models'=>$models,
  189. 'pages'=>$pages,
  190. 'layout_arr'=>self::$layout_arr,
  191. 'style_arr'=>self::$style_arr,
  192. ]);
  193. }
  194. //工地分页
  195. public function actionWorkpage(){
  196. $page = \Yii::$app->request->post('page');
  197. $models = Building::find()->where('uid=:uid and posted!=:posted and type=:type',[':uid'=>Yii::$app->user->id,':posted'=>Building::POSTED_DELETE,':type'=>Building::TYPE_SITE]);
  198. $models = $models->orderBy('created_at desc')->offset(self::PAGESIZE*$page)->limit(self::PAGESIZE)->all();
  199. return $this->renderPartial('workpage',['models'=>$models]);
  200. }
  201. //工地详情
  202. public function actionWorklist(){
  203. $id = Yii::$app->request->get('id');
  204. $model = Building::find()->where('id=:id and type=:type',[':id'=>$id,':type'=>Building::TYPE_SITE])->one();
  205. $comment = Comment::find()->where('pid=:pid and type=:type',[':pid'=>$id,':type'=>Comment::TYPE_SITE])->all();
  206. return $this->render('worklist',
  207. [
  208. 'model'=>$model,
  209. 'comment'=>$comment,
  210. ]);
  211. }
  212. public function actionPosition(){
  213. $id = Yii::$app->request->get('id');
  214. $model = Building::find()->where('id=:id',[':id'=>$id])->one();
  215. return $this->render('position',['model'=>$model]);
  216. }
  217. //样板详情的预约
  218. public function actionPre(){
  219. $id = Yii::$app->request->get('id');
  220. $models = Appointment::find()->where('pid=:pid',[':pid'=>$id])->all();
  221. return $this->render('pre',['models'=>$models]);
  222. }
  223. //发布和停止
  224. public function actionHandle(){
  225. $id = Yii::$app->request->get('id');
  226. $posted = Yii::$app->request->get('posted');
  227. if(!empty($id)){
  228. if($posted==Building::POSTED_YES){
  229. companybuilding::stop_posted($id);
  230. $result=['sign'=>1,'msg'=>'停止成功','posted'=>Building::POSTED_NO];
  231. }else if($posted==Building::POSTED_NO){
  232. companybuilding::delede_posted($id);
  233. $result=['sign'=>1,'msg'=>'发布成功','posted'=>Building::POSTED_YES];
  234. }
  235. }else{
  236. $result=['sign'=>0,'msg'=>'数据不存在'];
  237. }
  238. return json_encode($result);
  239. }
  240. //处理预约
  241. public function actionDispose(){
  242. $id = Yii::$app->request->get('id');
  243. $model = Appointment::find()->where('id=:id',[':id'=>$id])->one();
  244. $model->state = Appointment::STATE_YES;
  245. $model->updated_at = time();
  246. if($model->validate()&&$model->save()){
  247. $result=['sign'=>1,'msg'=>'已处理'];
  248. }else{
  249. $result=['sign'=>4000,'msg'=>'处理失败'];
  250. }
  251. return json_encode($result);
  252. }
  253. //上传客厅 主卧 布局 平面 等图片
  254. public function actionImgurl(){
  255. $serverid = Yii::$app->request->get('serverid');
  256. $result=['sign'=>4000,'msg'=>'参数有误'];
  257. $results = LMUploadFile::wechatUploaImage($serverid,'logo',false,200,200);
  258. if(!empty($results)){
  259. $result=['sign'=>1,'msg'=>'保存成功','imgurl'=>$results['remote']];
  260. }
  261. return json_encode($result);
  262. }
  263. }