DetailController.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: king/QQ:995265288
  5. * Date: 2019-06-19
  6. * Time: 16:52
  7. */
  8. namespace app\backend\modules\excelRecharge\controllers;
  9. use app\backend\models\excelRecharge\DetailModel;
  10. use app\common\components\BaseController;
  11. use app\common\helpers\PaginationHelper;
  12. class DetailController extends BaseController
  13. {
  14. /**
  15. * @var DetailModel
  16. */
  17. protected $recordsModels;
  18. //会员excel充值详细记录
  19. public function index()
  20. {
  21. $this->recordsModels = $this->pageList();
  22. return view('excelRecharge.detail', $this->resultData());
  23. }
  24. private function resultData()
  25. {
  26. return [
  27. 'page' => $this->page(),
  28. 'pageList' => $this->recordsModels
  29. ];
  30. }
  31. private function page()
  32. {
  33. return PaginationHelper::show($this->recordsModels->total(), $this->recordsModels->currentPage(), $this->recordsModels->perPage());
  34. }
  35. /**
  36. * @return DetailModel
  37. */
  38. private function pageList()
  39. {
  40. $records = DetailModel::with('member');
  41. $rechargeId = $this->rechargeIdParam();
  42. if ($rechargeId) {
  43. $records->where('recharge_id', $rechargeId);
  44. }
  45. return $records->orderBy('created_at', 'desc')
  46. ->orderBy('id', 'desc')
  47. ->paginate('', ['*'], '', $this->pageParam());
  48. }
  49. /**
  50. * @return int
  51. */
  52. private function pageParam()
  53. {
  54. return (int)request()->page ?: 1;
  55. }
  56. /**
  57. * @return int
  58. */
  59. private function rechargeIdParam()
  60. {
  61. return (int)request()->recharge_id ?: 1;
  62. }
  63. }