GoodsLists.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. use think\db\Query;
  21. use think\facade\Log;
  22. /**
  23. * Goods列表
  24. * Class GoodsLists
  25. * @package app\adminapi\listsgoods
  26. */
  27. class GoodsLists extends BaseAdminDataLists implements ListsSearchInterface
  28. {
  29. /**
  30. * @notes 设置搜索条件
  31. * @return \string[][]
  32. * @author likeadmin
  33. * @date 2024/07/07 18:37
  34. */
  35. public function setSearch(): array
  36. {
  37. return [
  38. '=' => ['goods_status','is_agent','is_activity'],
  39. '%like%' => ['goods_name','goods_brand'],
  40. 'between' => ['service_total', 'service_fee'],
  41. ];
  42. }
  43. public function queryWhere()
  44. {
  45. $where = [];
  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. if(empty($this->params['user_id'])){
  55. $where[] = ['user_id','=' ,0];
  56. } else {
  57. $where[] = ['user_id','=' ,$this->params['user_id']];
  58. }
  59. if (isset($this->params['labels']) && !empty($this->params['labels'])) {
  60. $sqls = [];
  61. foreach ($this->params['labels'] as $item) {
  62. $sqls[] = "FIND_IN_SET({$item}, labels) > 0";
  63. }
  64. $query_sql = implode(' OR ', $sqls);
  65. $period_ids = Goods::where('labels','<>', '')->whereRaw($query_sql)->column('id');
  66. $where[] = [ 'id','IN',$period_ids?:[0]];
  67. }
  68. if (isset($this->params['property_activity_id']) && !empty($this->params['property_activity_id'])) {
  69. // 筛选已选过的
  70. $where[] = ['is_activity','=' ,1];//100000
  71. }
  72. return $where;
  73. }
  74. /**
  75. * @notes 获取列表
  76. * @return array
  77. * @throws \think\db\exception\DataNotFoundException
  78. * @throws \think\db\exception\DbException
  79. * @throws \think\db\exception\ModelNotFoundException
  80. * @author likeadmin
  81. * @date 2024/07/07 18:37
  82. */
  83. public function lists(): array
  84. {
  85. $lists = Goods::with(['goodsCategory'=>function (Query $query) {
  86. $query->field('name');
  87. },'performanceRules'=>function (Query $query) {
  88. $query->field('type,rate');
  89. }])
  90. ->where($this->searchWhere)
  91. ->where($this->queryWhere())
  92. ->order(['id' => 'desc'])
  93. ->append(['is_type'])
  94. ->limit($this->limitOffset, $this->limitLength)
  95. ->select()
  96. ->toArray();
  97. $goodsCategoryObj = GoodsCategory::where(['status'=>1])->order(['pid' => 'asc','weigh' => 'desc', 'id' => 'desc'])
  98. ->select();
  99. foreach ($lists as &$item) {
  100. $item['goods_category_ids'] = array_map("intval",$item['goods_category_ids']);
  101. $item['goods_category_ids_str'] = implode(' / ',$goodsCategoryObj->whereIn('id', $item['goods_category_ids'])->column('name'));
  102. $item['goods_image'] = $item['goods_image'] ? FileService::getFileUrl($item['goods_image']):null;
  103. $item['goods_video'] = $item['goods_video'] ? FileService::getFileUrl($item['goods_video']):null;
  104. }
  105. return $lists;
  106. }
  107. /**
  108. * @notes 获取数量
  109. * @return int
  110. * @author likeadmin
  111. * @date 2024/07/07 18:37
  112. */
  113. public function count(): int
  114. {
  115. return Goods::where($this->searchWhere)->where($this->queryWhere())->count();
  116. }
  117. }