request; $action = $request->post('action'); $func = 'action'; $action = explode('_', $action); foreach ($action as $key => $vel) { $func .= ucfirst($vel); } if ($action === false || method_exists($this, $func) == false) { $json = ['code' => 1, 'info' => '必要参数缺失']; return json_encode($json); } return $this->$func(); } /** * Function Description:添加车次 * Function Name: actionAddBus * * @return string * * @author 张帅 */ public function actionAddBus() { $run_bus = new RunBus(); $base_resource = new BaseResource(); $run_main = new RunMain(); $base_resource_matrix = new BaseResourceMatrix(); $run_station = new RunStation(); #region 获取参数 $run_id = Yii::$app->request->post('run_id', 902716);//班次id //车次信息{bus_type_res_id base_resource 座位,brand_res_id base_resource 大巴品牌,cost_motorcade_id 承运车队,cost_type 包车计价 人数计价,cost_price 单价,allow_select_seat 选座} $bus_info_str = Yii::$app->request->post('bus_info', '{997,288,628,477,10}'); $user_id = Yii::$app->request->post('user_id',1);//用户id #endregion #region 获取班次详情 $run_info = $run_main->getRunInfoByRunId($run_id); if (!$run_info) { $result['code'] = '1'; $result['info'] = '班次不存在或已停运'; return json_encode($result); } #endregion #region 获取巴士信息 $bus_info = $run_bus->getBusInfoArray($bus_info_str); if (!$bus_info) { $result['code'] = '1'; $result['info'] = '数据不全'; return json_encode($result); } #endregion #region 通过车资源类型id获取车座详情 $bus_type_res_id = $bus_info['bus_type_res_id'];//车资源类型id $bus_res_info = $base_resource->getBusResInfoArray($bus_type_res_id); if (!$bus_res_info) { $result['code'] = '1'; $result['info'] = '车资源不存在或已停用'; return json_encode($result); } #endregion #region 通过车资源类型id获取车座座位图 $matrix_arr = $base_resource_matrix->getMatrixArr($bus_type_res_id); if (!$matrix_arr) { $result['code'] = '1'; $result['info'] = '该车没有座位图'; return json_encode($result); } #endregion #region 获取车号 $line_id = $run_info['line_id']; $run_date = $run_info['run_date']; $bus_order_id = $run_bus->getBusNoByLineDate($line_id, $run_date); #endregion #region 获取班次站点信息 $run_station_info = $run_station->getRunStation($run_id); if (!$run_station_info) { $result['code'] = '1'; $result['info'] = '该班次没有站点'; return json_encode($result); } #endregion #region 数据库添加车次 $result = $run_bus->addBusForRun($run_info, $bus_info, $bus_res_info, $matrix_arr, $run_station_info, $bus_order_id, $user_id); #endregion return json_encode($result); } }