1, "info" => "用户未登录"));
exit;
}
$runid = $_GET['runid'];
$startime = $_GET['startime'];
$allstation = $_GET['allstation'];
$allcar = $_GET['allcar'];
$allticket = $_GET['allticket'];
$sellday = $_GET['sellday'];
$pdo = conn();
$flag = checkData($pdo, $runid, $allcar);
if (!$flag) {
$data = array('errcode' => '1', 'errinfo' => '保存失败,已派车的数据不能进行数据修改');
echo json_encode($data);
return;
}
$yii_url = 'http://'.CS1_DOMAIN.'/api/dynamic-bus/run-bus-update';
$send_data = array(
'user_id'=>$userid,
'run_id'=>$runid,
'start_time'=>$startime,
'all_station'=>$allstation,
'all_car'=>$allcar,
'all_ticket'=>$allticket,
'sell_day'=>$sellday
);
//$sql = "call sp_bus_run_update(" . $userid . "," . $runid . ",'" . $startime . "','" . $allstation . "','" . $allcar . "','" . $allticket . "'," . $sellday . ")";
//writeLog("sp_bus_run_update: " . $sql);
if (is_object($pdo)) {
/* $result = $pdo->query($sql);
$rowset = $result->fetchAll(PDO::FETCH_ASSOC);
$result->closeCursor();*/
$res = httpRequest($yii_url,$send_data);
$allcar = substr($allcar, 1, -1);
$allcar = explode('}{', $allcar);
$content = '';
foreach ($allcar as $key => $vel) {
$vel = explode(',', $vel);
if ($vel[0] != 0) {
$title = '';
$content .= get_send_mail_info($pdo, $runid, $vel[0], $vel[5], $vel[6], $vel[4], $title);
$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";
$result = $pdo->exec($sql);
//获取run_bus id
$sql = "select id from run_bus where run_id = {$runid} and bus_order_id = {$vel[0]} and cancel_flag = 0";
$result = $pdo->query($sql);
$rowset1 = $result->fetch();
//发送完之后进行车管系统接口调用
$motor_request = httpRequest(CS1_DOMAIN . '/motorcade/bus/sync-one?run_bus_id_str=' . $rowset1['id']);
writeLog("sp_bus_run_update httpRequest: " . $motor_request);
}
}
$to_message_person_arr = array(
'qius@zhizhuchuxing.com',
'liuxm@zhizhuchuxing.com',
'panb@zhizhuchuxing.com',
'chenjz@zhizhuchuxing.com',
'shiql@zhizhuchuxing.com',
'huhh@zhizhuchuxing.com',
'wangyj@zhizhuchuxing.com',
'linjf@zhizhuchuxing.com'
);
$to_persons_str = implode(',', $to_message_person_arr);
if (strlen($content) > 0) {
// foreach ($to_message_person_arr as $value) {
send_mail('operations@zhizhuchuxing.com', 'Zzcx88888', $to_persons_str, $title . '发车的 线路派车价格有变动请确认', $content);
// }
}
// //发送完之后进行车管系统接口调用
// $motor_request = httpRequest(CS1_DOMAIN . '/motorcade/bus/sync-one?run_bus_id_str=' . $runid);
// writeLog("sp_bus_run_update httpRequest: " . $motor_request);
// if ($send_mail_res['code'] != '0') {
// $rowset[0]['errcode'] = '3';
// $rowset[0]['errcode'] = '数据保存成功,但是邮件发送失败,请手动发送邮件';
// }
echo $res;
}
/**
* Function Description:检查数据
* Function Name: checkData
* @param PDO $pdo
* @param $run_id
* @param $allcar
*
* @return bool
*
* @author LUOCJ
*/
function checkData(PDO $pdo, $run_id, $allcar)
{
$tmp_str = substr($allcar, 1, strlen($allcar) - 2);
$tmp_arr = explode('}{', $tmp_str);
foreach ($tmp_arr as $value) {
$value_arr = explode(',', $value);
if ($value_arr[0] != 0) {
$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";
$result = $pdo->query($sql);
$rowset = $result->fetch(PDO::FETCH_ASSOC);
$result->closeCursor();
if ($rowset['send_bus_res_id'] == 0)
continue;
if ($rowset['cost_motorcade_id'] != $value_arr[4] || $rowset['cost_type'] != $value_arr[5] || $rowset['cost_price'] != $value_arr[6]) {
return false;
}
}
}
return true;
}
function get_send_mail_info(PDO $pdo, $run_id, $bus_order_id, $cost_type, $cost_price, $cost_motorcade_id, &$title)
{
$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";
$result = $pdo->query($sql);
$rowset = $result->fetch();
$result->closeCursor();
$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";
$result = $pdo->query($sql);
$rowset1 = $result->fetch();
$result->closeCursor();
$sql = "select supplier_name from base_supplier where id = $cost_motorcade_id";
$result = $pdo->query($sql);
$rowset2 = $result->fetch();
$result->closeCursor();
$sql = "select run_date,run_time from run_main where run_id = {$run_id}";
$result = $pdo->query($sql);
$rowset3 = $result->fetch();
$result->closeCursor();
$show_now_cost_type = $cost_type == 477 ? '包车计价' : '车座计价';
$show_now_cost_price = $cost_price;
$show_past_cost_type = $rowset1['cost_type'] == 477 ? '包车计价' : '车座计价';
$show_past_cost_price = $rowset1['cost_price'];
$show_past_supplier_name = $rowset1['supplier_name'];
$show_now_supplier_name = $rowset2['supplier_name'];
if (
(
$show_now_cost_type == $show_past_cost_type &&
$show_now_cost_price == $show_past_cost_price &&
(in_array($cost_motorcade_id, array(628)) && in_array($rowset1['cost_motorcade_id'], array(628))) &&
$show_now_supplier_name == $show_past_supplier_name
) || (!in_array($cost_motorcade_id, array(628)) && !in_array($rowset1['cost_motorcade_id'], array(628)))
) {
return '';
}
$title .= "{$rowset3['run_date']} {$rowset3['run_time']}";
// $content = "{$rowset3['run_date']} {$rowset3['run_time']} 发车的 线路:{$rowset['line_name']} 线路代码: {$rowset['line_code']} 车次:{$bus_order_id} 的用车成本已被修改,具体修改信息如下:";
// if ($show_past_supplier_name != $show_now_supplier_name) {
// $content .= " 车队由{$show_past_supplier_name}变更为{$show_now_supplier_name}";
// }
// if (!($show_past_cost_type == $show_now_cost_type && $show_past_cost_price == $show_now_cost_price)) {
// $content .= " 旧:{$show_past_cost_type} :{$show_past_cost_price} 新:{$show_now_cost_type} :{$show_now_cost_price}";
// }
$content = "发车时间:{$rowset3['run_date']} {$rowset3['run_time']}
";
$content .= "线路名称:{$rowset['line_name']}
";
$content .= "线路代码:{$rowset['line_code']}
";
$content .= "车次号:{$bus_order_id}
";
if ($show_past_supplier_name != $show_now_supplier_name) {
$content .= "车队变更情况:车队由{$show_past_supplier_name}变更为{$show_now_supplier_name}";
}
if (!($show_past_cost_type == $show_now_cost_type && $show_past_cost_price == $show_now_cost_price)) {
$show_past_cost_price = number_format($show_past_cost_price, 2);
$show_now_cost_price = number_format($show_now_cost_price, 2);
$content .= "成本变更情况:由{$show_past_cost_price}({$show_past_cost_type})变更为{$show_now_cost_price}({$show_now_cost_type})";
}
return $content;
}