GoodsLists.php 4.1 KB

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