TopRankingLists.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\api\lists;
  15. use app\common\model\top_ranking\TopRanking;
  16. /**
  17. * TopRanking列表
  18. * Class TopRankingLists
  19. * @package app\adminapi\liststop_ranking
  20. */
  21. class TopRankingLists extends BaseApiDataLists
  22. {
  23. /**
  24. * @notes 设置搜索条件
  25. * @return \string[][]
  26. * @author likeadmin
  27. * @date 2024/07/07 16:15
  28. */
  29. public function setSearch(): array
  30. {
  31. return [
  32. '=' => ['name'],
  33. ];
  34. }
  35. public function queryWhere(){
  36. $where = [];
  37. // 用户余额
  38. if (isset($this->params['goods_id']) && is_array($this->params['goods_id'])) {
  39. $where[] = ['goods_id', 'in',$this->params['goods_id']];
  40. }
  41. return $where;
  42. }
  43. /**
  44. * @notes 获取列表
  45. * @return array
  46. * @throws \think\db\exception\DataNotFoundException
  47. * @throws \think\db\exception\DbException
  48. * @throws \think\db\exception\ModelNotFoundException
  49. * @author likeadmin
  50. * @date 2024/07/07 16:15
  51. */
  52. public function lists(): array
  53. {
  54. return TopRanking::where($this->searchWhere)
  55. ->where($this->queryWhere())
  56. ->field(['id', 'name', 'goods_id', 'sort'])
  57. ->limit($this->limitOffset, $this->limitLength)
  58. ->order(['sort' => 'desc','id' => 'desc'])
  59. ->select()
  60. ->toArray();
  61. }
  62. /**
  63. * @notes 获取数量
  64. * @return int
  65. * @author likeadmin
  66. * @date 2024/07/07 16:15
  67. */
  68. public function count(): int
  69. {
  70. return TopRanking::where($this->searchWhere)->count();
  71. }
  72. }