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

86 lines
3.0 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 GoodsReport extends EloquentRepository
  8. {
  9. /**
  10. * Model.
  11. *
  12. * @var string
  13. */
  14. protected $eloquentClass = Model::class;
  15. /**
  16. * 获取统计列表数据
  17. */
  18. public function get(GridModel $model)
  19. {
  20. // 获取当前页数
  21. $currentPage = $model->getCurrentPage();
  22. // 获取每页显示行数
  23. $perPage = $model->getPerPage();
  24. // 获取筛选参数
  25. $name = request()->input('name', '');
  26. $marketId = request()->input('market_id');
  27. $storeId = request()->input('store_id');
  28. $time = date('Y-m-d',time());
  29. $startTime = request()->input('start_time');
  30. $endTime = request()->input('end_time');
  31. $orderGoodsActivity = Model::select(DB::raw('COUNT(lanzu_order_goods.id) 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'))
  32. ->join('lanzu_order','lanzu_order_goods.order_id','=','lanzu_order.id')
  33. ->join('lanzu_order_main','lanzu_order.order_main_id','=','lanzu_order_main.global_order_id')
  34. ->where('lanzu_order_goods.activity_type',2)
  35. ->where('lanzu_order_goods.status',1)
  36. ->whereIn('lanzu_order_main.state',[4,5,10,11])
  37. ;
  38. if($name){
  39. $orderGoodsActivity->where('lanzu_order_goods.name','like',"%$name%");
  40. }
  41. if($marketId){
  42. $orderGoodsActivity->where('market_id',$marketId);
  43. }
  44. if($storeId){
  45. $orderGoodsActivity->where('store_id',$storeId);
  46. }
  47. if($startTime){
  48. $date = $startTime;
  49. $startTime = $startTime.' 00:00:00';
  50. $orderGoodsActivity->where([['lanzu_order_goods.created_at','>=',strtotime($startTime)]]);
  51. }else{
  52. $date = '2020-06-01';
  53. }
  54. if($endTime){
  55. $date = $date.' 至 '.$endTime;
  56. $endTime = $endTime.' 23:59:59';
  57. $orderGoodsActivity->where([['lanzu_order_goods.created_at','<=',strtotime($endTime)]]);
  58. }else{
  59. $date .= ' 至 '.$time;
  60. }
  61. // if(empty($startTime) && empty($endTime)){
  62. // $date = $time;
  63. // $todayStart = $time.' 00:00:00';
  64. // $todayEnd = $time.' 23:59:59';
  65. // $orderGoodsActivity->where([['lanzu_order_goods.created_at','>=',strtotime($todayStart)]]);
  66. // $orderGoodsActivity->where([['lanzu_order_goods.created_at','<=',strtotime($todayEnd)]]);
  67. // }
  68. $list = $orderGoodsActivity->groupBy('goods_id','lanzu_order_goods.name','cover_img','market_id','store_id')->paginate($perPage);
  69. $list = $list->toArray();
  70. return $model->makePaginator(
  71. $list['total'] ?? 0,$list['data'] ?? []
  72. );
  73. }
  74. }