|
- <?php
-
- namespace backend\modules\motorcade\controllers;
-
- use yii\imagine\Image;
- use Faker\Provider\Base;
- use kartik\form\ActiveForm;
- use Symfony\Component\DomCrawler\Field\InputFormField;
- use Symfony\Component\Yaml\Tests\B;
- use Yii;
- use backend\modules\motorcade\models\BaseBus;
- use backend\modules\motorcade\models\BusSearch;
- use yii\data\ActiveDataProvider;
- use yii\db\Query;
- use yii\web\NotFoundHttpException;
- use yii\filters\VerbFilter;
- use backend\modules\motorcade\models\BaseDocument;
- use common\models\zzcsUtils;
- use yii\web\UploadedFile;
-
- /**
- * BaseBusController implements the CRUD actions for BaseBus model.
- */
- class BaseBusController extends BaseController
- {
- public $layout = "@backend/modules/motorcade/views/layouts/iframe_new";
-
- /**
- * @inheritdoc
- */
- public function behaviors()
- {
- return [
- 'verbs' => [
- 'class' => VerbFilter::className(),
- 'actions' => [
- 'delete' => ['POST'],
- ],
- ],
- ];
- }
-
- /**
- * Lists all BaseBus models.
- * @return mixed
- */
- public function actionIndex()
- {
- $searchModel = new BusSearch();
- $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
-
- return $this->render('index', [
- 'searchModel' => $searchModel,
- 'dataProvider' => $dataProvider,
- ]);
- }
-
- /**
- * Displays a single BaseBus model.
- * @param integer $id
- * @return mixed
- */
- public function actionView($id)
- {
- return $this->render('view', [
- 'model' => $this->findModel($id),
- ]);
- }
-
- /**
- * Creates a new BaseBus model.
- * If creation is successful, the browser will be redirected to the 'view' page.
- * @return mixed
- */
- public function actionCreate()
- {
- $model = new BaseBus();
-
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- return $this->redirect(['view', 'id' => $model->BUS_ID]);
- } else {
- return $this->render('create', [
- 'model' => $model,
- ]);
- }
- }
-
- /**
- * Updates an existing BaseBus model.
- * If update is successful, the browser will be redirected to the 'view' page.
- * @param integer $id
- * @return mixed
- */
- public function actionUpdate($id)
- {
- $model = $this->findModel($id);
-
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- return $this->redirect(['view', 'id' => $model->BUS_ID]);
- } else {
- return $this->render('update', [
- 'model' => $model,
- ]);
- }
- }
-
- /**
- * Deletes an existing BaseBus model.
- * If deletion is successful, the browser will be redirected to the 'index' page.
- * @param integer $id
- * @return mixed
- */
- public function actionDelete($id)
- {
- $this->findModel($id)->delete();
-
- return $this->redirect(['index']);
- }
-
- /**
- * Finds the BaseBus model based on its primary key value.
- * If the model is not found, a 404 HTTP exception will be thrown.
- * @param integer $id
- * @return BaseBus the loaded model
- * @throws NotFoundHttpException if the model cannot be found
- */
- protected function findModel($id)
- {
- if (($model = BaseBus::findOne($id)) !== null) {
- return $model;
- } else {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
- public function actionValidateForm () {
- Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
- $model = new BusSearch();//这里要替换成自己的模型类
- $model->setScenario('add_bus');
- $model->load(Yii::$app->request->post());
- return \yii\widgets\ActiveForm::validate($model);
- }
- public function actionAddBus()
- {
- $obj = new BusSearch(['scenario' => 'add_bus']);
- if (Yii::$app->request->isPost) {
- $obj->load(Yii::$app->request->post());
- $user_id = Yii::$app->user->id;
- $main_cooperation_id = Yii::$app->user->identity->MAIN_CORP_ID2;
- $bus_company = Yii::$app->user->identity->ORG_ID;
-
- if (in_array($obj['BUS_BELONG'], [523, 524])) {
- $obj['ORG_ID'] = $bus_company;
- }
- $obj['MAIN_CORP_ID'] = $main_cooperation_id;
- $obj['CREATE_USER_ID'] = $user_id;
- $obj['CREATE_TIME'] = date("Y-m-d H:i:s");
- $obj['FUEL_FORM'] = (int)$obj['FUEL_FORM'];
- if ($obj->save()) {
- Yii::$app-> session -> setFlash('success', '保存成功!');
- $tab = isset($_REQUEST['tab']) ? $_REQUEST['tab'] : 'tab1';
- $this->redirect('/motorcade/base-bus/check-bus?bus_id=' . $obj->BUS_ID . '&tab=' . $tab);
- } else {
- Yii::$app->session->setFlash('error', '保存失败!');
- }
- }
- $seat_type = isset($_REQUEST['seat_type']) ? $_REQUEST['seat_type'] : '-1';
-
- $data = $obj->getSeatCount($seat_type);
- return $this->render('base_bus', ['data' => $data, 'view' => '_addBus']);
- }
-
- // 查看车辆
- public function actionCheckBus($bus_id, $tab = '')
- {
- //获取是查看车辆还是修改车辆 为modify则为修改
- $op = isset($_REQUEST['op']) ? $_REQUEST['op'] : '';
- //初始页选择
- $tab = isset($_REQUEST['tab']) ? $_REQUEST['tab'] : '';
- $obj = $this->findModel($bus_id);
- if (Yii::$app->request->isPost) {
- $OLD_BUS_TYPE_RES_ID = $obj['BUS_TYPE_RES_ID'];
- $obj->load(Yii::$app->request->post());
- $user_id = Yii::$app->user->id;
- $bus_company = Yii::$app->user->identity->ORG_ID;
-
- //修改车辆 SEAT_TYPE BUS_TYPE_RES_ID $seat_desc $seat_count
- $tmp_seat_type = $obj['SEAT_TYPE'];
- $tmp_seat_count = $obj['BUS_TYPE_RES_ID'];
- $tmp_seat_count1 = BusSearch::getModifySeatCount($tmp_seat_count)['res_name'];
- $seat_desc = BusSearch::getModifySeatType($tmp_seat_type)['type_name'] . $tmp_seat_count1;
- $seat_count = mb_substr($tmp_seat_count1, 0, strlen($tmp_seat_count1) - 3);
- if ($OLD_BUS_TYPE_RES_ID != $obj['BUS_TYPE_RES_ID']) {//如果座位数量 发送变更则断开与新座位图之间的联系
- $obj['SEAT_MATRIX_ID'] = 0;
- }
- $obj['SEAT_DESC'] = $seat_desc;
- $obj['SEAT_COUNT'] = $seat_count;
- //end 修改
- if (in_array($obj['BUS_BELONG'], [523, 524])) {
- $obj['ORG_ID'] = $bus_company;
- }
- $obj['CREATE_USER_ID'] = $user_id;
- $obj['CREATE_TIME'] = date("Y-m-d H:i:s");
- if ($obj->save()) {
- Yii::$app->session->setFlash('success', '保存成功!');
- } else {
- Yii::$app->session->setFlash('error', '保存失败!');
- };
- return $this->redirect(['/motorcade/base-bus/check-bus?bus_id=' . $obj->BUS_ID . '&tab=' . $tab . '&op=' . $op]);
- }
- $seat_type = isset($_REQUEST['seat_type']) ? $_REQUEST['seat_type'] : $obj['SEAT_TYPE'];
- $bus_id = isset($_REQUEST['bus_id']) ? $_REQUEST['bus_id'] : '-1';
- //获取座位数信息
- $data = $obj->getSeatCount($seat_type);
- //保单列表
- $dataProvider = new ActiveDataProvider([
- 'query' => BaseDocument::find()
- ->where(['CANCEL_FLAG' => 0, 'DOC_STATUS' => BaseDocument::STATUS_ID_ACTIVE, 'DOC_TYPE' => BaseDocument::BUS, 'DOC_ID' => $bus_id, 'DOC_OPTION' => [511, 512, 513,514]]),
- 'pagination' => [
- 'pageSize' => 20,
- ],
- 'sort' => [
- 'attributes' => [
- 'EXPIRE_DATE'
- ],
- 'defaultOrder' =>
- [
- 'EXPIRE_DATE' => SORT_DESC,
- ],
- ]
- ]);
- //保养列表
- $dataProvider1 = new ActiveDataProvider([
- 'query' => BaseDocument::find()
- ->where(['CANCEL_FLAG' => 0, 'DOC_TYPE' => BaseDocument::BUS, 'PID' => 0, 'DOC_ID' => $bus_id, 'DOC_OPTION' => [BaseDocument::MAINTAIN,BaseDocument::LICENCE_WX],'DOC_STATUS'=>0,'MT_STATUS'=>BaseDocument::WANCHENG]),
- 'pagination' => [
- 'pageSize' => 20,
- ],
- ]);
- return $this->render('base_bus', ['dataProvider1' => $dataProvider1, 'data' => $data, 'view' => '_checkBus', 'id' => $bus_id, 'model' => $obj, 'dataProvider' => $dataProvider, 'op' => $op, 'tab' => $tab]);
- }
- //修改
-
- /**
- * User: wangxj
- *
- * 车辆道路许可证等
- *
- * @params
- *
- * @return
- */
- public function action_image($id)
- {
- $result = false;
- $model = $this->findModel($id);
- if ($model === null) {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- $documents = Yii::$app->request->post('BaseDocument');
- //506 507 509 510
- foreach ($documents as $key => $document) {
- $expire_date = '';
- $start_date = '';
- $docArray = [];
- foreach ($document as $index => $item) {
- if (isset($item['ID']) && $item['ID'] != '') {
- $new = BaseDocument::findOne($item['ID']);
- $new->setScenario('bus');
- } else
- $new = new BaseDocument(['scenario' => 'bus']);
-
- //设置有效期
- if ($expire_date == '') {
- $expire_date = isset($item['EXPIRE_DATE']) ? $item['EXPIRE_DATE'] : '';
- $start_date = isset($item['START_DATE']) ? $item['START_DATE'] : '';
- } else {
- $item['EXPIRE_DATE'] = $expire_date;
- $item['START_DATE'] = $start_date;
- }
- $new->setAttributes($item);
- $new->DOC_ID = $id;
- $new->DOC_STATUS = 0;
- //保存图片 可以研究一下
- // \GuzzleHttp\Psr7\UploadedFile::
- @$img_url = $_FILES['BaseDocument']['name'][$key][$index]['IMG_URL'];
- if ($img_url && $img_url != '' && $img_url != Yii::$app->params['motorcadeDefaultImage']) {
- $new->image = UploadedFile::getInstances($new, "[$key][$index]IMG_URL");
- $base_path = Yii::$app->basePath . '/web' . Yii::$app->params['motorcadeImagePath'];
- // 如果路径中的文件夹不存在,则新建这一文件夹
- if (!is_dir($base_path)) {
- mkdir($base_path, 0777);
- }
- ini_set("memory_limit", "-1"); //图片分辨率生成缩略图时,会占用内存,这里设置无限制
- //获取文件名
- $file_name = zzcsUtils::initFileName($base_path, '.' . $new->image[0]->extension);
- $new->image[0]->saveAs($base_path . $file_name);
- $thumbnail_prefix = BaseDocument::THUMBNAIL_WIDTH . 'x' . BaseDocument::THUMBNAIL_HEIGHT;
- Image::thumbnail($base_path . $file_name, BaseDocument::THUMBNAIL_WIDTH, BaseDocument::THUMBNAIL_HEIGHT)
- ->save(
- $base_path . $thumbnail_prefix . '_' . $file_name,
- ['quality' => BaseDocument::THUMBNAIL_QUALITY]);
-
- $new->IMG_THUMBNAIL = Yii::$app->params['motorcadeImagePath'] . $thumbnail_prefix . '_' . $file_name;
- $new->IMG_URL = Yii::$app->params['motorcadeImagePath'] . $file_name;
- }
- $docArray[] = $new;
- }
-
- foreach ($docArray as $item) {
- // //设置之前的cancel_flag为1
- // $oldOne = BaseDocument::findOne(['DOC_TYPE' => BaseDocument::DRIVER, 'DOC_ID' => $item->DOC_ID, 'DOC_OPTION' => $item->DOC_OPTION, 'IMG_OPTION' => $item->IMG_OPTION,]);
- // if ($oldOne !== null) {
- // $oldOne->delete();
- // }
- if ($item->save()) {
- $result = true;
- }
- }
- }
-
- if ($result) {
- Yii::$app->session->setFlash('success', '保存成功!');
- $this->redirect('/motorcade/base-bus/check-bus?bus_id=' . $id . '&tab=tab2');
- } else {
- Yii::$app->session->setFlash('error', '保存失败!');
- return false;
- }
- // return $this->redirect("/motorcade/driver/update?id=$id&act=doc");
- }
-
- public function actionGetMaintain()
- {
- $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : '';
- $bus_id = isset($_REQUEST['bus_id']) ? $_REQUEST['bus_id'] : '';
- // wb 为515 为保养 为589为维修 默认为保养;
- $wb = isset($_REQUEST['wb'])?$_REQUEST['wb']:515;
- //end 表单提交
- //有bus_id则为添加,有id则为修改
- if ($id == '') {
- $model[] = new BaseDocument(['scenario' => 'bus-maintain']);
- $model[] = new BaseDocument(['scenario' => 'bus-maintain']);
- } else {
- $tmp = BaseDocument::findOne($id);
- $model = BaseDocument::find()->where(['DOC_TYPE' => BaseDocument::BUS, 'CANCEL_FLAG' => 0, 'DOC_OPTION' => $wb])->andWhere(['or', ['ID' => $id], ['PID' => $id]])->all();
- }
- return $this->render('_images_maintain', ['model' => $model, 'id' => $id, 'bus_id' => $bus_id,'wb'=>$wb]);
- }
-
- public function action_maintain_image($id)
- {
- $op = isset($_REQUEST['op']) ? $_REQUEST['op'] : '';
- //获取处理完成后的tab页
- $tab = isset($_REQUEST['tab']) ? $_REQUEST['tab'] : 'tab1';
- //表单提交
- $result = false;
- $model = $this->findModel($id);
- if ($model === null) {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- $documents = Yii::$app->request->post('BaseDocument');
- $pid = 0;
-
- foreach ($documents as $key => $document) {
- $expire_date = '';
- $start_date = '';
- $doc_man = '';
- $licheng = '';
- $res_id = '';
- $value = '';
- $docArray = [];
- foreach ($document as $index => $item) {
- if (isset($item['ID']) && $item['ID'] != '') {
- $new = BaseDocument::findOne($item['ID']);
- $new->setScenario('bus-maintain');
- } else
- $new = new BaseDocument(['scenario' => 'bus-maintain']);
-
- //设置有效期
- if ($expire_date == '') {
- $expire_date = isset($item['EXPIRE_DATE']) ? $item['EXPIRE_DATE'] : '';
- $start_date = isset($item['START_DATE']) ? $item['START_DATE'] : $start_date;
- $item['START_DATE'] = isset($item['START_DATE']) ? $item['START_DATE'] : $start_date;
- } else {
- $item['EXPIRE_DATE'] = $expire_date;
- $item['START_DATE'] = $start_date;
- }
- if ($doc_man == '') {
- $doc_man = isset($item['NAME']) ? $item['NAME'] : '';
- } else {
- $item['NAME'] = $doc_man;
- }
- if ($licheng == '') {
- $licheng = isset($item['LAST_MAINTAIN']) ? $item['LAST_MAINTAIN'] : '';
- } else {
- $item['LAST_MAINTAIN'] = $licheng;
- }
- if ($res_id == '') {
- $res_id = isset($item['RES_ID']) ? $item['RES_ID'] : '';
- } else {
- $item['RES_ID'] = $res_id;
- }
- if ($value == '') {
- $value = isset($item['VALUE']) ? $item['VALUE'] : '';
- } else {
- $item['VALUE'] = $value;
- }
- $new->setAttributes($item);
- $new->DOC_ID = $id;
- $new->DOC_STATUS = 0;
- $new->MT_STATUS = BaseDocument::WANCHENG;
- //保存图片 可以研究一下
- // \GuzzleHttp\Psr7\UploadedFile::
- @$img_url = $_FILES['BaseDocument']['name'][$key][$index]['IMG_URL'];
- if ($img_url && $img_url != '' && $img_url != Yii::$app->params['motorcadeDefaultImage']) {
- $new->image = UploadedFile::getInstances($new, "[$key][$index]IMG_URL");
- $base_path = Yii::$app->basePath . '/web' . Yii::$app->params['motorcadeImagePath'];
- // 如果路径中的文件夹不存在,则新建这一文件夹
- if (!is_dir($base_path)) {
- mkdir($base_path, 0777);
- }
- ini_set("memory_limit", "-1");
- //获取文件名
- $file_name = zzcsUtils::initFileName($base_path, '.' . $new->image[0]->extension);
- $new->image[0]->saveAs($base_path . $file_name);
- $thumbnail_prefix = BaseDocument::THUMBNAIL_WIDTH . 'x' . BaseDocument::THUMBNAIL_HEIGHT;
- Image::thumbnail($base_path . $file_name, BaseDocument::THUMBNAIL_WIDTH, BaseDocument::THUMBNAIL_HEIGHT)
- ->save(
- $base_path . $thumbnail_prefix . '_' . $file_name,
- ['quality' => BaseDocument::THUMBNAIL_QUALITY]);
-
- $new->IMG_THUMBNAIL = Yii::$app->params['motorcadeImagePath'] . $thumbnail_prefix . '_' . $file_name;
- $new->IMG_URL = Yii::$app->params['motorcadeImagePath'] . $file_name;
- }
- $docArray[] = $new;
- }
-
- foreach ($docArray as $item) {
- // //设置之前的cancel_flag为1
- // $oldOne = BaseDocument::findOne(['DOC_TYPE' => BaseDocument::DRIVER, 'DOC_ID' => $item->DOC_ID, 'DOC_OPTION' => $item->DOC_OPTION, 'IMG_OPTION' => $item->IMG_OPTION,]);
- // if ($oldOne !== null) {
- // $oldOne->delete();
- // }
- $item['PID'] = $pid;
- if ($item->save()) {
- $pid = $item['ID'];
- $result = true;
- }
- }
- }
- if ($result) {
- Yii::$app->session->setFlash('success', '保存成功!');
- } else {
- Yii::$app->session->setFlash('error', '保存失败!');
- }
- if ($op=='list'||$op=='detail'){
- return "<script>pjaxFinish('修改成功');</script>";
- }else{
- return $this->redirect("/motorcade/base-bus/check-bus?bus_id=$id&tab=$tab");
- }
-
- }
-
-
- /**
- * User: wangxj
- *
- * 加载保单数据
- *
- * @params $id integer
- *
- * @return string
- */
- public function action_image_insurance($id = '', $doc_id = '', $tab = 'tab2')
- {
-
- //保存保险
- if (Yii::$app->request->isPost) {
-
- $data = Yii::$app->request->post('BaseDocument');
- if ($data['ID'] == '') {
- $model = new BaseDocument(['scenario' => 'bus-insurance']);
- } else {
- $model = BaseDocument::findOne($id);
- $model->setScenario('bus-insurance');
- }
- $model->load(Yii::$app->request->post());
- if ($model->validate()) {
- @$img_url = $_FILES['BaseDocument']['name']['IMG_URL'];
- $model->DOC_STATUS = 0;
- if ($img_url && $img_url != '' && $img_url != Yii::$app->params['motorcadeDefaultImage']) {
- $model->image = UploadedFile::getInstances($model, "IMG_URL");
- $base_path = Yii::$app->basePath . '/web' . Yii::$app->params['motorcadeImagePath'];
- // 如果路径中的文件夹不存在,则新建这一文件夹
- if (!is_dir($base_path)) {
- mkdir($base_path, 0777);
- }
- ini_set("memory_limit", "-1");
- //获取文件名
- $file_name = zzcsUtils::initFileName($base_path, '.' . $model->image[0]->extension);
- $model->image[0]->saveAs($base_path . $file_name);
- $thumbnail_prefix = BaseDocument::THUMBNAIL_WIDTH . 'x' . BaseDocument::THUMBNAIL_HEIGHT;
- Image::thumbnail($base_path . $file_name, BaseDocument::THUMBNAIL_WIDTH, BaseDocument::THUMBNAIL_HEIGHT)
- ->save(
- $base_path . $thumbnail_prefix . '_' . $file_name,
- ['quality' => BaseDocument::THUMBNAIL_QUALITY]);
-
- $model->IMG_THUMBNAIL = Yii::$app->params['motorcadeImagePath'] . $thumbnail_prefix . '_' . $file_name;
- $model->IMG_URL = Yii::$app->params['motorcadeImagePath'] . $file_name;
-
- }
-
- Yii::$app->session->setFlash('success', '保存成功');
- $model->save();
- $this->redirect('/motorcade/base-bus/check-bus?bus_id=' . $model->DOC_ID . '&tab=' . $tab);
- } else {
- foreach ($model->getErrors() as $error):
- Yii::$app->session->setFlash('error', $error);
- endforeach;
- return $this->render('_images_insurance', ['model' => $model, 'DOC_ID' => $doc_id]);
- }
- } elseif (Yii::$app->request->isAjax) {
- $model = BaseDocument::findOne($id);
- if ($model == null) {
- $model = new BaseDocument(['scenario' => 'bus-insurance']);
- } else {
- $model->setScenario('bus-insurance');
- }
- return $this->render('_images_insurance', ['model' => $model, 'DOC_ID' => $doc_id]);
- }
- }
-
- // public function actionSeatType()
- // {
- // return $this->render('_checkBus',['seat_type'=>$_REQUEST['seat_type']]);
- // }
- //删除保单,或保险
- public function actionMaintainDelete($id, $bus_id, $tab)
- {
- $model = BaseDocument::updateAll(['CANCEL_FLAG' => 1], ['or', ['ID' => $id], ['PID' => $id]]);
- if ($model != 0) {
- Yii::$app->session->setFlash('success', '删除成功');
- } else {
- Yii::$app->session->setFlash('warning', '删除失败');
- }
- return $this->redirect(['/motorcade/base-bus/check-bus?bus_id=' . $bus_id . '&tab=' . $tab]);
- }
- }
|