GoodsTimeLists.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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\goods_time;
  15. use app\adminapi\lists\BaseAdminDataLists;
  16. use app\common\model\goods_time\GoodsTime;
  17. use app\common\lists\ListsSearchInterface;
  18. /**
  19. * GoodsTime列表
  20. * Class GoodsTimeLists
  21. * @package app\adminapi\listsgoods_time
  22. */
  23. class GoodsTimeLists extends BaseAdminDataLists implements ListsSearchInterface
  24. {
  25. /**
  26. * @notes 设置搜索条件
  27. * @return \string[][]
  28. * @author likeadmin
  29. * @date 2025/02/23 11:02
  30. */
  31. public function setSearch(): array
  32. {
  33. return [
  34. '=' => ['service_time'],
  35. ];
  36. }
  37. public function queryWhereRaw(){
  38. $where = '1=1';
  39. if(isset($this->params['goods_category_ids']) && !empty($this->params['goods_category_ids'])){
  40. $sqls = [];
  41. $goods_category_ids =[];
  42. foreach ($this->params['goods_category_ids'] as $val){
  43. ($val = json_decode($val,true))?($goods_category_ids[] = end($val)):($goods_category_ids[] = $val);
  44. }
  45. foreach ($goods_category_ids as $item) {
  46. $sqls[] = "FIND_IN_SET({$item}, goods_category_ids) > 0";
  47. }
  48. $where = implode(' OR ', $sqls);
  49. }
  50. return $where;
  51. }
  52. public function queryWhere(){
  53. $where = [];
  54. if(isset($this->params['title']) && !empty($this->params['title'])){
  55. $where[] = ['title', 'like','%' .$this->params['title'] . '%'];
  56. }
  57. return $where;
  58. }
  59. /**
  60. * @notes 获取列表
  61. * @return array
  62. * @throws \think\db\exception\DataNotFoundException
  63. * @throws \think\db\exception\DbException
  64. * @throws \think\db\exception\ModelNotFoundException
  65. * @author likeadmin
  66. * @date 2025/02/23 11:02
  67. */
  68. public function lists(): array
  69. {
  70. $list = GoodsTime::where($this->searchWhere)
  71. ->where($this->queryWhere())
  72. ->whereRaw($this->queryWhereRaw())
  73. ->field(['id', 'title','service_time', 'goods_category_ids'])
  74. ->limit($this->limitOffset, $this->limitLength)
  75. ->order(['id' => 'desc'])
  76. ->select()
  77. ->toArray();
  78. foreach($list as &$item) {
  79. $item['goods_category_ids'] = explode(',', $item['goods_category_ids']);
  80. }
  81. return $list;
  82. }
  83. /**
  84. * @notes 获取数量
  85. * @return int
  86. * @author likeadmin
  87. * @date 2025/02/23 11:02
  88. */
  89. public function count(): int
  90. {
  91. return GoodsTime::where($this->searchWhere)->count();
  92. }
  93. }