|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458 |
- <?php
-
- namespace backend\modules\api\controllers;
-
- use backend\modules\api\logic\LineManage;
- use backend\modules\api\models\BaseBusCost;
- use backend\modules\api\models\BaseResource;
- use backend\modules\api\models\BaseSupplier;
- use backend\modules\api\models\BaseUser;
- use backend\modules\api\models\OperaLine;
- use backend\modules\api\models\OperaStation;
- use backend\modules\api\models\OperaTickets;
- use backend\modules\api\models\OrderMain;
- use backend\modules\api\models\RunBus;
- use backend\modules\api\models\RunMain;
- use backend\modules\api\models\RunProd;
- use yii\db\Exception;
- use yii\web\Controller;
- use Yii;
-
- class RunEditController extends Controller
- {
- public $enableCsrfValidation = false;
-
- /**
- * Function Description:入口
- * Function Name: actionIndex
- *
- * @return string
- *
- * @author Redstop
- */
- public function actionIndex()
- {
- $request = Yii::$app->request;
- $action = $request->post('action');
- $func = 'action';
- $action = explode('_', $action);
- foreach ($action as $key => $vel) {
- $func .= ucfirst($vel);
- }
- //check 验证码
- if ($this->actionCheckAuthCode() == false) {
- $json = ['code' => 1, 'info' => '验证身份失败'];
- return json_encode($json);
- }
-
- if ($action === false || method_exists($this, $func) == false) {
- $json = ['code' => 1, 'info' => '必要参数缺失'];
- return json_encode($json);
- }
- return $this->$func();
- }
-
- /**
- * Function Description:得到当前班次信息
- * Function Name: actionGetRunInfo
- *
- * @return string
- *
- * @author 李健
- */
- public function actionGetRunInfo()
- {
- $user_id = Yii::$app->request->post('user_id', '');
- $run_id = Yii::$app->request->post('run_id', '');
- try {
- // 根据RUN_ID 获取线路信息
- $run_main = new RunMain();
- $json1 = $run_main->getLineInfo($run_id);
- if (!$json1) {
- throw new Exception('线路信息未找到');
- }
- $data["line"] = array("name" => $json1['name'], "lineid" => $json1['lineid']);
- $data['sellday'] = $json1['pre_sale_day'];
- $data['station'] = array();
-
- // 根据RUN_ID获取途径站点
- $json2 = $run_main->getRunStation($run_id);
- foreach ($json2 as $temp_info) {
- $ticket_gate_ary = explode(",", $temp_info["TICKET_GATE"]);
- if (strpos($temp_info["TICKET_GATE"], ":") != false && count($ticket_gate_ary) > 0) {
- $ticket_gate = array();
- foreach ($ticket_gate_ary as $ticket_simple) {
- $ticket_info = explode(":", $ticket_simple);
- $ticket_gate[] = array($ticket_info[0] => $ticket_info[1]);
- }
- } else {
- $ticket_gate = "";
- }
- $temp_info_insert = $temp_info;
- $temp_info_insert["TICKET_GATE"] = $ticket_gate;
- $data['station'][] = $temp_info_insert;
- }
-
- // 查询车辆基本信息
- $base_resource = new BaseResource();
- $json3 = $base_resource->getCarBaseInfo();
-
- if (count($json3) > 0) {
- $data['cartype'] = $json3;
- }
-
- // 根据RUN_ID获取车辆数及选座状态
- $run_bus = new RunBus();
- $json4 = $run_bus->getRunHasCar($run_id);
-
- if (count($json4) > 0) {
- $data['hascar'] = $json4;
- }
-
- // 根据RUN_ID获取线路ID
- $prod_id = $run_main->getProdId($run_id);
- if ($prod_id) {
- $prod_id = $prod_id['prod_id'];
- }
-
- $run_prod = new RunProd();
- $res1 = $run_prod->getRunTicketType($run_id, $prod_id);
- $opera_tickets = new OperaTickets();
- $res2 = $opera_tickets->getRunTicketsType($run_id, $prod_id);
- $json5 = array_merge($res1, $res2);
- if (count($json5) > 0) {
- $data['ticket'] = $json5;
- }
-
- //获取班次的出发日期
- $json6 = $run_main->getStartDate($run_id);
- $data['time'] = $json6["time"];
-
- // 获取供车商列表
- $base_supplier = new BaseSupplier();
- $json7 = $base_supplier->getBusTeamList();
- $data['supplier_list'] = $json7;
- $data['cost_type'] = array(array('type_id' => 477, 'type_name' => '包车计价'), array('type_id' => 478, 'type_name' => '车座计价'));
-
- // 获取车队基础价格
- $base_bus_cost = new BaseBusCost();
- $json8 = $base_bus_cost->getBaseCost();
- $base_cost = array();
- foreach ($json8 as $base_cost_info) {
- $supplier_id = $base_cost_info["supplier_id"];
- $bus_res_id = $base_cost_info["bus_res_id"];
- if (!isset($base_cost[$supplier_id])) {
- $base_cost[$supplier_id] = array();
- }
- $base_cost[$supplier_id][$bus_res_id] = $base_cost_info["base_cost"];
- }
- $data['base_cost'] = $base_cost;
-
- // 统计路程
- $opera_station = new OperaStation();
- $json9 = $opera_station->getSumDistance($json1['lineid']);
- if ($json9) {
- $data['line_distance'] = $json9["line_distance"];
- } else {
- $data['line_distance'] = 0;
- }
-
- // 获取订单里面的票种信息
- $order_main = new OrderMain();
- $res10 = $order_main->getRunTicketInfo($run_id);
- if ($res10) {
- foreach ($res10 as $k => $v) {
- $res10[$k]['crowd'] = '';
- $res10[$k]['if_ticket'] = '是';
- }
- }
-
- $data['order_ticket_info_list'] = $res10;
-
- // 显示班次可用票种
- $res11 = $run_prod->getTicketInfo($run_id);
- if ($res11) {
- foreach ($res11 as $k => $v) {
- $res11[$k]['sale'] = '可售';
- }
- }
- $data['not_in_order_ticket_info_list'] = $res11;
-
- } catch (Exception $e) {
- $data = [
- 'code' => 1,
- 'info' => $e->getMessage(),
- ];
- }
-
- return json_encode($data, true);
- }
-
- /**
- * Function Description:添加线路
- * Function Name: actionAddLine
- *
- * @return string
- *
- * @author 李健
- */
- public function actionAddLine()
- {
- $user_id = Yii::$app->request->post('user_id');
- $line_name = Yii::$app->request->post('line_name');
- $line_code = Yii::$app->request->post('line_code');
- $line_type = Yii::$app->request->post('line_type');
- $line_sub_type = Yii::$app->request->post('line_sub_type');
- $time_type = Yii::$app->request->post('time_type');
- $time_info = Yii::$app->request->post('time_info');
- $supply_id = Yii::$app->request->post('supply_id');
- $station_list = Yii::$app->request->post('station_list');
- $allow_selected_seat = Yii::$app->request->post('allow_selected_seat');
- $remark = Yii::$app->request->post('remark', '');
- $run_duty_id = Yii::$app->request->post('run_duty_id', 0);
-
- // 开启事务
- $transaction = Yii::$app->db->beginTransaction();
- try {
-
- // 判断线路编号是否已存在
- $opera_line = new OperaLine();
- $res = $opera_line->checkLineExists($line_code);
- if ($res && $res['line_id'] != '') {
- throw new Exception('线路编号已存在');
- }
-
- // 添加线路
- // 获取CS运营主体ID
- $base_user = new BaseUser();
- $main_corp_id = $base_user->getMainCorpIdByUserId($user_id);
- if ($main_corp_id) {
- $main_corp_id = $main_corp_id['main_corp_id'];
- }
-
- // 站点信息
- $station_list = strtr($station_list, [' ' => '']);
- $station_list = ltrim($station_list, '{');
- $station_list = rtrim($station_list, '}');
- $station_list = explode('}{', $station_list);
-
- // 增加线路
- $opera_line = new OperaLine();
- $res = $opera_line->insertInfo($user_id, $user_id, $line_name, $line_code, $line_type, $line_sub_type, $time_type, $time_info, $supply_id, $main_corp_id, $allow_selected_seat, $remark, $run_duty_id);
- if (!$res) {
- throw new Exception('插入线路失败');
- } else {
- $line_id = $res;
- }
-
- // 插入站点
- $opera_station = new OperaStation();
- foreach ($station_list as $info) {
- $info = explode(',', $info);
- $table = clone $opera_station;
- $res = $table->addStation($user_id, $line_id, $info[0], $info[1], $info[2], $info[3], $info[4], $info[5], $info[6]);
- if ($res === false) {
- throw new Exception('插入站点失败');
- }
- }
-
- // 提交事务
- $transaction->commit();
- $data = [
- 'code' => 0,
- 'info' => '数据插入成功',
- 'line_id' => $line_id,
- 'line_type' => $line_type,
- ];
- } catch (Exception $e) {
- // 回滚事务
- $transaction->rollBack();
- $data = [
- 'code' => 1,
- 'info' => $e->getMessage()
- ];
- }
-
- return json_encode($data, true);
- }
-
- /**
- * Function Description:获取单条线路详情
- * Function Name: actionGetLineDetail
- *
- * @return string
- *
- * @author 李健
- */
- public function actionGetLineDetail()
- {
- $line_id = Yii::$app->request->post('line_id', '');
-
- $opera_line = new OperaLine();
- $line_info = $opera_line->getLineDetail($line_id);
- if (count($line_info) == 0) {
- $json['code'] = '1';
- $json['info'] = '该线路配置不全';
- return json_encode($json);
- }
- foreach ($line_info as $k => $v) {
- if (!isset($line_base_info)) {
- $line_base_info['tailor_flag'] = $v['tailor_flag'];
- $line_base_info['line_id'] = $v['line_id'];
- $line_base_info['line_name'] = $v['line_name'];
- $line_base_info['line_code'] = $v['line_code'];
- $line_base_info['line_type'] = $v['line_type'];
- $line_base_info['org_id'] = $v['org_id'];
- $line_base_info['run_duty_id'] = $v['run_duty_id'];
- $line_base_info['sale_expired_type'] = $v['sale_expired_type'];
- $line_base_info['sale_expired_time'] = $v['sale_expired_time'];
- $line_base_info['allow_select_seat'] = $v['allow_select_seat'];
- $line_base_info['remark'] = $v['remark'];
- }
- $res_base_info[$v['order_id']]['res_id'] = $v['res_id'];
- $res_base_info[$v['order_id']]['inout_type'] = $v['inout_type'];
- $res_base_info[$v['order_id']]['checkport_res_id'] = $v['checkport_res_id'];
- $res_base_info[$v['order_id']]['area_id'] = $v['area_id'];
- $res_base_info[$v['order_id']]['start_minutes'] = $v['start_minutes'];
- $res_base_info[$v['order_id']]['distance'] = $v['distance'];
- }
-
- ksort($res_base_info);
- $logic = new LineManage();
-
- foreach ($res_base_info as $order_id => $res_v) {
- $res_detail_info = $logic->getStationInfo(array('res_id' => $res_v['res_id']));
- if ($res_detail_info['code'] != '0') {
- $json['code'] = '1';
- $json['info'] = '站点信息有误';
- return $json;
- }
- $res_detail_info = $res_detail_info['res_info'];
- foreach ($res_detail_info['parent_area'] as $k => $v) {
- if ($v['id'] == $res_v['area_id']) {
- $res_detail_info['parent_area'][$k]['checked'] = '1';
- } else {
- $res_detail_info['parent_area'][$k]['checked'] = '0';
- }
- }
- foreach ($res_detail_info['inout_type'] as $k => $v) {
- if ($v['id'] == $res_v['inout_type']) {
- $res_detail_info['inout_type'][$k]['checked'] = '1';
- } else {
- $res_detail_info['inout_type'][$k]['checked'] = '0';
- }
- }
- foreach ($res_detail_info['check_port'] as $k => $v) {
- if ($v['id'] == $res_v['checkport_res_id']) {
- $res_detail_info['check_port'][$k]['checked'] = '1';
- } else {
- $res_detail_info['check_port'][$k]['checked'] = '0';
- }
- }
- $res_detail_info['start_minutes'] = $res_v['start_minutes'];
- $res_detail_info['distance'] = $res_v['distance'];
- $res_array[$order_id] = $res_detail_info;
- }
- $json['code'] = '0';
- $json['info'] = '返回数据成功';
- $json['line_info'] = $line_base_info;
- $json['station_info'] = array_merge($res_array);
-
- return json_encode($json);
- }
-
-
- public function actionUptLine()
- {
- $user_id = Yii::$app->request->post('user_id');
- $line_code = Yii::$app->request->post('line_code');
- $line_name = Yii::$app->request->post('line_name');
- $line_type = Yii::$app->request->post('line_type');
- $line_sub_type = Yii::$app->request->post('line_sub_type');
- $time_type = Yii::$app->request->post('time_type');
- $time_info = Yii::$app->request->post('time_info');
- $supply_id = Yii::$app->request->post('supply_id');
- $station_list = Yii::$app->request->post('station_list');
- $tailor_flag = Yii::$app->request->post('tailor_flag');
- $line_id = Yii::$app->request->post('line_id');
- $remark = Yii::$app->request->post('remark', '');
- $run_duty_id = Yii::$app->request->post('run_duty_id', 0);
- $allow_selected_seat = Yii::$app->request->post('allow_selected_seat');
- // 开启事务
- $transaction = Yii::$app->db->beginTransaction();
- try {
-
- // 判断线路编号是否已存在
- $opera_line = new OperaLine();
- $res_check = $opera_line->checkLine($line_code, $line_id);
- if (count($res_check) > 0) {
- throw new Exception('线路编号已存在');
- }
-
- // 添加线路
- // 获取CS运营主体ID
- $base_user = new BaseUser();
- $main_corp_id = $base_user->getMainCorpIdByUserId($user_id);
- if ($main_corp_id) {
- $main_corp_id = $main_corp_id['main_corp_id'];
- }
-
- // 站点信息
- $station_list = strtr($station_list, [' ' => '']);
- $station_list = ltrim($station_list, '{');
- $station_list = rtrim($station_list, '}');
- $station_list = explode('}{', $station_list);
-
- // 更新站点
- $opera_station = new OperaStation();
- // 删除所有站点
- $res = $opera_station->delAllStation($line_id);
- if ($res == false) {
- throw new Exception('删除站点失败');
- }
- foreach ($station_list as $info) {
- $info = explode(',', $info);
- $table = clone $opera_station;
- // 获取线路对象
- $order_id = $info[1];
- $obj = $table->getStationObj($order_id, $line_id);
- if ($obj == false) {
- // 添加新路
- $res = $table->addStation($user_id, $line_id, $info[0], $info[1], $info[2], $info[3], $info[4], $info[5], $info[6]);
- if ($res === false) {
- throw new Exception('插入站点失败');
- }
- } else {
- $res = $table->uptStation($user_id, $line_id, $info[0], $info[1], $info[2], $info[3], $info[4], $info[5], $info[6]);
- if ($res === false) {
- throw new Exception('站点更新失败');
- }
- }
- }
-
- // 更新线路
- $res = $opera_line->uptInfo($line_id, $user_id, $user_id, $line_name, $line_code, $line_type, $line_sub_type, $time_type, $time_info, $supply_id, $main_corp_id, $allow_selected_seat, $remark, $run_duty_id);
- if ($res == false) {
- throw new Exception('线路更新失败');
- }
-
- // 提交事务
- $transaction->commit();
- $data = [
- 'code' => 0,
- 'info' => '数据插入成功',
- 'line_id' => $line_id,
- 'line_type' => $line_type,
- ];
- } catch (Exception $e) {
- // 回滚事务
- $transaction->rollBack();
- $data = [
- 'code' => 1,
- 'info' => $e->getMessage()
- ];
- }
-
- return json_encode($data, true);
- }
- }
|