OtherwatermarkController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/4/3
  6. * Time: 下午5:14
  7. * 楼盘导出
  8. */
  9. namespace backend\controllers;
  10. use common\models\Housepushstatus;
  11. use Yii;
  12. use backend\base\Help;
  13. use backend\base\CommonController;
  14. use common\models\House;
  15. use yii\helpers\ArrayHelper;
  16. class OtherwatermarkController extends CommonController
  17. {
  18. public function actionAa()
  19. {
  20. $m = House::find()->select(['id', 'name'])->asArray()->all();
  21. $s = new Housepushstatus();
  22. foreach ($m as $val) {
  23. $_s = clone $s;
  24. $_s->status = 1;
  25. $_s->hid = $val['id'];
  26. $_s->save();
  27. }
  28. }
  29. //楼盘导出-楼盘显示页面
  30. public function actionHouse()
  31. {
  32. return $this->render('house');
  33. }
  34. //楼盘导出-楼盘显示页面数据
  35. public function actionHousrform()
  36. {
  37. // $model = new House();
  38. $input = Yii::$app->request->post();
  39. if (!empty($input['city'])) {
  40. $city = new \common\models\CategoryCity();
  41. $pro = $city->FindById($input['city']);
  42. if ($pro['pid'] == 0) {
  43. $r = $city->GetAllSon($input['city'], ['city_name', 'id']);
  44. if (!empty($r)) {
  45. $input['city'] = array_column($r, 'id');
  46. }
  47. }
  48. }
  49. $query = House::find();
  50. if (ArrayHelper::keyExists('start_time', $input) && !empty($input['start_time'])) {
  51. $query->andFilterWhere(['>=', 'pfg_house.create_at', strtotime($input['start_time'] . ' 00:00:00')]);
  52. }
  53. if (ArrayHelper::keyExists('end_time', $input) && !empty($input['end_time'])) {
  54. $query->andFilterWhere(['<=', 'pfg_house.create_at', strtotime($input['end_time'] . ' 23:59:59')]);
  55. }
  56. $query->andFilterWhere(['pfg_house.del' => [1, 2]]);
  57. if (ArrayHelper::keyExists('name', $input)) {
  58. $query->andFilterWhere(['like', 'pfg_house.name', $input['name']]);
  59. }
  60. if (ArrayHelper::keyExists('id', $input)) {
  61. $query->andFilterWhere(['pfg_house.id' => $input['id']]);
  62. }
  63. if (ArrayHelper::keyExists('city', $input) && !empty($input['city'])) {
  64. $query->andWhere(['pfg_house.city' => $input['city']]);
  65. }
  66. if (ArrayHelper::keyExists('housestatus', $input)) {
  67. switch ($input['housestatus']) {
  68. case 1:
  69. case 2:
  70. $query->andFilterWhere(['pfg_house.is_view' => $input['housestatus']]);
  71. break;
  72. case 3:
  73. case 4:
  74. if ($input['housestatus'] == 3) {
  75. $delNum = 1;
  76. } else if ($input['housestatus'] == 4) {
  77. $delNum = 2;
  78. }
  79. $query->andFilterWhere(['pfg_house.del' => $delNum]);
  80. break;
  81. case 5:
  82. $query->andFilterWhere(['pfg_house.del' => 1]);
  83. $query->andFilterWhere(['pfg_house.is_view' => 1]);
  84. break;
  85. }
  86. }
  87. if (ArrayHelper::keyExists('housepermit', $input)) {
  88. $yushou = new \common\models\HousePermit();
  89. $yushow = $yushou::find()->andWhere(['del' => 1])->select(['hid'])->groupBy('hid')->column();
  90. switch ($input['housepermit']) {
  91. case 1:
  92. if ($yushow != null) {
  93. $query->andWhere(['pfg_house.id' => $yushow]);
  94. }
  95. break;
  96. case 2:
  97. if ($yushow != null) {
  98. $query->andWhere(['not', ['pfg_house.id' => $yushow]]);
  99. }
  100. break;
  101. }
  102. }
  103. if (!empty($input['page'])) {
  104. $query->offset = ($input['page'] - 1) * $input['limit'];
  105. $query->limit = $input['limit'];
  106. }
  107. $query->select(['pfg_house.create_at', 'pfg_house.id', 'pfg_category_city.city_name', 'pfg_house.name', 'pfg_house.is_view', 'pfg_house.del', 'pfg_housepushstatus.status']);
  108. $statusSql = '';
  109. if (ArrayHelper::keyExists('status', $input) && !empty($input['status'])) {
  110. switch ($input['status']) {
  111. case 1:
  112. $query->andFilterWhere(['pfg_housepushstatus.status' => 1]);
  113. break;
  114. case 2:
  115. $query->andWhere('pfg_house.id not in(select hid from pfg_housepushstatus where status in(1))');
  116. break;
  117. }
  118. }
  119. $query->leftJoin('pfg_housepushstatus', 'pfg_house.id = pfg_housepushstatus.hid');
  120. $query->leftJoin('pfg_category_city', 'pfg_house.city=pfg_category_city.id');
  121. $count = $query->count();
  122. $rows = $query->orderBy(['pfg_house.create_at' => SORT_DESC])->asArray()->all();
  123. if ($rows != null) {
  124. $id = array_column($rows, 'id');
  125. //预售证
  126. $yushou = new \common\models\HousePermit();
  127. $yushow = $yushou->HidTotal(['hid' => $id]);
  128. if ($yushow != null) {
  129. $PermitColumn = array_column($yushow, 'num', 'hid');
  130. }
  131. foreach ($rows as &$val) {
  132. $val['create_at'] = date('Y-m-d H:i', $val['create_at']);
  133. $val['permit'] = 0;
  134. if (!empty($PermitColumn[$val['id']])) {
  135. $val['permit'] = $PermitColumn[$val['id']];
  136. }
  137. }
  138. return Help::JsonData(0, '成功', $count, $rows);
  139. }
  140. return Help::JsonCode(Help::ERROR, Yii::t('app', 'get_error'));
  141. }
  142. //导出按钮
  143. public function actionExport()
  144. {
  145. $input = Yii::$app->request->get();
  146. if (!empty($input['city'])) {
  147. $city = new \common\models\CategoryCity();
  148. $pro = $city->FindById($input['city']);
  149. if ($pro['pid'] == 0) {
  150. $r = $city->GetAllSon($input['city'], ['city_name', 'id']);
  151. if (!empty($r)) {
  152. $input['city'] = array_column($r, 'id');
  153. }
  154. }
  155. }
  156. $query = House::find();
  157. if (ArrayHelper::keyExists('start_time', $input) && !empty($input['start_time'])) {
  158. $query->andFilterWhere(['>=', 'pfg_house.create_at', strtotime($input['start_time'] . ' 00:00:00')]);
  159. }
  160. if (ArrayHelper::keyExists('end_time', $input) && !empty($input['end_time'])) {
  161. $query->andFilterWhere(['<=', 'pfg_house.create_at', strtotime($input['end_time'] . ' 23:59:59')]);
  162. }
  163. $query->andFilterWhere(['pfg_house.del' => [1, 2]]);
  164. if (ArrayHelper::keyExists('name', $input)) {
  165. $query->andFilterWhere(['like', 'pfg_house.name', $input['name']]);
  166. }
  167. if (ArrayHelper::keyExists('id', $input)) {
  168. $query->andFilterWhere(['pfg_house.id' => $input['id']]);
  169. }
  170. if (ArrayHelper::keyExists('city', $input) && !empty($input['city'])) {
  171. $query->andWhere(['pfg_house.city' => $input['city']]);
  172. }
  173. if (ArrayHelper::keyExists('housestatus', $input)) {
  174. switch ($input['housestatus']) {
  175. case 1:
  176. case 2:
  177. $query->andFilterWhere(['pfg_house.is_view' => $input['housestatus']]);
  178. break;
  179. case 3:
  180. case 4:
  181. if ($input['housestatus'] == 3) {
  182. $delNum = 1;
  183. } else if ($input['housestatus'] == 4) {
  184. $delNum = 2;
  185. }
  186. $query->andFilterWhere(['pfg_house.del' => $delNum]);
  187. break;
  188. case 5:
  189. $query->andFilterWhere(['pfg_house.del' => 1]);
  190. $query->andFilterWhere(['pfg_house.is_view' => 1]);
  191. break;
  192. }
  193. }
  194. if (!empty($input['page'])) {
  195. $query->offset = ($input['page'] - 1) * $input['limit'];
  196. $query->limit = $input['limit'];
  197. }
  198. $query->select(['pfg_house.create_at', 'pfg_house.id', 'pfg_category_city.city_name', 'pfg_house.name', 'pfg_house.is_view', 'pfg_house.del', 'pfg_housepushstatus.status']);
  199. if (ArrayHelper::keyExists('status', $input) && !empty($input['status'])) {
  200. switch ($input['status']) {
  201. case 1:
  202. $query->andFilterWhere(['pfg_housepushstatus.status' => 1]);
  203. break;
  204. case 2:
  205. $query->andWhere('pfg_house.id not in(select hid from pfg_housepushstatus where status in(1))');
  206. break;
  207. }
  208. }
  209. $query->leftJoin('pfg_housepushstatus', 'pfg_house.id = pfg_housepushstatus.hid');
  210. $query->leftJoin('pfg_category_city', 'pfg_house.city=pfg_category_city.id');
  211. $data = $query->orderBy(['pfg_house.create_at' => SORT_DESC])->asArray()->all();
  212. if (!empty($data)) {
  213. $excel = new \common\api\ExcelServer();
  214. $excel->SetTitle('楼盘项目信息');
  215. $excel->SheetIndex();
  216. $excel->SheetText($data);
  217. $excel->Export(date('YmdHi') . '.xls');
  218. }
  219. echo '<script> alert("无该数据") </script>';
  220. }
  221. /**
  222. * 修改推广状态
  223. */
  224. public function actionPushstatus()
  225. {
  226. $input = Yii::$app->request->post();
  227. $model = new \common\models\Housepushstatus();
  228. $row = $model->FindById($input['id']);
  229. if (!empty($row)) {
  230. switch ($row->status) {
  231. case 1:
  232. $row->status = 2;
  233. break;
  234. case 2:
  235. $row->status = 1;
  236. break;
  237. }
  238. $result = $row->save();
  239. } else {
  240. $model->status = 1;
  241. $model->hid = $input['id'];
  242. $result = $model->save();
  243. }
  244. if ($result) return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
  245. return Help::JsonCode(Help::ERROR, Yii::t('app', 'edit_error'));
  246. }
  247. //批量修改推广
  248. public function actionPushstatuss()
  249. {
  250. $input = Yii::$app->request->post();
  251. $model = new \common\models\Housepushstatus();
  252. if (is_array($input['hid']) && !empty($input['hid'])) {
  253. foreach ($input['hid'] as $val) {
  254. $_m = clone $model;
  255. $find = $_m::findOne($val);
  256. if (!empty($find)) {
  257. switch ($find['status']) {
  258. case 1:
  259. $find->status = 2;
  260. break;
  261. case 2:
  262. $find->status = 1;
  263. break;
  264. }
  265. $find->save();
  266. } elseif (empty($find)) {
  267. $_m->status = 1;
  268. $_m->hid = $val;
  269. $_m->save();
  270. }
  271. }
  272. return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
  273. }
  274. return Help::JsonCode(Help::ERROR, Yii::t('app', 'edit_error'));
  275. }
  276. /*
  277. * 其他管理-水印设置显示页面
  278. * */
  279. public function actionHome()
  280. {
  281. $query = \common\models\CategoryWatermark::find()->asArray()->one();
  282. $positionArr = [
  283. 1 => '#1',
  284. 2 => '#2',
  285. 3 => '#3',
  286. 4 => '#4',
  287. 5 => '#5',
  288. 6 => '#6',
  289. 7 => '#7',
  290. 8 => '#8',
  291. 9 => '#9',
  292. ];
  293. $query['template'] = Yii::$app->params['watermark_img']['url'] . $query['template'];
  294. return $this->render('home', ['model' => $query, 'position' => $positionArr]);
  295. }
  296. /*
  297. * 其他管理-修改水印设置
  298. * */
  299. public function actionEditform()
  300. {
  301. $model = new \common\models\CategoryWatermark();
  302. $input = Yii::$app->request->post();
  303. $model->load($input, '');
  304. if ($model->validate()) {
  305. $url = Yii::$app->params['watermark_img']['url'];
  306. $img = \backend\server\UploadFile::InstanceImgName('template', $url);
  307. $row = $model->FindById(Yii::$app->request->post('id'));
  308. if ($row != null) {
  309. $setAtt = Help::SetAttr(Yii::$app->request->post(), $model, $row);
  310. if ($img != false) {
  311. $setAtt->template = $img;
  312. }
  313. if (!isset($input['status'])) {
  314. $setAtt->status = 2;
  315. }
  316. if ($setAtt->update(false) == true) return Help::JsonCode(Help::SUCCESS, '操作成功');
  317. }
  318. }
  319. return Help::JsonCode(Help::ERROR, '操作失败', $model->errors);
  320. }
  321. }