FirmGoodLists.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * @author 林海涛
  4. * @date 2024/7/15 下午3:41
  5. */
  6. namespace app\api\lists;
  7. use app\common\model\goods\Goods;
  8. use app\common\lists\ListsSearchInterface;
  9. use app\common\model\goods_category\GoodsCategory;
  10. use app\common\service\FileService;
  11. /**
  12. * Goods列表
  13. * Class GoodsLists
  14. * @package app\adminapi\listsgoods
  15. */
  16. class FirmGoodLists extends BaseApiDataLists implements ListsSearchInterface
  17. {
  18. /**
  19. * @notes 设置搜索条件
  20. * @return \string[][]
  21. * @author likeadmin
  22. * @date 2024/07/07 18:37
  23. */
  24. public function setSearch(): array
  25. {
  26. return [
  27. '=' => ['goods_status'],
  28. '%like%' => ['goods_name', 'goods_brand'],
  29. 'between' => ['service_total', 'service_fee'],
  30. ];
  31. }
  32. public function queryWhere()
  33. {
  34. $where = [];
  35. //$where[] = ['user_id',];
  36. if (!empty($this->params['goods_category_id'])) {
  37. $goodsCategoryId = end($this->params['goods_category_id']);
  38. $goodsCategoryData = GoodsCategory::where(['status' => 1])->order(['pid' => 'asc', 'weigh' => 'desc', 'id' => 'desc'])
  39. ->select()->toArray();
  40. $ids = get_tree_ids($goodsCategoryData, $goodsCategoryId);
  41. $ids[] = $goodsCategoryId;
  42. $where[] = ['goods_category_id', 'in', $ids];
  43. }
  44. // 创建时间
  45. if (!empty($this->params['create_time'])) {
  46. $time = [strtotime($this->params['create_time'][0]), strtotime($this->params['create_time'][1])];
  47. $where[] = ['create_time', 'between', $time];
  48. }
  49. //更新时间
  50. if (!empty($this->params['update_time'])) {
  51. $time = [strtotime($this->params['update_time'][0]), strtotime($this->params['update_time'][1])];
  52. $where[] = ['update_time', 'between', $time];
  53. }
  54. return $where;
  55. }
  56. /**
  57. * @notes 获取列表
  58. * @return array
  59. * @throws \think\db\exception\DataNotFoundException
  60. * @throws \think\db\exception\DbException
  61. * @throws \think\db\exception\ModelNotFoundException
  62. * @author likeadmin
  63. * @date 2024/07/07 18:37
  64. */
  65. public function lists(): array
  66. {
  67. $lists = Goods::order(['id' => 'desc'])
  68. ->where($this->searchWhere)
  69. ->where($this->queryWhere())
  70. ->limit($this->limitOffset, $this->limitLength)
  71. ->select()
  72. ->toArray();
  73. $goodsCategoryObj = GoodsCategory::where(['status' => 1])->order(['pid' => 'asc', 'weigh' => 'desc', 'id' => 'desc'])
  74. ->select();
  75. foreach ($lists as &$item) {
  76. $item['goods_category_ids'] = array_map("intval", $item['goods_category_ids']);
  77. $item['goods_category_ids_str'] = implode(' / ', $goodsCategoryObj->whereIn('id', $item['goods_category_ids'])->column('name'));
  78. $item['goods_image'] = $item['goods_image'] ? FileService::getFileUrl($item['goods_image']) : null;
  79. $item['goods_video'] = $item['goods_video'] ? FileService::getFileUrl($item['goods_video']) : null;
  80. }
  81. return $lists;
  82. }
  83. /**
  84. * @notes 获取数量
  85. * @return int
  86. * @author likeadmin
  87. * @date 2024/07/07 18:37
  88. */
  89. public function count(): int
  90. {
  91. return Goods::where($this->searchWhere)->where($this->queryWhere())->count();
  92. }
  93. }