GoodsLists.php 4.8 KB

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