Talent
ECharts-PHP 是百度图表插件的PHP库,支持 ECharts 版本 2.2.x to 3.x。

安装

composer require "hisune/echarts-php:~1.0.6"

作者博客:https://hisune.com
Github:https://github.com/hisune/Echarts-PHP

基本用法

use Hisune\EchartsPHP\ECharts;
$chart = new ECharts();
$chart->tooltip->show = true;
$chart->legend->data[] = '销量';
$chart->xAxis[] = array(
    'type' => 'category',
    'data' => array("衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子")
);
$chart->yAxis[] = array(
    'type' => 'value'
);
$chart->series[] = array(
    'name' => '销量',
    'type' => 'bar',
    'data' => array(5, 20, 40, 10, 10, 20)
);
echo $chart->render('simple-custom-id');

Talent

下载插件:

请自行到群文件下载 Excel 导入导出插件。

安装插件:

将插件目录移动到 /plugins 目录下,并访问后台 系统 > 扩展中心 > 插件管理 > 安装 Excel 插件。

导出 Excel 代码示例

    public function export()
    {
        // 查询数据
        $data = LevelModel::all();
        // 设置表头信息(对应字段名,宽度,显示表头名称)
        $cellName = [
            ['id', 'auto', 'ID'],
            ['name', 'auto', '级别名称'],
            ['score', 'auto', '积分要求'],
            ['discount', 'auto', '享受折扣'],
            ['create_time', 'auto', '创建时间'],
            ['update_time', 'auto', '更新时间']
        ];
        // 调用插件(传入插件名,[导出文件名、表头信息、具体数据])
        plugin_action('Excel/Excel/export', ['test', $cellName, $data]);
    }

导入 Excel 代码示例

    public function import()
    {
        // 提交数据
        if ($this->request->isPost()) {
            // 接收附件 ID
            $excel_file = $this->request->post('excel');
            // 获取附件 ID 完整路径
            $full_path = getcwd() . get_file_path($excel_file);
            // 只导入的字段列表
            $fields = [
                'name' => '姓名',
                'last_login_time' => '最后登录时间',
                'last_login_ip' => '最后登陆IP'
            ];
            // 调用插件('插件',[路径,导入表名,字段限制,类型,条件,重复数据检测字段])
            $import = plugin_action('Excel/Excel/import', [$full_path, 'vip_test', $fields, $type = 0, $where = null, $main_field = 'name']);
            
            // 失败或无数据导入
            if ($import['error']){
                $this->error($import['message']);
            }

            // 导入成功
            $this->success($import['message']);
        }

        // 创建演示用表单
        return ZBuilder::make('form')
            ->setPageTitle('导入Excel')
            ->addFormItems([ // 添加上传 Excel
                ['file', 'excel', '上传文件'],
            ])
            ->fetch();
    }
更多使用方法请自行阅读 Excel 插件源码
Talent
最近在 ThinkPHP 官方看到了一个不错的轮子:DolphinPHP,正好手头有个小项目就用这个轮子来建吧;期间遇到的问题就是代码更新问题,官方还在用比较老的补丁压缩包形式来更新版本;作为现代PHP工(da)程(cai)师(niao)这是无法容忍的。官方没有发发布到 composer ,但是有 github 仓库;那咱们就用 git 来更新吧,下面是一个基本的克隆开源项目二次开发的流程和拉取更新代码冲突的解决方案。

克隆项目到本地

git clone https://github.com/caiweiming/DolphinPHP.git [你的目录]

给本地项目添加自己的远程仓库

git remote add coding https://git.coding.net/tlerbao/MyDP.git