PresellLists.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace app\shopapi\lists;
  3. use app\common\enum\PresellEnum;
  4. use app\common\lists\BaseDataLists;
  5. use app\common\model\PresellGoods;
  6. class PresellLists extends BaseDataLists
  7. {
  8. /**
  9. * @inheritDoc
  10. */
  11. public function lists(): array
  12. {
  13. $field = [
  14. 'pg.id', 'pg.goods_id', 'pg.presell_id', 'pg.click', 'pg.virtual_click', 'pg.virtual_sale',
  15. 'pg.max_price', 'pg.min_price',
  16. 'content',
  17. ];
  18. $lists = PresellGoods::alias('pg')
  19. ->join('presell p', 'p.id=pg.presell_id')
  20. ->field($field)
  21. ->with([ 'items' ])
  22. ->append([ 'show_goods' ])
  23. ->hidden([ 'content' ])
  24. ->where('p.status', PresellEnum::STATUS_START)
  25. ->where('p.start_time', '<=', time())
  26. ->where('p.end_time', '>=', time())
  27. ->order('pg.min_price asc')
  28. ->limit($this->limitOffset, $this->limitLength)
  29. ->select()->toArray();
  30. foreach ($lists as &$info) {
  31. $info['sale_nums'] = array_sum(array_column($info['items'], 'sale_nums'));
  32. unset($info['items']);
  33. }
  34. return $lists;
  35. }
  36. /**
  37. * @inheritDoc
  38. */
  39. public function count(): int
  40. {
  41. return PresellGoods::alias('pg')
  42. ->join('presell p', 'p.id=pg.presell_id')
  43. ->field('pg.id')
  44. ->where('p.status', PresellEnum::STATUS_START)
  45. ->where('p.start_time', '<=', time())
  46. ->where('p.end_time', '>=', time())
  47. ->count();
  48. }
  49. }