You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
115 lines
5.9 KiB
115 lines
5.9 KiB
<?php
|
|
|
|
namespace App\Admin\Repositories;
|
|
|
|
use App\Models\v3\Store as Model;
|
|
use Dcat\Admin\Grid\Model as GridModel;
|
|
use Dcat\Admin\Repositories\EloquentRepository;
|
|
use App\Models\StoreAccount as StoreAccountModel;
|
|
use App\Models\FinancialRecord0 as FinancialRecordModel0;
|
|
use App\Models\FinancialRecord1 as FinancialRecordModel1;
|
|
use App\Models\FinancialRecord2 as FinancialRecordModel2;
|
|
use App\Models\FinancialRecord3 as FinancialRecordModel3;
|
|
use App\Models\FinancialRecord4 as FinancialRecordModel4;
|
|
use Dcat\Admin\Layout\Row;
|
|
use Illuminate\Support\Facades\DB;
|
|
use App\Admin\Common\Type;
|
|
|
|
class StoreUserReport extends EloquentRepository
|
|
{
|
|
/**
|
|
* Model.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $eloquentClass = Model::class;
|
|
|
|
/**
|
|
* 获取统计列表数据
|
|
* 旧表流水数据未洗到新表,所以统计需要查询旧表和新表数据
|
|
*/
|
|
public function get(GridModel $model)
|
|
{
|
|
$this->setSort($model);
|
|
$this->setPaginate($model);
|
|
|
|
/* 根据流水查询 2020-08-18 用全匹配文字方式查询新用户 旧表 */
|
|
// $storeAccountModel = new StoreAccountModel();
|
|
// $query = StoreAccountModel::join(Model::$tableName.' as store',StoreAccountModel::$tableName.'.store_id','store.id')
|
|
// ->select('store_id','store.market_id','store.name as store_name',DB::raw("count(distinct ".StoreAccountModel::$tableName.".id) as new_user_total"))
|
|
// ->whereRaw("note = '新用户下单成功,平台奖励'")
|
|
// ->groupBy('store_id')
|
|
// ->orderBy('store.market_id','desc')
|
|
// ->orderBY('new_user_total','desc')
|
|
// ->orderBY('store_id','desc');
|
|
// $l = $query->get()->toArray();
|
|
// dd($l);
|
|
/* 根据流水查询 2020-10-29 用类型字段查询新用户 新表 */
|
|
$financial0 = Model::select(Model::$tableName.'.id as store_id',Model::$tableName.'.name as store_name','market_id',DB::raw('count(distinct f0.id) as new_user_total'))
|
|
->join(FinancialRecordModel0::$tableName.' as f0',Model::$tableName.'.user_id','=','f0.user_id','left')
|
|
->whereRaw(Model::$tableName.'.user_id MOD 5 = 0')
|
|
->where('user_type',Type::USER_TYPE_STORE)
|
|
// ->where('source_type',Type::SOURCE_TYPE_ORDER)
|
|
// ->where('money_type',Type::MONEY_TYPE_STORE_PLAT_NEW_USER)
|
|
->where('f0.created_at','>','1600444800')
|
|
->groupBy('store_id','store_name','market_id');
|
|
|
|
$financial1 = Model::select(Model::$tableName.'.id as store_id',Model::$tableName.'.name as store_name','market_id',DB::raw('count(distinct f1.id) as new_user_total'))
|
|
->join(FinancialRecordModel1::$tableName.' as f1',Model::$tableName.'.user_id','=','f1.user_id','left')
|
|
->whereRaw(Model::$tableName.'.user_id MOD 5 = 1')
|
|
->where('user_type',Type::USER_TYPE_STORE)
|
|
// ->where('source_type',Type::SOURCE_TYPE_ORDER)
|
|
// ->where('money_type',Type::MONEY_TYPE_STORE_PLAT_NEW_USER)
|
|
->where('f1.created_at','>','1600444800')
|
|
->groupBy('store_id','store_name','market_id');
|
|
|
|
$financial2 = Model::select(Model::$tableName.'.id as store_id',Model::$tableName.'.name as store_name','market_id',DB::raw('count(distinct f2.id) as new_user_total'))
|
|
->join(FinancialRecordModel2::$tableName.' as f2',Model::$tableName.'.user_id','=','f2.user_id','left')
|
|
->whereRaw(Model::$tableName.'.user_id MOD 5 = 2')
|
|
->where('user_type',Type::USER_TYPE_STORE)
|
|
// ->where('source_type',Type::SOURCE_TYPE_ORDER)
|
|
// ->where('money_type',Type::MONEY_TYPE_STORE_PLAT_NEW_USER)
|
|
->where('f2.created_at','>','1600444800')
|
|
->groupBy('store_id','store_name','market_id');
|
|
|
|
$financial3 = Model::select(Model::$tableName.'.id as store_id',Model::$tableName.'.name as store_name','market_id',DB::raw('count(distinct f3.id) as new_user_total'))
|
|
->join(FinancialRecordModel3::$tableName.' as f3',Model::$tableName.'.user_id','=','f3.user_id','left')
|
|
->whereRaw(Model::$tableName.'.user_id MOD 5 = 3')
|
|
->where('user_type',Type::USER_TYPE_STORE)
|
|
// ->where('source_type',Type::SOURCE_TYPE_ORDER)
|
|
// ->where('money_type',Type::MONEY_TYPE_STORE_PLAT_NEW_USER)
|
|
->where('f3.created_at','>','1600444800')
|
|
->groupBy('store_id','store_name','market_id');
|
|
|
|
$financial4 = Model::select(Model::$tableName.'.id as store_id',Model::$tableName.'.name as store_name','market_id',DB::raw('count(distinct f4.id) as new_user_total'))
|
|
->join(FinancialRecordModel4::$tableName.' as f4',Model::$tableName.'.user_id','=','f4.user_id','left')
|
|
->whereRaw(Model::$tableName.'.user_id MOD 5 = 4')
|
|
->where('user_type',Type::USER_TYPE_STORE)
|
|
// ->where('source_type',Type::SOURCE_TYPE_ORDER)
|
|
// ->where('money_type',Type::MONEY_TYPE_STORE_PLAT_NEW_USER)
|
|
->where('f4.created_at','>','1600444800')
|
|
->groupBy('store_id','store_name','market_id')
|
|
->union($financial0)
|
|
->union($financial1)
|
|
->union($financial2)
|
|
->union($financial3);
|
|
|
|
$query = $financial4->get()->toArray();
|
|
|
|
dd($query);
|
|
|
|
$model->getQueries()->unique()->each(function ($value) use (&$query) {
|
|
if ($value['method'] == 'paginate') {
|
|
$value['arguments'][1] = $this->getGridColumns();
|
|
} elseif ($value['method'] == 'get') {
|
|
$value['arguments'] = [$this->getGridColumns()];
|
|
}
|
|
$query = call_user_func_array([$query, $value['method']], $value['arguments'] ?? []);
|
|
});
|
|
|
|
$query = $query->toArray();
|
|
|
|
$query = $model->makePaginator($query['total'],$query['data']);
|
|
return $query;
|
|
}
|
|
}
|