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; } }