链街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.

82 lines
3.6 KiB

  1. <?php
  2. namespace App\Admin\Repositories;
  3. use App\Models\storeUserReport as Model;
  4. use Dcat\Admin\Grid\Model as GridModel;
  5. use Dcat\Admin\Repositories\EloquentRepository;
  6. use App\Models\ImsCjdcOrder as orderModel;
  7. use App\Models\StoreAccount as storeAccountModel;
  8. use App\Models\ImsCjdcStore as storeModel;
  9. use Illuminate\Support\Facades\DB;
  10. class StoreUserReport extends EloquentRepository
  11. {
  12. /**
  13. * Model.
  14. *
  15. * @var string
  16. */
  17. protected $eloquentClass = Model::class;
  18. /**
  19. * 获取统计列表数据
  20. */
  21. public function get(GridModel $model)
  22. {
  23. $startTime = '2020-06-01';$endTime = '2020-08-01';
  24. $this->setSort($model);
  25. $this->setPaginate($model);
  26. //根据订单查询 方法查询出来的数据不对
  27. // $orderModel = new orderModel();
  28. // $query = $orderModel::join('ims_cjdc_store as store','order.store_id','store.id')
  29. // ->join('ims_cjdc_user as user','order.user_id','user.id')
  30. // ->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"))
  31. // ->whereRaw("UNIX_TIMESTAMP(pay_time) BETWEEN UNIX_TIMESTAMP(?) AND UNIX_TIMESTAMP(?)",[$startTime,$endTime])
  32. // ->whereRaw("join_time BETWEEN UNIX_TIMESTAMP(?) AND UNIX_TIMESTAMP(?)",[$startTime,$endTime])
  33. // ->groupBy('store_id')
  34. // ->orderBy('market_id','desc')
  35. // ->orderBY('new_user_total','desc');
  36. /* 根据流水查询 2020-08-18 目前用全匹配文字方式查询新用户,后期维护店铺流水表的类型(category)后再换,或者使用其他方法 */
  37. $storeAccountModel = new storeAccountModel();
  38. $query = $storeAccountModel::join('ims_cjdc_store as store','ims_cjdc_store_account.store_id','store.id')
  39. // with(['store' => function($query){
  40. // $query->select('id','market_id','name as store_name','mm_user_id');
  41. // }])
  42. ->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"))
  43. ->whereRaw("note = '新用户下单成功,平台奖励'")
  44. // ->whereRaw("UNIX_TIMESTAMP(account.time) BETWEEN UNIX_TIMESTAMP(?) AND UNIX_TIMESTAMP(?)",[$startTime,$endTime])
  45. ->groupBy('store_id')
  46. ->orderBy('store.market_id','desc')
  47. ->orderBY('new_user_total','desc');
  48. // $storeModel = new storeModel();
  49. // $query = $storeModel
  50. // ->with(['storeAccount'=>function($query){
  51. // $query->where('note',"新用户下单成功,平台奖励")
  52. // ->select(DB::raw("count(distinct id) as new_user_total"));
  53. // }])
  54. // ->select('id as store_id','market_id','name as store_name','mm_user_id')
  55. // ->groupBy('id')
  56. // ->orderBy('market_id','desc')
  57. // ->orderBY('new_user_total','desc')
  58. // ;
  59. $model->getQueries()->unique()->each(function ($value) use (&$query) {
  60. if ($value['method'] == 'paginate') {
  61. $value['arguments'][1] = $this->getGridColumns();
  62. } elseif ($value['method'] == 'get') {
  63. $value['arguments'] = [$this->getGridColumns()];
  64. }
  65. $query = call_user_func_array([$query, $value['method']], $value['arguments'] ?? []);
  66. });
  67. $query = $query->toArray();
  68. $query = $model->makePaginator($query['total'],$query['data']);
  69. return $query;
  70. }
  71. }