1
0

GoodsLists.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 (isset($this->params['platform_value']) && !empty($this->params['platform_value'])) {
  47. $where['platform_value'] = $this->params['platform_value'];//外部平台商品
  48. }
  49. if (!empty($this->params['goods_category_id'])) {
  50. $goodsCategoryId = end($this->params['goods_category_id']);
  51. $goodsCategoryData = GoodsCategory::where(['status'=>1])->order(['pid' => 'asc','weigh' => 'desc', 'id' => 'desc'])
  52. ->select()->toArray();
  53. $ids =get_tree_ids($goodsCategoryData,$goodsCategoryId);
  54. $ids[] = $goodsCategoryId;
  55. $where[] = ['goods_category_id','in' ,$ids];
  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::order(['id' => 'desc'])
  71. ->where($this->searchWhere)
  72. ->where($this->queryWhere())
  73. ->visible(['id','goods_name','goods_image','service_fee','category_type','goods_category_ids','goods_category_id','goods_payment_type','base_service_fee','service_total'])
  74. ->limit($this->limitOffset, $this->limitLength)
  75. ->select()
  76. ->toArray();
  77. return $lists;
  78. }
  79. /**
  80. * @notes 获取数量
  81. * @return int
  82. * @author likeadmin
  83. * @date 2024/07/07 18:37
  84. */
  85. public function count(): int
  86. {
  87. return Goods::where($this->searchWhere)->where($this->queryWhere())->count();
  88. }
  89. }