Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

458 wiersze
17 KiB

  1. <?php
  2. namespace backend\modules\api\controllers;
  3. use backend\modules\api\logic\LineManage;
  4. use backend\modules\api\models\BaseBusCost;
  5. use backend\modules\api\models\BaseResource;
  6. use backend\modules\api\models\BaseSupplier;
  7. use backend\modules\api\models\BaseUser;
  8. use backend\modules\api\models\OperaLine;
  9. use backend\modules\api\models\OperaStation;
  10. use backend\modules\api\models\OperaTickets;
  11. use backend\modules\api\models\OrderMain;
  12. use backend\modules\api\models\RunBus;
  13. use backend\modules\api\models\RunMain;
  14. use backend\modules\api\models\RunProd;
  15. use yii\db\Exception;
  16. use yii\web\Controller;
  17. use Yii;
  18. class RunEditController extends Controller
  19. {
  20. public $enableCsrfValidation = false;
  21. /**
  22. * Function Description:入口
  23. * Function Name: actionIndex
  24. *
  25. * @return string
  26. *
  27. * @author Redstop
  28. */
  29. public function actionIndex()
  30. {
  31. $request = Yii::$app->request;
  32. $action = $request->post('action');
  33. $func = 'action';
  34. $action = explode('_', $action);
  35. foreach ($action as $key => $vel) {
  36. $func .= ucfirst($vel);
  37. }
  38. //check 验证码
  39. if ($this->actionCheckAuthCode() == false) {
  40. $json = ['code' => 1, 'info' => '验证身份失败'];
  41. return json_encode($json);
  42. }
  43. if ($action === false || method_exists($this, $func) == false) {
  44. $json = ['code' => 1, 'info' => '必要参数缺失'];
  45. return json_encode($json);
  46. }
  47. return $this->$func();
  48. }
  49. /**
  50. * Function Description:得到当前班次信息
  51. * Function Name: actionGetRunInfo
  52. *
  53. * @return string
  54. *
  55. * @author 李健
  56. */
  57. public function actionGetRunInfo()
  58. {
  59. $user_id = Yii::$app->request->post('user_id', '');
  60. $run_id = Yii::$app->request->post('run_id', '');
  61. try {
  62. // 根据RUN_ID 获取线路信息
  63. $run_main = new RunMain();
  64. $json1 = $run_main->getLineInfo($run_id);
  65. if (!$json1) {
  66. throw new Exception('线路信息未找到');
  67. }
  68. $data["line"] = array("name" => $json1['name'], "lineid" => $json1['lineid']);
  69. $data['sellday'] = $json1['pre_sale_day'];
  70. $data['station'] = array();
  71. // 根据RUN_ID获取途径站点
  72. $json2 = $run_main->getRunStation($run_id);
  73. foreach ($json2 as $temp_info) {
  74. $ticket_gate_ary = explode(",", $temp_info["TICKET_GATE"]);
  75. if (strpos($temp_info["TICKET_GATE"], ":") != false && count($ticket_gate_ary) > 0) {
  76. $ticket_gate = array();
  77. foreach ($ticket_gate_ary as $ticket_simple) {
  78. $ticket_info = explode(":", $ticket_simple);
  79. $ticket_gate[] = array($ticket_info[0] => $ticket_info[1]);
  80. }
  81. } else {
  82. $ticket_gate = "";
  83. }
  84. $temp_info_insert = $temp_info;
  85. $temp_info_insert["TICKET_GATE"] = $ticket_gate;
  86. $data['station'][] = $temp_info_insert;
  87. }
  88. // 查询车辆基本信息
  89. $base_resource = new BaseResource();
  90. $json3 = $base_resource->getCarBaseInfo();
  91. if (count($json3) > 0) {
  92. $data['cartype'] = $json3;
  93. }
  94. // 根据RUN_ID获取车辆数及选座状态
  95. $run_bus = new RunBus();
  96. $json4 = $run_bus->getRunHasCar($run_id);
  97. if (count($json4) > 0) {
  98. $data['hascar'] = $json4;
  99. }
  100. // 根据RUN_ID获取线路ID
  101. $prod_id = $run_main->getProdId($run_id);
  102. if ($prod_id) {
  103. $prod_id = $prod_id['prod_id'];
  104. }
  105. $run_prod = new RunProd();
  106. $res1 = $run_prod->getRunTicketType($run_id, $prod_id);
  107. $opera_tickets = new OperaTickets();
  108. $res2 = $opera_tickets->getRunTicketsType($run_id, $prod_id);
  109. $json5 = array_merge($res1, $res2);
  110. if (count($json5) > 0) {
  111. $data['ticket'] = $json5;
  112. }
  113. //获取班次的出发日期
  114. $json6 = $run_main->getStartDate($run_id);
  115. $data['time'] = $json6["time"];
  116. // 获取供车商列表
  117. $base_supplier = new BaseSupplier();
  118. $json7 = $base_supplier->getBusTeamList();
  119. $data['supplier_list'] = $json7;
  120. $data['cost_type'] = array(array('type_id' => 477, 'type_name' => '包车计价'), array('type_id' => 478, 'type_name' => '车座计价'));
  121. // 获取车队基础价格
  122. $base_bus_cost = new BaseBusCost();
  123. $json8 = $base_bus_cost->getBaseCost();
  124. $base_cost = array();
  125. foreach ($json8 as $base_cost_info) {
  126. $supplier_id = $base_cost_info["supplier_id"];
  127. $bus_res_id = $base_cost_info["bus_res_id"];
  128. if (!isset($base_cost[$supplier_id])) {
  129. $base_cost[$supplier_id] = array();
  130. }
  131. $base_cost[$supplier_id][$bus_res_id] = $base_cost_info["base_cost"];
  132. }
  133. $data['base_cost'] = $base_cost;
  134. // 统计路程
  135. $opera_station = new OperaStation();
  136. $json9 = $opera_station->getSumDistance($json1['lineid']);
  137. if ($json9) {
  138. $data['line_distance'] = $json9["line_distance"];
  139. } else {
  140. $data['line_distance'] = 0;
  141. }
  142. // 获取订单里面的票种信息
  143. $order_main = new OrderMain();
  144. $res10 = $order_main->getRunTicketInfo($run_id);
  145. if ($res10) {
  146. foreach ($res10 as $k => $v) {
  147. $res10[$k]['crowd'] = '';
  148. $res10[$k]['if_ticket'] = '是';
  149. }
  150. }
  151. $data['order_ticket_info_list'] = $res10;
  152. // 显示班次可用票种
  153. $res11 = $run_prod->getTicketInfo($run_id);
  154. if ($res11) {
  155. foreach ($res11 as $k => $v) {
  156. $res11[$k]['sale'] = '可售';
  157. }
  158. }
  159. $data['not_in_order_ticket_info_list'] = $res11;
  160. } catch (Exception $e) {
  161. $data = [
  162. 'code' => 1,
  163. 'info' => $e->getMessage(),
  164. ];
  165. }
  166. return json_encode($data, true);
  167. }
  168. /**
  169. * Function Description:添加线路
  170. * Function Name: actionAddLine
  171. *
  172. * @return string
  173. *
  174. * @author 李健
  175. */
  176. public function actionAddLine()
  177. {
  178. $user_id = Yii::$app->request->post('user_id');
  179. $line_name = Yii::$app->request->post('line_name');
  180. $line_code = Yii::$app->request->post('line_code');
  181. $line_type = Yii::$app->request->post('line_type');
  182. $line_sub_type = Yii::$app->request->post('line_sub_type');
  183. $time_type = Yii::$app->request->post('time_type');
  184. $time_info = Yii::$app->request->post('time_info');
  185. $supply_id = Yii::$app->request->post('supply_id');
  186. $station_list = Yii::$app->request->post('station_list');
  187. $allow_selected_seat = Yii::$app->request->post('allow_selected_seat');
  188. $remark = Yii::$app->request->post('remark', '');
  189. $run_duty_id = Yii::$app->request->post('run_duty_id', 0);
  190. // 开启事务
  191. $transaction = Yii::$app->db->beginTransaction();
  192. try {
  193. // 判断线路编号是否已存在
  194. $opera_line = new OperaLine();
  195. $res = $opera_line->checkLineExists($line_code);
  196. if ($res && $res['line_id'] != '') {
  197. throw new Exception('线路编号已存在');
  198. }
  199. // 添加线路
  200. // 获取CS运营主体ID
  201. $base_user = new BaseUser();
  202. $main_corp_id = $base_user->getMainCorpIdByUserId($user_id);
  203. if ($main_corp_id) {
  204. $main_corp_id = $main_corp_id['main_corp_id'];
  205. }
  206. // 站点信息
  207. $station_list = strtr($station_list, [' ' => '']);
  208. $station_list = ltrim($station_list, '{');
  209. $station_list = rtrim($station_list, '}');
  210. $station_list = explode('}{', $station_list);
  211. // 增加线路
  212. $opera_line = new OperaLine();
  213. $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);
  214. if (!$res) {
  215. throw new Exception('插入线路失败');
  216. } else {
  217. $line_id = $res;
  218. }
  219. // 插入站点
  220. $opera_station = new OperaStation();
  221. foreach ($station_list as $info) {
  222. $info = explode(',', $info);
  223. $table = clone $opera_station;
  224. $res = $table->addStation($user_id, $line_id, $info[0], $info[1], $info[2], $info[3], $info[4], $info[5], $info[6]);
  225. if ($res === false) {
  226. throw new Exception('插入站点失败');
  227. }
  228. }
  229. // 提交事务
  230. $transaction->commit();
  231. $data = [
  232. 'code' => 0,
  233. 'info' => '数据插入成功',
  234. 'line_id' => $line_id,
  235. 'line_type' => $line_type,
  236. ];
  237. } catch (Exception $e) {
  238. // 回滚事务
  239. $transaction->rollBack();
  240. $data = [
  241. 'code' => 1,
  242. 'info' => $e->getMessage()
  243. ];
  244. }
  245. return json_encode($data, true);
  246. }
  247. /**
  248. * Function Description:获取单条线路详情
  249. * Function Name: actionGetLineDetail
  250. *
  251. * @return string
  252. *
  253. * @author 李健
  254. */
  255. public function actionGetLineDetail()
  256. {
  257. $line_id = Yii::$app->request->post('line_id', '');
  258. $opera_line = new OperaLine();
  259. $line_info = $opera_line->getLineDetail($line_id);
  260. if (count($line_info) == 0) {
  261. $json['code'] = '1';
  262. $json['info'] = '该线路配置不全';
  263. return json_encode($json);
  264. }
  265. foreach ($line_info as $k => $v) {
  266. if (!isset($line_base_info)) {
  267. $line_base_info['tailor_flag'] = $v['tailor_flag'];
  268. $line_base_info['line_id'] = $v['line_id'];
  269. $line_base_info['line_name'] = $v['line_name'];
  270. $line_base_info['line_code'] = $v['line_code'];
  271. $line_base_info['line_type'] = $v['line_type'];
  272. $line_base_info['org_id'] = $v['org_id'];
  273. $line_base_info['run_duty_id'] = $v['run_duty_id'];
  274. $line_base_info['sale_expired_type'] = $v['sale_expired_type'];
  275. $line_base_info['sale_expired_time'] = $v['sale_expired_time'];
  276. $line_base_info['allow_select_seat'] = $v['allow_select_seat'];
  277. $line_base_info['remark'] = $v['remark'];
  278. }
  279. $res_base_info[$v['order_id']]['res_id'] = $v['res_id'];
  280. $res_base_info[$v['order_id']]['inout_type'] = $v['inout_type'];
  281. $res_base_info[$v['order_id']]['checkport_res_id'] = $v['checkport_res_id'];
  282. $res_base_info[$v['order_id']]['area_id'] = $v['area_id'];
  283. $res_base_info[$v['order_id']]['start_minutes'] = $v['start_minutes'];
  284. $res_base_info[$v['order_id']]['distance'] = $v['distance'];
  285. }
  286. ksort($res_base_info);
  287. $logic = new LineManage();
  288. foreach ($res_base_info as $order_id => $res_v) {
  289. $res_detail_info = $logic->getStationInfo(array('res_id' => $res_v['res_id']));
  290. if ($res_detail_info['code'] != '0') {
  291. $json['code'] = '1';
  292. $json['info'] = '站点信息有误';
  293. return $json;
  294. }
  295. $res_detail_info = $res_detail_info['res_info'];
  296. foreach ($res_detail_info['parent_area'] as $k => $v) {
  297. if ($v['id'] == $res_v['area_id']) {
  298. $res_detail_info['parent_area'][$k]['checked'] = '1';
  299. } else {
  300. $res_detail_info['parent_area'][$k]['checked'] = '0';
  301. }
  302. }
  303. foreach ($res_detail_info['inout_type'] as $k => $v) {
  304. if ($v['id'] == $res_v['inout_type']) {
  305. $res_detail_info['inout_type'][$k]['checked'] = '1';
  306. } else {
  307. $res_detail_info['inout_type'][$k]['checked'] = '0';
  308. }
  309. }
  310. foreach ($res_detail_info['check_port'] as $k => $v) {
  311. if ($v['id'] == $res_v['checkport_res_id']) {
  312. $res_detail_info['check_port'][$k]['checked'] = '1';
  313. } else {
  314. $res_detail_info['check_port'][$k]['checked'] = '0';
  315. }
  316. }
  317. $res_detail_info['start_minutes'] = $res_v['start_minutes'];
  318. $res_detail_info['distance'] = $res_v['distance'];
  319. $res_array[$order_id] = $res_detail_info;
  320. }
  321. $json['code'] = '0';
  322. $json['info'] = '返回数据成功';
  323. $json['line_info'] = $line_base_info;
  324. $json['station_info'] = array_merge($res_array);
  325. return json_encode($json);
  326. }
  327. public function actionUptLine()
  328. {
  329. $user_id = Yii::$app->request->post('user_id');
  330. $line_code = Yii::$app->request->post('line_code');
  331. $line_name = Yii::$app->request->post('line_name');
  332. $line_type = Yii::$app->request->post('line_type');
  333. $line_sub_type = Yii::$app->request->post('line_sub_type');
  334. $time_type = Yii::$app->request->post('time_type');
  335. $time_info = Yii::$app->request->post('time_info');
  336. $supply_id = Yii::$app->request->post('supply_id');
  337. $station_list = Yii::$app->request->post('station_list');
  338. $tailor_flag = Yii::$app->request->post('tailor_flag');
  339. $line_id = Yii::$app->request->post('line_id');
  340. $remark = Yii::$app->request->post('remark', '');
  341. $run_duty_id = Yii::$app->request->post('run_duty_id', 0);
  342. $allow_selected_seat = Yii::$app->request->post('allow_selected_seat');
  343. // 开启事务
  344. $transaction = Yii::$app->db->beginTransaction();
  345. try {
  346. // 判断线路编号是否已存在
  347. $opera_line = new OperaLine();
  348. $res_check = $opera_line->checkLine($line_code, $line_id);
  349. if (count($res_check) > 0) {
  350. throw new Exception('线路编号已存在');
  351. }
  352. // 添加线路
  353. // 获取CS运营主体ID
  354. $base_user = new BaseUser();
  355. $main_corp_id = $base_user->getMainCorpIdByUserId($user_id);
  356. if ($main_corp_id) {
  357. $main_corp_id = $main_corp_id['main_corp_id'];
  358. }
  359. // 站点信息
  360. $station_list = strtr($station_list, [' ' => '']);
  361. $station_list = ltrim($station_list, '{');
  362. $station_list = rtrim($station_list, '}');
  363. $station_list = explode('}{', $station_list);
  364. // 更新站点
  365. $opera_station = new OperaStation();
  366. // 删除所有站点
  367. $res = $opera_station->delAllStation($line_id);
  368. if ($res == false) {
  369. throw new Exception('删除站点失败');
  370. }
  371. foreach ($station_list as $info) {
  372. $info = explode(',', $info);
  373. $table = clone $opera_station;
  374. // 获取线路对象
  375. $order_id = $info[1];
  376. $obj = $table->getStationObj($order_id, $line_id);
  377. if ($obj == false) {
  378. // 添加新路
  379. $res = $table->addStation($user_id, $line_id, $info[0], $info[1], $info[2], $info[3], $info[4], $info[5], $info[6]);
  380. if ($res === false) {
  381. throw new Exception('插入站点失败');
  382. }
  383. } else {
  384. $res = $table->uptStation($user_id, $line_id, $info[0], $info[1], $info[2], $info[3], $info[4], $info[5], $info[6]);
  385. if ($res === false) {
  386. throw new Exception('站点更新失败');
  387. }
  388. }
  389. }
  390. // 更新线路
  391. $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);
  392. if ($res == false) {
  393. throw new Exception('线路更新失败');
  394. }
  395. // 提交事务
  396. $transaction->commit();
  397. $data = [
  398. 'code' => 0,
  399. 'info' => '数据插入成功',
  400. 'line_id' => $line_id,
  401. 'line_type' => $line_type,
  402. ];
  403. } catch (Exception $e) {
  404. // 回滚事务
  405. $transaction->rollBack();
  406. $data = [
  407. 'code' => 1,
  408. 'info' => $e->getMessage()
  409. ];
  410. }
  411. return json_encode($data, true);
  412. }
  413. }