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

105 lines
3.8 KiB

  1. <?php
  2. namespace App\Admin\Repositories\v3;
  3. use App\Models\LanzuOrderGoods as Model;
  4. use Dcat\Admin\Grid\Model as GridModel;
  5. use Dcat\Admin\Repositories\EloquentRepository;
  6. use Illuminate\Support\Facades\DB;
  7. class GoodsActivityReport extends EloquentRepository
  8. {
  9. public $data = [];
  10. /**
  11. * Model.
  12. *
  13. * @var string
  14. */
  15. protected $eloquentClass = Model::class;
  16. /**
  17. * 获取统计列表数据
  18. */
  19. public function get(GridModel $model)
  20. {
  21. // 获取当前页数
  22. $currentPage = $model->getCurrentPage();
  23. // 获取每页显示行数
  24. $perPage = $model->getPerPage();
  25. $selects = 'SUM(number) as total,SUM((original_price-price)*number) as subsidy_total,price,original_price,lanzu_order_goods.goods_id,lanzu_order_goods.name,lanzu_order_goods.cover_img,lanzu_order_main.market_id,lanzu_order.store_id';
  26. $orderGoodsActivity = $this->getDataModel($selects, $perPage);
  27. $list = $orderGoodsActivity->orderBy('total','desc')->groupBy('goods_id','lanzu_order_goods.name','cover_img','market_id','store_id','price','original_price')->paginate($perPage);
  28. $list = $list->toArray();
  29. return $model->makePaginator(
  30. $list['total'] ?? 0,$list['data'] ?? []
  31. );
  32. }
  33. public function getDataModel($selects ,$perPage = 10)
  34. {
  35. // 获取筛选参数
  36. $name = request()->input('name', '');
  37. $marketId = request()->input('market_id');
  38. $storeId = request()->input('store_id');
  39. $time = date('Y-m-d',time());
  40. $startTime = request()->input('start_time');
  41. $endTime = request()->input('end_time');
  42. $orderGoodsActivity = Model::select(DB::raw($selects))
  43. ->join('lanzu_order','lanzu_order_goods.order_id','=','lanzu_order.id')
  44. ->join('lanzu_order_main','lanzu_order.order_main_id','=','lanzu_order_main.global_order_id')
  45. ->where('lanzu_order_goods.activity_type',2)
  46. ->where('lanzu_order_goods.status',1)
  47. ->whereIn('lanzu_order_main.state',[4,5,10,11]);
  48. if($name){
  49. $orderGoodsActivity->where('lanzu_order_goods.name','like',"%$name%");
  50. }
  51. if($marketId){
  52. $orderGoodsActivity->where('market_id',$marketId);
  53. }
  54. if($storeId){
  55. $orderGoodsActivity->where('store_id',$storeId);
  56. }
  57. if($startTime){
  58. $date = $startTime;
  59. $startTime = $startTime.' 00:00:00';
  60. $orderGoodsActivity->where([['lanzu_order_goods.created_at','>=',strtotime($startTime)]]);
  61. }else{
  62. $date = '2020-06-01';
  63. }
  64. if($endTime){
  65. $date = $date.' 至 '.$endTime;
  66. $endTime = $endTime.' 23:59:59';
  67. $orderGoodsActivity->where([['lanzu_order_goods.created_at','<=',strtotime($endTime)]]);
  68. }else{
  69. $date .= ' 至 '.$time;
  70. }
  71. // if(empty($startTime) && empty($endTime)){
  72. // $date = $time;
  73. // $todayStart = $time.' 00:00:00';
  74. // $todayEnd = $time.' 23:59:59';
  75. // $orderGoodsActivity->where([['lanzu_order_goods.created_at','>=',strtotime($todayStart)]]);
  76. // $orderGoodsActivity->where([['lanzu_order_goods.created_at','<=',strtotime($todayEnd)]]);
  77. // }
  78. return $orderGoodsActivity;
  79. }
  80. /**
  81. * 获取总数
  82. */
  83. public function getCountData()
  84. {
  85. $selects = "SUM(lanzu_order_goods.number) as total,SUM((original_price-price)*number) as subsidy_total,FROM_UNIXTIME(lanzu_order_goods.created_at,'%Y-%m-%d') as dtime";
  86. $orderGoodsActivity = $this->getDataModel($selects);
  87. $total = $orderGoodsActivity->groupBy('dtime')->get()->toArray();
  88. return $total ?? [];
  89. }
  90. }