GoodsLists.php 5.2 KB

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