GoodsLists.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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','id'],
  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. if (isset($this->params['platforms']) && !empty($this->params['platforms'])) {
  74. $where[] = [ 'platform_value','>',0];
  75. }
  76. if (isset($this->params['platform_value']) && $this->params['platform_value'] != '' ) {
  77. $where[] = [ 'platform_value','=',$this->params['platform_value']?:0];
  78. }
  79. if (isset($this->params['goods_payment_type']) && !empty($this->params['goods_payment_type'])) {
  80. if(is_array($this->params['goods_payment_type'])){
  81. $where[] = [ 'goods_payment_type','IN',$this->params['goods_payment_type']];
  82. }else{
  83. $where[] = [ 'goods_payment_type','=' ,$this->params['goods_payment_type']];
  84. }
  85. }
  86. return $where;
  87. }
  88. /**
  89. * @notes 获取列表
  90. * @return array
  91. * @throws \think\db\exception\DataNotFoundException
  92. * @throws \think\db\exception\DbException
  93. * @throws \think\db\exception\ModelNotFoundException
  94. * @author likeadmin
  95. * @date 2024/07/07 18:37
  96. */
  97. public function lists(): array
  98. {
  99. $lists = Goods::with(['goodsCategory'=>function (Query $query) {
  100. $query->field('name');
  101. },'performanceRules'=>function (Query $query) {
  102. $query->field('type,rate');
  103. }])
  104. ->where($this->searchWhere)
  105. ->where($this->queryWhere())
  106. ->order(['id' => 'desc'])
  107. ->append(['is_type'])
  108. ->limit($this->limitOffset, $this->limitLength)
  109. ->select()
  110. ->toArray();
  111. $goodsCategoryObj = GoodsCategory::where(['status'=>1])->order(['pid' => 'asc','weigh' => 'desc', 'id' => 'desc'])
  112. ->select();
  113. foreach ($lists as &$item) {
  114. $item['goods_category_ids'] = array_map("intval",$item['goods_category_ids']);
  115. $item['goods_category_ids_str'] = implode(' / ',$goodsCategoryObj->whereIn('id', $item['goods_category_ids'])->column('name'));
  116. $item['goods_image'] = $item['goods_image'] ? FileService::getFileUrl($item['goods_image']):null;
  117. $item['goods_video'] = $item['goods_video'] ? FileService::getFileUrl($item['goods_video']):null;
  118. }
  119. return $lists;
  120. }
  121. /**
  122. * @notes 获取数量
  123. * @return int
  124. * @author likeadmin
  125. * @date 2024/07/07 18:37
  126. */
  127. public function count(): int
  128. {
  129. return Goods::where($this->searchWhere)->where($this->queryWhere())->count();
  130. }
  131. }