EffectiveRulesLists.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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\adminapi\lists\effective;
  15. use app\adminapi\lists\BaseAdminDataLists;
  16. use app\common\model\effective\EffectiveRules;
  17. use app\common\lists\ListsSearchInterface;
  18. use think\db\Query;
  19. /**
  20. * EffectiveRules列表
  21. * Class EffectiveRulesLists
  22. * @package app\adminapi\listseffective
  23. */
  24. class EffectiveRulesLists extends BaseAdminDataLists implements ListsSearchInterface
  25. {
  26. /**
  27. * @notes 设置搜索条件
  28. * @return \string[][]
  29. * @author likeadmin
  30. * @date 2024/07/17 11:49
  31. */
  32. public function setSearch(): array
  33. {
  34. return [
  35. '=' => ['effective_num', 'effective_unit', 'remark'],
  36. ];
  37. }
  38. /**
  39. * @notes 获取列表
  40. * @return array
  41. * @throws \think\db\exception\DataNotFoundException
  42. * @throws \think\db\exception\DbException
  43. * @throws \think\db\exception\ModelNotFoundException
  44. * @author likeadmin
  45. * @date 2024/07/17 11:49
  46. */
  47. public function lists(): array
  48. {
  49. $data = EffectiveRules::with(['effectiveWithCategory'=>function(Query $query){
  50. $query->field('id,name');
  51. }])
  52. ->where($this->searchWhere)
  53. ->field(['id', 'effective_num', 'effective_unit', 'remark'])
  54. ->limit($this->limitOffset, $this->limitLength)
  55. ->order(['id' => 'desc'])
  56. ->select()
  57. ->toArray();
  58. foreach($data as $k => $v){
  59. $v['goods_category_ids'] = array_column($v['effectiveWithCategory'],'id');
  60. $data[$k] = $v;
  61. }
  62. return $data;
  63. }
  64. /**
  65. * @notes 获取数量
  66. * @return int
  67. * @author likeadmin
  68. * @date 2024/07/17 11:49
  69. */
  70. public function count(): int
  71. {
  72. return EffectiveRules::where($this->searchWhere)->count();
  73. }
  74. }