123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379 |
- <?php
- /**
- * Created by PhpStorm.
- * User: xiaofeng
- * Date: 2018/4/3
- * Time: 下午5:14
- * 楼盘导出
- */
- namespace backend\controllers;
- use common\models\Housepushstatus;
- use Yii;
- use backend\base\Help;
- use backend\base\CommonController;
- use common\models\House;
- use yii\helpers\ArrayHelper;
- class OtherwatermarkController extends CommonController
- {
- public function actionAa()
- {
- $m = House::find()->select(['id', 'name'])->asArray()->all();
- $s = new Housepushstatus();
- foreach ($m as $val) {
- $_s = clone $s;
- $_s->status = 1;
- $_s->hid = $val['id'];
- $_s->save();
- }
- }
- //楼盘导出-楼盘显示页面
- public function actionHouse()
- {
- return $this->render('house');
- }
- //楼盘导出-楼盘显示页面数据
- public function actionHousrform()
- {
- // $model = new House();
- $input = Yii::$app->request->post();
- if (!empty($input['city'])) {
- $city = new \common\models\CategoryCity();
- $pro = $city->FindById($input['city']);
- if ($pro['pid'] == 0) {
- $r = $city->GetAllSon($input['city'], ['city_name', 'id']);
- if (!empty($r)) {
- $input['city'] = array_column($r, 'id');
- }
- }
- }
- $query = House::find();
- if (ArrayHelper::keyExists('start_time', $input) && !empty($input['start_time'])) {
- $query->andFilterWhere(['>=', 'pfg_house.create_at', strtotime($input['start_time'] . ' 00:00:00')]);
- }
- if (ArrayHelper::keyExists('end_time', $input) && !empty($input['end_time'])) {
- $query->andFilterWhere(['<=', 'pfg_house.create_at', strtotime($input['end_time'] . ' 23:59:59')]);
- }
- $query->andFilterWhere(['pfg_house.del' => [1, 2]]);
- if (ArrayHelper::keyExists('name', $input)) {
- $query->andFilterWhere(['like', 'pfg_house.name', $input['name']]);
- }
- if (ArrayHelper::keyExists('id', $input)) {
- $query->andFilterWhere(['pfg_house.id' => $input['id']]);
- }
- if (ArrayHelper::keyExists('city', $input) && !empty($input['city'])) {
- $query->andWhere(['pfg_house.city' => $input['city']]);
- }
- if (ArrayHelper::keyExists('housestatus', $input)) {
- switch ($input['housestatus']) {
- case 1:
- case 2:
- $query->andFilterWhere(['pfg_house.is_view' => $input['housestatus']]);
- break;
- case 3:
- case 4:
- if ($input['housestatus'] == 3) {
- $delNum = 1;
- } else if ($input['housestatus'] == 4) {
- $delNum = 2;
- }
- $query->andFilterWhere(['pfg_house.del' => $delNum]);
- break;
- case 5:
- $query->andFilterWhere(['pfg_house.del' => 1]);
- $query->andFilterWhere(['pfg_house.is_view' => 1]);
- break;
- }
- }
- if (ArrayHelper::keyExists('housepermit', $input)) {
- $yushou = new \common\models\HousePermit();
- $yushow = $yushou::find()->andWhere(['del' => 1])->select(['hid'])->groupBy('hid')->column();
- switch ($input['housepermit']) {
- case 1:
- if ($yushow != null) {
- $query->andWhere(['pfg_house.id' => $yushow]);
- }
- break;
- case 2:
- if ($yushow != null) {
- $query->andWhere(['not', ['pfg_house.id' => $yushow]]);
- }
- break;
- }
- }
- if (!empty($input['page'])) {
- $query->offset = ($input['page'] - 1) * $input['limit'];
- $query->limit = $input['limit'];
- }
- $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']);
- $statusSql = '';
- if (ArrayHelper::keyExists('status', $input) && !empty($input['status'])) {
- switch ($input['status']) {
- case 1:
- $query->andFilterWhere(['pfg_housepushstatus.status' => 1]);
- break;
- case 2:
- $query->andWhere('pfg_house.id not in(select hid from pfg_housepushstatus where status in(1))');
- break;
- }
- }
- $query->leftJoin('pfg_housepushstatus', 'pfg_house.id = pfg_housepushstatus.hid');
- $query->leftJoin('pfg_category_city', 'pfg_house.city=pfg_category_city.id');
- $count = $query->count();
- $rows = $query->orderBy(['pfg_house.create_at' => SORT_DESC])->asArray()->all();
- if ($rows != null) {
- $id = array_column($rows, 'id');
- //预售证
- $yushou = new \common\models\HousePermit();
- $yushow = $yushou->HidTotal(['hid' => $id]);
- if ($yushow != null) {
- $PermitColumn = array_column($yushow, 'num', 'hid');
- }
- foreach ($rows as &$val) {
- $val['create_at'] = date('Y-m-d H:i', $val['create_at']);
- $val['permit'] = 0;
- if (!empty($PermitColumn[$val['id']])) {
- $val['permit'] = $PermitColumn[$val['id']];
- }
- }
- return Help::JsonData(0, '成功', $count, $rows);
- }
- return Help::JsonCode(Help::ERROR, Yii::t('app', 'get_error'));
- }
- //导出按钮
- public function actionExport()
- {
- $input = Yii::$app->request->get();
- if (!empty($input['city'])) {
- $city = new \common\models\CategoryCity();
- $pro = $city->FindById($input['city']);
- if ($pro['pid'] == 0) {
- $r = $city->GetAllSon($input['city'], ['city_name', 'id']);
- if (!empty($r)) {
- $input['city'] = array_column($r, 'id');
- }
- }
- }
- $query = House::find();
- if (ArrayHelper::keyExists('start_time', $input) && !empty($input['start_time'])) {
- $query->andFilterWhere(['>=', 'pfg_house.create_at', strtotime($input['start_time'] . ' 00:00:00')]);
- }
- if (ArrayHelper::keyExists('end_time', $input) && !empty($input['end_time'])) {
- $query->andFilterWhere(['<=', 'pfg_house.create_at', strtotime($input['end_time'] . ' 23:59:59')]);
- }
- $query->andFilterWhere(['pfg_house.del' => [1, 2]]);
- if (ArrayHelper::keyExists('name', $input)) {
- $query->andFilterWhere(['like', 'pfg_house.name', $input['name']]);
- }
- if (ArrayHelper::keyExists('id', $input)) {
- $query->andFilterWhere(['pfg_house.id' => $input['id']]);
- }
- if (ArrayHelper::keyExists('city', $input) && !empty($input['city'])) {
- $query->andWhere(['pfg_house.city' => $input['city']]);
- }
- if (ArrayHelper::keyExists('housestatus', $input)) {
- switch ($input['housestatus']) {
- case 1:
- case 2:
- $query->andFilterWhere(['pfg_house.is_view' => $input['housestatus']]);
- break;
- case 3:
- case 4:
- if ($input['housestatus'] == 3) {
- $delNum = 1;
- } else if ($input['housestatus'] == 4) {
- $delNum = 2;
- }
- $query->andFilterWhere(['pfg_house.del' => $delNum]);
- break;
- case 5:
- $query->andFilterWhere(['pfg_house.del' => 1]);
- $query->andFilterWhere(['pfg_house.is_view' => 1]);
- break;
- }
- }
- if (!empty($input['page'])) {
- $query->offset = ($input['page'] - 1) * $input['limit'];
- $query->limit = $input['limit'];
- }
- $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']);
- if (ArrayHelper::keyExists('status', $input) && !empty($input['status'])) {
- switch ($input['status']) {
- case 1:
- $query->andFilterWhere(['pfg_housepushstatus.status' => 1]);
- break;
- case 2:
- $query->andWhere('pfg_house.id not in(select hid from pfg_housepushstatus where status in(1))');
- break;
- }
- }
- $query->leftJoin('pfg_housepushstatus', 'pfg_house.id = pfg_housepushstatus.hid');
- $query->leftJoin('pfg_category_city', 'pfg_house.city=pfg_category_city.id');
- $data = $query->orderBy(['pfg_house.create_at' => SORT_DESC])->asArray()->all();
- if (!empty($data)) {
- $excel = new \common\api\ExcelServer();
- $excel->SetTitle('楼盘项目信息');
- $excel->SheetIndex();
- $excel->SheetText($data);
- $excel->Export(date('YmdHi') . '.xls');
- }
- echo '<script> alert("无该数据") </script>';
- }
- /**
- * 修改推广状态
- */
- public function actionPushstatus()
- {
- $input = Yii::$app->request->post();
- $model = new \common\models\Housepushstatus();
- $row = $model->FindById($input['id']);
- if (!empty($row)) {
- switch ($row->status) {
- case 1:
- $row->status = 2;
- break;
- case 2:
- $row->status = 1;
- break;
- }
- $result = $row->save();
- } else {
- $model->status = 1;
- $model->hid = $input['id'];
- $result = $model->save();
- }
- if ($result) return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
- return Help::JsonCode(Help::ERROR, Yii::t('app', 'edit_error'));
- }
- //批量修改推广
- public function actionPushstatuss()
- {
- $input = Yii::$app->request->post();
- $model = new \common\models\Housepushstatus();
- if (is_array($input['hid']) && !empty($input['hid'])) {
- foreach ($input['hid'] as $val) {
- $_m = clone $model;
- $find = $_m::findOne($val);
- if (!empty($find)) {
- switch ($find['status']) {
- case 1:
- $find->status = 2;
- break;
- case 2:
- $find->status = 1;
- break;
- }
- $find->save();
- } elseif (empty($find)) {
- $_m->status = 1;
- $_m->hid = $val;
- $_m->save();
- }
- }
- return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
- }
- return Help::JsonCode(Help::ERROR, Yii::t('app', 'edit_error'));
- }
- /*
- * 其他管理-水印设置显示页面
- * */
- public function actionHome()
- {
- $query = \common\models\CategoryWatermark::find()->asArray()->one();
- $positionArr = [
- 1 => '#1',
- 2 => '#2',
- 3 => '#3',
- 4 => '#4',
- 5 => '#5',
- 6 => '#6',
- 7 => '#7',
- 8 => '#8',
- 9 => '#9',
- ];
- $query['template'] = Yii::$app->params['watermark_img']['url'] . $query['template'];
- return $this->render('home', ['model' => $query, 'position' => $positionArr]);
- }
- /*
- * 其他管理-修改水印设置
- * */
- public function actionEditform()
- {
- $model = new \common\models\CategoryWatermark();
- $input = Yii::$app->request->post();
- $model->load($input, '');
- if ($model->validate()) {
- $url = Yii::$app->params['watermark_img']['url'];
- $img = \backend\server\UploadFile::InstanceImgName('template', $url);
- $row = $model->FindById(Yii::$app->request->post('id'));
- if ($row != null) {
- $setAtt = Help::SetAttr(Yii::$app->request->post(), $model, $row);
- if ($img != false) {
- $setAtt->template = $img;
- }
- if (!isset($input['status'])) {
- $setAtt->status = 2;
- }
- if ($setAtt->update(false) == true) return Help::JsonCode(Help::SUCCESS, '操作成功');
- }
- }
- return Help::JsonCode(Help::ERROR, '操作失败', $model->errors);
- }
- }
|