You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

189 lines
8.0 KiB

  1. <?php
  2. /*
  3. Author:XM
  4. Compeny:Spiders Travel
  5. */
  6. require_once '../Common/Mysql.php';
  7. require_once '../Common/Function.php';
  8. if (ALLOW_ORIGIN)
  9. header("Access-Control-Allow-Origin:*");
  10. $userid = getUserId();
  11. if ($userid === false) {
  12. echo json_encode(array("code" => 1, "info" => "用户未登录"));
  13. exit;
  14. }
  15. $runid = $_GET['runid'];
  16. $startime = $_GET['startime'];
  17. $allstation = $_GET['allstation'];
  18. $allcar = $_GET['allcar'];
  19. $allticket = $_GET['allticket'];
  20. $sellday = $_GET['sellday'];
  21. $pdo = conn();
  22. $flag = checkData($pdo, $runid, $allcar);
  23. if (!$flag) {
  24. $data = array('errcode' => '1', 'errinfo' => '保存失败,已派车的数据不能进行数据修改');
  25. echo json_encode($data);
  26. return;
  27. }
  28. $yii_url = 'http://'.CS1_DOMAIN.'/api/dynamic-bus/run-bus-update';
  29. $send_data = array(
  30. 'user_id'=>$userid,
  31. 'run_id'=>$runid,
  32. 'start_time'=>$startime,
  33. 'all_station'=>$allstation,
  34. 'all_car'=>$allcar,
  35. 'all_ticket'=>$allticket,
  36. 'sell_day'=>$sellday
  37. );
  38. //$sql = "call sp_bus_run_update(" . $userid . "," . $runid . ",'" . $startime . "','" . $allstation . "','" . $allcar . "','" . $allticket . "'," . $sellday . ")";
  39. //writeLog("sp_bus_run_update: " . $sql);
  40. if (is_object($pdo)) {
  41. /* $result = $pdo->query($sql);
  42. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  43. $result->closeCursor();*/
  44. $res = httpRequest($yii_url,$send_data);
  45. $allcar = substr($allcar, 1, -1);
  46. $allcar = explode('}{', $allcar);
  47. $content = '';
  48. foreach ($allcar as $key => $vel) {
  49. $vel = explode(',', $vel);
  50. if ($vel[0] != 0) {
  51. $title = '';
  52. $content .= get_send_mail_info($pdo, $runid, $vel[0], $vel[5], $vel[6], $vel[4], $title);
  53. $sql = "update run_bus set cost_motorcade_id = " . $vel[4] . ",cost_type = " . $vel[5] . ",cost_price = " . $vel[6] . " where run_id = " . $runid . " and bus_order_id = " . $vel[0] . " and cancel_flag = 0";
  54. $result = $pdo->exec($sql);
  55. //获取run_bus id
  56. $sql = "select id from run_bus where run_id = {$runid} and bus_order_id = {$vel[0]} and cancel_flag = 0";
  57. $result = $pdo->query($sql);
  58. $rowset1 = $result->fetch();
  59. //发送完之后进行车管系统接口调用
  60. $motor_request = httpRequest(CS1_DOMAIN . '/motorcade/bus/sync-one?run_bus_id_str=' . $rowset1['id']);
  61. writeLog("sp_bus_run_update httpRequest: " . $motor_request);
  62. }
  63. }
  64. $to_message_person_arr = array(
  65. 'qius@zhizhuchuxing.com',
  66. 'liuxm@zhizhuchuxing.com',
  67. 'panb@zhizhuchuxing.com',
  68. 'chenjz@zhizhuchuxing.com',
  69. 'shiql@zhizhuchuxing.com',
  70. 'huhh@zhizhuchuxing.com',
  71. 'wangyj@zhizhuchuxing.com',
  72. 'linjf@zhizhuchuxing.com'
  73. );
  74. $to_persons_str = implode(',', $to_message_person_arr);
  75. if (strlen($content) > 0) {
  76. // foreach ($to_message_person_arr as $value) {
  77. send_mail('operations@zhizhuchuxing.com', 'Zzcx88888', $to_persons_str, $title . '发车的 线路派车价格有变动请确认', $content);
  78. // }
  79. }
  80. // //发送完之后进行车管系统接口调用
  81. // $motor_request = httpRequest(CS1_DOMAIN . '/motorcade/bus/sync-one?run_bus_id_str=' . $runid);
  82. // writeLog("sp_bus_run_update httpRequest: " . $motor_request);
  83. // if ($send_mail_res['code'] != '0') {
  84. // $rowset[0]['errcode'] = '3';
  85. // $rowset[0]['errcode'] = '数据保存成功,但是邮件发送失败,请手动发送邮件';
  86. // }
  87. echo $res;
  88. }
  89. /**
  90. * Function Description:检查数据
  91. * Function Name: checkData
  92. * @param PDO $pdo
  93. * @param $run_id
  94. * @param $allcar
  95. *
  96. * @return bool
  97. *
  98. * @author LUOCJ
  99. */
  100. function checkData(PDO $pdo, $run_id, $allcar)
  101. {
  102. $tmp_str = substr($allcar, 1, strlen($allcar) - 2);
  103. $tmp_arr = explode('}{', $tmp_str);
  104. foreach ($tmp_arr as $value) {
  105. $value_arr = explode(',', $value);
  106. if ($value_arr[0] != 0) {
  107. $sql = "select send_bus_res_id,cost_motorcade_id,cost_type,cost_price from run_bus where run_id ={$run_id} and bus_order_id ={$value_arr[0]} and cancel_flag = 0";
  108. $result = $pdo->query($sql);
  109. $rowset = $result->fetch(PDO::FETCH_ASSOC);
  110. $result->closeCursor();
  111. if ($rowset['send_bus_res_id'] == 0)
  112. continue;
  113. if ($rowset['cost_motorcade_id'] != $value_arr[4] || $rowset['cost_type'] != $value_arr[5] || $rowset['cost_price'] != $value_arr[6]) {
  114. return false;
  115. }
  116. }
  117. }
  118. return true;
  119. }
  120. function get_send_mail_info(PDO $pdo, $run_id, $bus_order_id, $cost_type, $cost_price, $cost_motorcade_id, &$title)
  121. {
  122. $sql = "select line_name,line_code from run_prod inner join opera_line on opera_line.line_id = run_prod.parent_prod_id where run_prod.run_id =$run_id and run_prod.cancel_flag=0";
  123. $result = $pdo->query($sql);
  124. $rowset = $result->fetch();
  125. $result->closeCursor();
  126. $sql = "select run_bus.cost_motorcade_id,run_bus.cost_price,run_bus.cost_type,base_supplier.supplier_name from run_bus left join base_supplier on base_supplier.id = run_bus.cost_motorcade_id where run_bus.run_id = $run_id and run_bus.bus_order_id = $bus_order_id and run_bus.cancel_flag = 0";
  127. $result = $pdo->query($sql);
  128. $rowset1 = $result->fetch();
  129. $result->closeCursor();
  130. $sql = "select supplier_name from base_supplier where id = $cost_motorcade_id";
  131. $result = $pdo->query($sql);
  132. $rowset2 = $result->fetch();
  133. $result->closeCursor();
  134. $sql = "select run_date,run_time from run_main where run_id = {$run_id}";
  135. $result = $pdo->query($sql);
  136. $rowset3 = $result->fetch();
  137. $result->closeCursor();
  138. $show_now_cost_type = $cost_type == 477 ? '包车计价' : '车座计价';
  139. $show_now_cost_price = $cost_price;
  140. $show_past_cost_type = $rowset1['cost_type'] == 477 ? '包车计价' : '车座计价';
  141. $show_past_cost_price = $rowset1['cost_price'];
  142. $show_past_supplier_name = $rowset1['supplier_name'];
  143. $show_now_supplier_name = $rowset2['supplier_name'];
  144. if (
  145. (
  146. $show_now_cost_type == $show_past_cost_type &&
  147. $show_now_cost_price == $show_past_cost_price &&
  148. (in_array($cost_motorcade_id, array(628)) && in_array($rowset1['cost_motorcade_id'], array(628))) &&
  149. $show_now_supplier_name == $show_past_supplier_name
  150. ) || (!in_array($cost_motorcade_id, array(628)) && !in_array($rowset1['cost_motorcade_id'], array(628)))
  151. ) {
  152. return '';
  153. }
  154. $title .= "{$rowset3['run_date']} {$rowset3['run_time']}";
  155. // $content = "{$rowset3['run_date']} {$rowset3['run_time']} 发车的 线路:{$rowset['line_name']} 线路代码: {$rowset['line_code']} 车次:{$bus_order_id} 的用车成本已被修改,具体修改信息如下:";
  156. // if ($show_past_supplier_name != $show_now_supplier_name) {
  157. // $content .= " 车队由{$show_past_supplier_name}变更为{$show_now_supplier_name}";
  158. // }
  159. // if (!($show_past_cost_type == $show_now_cost_type && $show_past_cost_price == $show_now_cost_price)) {
  160. // $content .= " 旧:{$show_past_cost_type} :{$show_past_cost_price} 新:{$show_now_cost_type} :{$show_now_cost_price}";
  161. // }
  162. $content = "发车时间:{$rowset3['run_date']} {$rowset3['run_time']}<br/>";
  163. $content .= "线路名称:{$rowset['line_name']}<br/>";
  164. $content .= "线路代码:{$rowset['line_code']}<br/>";
  165. $content .= "车次号:{$bus_order_id}<br/>";
  166. if ($show_past_supplier_name != $show_now_supplier_name) {
  167. $content .= "车队变更情况:车队由{$show_past_supplier_name}变更为{$show_now_supplier_name}";
  168. }
  169. if (!($show_past_cost_type == $show_now_cost_type && $show_past_cost_price == $show_now_cost_price)) {
  170. $show_past_cost_price = number_format($show_past_cost_price, 2);
  171. $show_now_cost_price = number_format($show_now_cost_price, 2);
  172. $content .= "成本变更情况:由{$show_past_cost_price}({$show_past_cost_type})变更为{$show_now_cost_price}({$show_now_cost_type})";
  173. }
  174. return $content;
  175. }