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.
82 lines
3.6 KiB
82 lines
3.6 KiB
<?php
|
|
|
|
namespace App\Admin\Repositories;
|
|
|
|
use App\Models\storeUserReport as Model;
|
|
use Dcat\Admin\Grid\Model as GridModel;
|
|
use Dcat\Admin\Repositories\EloquentRepository;
|
|
use App\Models\ImsCjdcOrder as orderModel;
|
|
use App\Models\StoreAccount as storeAccountModel;
|
|
use App\Models\ImsCjdcStore as storeModel;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class StoreUserReport extends EloquentRepository
|
|
{
|
|
/**
|
|
* Model.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $eloquentClass = Model::class;
|
|
|
|
/**
|
|
* 获取统计列表数据
|
|
*/
|
|
public function get(GridModel $model)
|
|
{
|
|
|
|
$startTime = '2020-06-01';$endTime = '2020-08-01';
|
|
$this->setSort($model);
|
|
$this->setPaginate($model);
|
|
|
|
//根据订单查询 方法查询出来的数据不对
|
|
// $orderModel = new orderModel();
|
|
// $query = $orderModel::join('ims_cjdc_store as store','order.store_id','store.id')
|
|
// ->join('ims_cjdc_user as user','order.user_id','user.id')
|
|
// ->select('store_id','store.market_id','store.name as store_name','mm_user_id',DB::raw("count(distinct order.user_id) as new_user_total"))
|
|
// ->whereRaw("UNIX_TIMESTAMP(pay_time) BETWEEN UNIX_TIMESTAMP(?) AND UNIX_TIMESTAMP(?)",[$startTime,$endTime])
|
|
// ->whereRaw("join_time BETWEEN UNIX_TIMESTAMP(?) AND UNIX_TIMESTAMP(?)",[$startTime,$endTime])
|
|
// ->groupBy('store_id')
|
|
// ->orderBy('market_id','desc')
|
|
// ->orderBY('new_user_total','desc');
|
|
|
|
/* 根据流水查询 2020-08-18 目前用全匹配文字方式查询新用户,后期维护店铺流水表的类型(category)后再换,或者使用其他方法 */
|
|
$storeAccountModel = new storeAccountModel();
|
|
$query = $storeAccountModel::join('ims_cjdc_store as store','ims_cjdc_store_account.store_id','store.id')
|
|
// with(['store' => function($query){
|
|
// $query->select('id','market_id','name as store_name','mm_user_id');
|
|
// }])
|
|
->select('store_id','store.market_id','store.name as store_name','mm_user_id',DB::raw("count(distinct ims_cjdc_store_account.id) as new_user_total"))
|
|
->whereRaw("note = '新用户下单成功,平台奖励'")
|
|
// ->whereRaw("UNIX_TIMESTAMP(account.time) BETWEEN UNIX_TIMESTAMP(?) AND UNIX_TIMESTAMP(?)",[$startTime,$endTime])
|
|
->groupBy('store_id')
|
|
->orderBy('store.market_id','desc')
|
|
->orderBY('new_user_total','desc');
|
|
|
|
// $storeModel = new storeModel();
|
|
// $query = $storeModel
|
|
// ->with(['storeAccount'=>function($query){
|
|
// $query->where('note',"新用户下单成功,平台奖励")
|
|
// ->select(DB::raw("count(distinct id) as new_user_total"));
|
|
// }])
|
|
// ->select('id as store_id','market_id','name as store_name','mm_user_id')
|
|
// ->groupBy('id')
|
|
// ->orderBy('market_id','desc')
|
|
// ->orderBY('new_user_total','desc')
|
|
// ;
|
|
|
|
$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;
|
|
}
|
|
}
|