ChartsController.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /****************************************************************
  3. * Author: libaojia
  4. * Date: 2017/10/20 上午9:36
  5. * Email: livsyitian@163.com
  6. * QQ: 995265288
  7. * User: 芸众商城 www.yunzshop.com
  8. ****************************************************************/
  9. namespace app\backend\modules\charts\controllers;
  10. use app\common\components\BaseController;
  11. use app\common\helpers\PaginationHelper;
  12. class ChartsController extends BaseController
  13. {
  14. protected $page_size = 10;
  15. public function arrayKrSort(array $data, $field)
  16. {
  17. $data = array_values(array_sort($data, function ($value) use ($field) {
  18. return $value[$field];
  19. }));
  20. krsort($data);
  21. return array_values($data);
  22. }
  23. protected function getPagination(array $data)
  24. {
  25. return PaginationHelper::show(sizeof($data) - $this->page_size, $this->getPage(), $this->page_size);
  26. }
  27. protected function getPageData(array $data)
  28. {
  29. $start = $this->getPage() * $this->page_size - $this->page_size;
  30. $end = $start + $this->page_size;
  31. $data = array_where($data, function ($value, $key) use($start,$end) {
  32. return $key >= $start && $key < $end;
  33. });
  34. return $data;
  35. }
  36. protected function getPage()
  37. {
  38. return \YunShop::request()->page ?: 1;
  39. }
  40. }