From 7fc802ed32a149371dbeec8ed8dee64f7cd1dc75 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Thu, 29 Oct 2020 18:06:49 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=BA=97=E9=93=BA=E6=96=B0=E7=94=A8?= =?UTF-8?q?=E6=88=B7--=E4=BF=AE=E6=94=B9=E6=9F=A5=E8=AF=A2=E8=AF=AD?= =?UTF-8?q?=E5=8F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Common/Type.php | 15 ++++ app/Admin/Repositories/StoreUserReport.php | 81 +++++++++++++++++++--- app/Models/FinancialRecord0.php | 2 + app/Models/FinancialRecord1.php | 2 + app/Models/FinancialRecord2.php | 2 + app/Models/FinancialRecord3.php | 2 + app/Models/FinancialRecord4.php | 2 + app/Models/StoreAccount.php | 3 + app/Models/v3/Store.php | 34 +++++++++ 9 files changed, 134 insertions(+), 9 deletions(-) diff --git a/app/Admin/Common/Type.php b/app/Admin/Common/Type.php index 1e7b58a..a4d31e8 100644 --- a/app/Admin/Common/Type.php +++ b/app/Admin/Common/Type.php @@ -7,6 +7,7 @@ namespace App\Admin\Common; class Type { /** + * lanzu_financial_record * 流水类型,大的分类,<100是奖励分账等收入项 >=100是提现消费等支出项 */ const MONEY_TYPE_CS_PLAT_NEW_USER = 1; // 社区服务点新用户奖励(线上订单完成) @@ -29,6 +30,20 @@ class Type const MONEY_TYPE_MM = 103; //市场经理提现类型 const MONEY_TYPE_CS = 104; //社区提现类型 + // 账户类型 + const USER_TYPE_LEDGER = -1; // 虚拟账户 + const USER_TYPE_USER = 1; // user用户 + const USER_TYPE_MP = 2; // 服务商 mp用户 + const USER_TYPE_MM = 3; // 市场经理 mm用户 + const USER_TYPE_CS = 4; // 社区代理点 cs用户 + const USER_TYPE_STORE = 5; // 商户 store用户 + + // 流水关联id类型 + const SOURCE_TYPE_NONE = 0; // 无类型 + const SOURCE_TYPE_ORDER = 1; // 订单,关联主订单 + const SOURCE_TYPE_STORE_WITHDRAW = 2; // 商户提现,关联商户提现表 + + /** * lanzu_user_balance 提现类型 */ diff --git a/app/Admin/Repositories/StoreUserReport.php b/app/Admin/Repositories/StoreUserReport.php index 9131dae..0b9c6d0 100644 --- a/app/Admin/Repositories/StoreUserReport.php +++ b/app/Admin/Repositories/StoreUserReport.php @@ -6,7 +6,14 @@ 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 { @@ -19,21 +26,77 @@ class StoreUserReport extends EloquentRepository /** * 获取统计列表数据 + * 旧表流水数据未洗到新表,所以统计需要查询旧表和新表数据 */ public function get(GridModel $model) { $this->setSort($model); $this->setPaginate($model); - /* 根据流水查询 2020-08-18 目前用全匹配文字方式查询新用户 */ - $storeAccountModel = new StoreAccountModel(); - $query = $storeAccountModel::join('ims_cjdc_store as store','ims_cjdc_store_account.store_id','store.id') - ->select('store_id','store.market_id','store.name as store_name',DB::raw("count(distinct ims_cjdc_store_account.id) as new_user_total")) - ->whereRaw("note = '新用户下单成功,平台奖励'") - ->groupBy('store_id') - ->orderBy('store.market_id','desc') - ->orderBY('new_user_total','desc') - ->orderBY('store_id','desc'); + /* 根据流水查询 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') { diff --git a/app/Models/FinancialRecord0.php b/app/Models/FinancialRecord0.php index 0f2dfd3..8fa5b04 100644 --- a/app/Models/FinancialRecord0.php +++ b/app/Models/FinancialRecord0.php @@ -8,4 +8,6 @@ class FinancialRecord0 extends FinancialRecord { protected $table = 'lanzu_financial_record_0'; + public static $tableName = 'lanzu_financial_record_0'; + } diff --git a/app/Models/FinancialRecord1.php b/app/Models/FinancialRecord1.php index 4e656b3..151c948 100644 --- a/app/Models/FinancialRecord1.php +++ b/app/Models/FinancialRecord1.php @@ -7,4 +7,6 @@ use Illuminate\Database\Eloquent\Model; class FinancialRecord1 extends FinancialRecord { protected $table = 'lanzu_financial_record_1'; + public static $tableName = 'lanzu_financial_record_1'; + } diff --git a/app/Models/FinancialRecord2.php b/app/Models/FinancialRecord2.php index 85eefb7..91efabf 100644 --- a/app/Models/FinancialRecord2.php +++ b/app/Models/FinancialRecord2.php @@ -7,4 +7,6 @@ use Illuminate\Database\Eloquent\Model; class FinancialRecord2 extends FinancialRecord { protected $table = 'lanzu_financial_record_2'; + public static $tableName = 'lanzu_financial_record_2'; + } diff --git a/app/Models/FinancialRecord3.php b/app/Models/FinancialRecord3.php index ca5218c..e258c26 100644 --- a/app/Models/FinancialRecord3.php +++ b/app/Models/FinancialRecord3.php @@ -7,4 +7,6 @@ use Illuminate\Database\Eloquent\Model; class FinancialRecord3 extends FinancialRecord { protected $table = 'lanzu_financial_record_3'; + public static $tableName = 'lanzu_financial_record_3'; + } diff --git a/app/Models/FinancialRecord4.php b/app/Models/FinancialRecord4.php index 25fb416..15b2691 100644 --- a/app/Models/FinancialRecord4.php +++ b/app/Models/FinancialRecord4.php @@ -7,4 +7,6 @@ use Illuminate\Database\Eloquent\Model; class FinancialRecord4 extends FinancialRecord { protected $table = 'lanzu_financial_record_4'; + public static $tableName = 'lanzu_financial_record_4'; + } diff --git a/app/Models/StoreAccount.php b/app/Models/StoreAccount.php index 029559b..53aa525 100644 --- a/app/Models/StoreAccount.php +++ b/app/Models/StoreAccount.php @@ -14,6 +14,9 @@ class StoreAccount extends Model { use HasDateTimeFormatter; protected $table = 'ims_cjdc_store_account'; + + public static $tableName = 'ims_cjdc_store_account'; + protected $dateFormat = 'U'; public $timestamps = false; diff --git a/app/Models/v3/Store.php b/app/Models/v3/Store.php index 968408d..96ea359 100644 --- a/app/Models/v3/Store.php +++ b/app/Models/v3/Store.php @@ -11,6 +11,8 @@ class Store extends Model use HasDateTimeFormatter; use SoftDeletes; + public static $tableName = 'lanzu_store'; + protected $table = 'lanzu_store'; protected $dateFormat = 'U'; @@ -103,4 +105,36 @@ class Store extends Model return $value; } } + + // 关联旧流水 + public function storeAccount() + { + return $this->belongsTo('App\Models\v3\StoreAccount','store_id','id','light'); + } + + // 关联流水 + public function financialRecord0() + { + return $this->belongsTo('App\Models\FinancialRecord0','user_id','user_id','light'); + } + // 关联流水 + public function financialRecord1() + { + return $this->belongsTo('App\Models\FinancialRecord1','user_id','user_id','light'); + } + // 关联流水 + public function financialRecord2() + { + return $this->belongsTo('App\Models\FinancialRecord2','user_id','user_id','light'); + } + // 关联流水 + public function financialRecord3() + { + return $this->belongsTo('App\Models\FinancialRecord3','user_id','user_id','light'); + } + // 关联流水 + public function financialRecord4() + { + return $this->belongsTo('App\Models\FinancialRecord4','user_id','user_id','light'); + } } From 71ae2db337f5e1289898d293c9e47a05aeffebb1 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Fri, 30 Oct 2020 11:38:22 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=BA=97=E9=93=BA=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=80=BB=E6=95=B0=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/StoreUserReportController.php | 48 ++++----- app/Admin/Repositories/StoreUserReport.php | 100 +++++++++++------- resources/lang/zh-CN/store-user-report.php | 1 + 3 files changed, 85 insertions(+), 64 deletions(-) diff --git a/app/Admin/Controllers/StoreUserReportController.php b/app/Admin/Controllers/StoreUserReportController.php index 8358b25..d8b835e 100644 --- a/app/Admin/Controllers/StoreUserReportController.php +++ b/app/Admin/Controllers/StoreUserReportController.php @@ -7,7 +7,9 @@ use Dcat\Admin\Form; use Dcat\Admin\Grid; use Dcat\Admin\Show; use Dcat\Admin\Controllers\AdminController; -use App\Models\ImsCjdcMarket as marketModel; +use App\Models\v3\Market as MarketModel; +use App\Models\StoreAccount as StoreAccountModel; +use App\Models\v3\Store as StoreModel; class StoreUserReportController extends AdminController { @@ -24,37 +26,29 @@ class StoreUserReportController extends AdminController $grid->disableEditButton(); $grid->disableQuickEditButton(); $grid->disableViewButton(); + $grid->disableActions(); + $grid->disableRowSelector(); + + $marketList = MarketModel::getMarketArray(); + $storeList = StoreModel::getStoreArray(); $grid->store_id; - $grid->market_id->display(function ($markrtId) { - $market = marketModel::select('id', 'name')->find($markrtId); - if (!$market) { - return '数据错误'; - } - return $market->name; + $grid->market_id->display(function ($marketId) use($marketList){ + return $marketList[$marketId] ?? ''; }); - $grid->store_name; - $grid->new_user_total; + $grid->store_name->width('25%'); + $grid->new_total; + + $grid->filter(function (Grid\Filter $filter) use($marketList,$storeList){ + $filter->panel(); - $grid->filter(function (Grid\Filter $filter) { - $marketList = []; - $list = marketModel::select('id', 'name')->get()->toArray(); - foreach ($list as $value) { - $marketList[$value['id']] = $value['name']; - } - $filter->in('market_id')->multipleSelect($marketList); - $filter->like('store.name', '店铺名称'); - $filter->whereBetween('time', function ($q) { - $start = $this->input['start'] ?? null; - $end = $this->input['end'] ?? null; - if ($start !== null) { - $q->whereRaw("ims_cjdc_store_account.time >= ?", $start); - } - if ($end !== null) { - $q->whereRaw("ims_cjdc_store_account.time <= ?", $end); - } - })->datetime(); + $filter->equal('start_time','开始时间')->date()->width(2); + $filter->equal('end_time','结束时间')->date()->width(2); + $filter->equal('market_id')->select($marketList)->width(3); + $filter->in('store_id','店铺名称')->multipleSelect($storeList)->width(4); }); + // 每页10条 + $grid->paginate(10); }); } diff --git a/app/Admin/Repositories/StoreUserReport.php b/app/Admin/Repositories/StoreUserReport.php index 0b9c6d0..ce51045 100644 --- a/app/Admin/Repositories/StoreUserReport.php +++ b/app/Admin/Repositories/StoreUserReport.php @@ -32,80 +32,106 @@ class StoreUserReport extends EloquentRepository { $this->setSort($model); $this->setPaginate($model); + // 获取每页显示行数 + $perPage = $model->getPerPage(); + $startTime = $params['start_time'] ?? request()->input('start_time',''); + $endTime = $params['end_time'] ?? request()->input('end_time',''); + $marketId = $params['market_id'] ?? request()->input('market_id',0); + $storeIds = $params['store_id'] ?? request()->input('store_id',[]); /* 根据流水查询 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); + $storeAccount = StoreAccountModel::join(Model::$tableName.' as store',StoreAccountModel::$tableName.'.store_id','store.id') + ->select('store_id','store.name as store_name','store.market_id',DB::raw("count(distinct ".StoreAccountModel::$tableName.".id) as new_user_total")) + ->whereRaw("note = '新用户下单成功,平台奖励'") + ->groupBy('store_id'); + // dd($storeAccount->get()->toArray()); + /* 根据流水查询 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) + ->whereRaw('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') + ->whereRaw('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) + ->whereRaw('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') + ->whereRaw('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) + ->whereRaw('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') + ->whereRaw('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) + ->whereRaw('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') + ->whereRaw('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) + ->whereRaw('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); + ->whereRaw('f4.created_at > 1600444800') + ->groupBy('store_id','store_name','market_id'); - $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'] ?? []); - }); + if($startTime){ + $startTime = $startTime.' 00:00:00'; + $storeAccount->whereRaw(StoreAccountModel::$tableName.".time >= '".$startTime."'"); + $financial0->whereRaw('f0.created_at >='.strtotime($startTime)); + $financial1->whereRaw('f1.created_at >='.strtotime($startTime)); + $financial2->whereRaw('f2.created_at >='.strtotime($startTime)); + $financial3->whereRaw('f3.created_at >='.strtotime($startTime)); + $financial4->whereRaw('f4.created_at >='.strtotime($startTime)); + } + if($endTime){ + $endTime = $endTime.' 23:59:59'; + $storeAccount->whereRaw(StoreAccountModel::$tableName.".time <='".$endTime."'"); + $financial0->whereRaw('f0.created_at <='.strtotime($endTime)); + $financial1->whereRaw('f1.created_at <='.strtotime($endTime)); + $financial2->whereRaw('f2.created_at <='.strtotime($endTime)); + $financial3->whereRaw('f3.created_at <='.strtotime($endTime)); + $financial4->whereRaw('f4.created_at <='.strtotime($endTime)); + } + if($marketId){ + $storeAccount->whereRaw('store.market_id ='.$marketId); + $financial0->whereRaw(Model::$tableName.'.market_id ='.$marketId); + $financial1->whereRaw(Model::$tableName.'.market_id ='.$marketId); + $financial2->whereRaw(Model::$tableName.'.market_id ='.$marketId); + $financial3->whereRaw(Model::$tableName.'.market_id ='.$marketId); + $financial4->whereRaw(Model::$tableName.'.market_id ='.$marketId); + } + if($storeIds){ + $storeStr = implode(',',$storeIds);//dd($storeArr); + $storeAccount->whereRaw('store.id in('. $storeStr.')'); + $financial0->whereRaw(Model::$tableName.'.id in('. $storeStr.')'); + $financial1->whereRaw(Model::$tableName.'.id in('. $storeStr.')'); + $financial2->whereRaw(Model::$tableName.'.id in('. $storeStr.')'); + $financial3->whereRaw(Model::$tableName.'.id in('. $storeStr.')'); + $financial4->whereRaw(Model::$tableName.'.id in('. $storeStr.')'); + } + $unionAll = $storeAccount->union($financial0)->union($financial1)->union($financial2)->union($financial3)->union($financial4); + $query = DB::table(Db::raw("({$unionAll->toSql()}) as a1")) + ->select('a1.store_id','a1.store_name','a1.market_id',DB::raw('SUM(a1.new_user_total) as new_total')) + ->groupBy('market_id','store_id','store_name') + ->orderBy('new_total','desc')->paginate($perPage); $query = $query->toArray(); diff --git a/resources/lang/zh-CN/store-user-report.php b/resources/lang/zh-CN/store-user-report.php index 5bb0d36..a09f452 100644 --- a/resources/lang/zh-CN/store-user-report.php +++ b/resources/lang/zh-CN/store-user-report.php @@ -9,6 +9,7 @@ return [ 'market_id' => '所属市场', 'store_name' => '商家名称', 'new_user_total' => '新增用户总数', + 'new_total' => '新增用户总数', 'mm_user_id' => '所属市场经理', 'time' => '时间', ], From 47ce5dc5edb22742739923415c71b5e12faeb27a Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Fri, 30 Oct 2020 11:44:16 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=BA=97=E9=93=BA=E6=96=B0=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E7=BB=9F=E8=AE=A1--=E6=B7=BB=E5=8A=A0=E5=BF=AB?= =?UTF-8?q?=E6=8D=B7=E6=97=B6=E9=97=B4=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Controllers/StoreUserReportController.php | 9 +++++++++ app/Admin/routes.php | 2 +- resources/lang/zh-CN/store-user-report.php | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/Admin/Controllers/StoreUserReportController.php b/app/Admin/Controllers/StoreUserReportController.php index d8b835e..3488f2e 100644 --- a/app/Admin/Controllers/StoreUserReportController.php +++ b/app/Admin/Controllers/StoreUserReportController.php @@ -2,6 +2,7 @@ namespace App\Admin\Controllers; +use App\Admin\Actions\Grid\v3\DataReportOption; use App\Admin\Repositories\StoreUserReport; use Dcat\Admin\Form; use Dcat\Admin\Grid; @@ -47,6 +48,14 @@ class StoreUserReportController extends AdminController $filter->equal('market_id')->select($marketList)->width(3); $filter->in('store_id','店铺名称')->multipleSelect($storeList)->width(4); }); + $grid->tools([ + new DataReportOption('today','store_new_user','今日'), + new DataReportOption('yesterday','store_new_user','昨日'), + new DataReportOption('this_week','store_new_user','本周'), + new DataReportOption('last_week','store_new_user','上周'), + new DataReportOption('this_month','store_new_user','本月'), + new DataReportOption('last_month','store_new_user','上月') + ]); // 每页10条 $grid->paginate(10); }); diff --git a/app/Admin/routes.php b/app/Admin/routes.php index db8ebcb..5f5cef3 100644 --- a/app/Admin/routes.php +++ b/app/Admin/routes.php @@ -46,7 +46,7 @@ Route::group([ //根据市场id,商户名查询商户 $router->any('/api/stores', 'LanzuServiceSpeakerController@getStores'); //统计店铺新增用户 - $router->resource('/storeUserReport', 'StoreUserReportController'); + $router->resource('/store_new_user', 'StoreUserReportController'); $router->any('/sentsms', 'Test@sentSms'); // 分类 diff --git a/resources/lang/zh-CN/store-user-report.php b/resources/lang/zh-CN/store-user-report.php index a09f452..75528f2 100644 --- a/resources/lang/zh-CN/store-user-report.php +++ b/resources/lang/zh-CN/store-user-report.php @@ -2,7 +2,7 @@ return [ 'labels' => [ 'StoreUserReport' => '店铺新用户报表', - 'storeUserReport' => '店铺新用户报表', + 'store_new_user' => '店铺新用户报表', ], 'fields' => [ 'store_id' => '店铺ID',