getWhere($supplier_name, $is_disabled); //2.获取数据库原始数据 $db_data = $this->getDbData($sql_where, $product_type,$current,$pagesize); //3.处理数据 $tidyData = $this->tidyData($db_data['supplier_array']); $tidyData['total_page'] = (string)$db_data['total_page']; echo json_encode($tidyData); exit(); } //获取筛选条件 function getWhere($supplier_name, $is_disabled) { $res = array(); if (!empty($is_disabled) && $is_disabled != -1) { $res[] = " is_disabled = " . $is_disabled; } if (!empty($supplier_name)) { $res[] = " supplier_name like '%%" . $supplier_name . "%%' "; } $main_corp_id = isset($_COOKIE["user_main_corp"]) ? $_COOKIE["user_main_corp"] : 0; if( $main_corp_id == 0 ) { $res[] = " main_corp_id = 0 "; } else { $res[] = " main_corp_id IN(0,{$main_corp_id}) "; } if (count($res) > 0) { $res = " and " . implode(" and ", $res); } else { $res = ''; } return $res; } //获取数据库原始数据 function getDbData($sql_where, $product_type,$current,$pagesize) { global $pdo; if (!empty($product_type) && $product_type != -1)//如果选了采购类型 { $sale_sql = "SELECT supplier_id, product_type, parent_type FROM base_supplier_sale WHERE product_type = " . $product_type . " or parent_type = " . $product_type . " and cancel_flag = 0 GROUP BY supplier_id"; writeLog("select base_supplier_sale:" . $sale_sql); $result = $pdo->query($sale_sql); $supplier_id_array = $result->fetchAll(PDO::FETCH_ASSOC);//获取有该采购类型的所有supplier_id //如果没有该采购类型的supplier,返回空数组 if (count($supplier_id_array) == 0) { $json['code'] = '0'; $json['info'] = '没有符合条件的数据'; $json['list'] = array(); $json['count'] = '0'; $json['total_page'] = '0'; echo json_encode($json); exit(); } //如果有该采购类型的supplier foreach ($supplier_id_array as $k => $v) { $supplier_id_array[$k] = $v['supplier_id']; } $sql_where .= " and id in(" . implode(",", $supplier_id_array) . ")" . $sql_where . " "; } $supplier_sql = "SELECT id, supplier_name, area_id, is_disabled, supplier_type, manage_type FROM base_supplier WHERE cancel_flag = 0 " . $sql_where . " AND supplier_type = 301 LIMIT " . ($current-1)*$pagesize . "," . $pagesize; writeLog("select base_supplier:" . $supplier_sql); $result = $pdo->query($supplier_sql); $supplier_array1 = $result->fetchAll(PDO::FETCH_ASSOC);//获取所有数据 if(count($supplier_array1) > 0) { foreach($supplier_array1 as $k => $v) { $id_array[$v['id']] = $v['id']; $supplier_array[$v['id']] = $v; // $v['product_type'] = explode(",",$v['product_type']); // $v['parent_type'] = explode(",",$v['parent_type']); // foreach ($v['product_type'] as $key => $value) // { // if(empty($value)) // { // $v['product_type'][$key] = $v['parent_type'][$key]; // } // } // $v['product_type'] = array_unique($v['product_type']); // $v['product_type'] = implode(",",$v['product_type']); // unset($v['parent_type']); // $supplier_array[$k] = $v; } $sql = "select group_concat(product_type) as product_type,group_concat(parent_type) as parent_type,supplier_id from base_supplier_sale where supplier_id in (" . implode(",",$id_array) . ") and cancel_flag = 0 group by supplier_id"; $result = $pdo->query($sql); $sale_array1 = $result->fetchAll(PDO::FETCH_ASSOC); foreach($sale_array1 as $k => $v) { $v['product_type'] = explode(",",$v['product_type']); $v['parent_type'] = explode(",",$v['parent_type']); foreach ($v['product_type'] as $key => $value) { if(empty($value)) { $v['product_type'][$key] = $v['parent_type'][$key]; } } $v['product_type'] = array_unique($v['product_type']); $v['product_type'] = implode(",",$v['product_type']); $sale_array[$v['supplier_id']] = $v; } foreach($supplier_array as $k => $v) { if(isset($sale_array[$k])) { $supplier_array[$k]['product_type'] = $sale_array[$k]['product_type']; } else { $supplier_array[$k]['product_type'] = ''; } } $count_sql = "SELECT id FROM base_supplier WHERE cancel_flag = 0 " . $sql_where . " AND supplier_type = 301"; $result = $pdo->query($count_sql); $total_page = $result->fetchAll(PDO::FETCH_ASSOC);//获取所有数据 $res['supplier_array'] = $supplier_array; $res['total_page'] = ceil(count($total_page)/$pagesize); } else { $json['code'] = '0'; $json['info'] = '没有符合条件的数据'; $json['list'] = array(); $json['count'] = '0'; $json['total_page'] = '0'; echo json_encode($json); exit(); } return $res; } //处理数据 function tidyData($db_data) { global $pdo; $supplier_array = array(); $area_id_array = array(); $type = array( 0 => '正常', 1 => '关闭', 25 => '酒店', 255 => '直通巴士', 256 => '穿梭巴士', 259 => '车队', 284 => '城际商务车', 310 => '巴士', 311 => '门票' ); foreach($db_data as $key => $vel) { $vel['product_type'] = explode(",",$vel['product_type']); //获取采购范围的中文 foreach($vel['product_type'] as $k => $v) { $vel['product_type'][$k] = $type[$v]; } $vel['product_type'] = implode(",",$vel['product_type']); if($vel['manage_type'] == '1') { $vel['manage_type'] = '公司'; } else { $vel['manage_type'] = '个人'; } $supplier_array[$vel['id']] = $vel; //获取所有的area_id if(!isset($area_id_array[$vel['area_id']])) { $area_id_array[$vel['area_id']] = $vel['area_id']; } } //查询area_id的中文 $area_sql = "SELECT id, area_name FROM base_area WHERE id in(" . implode(",",$area_id_array) . ")"; writeLog("select base_area:" . $area_sql); $result = $pdo->query($area_sql); $area_id_array = $result->fetchAll(PDO::FETCH_ASSOC);//获取area中文 foreach($area_id_array as $key => $vel) { $area_array[$vel['id']] = $vel['area_name']; } foreach($supplier_array as $key => $vel) { $supplier_array[$key]['is_disabled'] = $type[$vel['is_disabled']]; $supplier_array[$key]['area_name'] = $area_array[$vel['area_id']]; unset($supplier_array[$key]['area_id']); } $supplier_array = array_values($supplier_array); $json['code'] = '0'; $json['info'] = '返回渠道商列表成功'; $json['list'] = $supplier_array; $json['count'] = (string)count($supplier_array); return $json; } } $supplier_name = trim($_POST['supplier_name']);//渠道商名称 $product_type = trim($_POST['product_type']);//销售范围 $is_disabled = trim($_POST['is_disabled']);//状态 $pagesize = trim($_POST['pagesize']);//每页的数据量 $current = trim($_POST['current']);//当前页数 $get_channel_list = new get_channel_list(); $get_channel_list->execGetChannelList($supplier_name, $product_type, $is_disabled,$current,$pagesize); ?>