|
- <?php
-
- namespace backend\modules\motorcade\controllers;
-
- use backend\modules\motorcade\components\BaseComponent;
- use backend\modules\motorcade\components\LogComponent;
- use backend\modules\motorcade\models\BaseDriver;
- use common\models\Utils;
- use function GuzzleHttp\Psr7\str;
- use yii\base\Exception;
-
- use backend\modules\motorcade\models\BusDepartment;
- use backend\modules\motorcade\models\BusDocLog;
- use backend\modules\motorcade\models\BusItinerary;
- use backend\modules\motorcade\models\BusOilDoc;
- use backend\modules\motorcade\models\BusOrderSearch;
- use backend\modules\motorcade\models\BusOrderStatusLog;
- use backend\modules\motorcade\models\BusReport;
- use backend\modules\motorcade\models\RunBusExpenses;
- use backend\modules\zzcs\models\BaseResource;
- use backend\modules\zzcs\models\RunBus;
- use common\components\zHttp;
- use common\models\BaseMainCorporation;
- use Yii;
- use backend\modules\motorcade\models\BusOrder;
- use backend\modules\motorcade\models\BaseBus;
- use yii\data\ActiveDataProvider;
- use yii\data\SqlDataProvider;
- use yii\helpers\ArrayHelper;
- use yii\helpers\Json;
- use yii\web\NotFoundHttpException;
- use yii\filters\AccessControl;
- use yii\filters\VerbFilter;
- use backend\modules\api\controllers\DriverController;
- use backend\modules\api\models\RunBusExpenses as BusExpense;
-
- /**
- * BusController implements the CRUD actions for BusOrder model.
- */
- class BusController extends BaseController
- {
- public $layout = "@backend/modules/motorcade/views/layouts/iframe_new";
-
- /**
- * @inheritdoc
- */
- public function behaviors()
- {
- return [
- 'access' => [
- 'class' => AccessControl::className(),
- 'rules' => [
- [
- 'actions' => ['index', 'add-bus-view', 'add-bus', 'detail', 'car-list', 'depart', 'add-bus-depart', 'search',
- 'cancel', 'resend', 'line-status', 'cancel1', 'bus-dispatch', 'save-bus', 'save-finance', 'send', 'test',
- 'sure', 'reject', 'reset', 'bus-resource', 'send-outside', 'batch', 'order-copy', 'sync-one'], 'allow' => true,
- ],
- [
- 'actions' => ['sync-bus-order', 'sync-bus-order-tem', 'simulation-bus', 'end-bus'], 'allow' => true,
- ],
- ],
- ],
- 'verbs' => [
- 'class' => VerbFilter::className(),
- 'actions' => [
- 'delete' => ['POST'],
- 'cancel' => ['POST'],
- ],
- ],
- ];
- }
-
- /**
- * Lists all BusOrder models.
- * @return mixed
- */
- public function actionIndex()
- {
- $searchModel = new BusOrderSearch();
- $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
- $dataProvider->pagination->pageSize = 10;
-
- return $this->render('index', [
- 'searchModel' => $searchModel,
- 'dataProvider' => $dataProvider,
- ]);
- }
-
- /**
- * Creates a new BusOrder model.
- * If creation is successful, the browser will be redirected to the 'view' page.
- * @return mixed
- */
- public function actionCreate()
- {
- $model = new BusOrder();
-
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- return $this->redirect(['view', 'id' => $model->id]);
- } else {
- return $this->render('create', [
- 'model' => $model,
- ]);
- }
- }
-
- /**
- * User: wangxj
- *
- * 订单详情
- *
- * @param integer $id
- *
- * @return string
- */
- public function actionDetail($id)
- {
- $model = $this->findModel($id);
- $data['bus_type'] = $model->getBusType(); //用车类型
- $data['bus_depart'] = $model->getBusdepartment();
- $data['bus_log'] = $model->getLogInfo($model->bus_number);
- $single = ArrayHelper::index($data['bus_depart']['data'], 'ID', 'settle_type');
- $data['bus_depart']['data'] = ArrayHelper::map($data['bus_depart']['data'], 'ID', 'depart_name');
- if (!isset($data['bus_depart']['data'][$model->use_bus_org_id])) {
- $tmpModel = BusDepartment::findOne($model->use_bus_org_id);
- if ($tmpModel != null) {
- $data['bus_depart']['data'] += [$tmpModel->ID => $tmpModel->depart_name];
- }
- }
- //用车单位结算类型为单结
-
- $single = isset($single['292']) ? $single['292'] : [];
- $single_arr = [];
- if (!empty($single)) {
- $single_arr = array_keys($single);
- }
- $data['bus_depart']['single'] = $single_arr;
- return $this->render('detail', [
- 'model' => $model,
- 'data' => $data
- ]);
- }
-
- /**
- * User: wangxj
- *
- * 取消出车,只能通过ajax调用
- *
- * @params $id integer
- *
- * @return string
- */
- public function actionCancel()
- {
-
- $post = Yii::$app->request->post();
- if (isset($post['id'])) {
- $model = $this->findModel(Yii::$app->request->post('id'));
- //订单状态不可取消
- if ($model->run_status > 436) {
- $result = ['code' => 1, 'data' => ['msg' => '订单当前状态不可取消']];
- } else {
- $model->run_status = 439;
- $model->send_bus_res_id = null;
- $model->send_bus_driver_res_id = null;
- $model->send_type = 0;
- $model->setScenario('cancel');
- if ($model->save()) {
- //如果是从巴士同步过来的出车任务,run_id不为0,取消出车任务要操作run_bus表
- if ($model->run_id != 0) {
- $run_bus = RunBus::findOne(['cancel_flag' => 0, 'run_id' => $model->run_id, 'bus_order_id' => $model->bus_order_id]);
- if ($run_bus) {
- $run_bus->SEND_STATUS = 144;
- $run_bus->SEND_BUS_RES_ID = 0;
- $run_bus->SEND_BUS_NO = '';
- $run_bus->SEND_BUS_DRIVER_RES_ID = 0;
- $run_bus->SEND_DRIVER_NAME = '';
- $run_bus->SEND_DRIVER_MOBILE = '';
- $run_bus->save();
- }
- }
-
- $result = ['code' => 0, 'data' => ''];
- LogComponent::addLog($model->bus_number, LOG_TYPE_ORDER, '取消出车任务,取消成功', 'run_status', $model->run_status);
- } else {
- $result = ['code' => 1, 'data' => $model->getFirstErrors()];
- }
-
- }
-
- } else {
- $result = ['code' => 400, 'data' => ['msg' => '缺少参数']];
- }
-
- $test = Json::encode($result);
- return $test;
- }
-
- /**
- * 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 BusOrder the loaded model
- * @throws NotFoundHttpException if the model cannot be found
- */
- protected function findModel($id)
- {
- if (($model = BusOrder::findOne($id)) !== null) {
- $model->run_status_name = BusOrder::bus_order_status_array[$model->run_status];
- $model->send_status_name = BusOrder::bus_order_status_array[$model->send_status];
- $model->finance_status_name = BusOrder::bus_order_status_array[$model->finance_status];
- $model->end_status_name = BusOrder::bus_order_status_array[$model->end_status];
- return $model;
- } else {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
-
- /**
- * User:Steven
- * 保存出车任务
- *
- * @return string
- */
- public function actionAddBus()
- {
- $bus_order = new BusOrder();
- $res = false;
- if (Yii::$app->request->isPost) {
- $bus_order->load(Yii::$app->request->post());
- $BusIt = array_values(Yii::$app->request->post('BusItinerary'));
- $bus_order->itinerary_list = [];
- foreach ($BusIt as $key => $item) {
- $BusItinerary = new BusItinerary();
- $BusItinerary->setAttributes($item);
- // if ($BusItinerary->validate()) {
- // $res = false;
- // }
- $bus_order->itinerary_list[] = $BusItinerary;
- }
- $res = $bus_order->addBus();
- if ($res) {
- Yii::$app->session->setFlash('success', "出车任务添加成功!");
- } else {
- Yii::$app->session->setFlash('error', "出车任务添加失败!");
- }
- // $bus_order = new BusOrder();
- // $BusItinerary = new BusItinerary();
- // $bus_order->itinerary_list[] = $BusItinerary;
- }
- if (empty($bus_order->itinerary_list)) {
- $BusItinerary = new BusItinerary();
- $bus_order->itinerary_list[] = $BusItinerary;
- }
- $bus_list = BaseBus::find()->select(['BUS_ID', 'BUS_NO'])->where(['CANCEL_FLAG' => 0, 'BUS_STATE' => BaseBus::BUS_STATUS_NORMAL, 'ORG_ID' => Yii::$app->user->identity->ORG_ID, 'BUS_BELONG' => BaseBus::BUS_BELONG_OWN])->asArray()->all();
- $driver_list = BaseDriver::find()->select(['DRIVER_ID', 'DRIVER_NAME'])->where(['CANCEL_FLAG' => 0, 'DRIVER_STATUS' => BaseDriver::DRIVER_STATUS_NORMAL, 'ORG_ID' => Yii::$app->user->identity->ORG_ID])->asArray()->all();
- $data['data']['result'] = $res;
- $data['data']['model'] = $bus_order;
- $data['data']['bus_list'] = $bus_list;
- $data['data']['driver_list'] = $driver_list;
- $data['data']['bus_type'] = $bus_order->getBusType(); //用车类型
- $data['data']['bus_depart'] = $bus_order->getBusdepartment();
- return $this->render('bus', ['view' => 'addBus', 'data' => $data]);
- }
-
- /**
- * User:Steven
- * 车辆调度
- *
- * @return string
- */
- public function actionBusDispatch()
- {
- $searchModel = new BusOrderSearch();
- $base_bus = new BaseBus();
- $data['data']['order_list'] = $searchModel->search(Yii::$app->request->queryParams);
- $data['data']['searchModel'] = $searchModel;
- $key_driver = isset($_GET['key_driver']) ? $_GET['key_driver'] : '';
- $key_bus = isset($_GET['key_bus']) ? $_GET['key_bus'] : '';
- $key = isset($_GET['key']) ? $_GET['key'] : '';
- $key1 = isset($_GET['key1']) ? $_GET['key1'] : '';
- $date = isset($_GET['date']) ? $_GET['date'] : '';
- $data['data']['active'] = isset($_GET['active']) ? $_GET['active'] : 'bus';
- $data['data']['bus_list'] = $base_bus->GetBusList($key_bus, $key, $date);
- $data['data']['convoy'] = $base_bus->getConvoy();
- $data['data']['driver'] = $base_bus->getDriver($key_driver, $date, $key1);
- $data['data']['searchDate'] = $date;
- $data['data']['driver_bus_search'] = ['key_driver' => $key_driver, 'key_bus' => $key_bus, 'key' => $key];
- if (Yii::$app->request->isAjax)
- return $this->renderPartial('bus', ['view' => 'busDispatch', 'data' => $data]);
- else
- return $this->render('bus', ['view' => 'busDispatch', 'data' => $data]);
- }
-
-
- /**
- * User:Steven
- * 添加用车单位
- *
- * @return string
- */
- public function actionAddBusDepart()
- {
- $bus_depart = new BusDepartment();
- if (Yii::$app->request->isPost) {
- $bus_depart->cancel_flag = 0;
- $bus_depart->main_cooperation_id = Yii::$app->user->identity->MAIN_CORP_ID2;
- $bus_depart->load(Yii::$app->request->post());
-
- $result = $bus_depart->save();
- if ($result) {
- $result = ['code' => 0, 'data' => $result];
- } else {
- $error = $bus_depart->getErrors();
- $result = ['code' => 1, 'data' => $error];
- }
- return Json::encode($result);
- }
- return true;
- }
-
-
- public function actionCarList($op = 'ready')
- {
- $searchModel = new BusOrderSearch();
- $search = Yii::$app->request->queryParams;
- if (empty($search)) {
- $search['BusOrderSearch']['start_date'] = date('Y-m-d', strtotime('this week'));
- $search['BusOrderSearch']['end_date'] = date('Y-m-d', strtotime('last day next week'));
- }
- $dataProvider = $searchModel->searchList($search);
- return $this->render('carList', [
- 'searchModel' => $searchModel,
- 'dataProvider' => $dataProvider,
- ]
- );
- }
-
-
- /**
- * User:Steven
- * Desc:复制出车功能
- * @return string
- */
- public function actionOrderCopy()
- {
- $model = new BusOrder();
- $bus_order_id = Yii::$app->request->get('id');
- if (Yii::$app->request->isPost) {
- $conn = Yii::$app->db;
- $param = Yii::$app->request->post();
- $res = $this->dataService($param);
- // $ori_order = BusOrder::findOne(['id' => $bus_order_id]);
- $ori_order = BusOrder::find()->select(['create_user_id', 'bus_number', 'use_bus_org_id', 'motorcade_id', 'task_type', 'bus_type_res_id', 'seat_count', 'itinerary_id', 'itinerary_name', 'line_type', 'day_num',
- 'bus_cost_type', 'bus_cost', 'remark', 'send_type', 'send_cost', 'send_bus_res_id', 'send_bus_driver_res_id', 'contacts', 'tels'])->where(['id' => $bus_order_id])->one();
- $transaction = $conn->beginTransaction(); //开始事务
- try {
- foreach ($res as $item) {
- $bus_order = new BusOrder();
- $bus_order->setAttributes($ori_order->getAttributes());
- $bus_order->create_time = date('Y-m-d H:i:s');
- $bus_order->run_date = $item['run_date'];
- $bus_order->start_time = $item['start_time'];
- $bus_order->saled_count = 0;
- $get_unique_id = "select func_get_unique_id(5,1) as unique_id"; //得到新的出车任务ID
- $data_id = $conn->createCommand($get_unique_id)->queryAll();
- $bus_order->bus_number = $data_id[0]['unique_id'];
- $bus_order->itinerary_id = $data_id[0]['unique_id'];
- $bus_order->run_bus_id = 0;
- $bus_order->run_id = 0;
- $bus_order->bus_order_id = 0;
- $bus_order->run_status = 434; //出车状态
- $bus_order->finance_status = 444; //报账状态
- $bus_order->send_status = 441;
- if (!isset($param['choosebus']) || $param['choosebus'] != 1) { //不需要同时复制司机和车辆
- $bus_order->send_cost = null;
- $bus_order->send_bus_res_id = null;
- $bus_order->send_bus_driver_res_id = null;
- $bus_order->send_status = 440;
- }
- $rs = BusItinerary::find()->select(['create_user_id', 'station_res_id', 'station_seq_id', 'station_name', 'station_address', 'Longitude', 'Latitude', 'inout_type', 'day_seq_id', 'start_time'])
- ->where(['itinerary_id' => $ori_order->itinerary_id])->orderBy('station_seq_id')->asArray()->all();
-
- foreach ($rs as $key => $val) {
- $itinerary = new BusItinerary();
- if (!$itinerary->load($val, '')) {
- throw new \Exception();
- }
- $itinerary->create_time = date('Y-m-d H:i:s');
- $diff_time = $this->timediff(date('Y-m-d', strtotime('+' . ($val['day_seq_id'] - 1) . 'days')) . ' ' . $val['start_time'] . ':00', date('Y-m-d') . ' ' . $rs[0]['start_time'] . ':00');
- $new_time = date('Y-m-d H:i:s', strtotime("+{$diff_time['day']} day +{$diff_time['hour']}hour +{$diff_time['min']} minute", strtotime($item['run_date'] . $item['start_time'] . ':00')));
- $itinerary->start_time = date('H:i', strtotime($new_time));
- $itinerary->itinerary_id = $data_id[0]['unique_id'];
- if (!$itinerary->save()) { //如果执行失败,手动抛出异常
- throw new \Exception();
- }
- }
- if (!$bus_order->save(false)) { //如果执行失败,手动抛出异常
- throw new \Exception();
- }
- //添加操作日志
- $msg = "复制出车任务,出车单号{$bus_order->bus_number},原单单号:{$ori_order['bus_number']}";
- if ($bus_order->send_bus_res_id != '') {
- $bus = BaseBus::findOne($bus_order->send_bus_res_id);
- $msg .= '同时复制车辆:' . $bus->BUS_NO . ';';
- }
- if ($bus_order->send_bus_driver_res_id != '') {
- $driver = BaseDriver::findOne($bus_order->send_bus_driver_res_id);
- $msg .= '同时复制司机:' . $driver->DRIVER_NAME;
- }
- LogComponent::addLog($bus_order->bus_number, LOG_TYPE_ORDER, $msg, 'bus_number', $bus_order->bus_number, 0);
- }
- $transaction->commit(); //提交
- return "<script>z.pjaxFinish('success','复制成功!','#float-div');</script>";
- } catch (Exception $e) {
- $transaction->rollBack();
- return "<script>z.pjaxFinish('error','复制失败!','#float-div');</script>";
- }
- }
- return $this->renderPartial('_order_copy', [
- 'model' => $model
- ]);
- }
-
- public function timediff($begin_time, $end_time)
- {
- $begin_time = strtotime($begin_time);
- $end_time = strtotime($end_time);
- if ($begin_time < $end_time) {
- $starttime = $begin_time;
- $endtime = $end_time;
- } else {
- $starttime = $end_time;
- $endtime = $begin_time;
- }
- $timediff = $endtime - $starttime;
- $days = intval($timediff / 86400);
- $remain = $timediff % 86400;
- $hours = intval($remain / 3600);
- $remain = $remain % 3600;
- $mins = intval($remain / 60);
- $secs = $remain % 60;
- $res = array("day" => $days, "hour" => $hours, "min" => $mins, "sec" => $secs);
- return $res;
- }
-
- /**
- * Created by PhpStorm.
- * NOTES:日期处理
- * User: Steven
- * Date: 2018/3/15
- * Time: 14:29
- * Class dataService
- * @param $param
- * @return array
- */
- private function dataService($param)
- {
- $count = 0;
- foreach ($param as $key => $value) {
- if (strstr($key, 'start_date') != false) {
- $count++;
- }
- }
- $order_data = array();
-
- for ($i = 0; $i < $count; $i++) {
- $start_date = $param['start_date' . $i];
- $end_date = $param['end_date' . $i];
- $week = isset($param['child_cb' . $i]) ? $param['child_cb' . $i] : array(0, 1, 2, 3, 4, 5, 6);
- $date_arr = $this->createDateRangeArray($start_date, $end_date, $week);
- foreach ($date_arr as $item) {
- foreach ($param['time' . $i] as $val)
- $order_data[] = array(
- 'run_date' => $item,
- 'start_time' => $val,
- );
- }
- }
- return $order_data;
- }
-
- /**
- * User:Steven
- * Desc:
- * @param $strDateFrom
- * @param $strDateTo
- * @return array
- */
- private function createDateRangeArray($strDateFrom, $strDateTo, $week_arr)
- {
- $aryRange = array();
- $iDateFrom = mktime(1, 0, 0, substr($strDateFrom, 5, 2), substr($strDateFrom, 8, 2), substr($strDateFrom, 0, 4));
- $iDateTo = mktime(1, 0, 0, substr($strDateTo, 5, 2), substr($strDateTo, 8, 2), substr($strDateTo, 0, 4));
- if ($iDateTo >= $iDateFrom) {
- if (in_array(date("w", $iDateFrom), $week_arr)) {
- array_push($aryRange, date('Y-m-d', $iDateFrom));//first entry
- }
- while ($iDateFrom < $iDateTo) {
- $iDateFrom += 86400;//add 24 hours
- $number_wk = date("w", $iDateFrom);
- if (in_array($number_wk, $week_arr)) {
- array_push($aryRange, date('Y-m-d', $iDateFrom));
- }
- }
- }
- return $aryRange;
- }
-
-
- //线路牌确认
- public function actionLineStatus()
- {
- $obj = new BusOrder();
- $data = $obj->modifyLineSafe();
- echo json_encode($data);
- }
-
- //列表页取消订单
- public function actionCancel1()
- {
- $obj = new BusOrder();
- $data = $obj->cancelBusOrder();
- echo json_encode($data);
- }
-
- /**
- * User: wangxj
- *
- * 变更出车需求,只允许ajax提交
- *
- * @params
- *
- * @return string
- */
- public function actionSaveBus($id)
- {
- if (Yii::$app->request->isAjax) {
- $model = $this->findModel($id);
- $model->load(Yii::$app->request->post());
- if ($model->validate()) {
- $arr = [];
- $line = true;
- $errArray = [];
- foreach (Yii::$app->request->post('BusItinerary') as $key => $item) {
- if (isset($item['id']) && $item['id'] != '') {
- $tmpModel = BusItinerary::findOne(['id' => $item['id']]);
- $tmpModel->setOldAttribute('cancel_flag', 1);
- } else
- $tmpModel = new BusItinerary();
- $tmpModel->load($item, '');
- $tmpModel['itinerary_id'] = $model->bus_number;
- $tmpModel['station_seq_id'] = $key;
- $tmpModel['cancel_flag'] = 0;
- if ($line && $tmpModel->validate()) {
- $arr[] = $tmpModel;
- } else {
- if (count($tmpModel->getFirstErrors()) > 0)
- $errArray[] = $tmpModel->getFirstErrors();
- $line = false;
- }
- //取第一个站点的时间保存发车时间
- if ($key == 0) {
- $model->start_time = $item['start_time'];
- }
- }
- if ($line) {
- $seat_res_model = BaseResource::findOne(['ID' => $model->bus_type_res_id]);
- $model->seat_count = $seat_res_model->getResNum();
- $model->save();
- //修改时,先置旧数据cancel_flag全为0,
- BusItinerary::setCancel($model->bus_number);
- foreach ($arr as $item) {
- $item->save();
- }
- $result = ['code' => 0, 'data' => []];
- //::todo 具体变更了哪些字段还需要写函数判断
- LogComponent::addLog($model->bus_number, LOG_TYPE_ORDER, '出车需求变更', 'send_status', $model->send_status);
- //给司机端发送提醒信息
- $data = [
- 'action' => 'send_driver_msg',
- 'msg_type' => 4,
- 'bus_number' => $model->bus_number
- ];
- zHttp::httpRequest('http://' . CS1_DOMAIN . '/api/driver/', $data);
- } else {
-
- $result = ['code' => 1, 'data' => $errArray];
- }
- } else {
- $result = ['code' => 1, 'data' => $model->getFirstErrors()];
- }
- return Json::encode($result);
- } else {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
-
- /**
- * User: wangxj
- *
- * 变更出车需求,报账,只允许ajax提交
- *
- * @param $id integer
- *
- * @return string
- */
- public function actionSaveFinance($id)
- {
- if (Yii::$app->request->isAjax) {
- //外部派车在数据库中有RunBusExpenses,但是这里无法修改RunBusExpenses记录,且不会传数据到些函数
- $runBusExpenses = Yii::$app->request->post('RunBusExpenses');
- if ($runBusExpenses || Yii::$app->request->post('BusOrder')) {
-
- $line = true;
- $errArray = [];
- $transaction = Yii::$app->db->beginTransaction();
- try {
- //保存收入
- $tmpData = Yii::$app->request->post('BusOrder');
- $bus_order = BusOrder::findOne($tmpData['id']);
- if ($bus_order->load($tmpData, '')) {
- $bus_order->save();
- }
- //保存报账
- if (empty(!$runBusExpenses)) {
-
- foreach ($runBusExpenses as $key => $item) {
- $tmpModel = RunBusExpenses::findOne(['ID' => $key, 'cancel_flag' => 0]);
- // $tmpModel->load($item, false);
- if ($tmpModel != null) {
- $tmpModel->setAttributes($item);
- //如果是路桥费且是ETC支付,并且变更了值需要更新ETC消费记录
- if ($tmpModel->expense_subject_id == RunBusExpenses::SUBJECT_BRIDGE &&
- $tmpModel->expense_type == RunBusExpenses::PAY_TYPE_ETC &&
- $tmpModel->doc_log_id != 0
- ) {
- $log = BusDocLog::findOne($tmpModel->doc_log_id);
- if ($tmpModel->start_value < $tmpModel->end_value) {
- //起始值小于结束值
- $errArray[] = ['end_value' => '结束值不能大于起始值'];
- $line = false;
- } elseif ($log && $log->OPERATION_TYPE == BusDocLog::OPERATION_TYPE_PAID
- ) {
- // $log->CANCEL_FLAG = 1;
- $log->VALUE = $tmpModel->start_value - $tmpModel->end_value;
- if ($log->VALUE != $log->getOldAttribute('VALUE')) {
- $log->NOTE = '报账变更数据';
- $log->OPERATION_USER = Yii::$app->user->id;
- $doc = BusOilDoc::findOne($log->CARD_ID);
- if ($doc) {
- $doc->CARD_BALANCE = $doc->CARD_BALANCE - $log->VALUE + $log->getOldAttribute('VALUE');
- $log->save(false);
- $doc->save(false);
- }
- }
- }
-
- }
- $tmpModel->save();
- /* @var $bus_order BusOrder */
- //已审核或驳回也可以修改报账数据,但是报账状态要变更为待审核
- $bus_order = BusOrder::findOne($id);
- $bus_order->finance_status = BusOrder::STATUS_FINANCE_WAITING;
- $bus_order->save(false);
- if (count($tmpModel->getFirstErrors()) > 0) {
- $errArray[] = $tmpModel->getFirstErrors();
- $line = false;
- }
- }
- }
- }
- if ($line && !$bus_order->hasErrors()) {
- $transaction->commit();
- } else {
- $transaction->rollBack();
- }
-
- } catch (Exception $exception) {
- $transaction->rollBack();
- throw new Exception('数据库错误', 500);
- }
-
- if ($line) {
- $result = ['code' => 0, 'data' => []];
- } else {
- $result = ['code' => 1, 'data' => $errArray];
- }
- } else {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- return Json::encode($result);
- } else {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
-
- /**
- * User: wangxj
- *
- * 调派车辆司机,如果是同步的出车任务,需要修改run_bus表
- *
- * @params $type string 司机或车辆
- * @params $id integer bus_order id
- *
- * @return string
- */
- public function actionSend($type, $id, $res_id)
- {
- if (Yii::$app->request->isAjax) {
- $model = $this->findModel($id);
- //出车状态
- if ($model->run_status == 434) {
- // 调度状态不为已驳回
- if ($model->send_status != 443) {
- //车辆或司机的res_id写入对应字段
- $model->$type = $res_id;
- //如果司机和车辆都调度了,修改状态为 待确认
- if ($model->send_bus_res_id !== null && $model->send_bus_driver_res_id !== null)
- $model->send_status = 441;
- //如果是外部用车,只依据是否传回了outside_value没有进行数据验证,需要多查询一次
- if (isset($_POST['outside_value'])) {
- $model->send_cost = floatval($_POST['outside_value']);
- $model->send_type = 1;
- } elseif ($type == 'send_bus_res_id') {
- $model->send_type = 0;
- //内部派车,成本默认为0
- $model->send_cost = 0;
- // $model->send_cost = $model->bus_cost;
- }
- if ($type == 'send_bus_res_id') {//车辆
- $res = BaseBus::findOne(['BUS_ID' => $res_id]);
- $res_name = $res->BUS_NO;
- } else {
- $res = BaseDriver::findOne(['DRIVER_ID' => $res_id]);
- $res_name = $res->DRIVER_NAME;
- }
-
- //修改run_bus表,好像只需要调用存储过程 SP_VEHICLE_DISPATCH('".$USER_ID."','".$BUS_ID."','".$RES_ID."')
- if ($model->task_type == BusOrder::TASK_TYPE_SYNC) {
-
- $run_bus = RunBus::findOne(['cancel_flag' => 0, 'id' => $model->run_bus_id]);
- if ($run_bus) {
- if ($type == 'send_bus_res_id') {//车辆
-
- // $sql_proc = "call SP_VEHICLE_DISPATCH('" . Yii::$app->user->id . "','" . $model->run_bus_id . "','" . $res_id . "')";
- // $conn = Yii::$app->db;
- // $data = $conn->createCommand($sql_proc)->queryAll();
- // if ($data[0]['errorcode'] != 0) {
- // $model->addError('id', $data[0]['errorinfo']);
- //// $flag = false;
- //// $errMessage = $data[0]['errorinfo'];
- // }
- // $run_bus->SEND_BUS_ORG_ID = $res->ORG_ID;
- // $run_bus->SEND_BUS_RES_ID = $res->BUS_ID;
- // $run_bus->SEND_BUS_TYPE_RES_ID = $res->BUS_TYPE_RES_ID;
- // $run_bus->SEND_BUS_NO = $res->BUS_NO;
- $url = 'http://' . CS1_DOMAIN . '/api/change-seat/change-bus-for-run-bus';
- $params = array(
- 'user_id' => Yii::$app->user->id,
- 'bus_id' => $res_id,
- 'run_bus_id' => $model->run_bus_id
- );
- $result = Utils::httpRequest($url, $params);
- $result = json_decode($result, true);
- if (!isset($result['code']) || $result['code'] != 0) {
- $result['code'] = "1";
- $result['data'] = empty($result['info']) ? '接口异常' : $result['info'];
- return Json::encode($result);
- }
- } elseif ($type == 'send_bus_driver_res_id') {
- $run_bus->SEND_BUS_DRIVER_RES_ID = $res_id;
- $run_bus->SEND_DRIVER_NAME = $res->DRIVER_NAME;
- $run_bus->SEND_DRIVER_MOBILE = $res->PHONE_NO;
- if (!$run_bus->save()) {
- $tmpKey = array_keys($run_bus->getFirstErrors())[0];
- $model->addError('id', $run_bus->getFirstError($tmpKey));
- }
- }
-
- }
- }
- if (empty($model->getErrors()) && $model->save()) {
- if ($model->task_type == BusOrder::TASK_TYPE_CUSTOM && empty($model->getErrors())) {
- $model->updateRunBus();
- }
- $result = ['code' => 0, 'data' => $res_name];
- LogComponent::addLog($model->bus_number, LOG_TYPE_ORDER, '调派' . $model->getAttributeLabel($type) . ":{$res_name} 成功", 'send_status', $model->send_status);
- } else {
- $result = ['code' => 1, 'data' => $model->getFirstErrors()];
- }
- } else {
- $result = ['code' => 2, 'data' => ['msg' => $model->getAttributeLabel($type) . '调派失败,已驳回状态下不能调度']];
- }
-
- } else {
- $result = ['code' => 1, 'data' => ['msg' => $model->getAttributeLabel($type) . '调派失败']];
- }
- return Json::encode($result);
- } else {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
-
- /**
- * User: wangxj
- *
- * 判断是否外部用车
- *
- * @params $res_id 车id
- *
- * @return string json
- */
- public function actionSendOutside($res_id)
- {
- // $res = BaseBus::findOne(['BUS_ID' => $res_id]);
- $res = BaseBus::find()
- ->select(['a.BUS_BELONG', 'b.START_DATE', 'b.EXPIRE_DATE'])
- ->leftJoin('base_document b', 'a.BUS_ID=b.DOC_ID AND b.DOC_TYPE = 1 AND b.DOC_STATUS =1 AND b.PID=0 AND b.CANCEL_FLAG = 0 AND b.MT_STATUS in(591, 592)')
- ->from('base_bus a')
- ->where(['a.CANCEL_FLAG' => 0, 'a.BUS_ID' => $res_id])
- ->asArray()->one();
-
- if ($res != null) {
- // 如果两个都不为空,提示两次
- if ($res['BUS_BELONG'] != BaseBus::BUS_BELONG_OWN && isset($res['START_DATE'])) {
- return json_encode(array('code' => 3, 'start_date' => $res['START_DATE']));
- } elseif ($res['BUS_BELONG'] != BaseBus::BUS_BELONG_OWN) { // 只提示外部车辆
- return json_encode(array('code' => 1));
- } elseif (isset($res['START_DATE'])) // 只提示维保日期
- {
- return json_encode(array('code' => 2, 'start_date' => $res['START_DATE']));
- }
- }
- return 0;
- }
-
- /**
- * @Author wanglg
- * @Desc 判断维保时间
- */
- public function actionOutTime()
- {
-
- }
-
- public function actionSureRun($id, $attribute)
- {
- return $this->sure($id, $attribute);
- }
-
- public function actionSureFinance($id, $attribute)
- {
- return $this->sure($id, $attribute);
- }
-
- /**
- * User: wangxj
- *
- * 确认派车派司机 报账审核通过 结算通过 442已调度 446已审核 449已结算
- *
- * @params $id integer 出车订单id
- *
- * @return string
- */
- public function actionSure($id, $attribute)
- {
- $flag = true;
- if (Yii::$app->getRequest()->isAjax) {
- $model = $this->findModel($id);
- switch ($attribute) {
- case 'send_status':
- $status = 442;
- break;
- case 'finance_status':
- $status = 446;
- break;
- case 'end_status':
- $status = 449;
- break;
- default:
- throw new NotFoundHttpException('无法被验证的状态类型');
- }
- $tran = Yii::$app->db->beginTransaction();
- try {
- if ($model) {
- $already_send_count = $model->send_bus_count;//add by qius on 2017.04.19
- $beforeValue = $model->$attribute;
- if ($attribute == 'send_status') {
- if ($model->send_bus_res_id && $model->send_bus_driver_res_id) {
- $model->$attribute = $status;
- $model->run_status = 435;
- $model->send_bus_count = $already_send_count + 1;//add by qius on 2017.04.19
- if (!$model->save())
- $flag = false;
- //调用http://cs1.zhizhuchuxing.com/api/driver/接口
- $data = [
- 'action' => 'send_driver_msg',
- 'msg_type' => 3,
- 'bus_number' => $model->bus_number
- ];
- // zHttp::httpRequest('http://' . CS1_DOMAIN . '/api/driver/', $data);
- $post1 = $data;
- //判断是否需要发送短信
- if ($model->run_id != 0) {
- $today_day = date("Y-m-d");
- $current_hm = date("H:i");
- $current_time = $today_day . " " . $current_hm;
- $tomorrow_day = date("Y-m-d", strtotime("+1 days"));
- $limit_time = date("Y-m-d H:i", strtotime("+1 hours"));
- $run_start_time = $model->run_date . " " . $model->start_time;
- // if ($run_start_time > $current_time && (($model->run_date == $tomorrow_day && $current_hm > "18:30") || $model->run_date == $today_day)) {
- if ($run_start_time < $limit_time) {
- $data = [
- 'action' => 'send_bus_change_message',
- 'action' => 'send_bus_change_message',
- 'run_id' => $model->run_id,
- 'bus_order_id' => $model->bus_order_id,
- 'send_bus_count' => $already_send_count,
- 'itinerary_name' => $model->itinerary_name,
- 'new_bus_no' => $model->bus->BUS_NO,
- 'run_start_time' => $run_start_time
- ];
- // zHttp::httpRequest('http://' . CS1_DOMAIN . '/api/msg/send-bus-change-message', $data);
- $post2 = $data;
- }
- }
-
- //调度成功,需要写memcache
- $one = [
- 'bus_number' => $model->bus_number, //出车单号
- 'bus_no' => $model->bus->BUS_NO, //车牌号
- 'driver_name' => $model->driver->DRIVER_NAME, //司机姓名
- 'line_name' => $model->itinerary_name, //线路名称
- 'run_date' => date('Y-m-d H:i:s'), //确认调度的时间,目前确认调度的时间
- ];
- if ($flag)
- $cacheData = $one;
- $result = ['code' => 0, 'data' => ''];
- } else {
- $result = ['code' => 1, 'data' => ['msg' => '无法确认']];
- }
- } else {
- $model->$attribute = $status;
- //如果是报账审核通过,结算状态由之前的无状态变为未结算
- if ($attribute == 'finance_status') {
- $model->end_status = 448;
- }
- $model->save();
- $result = ['code' => 0, 'data' => ''];
- }
- if ($result['code'] == 0 && $flag) {
-
- //如果是从巴士同步过来的出车任务,run_id不为0,要操作run_bus表
- if ($model->run_id != 0) {
- $run_bus = RunBus::findOne(['cancel_flag' => 0, 'run_id' => $model->run_id, 'bus_order_id' => $model->bus_order_id]);
- if ($run_bus) {
- $run_bus->SEND_STATUS = 143;
- if (!$run_bus->save(false)) {
- $flag = false;
- }
- }
- }
-
- $type = BusOrderStatusLog::$_type_array[strtoupper($attribute)];
- $msg = $attribute == 'send_status' ? '确认调度,确认调度成功' : ($attribute == 'finance_status' ? '出车完报账待审核,审核通过' : '结算审核');
- BaseComponent::addStatusLog($model->bus_number, $type, $beforeValue, $model->$attribute, $msg);
- }
- } else {
- $result = ['code' => 1, 'data' => ['msg' => '无法确认']];
- }
- } catch (Exception $e) {
- $tran->rollBack();
- $result = ['code' => 1, 'data' => ['msg' => '无法确认']];
- }
- if ($flag) {
- $tran->commit();
-
- //调用http://cs1.zhizhuchuxing.com/api/driver/接口
- if (isset($post1)) {
- zHttp::httpRequest('http://' . CS1_DOMAIN . '/api/driver/', $post1);
- }
- //判断是否需要发送短信
- if (isset($post2)) {
- zHttp::httpRequest('http://' . CS1_DOMAIN . '/api/msg/send-bus-change-message', $post2);
- }
-
- if (isset($cacheData)) {
- $cache = Yii::$app->cache;
- $send_sure = $cache->get('send_sure_' . $model->login_user->MAIN_CORP_ID2);
- if ($send_sure === false) {
- // $data is not found in cache, calculate it from scratch
- $data = [$cacheData];
- // store $data in cache so that it can be retrieved next time
- $cache->set('send_sure_' . $model->login_user->MAIN_CORP_ID2, $data);
- } else {
- $send_sure[] = $cacheData;
- $cache->set('send_sure_' . $model->login_user->MAIN_CORP_ID2, $send_sure);
- }
- }
- }
- return Json::encode($result);
- } else {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
-
- /**
- * User: wangxj
- *
- * 驳回 send_status 443 finance_status 447 end_status 482
- *
- * @params $id integer 出车订单id
- *
- * @return string
- */
- public function actionReject($id, $msg, $attribute)
- {
- if (Yii::$app->getRequest()->isAjax) {
- $model = $this->findModel($id);
- switch ($attribute) {
- case 'send_status':
- $status = 443;
- break;
- case 'finance_status':
- $status = 447;
- break;
- case 'end_status':
- $status = 482;
- break;
- default:
- throw new NotFoundHttpException('无法被验证的状态类型');
- }
- if ($model) {
- $beforeValue = $model->$attribute;
- if ($attribute == 'send_status') {
- $model->send_status = 443;
- $model->send_msg = $msg;
- $model->send_type = 0;
- $model->send_bus_driver_res_id = '';
- $model->send_bus_res_id = '';
- $model->save();
- $result = ['code' => 0, 'data' => ''];//修改run_bus表
- if ($model->run_id != 0) {
- $run_bus = RunBus::findOne(['cancel_flag' => 0, 'run_id' => $model->run_id, 'bus_order_id' => $model->bus_order_id]);
- if ($run_bus) {
- //车辆
- $run_bus->SEND_BUS_ORG_ID = '';
- $run_bus->SEND_BUS_RES_ID = '';
- $run_bus->SEND_BUS_TYPE_RES_ID = '';
- $run_bus->SEND_BUS_NO = '';
-
- //司机
- $run_bus->SEND_BUS_DRIVER_RES_ID = '';
- $run_bus->SEND_DRIVER_NAME = '';
- $run_bus->SEND_DRIVER_MOBILE = '';
-
- $run_bus->save();
- }
- }
- } else {
- $model->$attribute = $status;
- $model->send_msg = $msg;
- $model->save();
- $result = ['code' => 0, 'data' => ''];
-
- //报账驳回调用接口
- if ($attribute == 'finance_status') {
- $data = [
- 'action' => 'send_driver_msg',
- 'msg_type' => 2,
- 'bus_number' => $model->bus_number
- ];
- zHttp::httpRequest('http://' . CS1_DOMAIN . '/api/driver/', $data);
- }
- }
- } else {
- $result = ['code' => 1, 'data' => ['msg' => '驳回失败']];
- }
- if ($result['code'] == 0) { //驳回成功,更新BusOrderStatusLog
- $type = BusOrderStatusLog::$_type_array[strtoupper($attribute)];
- BaseComponent::addStatusLog($model->bus_number, $type, $beforeValue, $model->$attribute, '驳回出车任务,原因:' . $msg);
- }
- return Json::encode($result);
- } else {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
-
- /**
- * User: wangxj
- *
- * 重置调度
- *
- * @params $id integer 出车订单id
- *
- * @param $id
- * @param string $attribute
- * @return string
- * @throws NotFoundHttpException
- */
- public function actionReset($id, $attribute = 'send_status')
- {
- if (Yii::$app->getRequest()->isAjax) {
- $model = $this->findModel($id);
- if ($model && in_array($model->run_status, [434, 435, 436])) {
- $model->send_status = 440;
- $model->run_status = 434;
- $model->send_bus_res_id = '';
- $model->send_bus_driver_res_id = '';
- $model->send_type = 0;
- $model->send_cost = 0;
- $model->save();
- $result = ['code' => 0, 'data' => ''];
- //如果是从巴士同步过来的出车任务,run_id不为0,取消出车任务要操作run_bus表
- if ($model->run_id != 0) {
- $run_bus = RunBus::findOne(['cancel_flag' => 0, 'run_id' => $model->run_id, 'bus_order_id' => $model->bus_order_id]);
- if ($run_bus) {
- $run_bus->SEND_STATUS = 144;
- //车辆
- $run_bus->SEND_BUS_ORG_ID = '';
- $run_bus->SEND_BUS_RES_ID = '';
- $run_bus->SEND_BUS_TYPE_RES_ID = '';
- $run_bus->SEND_BUS_NO = '';
-
- //司机
- $run_bus->SEND_BUS_DRIVER_RES_ID = '';
- $run_bus->SEND_DRIVER_NAME = '';
- $run_bus->SEND_DRIVER_MOBILE = '';
-
- $run_bus->save();
- $run_bus->save();
- }
- }
- } else {
- $result = ['code' => 1, 'data' => ['msg' => BusOrder::bus_order_status_array[$model->run_status] . '状态无法重置']];
- }
- if ($result['code'] == 0) {
- $type = BusOrderStatusLog::$_type_array[strtoupper($attribute)];
- $beforeValue = $model->oldAttributes[$attribute];
- BaseComponent::addStatusLog($model->bus_number, $type, $beforeValue, $model->$attribute, '重置调度信息,重置成功');
- }
- return Json::encode($result);
- } else {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
-
- /**
- * User:Steven
- * 同步CS车次记录为出车任务
- */
- public function actionSyncBusOrder()
- {
- $model = new BusOrder();
- $model->SyncBusOrder();
- }
-
- /**
- * User:Steven
- * 临时
- * 自定义同步CS车次记录为出车任务
- */
- public function actionSyncBusOrderTem()
- {
- $model = new BusOrder();
- $model->SyncBusOrder(false);
- }
-
- /**
- * User:Steven
- *
- * 资源信息管理--基础配置
- * @return string
- */
- public function actionBusResource()
- {
- \Yii::$app->view->title = '品牌管理';
- //品牌列表
- $brand_list = BaseResource::find()->select(['res_id', 'res_name'])->where(['res_type_id' => 134, 'cancel_flag' => 0])->asArray()->orderBy(['update_time' => SORT_DESC])->all();
- return $this->render('bus', ['view' => 'busResource', 'data' => $brand_list]);
- }
-
- /**
- * User:Steven
- *
- * 资源信息管理--基础配置
- * @return string
- */
- public function actionBusManager()
- {
- return $this->render('bus', ['view' => 'busResource', 'data' => '']);
- }
-
- /**
- * 同步数据时站点信息错误, 更新错误数据
- * User: Steven
- */
-
- public function actionTest()
- {
- $buso = new BusOrder();
- $res = $buso->test();
- }
-
- /**
- * User: wangxj
- *
- * 批量操作,确认 驳回 重置
- *
- * @return string
- */
- public function actionBatch()
- {
- $data = Yii::$app->request->post();
- $type = $data['type'];
- $list = $data['list'];
- $count = count($list);
- $count_s = 0;
- $count_e = 0;
- foreach ($list as $item) {
- $model = BusOrder::findOne($item);
- if ($model !== null) {
- //调度确认
- if ($type == 'sure') {
- $today_day = date("Y-m-d");
- $current_hm = date("H:i");
- $current_time = $today_day . " " . $current_hm;
- $tomorrow_day = date("Y-m-d", strtotime("+1 days"));
- if ($model->send_status == BusOrder::STATUS_SEND_WAITING_SURE) {
- $model->send_status = BusOrder::STATUS_SEND_SURE;
- $model->run_status = BusOrder::STATUS_RUN_READY;
- $already_send_count = $model->send_bus_count;
- $model->send_bus_count = $already_send_count + 1;
- if ($model->save()) {
- //发送短信
- if ($model->run_id != 0) {
- $run_start_time = $model->run_date . " " . $model->start_time;
- if ($run_start_time > $current_time && (($model->run_date == $tomorrow_day && $current_hm > "18:30") || $model->run_date == $today_day)) {
- $run_bus = RunBus::findOne(['cancel_flag' => 0, 'run_id' => $model->run_id, 'bus_order_id' => $model->bus_order_id]);
- $post1 = [
- 'action' => 'send_driver_msg',
- 'msg_type' => 3,
- 'bus_number' => $model->bus_number
- ];
- zHttp::httpRequest('http://' . CS1_DOMAIN . '/api/driver/', $post1);
- $post2 = [
- 'action' => 'send_bus_change_message',
- 'run_id' => $model->run_id,
- 'bus_order_id' => $model->bus_order_id,
- 'send_bus_count' => $already_send_count,
- 'itinerary_name' => $model->itinerary_name,
- 'new_bus_no' => $run_bus->SEND_BUS_NO,
- 'run_start_time' => $run_start_time
- ];
- zHttp::httpRequest('http://' . CS1_DOMAIN . '/api/msg/send-bus-change-message', $post2);
- }
- }
- $count_s++;
- }
- }
- }
-
- //驳回
- if ($type == 'reject') {
-
- }
-
- //重置
- if ($type == 'reset') {
-
- }
- }
- }
- Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
- if ($count_s == $count) {
- return ['status' => 0, 'list' => $list, 'type' => 'success', 'msg' => "确认成功:{$count_s} 个出车任务完成调度确认"];
- } else if ($count_s != 0) {
- $count_e = $count - $count_s;
- return ['status' => 1, 'list' => $list, 'type' => 'success', 'msg' => "确认成功:{$count_s} 个出车任务完成调度确认", 'fail' => "确认失败:{$count_e} 个出车任务确认失败"];
- } else if ($count_s == 0) {
- return ['status' => 2, 'list' => $list, 'type' => 'error', 'msg' => "确认失败:{$count} 个出车任务确认失败"];
- }
- }
-
- /**
- * 同步单个出车任务
- *
- * @param $run_bus_id_str string 多任务用逗号分隔
- * @return string
- * @author wangxj
- */
- public function actionSyncOne($run_bus_id_str)
- {
- $arr = explode(',', $run_bus_id_str);
- if (!empty($arr)) {
- $flag_error = false; //是否有失败记录
- $flag_success = false; //成功过一次
- $error_list = [];
- foreach ($arr as $item) {
- $bus_order = BusOrder::findOne(['cancel_flag' => 0, 'run_bus_id' => $item]);
- if ($bus_order == null) {
- $flag_error = true;
- $error_list[] = ['run_bus_id' => $item, 'msg' => '无法找到出车任务'];
- } else {
- if ($bus_order->finance_lock == 1 || $bus_order->outcome_finance_lock == 1) {
- $error_list[] = ['run_bus_id' => $item, 'msg' => '已经关账'];
- continue;
- }
- $tmp_sync = $bus_order->syncOneBusOrder();
- $flag_success = $tmp_sync ? true : $flag_success;
- if (!$tmp_sync) {
- $error_list[] = ['run_bus_id' => $item, 'msg' => '同步失败'];
- }
- }
- }
-
- return json_encode(['flag' => !$flag_error && $flag_success, 'msg' => '', 'error_list' => $error_list]);
- } else {
- return json_encode(['flag' => false, 'msg' => '无效参数']);
- }
- }
-
- /**
- * Author:Steven
- * @param bus_id 车辆ID
- * Desc:模拟司机端进行出车任务
- */
- public function actionSimulationBus()
- {
- //获取页面数据请求接口
- $bus_res_id = Yii::$app->request->get('bus_id');
- $run_bus_expenses = new BusExpense();
- $data['end_value'] = $run_bus_expenses->getExpenseMaxEndValue($bus_res_id, 462);// 用于显示上次行驶结束后的里程数
- if (Yii::$app->request->isPost) {
- $res = Yii::$app->runAction('api/driver/run-start');
- return $res;
- }
- return $this->render('simulation_bus', [
- 'data' => $data
- ]);
- }
-
- /**
- * @Author wanglg
- * @Desc 模拟司机端结束用车
- * @param bus_number 出车单号
- * @return int|mixed|string|\yii\console\Response
- */
- public function actionEndBus()
- {
- $bus_number = Yii::$app->request->get('bus_number');
- // $run_bus_expenses = new BusExpense();
- $data = RunBusExpenses::find()->select('start_value')->where(['bus_number' => $bus_number, 'cancel_flag' => 0, 'expense_subject_id' => 462])->asArray()->one(); //用于显示上次行驶结束后的里程数
-
- if (Yii::$app->request->isPost) {
- $res = Yii::$app->runAction('api/driver/run-end');
- return $res;
- }
- return $this->render('simulation_end', [
- 'data' => $data
- ]);
-
- }
- }
|