1
0

GoodsLists.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. $where['platform_value'] = 0;//自平台商品
  46. if (!empty($this->params['goods_category_id'])) {
  47. $goodsCategoryId = end($this->params['goods_category_id']);
  48. $goodsCategoryData = GoodsCategory::where(['status'=>1])->order(['pid' => 'asc','weigh' => 'desc', 'id' => 'desc'])
  49. ->select()->toArray();
  50. $ids =get_tree_ids($goodsCategoryData,$goodsCategoryId);
  51. $ids[] = $goodsCategoryId;
  52. $where[] = ['goods_category_id','in' ,$ids];
  53. }
  54. return $where;
  55. }
  56. /**
  57. * @notes 获取列表
  58. * @return array
  59. * @throws \think\db\exception\DataNotFoundException
  60. * @throws \think\db\exception\DbException
  61. * @throws \think\db\exception\ModelNotFoundException
  62. * @author likeadmin
  63. * @date 2024/07/07 18:37
  64. */
  65. public function lists(): array
  66. {
  67. $lists = Goods::order(['id' => 'desc'])
  68. ->where($this->searchWhere)
  69. ->where($this->queryWhere())
  70. ->visible(['id','goods_name','goods_image'])
  71. ->limit($this->limitOffset, $this->limitLength)
  72. ->select()
  73. ->toArray();
  74. return $lists;
  75. }
  76. /**
  77. * @notes 获取数量
  78. * @return int
  79. * @author likeadmin
  80. * @date 2024/07/07 18:37
  81. */
  82. public function count(): int
  83. {
  84. return Goods::where($this->searchWhere)->where($this->queryWhere())->count();
  85. }
  86. }