BookGiftsController.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace App\Http\Controllers\Manage\Book;
  3. use App\Http\Controllers\Manage\Book\Transformers\BookGiftDailyTransformer;
  4. use App\Http\Controllers\Manage\Book\Transformers\BookGiftTransformer;
  5. use App\Modules\Book\Services\BookCategoryService;
  6. use App\Modules\Book\Services\BookConfigService;
  7. use App\Modules\Book\Services\BookGiftsService;
  8. use App\Modules\Book\Services\BookService;
  9. use Illuminate\Http\Request;
  10. use App\Http\Controllers\Controller;
  11. class BookGiftsController extends Controller
  12. {
  13. /**
  14. * 获取按书统计送礼数据
  15. * @param Request $request
  16. * @return mixed
  17. */
  18. public function getBookGiftsStatsByBook(Request $request){
  19. $time = $request->input('time','');
  20. if(!in_array($time,['last_week','last_month','today'])){
  21. return response()->error('PARAM_ERROR');
  22. }
  23. if($time=='last_week'){
  24. $start = date('Y-m-d H:i:s',mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y')));
  25. $end = date('Y-m-d H:i:s',mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y')));
  26. }
  27. if($time=='last_month'){
  28. $start = date('Y-m-01 00:00:00',strtotime('-1 month'));
  29. $end = date('Y-m-d 23:59:59',strtotime(date('Y-m-01 H:i:s -1 day')));
  30. }
  31. if($time=='today'){
  32. $start = date('Y-m-d 00:00:00');
  33. $end = date('Y-m-d 23:59:59');
  34. }
  35. $res = BookGiftsService::getGiftsSendStatisticByBook($start,$end);
  36. foreach ($res as $value){
  37. $res->book_name = (BookConfigService::getBookById($value->bid))->book_name;
  38. }
  39. return response()->pagination(new BookGiftTransformer(),$res);
  40. }
  41. /**
  42. * 获取按礼物分组统计送礼数据
  43. * @param Request $request
  44. * @return mixed
  45. */
  46. public function getBookGiftsStatsByGift(Request $request){
  47. $time = $request->input('time','');
  48. if(!in_array($time,['last_week','last_month','today'])){
  49. return response()->error('PARAM_ERROR');
  50. }
  51. if($time=='last_week'){
  52. $start = date('Y-m-d H:i:s',mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y')));
  53. $end = date('Y-m-d H:i:s',mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y')));
  54. }
  55. if($time=='last_month'){
  56. $start = date('Y-m-01 00:00:00',strtotime('-1 month'));
  57. $end = date('Y-m-d 23:59:59',strtotime(date('Y-m-01 H:i:s -1 day')));
  58. }
  59. if($time=='today'){
  60. $start = date('Y-m-d 00:00:00');
  61. $end = date('Y-m-d 23:59:59');
  62. }
  63. $res = BookGiftsService::getGiftsSendStatisticByGift($start,$end);
  64. return response()->pagination(new BookGiftTransformer(),$res);
  65. }
  66. /**
  67. * 获取按书分组每日送礼统计
  68. * @param Request $request
  69. * @return mixed
  70. */
  71. public function getBookGiftDailyStatsByBook(Request $request) {
  72. $start = $request->input('start_date','');
  73. $end = $request->input('end_date','');
  74. $res = BookGiftsService::getGiftsSendDaillyStatsByBook($start,$end);
  75. return response()->pagination(new BookGiftDailyTransformer(),$res);
  76. }
  77. /**
  78. * 获取按书分组每日送礼统计
  79. * @param Request $request
  80. * @return mixed
  81. */
  82. public function getBookGiftDailyStatsByGift(Request $request) {
  83. $res = BookGiftsService::getGiftsSendDaillyStatsByGift();
  84. return response()->pagination(new BookGiftDailyTransformer(),$res);
  85. }
  86. }