GoodsLists.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. if(empty($this->params['user_id'])){
  53. $where[] = ['user_id','=' ,0];
  54. } else {
  55. $where[] = ['user_id','=' ,$this->params['user_id']];
  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 2024/07/07 18:37
  67. */
  68. public function lists(): array
  69. {
  70. $lists = Goods::with('goodsCategory')
  71. ->where($this->searchWhere)
  72. ->where($this->queryWhere())
  73. ->order(['id' => 'desc'])
  74. ->limit($this->limitOffset, $this->limitLength)
  75. ->select()
  76. ->toArray();
  77. $goodsCategoryObj = GoodsCategory::where(['status'=>1])->order(['pid' => 'asc','weigh' => 'desc', 'id' => 'desc'])
  78. ->select();
  79. foreach ($lists as &$item) {
  80. $item['goods_category_ids'] = array_map("intval",$item['goods_category_ids']);
  81. $item['goods_category_ids_str'] = implode(' / ',$goodsCategoryObj->whereIn('id', $item['goods_category_ids'])->column('name'));
  82. $item['goods_image'] = $item['goods_image'] ? FileService::getFileUrl($item['goods_image']):null;
  83. $item['goods_video'] = $item['goods_video'] ? FileService::getFileUrl($item['goods_video']):null;
  84. }
  85. return $lists;
  86. }
  87. /**
  88. * @notes 获取数量
  89. * @return int
  90. * @author likeadmin
  91. * @date 2024/07/07 18:37
  92. */
  93. public function count(): int
  94. {
  95. return Goods::where($this->searchWhere)->where($this->queryWhere())->count();
  96. }
  97. }