链街Dcat后台
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

  1. <?php
  2. namespace App\Admin\Repositories;
  3. use App\Models\v3\Store as Model;
  4. use Dcat\Admin\Grid\Model as GridModel;
  5. use Dcat\Admin\Repositories\EloquentRepository;
  6. use App\Models\StoreAccount as StoreAccountModel;
  7. use App\Models\FinancialRecord0 as FinancialRecordModel0;
  8. use App\Models\FinancialRecord1 as FinancialRecordModel1;
  9. use App\Models\FinancialRecord2 as FinancialRecordModel2;
  10. use App\Models\FinancialRecord3 as FinancialRecordModel3;
  11. use App\Models\FinancialRecord4 as FinancialRecordModel4;
  12. use Dcat\Admin\Layout\Row;
  13. use Illuminate\Support\Facades\DB;
  14. use App\Admin\Common\Type;
  15. class StoreUserReport extends EloquentRepository
  16. {
  17. /**
  18. * Model.
  19. *
  20. * @var string
  21. */
  22. protected $eloquentClass = Model::class;
  23. /**
  24. * 获取统计列表数据
  25. * 旧表流水数据未洗到新表,所以统计需要查询旧表和新表数据
  26. */
  27. public function get(GridModel $model)
  28. {
  29. $this->setSort($model);
  30. $this->setPaginate($model);
  31. /* 根据流水查询 2020-08-18 用全匹配文字方式查询新用户 旧表 */
  32. // $storeAccountModel = new StoreAccountModel();
  33. // $query = StoreAccountModel::join(Model::$tableName.' as store',StoreAccountModel::$tableName.'.store_id','store.id')
  34. // ->select('store_id','store.market_id','store.name as store_name',DB::raw("count(distinct ".StoreAccountModel::$tableName.".id) as new_user_total"))
  35. // ->whereRaw("note = '新用户下单成功,平台奖励'")
  36. // ->groupBy('store_id')
  37. // ->orderBy('store.market_id','desc')
  38. // ->orderBY('new_user_total','desc')
  39. // ->orderBY('store_id','desc');
  40. // $l = $query->get()->toArray();
  41. // dd($l);
  42. /* 根据流水查询 2020-10-29 用类型字段查询新用户 新表 */
  43. $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'))
  44. ->join(FinancialRecordModel0::$tableName.' as f0',Model::$tableName.'.user_id','=','f0.user_id','left')
  45. ->whereRaw(Model::$tableName.'.user_id MOD 5 = 0')
  46. ->where('user_type',Type::USER_TYPE_STORE)
  47. // ->where('source_type',Type::SOURCE_TYPE_ORDER)
  48. // ->where('money_type',Type::MONEY_TYPE_STORE_PLAT_NEW_USER)
  49. ->where('f0.created_at','>','1600444800')
  50. ->groupBy('store_id','store_name','market_id');
  51. $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'))
  52. ->join(FinancialRecordModel1::$tableName.' as f1',Model::$tableName.'.user_id','=','f1.user_id','left')
  53. ->whereRaw(Model::$tableName.'.user_id MOD 5 = 1')
  54. ->where('user_type',Type::USER_TYPE_STORE)
  55. // ->where('source_type',Type::SOURCE_TYPE_ORDER)
  56. // ->where('money_type',Type::MONEY_TYPE_STORE_PLAT_NEW_USER)
  57. ->where('f1.created_at','>','1600444800')
  58. ->groupBy('store_id','store_name','market_id');
  59. $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'))
  60. ->join(FinancialRecordModel2::$tableName.' as f2',Model::$tableName.'.user_id','=','f2.user_id','left')
  61. ->whereRaw(Model::$tableName.'.user_id MOD 5 = 2')
  62. ->where('user_type',Type::USER_TYPE_STORE)
  63. // ->where('source_type',Type::SOURCE_TYPE_ORDER)
  64. // ->where('money_type',Type::MONEY_TYPE_STORE_PLAT_NEW_USER)
  65. ->where('f2.created_at','>','1600444800')
  66. ->groupBy('store_id','store_name','market_id');
  67. $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'))
  68. ->join(FinancialRecordModel3::$tableName.' as f3',Model::$tableName.'.user_id','=','f3.user_id','left')
  69. ->whereRaw(Model::$tableName.'.user_id MOD 5 = 3')
  70. ->where('user_type',Type::USER_TYPE_STORE)
  71. // ->where('source_type',Type::SOURCE_TYPE_ORDER)
  72. // ->where('money_type',Type::MONEY_TYPE_STORE_PLAT_NEW_USER)
  73. ->where('f3.created_at','>','1600444800')
  74. ->groupBy('store_id','store_name','market_id');
  75. $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'))
  76. ->join(FinancialRecordModel4::$tableName.' as f4',Model::$tableName.'.user_id','=','f4.user_id','left')
  77. ->whereRaw(Model::$tableName.'.user_id MOD 5 = 4')
  78. ->where('user_type',Type::USER_TYPE_STORE)
  79. // ->where('source_type',Type::SOURCE_TYPE_ORDER)
  80. // ->where('money_type',Type::MONEY_TYPE_STORE_PLAT_NEW_USER)
  81. ->where('f4.created_at','>','1600444800')
  82. ->groupBy('store_id','store_name','market_id')
  83. ->union($financial0)
  84. ->union($financial1)
  85. ->union($financial2)
  86. ->union($financial3);
  87. $query = $financial4->get()->toArray();
  88. dd($query);
  89. $model->getQueries()->unique()->each(function ($value) use (&$query) {
  90. if ($value['method'] == 'paginate') {
  91. $value['arguments'][1] = $this->getGridColumns();
  92. } elseif ($value['method'] == 'get') {
  93. $value['arguments'] = [$this->getGridColumns()];
  94. }
  95. $query = call_user_func_array([$query, $value['method']], $value['arguments'] ?? []);
  96. });
  97. $query = $query->toArray();
  98. $query = $model->makePaginator($query['total'],$query['data']);
  99. return $query;
  100. }
  101. }