<?php
class webBase
{
public static $table_sp_channel = 'sp_channel';
public static $table_sp_server = 'sp_server';
function __construct() {
Mysql::getInstance();
}
public function select()
{
$sql = "";
$cond = "";
if (isset($_GET['area']) && !empty($_GET['area']))
$cond = " and d.province_and_limit like '%".$_GET['area']."%'";
$sql = "select a.id as keyid, a.sp_id, c.`name` as cooper, b.`name` as operator,a.`name` as spname,a.number,a.`code`,a.price, a.wastage,a.is_double_precise ,d.* from sp_service a
left join sp_type b on a.sp_type_id = b.id
left join sp c on a.sp_id = c.id
LEFT JOIN sp_channel d on a.id = d.id
where d.status = 1 $cond
ORDER BY sp_id";
$result = mysql_query($sql);
$res = array();
$rowspan = array();
$sp_id = '';
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
if ($sp_id != $line['sp_id']){
$sp_id = $line['sp_id'];
$rowspan[$sp_id] = 1;
}
else{
$rowspan[$sp_id] = $rowspan[$sp_id]+1;
}
$pro_limit = explode('|',$line['province_and_limit']);
$line['pro_limit'] = $pro_limit;
$res[] = $line;
}
return array('data'=>$res, 'rowspan' => $rowspan);
}
public function select_detail()
{
$sql = "";
$cond = "";
if (isset($_GET['area']) && !empty($_GET['area']))
$cond = " WHERE d.province_and_limit like '%".$_GET['area']."%'";
$sql = "select a.id as keyid, a.sp_id, c.`name` as cooper, b.`name` as operator,a.`name` as spname,a.number,a.`code`,a.price, a.wastage,a.is_double_precise ,d.* from sp_service a
left join sp_type b on a.sp_type_id = b.id
left join sp c on a.sp_id = c.id
LEFT JOIN sp_channel d on a.id = d.id
$cond
ORDER BY sp_id";
$result = mysql_query($sql);
$res = array();
$rowspan = array();
$sp_id = '';
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
if ($sp_id != $line['sp_id']){
$sp_id = $line['sp_id'];
$rowspan[$sp_id] = 1;
}
else{
$rowspan[$sp_id] = $rowspan[$sp_id]+1;
}
$pro_limit = explode('|',$line['province_and_limit']);
$line['pro_limit'] = $pro_limit;
$res[] = $line;
}
return array('data'=>$res, 'rowspan' => $rowspan);
}
/*
* 更新sp_channel 插入或编码操作
*/
public function update()
{
$sql = "replace into ".self::$table_sp_channel." values(
'".$_GET['id']."',
'".$_POST['newprice']."',
'".$_POST['totallimit']."',
'".$_POST['province_and_limit']."',
'".$_POST['remark']."',
'".$_POST['status']."',
'".$_POST['rule']."'
)";
$result = mysql_query($sql);
if (mysql_affected_rows() > 0)
echo "{'satus':1,'msg':'修改成功!'}";
else
echo "{'satus':0,'msg':'修改失败!'}";
exit;
}
/*
* 获取省份过滤条件
*/
public function findAreaAll()
{
$sql = "select distinct(province_and_limit) from ".self::$table_sp_channel." where province_and_limit != ''";
$result = mysql_query($sql);
$res = array();
while ($line = mysql_fetch_row($result)) {
$tmp_arr = explode('|',$line[0]);
for ($i = 0; $i<count($tmp_arr); $i++)
{
$p_a_l = explode('/', $tmp_arr[$i]);
if (!in_array(trim($p_a_l[0]),$res))
array_push($res, trim($p_a_l[0]));
}
}
return $res;
}
function getArea()
{
$province = array('上海','北京','广东','江苏','安徽','重庆','福建','甘肃',
'贵州','湖北','黑龙江','湖南','吉林','江西','辽宁','内蒙古','山东',
'天津','青海','四川','宁夏','新疆','云南','浙江','河北','海南','山西','河南','陕西','西藏');
return $province;
}
/*
* 获取联网或短信数据
*/
function getChannelCategory($type)
{
$sql = "select id, channel_name, totallimit,province_and_limit,remark from ".self::$table_sp_server." where operator like '%$type%' order by id";
$sql = "select a.id,a.name, b.totallimit, b.province_and_limit,b.remark from sp_service a
left join sp_channel b on a.id = b.id
left join sp_type c on a.sp_type_id = c.id
where b.status = 1 and c.name like '%$type%' order by a.id";
$result = mysql_query($sql);
$res = array();
$id_arr = array();
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
$res[] = $line;
$id_arr[] = $line['id'];
}
$res['id_arr'] = $id_arr;
return $res;
}
/*
* 返回通道id对应选中的地区
* @return array
*/
function getAreaBySp($id_arr)
{
$str_id = implode(',',$id_arr);
$sql = "SELECT b.sp_service_id,a.`name` from area a
JOIN (SELECT b.sp_service_id,b.isp_id, a.area_id,a.`name` FROM isp a
JOIN (SELECT b.sp_service_id,b.isp_id from sp_service a JOIN sp_service_has_isp b on a.id = b.sp_service_id where a.id in ($str_id)) b
on a.id = b.isp_id) b
on a.id = b.area_id";
$result = mysql_query($sql);
$res = array();
$key = '';
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
if ($line['sp_service_id'] != $key)
$key = $line['sp_service_id'];
$res[$key][] = $line['name'];
}
return $res;
}
/*
* 获取前台配置的地区信息
*/
function getAreaFront($id_arr)
{
$str_id = implode(',',$id_arr);
$sql = "select id, province_and_limit from sp_channel where id in ($str_id)";
$result = mysql_query($sql);
$res = array();
while ($line = mysql_fetch_row($result)) {
$tmp_arr = explode('|',$line[1]);
for ($i = 0; $i<count($tmp_arr); $i++)
{
$p_a_l = explode('/', $tmp_arr[$i]);
if (!in_array(trim($p_a_l[0]),$res))
$res[$line[0]][] = trim($p_a_l[0]);
}
}
return $res;
}
/*
* 获取单个通道ID信息
*/
public function selectByCode($id)
{
$sql = "select * from ".self::$table_sp_channel." where id = '$id'";
$result = mysql_query($sql);
return mysql_fetch_array($result);
}
/******************************************************/
/*
* 导出[hs_venus_system]sp_server 中通道数据信息插入到李M界面数据表channel
*/
// function export()
// {
// $sql = " SELECT id,sp_id,name,code,price from sp_service where status = 'normal'";
// $result = mysql_query($sql);
//
// $sql_value = "insert into ".self::$tablename." values";
// while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
// $sql_value .= "('".$line['id']."',
// '".$line['sp_id']."',
// '',
// '".$line['name']."',
// '".$line['code']."',
// '".$line['price']."',
// '',
// 0,
// '',
// '8080',
// 500,
// '湖北/300|湖南/200',
// ''
// ),";
// }
// $sql = substr($sql_value, 0, -1);
// $result = mysql_query($sql);
// if (mysql_affected_rows() > 0)
// echo "{'satus':1,'msg':'插入记录成功!'}";
// else
// echo "{'satus':0,'msg':'插入失败!'}";
// exit;
// }
//
// public function select_id()
// {
// $sql = "select id from ".self::$tablename." where id = '".$_POST['id']."'";
// $result = mysql_query($sql);
// return mysql_num_rows($result);
// }
//
// public function select_spid()
// {
// $sql = "select sp_id,count(sp_id) as num from sp_service group by sp_id";
// $result = mysql_query($sql);
// $res = array();
// while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
// $res[$line['sp_id']] = $line['num'];
// }
// return $res;
// }
//
// public function insert()
// {
// $num = $this->select_id();
//
// if ($num>0)
// echo "{'satus':0,'msg':'添加失败,代码名称已存在!'}";
// else
// {
// $sql = "insert into ".self::$tabla_sp_channel." values(
// '".$_POST['id']."',
// '".$_POST['sp_id']."',
// '"
- 1
- 2
前往页