GoodsLists.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. $where['is_show'] = 1;//后台正常显示商品
  47. if (!empty($this->params['goods_category_id'])) {
  48. $goodsCategoryId = end($this->params['goods_category_id']);
  49. $goodsCategoryData = GoodsCategory::where(['status'=>1])->order(['pid' => 'asc','weigh' => 'desc', 'id' => 'desc'])
  50. ->select()->toArray();
  51. $ids =get_tree_ids($goodsCategoryData,$goodsCategoryId);
  52. $ids[] = $goodsCategoryId;
  53. $where[] = ['goods_category_id','in' ,$ids];
  54. }
  55. if(empty($this->params['user_id'])){
  56. $where[] = ['user_id','=' ,0];
  57. } else {
  58. $where[] = ['user_id','=' ,$this->params['user_id']];
  59. }
  60. if (isset($this->params['labels']) && !empty($this->params['labels'])) {
  61. $sqls = [];
  62. foreach ($this->params['labels'] as $item) {
  63. $sqls[] = "FIND_IN_SET({$item}, labels) > 0";
  64. }
  65. $query_sql = implode(' OR ', $sqls);
  66. $period_ids = Goods::where('labels','<>', '')->whereRaw($query_sql)->column('id');
  67. $where[] = [ 'id','IN',$period_ids?:[0]];
  68. }
  69. if (isset($this->params['property_activity_id']) && !empty($this->params['property_activity_id'])) {
  70. // 筛选已选过的
  71. $where[] = ['is_activity','=' ,1];//100000
  72. }
  73. return $where;
  74. }
  75. /**
  76. * @notes 获取列表
  77. * @return array
  78. * @throws \think\db\exception\DataNotFoundException
  79. * @throws \think\db\exception\DbException
  80. * @throws \think\db\exception\ModelNotFoundException
  81. * @author likeadmin
  82. * @date 2024/07/07 18:37
  83. */
  84. public function lists(): array
  85. {
  86. $lists = Goods::with(['goodsCategory'=>function (Query $query) {
  87. $query->field('name');
  88. },'performanceRules'=>function (Query $query) {
  89. $query->field('type,rate');
  90. }])
  91. ->where($this->searchWhere)
  92. ->where($this->queryWhere())
  93. ->order(['id' => 'desc'])
  94. ->append(['is_type'])
  95. ->limit($this->limitOffset, $this->limitLength)
  96. ->select()
  97. ->toArray();
  98. $goodsCategoryObj = GoodsCategory::where(['status'=>1])->order(['pid' => 'asc','weigh' => 'desc', 'id' => 'desc'])
  99. ->select();
  100. foreach ($lists as &$item) {
  101. $item['goods_category_ids'] = array_map("intval",$item['goods_category_ids']);
  102. $item['goods_category_ids_str'] = implode(' / ',$goodsCategoryObj->whereIn('id', $item['goods_category_ids'])->column('name'));
  103. $item['goods_image'] = $item['goods_image'] ? FileService::getFileUrl($item['goods_image']):null;
  104. $item['goods_video'] = $item['goods_video'] ? FileService::getFileUrl($item['goods_video']):null;
  105. }
  106. return $lists;
  107. }
  108. /**
  109. * @notes 获取数量
  110. * @return int
  111. * @author likeadmin
  112. * @date 2024/07/07 18:37
  113. */
  114. public function count(): int
  115. {
  116. return Goods::where($this->searchWhere)->where($this->queryWhere())->count();
  117. }
  118. }