GoodsLists.php 3.0 KB

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