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

90 lines
3.2 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. $list = $this->getData($perPage);
  26. return $model->makePaginator(
  27. $list['total'] ?? 0,$list['data'] ?? []
  28. );
  29. }
  30. public function getData($perPage = 10)
  31. {
  32. // 获取筛选参数
  33. $name = request()->input('name', '');
  34. $marketId = request()->input('market_id');
  35. $storeId = request()->input('store_id');
  36. $time = date('Y-m-d',time());
  37. $startTime = request()->input('start_time');
  38. $endTime = request()->input('end_time');
  39. $orderGoodsActivity = Model::select(DB::raw('SUM(lanzu_order_goods.number) as total,lanzu_order_goods.goods_id,lanzu_order_goods.name,lanzu_order_goods.cover_img,lanzu_order_main.market_id,lanzu_order.store_id'))
  40. ->join('lanzu_order','lanzu_order_goods.order_id','=','lanzu_order.id')
  41. ->join('lanzu_order_main','lanzu_order.order_main_id','=','lanzu_order_main.global_order_id')
  42. ->where('lanzu_order_goods.activity_type',2)
  43. ->where('lanzu_order_goods.status',1)
  44. ->whereIn('lanzu_order_main.state',[4,5,10,11]);
  45. if($name){
  46. $orderGoodsActivity->where('lanzu_order_goods.name','like',"%$name%");
  47. }
  48. if($marketId){
  49. $orderGoodsActivity->where('market_id',$marketId);
  50. }
  51. if($storeId){
  52. $orderGoodsActivity->where('store_id',$storeId);
  53. }
  54. if($startTime){
  55. $date = $startTime;
  56. $startTime = $startTime.' 00:00:00';
  57. $orderGoodsActivity->where([['lanzu_order_goods.created_at','>=',strtotime($startTime)]]);
  58. }else{
  59. $date = '2020-06-01';
  60. }
  61. if($endTime){
  62. $date = $date.' 至 '.$endTime;
  63. $endTime = $endTime.' 23:59:59';
  64. $orderGoodsActivity->where([['lanzu_order_goods.created_at','<=',strtotime($endTime)]]);
  65. }else{
  66. $date .= ' 至 '.$time;
  67. }
  68. // if(empty($startTime) && empty($endTime)){
  69. // $date = $time;
  70. // $todayStart = $time.' 00:00:00';
  71. // $todayEnd = $time.' 23:59:59';
  72. // $orderGoodsActivity->where([['lanzu_order_goods.created_at','>=',strtotime($todayStart)]]);
  73. // $orderGoodsActivity->where([['lanzu_order_goods.created_at','<=',strtotime($todayEnd)]]);
  74. // }
  75. $list = $orderGoodsActivity->orderBy('total','desc')->groupBy('goods_id','lanzu_order_goods.name','cover_img','market_id','store_id')->paginate($perPage);
  76. $list = $list->toArray();
  77. return $list;
  78. }
  79. }