getLineList($line_code,$line_status,$use_status,$line_type,$tailor_type,$run_duty_id,$current_page,$page_size); return $line_list; } /** * Function Description:线路启用/停用 * Function Name: LineUpt * @param $opt_code * @param $line_id_str * * @return array * * @author 冒炎 */ public function LineUpt($opt_code,$line_id_str){ if(($opt_code!=1&&$opt_code!=2)||$line_id_str == -1){ return [ 'code'=>1, 'msg'=>'参数有误' ]; } if($opt_code ==1){ $ex_msg = '启用'; }else{ $ex_msg = '停用'; } $model = new OperaLine(); $upt_res = $model->LineUpt($opt_code,$line_id_str); if($upt_res ==1){ return [ 'code'=>0, 'msg'=>$ex_msg . '成功' ]; }else if($upt_res ==-1){ return [ 'code'=>3, 'msg'=>'线路下有未完成的班次,操作失败' ]; }else{ return [ 'code'=>2, 'msg'=>'操作失败' ]; } } /** * Function Description:获得站点详情 * Function Name: getAreaByRes * @param $res_id * * @return mixed * * @author 冒炎 */ public function getAreaByRes($res_id){ if($res_id == -1){ $data['code']= '2'; $data ['info'] = '参数有误'; return $data; } $model = new BaseResource(); $area= $model->getAreaByRes($res_id); if ($area['area_id'] == 0) { $data['code'] = '1'; $data['info'] = '该站点无应用POI,请先配置应用POI!'; return $data; } $res_info = $model->getStationsByres($res_id); $res_info['parent_area_id_list'] = substr($res_info['parent_area_id_list'], 1, -1); $res_info['parent_area_name_list'] = substr($res_info['parent_area_name_list'], 1, -1); $res_info['parent_area_id_list'] = explode("}{", $res_info['parent_area_id_list']);//应用POI站点id数组 $res_info['parent_area_name_list'] = explode("}{", $res_info['parent_area_name_list']);//应用POI站点name数组 $res_info['checkport_res_id'] = explode(",", $res_info['checkport_res_id']);//检票口id数组 $res_info['checkport_res_name'] = explode(",", $res_info['checkport_res_name']);//检票口name数组 //规整返回前端的站点数据 $res = array(); $res['res_id'] = $res_info['res_id']; $res['res_name'] = $res_info['res_name']; foreach ($res_info['parent_area_id_list'] as $k => $v) { $res['parent_area'][$k]['id'] = $v; $res['parent_area'][$k]['name'] = $res_info['parent_area_name_list'][$k]; } foreach ($res_info['checkport_res_id'] as $k => $v) { $res['check_port'][$k]['id'] = $v; $res['check_port'][$k]['name'] = $res_info['checkport_res_name'][$k]; } $res['inout_type'] = array( 0 => array( 'id' => '108', 'name' => '上' ), 1 => array( 'id' => '109', 'name' => '上下' ), 2 => array( 'id' => '110', 'name' => '下' ) ); $data['code'] = '0'; $data['info'] = '返回数据成功'; $data['res_info'] = $res; return $data; } /** * Function Description:根据名字搜索站点名 * Function Name: getLineStation * @param $res_name * * @return mixed * * @author 冒炎 */ public function getLineStation($res_name){ if($res_name == -1){ $data['code'] = '1'; $data['info'] = '参数有误'; return $data; } $model = new BaseResource(); $res_list = $model->getLineStationByRes($res_name); $data['code'] = '0'; $data['info'] = '返回数据成功'; $data['res_list'] = $res_list; return $data; } /** * Function Description:获取运营商列表数据 * Function Name: getBaseInfo * * @return array * * @author 冒炎 */ public function getBaseInfo(){ $model = new BaseSupplierPurchase(); $list = $model->getSupplies(); $data = [ 'list'=>$list ]; return $data; } /** * Function Description:根据line_id获取票种列表 * Function Name: getTicketList * @param $line_id * @param $current_page * @param $page_size * * @return mixed * * @author 冒炎 */ public function getTicketList($line_id,$current_page,$page_size){ $model = new OperaTicketsGroup(); $data = $model->GetTicketListByLineId($line_id,$current_page,$page_size); return $data; } /** * Function Description:获取票种配置信息 * Function Name: getTicketBase * @param $line_id * * @return mixed * * @author 冒炎 */ public function getTicketBase($line_id){ $model = new OperaStation(); $data = $model->getTicketBase($line_id); return $data; } /** * Function Description:根据起始站获得终点站 * Function Name: getTicketEndStation * @param $line_id * @param $start_res_id * * @return mixed * * @author 冒炎 */ public function getTicketEndStation($line_id,$start_res_id){ $model = new OperaStation(); $data = $model->getTicketEndStation($line_id,$start_res_id); return $data; } /** * Function Description:添加票种保存数据 * Function Name: addTicketSave * @param $line_id * @param $station_str * @param $prod_price * @param $cus_price * @param $cost_price * @param $seat_type * @param $human_type * @param $user_id * @param $create_time * * @return mixed * @throws \yii\db\Exception * * @author 冒炎 */ public function addTicketSave($line_id,$station_str,$prod_price,$cus_price,$cost_price,$seat_type,$human_type,$user_id,$create_time){ $model = new OperaTickets(); $ticket_name_sql = "select type_name from dict_type where id = " . $seat_type; $ticket_name = \Yii::$app->db->createCommand($ticket_name_sql)->queryOne(); $ticket_name = $ticket_name['type_name'] . "票"; //获取最大的ticket_id $ticket_id_sql = "select ifnull(max(ticket_id),0) as ticket_id from opera_tickets"; $ticket_id = \Yii::$app->db->createCommand($ticket_id_sql)->queryOne(); $ticket_id = $ticket_id['ticket_id']; $station_str = substr($station_str,1,-1); $station_array = explode("}{",$station_str); //获取检验是否存在票种的查询条件 foreach($station_array as $k => $v) { $res_group = explode(",",$v); //获取所有的站点id; $res_array[$res_group[0]] = $res_group[0]; $res_array[$res_group[1]] = $res_group[1]; $check_arr[] = "(start_station_res_id = " . $res_group[0] . " and end_station_res_id = " . $res_group[1] . ")"; } $check_str = "(" . implode(" or ",$check_arr) . ")"; //检查是否存在已添加的票种 $check_sql = "SELECT start_station_res_id, (SELECT res_name FROM base_resource WHERE res_id = t.start_station_res_id) as start_station_res_name, end_station_res_id, (SELECT res_name FROM base_resource WHERE res_id = t.end_station_res_id) as end_station_res_name FROM opera_tickets as t WHERE line_id = " . $line_id . " AND cancel_flag = 0 AND seat_type = " . $seat_type . " AND human_type = " . $human_type . " AND " . $check_str; $check_ticket = \Yii::$app->db->createCommand($check_sql)->queryAll(); if(count($check_ticket) > 0) { $info_array = array(); foreach($check_ticket as $k => $v) { $info_array[] = $v['start_station_res_name'] . "-" . $v['end_station_res_name']; } $json['code'] = '1'; $json['info'] = implode(",",$info_array) . "的该人群及座位等级已添加过,添加失败"; return $json; } //查询所有站点ID的area_id $area_sql = "SELECT area_id, res_id FROM opera_station WHERE line_id = " . $line_id . " AND res_id in (" . implode(",",$res_array) . ") AND cancel_flag = 0"; $res_area = \Yii::$app->db->createCommand($area_sql)->queryAll(); //查询所有的站点名称 $area_sql = "SELECT res_id, res_name FROM base_resource WHERE res_id in (" . implode(",",$res_array) . ") AND cancel_flag = 0"; $res_name = \Yii::$app->db->createCommand($area_sql)->queryAll(); foreach ($res_area as $k => $v) { $res_area_array[$v['res_id']] = $v['area_id']; } foreach ($res_name as $k => $v) { $res_name_array[$v['res_id']] = $v['res_name']; } $insert_ticket_sql = "INSERT INTO opera_tickets ( ticket_id, create_user_id, create_time, update_user_id, cancel_flag, line_id, ticket_name, ticket_type, start_station_res_id, end_station_res_id, start_station_area_id, end_station_area_id, seat_type, human_type, prod_price, cus_price, cost_price, is_onsale ) VALUES "; foreach($station_array as $k => $v) { $ticket_id ++; $ticket_group[] = $ticket_id; $station_res_group = explode(",",$v); $station_id_group[] = $station_res_group[0] . "-" . $station_res_group[1];//站点联系组合 $station_name_group[] = $res_name_array[$station_res_group[0]] . "-" . $res_name_array[$station_res_group[1]];//站点名称联系组合 $ticket_sql_array[] = "(" . $ticket_id . "," . $user_id . ",'" . $create_time . "'," . $user_id . ",0," . $line_id . ",'" . $ticket_name . "',1," . $station_res_group[0] . "," . $station_res_group[1] . "," . $res_area_array[$station_res_group[0]] . "," . $res_area_array[$station_res_group[1]] . "," . $seat_type . "," . $human_type . ",'" . $prod_price . "','" . $cus_price . "','" . $cost_price . "',0)"; } $ticket_sql = implode(",",$ticket_sql_array); $insert_ticket_sql .= $ticket_sql; //添加票种分组 $insert_ticket_group_sql = "INSERT INTO opera_tickets_group ( create_user_id, create_time, update_user_id, update_time, cancel_flag, line_id, ticket_id, station_id, station_name, seat_type, human_type, prod_price, cus_price, cost_price ) VALUES(" . $user_id . ",'" . $create_time . "'," . $user_id . ",'" . $create_time . "',0," . $line_id . ",'" . implode(",",$ticket_group) . "','" . implode(",",$station_id_group) . "','" . implode(",",$station_name_group) . "'," . $seat_type . "," . $human_type . ",'" . $prod_price . "','" . $cus_price . "','" . $cost_price . "')"; // zzcsUtils::writeLog($insert_ticket_sql); $result1 = \Yii::$app->db->createCommand($insert_ticket_sql)->execute(); // zzcsUtils::writeLog($insert_ticket_group_sql); $result2 = \Yii::$app->db->createCommand($insert_ticket_group_sql)->execute(); if($result1 && $result2) { $json['code'] = '0'; $json['info'] = '添加票种成功'; } else { $json['code'] = '1'; $json['info'] = '后台逻辑有误'; } return $json; } /** * Function Description:票种修改数据保存 * Function Name: uptTicketSave * @param $line_id * @param $group_id * @param $ticket_id * @param $prod_price * @param $cus_price * @param $cost_price * @param $user_id * @param $update_time * * @return array * @throws \yii\db\Exception * * @author 冒炎 */ public function uptTicketSave($line_id,$group_id,$ticket_id,$prod_price,$cus_price,$cost_price,$user_id,$update_time){ //判断分销价是否改变,改变需要操作下属分销 $get_prod_price_sql="select prod_price from opera_tickets where ticket_id in ($ticket_id) limit 1"; $tmp_prod_price = \Yii::$app->db->createCommand($get_prod_price_sql)->queryOne(); if($tmp_prod_price['prod_price'] != $prod_price){ $url='http://'.CS1_DOMAIN.'/zzcs/agent-product/upt-status-for-self-sale'; $cookie="user_id=$user_id"; $send_data=array( 'prod_price'=>$prod_price, 'ticket_list'=>$ticket_id, 'is_onsale'=>0 ); $result= $this->httpRequestForYii($url,$send_data,$cookie); $result=unserialize($result); if($result['code']!=0){ return array( 'code'=>1, 'info'=>'票种代售授权失败' ); } } $ticket_sql = "UPDATE opera_tickets SET prod_price = '" . $prod_price . "', cus_price = '" . $cus_price . "', cost_price = '" . $cost_price . "', update_user_id = " . $user_id . ", update_time = '" . $update_time . "' WHERE line_id = " . $line_id . " AND cancel_flag = 0 AND ticket_id IN (" . $ticket_id . ")"; $ticket_group_sql = "UPDATE opera_tickets_group SET prod_price = '" . $prod_price . "', cus_price = '" . $cus_price . "', cost_price = '" . $cost_price . "', update_user_id = " . $user_id . ", update_time = '" . $update_time . "' WHERE line_id = " . $line_id . " AND cancel_flag = 0 AND id = " . $group_id; //zzcsUtils::writeLog($ticket_sql); $result1 = \Yii::$app->db->createCommand($ticket_sql)->execute(); //zzcsUtils::writeLog($ticket_group_sql); $result2 = \Yii::$app->db->createCommand($ticket_group_sql)->execute(); if($result1 && $result2) { $json['code'] = '0'; $json['info'] = '修改价格成功'; } else { $json['code'] = '1'; $json['info'] = '后台逻辑有误'; } return $json; } public function deleteTicket($line_id,$group_id,$ticket_id,$user_id,$update_time,$current_day){ $ticket_type_exists_sql = "SELECT count(order_id) as total_num FROM `order_main` WHERE `order_status` IN (145,146) AND `RUN_DATE` >= '{$current_day}' AND `PROD_ID` IN ($ticket_id)"; $run_bus_exists_sql = "SELECT count(id) as total_num2 FROM `run_bus` WHERE `RUN_ID` IN (SELECT `RUN_ID` FROM `run_main` WHERE `PROD_id`= '{$line_id}') AND `RUN_BUS_STATUS` IN (137,138,139)"; $result5 = \Yii::$app->db->createCommand($ticket_type_exists_sql)->queryOne(); $result6 = \Yii::$app->db->createCommand($run_bus_exists_sql)->queryOne(); if( $result5["total_num"] > 0 || $result6["total_num2"] > 0 ) { $json['code'] = '3'; $json['info'] = $result5["total_num"] > 0 ? '请将该票种相关未完成的订单全部取消后再执行删除操作' : '请将该线路的未完成班次全部停运后再执行删除操作' ; return $json; } $ticket_sql = "UPDATE opera_tickets SET cancel_flag = 1, update_user_id = " . $user_id . ", update_time = '" . $update_time . "' WHERE line_id = " . $line_id . " AND cancel_flag = 0 AND ticket_id IN (" . $ticket_id . ")"; $ticket_group_sql = "UPDATE opera_tickets_group SET cancel_flag = 1, update_user_id = " . $user_id . ", update_time = '" . $update_time . "' WHERE line_id = " . $line_id . " AND cancel_flag = 0 AND id = " . $group_id; //将opera_message_template表的相关数据cancel_flag置为1 $ticket_template_sql = "UPDATE opera_message_template SET cancel_flag = 1, update_user_id = " . $user_id . ", update_time = '" . $update_time . "' WHERE template_type=2 AND cancel_flag = 0 AND ticket_group_id = " . $group_id; // zzcsUtils::writeLog($ticket_sql); $result1 = \Yii::$app->db->createCommand($ticket_sql)->execute(); // zzcsUtils::writeLog($ticket_group_sql); $result2 = \Yii::$app->db->createCommand($ticket_group_sql)->execute(); // zzcsUtils::writeLog($ticket_template_sql); $result3 = \Yii::$app->db->createCommand($ticket_template_sql)->execute(); if($result1 && $result2) { //删除票种后,代售信息删除 $url='http://'.CS1_DOMAIN.'/zzcs/agent-product/delete-ticket'; $cookie="user_id=$user_id"; $send_data=array( 'ticket_list'=>$ticket_id, ); $result4=$this->httpRequestForYii($url,$send_data,$cookie); //return unserialize($result); $json['code'] = '0'; $json['info'] = '删除票种成功'; } else { $json['code'] = '1'; $json['info'] = '后台逻辑有误'; } return $json; } /** * Function Description:票种上下架 * Function Name: sendInfo * @param $ticket_list * @param $is_onsale * * @return mixed * * @author 冒炎 */ public function sendInfo($ticket_list,$is_onsale){ $param = []; $param['ticket_list'] = $ticket_list; $param['is_onsale'] = $is_onsale; $url='http://'.CS1_DOMAIN.'/zzcs/agent-product/upt-status-for-self-sale'; $user_id = \Yii::$app->request->cookies->getValue('user_id',-1); $cookie="user_id=$user_id"; $result=$this->httpRequestForYii($url,$param,$cookie); return unserialize($result); } /** * Function Description:修改票种是否需要检票属性 * Function Name: CheckChange * @param $ticket_list * @param $is_check * * @return array * * @author 冒炎 */ public function CheckChange($ticket_list,$is_check){ $model = new OperaTickets(); $ticket_arr = explode(',', $ticket_list); foreach($ticket_arr as $ticket_id){ $model->uptIsCheck($ticket_id,$is_check); } return [ 'code'=>0, 'info'=>'修改成功' ]; } public function httpRequestForYii($url,$data=null,$cookie) { $ch=curl_init(); curl_setopt($ch, CURLOPT_COOKIE, $cookie); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); if (!empty($data)){ curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); } curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output=curl_exec($ch); curl_close($ch); return $output; } /** * Function Description:获取运营负责人信息列表 * Function Name: getRunDuty * @param $user_id * @return array|\yii\db\ActiveRecord[] * @author 田玲菲 */ public function getRunDuty($user_id){ $baseUser = new BaseUser(); $res = $baseUser->getRunDutyList($user_id); return $res; } }