PHP code example of shanjing / laravel-statistics

1. Go to this page and download the library: Download shanjing/laravel-statistics library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

shanjing / laravel-statistics example snippets


// 今天淘宝销量、销售额
// period   year | month | week | day
// orderBy  desc | asc
app('statistics')
->get("taobao", ['gmv', 'order_num'])
->period('day')
->orderBy("desc")
->exec();

// 20210901~20210921 淘宝销量、销售额
app('statistics')
->get("taobao", ['gmv', 'order_num'])
->occurredBetween([20210901, 20210921])
->period('day')
->orderBy("desc") 
->exec();

// 更新数据
// $arr: 会已 json 的格式存储在 data 列
// taobao: 存储在 key 列
// occurredAt: 存储在 occurred_at 列
$arr = ['gmv'=>'value', 'order_num'=>'value'];
app('statistics')
->save("taobao", $arr)
->occurredAt(20210921)
->exec();


  
namespace App\Models\Order;
  
use Illuminate\Database\Eloquent\Model;
use Shanjing\LaravelStatistics\Traits\Statistics;
  
class Order extends Model
{ 
    use Statistics;
  
    protected $table = '';
  
    protected $connection = '';
}

// period   year | month | week | day
// occurredBetween 时间范围
// orderBy  desc | asc
Order::period("day")
   ->occurredBetween(["20210718", "20210921"])
   ->selectRaw('count(id) as total') // 支持 select 语句
   ->selectRaw('SUM(`price`) as gmv') // 支持 select 语句
   ->orderBy('desc')
   ->summary();
bash
php artisan laravel-statistics:publish
bash
php artisan laravel-statistics:install