大概需求:

基于强大的pchart类库。

闭包也叫匿名函数 PHP5.3 引入。

每一个订单都有多个文件附件,在下载的时候希望对当前订单的文件自动打包成一个压缩包下载

 * @created: 02/05/2015 */include "libs/pData.class.php";include "libs/pDraw.class.php";include "libs/pImage.class.php";include "database.php";include "libs/convert.php";date_default_timezone_set;/* * @param type line/other 趋势图/柱形图 默认趋势图 * @param txt 1/other 显示/不显示 提示文字 默认不显示 * @param lang hk/cn 繁体中文/简体中文 默认繁体 * @param id int 股票编号 必填 * @param min int 最小时间 默认无 * @param max int 最大时间 默认无 */$type = isset ? $_GET['type'] : 'line';$showtxt =  &&  ? true : false;//设置语言if  { $lang = $_GET['lang'] == 'cn' ? 'cn' : 'hk';} else { $lang = 'hk';} $desc_tip = array( 'hk' => array( 'line' => array, 'bar' => "总成交量:" ), 'cn' => array( 'line' => array, 'bar' => "总成交量:" ));$id = isset ? $_GET['id'] : 1; //股票编码//条件$wheres = "where stock_no = ".$id;//最小时间if  { $wheres .= " and `created` >= ".$_GET['min'];}//最大时间if  { $wheres .= " and `created` <= ".$_GET['max'];}$wheres .= " order by created";$sth = $dbh->prepare("SELECT * FROM $tb_name " . $wheres);$sth->execute();$results = $sth->fetchAll;if  { $ttf_path = "fonts/zh_hk.ttc";} else { $ttf_path = "fonts/zh_cn.ttf";}//初始化$line2 = array; //成交量$times = array(); //时间foreach ($results as $keys => $values) : $line2[] = $values['current_price']; $bar[] = $values['volume']; //只显示整点的标签 if  { $times[] = $values['created']; } else { $times[] = VOID; }endforeach;$l2counts = count;$myData = new pData();//如果是线型图if  { //取股票名称 $stock_sth = $dbh->prepare("SELECT `name` FROM `tbl_stock` WHERE `code` = {$id}"); $stock_sth->execute(); $stock_info = $stock_sth->fetch; $func_name = "zhconversion_".$lang; //$stock_name = $func_name; $stock_name = "某某公司";//取出最值 $sql = "SELECT MIN xiao, MAX da FROM $tb_name $wheres"; foreach ($dbh->query($sql, PDO::FETCH_ASSOC) as $row) { $bottom = $row['xiao'] - 2; $top = $row['da'] + 2; } //昨日收盘价 $l1s = array(); for ($i = 1; $i <= $l2counts; $i++) { $l1s[] = 130; } $myData->addPoints; $myData->addPoints; $myData->setPalette("Line1",array("R"=>51,"G"=>114,"B"=>178)); $myData->setPalette("Line2",array("R"=>0,"G"=>255,"B"=>0)); $myData->setAxisPosition(0, AXIS_POSITION_RIGHT); $myData->addPoints; $myData->setSerieDescription; $myData->setAbscissa; $myData->setXAxisDisplay(AXIS_FORMAT_TIME,"H:i"); $myPicture = new pImage; //设置默认字体 $myPicture->setFontProperties(array("FontName" => "fonts/en_us.ttf", "FontSize" => 6)); //背景颜色 //$Settings = array("StartR"=>219, "StartG"=>231, "StartB"=>139, "EndR"=>1, "EndG"=>138, "EndB"=>68, "Alpha"=>50); //$myPicture->drawGradientArea(0,0,480,300,DIRECTION_VERTICAL,$Settings);//画格子和标签 $myPicture->setGraphArea; $AxisBoundaries = array(0 => array("Min" => $bottom, "Max" => $top)); $Settings = array( "Mode" => SCALE_MODE_MANUAL, "GridR" => 200, "GridG" => 200, "GridB" => 200, "XMargin" => 0, "YMargin" => 0, //"DrawXLines" => false, "GridTicks" => 3, //格子密度 "ManualScale" => $AxisBoundaries, ); $myPicture->drawScale;//画线 /* $line_arr = array( "ForceColor" => TRUE, "ForceR" => 0, "ForceG" => 0, "ForceB" => 255); $myPicture->drawLineChart; */ $myPicture->drawLineChart(); //设置Line1为无效,再画底色 $myData->setSerieDrawable;//画区域底线 $area_arr = array( "ForceTransparency"=>15, //透明度 ); $myPicture->drawAreaChart; //是否显示文字 if  { //标题 $myPicture->drawText(200,30,$stock_name,array("FontName"=>$ttf_path, "FontSize"=>11,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE)); //设置Line1为有效 $myData->setSerieDrawable; $myData->setSerieDescription("Line1",$desc_tip[$lang]['line'][0]); $myData->setSerieDescription("Line2",$desc_tip[$lang]['line'][1]); $myPicture->setFontProperties(array("FontName" => $ttf_path,"FontSize"=>8)); $tips = array( "Style"=>LEGEND_NOBORDER, "Mode"=>LEGEND_HORIZONTAL, "FontR"=>0,"FontG"=>0,"FontB"=>0, ); $myPicture->drawLegend; }//柱形图} else { $myData->addPoints; $myData->setPalette("Bar",array("R"=>51,"G"=>114,"B"=>178)); //设置柱子的颜色 $myData->addPoints; $myData->setSerieDescription; $myData->setAbscissa; $myData->setXAxisDisplay(AXIS_FORMAT_TIME,"H:i"); $myPicture = new pImage; //设置默认字体 $myPicture->setFontProperties(array("FontName" => "fonts/en_us.ttf", "FontSize"=>6)); $myPicture->Antialias = FALSE; $myPicture->setGraphArea; //网格及坐标 $scaleSettings = array( "Mode" => SCALE_MODE_START0, "GridR"=>200, "GridG"=>200, "GridB"=>200); $myPicture->drawScale; /* $Palette = array(); for ($i = 0; $i <= $l2counts; $i++) { $Palette[$i] = array("R"=>74,"G"=>114,"B"=>178,"Alpha"=>100); } //$Palette = array("0"=>array("R"=>74,"G"=>114,"B"=>178,"Alpha"=>100)); /* 覆盖画板色 $barSetting = array( "OverrideColors"=>$Palette, ); $myPicture->drawBarChart; */ $myPicture->drawBarChart(); //是否显示文字 if  { $tips = array( "Style"=>LEGEND_NOBORDER, "Mode"=>LEGEND_HORIZONTAL, "FontR"=>0,"FontG"=>0,"FontB"=>0, ); $myPicture->setFontProperties(array("FontName" => $ttf_path,"FontSize"=>9)); $alls = 0; //总成交量初始化 foreach  { $alls += $value; } $myData->setSerieDescription("Bar", $desc_tip[$lang]['bar'].$alls); $myPicture->drawLegend; }}$myPicture->stroke();//$myPicture->autoOutput;//保存日志//file_put_contents("log.txt", json_encode;?>

使用方法

细节需求:当前订单号_年月日+时间.zip 例如:

需要调整数组元素中的值复制代码
代码如下:$data = range;//想要每个元素的值都加上.html的后缀$suffix =
‘.html’;

1.生成压缩文件,压缩文件名格式:

function makeSuffix{ return $str . $suffix;}

2.压缩文件存放在根目录 /upload/zipfile/年月/自定义的压缩文件名.zip

$new_data = array_map use { return makeSuffix;}, $data);

3.点击下载压缩包,系统开始对压缩文件打包,打包完成后自动开始下载

需要改变元素的结构复制代码
代码如下:$arr = [ [ ‘id’=>”, ‘name’=>”, ‘create_time’=>”,
],];

发表评论

电子邮件地址不会被公开。 必填项已用*标注