|
- <?php
-
- namespace backend\modules\zzcs\controllers;
-
- use Yii;
- use yii\web\Controller;
- use backend\modules\zzcs\models\BaseBus;
- use backend\modules\zzcs\models\BaseSupplier;
- use backend\modules\zzcs\models\BaseResource;
- use backend\modules\zzcs\models\DictType;
- use common\models\zzcsUtils;
- use yii\base\Exception;
- use backend\modules\zzcs\models\BaseUser;
-
- class CarController extends Controller
- {
- public $enableCsrfValidation = false;
- public $layout = '@backend/modules/zzcs/views/layouts/zzcs';
-
- /**
- * Function Description:
- * Function Name: actionIndex
- *
- * @return string
- *
- * @author 温依莅
- */
- public function actionIndex()
- {
- return $this->render('index');
- }
-
- /**
- * Function Description:获取车辆列表
- * Function Name: actionList
- *
- * @return string
- *
- * @author 温依莅
- */
- public function actionList()
- {
- $supplier = new BaseSupplier();
- $busInfo = new BaseBus();
-
- Yii::$app->view->title = '车辆列表';
- $request = Yii::$app->request;
-
- //1.获取get参数
- $bus_no = $request->get('bus_no', '');
- $car_team = $request->get('car_team', -1);
- $team_no = $request->get('team_no', -1);
- $brand = $request->get('brand', -1);
- $page_size = $request->get('page_size', 10);
- $current_page = $request->get('current_page', 1);
-
- //2.品牌列表
- $brand_list = BaseResource::find()->select(['res_id', 'res_name'])->where(['res_type_id' => 134, 'cancel_flag' => 0])->asArray()->all();
- //3.车队列表
-
- $motorcade_list = $supplier->getMotorcadeInfo();
-
-
- $data['brand_list'] = $brand_list;
- $data['motorcade_list'] = $motorcade_list;
- //4.列表信息
- $tempData = $busInfo->getBusList($bus_no, $car_team, $team_no, $brand, $page_size, $current_page);
-
- return $this->render('list', ['data' => $data, 'listData' => $tempData['bus_list'], 'param' => $tempData['param'], 'page_arr' => $tempData['page_arr']]);
- }
-
- /**
- * @return array
- * 品牌列表
- */
- public function actionBrandList()
- {
- try {
- $brand_list = BaseResource::find()->select(['res_id', 'res_name'])->where(['res_type_id' => 134, 'cancel_flag' => 0])->asArray()->all();
- $json["code"] = '0';
- $json["info"] = '获取成功';
- $json['data'] = $brand_list;
- return json_encode($json);
- } catch (Exception $e) {
- $json["code"] = '1';
- $json["info"] = '品牌获取失败';
- return json_encode($json);
- }
- }
-
- /**
- * @return array
- * 客座数选项
- * seat-num-list
- */
- public function actionSeatNumList()
- {
- $request = Yii::$app->request;
- $parent_id = $request->post('parent_id');
- try {
- $list = BaseResource::find()->select(['res_id', 'res_name'])->where(['res_type_id' => 69, 'cancel_flag' => 0, 'parent_id' => $parent_id])->orderBy(['res_name' => SORT_ASC])->asArray()->all();
- $json["code"] = '0';
- $json["info"] = '获取座位数列表成功';
- $json['data'] = $list;
- return json_encode($json);
- } catch (Exception $e) {
- $json["code"] = '1';
- $json["info"] = '获取座位数列表失败';
- return json_encode($json);
- }
- }
-
-
-
- /**
- * Function Description:获取车辆详情
- * Function Name: actionGetBaseInfo
- *
- * @return bool
- *
- * @author 温依莅
- */
- public function actionGetBaseInfo()
- {
- try {
- //1.品牌列表
- $brand_list = BaseResource::find()->select(['res_id', 'res_name'])->where(['res_type_id' => 134, 'cancel_flag' => 0])->asArray()->all();
-
- $supplier = new BaseSupplier();
- $motorcade_list = $supplier->getMotorcadeInfo();
- //2.车辆颜色
- $color_list = BaseResource::find()->select(['res_id', 'res_name'])->where(['res_type_id' => 338, 'cancel_flag' => 0])->asArray()->all();
- //3.座位类型
- $seat_type = BaseResource::find()->select(['b.id as seat_id', 'b.type_name'])->distinct()->from('base_resource a')->leftJoin('dict_type as b', 'a.parent_id=b.id')->where(['a.res_type_id' => 69, 'cancel_flag' => 0])->asArray()->all();
- //4.车辆图片类型
- $pic_type = DictType::find()->select(['id as img_id', 'type_name'])->where(['parent_id' => 360])->asArray()->all();
- } catch (Exception $e) {
- return false;
- }
- $data['brand_list'] = $brand_list;
- $data['motorcade_list'] = $motorcade_list;
- $data['color_list'] = $color_list;
- $data['seat_type'] = $seat_type;
- $data['pic_type'] = $pic_type;
- return $data;
- }
-
- /**
- * Function Description:添加车辆页面
- * Function Name: actionAdd
- *
- * @return string
- *
- * @author 温依莅
- */
- public function actionAdd()
- {
- Yii::$app->view->title = '添加车辆';
- $data = $this->actionGetBaseInfo();
- if (false === $data) {
-
- }
- return $this->render('add', ['baseData' => $data]);
- }
-
-
- /*==================================================================ajax=======================================================================================*/
-
-
- /**
- * Function Description:添加车辆ajax
- * Function Name: actionAddConfirm
- *
- * @return string
- *
- * @author 温依莅
- */
- public function actionAddConfirm()
- {
- $request = Yii::$app->request;
- $baseBus = new BaseBus();
-
- try {
- $imgMeta = zzcsUtils::uploadMultiple('bus_img');
- } catch (Exception $e) {
- $json = array();
- $json["code"] = "1";
- $json["info"] = "图片上传失败!";
- return json_encode($json);
- }
- $imgType = '';
- $imgPath = '';
- if ($imgMeta) {
- $imgType = $imgMeta['type'];
- $imgPath = $imgMeta['path'];
- }
-
- $user_id = $request->cookies->getValue('user_id', 0);;//用户id
-
- //运营主体
- $main_corp_id = BaseUser::find()->select('main_corp_id')->where(['id' => $user_id,'cancel_flag' => 0])->asArray()->one();
-
- $bus_number = $request->post("bus_number");//车牌号
- $bus_team = $request->post("bus_team");//车队
- $bus_brand = $request->post("bus_brand");//品牌
- $bus_version = $request->post("bus_version");//型号
- $buy_date = $request->post("buy_date");//购买日期
- $seat_type = $request->post("seat_type");//座位类型
- $seat_number = $request->post("seat_number");//座位数量res_id
- $seat_real_number = $request->post("seat_real_number");//座位数量
- $driver = $request->post("driver");//司机
- $guider = $request->post("guider");//导游
- $auxiliary_seat = $request->post("auxiliary_seat");//辅座
- $consumption = $request->post("consumption");//油耗
- $res_date = $request->post("res_date");//注册登记日期
- $day_cost = $request->post("day_cost");//成本
- $status_select = $request->post("status_select");//状态
- $bus_color = $request->post("bus_color");//颜色
- $bus_desc = $request->post("bus_desc");//车型描述
- //$bus_img_type = $request->post("bus_img_type");//车辆图片类型
- if ($bus_number === false || $bus_team === false || $bus_brand === false || $bus_version === false || $buy_date === false || $seat_type === false || $seat_number === false || $driver === false || $guider === false || $auxiliary_seat === false || $consumption === false || $day_cost === false || $status_select === false || $bus_color === false || $bus_desc === false) {
- $json["code"] = "2";
- $json["info"] = "缺少必要参数";
- return json_encode($json);
- } else {
- //座位数量前台没有传入具体数值
- $seat_count = preg_replace('/[^\d]/', '', $seat_real_number);
- if (empty($driver)) {
- $driver = '';
- }
- if (empty($guider)) {
- $guider = '';
- }
- if (empty($auxiliary_seat)) {
- $auxiliary_seat = '';
- }
- if (empty($consumption)) {
- $consumption = '';
- }
- if (empty($day_cost)) {
- $day_cost = '';
- }
- if (empty($bus_color)) {
- $bus_color = 0;
- }
- $tmpArray = explode(',', $imgPath);
- $newArray = array_reverse($tmpArray);
- $csArray = array();
- foreach ($newArray as $k => $v) {
- if ($v) {
- $csArray[$k] = 'http://' . CS1_DOMAIN .'' . $v;
- }
- }
- $imgPath = implode(',', $newArray);
- $imgPath2 = implode(',', $csArray);
-
- $tmpArray = explode(',', $imgType);
- $newArray = array_reverse($tmpArray);
- $imgType = implode(',', $newArray);
- $values = [
- 'CREATE_USER_ID' => $user_id,
- 'CREATE_TIME' => date('Y-m-d H:i:s', time()),
- 'UPDATE_USER_ID' => $user_id,
- 'UPDATE_TIME' => date('Y-m-d H:i:s', time()),
- 'CANCEL_FLAG' => 0,
- 'BUS_NO' => $bus_number,
- 'BUS_TYPE_RES_ID' => $seat_number,
- 'SEAT_COUNT' => $seat_count,
- 'BRAND_ID' => $bus_brand,
- 'ORG_ID' => $bus_team,
- 'SEAT_DESC' => $bus_desc,
- 'BUY_DATE' => $buy_date,
- 'BUS_LICENSE' => $bus_version,
- 'DRIVER_COUNT' => $driver,
- 'TOUR_COUNT' => $guider,
- 'EXTRA_COUNT' => $auxiliary_seat,
- 'MPG' => $consumption,
- 'REGISTER_TIME' => $res_date,
- 'COST' => $day_cost,
- 'BUS_STATE' => $status_select,
- 'SEAT_TYPE' => $seat_type,
- 'BUS_COLOR' => $bus_color,
- //'BUS_IMG_TYPE' => $bus_img_type,
- 'BUS_IMG_PATH_ORI' => $imgPath,
- 'BUS_IMG_PATH' => $imgPath2,
- 'BUS_IMG_TYPE' => $imgType,
- 'MAIN_CORP_ID' => $main_corp_id['main_corp_id'],//运营主体
- ];
- $baseBus->attributes = $values;
- try {
- $res = $baseBus->insert();
- if (!$res) {
- $json = array();
- $json["code"] = "2";
- $json["info"] = "新增车辆失败!";
- $json["error"] = $baseBus->getErrors();
- return json_encode($json);
- }
- } catch (Exception $e) {
- $json = array();
- $json["code"] = "1";
- $json["info"] = "新增车辆失败!";
- return json_encode($json);
- }
- $json = array();
- $json["code"] = "0";
- $json["info"] = "新增车辆成功!";
- return json_encode($json);
-
- }
-
- }
-
- /**
- * Function Description:修改车辆信息
- * Function Name: actionModifyConfirm
- *
- * @return string
- *
- * @author 张帅
- */
- public function actionModifyConfirm()
- {
- $request = Yii::$app->request;
- $user_id = $request->cookies->getValue('user_id', 0);;//用户id
- $bus_id = $request->post("bus_id");//需要更新的bus_id
- $bus_number = $request->post("bus_number");//车牌号
- $bus_team = $request->post("bus_team");//车队
- $bus_brand = $request->post("bus_brand");//品牌
- $bus_version = $request->post("bus_version");//型号
- $buy_date = $request->post("buy_date");//购买日期
- $seat_type = $request->post("seat_type");//座位类型
- $seat_number = $request->post("seat_number");//座位数量res_id
- $seat_real_number = $request->post("seat_real_number");//座位数量
- $driver = $request->post("driver");//司机
- $guider = $request->post("guider");//导游
- $auxiliary_seat = $request->post("auxiliary_seat");//辅座
- $consumption = $request->post("consumption");//油耗
- $res_date = $request->post("res_date");//注册登记日期
- $day_cost = $request->post("day_cost");//成本
- $status_select = $request->post("status_select");//状态
- $bus_color = $request->post("bus_color");//颜色
- $bus_desc = $request->post("bus_desc");//车型描述
- $old_path = '';
- $old_type = '';
- $img_path_old = $request->post('bus_img_path_old');
- $img_type_old = $request->post('bus_img_type_old');
- if (isset($img_path_old)) {
- foreach ($img_path_old as $key => $item) {
- if ($item != '' || $img_type_old[$key] != '') {
- $type = $img_type_old[$key];
- if ($old_path == '') {
- $old_path .= $item;
- $old_type .= $type;
- } else {
- $old_path .= ',' . $item;
- $old_type .= ',' . $type;
- }
-
- }
- }
- }
- if ($bus_id === false || $bus_number === false || $bus_team === false || $bus_brand === false || $bus_version === false || $buy_date === false || $seat_type === false || $seat_number === false || $driver === false || $guider === false || $auxiliary_seat === false || $consumption === false || $day_cost === false || $status_select === false || $bus_color === false || $bus_desc === false) {
- $json = array();
- $json["code"] = "2";
- $json["info"] = "缺少必要参数";
- return $json;
- } else {
- //座位数量前台没有传入具体数值
- //$seat_count = preg_replace('/[^\d]/', '', $bus_desc);
- $seat_count = preg_replace('/[^\d]/', '', $seat_real_number);
- //更新操作
- if (empty($driver)) {
- $driver = '';
- }
- if (empty($guider)) {
- $guider = '';
- }
- if (empty($auxiliary_seat)) {
- $auxiliary_seat = '';
- }
- if (empty($consumption)) {
- $consumption = '';
- }
- if (empty($day_cost)) {
- $day_cost = '';
- }
- if (empty($bus_color)) {
- $bus_color = 0;
- }
- $imgType = '';
- $imgPath = '';
- $imgMeta = zzcsUtils::uploadMultiple('bus_img');
- if ($imgMeta) {
- $imgType = $imgMeta['type'];
- $imgPath = $imgMeta['path'];
- }
- $imgPath = $old_path == '' ? $imgPath : $old_path . ($imgPath != '' ? (',' . $imgPath) : '');
- $imgType = $old_type == '' ? $imgType : $old_type . ($imgType != '' ? (',' . $imgType) : '');
-
- $tmpArray = explode(',', $imgPath);
- $newArray = array_reverse($tmpArray);
- $csArray = array();
- foreach ($newArray as $k => $v) {
- if ($v) {
- $csArray[$k] = 'http://' . CS1_DOMAIN .'' . $v;
- }
- }
- $imgPath = implode(',', $newArray);
- $imgPath2 = implode(',', $csArray);
-
- $tmpArray = explode(',', $imgType);
- $newArray = array_reverse($tmpArray);
- $imgType = implode(',', $newArray);
-
- //删除旧图片
- zzcsUtils::deleteFiles($request->post('bus_img_allpath_old'), $imgPath);
- //更新数据
- $values = [
- 'UPDATE_USER_ID' => $user_id,
- 'UPDATE_TIME' => date('Y-m-d H:i:s', time()),
- 'BUS_NO' => $bus_number,
- 'BUS_TYPE_RES_ID' => $seat_number,
- 'SEAT_COUNT' => $seat_count,
- 'BRAND_ID' => $bus_brand,
- 'ORG_ID' => $bus_team,
- 'SEAT_DESC' => $bus_desc,
- 'BUY_DATE' => $buy_date,
- 'BUS_LICENSE' => $bus_version,
- 'DRIVER_COUNT' => $driver,
- 'TOUR_COUNT' => $guider,
- 'EXTRA_COUNT' => $auxiliary_seat,
- 'MPG' => $consumption,
- 'REGISTER_TIME' => $res_date,
- 'COST' => $day_cost,
- 'BUS_STATE' => $status_select,
- 'SEAT_TYPE' => $seat_type,
- 'BUS_COLOR' => $bus_color,
- 'BUS_IMG_PATH_ORI' => $imgPath,
- 'BUS_IMG_PATH' => $imgPath2,
- 'BUS_IMG_TYPE' => $imgType,
- ];
- $specBus = BaseBus::findOne(['bus_id' => $bus_id, 'cancel_flag' => 0]);
- $specBus->attributes = $values;
- //$specBus->save(false);
- try {
- $res = $specBus->update();
- if (!$res) {
- $json = array();
- $json["code"] = "2";
- $json["info"] = "修改车辆信息失败!";
- $json["error"] = $specBus->getErrors();
- return json_encode($json);
- }
- } catch (Exception $e) {
- $json = array();
- $json["code"] = "1";
- $json["info"] = "修改车辆信息失败!";
- return json_encode($json);
- }
- $json = array();
- $json["code"] = "0";
- $json["info"] = "修改车辆信息成功!";
- return json_encode($json);
- }
- }
-
- /**
- * Function Description:修改车辆
- * Function Name: actionModify
- *
- * @return string
- *
- * @author 温依莅
- */
- public function actionModify()
- {
- $request = Yii::$app->request;
- $type = $request->get('type', '');
- if ($type) {
- Yii::$app->view->title = '查看车辆';
- } else {
- Yii::$app->view->title = '编辑车辆';
- }
- $data = $this->actionGetBaseInfo();
- $bus_info = BaseBus::find()->where(['bus_id' => $request->get('bus_id'), 'cancel_flag' => 0])->asArray()->one();
- $bus_info = array_change_key_case($bus_info, CASE_LOWER);
- //这里要对图片做特别的处理
- $data['bus_info'] = $bus_info;
- $data['seat_num_list'] = BaseResource::find()->select(['res_id', 'res_name'])->where(['res_type_id' => 69, 'cancel_flag' => 0, 'parent_id' => $bus_info['seat_type']])->orderBy(['res_name' => SORT_ASC])->asArray()->all();
- return $this->render('modify', ['baseData' => $data, 'type' => $type]);
- }
-
- /**
- * Function Description:获取图片ajax
- * Function Name: actionGetImages
- *
- * @return string
- *
- * @author 温依莅
- */
- public function actionGetImages()
- {
- $request = Yii::$app->request;
- try {
- $arr = BaseBus::find()->select(['register_time', 'bus_img_path_ori', 'bus_img_type'])->where(['bus_id' => $request->post('bus_id'), 'cancel_flag' => 0])->asArray()->one();
- $img_info = array_change_key_case($arr, CASE_LOWER);
- //print_r($img_info);exit;
- $json["code"] = '0';
- $json["info"] = '获取图片信息成功';
- $json['data'] = $img_info;
- return json_encode($json);
- } catch (Exception $e) {
- $json["code"] = '1';
- $json["info"] = '获取图片信息失败';
- return json_encode($json);
- }
- }
-
- /**
- * Function Description:删除车辆ajax
- * Function Name: actionDelete
- *
- * @return string
- *
- * @author 温依莅
- */
- public function actionDelete()
- {
- $request = Yii::$app->request;
- $bus_id = $request->post("bus_id");//需要更新的bus_id
- $specBus = BaseBus::findOne(['bus_id' => $bus_id, 'cancel_flag' => 0]);
- $specBus->CANCEL_FLAG = 1;
- try {
- $res = $specBus->update();
- if (!$res) {
- $json = array();
- $json["code"] = "2";
- $json["info"] = "删除车辆信息失败!";
- $json["error"] = $specBus->getErrors();
- return json_encode($json);
- }
- } catch (Exception $e) {
- $json = array();
- $json["code"] = "1";
- $json["info"] = "删除车辆信息失败!";
- return json_encode($json);
- }
- $json = array();
- $json["code"] = "0";
- $json["info"] = "已删除";
- return json_encode($json);
- }
- }
|