GoodsLists.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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;
  15. use app\adminapi\lists\BaseAdminDataLists;
  16. use app\common\model\goods\Goods;
  17. use app\common\lists\ListsSearchInterface;
  18. use app\common\model\goods_category\GoodsCategory;
  19. use app\common\service\FileService;
  20. /**
  21. * Goods列表
  22. * Class GoodsLists
  23. * @package app\adminapi\listsgoods
  24. */
  25. class GoodsLists extends BaseAdminDataLists implements ListsSearchInterface
  26. {
  27. /**
  28. * @notes 设置搜索条件
  29. * @return \string[][]
  30. * @author likeadmin
  31. * @date 2024/07/07 18:37
  32. */
  33. public function setSearch(): array
  34. {
  35. return [
  36. '=' => ['goods_status'],
  37. '%like%' => ['goods_name','goods_brand'],
  38. 'between' => ['service_total', 'service_fee'],
  39. ];
  40. }
  41. public function queryWhere()
  42. {
  43. $where = [];
  44. if (!empty($this->params['goods_category_id'])) {
  45. $goodsCategoryId = end($this->params['goods_category_id']);
  46. $goodsCategoryData = GoodsCategory::where(['status'=>1])->order(['pid' => 'asc','weigh' => 'desc', 'id' => 'desc'])
  47. ->select()->toArray();
  48. $ids =get_tree_ids($goodsCategoryData,$goodsCategoryId);
  49. $ids[] = $goodsCategoryId;
  50. $where[] = ['goods_category_id','in' ,$ids];
  51. }
  52. return $where;
  53. }
  54. /**
  55. * @notes 获取列表
  56. * @return array
  57. * @throws \think\db\exception\DataNotFoundException
  58. * @throws \think\db\exception\DbException
  59. * @throws \think\db\exception\ModelNotFoundException
  60. * @author likeadmin
  61. * @date 2024/07/07 18:37
  62. */
  63. public function lists(): array
  64. {
  65. $lists = Goods::order(['id' => 'desc'])
  66. ->where($this->searchWhere)
  67. ->where($this->queryWhere())
  68. ->limit($this->limitOffset, $this->limitLength)
  69. ->select()
  70. ->toArray();
  71. $goodsCategoryObj = GoodsCategory::where(['status'=>1])->order(['pid' => 'asc','weigh' => 'desc', 'id' => 'desc'])
  72. ->select();
  73. foreach ($lists as &$item) {
  74. $item['goods_category_ids'] = array_map("intval",$item['goods_category_ids']);
  75. $item['goods_category_ids_str'] = implode(' / ',$goodsCategoryObj->whereIn('id', $item['goods_category_ids'])->column('name'));
  76. $item['goods_image'] = $item['goods_image'] ? FileService::getFileUrl($item['goods_image']):null;
  77. $item['goods_video'] = $item['goods_video'] ? FileService::getFileUrl($item['goods_video']):null;
  78. }
  79. return $lists;
  80. }
  81. /**
  82. * @notes 获取数量
  83. * @return int
  84. * @author likeadmin
  85. * @date 2024/07/07 18:37
  86. */
  87. public function count(): int
  88. {
  89. return Goods::where($this->searchWhere)->where($this->queryWhere())->count();
  90. }
  91. }